mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 21:36:59 +00:00
Nested navigation using global actions
Using a workaround for including global actions. This may change in the future releases of Navigation lib
This commit is contained in:
parent
649115a665
commit
8f1a158b92
@ -289,7 +289,7 @@ public class HashTagFragment extends Fragment {
|
|||||||
private void setTitle() {
|
private void setTitle() {
|
||||||
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setTitle(hashtag.substring(1));
|
actionBar.setTitle(hashtag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ public class DirectMessageThreadFragment extends Fragment {
|
|||||||
|
|
||||||
private void searchUsername(final String text) {
|
private void searchUsername(final String text) {
|
||||||
// startActivity(new Intent(requireContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text));
|
// startActivity(new Intent(requireContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text));
|
||||||
final NavDirections action = DirectMessageThreadFragmentDirections.actionDirectMessagesThreadFragmentToProfileFragment("@" + text);
|
final NavDirections action = DirectMessageThreadFragmentDirections.actionGlobalProfileFragment("@" + text);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,55 +152,9 @@ public class FeedFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private final MentionClickListener mentionClickListener = (view, text, isHashtag, isLocation) -> {
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
fragmentActivity = (MainActivity) requireActivity();
|
|
||||||
storiesService = StoriesService.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
||||||
final ViewGroup container,
|
|
||||||
final Bundle savedInstanceState) {
|
|
||||||
if (root != null) {
|
|
||||||
shouldRefresh = false;
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
binding = FragmentFeedBinding.inflate(inflater, container, false);
|
|
||||||
root = binding.getRoot();
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
|
||||||
if (!shouldRefresh) return;
|
|
||||||
// setupActionBar();
|
|
||||||
setupFeedStories();
|
|
||||||
setupFeed();
|
|
||||||
shouldRefresh = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
if (videoAwareRecyclerScroller != null) {
|
|
||||||
videoAwareRecyclerScroller.stopPlaying();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
if (videoAwareRecyclerScroller != null && SHOULD_AUTO_PLAY) {
|
|
||||||
videoAwareRecyclerScroller.startPlaying();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final MentionClickListener mentionClickListener = (view, text, isHashtag, isLocation) -> {
|
|
||||||
if (isHashtag) {
|
if (isHashtag) {
|
||||||
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToHashTagFragment(text);
|
final NavDirections action = FeedFragmentDirections.actionGlobalHashTagFragment(text);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -209,10 +163,9 @@ public class FeedFragment extends Fragment {
|
|||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToProfileFragment("@" + text);
|
final NavDirections action = FeedFragmentDirections.actionGlobalProfileFragment("@" + text);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
};
|
};
|
||||||
|
|
||||||
private final View.OnClickListener postViewClickListener = v -> {
|
private final View.OnClickListener postViewClickListener = v -> {
|
||||||
final Object tag = v.getTag();
|
final Object tag = v.getTag();
|
||||||
if (!(tag instanceof FeedModel)) return;
|
if (!(tag instanceof FeedModel)) return;
|
||||||
@ -293,6 +246,51 @@ public class FeedFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
fragmentActivity = (MainActivity) requireActivity();
|
||||||
|
storiesService = StoriesService.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
||||||
|
final ViewGroup container,
|
||||||
|
final Bundle savedInstanceState) {
|
||||||
|
if (root != null) {
|
||||||
|
shouldRefresh = false;
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
binding = FragmentFeedBinding.inflate(inflater, container, false);
|
||||||
|
root = binding.getRoot();
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
||||||
|
if (!shouldRefresh) return;
|
||||||
|
// setupActionBar();
|
||||||
|
setupFeedStories();
|
||||||
|
setupFeed();
|
||||||
|
shouldRefresh = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
if (videoAwareRecyclerScroller != null) {
|
||||||
|
videoAwareRecyclerScroller.stopPlaying();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (videoAwareRecyclerScroller != null && SHOULD_AUTO_PLAY) {
|
||||||
|
videoAwareRecyclerScroller.startPlaying();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setupFeed() {
|
private void setupFeed() {
|
||||||
feedViewModel = new ViewModelProvider(fragmentActivity).get(FeedViewModel.class);
|
feedViewModel = new ViewModelProvider(fragmentActivity).get(FeedViewModel.class);
|
||||||
final LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
|
final LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
|
||||||
|
@ -29,6 +29,8 @@ import androidx.core.content.ContextCompat;
|
|||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.NavDirections;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -54,6 +56,7 @@ import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
|
|||||||
import awais.instagrabber.databinding.FragmentProfileBinding;
|
import awais.instagrabber.databinding.FragmentProfileBinding;
|
||||||
import awais.instagrabber.fragments.main.viewmodels.PostsViewModel;
|
import awais.instagrabber.fragments.main.viewmodels.PostsViewModel;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
|
import awais.instagrabber.interfaces.MentionClickListener;
|
||||||
import awais.instagrabber.models.PostModel;
|
import awais.instagrabber.models.PostModel;
|
||||||
import awais.instagrabber.models.ProfileModel;
|
import awais.instagrabber.models.ProfileModel;
|
||||||
import awais.instagrabber.models.StoryModel;
|
import awais.instagrabber.models.StoryModel;
|
||||||
@ -109,9 +112,7 @@ public class ProfileFragment extends Fragment {
|
|||||||
remove();
|
remove();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final PrimaryActionModeCallback multiSelectAction = new PrimaryActionModeCallback(
|
private final PrimaryActionModeCallback multiSelectAction = new PrimaryActionModeCallback(R.menu.multi_select_download_menu, new CallbacksHelper() {
|
||||||
R.menu.multi_select_download_menu,
|
|
||||||
new CallbacksHelper() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(final ActionMode mode) {
|
public void onDestroy(final ActionMode mode) {
|
||||||
onBackPressedCallback.handleOnBackPressed();
|
onBackPressedCallback.handleOnBackPressed();
|
||||||
@ -159,6 +160,21 @@ public class ProfileFragment extends Fragment {
|
|||||||
binding.privatePage.setVisibility(View.VISIBLE);
|
binding.privatePage.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private final MentionClickListener mentionClickListener = (view, text, isHashtag, isLocation) -> {
|
||||||
|
Log.d(TAG, "action...");
|
||||||
|
if (isHashtag) {
|
||||||
|
final NavDirections action = ProfileFragmentDirections.actionGlobalHashTagFragment(text);
|
||||||
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isLocation) {
|
||||||
|
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToLocationFragment(text);
|
||||||
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final NavDirections action = ProfileFragmentDirections.actionGlobalProfileFragment("@" + text);
|
||||||
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
@ -409,7 +425,7 @@ public class ProfileFragment extends Fragment {
|
|||||||
if (Utils.hasMentions(biography)) {
|
if (Utils.hasMentions(biography)) {
|
||||||
biography = Utils.getMentionText(biography);
|
biography = Utils.getMentionText(biography);
|
||||||
binding.mainBiography.setText(biography, TextView.BufferType.SPANNABLE);
|
binding.mainBiography.setText(biography, TextView.BufferType.SPANNABLE);
|
||||||
// binding.mainBiography.setMentionClickListener(mentionClickListener);
|
binding.mainBiography.setMentionClickListener(mentionClickListener);
|
||||||
} else {
|
} else {
|
||||||
binding.mainBiography.setText(biography);
|
binding.mainBiography.setText(biography);
|
||||||
binding.mainBiography.setMentionClickListener(null);
|
binding.mainBiography.setMentionClickListener(null);
|
||||||
@ -596,7 +612,6 @@ public class ProfileFragment extends Fragment {
|
|||||||
.putExtra(Constants.EXTRAS_INDEX, "%" + profileModel.getId())
|
.putExtra(Constants.EXTRAS_INDEX, "%" + profileModel.getId())
|
||||||
.putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername())
|
.putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername())
|
||||||
));
|
));
|
||||||
// binding.btnFollowTag.setOnClickListener(profileActionListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUsernameDelayed() {
|
private void setUsernameDelayed() {
|
||||||
|
@ -5,6 +5,17 @@
|
|||||||
android:id="@+id/direct_messages_nav_graph"
|
android:id="@+id/direct_messages_nav_graph"
|
||||||
app:startDestination="@id/directMessagesInboxFragment">
|
app:startDestination="@id/directMessagesInboxFragment">
|
||||||
|
|
||||||
|
<include app:graph="@navigation/profile_nav_graph" />
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_profileFragment"
|
||||||
|
app:destination="@id/profile_nav_graph">
|
||||||
|
<argument
|
||||||
|
android:name="username"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</action>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/directMessagesInboxFragment"
|
android:id="@+id/directMessagesInboxFragment"
|
||||||
android:name="awais.instagrabber.fragments.directmessages.DirectMessageInboxFragment"
|
android:name="awais.instagrabber.fragments.directmessages.DirectMessageInboxFragment"
|
||||||
@ -28,9 +39,6 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_dMThreadFragment_to_dMSettingsFragment"
|
android:id="@+id/action_dMThreadFragment_to_dMSettingsFragment"
|
||||||
app:destination="@id/directMessagesSettingsFragment" />
|
app:destination="@id/directMessagesSettingsFragment" />
|
||||||
<action
|
|
||||||
android:id="@+id/action_directMessagesThreadFragment_to_profileFragment"
|
|
||||||
app:destination="@id/profileFragment" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/directMessagesSettingsFragment"
|
android:id="@+id/directMessagesSettingsFragment"
|
||||||
@ -44,14 +52,4 @@
|
|||||||
android:name="title"
|
android:name="title"
|
||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
|
||||||
android:id="@+id/profileFragment"
|
|
||||||
android:name="awais.instagrabber.fragments.main.ProfileFragment"
|
|
||||||
android:label="ProfileFragment"
|
|
||||||
tools:layout="@layout/fragment_profile">
|
|
||||||
<argument
|
|
||||||
android:name="username"
|
|
||||||
app:argType="string"
|
|
||||||
app:nullable="false" />
|
|
||||||
</fragment>
|
|
||||||
</navigation>
|
</navigation>
|
@ -5,6 +5,28 @@
|
|||||||
android:id="@+id/feed_nav_graph"
|
android:id="@+id/feed_nav_graph"
|
||||||
app:startDestination="@id/feedFragment">
|
app:startDestination="@id/feedFragment">
|
||||||
|
|
||||||
|
<include app:graph="@navigation/hashtag_nav_graph" />
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_hashTagFragment"
|
||||||
|
app:destination="@id/hashtag_nav_graph">
|
||||||
|
<argument
|
||||||
|
android:name="hashtag"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</action>
|
||||||
|
|
||||||
|
<include app:graph="@navigation/profile_nav_graph" />
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_profileFragment"
|
||||||
|
app:destination="@id/profile_nav_graph">
|
||||||
|
<argument
|
||||||
|
android:name="username"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</action>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/feedFragment"
|
android:id="@+id/feedFragment"
|
||||||
android:name="awais.instagrabber.fragments.main.FeedFragment"
|
android:name="awais.instagrabber.fragments.main.FeedFragment"
|
||||||
@ -13,12 +35,6 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_feedFragment_to_storyViewerFragment"
|
android:id="@+id/action_feedFragment_to_storyViewerFragment"
|
||||||
app:destination="@id/storyViewerFragment" />
|
app:destination="@id/storyViewerFragment" />
|
||||||
<action
|
|
||||||
android:id="@+id/action_feedFragment_to_profileFragment"
|
|
||||||
app:destination="@id/profileFragment" />
|
|
||||||
<action
|
|
||||||
android:id="@+id/action_feedFragment_to_hashTagFragment"
|
|
||||||
app:destination="@id/hashTagFragment" />
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_feedFragment_to_locationFragment"
|
android:id="@+id/action_feedFragment_to_locationFragment"
|
||||||
app:destination="@id/locationFragment" />
|
app:destination="@id/locationFragment" />
|
||||||
@ -40,26 +56,6 @@
|
|||||||
android:name="isHashtag"
|
android:name="isHashtag"
|
||||||
app:argType="boolean" />
|
app:argType="boolean" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
|
||||||
android:id="@+id/profileFragment"
|
|
||||||
android:name="awais.instagrabber.fragments.main.ProfileFragment"
|
|
||||||
android:label="ProfileFragment"
|
|
||||||
tools:layout="@layout/fragment_profile">
|
|
||||||
<argument
|
|
||||||
android:name="username"
|
|
||||||
app:argType="string"
|
|
||||||
app:nullable="false" />
|
|
||||||
</fragment>
|
|
||||||
<fragment
|
|
||||||
android:id="@+id/hashTagFragment"
|
|
||||||
android:name="awais.instagrabber.fragments.HashTagFragment"
|
|
||||||
android:label=""
|
|
||||||
tools:layout="@layout/fragment_hashtag">
|
|
||||||
<argument
|
|
||||||
android:name="hashtag"
|
|
||||||
app:argType="string"
|
|
||||||
app:nullable="false" />
|
|
||||||
</fragment>
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/locationFragment"
|
android:id="@+id/locationFragment"
|
||||||
android:name="awais.instagrabber.fragments.LocationFragment"
|
android:name="awais.instagrabber.fragments.LocationFragment"
|
||||||
|
25
app/src/main/res/navigation/hashtag_nav_graph.xml
Normal file
25
app/src/main/res/navigation/hashtag_nav_graph.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/hashtag_nav_graph"
|
||||||
|
app:startDestination="@id/hashTagFragment">
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/hashTagFragment"
|
||||||
|
android:name="awais.instagrabber.fragments.HashTagFragment"
|
||||||
|
android:label=""
|
||||||
|
tools:layout="@layout/fragment_hashtag">
|
||||||
|
<argument
|
||||||
|
android:name="hashtag"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</fragment>
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_hashTagFragment"
|
||||||
|
app:destination="@id/hashTagFragment">
|
||||||
|
<argument
|
||||||
|
android:name="hashtag"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</action>
|
||||||
|
</navigation>
|
@ -4,9 +4,38 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/profile_nav_graph"
|
android:id="@+id/profile_nav_graph"
|
||||||
app:startDestination="@id/profileFragment">
|
app:startDestination="@id/profileFragment">
|
||||||
|
|
||||||
|
<include app:graph="@navigation/hashtag_nav_graph" />
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_hashTagFragment"
|
||||||
|
app:destination="@id/hashtag_nav_graph">
|
||||||
|
<argument
|
||||||
|
android:name="hashtag"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</action>
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_profileFragment"
|
||||||
|
app:destination="@id/profileFragment">
|
||||||
|
<argument
|
||||||
|
android:name="username"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
</action>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/profileFragment"
|
android:id="@+id/profileFragment"
|
||||||
android:name="awais.instagrabber.fragments.main.ProfileFragment"
|
android:name="awais.instagrabber.fragments.main.ProfileFragment"
|
||||||
android:label="@string/profile"
|
android:label="@string/profile"
|
||||||
tools:layout="@layout/fragment_profile" />
|
tools:layout="@layout/fragment_profile" >
|
||||||
|
<argument
|
||||||
|
android:name="username"
|
||||||
|
app:argType="string"
|
||||||
|
app:nullable="false" />
|
||||||
|
<!--<action-->
|
||||||
|
<!-- android:id="@+id/action_profileFragment_self"-->
|
||||||
|
<!-- app:destination="@id/profileFragment" />-->
|
||||||
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
Loading…
Reference in New Issue
Block a user