Fixing crashes resulting from fragment lifecycle mismanagement
This commit is contained in:
parent
5f222e2d5b
commit
c8a2fd8262
@ -5,6 +5,7 @@ package acr.browser.lightning.fragment;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@ -61,6 +62,8 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
||||
@Nullable private Activity mActivity;
|
||||
|
||||
@Inject BookmarkModel mBookmarkManager;
|
||||
@Inject Application mApplication;
|
||||
|
||||
private File[] mFileList;
|
||||
private String[] mFileNameList;
|
||||
@Nullable private BookmarkLocalSync mSync;
|
||||
@ -454,7 +457,12 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
||||
@Override
|
||||
public void onError(@NonNull Throwable throwable) {
|
||||
Log.e(TAG, "onError: importing bookmarks", throwable);
|
||||
Utils.createInformativeDialog(getActivity(), R.string.title_error, R.string.import_bookmark_error);
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
Utils.createInformativeDialog(activity, R.string.title_error, R.string.import_bookmark_error);
|
||||
} else {
|
||||
Utils.showToast(mApplication, R.string.import_bookmark_error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -233,12 +233,16 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
@Override
|
||||
public void onItem(@Nullable Boolean item) {
|
||||
Preconditions.checkNonNull(item);
|
||||
Activity activity = getActivity();
|
||||
if (mBookmarkImage == null || activity == null) {
|
||||
return;
|
||||
}
|
||||
if (!item) {
|
||||
mBookmarkImage.setImageResource(R.drawable.ic_action_star);
|
||||
mBookmarkImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
mBookmarkImage.setImageResource(R.drawable.ic_bookmark);
|
||||
mBookmarkImage.setColorFilter(ThemeUtils.getAccentColor(getContext()), PorterDuff.Mode.SRC_IN);
|
||||
mBookmarkImage.setColorFilter(ThemeUtils.getAccentColor(activity), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -34,6 +34,7 @@ import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.anthonycr.grant.PermissionsManager;
|
||||
import com.anthonycr.grant.PermissionsResultAction;
|
||||
@ -175,6 +176,18 @@ public final class Utils {
|
||||
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a toast to the user.
|
||||
* Should only be used if an activity is
|
||||
* not available to show a snackbar.
|
||||
*
|
||||
* @param context the context needed to show the toast.
|
||||
* @param resource the string shown by the toast to the user.
|
||||
*/
|
||||
public static void showToast(@NonNull Context context, @StringRes int resource) {
|
||||
Toast.makeText(context, resource, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Density Pixels (DP) to Pixels (PX).
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user