mirror of
https://github.com/gsantner/dandelion
synced 2024-11-24 13:22:08 +01:00
Fixed lint issues and moved webview related method calls to UI Thread
This commit is contained in:
parent
e79c1d48ea
commit
e3c2e91b70
19 changed files with 117 additions and 70 deletions
|
@ -15,7 +15,8 @@
|
|||
|
||||
<provider
|
||||
android:name="com.github.dfa.diaspora_android.data.HashtagProvider"
|
||||
android:authorities="com.github.dfa.diaspora_android.mainactivity" />
|
||||
android:authorities="com.github.dfa.diaspora_android.mainactivity"
|
||||
android:exported="false"/>
|
||||
|
||||
<service
|
||||
android:name="com.github.dfa.diaspora_android.task.GetPodsService"
|
||||
|
|
|
@ -69,7 +69,7 @@ public class AboutActivity extends ThemedActivity
|
|||
private ViewPager mViewPager;
|
||||
|
||||
@BindView(R.id.about__appbar)
|
||||
AppBarLayout appBarLayout;
|
||||
protected AppBarLayout appBarLayout;
|
||||
|
||||
@BindView(R.id.main__topbar)
|
||||
protected Toolbar toolbar;
|
||||
|
@ -87,7 +87,11 @@ public class AboutActivity extends ThemedActivity
|
|||
ButterKnife.bind(this);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
if(Build.VERSION.SDK_INT >= 21) {
|
||||
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24px, getTheme()));
|
||||
} else {
|
||||
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24px));
|
||||
}
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -231,9 +235,8 @@ public class AboutActivity extends ThemedActivity
|
|||
}
|
||||
|
||||
public String getContributorsHtml(Context context) {
|
||||
String text = Helpers.readTextfileFromRawRessource(context, R.raw.contributors,
|
||||
return Helpers.readTextfileFromRawRessource(context, R.raw.contributors,
|
||||
"<font color='" + accentColor + "'><b>*</b></font> ", "<br>");
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getMaintainersHtml(Context context) {
|
||||
|
@ -245,9 +248,8 @@ public class AboutActivity extends ThemedActivity
|
|||
}
|
||||
|
||||
public String getLicenseHtml(Context context) {
|
||||
String text = Helpers.readTextfileFromRawRessource(context, R.raw.license,
|
||||
return Helpers.readTextfileFromRawRessource(context, R.raw.license,
|
||||
"", "").replace("\n\n", "<br><br>");
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getLicense3dPartyHtml(Context context) {
|
||||
|
|
|
@ -442,11 +442,19 @@ public class MainActivity extends ThemedActivity
|
|||
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
|
||||
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
|
||||
appSettings.setPod(null);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
|
||||
}
|
||||
});
|
||||
showFragment(getFragment(PodSelectionFragment.TAG));
|
||||
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
||||
AppLog.v(this, "Clear WebView cache");
|
||||
showFragment(getFragment(DiasporaStreamFragment.TAG));
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ContextMenuWebView wv = ((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView();
|
||||
if(wv != null) {
|
||||
AppLog.d(this, "clearing...");
|
||||
|
@ -454,6 +462,8 @@ public class MainActivity extends ThemedActivity
|
|||
} else {
|
||||
AppLog.e(this, "WebView is null!");
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
switch (type) {
|
||||
case "text/plain":
|
||||
|
@ -750,7 +760,7 @@ public class MainActivity extends ThemedActivity
|
|||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
View layout = getLayoutInflater().inflate(R.layout.ui__dialog_search__people_tags, null, false);
|
||||
View layout = getLayoutInflater().inflate(R.layout.ui__dialog_search__people_tags, this.appBarLayout, false);
|
||||
final EditText input = (EditText) layout.findViewById(R.id.dialog_search__input);
|
||||
final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,7 @@ package com.github.dfa.diaspora_android.data;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
|
||||
|
@ -434,13 +435,21 @@ public class AppSettings {
|
|||
|
||||
public int[] getPrimaryColorPickerSettings() {
|
||||
return new int[]{
|
||||
getInt(prefApp, R.string.pref_key__primary_color_base, context.getResources().getColor(R.color.md_blue_500)),
|
||||
getInt(prefApp, R.string.pref_key__primary_color_shade, context.getResources().getColor(R.color.primary))
|
||||
getInt(prefApp, R.string.pref_key__primary_color_base, getColor(R.color.md_blue_500)),
|
||||
getInt(prefApp, R.string.pref_key__primary_color_shade, getColor(R.color.primary))
|
||||
};
|
||||
}
|
||||
|
||||
public int getPrimaryColor() {
|
||||
return getInt(prefApp, R.string.pref_key__primary_color_shade, context.getResources().getColor(R.color.primary));
|
||||
return getInt(prefApp, R.string.pref_key__primary_color_shade, getColor(R.color.primary));
|
||||
}
|
||||
|
||||
private int getColor(int id) {
|
||||
if(Build.VERSION.SDK_INT >= 23) {
|
||||
return context.getResources().getColor(id, context.getTheme());
|
||||
} else {
|
||||
return context.getResources().getColor(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAccentColorPickerSettings(int base, int shade) {
|
||||
|
@ -450,13 +459,13 @@ public class AppSettings {
|
|||
|
||||
public int[] getAccentColorPickerSettings() {
|
||||
return new int[]{
|
||||
getInt(prefApp, R.string.pref_key__accent_color_base, context.getResources().getColor(R.color.md_deep_orange_500)),
|
||||
getInt(prefApp, R.string.pref_key__accent_color_shade, context.getResources().getColor(R.color.accent))
|
||||
getInt(prefApp, R.string.pref_key__accent_color_base, getColor(R.color.md_deep_orange_500)),
|
||||
getInt(prefApp, R.string.pref_key__accent_color_shade, getColor(R.color.accent))
|
||||
};
|
||||
}
|
||||
|
||||
public int getAccentColor() {
|
||||
return getInt(prefApp, R.string.pref_key__accent_color_shade, context.getResources().getColor(R.color.accent));
|
||||
return getInt(prefApp, R.string.pref_key__accent_color_shade, getColor(R.color.accent));
|
||||
}
|
||||
|
||||
public boolean isExtendedNotifications() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.github.dfa.diaspora_android.data;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -280,14 +282,12 @@ public class DiasporaPodList implements Iterable<DiasporaPodList.DiasporaPod>, S
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(DiasporaPod otherPod) {
|
||||
if (otherPod != null) {
|
||||
public int compareTo(@NonNull DiasporaPod otherPod) {
|
||||
List<DiasporaPodUrl> myPodUrls = getPodUrls();
|
||||
List<DiasporaPodUrl> otherPodUrls = otherPod.getPodUrls();
|
||||
if (!myPodUrls.isEmpty() && !otherPodUrls.isEmpty()) {
|
||||
return myPodUrls.get(0).getHost().compareTo(otherPodUrls.get(0).getHost());
|
||||
}
|
||||
}
|
||||
return name.compareTo(otherPod.getName());
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ public class DiasporaPodList implements Iterable<DiasporaPodList.DiasporaPod>, S
|
|||
/**
|
||||
* Get the base url
|
||||
*
|
||||
* @return
|
||||
* @return baseUrl
|
||||
*/
|
||||
public String getBaseUrl() {
|
||||
return protocol + "://" + host + (isPortNeeded() ? port : "");
|
||||
|
|
|
@ -24,21 +24,22 @@ import android.content.ContentProvider;
|
|||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class HashtagProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public int delete(Uri arg0, String arg1, String[] arg2) {
|
||||
public int delete(@NonNull Uri arg0, String arg1, String[] arg2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri arg0) {
|
||||
public String getType(@NonNull Uri arg0) {
|
||||
return "vnd.android.cursor.item/vnd.cc.tag";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri arg0, ContentValues arg1) {
|
||||
public Uri insert(@NonNull Uri arg0, ContentValues arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -48,13 +49,13 @@ public class HashtagProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
|
||||
public Cursor query(@NonNull Uri arg0, String[] arg1, String arg2, String[] arg3,
|
||||
String arg4) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
|
||||
public int update(@NonNull Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -107,9 +107,12 @@ public class BrowserFragment extends ThemedFragment {
|
|||
loadUrl(pendingUrl);
|
||||
pendingUrl = null;
|
||||
}
|
||||
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
webView.setParentActivity(getActivity());
|
||||
|
||||
}
|
||||
});
|
||||
this.setRetainInstance(true);
|
||||
}
|
||||
|
||||
|
@ -149,11 +152,16 @@ public class BrowserFragment extends ThemedFragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (webView != null) {
|
||||
webSettings.setMinimumFontSize(appSettings.getMinimumFontSize());
|
||||
webSettings.setLoadsImagesAutomatically(appSettings.isLoadImages());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
protected boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
|
||||
|
@ -249,16 +257,27 @@ public class BrowserFragment extends ThemedFragment {
|
|||
|
||||
public boolean onBackPressed() {
|
||||
if (webView.canGoBack()) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
webView.goBack();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void loadUrl(String url) {
|
||||
public void loadUrl(final String url) {
|
||||
if (getWebView() != null) {
|
||||
AppLog.v(this, "loadUrl(): load " + url);
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getWebView().loadUrlNew(url);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
AppLog.v(this, "loadUrl(): WebView null: Set pending url to " + url);
|
||||
pendingUrl = url;
|
||||
|
@ -275,10 +294,16 @@ public class BrowserFragment extends ThemedFragment {
|
|||
|
||||
public void reloadUrl() {
|
||||
AppLog.v(this, "reloadUrl()");
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getWebView() != null) {
|
||||
getWebView().reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public ContextMenuWebView getWebView() {
|
||||
return this.webView;
|
||||
|
|
|
@ -22,7 +22,6 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
|
@ -52,7 +51,6 @@ import com.github.dfa.diaspora_android.ui.PodSelectionDialog;
|
|||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
|
|
@ -53,7 +53,7 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
|||
|
||||
AppLog.v(this, "OpenExternalLinkReceiver.onReceive(): url");
|
||||
|
||||
Uri url = null;
|
||||
Uri url;
|
||||
try {
|
||||
String sUrl = receiveIntent.getStringExtra(MainActivity.EXTRA_URL);
|
||||
url = Uri.parse(sUrl);
|
||||
|
|
|
@ -56,7 +56,6 @@ public class StatisticsFetchTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
String extractedProfileData = null;
|
||||
final CookieManager cookieManager = app.getCookieManager();
|
||||
String cookies = cookieManager.getCookie(urls.getPodUrl());
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.graphics.Rect;
|
|||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
@ -67,7 +68,7 @@ public class BadgeDrawable extends Drawable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
if (!shouldDraw) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.app.Dialog;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatDialogFragment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -35,12 +34,13 @@ import butterknife.OnClick;
|
|||
import butterknife.OnItemSelected;
|
||||
|
||||
/**
|
||||
* Dialog that lets the user chose a pod
|
||||
* Created by gsantner (https://gsantner.github.io) on 06.10.16.
|
||||
*/
|
||||
public class PodSelectionDialog extends ThemedAppCompatDialogFragment {
|
||||
public static final String TAG = "com.github.dfa.diaspora_android.PodSelectionDialog";
|
||||
|
||||
public static interface PodSelectionDialogResultListener {
|
||||
public interface PodSelectionDialogResultListener {
|
||||
void onPodSelectionDialogResult(DiasporaPod pod, boolean accepted);
|
||||
}
|
||||
|
||||
|
@ -118,8 +118,8 @@ public class PodSelectionDialog extends ThemedAppCompatDialogFragment {
|
|||
textProfile.setVisibility(View.VISIBLE);
|
||||
spinnerProfile.setVisibility(View.VISIBLE);
|
||||
String[] podUrlss = new String[podUrls.size()];
|
||||
for (int i = 0; i < podUrls.size(); podUrlss[i] = podUrls.get(i++).getBaseUrl()) ;
|
||||
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, podUrlss);
|
||||
//for (int i = 0; i < podUrls.size(); podUrlss[i] = podUrls.get(i++).getBaseUrl()) ;
|
||||
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, podUrlss);
|
||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerProfile.setAdapter(spinnerAdapter);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
|
|||
|
||||
AppLog.d(this, "ShowValueInSummary: "+showValueInSummary + " port: "+appSettings.getProxyHttpPort());
|
||||
setTitleText(titleText);
|
||||
setSummaryText(showValueInSummary ? ""+appSettings.getThemedIntEditTextPreferenceValue(this) : summaryText);
|
||||
setSummaryText(showValueInSummary ? Integer.toString(appSettings.getThemedIntEditTextPreferenceValue(this)) : summaryText);
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -93,7 +93,7 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false);
|
||||
dialogLayout.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
dialogLayout.setText(""+appSettings.getThemedIntEditTextPreferenceValue(this));
|
||||
dialogLayout.setText(Integer.toString(appSettings.getThemedIntEditTextPreferenceValue(this)));
|
||||
builder.setTitle(title)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -140,7 +140,7 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
|
|||
public void setValue(Integer value) {
|
||||
appSettings.setThemedIntEditTextPreferenceValue(this, value);
|
||||
if(showValueInSummary) {
|
||||
setSummaryText(""+value);
|
||||
setSummaryText(Integer.toString(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public class CustomTabActivityHelper {
|
|||
/**
|
||||
* Register a Callback to be called when connected or disconnected from the Custom Tabs Service
|
||||
*
|
||||
* @param connectionCallback
|
||||
* @param connectionCallback connectionCallback
|
||||
*/
|
||||
public void setConnectionCallback(ConnectionCallback connectionCallback) {
|
||||
this.mConnectionCallback = connectionCallback;
|
||||
|
@ -130,10 +130,14 @@ public class CustomTabActivityHelper {
|
|||
}
|
||||
|
||||
public boolean mayLaunchUrl(Uri uri, Bundle extras, List<Bundle> otherLikelyBundles) {
|
||||
if (mClient == null) return false;
|
||||
if (mClient == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomTabsSession session = getSession();
|
||||
if (session == null) return false;
|
||||
if (session == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return session.mayLaunchUrl(uri, extras, otherLikelyBundles);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class Helpers {
|
|||
|
||||
public static String readTextfileFromRawRessource(Context context, int rawRessourceId, String linePrefix, String linePostfix) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = "";
|
||||
String line;
|
||||
BufferedReader br = null;
|
||||
linePrefix = linePrefix == null ? "" : linePrefix;
|
||||
linePostfix = linePostfix == null ? "" : linePostfix;
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.support.v4.graphics.ColorUtils;
|
|||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
/**
|
||||
* ColorPalette
|
||||
* Created by dnld on 24/02/16.
|
||||
*/
|
||||
public class ColorPalette {
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.github.dfa.diaspora_android.util.AppLog;
|
|||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
/**
|
||||
* WebChromeClient for DiasporaStreams
|
||||
* Created by vanitas on 26.09.16.
|
||||
*/
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.webkit.WebView;
|
|||
import android.widget.ProgressBar;
|
||||
|
||||
/**
|
||||
* WebChromeClient that supports uploading images
|
||||
* Created by vanitas on 26.09.16.
|
||||
*/
|
||||
|
||||
|
@ -35,11 +36,6 @@ public class FileUploadWebChromeClient extends ProgressBarWebChromeClient {
|
|||
this.fileUploadCallback = fileUploadCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(WebView wv, int progress) {
|
||||
super.onProgressChanged(wv, progress);
|
||||
}
|
||||
|
||||
//For Android 4.1/4.2 only. DO NOT REMOVE!
|
||||
@SuppressWarnings("unused")
|
||||
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
android:id="@+id/nav_drawer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="110dp"
|
||||
android:background="@color/colorPrimary"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||
|
|
Loading…
Reference in a new issue