mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
Add highlights back to ProfileFragment
This commit is contained in:
parent
465defd1ff
commit
4efd2cb6ac
@ -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<FeedStoryModel, HighlightViewHolder> {
|
||||
public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedStoryViewHolder> {
|
||||
private final OnFeedStoryClickListener listener;
|
||||
|
||||
private static final DiffUtil.ItemCallback<FeedStoryModel> diffCallback = new DiffUtil.ItemCallback<FeedStoryModel>() {
|
||||
@ -33,14 +33,14 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, Highli
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public HighlightViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
||||
public FeedStoryViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
||||
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
||||
final ItemHighlightBinding binding = ItemHighlightBinding.inflate(layoutInflater, parent, false);
|
||||
return new HighlightViewHolder(binding);
|
||||
return new FeedStoryViewHolder(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final HighlightViewHolder holder, final int position) {
|
||||
public void onBindViewHolder(@NonNull final FeedStoryViewHolder holder, final int position) {
|
||||
final FeedStoryModel model = getItem(position);
|
||||
holder.bind(model, position, listener);
|
||||
}
|
||||
|
@ -1,54 +1,55 @@
|
||||
package awais.instagrabber.adapters;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.adapters.viewholder.HighlightViewHolder;
|
||||
import awais.instagrabber.databinding.ItemHighlightBinding;
|
||||
import awais.instagrabber.models.HighlightModel;
|
||||
|
||||
public final class HighlightsAdapter extends RecyclerView.Adapter<HighlightViewHolder> {
|
||||
private final View.OnClickListener clickListener;
|
||||
private LayoutInflater layoutInflater;
|
||||
private HighlightModel[] highlightModels;
|
||||
public final class HighlightsAdapter extends ListAdapter<HighlightModel, HighlightViewHolder> {
|
||||
|
||||
public HighlightsAdapter(final HighlightModel[] highlightModels, final View.OnClickListener clickListener) {
|
||||
this.highlightModels = highlightModels;
|
||||
private final OnHighlightClickListener clickListener;
|
||||
|
||||
private static final DiffUtil.ItemCallback<HighlightModel> diffCallback = new DiffUtil.ItemCallback<HighlightModel>() {
|
||||
@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 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<Void, Void, HighlightModel[]> {
|
||||
public final class HighlightsFetcher extends AsyncTask<Void, Void, List<HighlightModel>> {
|
||||
private final String id;
|
||||
private final boolean storiesig;
|
||||
private final FetchListener<HighlightModel[]> fetchListener;
|
||||
private final FetchListener<List<HighlightModel>> fetchListener;
|
||||
|
||||
public HighlightsFetcher(final String id, final boolean storiesig, final FetchListener<HighlightModel[]> fetchListener) {
|
||||
public HighlightsFetcher(final String id, final boolean storiesig, final FetchListener<List<HighlightModel>> fetchListener) {
|
||||
this.id = id;
|
||||
this.storiesig = storiesig;
|
||||
this.fetchListener = fetchListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HighlightModel[] doInBackground(final Void... voids) {
|
||||
HighlightModel[] result = null;
|
||||
protected List<HighlightModel> doInBackground(final Void... voids) {
|
||||
List<HighlightModel> 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<Void, Void, HighlightMode
|
||||
final JSONArray highlightsReel = new JSONObject(Utils.readFromConnection(conn)).getJSONArray("tray");
|
||||
|
||||
final int length = highlightsReel.length();
|
||||
final HighlightModel[] highlightModels = new HighlightModel[length];
|
||||
final String[] highlightIds = new String[length];
|
||||
final List<HighlightModel> 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<Void, Void, HighlightMode
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final HighlightModel[] result) {
|
||||
protected void onPostExecute(final List<HighlightModel> result) {
|
||||
if (fetchListener != null) fetchListener.onResult(result);
|
||||
}
|
||||
}
|
@ -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<FeedStoryModel> 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<StoryModel> 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<HighlightModel> 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<FeedStoryModel> 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<List<StoryModel>>() {
|
||||
storiesService.getUserStory(currentStoryMediaId, null, false, false, false, isHighlight, new ServiceCallback<List<StoryModel>>() {
|
||||
@Override
|
||||
public void onSuccess(final List<StoryModel> storyModels) {
|
||||
fetching = false;
|
||||
|
@ -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<Void, Void, PostModel[]> 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);
|
||||
|
@ -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<HighlightModel>> list;
|
||||
|
||||
public MutableLiveData<List<HighlightModel>> getList() {
|
||||
if (list == null) {
|
||||
list = new MutableLiveData<>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/profileInfo"
|
||||
|
@ -60,6 +60,9 @@
|
||||
<action
|
||||
android:id="@+id/action_profileFragment_to_followViewerFragment"
|
||||
app:destination="@id/followViewerFragment" />
|
||||
<action
|
||||
android:id="@+id/action_profileFragment_to_storyViewerFragment"
|
||||
app:destination="@id/storyViewerFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/savedViewerFragment"
|
||||
@ -106,4 +109,21 @@
|
||||
app:nullable="true" />
|
||||
</action>
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/storyViewerFragment"
|
||||
android:name="awais.instagrabber.fragments.StoryViewerFragment"
|
||||
android:label="StoryViewerFragment"
|
||||
tools:layout="@layout/activity_story_viewer">
|
||||
<argument
|
||||
android:name="feedStoryIndex"
|
||||
app:argType="integer"
|
||||
app:nullable="false" />
|
||||
<argument
|
||||
android:name="highlight"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
<argument
|
||||
android:name="isHashtag"
|
||||
app:argType="boolean" />
|
||||
</fragment>
|
||||
</navigation>
|
Loading…
Reference in New Issue
Block a user