mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
long-clicking a discover topic should now show cover post
This commit is contained in:
parent
f4d1575edb
commit
d5e75d16c3
@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter;
|
||||
import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder;
|
||||
import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
|
||||
import awais.instagrabber.repositories.responses.discover.TopicCluster;
|
||||
import awais.instagrabber.repositories.responses.Media;
|
||||
import awais.instagrabber.utils.ResponseBodyUtils;
|
||||
|
||||
public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> {
|
||||
@ -50,6 +51,8 @@ public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicCluste
|
||||
}
|
||||
|
||||
public interface OnTopicClickListener {
|
||||
void onTopicClick(TopicCluster topicCluster, View root, View cover, View title, int titleColor, int backgroundColor);
|
||||
void onTopicClick(TopicCluster topicCluster, View cover, int titleColor, int backgroundColor);
|
||||
|
||||
void onTopicLongClick(Media coverMedia);
|
||||
}
|
||||
}
|
||||
|
@ -54,12 +54,14 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder {
|
||||
if (onTopicClickListener != null) {
|
||||
itemView.setOnClickListener(v -> onTopicClickListener.onTopicClick(
|
||||
topicCluster,
|
||||
binding.getRoot(),
|
||||
binding.cover,
|
||||
binding.title,
|
||||
titleColor.get(),
|
||||
backgroundColor.get()
|
||||
));
|
||||
itemView.setOnLongClickListener(v -> {
|
||||
onTopicClickListener.onTopicLongClick(topicCluster.getCoverMedia());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
// binding.title.setTransitionName("title-" + topicCluster.getId());
|
||||
binding.cover.setTransitionName("cover-" + topicCluster.getId());
|
||||
|
@ -5,12 +5,15 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.fragment.FragmentNavigator;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
@ -18,15 +21,19 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.activities.MainActivity;
|
||||
import awais.instagrabber.adapters.DiscoverTopicsAdapter;
|
||||
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
|
||||
import awais.instagrabber.databinding.FragmentDiscoverBinding;
|
||||
import awais.instagrabber.fragments.PostViewV2Fragment;
|
||||
import awais.instagrabber.repositories.responses.Media;
|
||||
import awais.instagrabber.repositories.responses.discover.TopicCluster;
|
||||
import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
import awais.instagrabber.viewmodels.TopicClusterViewModel;
|
||||
import awais.instagrabber.webservices.DiscoverService;
|
||||
import awais.instagrabber.webservices.MediaService;
|
||||
import awais.instagrabber.webservices.ServiceCallback;
|
||||
|
||||
public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
@ -38,12 +45,14 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||
private TopicClusterViewModel topicClusterViewModel;
|
||||
private boolean shouldRefresh = true;
|
||||
private DiscoverService discoverService;
|
||||
private MediaService mediaService;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
fragmentActivity = (MainActivity) requireActivity();
|
||||
discoverService = DiscoverService.getInstance();
|
||||
mediaService = MediaService.getInstance(null, null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,13 +89,47 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||
public void setupTopics() {
|
||||
topicClusterViewModel = new ViewModelProvider(fragmentActivity).get(TopicClusterViewModel.class);
|
||||
binding.topicsRecyclerView.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(2)));
|
||||
final DiscoverTopicsAdapter adapter = new DiscoverTopicsAdapter((topicCluster, root, cover, title, titleColor, backgroundColor) -> {
|
||||
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
|
||||
.addSharedElement(cover, "cover-" + topicCluster.getId());
|
||||
final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections
|
||||
.actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor);
|
||||
NavHostFragment.findNavController(this).navigate(action, builder.build());
|
||||
});
|
||||
final DiscoverTopicsAdapter.OnTopicClickListener otcl = new DiscoverTopicsAdapter.OnTopicClickListener() {
|
||||
public void onTopicClick(final TopicCluster topicCluster, final View cover, final int titleColor, final int backgroundColor) {
|
||||
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
|
||||
.addSharedElement(cover, "cover-" + topicCluster.getId());
|
||||
final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections
|
||||
.actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor);
|
||||
NavHostFragment.findNavController(DiscoverFragment.this).navigate(action, builder.build());
|
||||
}
|
||||
|
||||
public void onTopicLongClick(final Media coverMedia) {
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(requireContext())
|
||||
.setCancelable(false)
|
||||
.setView(R.layout.dialog_opening_post)
|
||||
.create();
|
||||
alertDialog.show();
|
||||
mediaService.fetch(Long.valueOf(coverMedia.getPk()), new ServiceCallback<Media>() {
|
||||
@Override
|
||||
public void onSuccess(final Media feedModel) {
|
||||
final NavController navController = NavHostFragment.findNavController(DiscoverFragment.this);
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel);
|
||||
try {
|
||||
navController.navigate(R.id.action_global_post_view, bundle);
|
||||
alertDialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onSuccess: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable t) {
|
||||
alertDialog.dismiss();
|
||||
try {
|
||||
Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
catch (Throwable e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
final DiscoverTopicsAdapter adapter = new DiscoverTopicsAdapter(otcl);
|
||||
binding.topicsRecyclerView.setAdapter(adapter);
|
||||
topicClusterViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user