From ccfaa1c3974e11a04469a328e95e43fd76d5aa7a Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 7 Sep 2020 22:44:56 +0900 Subject: [PATCH] Open post from dm thread and handle ig links properly from within the app --- .../instagrabber/activities/MainActivity.java | 6 ++++++ .../DirectMessageThreadFragment.java | 16 ++++++++++++---- .../res/navigation/direct_messages_nav_graph.xml | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 787d3b99..1efb8e79 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -157,6 +157,12 @@ public class MainActivity extends BaseLanguageActivity { return false; } + @Override + protected void onNewIntent(final Intent intent) { + super.onNewIntent(intent); + handleIntent(intent); + } + private void setupSuggestions() { suggestionsFetchHandler = new Handler(); suggestionAdapter = new SuggestionsAdapter(this, (type, query) -> { diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index 8a5c8196..8c223566 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -29,6 +29,7 @@ import androidx.fragment.app.Fragment; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; +import androidx.navigation.NavController; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; import androidx.recyclerview.widget.LinearLayoutManager; @@ -223,11 +224,18 @@ public class DirectMessageThreadFragment extends Fragment { case CLIP: final long postId = directItemModel.getMediaModel().getPk(); final boolean isId = true; - // startActivity(new Intent(requireContext(), PostViewer.class) - // .putExtra(Constants.EXTRAS_POST, new PostModel(postId, false))); + final NavController navController = NavHostFragment.findNavController(this); + final NavDirections action = DirectMessageThreadFragmentDirections + .actionGlobalPostViewFragment( + 0, + new String[]{String.valueOf(postId)}, + isId + ); + navController.navigate(action); break; case LINK: Intent linkIntent = new Intent(Intent.ACTION_VIEW); + linkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP); linkIntent.setData(Uri.parse(directItemModel.getLinkModel().getLinkContext().getLinkUrl())); startActivity(linkIntent); break; @@ -545,8 +553,8 @@ public class DirectMessageThreadFragment extends Fragment { wr.close(); urlConnection.connect(); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { - if (action == "delete") hasDeletedSomething = true; - else if (action == "seen") DirectMessageInboxFragment.refreshPlease = true; + if (action.equals("delete")) hasDeletedSomething = true; + else if (action.equals("seen")) DirectMessageInboxFragment.refreshPlease = true; } urlConnection.disconnect(); } catch (Throwable ex) { diff --git a/app/src/main/res/navigation/direct_messages_nav_graph.xml b/app/src/main/res/navigation/direct_messages_nav_graph.xml index 11903a11..33fd3bfa 100644 --- a/app/src/main/res/navigation/direct_messages_nav_graph.xml +++ b/app/src/main/res/navigation/direct_messages_nav_graph.xml @@ -38,6 +38,22 @@ app:nullable="false" /> + + + + + + + +