custom story sort, #122 point 1

This commit is contained in:
Austin Huang 2020-12-29 13:41:38 -05:00
parent 830152f74e
commit 3d2dee0d94
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
8 changed files with 118 additions and 25 deletions

View File

@ -1,16 +1,22 @@
package awais.instagrabber.adapters;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import awais.instagrabber.adapters.viewholder.FeedStoryViewHolder;
import awais.instagrabber.databinding.ItemHighlightBinding;
import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils;
public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedStoryViewHolder> {
private final OnFeedStoryClickListener listener;
@ -46,6 +52,43 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedSt
holder.bind(model, position, listener);
}
@Override
public void submitList(@Nullable final List<FeedStoryModel> list, @Nullable final Runnable commitCallback) {
if (list == null) {
super.submitList(null, commitCallback);
return;
}
super.submitList(sort(list), commitCallback);
}
@Override
public void submitList(@Nullable final List<FeedStoryModel> list) {
if (list == null) {
super.submitList(null);
return;
}
super.submitList(sort(list));
}
private List<FeedStoryModel> sort(final List<FeedStoryModel> list) {
final List<FeedStoryModel> listCopy = new ArrayList<>(list);
Collections.sort(listCopy, (o1, o2) -> {
int result;
switch (Utils.settingsHelper.getString(Constants.STORY_SORT)) {
case "1":
result = o1.getTimestamp() > o2.getTimestamp() ? -1 : (o1.getTimestamp() == o2.getTimestamp() ? 0 : 1);
break;
case "2":
result = o1.getTimestamp() > o2.getTimestamp() ? 1 : (o1.getTimestamp() == o2.getTimestamp() ? 0 : -1);
break;
default:
result = 0;
}
return result;
});
return listCopy;
}
public interface OnFeedStoryClickListener {
void onFeedStoryClick(FeedStoryModel model, int position);

View File

@ -79,6 +79,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
screen.addPreference(loggedInUsersPreferenceCategory);
loggedInUsersPreferenceCategory.setIconSpaceReserved(false);
loggedInUsersPreferenceCategory.setTitle(R.string.login_settings);
loggedInUsersPreferenceCategory.addPreference(getStorySortPreference());
loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference());
loggedInUsersPreferenceCategory.addPreference(getMarkDMSeenPreference());
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
@ -204,6 +205,25 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
return preference;
}
private Preference getStorySortPreference() {
final Context context = getContext();
if (context == null) return null;
final ListPreference preference = new ListPreference(context);
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance());
final int length = getResources().getStringArray(R.array.story_sorts).length;
final String[] values = new String[length];
for (int i = 0; i < length; i++) {
values[i] = String.valueOf(i);
}
preference.setKey(Constants.STORY_SORT);
preference.setTitle(R.string.story_sort_setting);
preference.setDialogTitle(R.string.story_sort_setting);
preference.setEntries(R.array.story_sorts);
preference.setIconSpaceReserved(false);
preference.setEntryValues(values);
return preference;
}
private Preference getMarkStoriesSeenPreference() {
final Context context = getContext();
if (context == null) return null;

View File

@ -7,30 +7,37 @@ import java.io.Serializable;
public final class FeedStoryModel implements Serializable {
private final String storyMediaId;
private final ProfileModel profileModel;
private StoryModel[] storyModels;
// private StoryModel[] storyModels;
private Boolean fullyRead;
private final long timestamp;
public FeedStoryModel(final String storyMediaId, final ProfileModel profileModel, final boolean fullyRead) {
public FeedStoryModel(final String storyMediaId, final ProfileModel profileModel,
final boolean fullyRead, final long timestamp) {
this.storyMediaId = storyMediaId;
this.profileModel = profileModel;
this.fullyRead = fullyRead;
this.timestamp = timestamp;
}
public String getStoryMediaId() {
return storyMediaId;
}
public long getTimestamp() {
return timestamp;
}
public ProfileModel getProfileModel() {
return profileModel;
}
public void setStoryModels(final StoryModel[] storyModels) {
this.storyModels = storyModels;
}
// public void setStoryModels(final StoryModel[] storyModels) {
// this.storyModels = storyModels;
// }
public StoryModel[] getStoryModels() {
return storyModels;
}
// public StoryModel[] getStoryModels() {
// return storyModels;
// }
public Boolean isFullyRead() {
return fullyRead;

View File

@ -8,6 +8,7 @@ public final class Constants {
public static final String CUSTOM_DATE_TIME_FORMAT = "date_time_custom_format";
public static final String APP_THEME = "app_theme_v19";
public static final String APP_LANGUAGE = "app_language_v19";
public static final String STORY_SORT = "story_sort";
// int prefs
public static final String PREV_INSTALL_VERSION = "prevVersion";
// boolean prefs

View File

@ -40,6 +40,7 @@ import static awais.instagrabber.utils.Constants.PREF_TOPIC_POSTS_LAYOUT;
import static awais.instagrabber.utils.Constants.PREV_INSTALL_VERSION;
import static awais.instagrabber.utils.Constants.SHOW_QUICK_ACCESS_DIALOG;
import static awais.instagrabber.utils.Constants.SKIPPED_VERSION;
import static awais.instagrabber.utils.Constants.STORY_SORT;
import static awais.instagrabber.utils.Constants.SWAP_DATE_TIME_FORMAT_ENABLED;
public final class SettingsHelper {
@ -122,7 +123,7 @@ public final class SettingsHelper {
{APP_LANGUAGE, APP_THEME, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION, CUSTOM_DATE_TIME_FORMAT,
DEVICE_UUID, SKIPPED_VERSION, DEFAULT_TAB, PREF_DARK_THEME, PREF_LIGHT_THEME, PREF_POSTS_LAYOUT,
PREF_PROFILE_POSTS_LAYOUT, PREF_TOPIC_POSTS_LAYOUT, PREF_HASHTAG_POSTS_LAYOUT, PREF_LOCATION_POSTS_LAYOUT,
PREF_LIKED_POSTS_LAYOUT, PREF_TAGGED_POSTS_LAYOUT, PREF_SAVED_POSTS_LAYOUT})
PREF_LIKED_POSTS_LAYOUT, PREF_TAGGED_POSTS_LAYOUT, PREF_SAVED_POSTS_LAYOUT, STORY_SORT})
public @interface StringSettings {}
@StringDef({DOWNLOAD_USER_FOLDER, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS,

View File

@ -18,12 +18,6 @@ import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.HighlightModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.stickers.PollModel;
import awais.instagrabber.models.stickers.QuestionModel;
import awais.instagrabber.models.stickers.QuizModel;
import awais.instagrabber.models.stickers.SliderModel;
import awais.instagrabber.models.stickers.SwipeUpModel;
import awais.instagrabber.repositories.StoriesRepository;
import awais.instagrabber.repositories.responses.StoryStickerResponse;
import awais.instagrabber.utils.Constants;
@ -128,8 +122,9 @@ public class StoriesService extends BaseService {
user.getString("profile_pic_url"),
null, 0, 0, 0, false, false, false, false, false);
final String id = node.getString("id");
final boolean fullyRead = !node.isNull("seen") && node.getLong("seen") == node.getLong("latest_reel_media");
feedStoryModels.add(new FeedStoryModel(id, profileModel, fullyRead));
final long timestamp = node.getLong("latest_reel_media");
final boolean fullyRead = !node.isNull("seen") && node.getLong("seen") == timestamp;
feedStoryModels.add(new FeedStoryModel(id, profileModel, fullyRead, timestamp));
}
callback.onSuccess(feedStoryModels);
} catch (JSONException e) {
@ -156,7 +151,7 @@ public class StoriesService extends BaseService {
final int length = highlightsReel.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.add(new HighlightModel(
@ -164,7 +159,8 @@ public class StoriesService extends BaseService {
highlightNode.getString(Constants.EXTRAS_ID),
highlightNode.getJSONObject("cover_media")
.getJSONObject("cropped_image_version")
.getString("url")
.getString("url"),
highlightNode.getLong("latest_reel_media")
));
}
callback.onSuccess(highlightModels);
@ -337,4 +333,29 @@ public class StoriesService extends BaseService {
}
return builder.toString();
}
public class ArchiveFetchResponse {
private List<HighlightModel> archives;
private final boolean hasNextPage;
private final String nextCursor;
public ArchiveFetchResponse(final List<HighlightModel> highlightModels, final boolean hasNextPage, final String nextCursor) {
this.archives = archives;
this.hasNextPage = hasNextPage;
this.nextCursor = nextCursor;
}
public List<HighlightModel> getArchives() {
return archives;
}
public boolean hasNextPage() {
return hasNextPage;
}
public String getNextCursor() {
return nextCursor;
}
}
}

View File

@ -27,11 +27,10 @@
<item>Dark</item>
<item>Light</item>
</string-array>
<string-array name="theme_presets_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<string-array name="story_sorts">
<item>Instagram default (Unread then read)</item>
<item>From newest to oldest</item>
<item>From oldest to newest</item>
</string-array>
<string-array name="separator_presets">
<item>None</item>

View File

@ -35,6 +35,7 @@
<string name="dm_mark_as_seen_setting">Mark DM as seen after viewing</string>
<string name="dm_mark_as_seen_setting_summary">Other members will know you viewed it</string>
<string name="activity_setting">Enable activity notifications</string>
<string name="story_sort_setting">Feed stories sort</string>
<string name="error_loading_profile">Error loading profile!\nTry logging in and search again.</string>
<string name="error_creating_folders">Error creating Download folder(s).</string>
<string name="save_to_folder">Save to custom folder</string>