mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-26 08:37:29 +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.adapters.viewholder.TopicClusterViewHolder;
|
||||||
import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
|
import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
|
||||||
import awais.instagrabber.repositories.responses.discover.TopicCluster;
|
import awais.instagrabber.repositories.responses.discover.TopicCluster;
|
||||||
|
import awais.instagrabber.repositories.responses.Media;
|
||||||
import awais.instagrabber.utils.ResponseBodyUtils;
|
import awais.instagrabber.utils.ResponseBodyUtils;
|
||||||
|
|
||||||
public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> {
|
public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> {
|
||||||
@ -50,6 +51,8 @@ public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicCluste
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface OnTopicClickListener {
|
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) {
|
if (onTopicClickListener != null) {
|
||||||
itemView.setOnClickListener(v -> onTopicClickListener.onTopicClick(
|
itemView.setOnClickListener(v -> onTopicClickListener.onTopicClick(
|
||||||
topicCluster,
|
topicCluster,
|
||||||
binding.getRoot(),
|
|
||||||
binding.cover,
|
binding.cover,
|
||||||
binding.title,
|
|
||||||
titleColor.get(),
|
titleColor.get(),
|
||||||
backgroundColor.get()
|
backgroundColor.get()
|
||||||
));
|
));
|
||||||
|
itemView.setOnLongClickListener(v -> {
|
||||||
|
onTopicClickListener.onTopicLongClick(topicCluster.getCoverMedia());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// binding.title.setTransitionName("title-" + topicCluster.getId());
|
// binding.title.setTransitionName("title-" + topicCluster.getId());
|
||||||
binding.cover.setTransitionName("cover-" + topicCluster.getId());
|
binding.cover.setTransitionName("cover-" + topicCluster.getId());
|
||||||
|
@ -5,12 +5,15 @@ import android.util.Log;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
import androidx.navigation.fragment.FragmentNavigator;
|
import androidx.navigation.fragment.FragmentNavigator;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
@ -18,15 +21,19 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.activities.MainActivity;
|
import awais.instagrabber.activities.MainActivity;
|
||||||
import awais.instagrabber.adapters.DiscoverTopicsAdapter;
|
import awais.instagrabber.adapters.DiscoverTopicsAdapter;
|
||||||
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
|
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
|
||||||
import awais.instagrabber.databinding.FragmentDiscoverBinding;
|
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.TopicCluster;
|
||||||
import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse;
|
import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
import awais.instagrabber.viewmodels.TopicClusterViewModel;
|
import awais.instagrabber.viewmodels.TopicClusterViewModel;
|
||||||
import awais.instagrabber.webservices.DiscoverService;
|
import awais.instagrabber.webservices.DiscoverService;
|
||||||
|
import awais.instagrabber.webservices.MediaService;
|
||||||
import awais.instagrabber.webservices.ServiceCallback;
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
|
|
||||||
public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||||
@ -38,12 +45,14 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
private TopicClusterViewModel topicClusterViewModel;
|
private TopicClusterViewModel topicClusterViewModel;
|
||||||
private boolean shouldRefresh = true;
|
private boolean shouldRefresh = true;
|
||||||
private DiscoverService discoverService;
|
private DiscoverService discoverService;
|
||||||
|
private MediaService mediaService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
fragmentActivity = (MainActivity) requireActivity();
|
fragmentActivity = (MainActivity) requireActivity();
|
||||||
discoverService = DiscoverService.getInstance();
|
discoverService = DiscoverService.getInstance();
|
||||||
|
mediaService = MediaService.getInstance(null, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,13 +89,47 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
public void setupTopics() {
|
public void setupTopics() {
|
||||||
topicClusterViewModel = new ViewModelProvider(fragmentActivity).get(TopicClusterViewModel.class);
|
topicClusterViewModel = new ViewModelProvider(fragmentActivity).get(TopicClusterViewModel.class);
|
||||||
binding.topicsRecyclerView.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(2)));
|
binding.topicsRecyclerView.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(2)));
|
||||||
final DiscoverTopicsAdapter adapter = new DiscoverTopicsAdapter((topicCluster, root, cover, title, titleColor, backgroundColor) -> {
|
final DiscoverTopicsAdapter.OnTopicClickListener otcl = new DiscoverTopicsAdapter.OnTopicClickListener() {
|
||||||
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
|
public void onTopicClick(final TopicCluster topicCluster, final View cover, final int titleColor, final int backgroundColor) {
|
||||||
.addSharedElement(cover, "cover-" + topicCluster.getId());
|
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
|
||||||
final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections
|
.addSharedElement(cover, "cover-" + topicCluster.getId());
|
||||||
.actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor);
|
final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections
|
||||||
NavHostFragment.findNavController(this).navigate(action, builder.build());
|
.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);
|
binding.topicsRecyclerView.setAdapter(adapter);
|
||||||
topicClusterViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
|
topicClusterViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user