From 4efd2cb6ace0497815e20a91b6d86a0d3d59a469 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 6 Sep 2020 03:34:16 +0900 Subject: [PATCH] Add highlights back to ProfileFragment --- .../adapters/FeedStoriesAdapter.java | 10 +-- .../adapters/HighlightsAdapter.java | 59 +++++++------- .../viewholder/FeedStoryViewHolder.java | 33 ++++++++ .../viewholder/HighlightViewHolder.java | 28 +++---- .../asyncs/HighlightsFetcher.java | 27 ++++--- .../fragments/StoryViewerFragment.java | 80 ++++++++++++------- .../fragments/main/ProfileFragment.java | 45 ++++++++++- .../main/viewmodels/HighlightsViewModel.java | 19 +++++ .../instagrabber/models/HighlightModel.java | 8 +- app/src/main/res/layout/fragment_profile.xml | 5 +- .../main/res/navigation/profile_nav_graph.xml | 20 +++++ 11 files changed, 238 insertions(+), 96 deletions(-) create mode 100644 app/src/main/java/awais/instagrabber/adapters/viewholder/FeedStoryViewHolder.java create mode 100644 app/src/main/java/awais/instagrabber/fragments/main/viewmodels/HighlightsViewModel.java diff --git a/app/src/main/java/awais/instagrabber/adapters/FeedStoriesAdapter.java b/app/src/main/java/awais/instagrabber/adapters/FeedStoriesAdapter.java index 2ad1adcb..c1759893 100755 --- a/app/src/main/java/awais/instagrabber/adapters/FeedStoriesAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/FeedStoriesAdapter.java @@ -7,11 +7,11 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ListAdapter; -import awais.instagrabber.adapters.viewholder.HighlightViewHolder; +import awais.instagrabber.adapters.viewholder.FeedStoryViewHolder; import awais.instagrabber.databinding.ItemHighlightBinding; import awais.instagrabber.models.FeedStoryModel; -public final class FeedStoriesAdapter extends ListAdapter { +public final class FeedStoriesAdapter extends ListAdapter { private final OnFeedStoryClickListener listener; private static final DiffUtil.ItemCallback diffCallback = new DiffUtil.ItemCallback() { @@ -33,14 +33,14 @@ public final class FeedStoriesAdapter extends ListAdapter { - private final View.OnClickListener clickListener; - private LayoutInflater layoutInflater; - private HighlightModel[] highlightModels; +public final class HighlightsAdapter extends ListAdapter { + + private final OnHighlightClickListener clickListener; + + private static final DiffUtil.ItemCallback diffCallback = new DiffUtil.ItemCallback() { + @Override + public boolean areItemsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) { + return oldItem.getId().equals(newItem.getId()); + } + + @Override + public boolean areContentsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) { + return oldItem.getId().equals(newItem.getId()); + } + }; - public HighlightsAdapter(final HighlightModel[] highlightModels, final View.OnClickListener clickListener) { - this.highlightModels = highlightModels; + public HighlightsAdapter(final OnHighlightClickListener clickListener) { + super(diffCallback); this.clickListener = clickListener; } @NonNull @Override public HighlightViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { - if (layoutInflater == null) layoutInflater = LayoutInflater.from(parent.getContext()); - // return new HighlightViewHolder(layoutInflater.inflate(R.layout.item_highlight, parent, false)); - return null; + final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); + final ItemHighlightBinding binding = ItemHighlightBinding.inflate(layoutInflater, parent, false); + return new HighlightViewHolder(binding); } @Override public void onBindViewHolder(@NonNull final HighlightViewHolder holder, final int position) { - // final HighlightModel highlightModel = highlightModels[position]; - // if (highlightModel != null) { - // holder.itemView.setTag(highlightModel); - // holder.itemView.setOnClickListener(clickListener); - // holder.title.setText(highlightModel.getTitle()); - // Glide.with(holder.itemView).load(highlightModel.getThumbnailUrl()).into(holder.icon); - // } + final HighlightModel highlightModel = getItem(position); + if (clickListener != null) { + holder.itemView.setOnClickListener(v -> clickListener.onHighlightClick(highlightModel, position)); + } + holder.bind(highlightModel); } - public void setData(final HighlightModel[] highlightModels) { - this.highlightModels = highlightModels; - notifyDataSetChanged(); - } - - @Override - public int getItemCount() { - return highlightModels == null ? 0 : highlightModels.length; + public interface OnHighlightClickListener { + void onHighlightClick(final HighlightModel model, final int position); } } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedStoryViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedStoryViewHolder.java new file mode 100644 index 00000000..10c00e69 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/FeedStoryViewHolder.java @@ -0,0 +1,33 @@ +package awais.instagrabber.adapters.viewholder; + +import androidx.recyclerview.widget.RecyclerView; + +import awais.instagrabber.adapters.FeedStoriesAdapter; +import awais.instagrabber.databinding.ItemHighlightBinding; +import awais.instagrabber.models.FeedStoryModel; +import awais.instagrabber.models.ProfileModel; + +public final class FeedStoryViewHolder extends RecyclerView.ViewHolder { + + private final ItemHighlightBinding binding; + + public FeedStoryViewHolder(final ItemHighlightBinding binding) { + super(binding.getRoot()); + this.binding = binding; + } + + public void bind(final FeedStoryModel model, + final int position, + final FeedStoriesAdapter.OnFeedStoryClickListener listener) { + if (model == null) return; + binding.getRoot().setOnClickListener(v -> { + if (listener == null) return; + listener.onFeedStoryClick(model, position); + }); + final ProfileModel profileModel = model.getProfileModel(); + binding.title.setText(profileModel.getUsername()); + binding.title.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); + binding.icon.setImageURI(profileModel.getSdProfilePic()); + binding.icon.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); + } +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/HighlightViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/HighlightViewHolder.java index a412c319..d9956e92 100755 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/HighlightViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/HighlightViewHolder.java @@ -2,10 +2,8 @@ package awais.instagrabber.adapters.viewholder; import androidx.recyclerview.widget.RecyclerView; -import awais.instagrabber.adapters.FeedStoriesAdapter; import awais.instagrabber.databinding.ItemHighlightBinding; -import awais.instagrabber.models.FeedStoryModel; -import awais.instagrabber.models.ProfileModel; +import awais.instagrabber.models.HighlightModel; public final class HighlightViewHolder extends RecyclerView.ViewHolder { @@ -16,18 +14,18 @@ public final class HighlightViewHolder extends RecyclerView.ViewHolder { this.binding = binding; } - public void bind(final FeedStoryModel model, - final int position, - final FeedStoriesAdapter.OnFeedStoryClickListener listener) { + public void bind(final HighlightModel model) { if (model == null) return; - binding.getRoot().setOnClickListener(v -> { - if (listener == null) return; - listener.onFeedStoryClick(model, position); - }); - final ProfileModel profileModel = model.getProfileModel(); - binding.title.setText(profileModel.getUsername()); - binding.title.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); - binding.icon.setImageURI(profileModel.getSdProfilePic()); - binding.icon.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); + binding.title.setText(model.getTitle()); + binding.icon.setImageURI(model.getThumbnailUrl()); + // binding.getRoot().setOnClickListener(v -> { + // if (listener == null) return; + // listener.onFeedStoryClick(model, position); + // }); + // final ProfileModel profileModel = model.getProfileModel(); + // binding.title.setText(profileModel.getUsername()); + // binding.title.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); + // binding.icon.setImageURI(profileModel.getSdProfilePic()); + // binding.icon.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/asyncs/HighlightsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/HighlightsFetcher.java index 0c5e081b..b9f487cd 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/HighlightsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/HighlightsFetcher.java @@ -8,6 +8,8 @@ import org.json.JSONObject; import java.net.HttpURLConnection; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; @@ -15,20 +17,20 @@ import awais.instagrabber.models.HighlightModel; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; -public final class HighlightsFetcher extends AsyncTask { +public final class HighlightsFetcher extends AsyncTask> { private final String id; private final boolean storiesig; - private final FetchListener fetchListener; + private final FetchListener> fetchListener; - public HighlightsFetcher(final String id, final boolean storiesig, final FetchListener fetchListener) { + public HighlightsFetcher(final String id, final boolean storiesig, final FetchListener> fetchListener) { this.id = id; this.storiesig = storiesig; this.fetchListener = fetchListener; } @Override - protected HighlightModel[] doInBackground(final Void... voids) { - HighlightModel[] result = null; + protected List doInBackground(final Void... voids) { + List result = null; String url = "https://" + (storiesig ? "storiesig" : "i.instagram") + ".com/api/v1/highlights/" + id + "/highlights_tray/"; try { @@ -42,17 +44,18 @@ public final class HighlightsFetcher extends AsyncTask highlightModels = new ArrayList<>(); + // final String[] highlightIds = new String[length]; for (int i = 0; i < length; ++i) { final JSONObject highlightNode = highlightsReel.getJSONObject(i); - highlightModels[i] = new HighlightModel( + highlightModels.add(new HighlightModel( highlightNode.getString("title"), highlightNode.getString(Constants.EXTRAS_ID), - highlightNode.getJSONObject("cover_media").getJSONObject("cropped_image_version").getString("url") - ); + highlightNode.getJSONObject("cover_media") + .getJSONObject("cropped_image_version") + .getString("url") + )); } - conn.disconnect(); result = highlightModels; } @@ -66,7 +69,7 @@ public final class HighlightsFetcher extends AsyncTask result) { if (fetchListener != null) fetchListener.onResult(result); } } \ 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 b2e8b53a..c877d3de 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -32,6 +32,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.core.view.GestureDetectorCompat; import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; @@ -70,9 +71,11 @@ import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.ActivityStoryViewerBinding; import awais.instagrabber.fragments.main.viewmodels.FeedStoriesViewModel; +import awais.instagrabber.fragments.main.viewmodels.HighlightsViewModel; import awais.instagrabber.fragments.main.viewmodels.StoriesViewModel; import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.models.FeedStoryModel; +import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.stickers.PollModel; @@ -103,7 +106,6 @@ public class StoryViewerFragment extends Fragment { private SwipeEvent swipeEvent; private GestureDetectorCompat gestureDetector; private StoriesService storiesService; - private List feedStoryModels; private StoryModel currentStory; private int slidePos; private int lastSlidePos; @@ -120,11 +122,12 @@ public class StoryViewerFragment extends Fragment { private boolean fetching = false; private int currentFeedStoryIndex; private StoriesViewModel storiesViewModel; - private String currentStoryMediaId; private boolean shouldRefresh = true; private final String cookie = settingsHelper.getString(Constants.COOKIE); private StoryViewerFragmentArgs fragmentArgs; + private ViewModel viewModel; + private boolean isHighlight; @Override public void onCreate(@Nullable final Bundle savedInstanceState) { @@ -232,11 +235,16 @@ public class StoryViewerFragment extends Fragment { } private void init() { - final FeedStoriesViewModel feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); - feedStoryModels = feedStoriesViewModel.getList().getValue(); - if (feedStoryModels == null || feedStoryModels.isEmpty() || getArguments() == null) return; + if (getArguments() == null) return; fragmentArgs = StoryViewerFragmentArgs.fromBundle(getArguments()); currentFeedStoryIndex = fragmentArgs.getFeedStoryIndex(); + highlight = fragmentArgs.getHighlight(); + isHighlight = !Utils.isEmpty(highlight); + viewModel = isHighlight + ? new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class) + : new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); + // feedStoryModels = feedStoriesViewModel.getList().getValue(); + // feedStoryModels == null || feedStoryModels.isEmpty() || setupStories(); } @@ -256,11 +264,26 @@ public class StoryViewerFragment extends Fragment { @SuppressLint("ClickableViewAccessibility") private void setupListeners() { + final boolean hasFeedStories; + final List models; + if (isHighlight) { + final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; + models = highlightsViewModel.getList().getValue(); + // final HighlightModel model = models.get(currentFeedStoryIndex); + // currentStoryMediaId = model.getId(); + // currentStoryUsername = model.getTitle(); + } else { + final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; + models = feedStoriesViewModel.getList().getValue(); + // final FeedStoryModel model = models.get(currentFeedStoryIndex); + // currentStoryMediaId = model.getStoryMediaId(); + // currentStoryUsername = model.getProfileModel().getUsername(); + } + hasFeedStories = models != null && !models.isEmpty(); swipeEvent = isRightSwipe -> { final List storyModels = storiesViewModel.getList().getValue(); final int storiesLen = storyModels == null ? 0 : storyModels.size(); if (storiesLen <= 0) return; - final boolean hasFeedStories = feedStoryModels != null && !feedStoryModels.isEmpty(); final boolean isLeftSwipe = !isRightSwipe; final boolean endOfCurrentStories = slidePos + 1 >= storiesLen; final boolean swipingBeyondCurrentStories = (endOfCurrentStories && isLeftSwipe) || (slidePos == 0 && isRightSwipe); @@ -269,13 +292,13 @@ public class StoryViewerFragment extends Fragment { if (settingsHelper.getBoolean(MARK_AS_SEEN)) { new SeenAction(cookie, currentStory).execute(); } - if ((isRightSwipe && index == 0) || (isLeftSwipe && index == feedStoryModels.size() - 1)) { + if ((isRightSwipe && index == 0) || (isLeftSwipe && index == models.size() - 1)) { Toast.makeText(requireContext(), R.string.no_more_stories, Toast.LENGTH_SHORT).show(); return; } - final FeedStoryModel feedStoryModel = isRightSwipe - ? feedStoryModels.get(index - 1) - : feedStoryModels.size() == index + 1 ? null : feedStoryModels.get(index + 1); + final Object feedStoryModel = isRightSwipe + ? models.get(index - 1) + : models.size() == index + 1 ? null : models.get(index + 1); if (feedStoryModel != null) { if (fetching) { Toast.makeText(requireContext(), R.string.be_patient, Toast.LENGTH_SHORT).show(); @@ -284,18 +307,6 @@ public class StoryViewerFragment extends Fragment { fetching = true; currentFeedStoryIndex = isRightSwipe ? (index - 1) : (index + 1); resetView(); - // new iStoryStatusFetcher(feedStoryModel.getStoryMediaId(), null, false, false, false, false, result -> { - // if (result != null && result.length > 0) { - // final Intent newIntent = new Intent(requireContext(), StoryViewer.class) - // .putExtra(Constants.EXTRAS_STORIES, result) - // .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) - // .putExtra(Constants.FEED, storyFeed) - // .putExtra(Constants.FEED_ORDER, isRightSwipe ? (index - 1) : (index + 1)); - // newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - // startActivity(newIntent); - // } else - // Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - // }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } return; } @@ -448,13 +459,24 @@ public class StoryViewerFragment extends Fragment { if (menuDm != null) menuDm.setVisible(false); binding.imageViewer.setController(null); releasePlayer(); - final FeedStoryModel feedStoryModel = feedStoryModels.get(currentFeedStoryIndex); - currentStoryMediaId = feedStoryModel.getStoryMediaId(); - currentStoryUsername = feedStoryModel.getProfileModel().getUsername(); + String currentStoryMediaId; + if (isHighlight) { + final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; + final List models = highlightsViewModel.getList().getValue(); + if (models == null) return; + final HighlightModel model = models.get(currentFeedStoryIndex); + currentStoryMediaId = model.getId(); + currentStoryUsername = model.getTitle(); + } else { + final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; + final List models = feedStoriesViewModel.getList().getValue(); + if (models == null) return; + final FeedStoryModel model = models.get(currentFeedStoryIndex); + currentStoryMediaId = model.getStoryMediaId(); + currentStoryUsername = model.getProfileModel().getUsername(); + } isHashtag = fragmentArgs.getIsHashtag(); - highlight = fragmentArgs.getHighlight(); final boolean hasUsername = !Utils.isEmpty(currentStoryUsername); - final boolean hasHighlight = !Utils.isEmpty(highlight); if (hasUsername) { currentStoryUsername = currentStoryUsername.replace("@", ""); final ActionBar actionBar = fragmentActivity.getSupportActionBar(); @@ -463,7 +485,7 @@ public class StoryViewerFragment extends Fragment { // actionBar.setOnClickListener(v -> { // searchUsername(username); // }); - if (hasHighlight) { + if (isHighlight) { actionBar.setSubtitle(getString(R.string.title_highlight, highlight)); } else { actionBar.setSubtitle(R.string.title_user_story); @@ -471,7 +493,7 @@ public class StoryViewerFragment extends Fragment { } } storiesViewModel.getList().setValue(Collections.emptyList()); - storiesService.getUserStory(currentStoryMediaId, null, false, false, false, false, new ServiceCallback>() { + storiesService.getUserStory(currentStoryMediaId, null, false, false, false, isHighlight, new ServiceCallback>() { @Override public void onSuccess(final List storyModels) { fetching = false; diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 54b2ce85..13c1f486 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -32,6 +32,8 @@ import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import java.util.ArrayList; @@ -42,6 +44,7 @@ import java.util.List; import awais.instagrabber.ProfileNavGraphDirections; import awais.instagrabber.R; import awais.instagrabber.activities.MainActivity; +import awais.instagrabber.adapters.HighlightsAdapter; import awais.instagrabber.adapters.PostsAdapter; import awais.instagrabber.asyncs.HighlightsFetcher; import awais.instagrabber.asyncs.PostsFetcher; @@ -54,6 +57,7 @@ import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.databinding.FragmentProfileBinding; +import awais.instagrabber.fragments.main.viewmodels.HighlightsViewModel; import awais.instagrabber.fragments.main.viewmodels.PostsViewModel; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.MentionClickListener; @@ -96,6 +100,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe private AsyncTask currentlyExecuting; private MenuItem favMenuItem; private boolean isPullToRefresh; + private HighlightsAdapter highlightsAdapter; private final Runnable usernameSettingRunnable = () -> { final ActionBar actionBar = fragmentActivity.getSupportActionBar(); @@ -186,6 +191,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe action.setUsername("@" + text); NavHostFragment.findNavController(this).navigate(action); }; + private HighlightsViewModel highlightsViewModel; @Override public void onCreate(@Nullable final Bundle savedInstanceState) { @@ -257,6 +263,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe if (postsViewModel != null) { postsViewModel.getList().postValue(Collections.emptyList()); } + if (highlightsViewModel != null) { + highlightsViewModel.getList().postValue(Collections.emptyList()); + } } private void init() { @@ -274,6 +283,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe return; } setupPosts(); + setupHighlights(); setupCommonListeners(); fetchUsername(); } @@ -348,9 +358,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe new HighlightsFetcher(profileId, !isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG), result -> { - if (result != null && result.length > 0) { + if (result != null) { binding.highlightsList.setVisibility(View.VISIBLE); - // highlightsAdapter.setData(result); + highlightsViewModel.getList().postValue(result); } else binding.highlightsList.setVisibility(View.GONE); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -729,6 +739,37 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.mainPosts.addOnScrollListener(lazyLoader); } + private void setupHighlights() { + highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class); + highlightsAdapter = new HighlightsAdapter((model, position) -> { + final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false); + NavHostFragment.findNavController(this).navigate(action); + // new iStoryStatusFetcher( + // model.getId(), + // null, + // false, + // false, + // !isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG), + // true, + // result -> { + // if (result == null || result.length <= 0) { + // Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + // return; + // } + // feedStoriesViewModel.getHighlights().postValue(Arrays.asList(result)); + // // startActivity(new Intent(ProfileViewer.this, StoryViewer.class) + // // .putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) + // // .putExtra(Constants.EXTRAS_HIGHLIGHT, highlightModel.getTitle()) + // // .putExtra(Constants.EXTRAS_STORIES, result) + // // ); + // }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }); + final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false); + binding.highlightsList.setLayoutManager(layoutManager); + binding.highlightsList.setAdapter(highlightsAdapter); + highlightsViewModel.getList().observe(getViewLifecycleOwner(), highlightModels -> highlightsAdapter.submitList(highlightModels)); + } + private void fetchPosts() { stopCurrentExecutor(); binding.swipeRefreshLayout.setRefreshing(true); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/viewmodels/HighlightsViewModel.java b/app/src/main/java/awais/instagrabber/fragments/main/viewmodels/HighlightsViewModel.java new file mode 100644 index 00000000..8ae71649 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/fragments/main/viewmodels/HighlightsViewModel.java @@ -0,0 +1,19 @@ +package awais.instagrabber.fragments.main.viewmodels; + +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +import java.util.List; + +import awais.instagrabber.models.HighlightModel; + +public class HighlightsViewModel extends ViewModel { + private MutableLiveData> list; + + public MutableLiveData> getList() { + if (list == null) { + list = new MutableLiveData<>(); + } + return list; + } +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/models/HighlightModel.java b/app/src/main/java/awais/instagrabber/models/HighlightModel.java index e2e20dc4..70e4032a 100755 --- a/app/src/main/java/awais/instagrabber/models/HighlightModel.java +++ b/app/src/main/java/awais/instagrabber/models/HighlightModel.java @@ -1,9 +1,13 @@ package awais.instagrabber.models; public final class HighlightModel { - private final String title, id, thumbnailUrl; + private final String title; + private final String id; + private final String thumbnailUrl; - public HighlightModel(final String title, final String id, final String thumbnailUrl) { + public HighlightModel(final String title, + final String id, + final String thumbnailUrl) { this.title = title; this.id = id; this.thumbnailUrl = thumbnailUrl; diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index b9885414..7b1015eb 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -200,12 +200,13 @@ android:layout_height="wrap_content" android:layout_below="@id/myActions" android:clipToPadding="false" - android:orientation="horizontal" android:paddingStart="5dp" android:paddingLeft="5dp" android:paddingEnd="5dp" android:paddingRight="5dp" - android:visibility="gone" /> + android:visibility="gone" + tools:itemCount="2" + tools:visibility="visible" /> + + + + + + \ No newline at end of file