mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +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.DiffUtil;
|
||||||
import androidx.recyclerview.widget.ListAdapter;
|
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.databinding.ItemHighlightBinding;
|
||||||
import awais.instagrabber.models.FeedStoryModel;
|
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 final OnFeedStoryClickListener listener;
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<FeedStoryModel> diffCallback = new DiffUtil.ItemCallback<FeedStoryModel>() {
|
private static final DiffUtil.ItemCallback<FeedStoryModel> diffCallback = new DiffUtil.ItemCallback<FeedStoryModel>() {
|
||||||
@ -33,14 +33,14 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, Highli
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@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 LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
||||||
final ItemHighlightBinding binding = ItemHighlightBinding.inflate(layoutInflater, parent, false);
|
final ItemHighlightBinding binding = ItemHighlightBinding.inflate(layoutInflater, parent, false);
|
||||||
return new HighlightViewHolder(binding);
|
return new FeedStoryViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
final FeedStoryModel model = getItem(position);
|
||||||
holder.bind(model, position, listener);
|
holder.bind(model, position, listener);
|
||||||
}
|
}
|
||||||
|
@ -1,54 +1,55 @@
|
|||||||
package awais.instagrabber.adapters;
|
package awais.instagrabber.adapters;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
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.adapters.viewholder.HighlightViewHolder;
|
||||||
|
import awais.instagrabber.databinding.ItemHighlightBinding;
|
||||||
import awais.instagrabber.models.HighlightModel;
|
import awais.instagrabber.models.HighlightModel;
|
||||||
|
|
||||||
public final class HighlightsAdapter extends RecyclerView.Adapter<HighlightViewHolder> {
|
public final class HighlightsAdapter extends ListAdapter<HighlightModel, HighlightViewHolder> {
|
||||||
private final View.OnClickListener clickListener;
|
|
||||||
private LayoutInflater layoutInflater;
|
|
||||||
private HighlightModel[] highlightModels;
|
|
||||||
|
|
||||||
public HighlightsAdapter(final HighlightModel[] highlightModels, final View.OnClickListener clickListener) {
|
private final OnHighlightClickListener clickListener;
|
||||||
this.highlightModels = highlightModels;
|
|
||||||
|
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;
|
this.clickListener = clickListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public HighlightViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
public HighlightViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
||||||
if (layoutInflater == null) layoutInflater = LayoutInflater.from(parent.getContext());
|
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
||||||
// return new HighlightViewHolder(layoutInflater.inflate(R.layout.item_highlight, parent, false));
|
final ItemHighlightBinding binding = ItemHighlightBinding.inflate(layoutInflater, parent, false);
|
||||||
return null;
|
return new HighlightViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull final HighlightViewHolder holder, final int position) {
|
public void onBindViewHolder(@NonNull final HighlightViewHolder holder, final int position) {
|
||||||
// final HighlightModel highlightModel = highlightModels[position];
|
final HighlightModel highlightModel = getItem(position);
|
||||||
// if (highlightModel != null) {
|
if (clickListener != null) {
|
||||||
// holder.itemView.setTag(highlightModel);
|
holder.itemView.setOnClickListener(v -> clickListener.onHighlightClick(highlightModel, position));
|
||||||
// holder.itemView.setOnClickListener(clickListener);
|
}
|
||||||
// holder.title.setText(highlightModel.getTitle());
|
holder.bind(highlightModel);
|
||||||
// Glide.with(holder.itemView).load(highlightModel.getThumbnailUrl()).into(holder.icon);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(final HighlightModel[] highlightModels) {
|
public interface OnHighlightClickListener {
|
||||||
this.highlightModels = highlightModels;
|
void onHighlightClick(final HighlightModel model, final int position);
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return highlightModels == null ? 0 : highlightModels.length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import awais.instagrabber.adapters.FeedStoriesAdapter;
|
|
||||||
import awais.instagrabber.databinding.ItemHighlightBinding;
|
import awais.instagrabber.databinding.ItemHighlightBinding;
|
||||||
import awais.instagrabber.models.FeedStoryModel;
|
import awais.instagrabber.models.HighlightModel;
|
||||||
import awais.instagrabber.models.ProfileModel;
|
|
||||||
|
|
||||||
public final class HighlightViewHolder extends RecyclerView.ViewHolder {
|
public final class HighlightViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@ -16,18 +14,18 @@ public final class HighlightViewHolder extends RecyclerView.ViewHolder {
|
|||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(final FeedStoryModel model,
|
public void bind(final HighlightModel model) {
|
||||||
final int position,
|
|
||||||
final FeedStoriesAdapter.OnFeedStoryClickListener listener) {
|
|
||||||
if (model == null) return;
|
if (model == null) return;
|
||||||
binding.getRoot().setOnClickListener(v -> {
|
binding.title.setText(model.getTitle());
|
||||||
if (listener == null) return;
|
binding.icon.setImageURI(model.getThumbnailUrl());
|
||||||
listener.onFeedStoryClick(model, position);
|
// binding.getRoot().setOnClickListener(v -> {
|
||||||
});
|
// if (listener == null) return;
|
||||||
final ProfileModel profileModel = model.getProfileModel();
|
// listener.onFeedStoryClick(model, position);
|
||||||
binding.title.setText(profileModel.getUsername());
|
// });
|
||||||
binding.title.setAlpha(model.getFullyRead() ? 0.5F : 1.0F);
|
// final ProfileModel profileModel = model.getProfileModel();
|
||||||
binding.icon.setImageURI(profileModel.getSdProfilePic());
|
// binding.title.setText(profileModel.getUsername());
|
||||||
binding.icon.setAlpha(model.getFullyRead() ? 0.5F : 1.0F);
|
// 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.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import awais.instagrabber.BuildConfig;
|
import awais.instagrabber.BuildConfig;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
@ -15,20 +17,20 @@ import awais.instagrabber.models.HighlightModel;
|
|||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.Utils;
|
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 String id;
|
||||||
private final boolean storiesig;
|
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.id = id;
|
||||||
this.storiesig = storiesig;
|
this.storiesig = storiesig;
|
||||||
this.fetchListener = fetchListener;
|
this.fetchListener = fetchListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected HighlightModel[] doInBackground(final Void... voids) {
|
protected List<HighlightModel> doInBackground(final Void... voids) {
|
||||||
HighlightModel[] result = null;
|
List<HighlightModel> result = null;
|
||||||
String url = "https://" + (storiesig ? "storiesig" : "i.instagram") + ".com/api/v1/highlights/" + id + "/highlights_tray/";
|
String url = "https://" + (storiesig ? "storiesig" : "i.instagram") + ".com/api/v1/highlights/" + id + "/highlights_tray/";
|
||||||
|
|
||||||
try {
|
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 JSONArray highlightsReel = new JSONObject(Utils.readFromConnection(conn)).getJSONArray("tray");
|
||||||
|
|
||||||
final int length = highlightsReel.length();
|
final int length = highlightsReel.length();
|
||||||
final HighlightModel[] highlightModels = new HighlightModel[length];
|
final List<HighlightModel> highlightModels = new ArrayList<>();
|
||||||
final String[] highlightIds = new String[length];
|
// final String[] highlightIds = new String[length];
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
final JSONObject highlightNode = highlightsReel.getJSONObject(i);
|
final JSONObject highlightNode = highlightsReel.getJSONObject(i);
|
||||||
highlightModels[i] = new HighlightModel(
|
highlightModels.add(new HighlightModel(
|
||||||
highlightNode.getString("title"),
|
highlightNode.getString("title"),
|
||||||
highlightNode.getString(Constants.EXTRAS_ID),
|
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();
|
conn.disconnect();
|
||||||
result = highlightModels;
|
result = highlightModels;
|
||||||
}
|
}
|
||||||
@ -66,7 +69,7 @@ public final class HighlightsFetcher extends AsyncTask<Void, Void, HighlightMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(final HighlightModel[] result) {
|
protected void onPostExecute(final List<HighlightModel> result) {
|
||||||
if (fetchListener != null) fetchListener.onResult(result);
|
if (fetchListener != null) fetchListener.onResult(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,6 +32,7 @@ import androidx.core.app.ActivityCompat;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.view.GestureDetectorCompat;
|
import androidx.core.view.GestureDetectorCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
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.customviews.helpers.SwipeGestureListener;
|
||||||
import awais.instagrabber.databinding.ActivityStoryViewerBinding;
|
import awais.instagrabber.databinding.ActivityStoryViewerBinding;
|
||||||
import awais.instagrabber.fragments.main.viewmodels.FeedStoriesViewModel;
|
import awais.instagrabber.fragments.main.viewmodels.FeedStoriesViewModel;
|
||||||
|
import awais.instagrabber.fragments.main.viewmodels.HighlightsViewModel;
|
||||||
import awais.instagrabber.fragments.main.viewmodels.StoriesViewModel;
|
import awais.instagrabber.fragments.main.viewmodels.StoriesViewModel;
|
||||||
import awais.instagrabber.interfaces.SwipeEvent;
|
import awais.instagrabber.interfaces.SwipeEvent;
|
||||||
import awais.instagrabber.models.FeedStoryModel;
|
import awais.instagrabber.models.FeedStoryModel;
|
||||||
|
import awais.instagrabber.models.HighlightModel;
|
||||||
import awais.instagrabber.models.StoryModel;
|
import awais.instagrabber.models.StoryModel;
|
||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
import awais.instagrabber.models.stickers.PollModel;
|
import awais.instagrabber.models.stickers.PollModel;
|
||||||
@ -103,7 +106,6 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
private SwipeEvent swipeEvent;
|
private SwipeEvent swipeEvent;
|
||||||
private GestureDetectorCompat gestureDetector;
|
private GestureDetectorCompat gestureDetector;
|
||||||
private StoriesService storiesService;
|
private StoriesService storiesService;
|
||||||
private List<FeedStoryModel> feedStoryModels;
|
|
||||||
private StoryModel currentStory;
|
private StoryModel currentStory;
|
||||||
private int slidePos;
|
private int slidePos;
|
||||||
private int lastSlidePos;
|
private int lastSlidePos;
|
||||||
@ -120,11 +122,12 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
private boolean fetching = false;
|
private boolean fetching = false;
|
||||||
private int currentFeedStoryIndex;
|
private int currentFeedStoryIndex;
|
||||||
private StoriesViewModel storiesViewModel;
|
private StoriesViewModel storiesViewModel;
|
||||||
private String currentStoryMediaId;
|
|
||||||
private boolean shouldRefresh = true;
|
private boolean shouldRefresh = true;
|
||||||
|
|
||||||
private final String cookie = settingsHelper.getString(Constants.COOKIE);
|
private final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||||
private StoryViewerFragmentArgs fragmentArgs;
|
private StoryViewerFragmentArgs fragmentArgs;
|
||||||
|
private ViewModel viewModel;
|
||||||
|
private boolean isHighlight;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
@ -232,11 +235,16 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
final FeedStoriesViewModel feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
if (getArguments() == null) return;
|
||||||
feedStoryModels = feedStoriesViewModel.getList().getValue();
|
|
||||||
if (feedStoryModels == null || feedStoryModels.isEmpty() || getArguments() == null) return;
|
|
||||||
fragmentArgs = StoryViewerFragmentArgs.fromBundle(getArguments());
|
fragmentArgs = StoryViewerFragmentArgs.fromBundle(getArguments());
|
||||||
currentFeedStoryIndex = fragmentArgs.getFeedStoryIndex();
|
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();
|
setupStories();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,11 +264,26 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private void setupListeners() {
|
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 -> {
|
swipeEvent = isRightSwipe -> {
|
||||||
final List<StoryModel> storyModels = storiesViewModel.getList().getValue();
|
final List<StoryModel> storyModels = storiesViewModel.getList().getValue();
|
||||||
final int storiesLen = storyModels == null ? 0 : storyModels.size();
|
final int storiesLen = storyModels == null ? 0 : storyModels.size();
|
||||||
if (storiesLen <= 0) return;
|
if (storiesLen <= 0) return;
|
||||||
final boolean hasFeedStories = feedStoryModels != null && !feedStoryModels.isEmpty();
|
|
||||||
final boolean isLeftSwipe = !isRightSwipe;
|
final boolean isLeftSwipe = !isRightSwipe;
|
||||||
final boolean endOfCurrentStories = slidePos + 1 >= storiesLen;
|
final boolean endOfCurrentStories = slidePos + 1 >= storiesLen;
|
||||||
final boolean swipingBeyondCurrentStories = (endOfCurrentStories && isLeftSwipe) || (slidePos == 0 && isRightSwipe);
|
final boolean swipingBeyondCurrentStories = (endOfCurrentStories && isLeftSwipe) || (slidePos == 0 && isRightSwipe);
|
||||||
@ -269,13 +292,13 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
if (settingsHelper.getBoolean(MARK_AS_SEEN)) {
|
if (settingsHelper.getBoolean(MARK_AS_SEEN)) {
|
||||||
new SeenAction(cookie, currentStory).execute();
|
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();
|
Toast.makeText(requireContext(), R.string.no_more_stories, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final FeedStoryModel feedStoryModel = isRightSwipe
|
final Object feedStoryModel = isRightSwipe
|
||||||
? feedStoryModels.get(index - 1)
|
? models.get(index - 1)
|
||||||
: feedStoryModels.size() == index + 1 ? null : feedStoryModels.get(index + 1);
|
: models.size() == index + 1 ? null : models.get(index + 1);
|
||||||
if (feedStoryModel != null) {
|
if (feedStoryModel != null) {
|
||||||
if (fetching) {
|
if (fetching) {
|
||||||
Toast.makeText(requireContext(), R.string.be_patient, Toast.LENGTH_SHORT).show();
|
Toast.makeText(requireContext(), R.string.be_patient, Toast.LENGTH_SHORT).show();
|
||||||
@ -284,18 +307,6 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
fetching = true;
|
fetching = true;
|
||||||
currentFeedStoryIndex = isRightSwipe ? (index - 1) : (index + 1);
|
currentFeedStoryIndex = isRightSwipe ? (index - 1) : (index + 1);
|
||||||
resetView();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -448,13 +459,24 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
if (menuDm != null) menuDm.setVisible(false);
|
if (menuDm != null) menuDm.setVisible(false);
|
||||||
binding.imageViewer.setController(null);
|
binding.imageViewer.setController(null);
|
||||||
releasePlayer();
|
releasePlayer();
|
||||||
final FeedStoryModel feedStoryModel = feedStoryModels.get(currentFeedStoryIndex);
|
String currentStoryMediaId;
|
||||||
currentStoryMediaId = feedStoryModel.getStoryMediaId();
|
if (isHighlight) {
|
||||||
currentStoryUsername = feedStoryModel.getProfileModel().getUsername();
|
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();
|
isHashtag = fragmentArgs.getIsHashtag();
|
||||||
highlight = fragmentArgs.getHighlight();
|
|
||||||
final boolean hasUsername = !Utils.isEmpty(currentStoryUsername);
|
final boolean hasUsername = !Utils.isEmpty(currentStoryUsername);
|
||||||
final boolean hasHighlight = !Utils.isEmpty(highlight);
|
|
||||||
if (hasUsername) {
|
if (hasUsername) {
|
||||||
currentStoryUsername = currentStoryUsername.replace("@", "");
|
currentStoryUsername = currentStoryUsername.replace("@", "");
|
||||||
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
||||||
@ -463,7 +485,7 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
// actionBar.setOnClickListener(v -> {
|
// actionBar.setOnClickListener(v -> {
|
||||||
// searchUsername(username);
|
// searchUsername(username);
|
||||||
// });
|
// });
|
||||||
if (hasHighlight) {
|
if (isHighlight) {
|
||||||
actionBar.setSubtitle(getString(R.string.title_highlight, highlight));
|
actionBar.setSubtitle(getString(R.string.title_highlight, highlight));
|
||||||
} else {
|
} else {
|
||||||
actionBar.setSubtitle(R.string.title_user_story);
|
actionBar.setSubtitle(R.string.title_user_story);
|
||||||
@ -471,7 +493,7 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
storiesViewModel.getList().setValue(Collections.emptyList());
|
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
|
@Override
|
||||||
public void onSuccess(final List<StoryModel> storyModels) {
|
public void onSuccess(final List<StoryModel> storyModels) {
|
||||||
fetching = false;
|
fetching = false;
|
||||||
|
@ -32,6 +32,8 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -42,6 +44,7 @@ import java.util.List;
|
|||||||
import awais.instagrabber.ProfileNavGraphDirections;
|
import awais.instagrabber.ProfileNavGraphDirections;
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.activities.MainActivity;
|
import awais.instagrabber.activities.MainActivity;
|
||||||
|
import awais.instagrabber.adapters.HighlightsAdapter;
|
||||||
import awais.instagrabber.adapters.PostsAdapter;
|
import awais.instagrabber.adapters.PostsAdapter;
|
||||||
import awais.instagrabber.asyncs.HighlightsFetcher;
|
import awais.instagrabber.asyncs.HighlightsFetcher;
|
||||||
import awais.instagrabber.asyncs.PostsFetcher;
|
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.GridSpacingItemDecoration;
|
||||||
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
|
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
|
||||||
import awais.instagrabber.databinding.FragmentProfileBinding;
|
import awais.instagrabber.databinding.FragmentProfileBinding;
|
||||||
|
import awais.instagrabber.fragments.main.viewmodels.HighlightsViewModel;
|
||||||
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.interfaces.MentionClickListener;
|
||||||
@ -96,6 +100,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private AsyncTask<Void, Void, PostModel[]> currentlyExecuting;
|
private AsyncTask<Void, Void, PostModel[]> currentlyExecuting;
|
||||||
private MenuItem favMenuItem;
|
private MenuItem favMenuItem;
|
||||||
private boolean isPullToRefresh;
|
private boolean isPullToRefresh;
|
||||||
|
private HighlightsAdapter highlightsAdapter;
|
||||||
|
|
||||||
private final Runnable usernameSettingRunnable = () -> {
|
private final Runnable usernameSettingRunnable = () -> {
|
||||||
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
||||||
@ -186,6 +191,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
action.setUsername("@" + text);
|
action.setUsername("@" + text);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
};
|
};
|
||||||
|
private HighlightsViewModel highlightsViewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
@ -257,6 +263,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
if (postsViewModel != null) {
|
if (postsViewModel != null) {
|
||||||
postsViewModel.getList().postValue(Collections.emptyList());
|
postsViewModel.getList().postValue(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
if (highlightsViewModel != null) {
|
||||||
|
highlightsViewModel.getList().postValue(Collections.emptyList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
@ -274,6 +283,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setupPosts();
|
setupPosts();
|
||||||
|
setupHighlights();
|
||||||
setupCommonListeners();
|
setupCommonListeners();
|
||||||
fetchUsername();
|
fetchUsername();
|
||||||
}
|
}
|
||||||
@ -348,9 +358,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
new HighlightsFetcher(profileId,
|
new HighlightsFetcher(profileId,
|
||||||
!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG),
|
!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG),
|
||||||
result -> {
|
result -> {
|
||||||
if (result != null && result.length > 0) {
|
if (result != null) {
|
||||||
binding.highlightsList.setVisibility(View.VISIBLE);
|
binding.highlightsList.setVisibility(View.VISIBLE);
|
||||||
// highlightsAdapter.setData(result);
|
highlightsViewModel.getList().postValue(result);
|
||||||
} else binding.highlightsList.setVisibility(View.GONE);
|
} else binding.highlightsList.setVisibility(View.GONE);
|
||||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
@ -729,6 +739,37 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
binding.mainPosts.addOnScrollListener(lazyLoader);
|
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() {
|
private void fetchPosts() {
|
||||||
stopCurrentExecutor();
|
stopCurrentExecutor();
|
||||||
binding.swipeRefreshLayout.setRefreshing(true);
|
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;
|
package awais.instagrabber.models;
|
||||||
|
|
||||||
public final class HighlightModel {
|
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.title = title;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.thumbnailUrl = thumbnailUrl;
|
this.thumbnailUrl = thumbnailUrl;
|
||||||
|
@ -200,12 +200,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/myActions"
|
android:layout_below="@id/myActions"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingStart="5dp"
|
android:paddingStart="5dp"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
android:paddingEnd="5dp"
|
android:paddingEnd="5dp"
|
||||||
android:paddingRight="5dp"
|
android:paddingRight="5dp"
|
||||||
android:visibility="gone" />
|
android:visibility="gone"
|
||||||
|
tools:itemCount="2"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/profileInfo"
|
android:id="@+id/profileInfo"
|
||||||
|
@ -60,6 +60,9 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_profileFragment_to_followViewerFragment"
|
android:id="@+id/action_profileFragment_to_followViewerFragment"
|
||||||
app:destination="@id/followViewerFragment" />
|
app:destination="@id/followViewerFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_profileFragment_to_storyViewerFragment"
|
||||||
|
app:destination="@id/storyViewerFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/savedViewerFragment"
|
android:id="@+id/savedViewerFragment"
|
||||||
@ -106,4 +109,21 @@
|
|||||||
app:nullable="true" />
|
app:nullable="true" />
|
||||||
</action>
|
</action>
|
||||||
</fragment>
|
</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>
|
</navigation>
|
Loading…
Reference in New Issue
Block a user