mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
story read improvement (WIP)
This commit is contained in:
parent
312c90ad92
commit
e539e426df
@ -1,5 +1,6 @@
|
|||||||
package awais.instagrabber.adapters;
|
package awais.instagrabber.adapters;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedSt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areContentsTheSame(@NonNull final FeedStoryModel oldItem, @NonNull final FeedStoryModel newItem) {
|
public boolean areContentsTheSame(@NonNull final FeedStoryModel oldItem, @NonNull final FeedStoryModel newItem) {
|
||||||
return oldItem.getStoryMediaId().equals(newItem.getStoryMediaId());
|
return oldItem.getStoryMediaId().equals(newItem.getStoryMediaId()) && oldItem.isFullyRead().equals(newItem.isFullyRead());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,5 +48,7 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedSt
|
|||||||
|
|
||||||
public interface OnFeedStoryClickListener {
|
public interface OnFeedStoryClickListener {
|
||||||
void onFeedStoryClick(FeedStoryModel model, int position);
|
void onFeedStoryClick(FeedStoryModel model, int position);
|
||||||
|
|
||||||
|
void onFeedStoryLongClick(FeedStoryModel model, int position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,14 @@ public final class FeedStoryViewHolder extends RecyclerView.ViewHolder {
|
|||||||
if (listener == null) return;
|
if (listener == null) return;
|
||||||
listener.onFeedStoryClick(model, position);
|
listener.onFeedStoryClick(model, position);
|
||||||
});
|
});
|
||||||
|
binding.getRoot().setOnLongClickListener(v -> {
|
||||||
|
if (listener != null) listener.onFeedStoryLongClick(model, position);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
final ProfileModel profileModel = model.getProfileModel();
|
final ProfileModel profileModel = model.getProfileModel();
|
||||||
binding.title.setText(profileModel.getUsername());
|
binding.title.setText(profileModel.getUsername());
|
||||||
binding.title.setAlpha(model.getFullyRead() ? 0.5F : 1.0F);
|
binding.title.setAlpha(model.isFullyRead() ? 0.5F : 1.0F);
|
||||||
binding.icon.setImageURI(profileModel.getSdProfilePic());
|
binding.icon.setImageURI(profileModel.getSdProfilePic());
|
||||||
binding.icon.setAlpha(model.getFullyRead() ? 0.5F : 1.0F);
|
binding.icon.setAlpha(model.isFullyRead() ? 0.5F : 1.0F);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,6 +60,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -315,9 +316,6 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
final boolean swipingBeyondCurrentStories = (endOfCurrentStories && isLeftSwipe) || (slidePos == 0 && isRightSwipe);
|
final boolean swipingBeyondCurrentStories = (endOfCurrentStories && isLeftSwipe) || (slidePos == 0 && isRightSwipe);
|
||||||
if (swipingBeyondCurrentStories && hasFeedStories) {
|
if (swipingBeyondCurrentStories && hasFeedStories) {
|
||||||
final int index = currentFeedStoryIndex;
|
final int index = currentFeedStoryIndex;
|
||||||
if (settingsHelper.getBoolean(MARK_AS_SEEN)) {
|
|
||||||
new SeenAction(cookie, currentStory).execute();
|
|
||||||
}
|
|
||||||
if ((isRightSwipe && index == 0) || (isLeftSwipe && index == finalModels.size() - 1)) {
|
if ((isRightSwipe && index == 0) || (isLeftSwipe && index == finalModels.size() - 1)) {
|
||||||
Toast.makeText(context, R.string.no_more_stories, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.no_more_stories, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
@ -325,7 +323,7 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
final Object feedStoryModel = isRightSwipe
|
final Object feedStoryModel = isRightSwipe
|
||||||
? finalModels.get(index - 1)
|
? finalModels.get(index - 1)
|
||||||
: finalModels.size() == index + 1 ? null : finalModels.get(index + 1);
|
: finalModels.size() == index + 1 ? null : finalModels.get(index + 1);
|
||||||
paginateStories(feedStoryModel, context, isRightSwipe, currentFeedStoryIndex == finalModels.size() - 2);
|
paginateStories(feedStoryModel, finalModels.get(index), context, isRightSwipe, currentFeedStoryIndex == finalModels.size() - 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isRightSwipe) {
|
if (isRightSwipe) {
|
||||||
@ -364,8 +362,12 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
if (hasFeedStories) {
|
if (hasFeedStories) {
|
||||||
binding.btnBackward.setVisibility(currentFeedStoryIndex == 0 ? View.INVISIBLE : View.VISIBLE);
|
binding.btnBackward.setVisibility(currentFeedStoryIndex == 0 ? View.INVISIBLE : View.VISIBLE);
|
||||||
binding.btnForward.setVisibility(currentFeedStoryIndex == finalModels.size() - 1 ? View.INVISIBLE : View.VISIBLE);
|
binding.btnForward.setVisibility(currentFeedStoryIndex == finalModels.size() - 1 ? View.INVISIBLE : View.VISIBLE);
|
||||||
binding.btnBackward.setOnClickListener(v -> paginateStories(finalModels.get(currentFeedStoryIndex - 1), context, true, false));
|
binding.btnBackward.setOnClickListener(v -> paginateStories(finalModels.get(currentFeedStoryIndex - 1),
|
||||||
binding.btnForward.setOnClickListener(v -> paginateStories(finalModels.get(currentFeedStoryIndex + 1), context, false,
|
finalModels.get(currentFeedStoryIndex),
|
||||||
|
context, true, false));
|
||||||
|
binding.btnForward.setOnClickListener(v -> paginateStories(finalModels.get(currentFeedStoryIndex + 1),
|
||||||
|
finalModels.get(currentFeedStoryIndex),
|
||||||
|
context, false,
|
||||||
currentFeedStoryIndex == finalModels.size() - 2));
|
currentFeedStoryIndex == finalModels.size() - 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -893,12 +895,27 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paginateStories(Object feedStory, Context context, boolean backward, boolean last) {
|
private void paginateStories(Object newFeedStory, Object oldFeedStory, Context context, boolean backward, boolean last) {
|
||||||
if (feedStory != null) {
|
if (newFeedStory != null) {
|
||||||
if (fetching) {
|
if (fetching) {
|
||||||
Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// if (settingsHelper.getBoolean(MARK_AS_SEEN)
|
||||||
|
// && oldFeedStory != null
|
||||||
|
// && oldFeedStory instanceof FeedStoryModel
|
||||||
|
// && viewModel instanceof FeedStoriesViewModel) {
|
||||||
|
// final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel;
|
||||||
|
// final FeedStoryModel oldFeedStoryModel = (FeedStoryModel) oldFeedStory;
|
||||||
|
// if (oldFeedStoryModel.isFullyRead()) {
|
||||||
|
// oldFeedStoryModel.setFullyRead(false);
|
||||||
|
// final List<FeedStoryModel> models = feedStoriesViewModel.getList().getValue();
|
||||||
|
// final List<FeedStoryModel> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models);
|
||||||
|
// Log.d("austin_debug", oldFeedStoryModel.getProfileModel().getUsername() + ", v " + models.get(currentFeedStoryIndex).isFullyRead() + " l " + oldFeedStoryModel.isFullyRead());
|
||||||
|
// modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel);
|
||||||
|
// feedStoriesViewModel.getList().setValue(models);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
fetching = true;
|
fetching = true;
|
||||||
binding.btnBackward.setVisibility(currentFeedStoryIndex == 1 && backward ? View.INVISIBLE : View.VISIBLE);
|
binding.btnBackward.setVisibility(currentFeedStoryIndex == 1 && backward ? View.INVISIBLE : View.VISIBLE);
|
||||||
binding.btnForward.setVisibility(last ? View.INVISIBLE : View.VISIBLE);
|
binding.btnForward.setVisibility(last ? View.INVISIBLE : View.VISIBLE);
|
||||||
|
@ -354,10 +354,21 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
|
|
||||||
private void setupFeedStories() {
|
private void setupFeedStories() {
|
||||||
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
||||||
final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter((model, position) -> {
|
final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter(
|
||||||
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false, false, null, null);
|
new FeedStoriesAdapter.OnFeedStoryClickListener() {
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
@Override
|
||||||
});
|
public void onFeedStoryClick(FeedStoryModel model, int position) {
|
||||||
|
Log.d("austin_debug", "read status is "+model.isFullyRead());
|
||||||
|
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false, false, null, null);
|
||||||
|
NavHostFragment.findNavController(FeedFragment.this).navigate(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFeedStoryLongClick(FeedStoryModel model, int position) {
|
||||||
|
navigateToProfile("@" + model.getProfileModel().getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
storiesRecyclerView = new RecyclerView(context);
|
storiesRecyclerView = new RecyclerView(context);
|
||||||
@ -369,7 +380,10 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
storiesRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
|
storiesRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
|
||||||
storiesRecyclerView.setAdapter(feedStoriesAdapter);
|
storiesRecyclerView.setAdapter(feedStoriesAdapter);
|
||||||
fragmentActivity.setCollapsingView(storiesRecyclerView);
|
fragmentActivity.setCollapsingView(storiesRecyclerView);
|
||||||
feedStoriesViewModel.getList().observe(fragmentActivity, feedStoriesAdapter::submitList);
|
feedStoriesViewModel.getList().observe(fragmentActivity, list -> {
|
||||||
|
Log.d("austin_debug", "observed");
|
||||||
|
feedStoriesAdapter.submitList(list);
|
||||||
|
});
|
||||||
fetchStories();
|
fetchStories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package awais.instagrabber.models;
|
package awais.instagrabber.models;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public final class FeedStoryModel implements Serializable {
|
public final class FeedStoryModel implements Serializable {
|
||||||
private final String storyMediaId;
|
private final String storyMediaId;
|
||||||
private final ProfileModel profileModel;
|
private final ProfileModel profileModel;
|
||||||
private StoryModel[] storyModels;
|
private StoryModel[] storyModels;
|
||||||
private boolean fullyRead;
|
private Boolean fullyRead;
|
||||||
|
|
||||||
public FeedStoryModel(final String storyMediaId, final ProfileModel profileModel, final boolean fullyRead) {
|
public FeedStoryModel(final String storyMediaId, final ProfileModel profileModel, final boolean fullyRead) {
|
||||||
this.storyMediaId = storyMediaId;
|
this.storyMediaId = storyMediaId;
|
||||||
@ -30,7 +32,11 @@ public final class FeedStoryModel implements Serializable {
|
|||||||
return storyModels;
|
return storyModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getFullyRead() {
|
public Boolean isFullyRead() {
|
||||||
return fullyRead;
|
return fullyRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFullyRead(final boolean fullyRead) {
|
||||||
|
this.fullyRead = fullyRead;
|
||||||
|
}
|
||||||
}
|
}
|
@ -644,7 +644,7 @@ public final class ResponseBodyUtils {
|
|||||||
.setPostId(itemJson.getString(Constants.EXTRAS_ID))
|
.setPostId(itemJson.getString(Constants.EXTRAS_ID))
|
||||||
.setThumbnailUrl(mediaType != MediaItemType.MEDIA_TYPE_SLIDER ? ResponseBodyUtils.getLowQualityImage(itemJson) : null)
|
.setThumbnailUrl(mediaType != MediaItemType.MEDIA_TYPE_SLIDER ? ResponseBodyUtils.getLowQualityImage(itemJson) : null)
|
||||||
.setShortCode(itemJson.getString("code"))
|
.setShortCode(itemJson.getString("code"))
|
||||||
.setPostCaption(captionJson != null ? captionJson.optString("text") : null)
|
.setPostCaption(captionJson != null ? captionJson.optString("text") : "")
|
||||||
.setCaptionId(captionJson != null ? captionJson.optString("pk") : null)
|
.setCaptionId(captionJson != null ? captionJson.optString("pk") : null)
|
||||||
.setCommentsCount(itemJson.optInt("comment_count"))
|
.setCommentsCount(itemJson.optInt("comment_count"))
|
||||||
.setTimestamp(itemJson.optLong("taken_at", -1))
|
.setTimestamp(itemJson.optLong("taken_at", -1))
|
||||||
|
@ -3,6 +3,7 @@ package awais.instagrabber.viewmodels;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import awais.instagrabber.models.FeedStoryModel;
|
import awais.instagrabber.models.FeedStoryModel;
|
||||||
|
@ -64,30 +64,6 @@ public class StoriesService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getFeedStories(final String csrfToken, final ServiceCallback<List<FeedStoryModel>> callback) {
|
public void getFeedStories(final String csrfToken, final ServiceCallback<List<FeedStoryModel>> callback) {
|
||||||
if (loadFromMock) {
|
|
||||||
final Handler handler = new Handler();
|
|
||||||
handler.postDelayed(() -> {
|
|
||||||
final ClassLoader classLoader = getClass().getClassLoader();
|
|
||||||
if (classLoader == null) {
|
|
||||||
Log.e(TAG, "getFeedStories: classLoader is null!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try (InputStream resourceAsStream = classLoader.getResourceAsStream("stories_response.json");
|
|
||||||
Reader in = new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8)) {
|
|
||||||
final int bufferSize = 1024;
|
|
||||||
final char[] buffer = new char[bufferSize];
|
|
||||||
final StringBuilder out = new StringBuilder();
|
|
||||||
int charsRead;
|
|
||||||
while ((charsRead = in.read(buffer, 0, buffer.length)) > 0) {
|
|
||||||
out.append(buffer, 0, charsRead);
|
|
||||||
}
|
|
||||||
parseStoriesBody(out.toString(), callback);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "getFeedStories: ", e);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Map<String, Object> form = new HashMap<>(4);
|
final Map<String, Object> form = new HashMap<>(4);
|
||||||
form.put("reason", "cold_start");
|
form.put("reason", "cold_start");
|
||||||
form.put("_csrftoken", csrfToken);
|
form.put("_csrftoken", csrfToken);
|
||||||
@ -115,6 +91,7 @@ public class StoriesService extends BaseService {
|
|||||||
|
|
||||||
private void parseStoriesBody(final String body, final ServiceCallback<List<FeedStoryModel>> callback) {
|
private void parseStoriesBody(final String body, final ServiceCallback<List<FeedStoryModel>> callback) {
|
||||||
try {
|
try {
|
||||||
|
Log.d("austin_debug", body);
|
||||||
final List<FeedStoryModel> feedStoryModels = new ArrayList<>();
|
final List<FeedStoryModel> feedStoryModels = new ArrayList<>();
|
||||||
final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray");
|
final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray");
|
||||||
for (int i = 0; i < feedStoriesReel.length(); ++i) {
|
for (int i = 0; i < feedStoriesReel.length(); ++i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user