Browse Source

Wrap navigate calls with try catch to prevent double click exceptions. Closes austinhuang0131/barinsta#1132, austinhuang0131/barinsta#1150, austinhuang0131/barinsta#1156

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
7658cacbc2
  1. 6
      app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java
  2. 19
      app/src/main/java/awais/instagrabber/fragments/SavedCollectionsFragment.java
  3. 3
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  4. 12
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java

6
app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java

@ -613,7 +613,11 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
bundle.putString("shortCode", media.getCode());
bundle.putString("postId", media.getPk());
bundle.putLong("postUserId", user.getPk());
navController.navigate(R.id.action_global_commentsViewerFragment, bundle);
try {
navController.navigate(R.id.action_global_commentsViewerFragment, bundle);
} catch (Exception e) {
Log.e(TAG, "setupComment: ", e);
}
});
binding.comment.setOnLongClickListener(v -> {
Utils.displayToastAboveView(context, v, getString(R.string.comment));

19
app/src/main/java/awais/instagrabber/fragments/SavedCollectionsFragment.java

@ -41,7 +41,7 @@ import awais.instagrabber.webservices.ServiceCallback;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class SavedCollectionsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "SavedCollectionsFragment";
private static final String TAG = SavedCollectionsFragment.class.getSimpleName();
public static boolean pleaseRefresh = false;
private MainActivity fragmentActivity;
@ -147,13 +147,16 @@ public class SavedCollectionsFragment extends Fragment implements SwipeRefreshLa
if (isSaving) {
setNavControllerResult(navController, topicCluster.getId());
navController.navigateUp();
}
else {
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
.addSharedElement(cover, "collection-" + topicCluster.getId());
final SavedCollectionsFragmentDirections.ActionSavedCollectionsFragmentToCollectionPostsFragment action = SavedCollectionsFragmentDirections
.actionSavedCollectionsFragmentToCollectionPostsFragment(topicCluster, titleColor, backgroundColor);
navController.navigate(action, builder.build());
} else {
try {
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
.addSharedElement(cover, "collection-" + topicCluster.getId());
final SavedCollectionsFragmentDirections.ActionSavedCollectionsFragmentToCollectionPostsFragment action = SavedCollectionsFragmentDirections
.actionSavedCollectionsFragmentToCollectionPostsFragment(topicCluster, titleColor, backgroundColor);
navController.navigate(action, builder.build());
} catch (Exception e) {
Log.e(TAG, "setupTopics: ", e);
}
}
});
binding.topicsRecyclerView.setAdapter(adapter);

3
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -456,7 +456,7 @@ public class StoryViewerFragment extends Fragment {
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
mediaService.fetch(Long.valueOf(mediaId), new ServiceCallback<Media>() {
mediaService.fetch(Long.parseLong(mediaId), new ServiceCallback<Media>() {
@Override
public void onSuccess(final Media feedModel) {
final PostViewV2Fragment fragment = PostViewV2Fragment
@ -1136,7 +1136,6 @@ public class StoryViewerFragment extends Fragment {
});
}
private void openProfile(final String username) {
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar != null) {

12
app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java

@ -139,7 +139,11 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
if (item.getItemId() == R.id.pending_requests) {
final NavDirections directions = DirectMessageInboxFragmentDirections.actionInboxToPendingInbox();
NavHostFragment.findNavController(this).navigate(directions);
try {
NavHostFragment.findNavController(this).navigate(directions);
} catch (Exception e) {
Log.e(TAG, "onOptionsItemSelected: ", e);
}
return true;
}
return super.onOptionsItemSelected(item);
@ -251,7 +255,11 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
if (isAdded()) {
final DirectMessageInboxFragmentDirections.ActionInboxToThread directions = DirectMessageInboxFragmentDirections
.actionInboxToThread(thread.getThreadId(), thread.getThreadTitle());
NavHostFragment.findNavController(this).navigate(directions);
try {
NavHostFragment.findNavController(this).navigate(directions);
} catch (Exception e) {
Log.e(TAG, "init: ", e);
}
}
navigating = false;
});

Loading…
Cancel
Save