From d2e3f6c4df5dbf863261fa85fe2043548932eadd Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 31 Dec 2020 12:43:56 -0500 Subject: [PATCH] fix story notifications --- .../dialogs/ProfilePicDialogFragment.java | 24 +----- .../NotificationsViewerFragment.java | 19 ++--- .../fragments/StoryViewerFragment.java | 73 +++++++++++++------ .../notification_viewer_nav_graph.xml | 36 +++++++++ 4 files changed, 92 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java b/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java index 1e75eba4..91779710 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java +++ b/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java @@ -43,7 +43,6 @@ import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.TextUtils; import awais.instagrabber.webservices.ProfileService; import awais.instagrabber.webservices.ServiceCallback; -import awais.instagrabber.webservices.StoriesService; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -104,8 +103,7 @@ public class ProfilePicDialogFragment extends DialogFragment { public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); init(); - if (id.contains("_")) fetchStory(); - else fetchAvatar(); + fetchAvatar(); } private void init() { @@ -150,26 +148,6 @@ public class ProfilePicDialogFragment extends DialogFragment { else new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - private void fetchStory() { - final StoriesService storiesService = StoriesService.getInstance(); - storiesService.fetch(id, new ServiceCallback() { - @Override - public void onSuccess(final StoryModel result) { - if (result != null) { - fetchListener.onResult(result.getStoryUrl()); - } - } - - @Override - public void onFailure(final Throwable t) { - final Context context = getContext(); - Log.d("austin_debug", "error", t); - Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - getDialog().dismiss(); - } - }); - } - private void setupPhoto() { if (TextUtils.isEmpty(url)) { url = fallbackUrl; diff --git a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java index 2eb9406d..56895648 100644 --- a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java @@ -75,7 +75,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe @Override public void onPreviewClick(final NotificationModel model) { if (model.getType() == NotificationType.RESPONDED_STORY) { - showProfilePicDialog(model); + final NavDirections action = NotificationsViewerFragmentDirections.actionNotificationsViewerFragmentToStoryViewerFragment( + -1, null, false, false, model.getPostId(), model.getUsername(), false); + NavHostFragment.findNavController(NotificationsViewerFragment.this).navigate(action); } else { mediaService.fetch(model.getPostId(), new ServiceCallback() { @@ -151,7 +153,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe return; } else if (model.getType() == NotificationType.RESPONDED_STORY) { - showProfilePicDialog(model); + final NavDirections action = NotificationsViewerFragmentDirections.actionNotificationsViewerFragmentToStoryViewerFragment( + -1, null, false, false, model.getPostId(), model.getUsername(), false); + NavHostFragment.findNavController(NotificationsViewerFragment.this).navigate(action); return; } final AlertDialog alertDialog = new AlertDialog.Builder(context) @@ -292,15 +296,4 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe .actionGlobalProfileFragment("@" + username); NavHostFragment.findNavController(this).navigate(action); } - - private void showProfilePicDialog(final NotificationModel model) { - final FragmentManager fragmentManager = getParentFragmentManager(); - final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(model.getPostId(), - model.getUsername(), - model.getPreviewPic()); - final FragmentTransaction ft = fragmentManager.beginTransaction(); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) - .add(fragment, "profilePicDialog") - .commit(); - } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 2f513b07..6c8f39f9 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -74,6 +74,7 @@ import awais.instagrabber.asyncs.direct_messages.CreateThreadAction; import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.FragmentStoryViewerBinding; +import awais.instagrabber.fragments.main.FeedFragment; import awais.instagrabber.fragments.main.ProfileFragmentDirections; import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.models.FeedStoryModel; @@ -692,33 +693,57 @@ public class StoryViewerFragment extends Fragment { } storiesViewModel.getList().setValue(Collections.emptyList()); if (currentStoryMediaId == null) return; - final ServiceCallback> storyCallback = new ServiceCallback>() { - @Override - public void onSuccess(final List storyModels) { - fetching = false; - if (storyModels == null || storyModels.isEmpty()) { - storiesViewModel.getList().setValue(Collections.emptyList()); - currentStory = null; + else if (currentFeedStoryIndex == -1) { + storiesService.fetch(currentStoryMediaId, new ServiceCallback() { + @Override + public void onSuccess(final StoryModel storyModel) { + fetching = false; binding.storiesList.setVisibility(View.GONE); - return; + if (storyModel == null) { + storiesViewModel.getList().setValue(Collections.emptyList()); + currentStory = null; + return; + } + storiesViewModel.getList().setValue(Collections.singletonList(storyModel)); + currentStory = storyModel; + refreshStory(); } - binding.storiesList.setVisibility(View.VISIBLE); - storiesViewModel.getList().setValue(storyModels); - currentStory = storyModels.get(0); - refreshStory(); - } - @Override - public void onFailure(final Throwable t) { - Log.e(TAG, "Error", t); - } - }; - storiesService.getUserStory(currentStoryMediaId, - currentStoryUsername, - isLoc, - isHashtag, - isHighlight, - storyCallback); + @Override + public void onFailure(final Throwable t) { + Log.e(TAG, "Error", t); + } + }); + } + else { + final ServiceCallback> storyCallback = new ServiceCallback>() { + @Override + public void onSuccess(final List storyModels) { + fetching = false; + if (storyModels == null || storyModels.isEmpty()) { + storiesViewModel.getList().setValue(Collections.emptyList()); + currentStory = null; + binding.storiesList.setVisibility(View.GONE); + return; + } + binding.storiesList.setVisibility(View.VISIBLE); + storiesViewModel.getList().setValue(storyModels); + currentStory = storyModels.get(0); + refreshStory(); + } + + @Override + public void onFailure(final Throwable t) { + Log.e(TAG, "Error", t); + } + }; + storiesService.getUserStory(currentStoryMediaId, + currentStoryUsername, + isLoc, + isHashtag, + isHighlight, + storyCallback); + } } private void refreshStory() { diff --git a/app/src/main/res/navigation/notification_viewer_nav_graph.xml b/app/src/main/res/navigation/notification_viewer_nav_graph.xml index eb5b18a4..9f25e79e 100644 --- a/app/src/main/res/navigation/notification_viewer_nav_graph.xml +++ b/app/src/main/res/navigation/notification_viewer_nav_graph.xml @@ -14,6 +14,9 @@ android:name="type" app:argType="string" app:nullable="false" /> + + + + + + + + + + + \ No newline at end of file