mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
Merge branch 'master' into go-to-top-of-page-button
This commit is contained in:
commit
ccd80a3e15
@ -272,70 +272,100 @@
|
||||
|
||||
<data
|
||||
android:host="www.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*"/>
|
||||
<data
|
||||
android:host="reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="www.google.com"
|
||||
android:scheme="https"
|
||||
android:pathPattern="/amp/s/amp.reddit.com/.*" />
|
||||
<data
|
||||
android:host="v.redd.it"
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="amp.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="m.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="old.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="new.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="np.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="reddit.app.link"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="redd.it"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="s.reddit.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="click.redditmail.com"
|
||||
android:scheme="https" />
|
||||
android:scheme="https"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="www.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="amp.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="m.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="old.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="new.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="np.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="reddit.app.link"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="redd.it"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="s.reddit.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
<data
|
||||
android:host="click.redditmail.com"
|
||||
android:scheme="http" />
|
||||
android:scheme="http"
|
||||
android:pathPattern=".*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
@ -12,7 +12,7 @@ import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubred
|
||||
|
||||
public class FetchPostFilterReadPostsAndConcatenatedSubredditNames {
|
||||
public interface FetchPostFilterAndReadPostsListener {
|
||||
void success(PostFilter postFilter, ArrayList<ReadPost> readPostList);
|
||||
void success(PostFilter postFilter, ArrayList<String> readPostList);
|
||||
}
|
||||
|
||||
public interface FetchPostFilterAndConcatenatecSubredditNamesListener {
|
||||
@ -26,8 +26,12 @@ public class FetchPostFilterReadPostsAndConcatenatedSubredditNames {
|
||||
List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage);
|
||||
PostFilter mergedPostFilter = PostFilter.mergePostFilter(postFilters);
|
||||
if (accountName != null) {
|
||||
ArrayList<ReadPost> readPosts = (ArrayList<ReadPost>) redditDataRoomDatabase.readPostDao().getAllReadPosts(accountName);
|
||||
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, readPosts));
|
||||
List<ReadPost> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPosts(accountName);
|
||||
ArrayList<String> readPostStrings = new ArrayList<>();
|
||||
for (ReadPost readPost : readPosts) {
|
||||
readPostStrings.add(readPost.getId());
|
||||
}
|
||||
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, readPostStrings));
|
||||
} else {
|
||||
handler.post(() -> fetchPostFilterAndReadPostsListener.success(mergedPostFilter, null));
|
||||
}
|
||||
|
@ -49,7 +49,8 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?";
|
||||
private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?";
|
||||
private static final String RPAN_BROADCAST_PATTERN = "/rpan/r/[\\w-]+/\\w+/?\\w+/?";
|
||||
private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)/?\\w+";
|
||||
private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)?(?:/\\w+)+";
|
||||
private static final String GOOGLE_AMP_PATTERN = "/amp/s/amp.reddit.com/.*";
|
||||
|
||||
@Inject
|
||||
@Named("default")
|
||||
@ -173,8 +174,10 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
} else if (path.matches(WIKI_PATTERN)) {
|
||||
final String wikiPage = path.substring(path.lastIndexOf("/wiki/") + 6);
|
||||
Intent intent = new Intent(this, WikiActivity.class);
|
||||
intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1));
|
||||
intent.putExtra(WikiActivity.EXTRA_WIKI_PATH, wikiPage);
|
||||
startActivity(intent);
|
||||
} else if (path.matches(SUBREDDIT_PATTERN)) {
|
||||
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||
@ -266,6 +269,13 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
} else if (authority.contains("google.com") ){
|
||||
if ( path.matches(GOOGLE_AMP_PATTERN) ) {
|
||||
String url = path.substring(11, path.length()); // skipping past amp straight to reddit
|
||||
handleUri(Uri.parse("https://" + url));
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
|
@ -1188,6 +1188,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
} else if (itemId == R.id.action_go_to_wiki_activity ) {
|
||||
Intent wikiIntent = new Intent(this, WikiActivity.class);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_WIKI_PATH, "index");
|
||||
startActivity(wikiIntent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ import retrofit2.Retrofit;
|
||||
public class WikiActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
public static final String EXTRA_WIKI_PATH = "EWP";
|
||||
private static final String WIKI_MARKDOWN_STATE = "WMS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_comment_wiki_activity)
|
||||
@ -281,7 +282,7 @@ public class WikiActivity extends BaseActivity {
|
||||
Glide.with(this).clear(mFetchWikiInfoImageView);
|
||||
mFetchWikiInfoLinearLayout.setVisibility(View.GONE);
|
||||
|
||||
retrofit.create(RedditAPI.class).getWiki(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME)).enqueue(new Callback<String>() {
|
||||
retrofit.create(RedditAPI.class).getWikiPage(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME), getIntent().getStringExtra(EXTRA_WIKI_PATH)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package ml.docilealligator.infinityforreddit.adapters;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -60,12 +59,9 @@ public class Paging3LoadingStateAdapter extends LoadStateAdapter<Paging3LoadingS
|
||||
mRetry.setTextColor(mCustomThemeWrapper.getButtonTextColor());
|
||||
mRetry.setOnClickListener(retryCallback);
|
||||
mErrorView.setOnClickListener(retryCallback);
|
||||
|
||||
Log.i("asfasdf", "asdf ");
|
||||
}
|
||||
|
||||
public void bind(LoadState loadState) {
|
||||
Log.i("asfasdf", "asdf bind");
|
||||
mProgressBar.setVisibility(loadState instanceof LoadState.Loading
|
||||
? View.VISIBLE : View.GONE);
|
||||
mErrorView.setVisibility(loadState instanceof LoadState.Error
|
||||
|
@ -2574,6 +2574,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3560,6 +3561,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3796,6 +3798,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,8 +294,12 @@ public interface RedditAPI {
|
||||
@GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1")
|
||||
Call<String> getTrendingSearches(@HeaderMap Map<String, String> headers);
|
||||
|
||||
@GET("/r/{subredditName}/wiki/index.json?raw_json=1")
|
||||
Call<String> getWiki(@Path("subredditName") String subredditName);
|
||||
default Call<String> getWiki(@Path("subredditName") String subredditName) {
|
||||
return getWikiPage(subredditName, "index");
|
||||
};
|
||||
|
||||
@GET("/r/{subredditName}/wiki/{wikiPage}.json?raw_json=1")
|
||||
Call<String> getWikiPage(@Path("subredditName") String subredditName, @Path("wikiPage") String wikiPage);
|
||||
|
||||
@GET("{sortType}?raw_json=1")
|
||||
ListenableFuture<Response<String>> getBestPostsListenableFuture(@Path("sortType") String sortType, @Query("after") String lastItem, @HeaderMap Map<String, String> headers);
|
||||
|
@ -18,6 +18,7 @@ import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
@ -129,7 +130,6 @@ import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostViewModel;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
import retrofit2.Retrofit;
|
||||
@ -248,7 +248,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
private boolean vibrateWhenActionTriggered;
|
||||
private float swipeActionThreshold;
|
||||
private ItemTouchHelper touchHelper;
|
||||
private ArrayList<ReadPost> readPosts;
|
||||
private ArrayList<String> readPosts;
|
||||
private Unbinder unbinder;
|
||||
private Map<String, String> subredditOrUserIcons = new HashMap<>();
|
||||
|
||||
@ -390,7 +390,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
recyclerViewPosition = savedInstanceState.getInt(RECYCLER_VIEW_POSITION_STATE);
|
||||
|
||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||
readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE);
|
||||
readPosts = savedInstanceState.getStringArrayList(READ_POST_LIST_STATE);
|
||||
postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
|
||||
concatenatedSubredditNames = savedInstanceState.getString(CONCATENATED_SUBREDDIT_NAMES_STATE);
|
||||
postFragmentId = savedInstanceState.getLong(POST_FRAGMENT_ID_STATE);
|
||||
@ -1264,7 +1264,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||
outState.putParcelableArrayList(READ_POST_LIST_STATE, readPosts);
|
||||
outState.putStringArrayList(READ_POST_LIST_STATE, readPosts);
|
||||
if (mLinearLayoutManager != null) {
|
||||
outState.putInt(RECYCLER_VIEW_POSITION_STATE, mLinearLayoutManager.findFirstVisibleItemPosition());
|
||||
} else if (mStaggeredGridLayoutManager != null) {
|
||||
@ -1561,6 +1561,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
}
|
||||
|
||||
public void markPostAsRead(Post post) {
|
||||
readPosts.add(post.getId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
|
||||
ItemSnapshotList<Post> posts = mAdapter.snapshot();
|
||||
@ -1575,6 +1579,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
post.setSpoiler(event.post.isSpoiler());
|
||||
post.setFlair(event.post.getFlair());
|
||||
post.setSaved(event.post.isSaved());
|
||||
if (event.post.isRead()) {
|
||||
post.markAsRead(true);
|
||||
}
|
||||
mAdapter.notifyItemChanged(event.positionInList);
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ import ml.docilealligator.infinityforreddit.post.FetchRemovedPost;
|
||||
import ml.docilealligator.infinityforreddit.post.HidePost;
|
||||
import ml.docilealligator.infinityforreddit.post.ParsePost;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
|
||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||
@ -170,6 +171,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
@Named("post_details")
|
||||
SharedPreferences mPostDetailsSharedPreferences;
|
||||
@Inject
|
||||
@Named("post_history")
|
||||
SharedPreferences mPostHistorySharedPreferences;
|
||||
@Inject
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
ExoCreator mExoCreator;
|
||||
@ -219,6 +223,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
private boolean mSwipeUpToHideFab;
|
||||
private boolean mExpandChildren;
|
||||
private boolean mSeparatePostAndComments = false;
|
||||
private boolean mMarkPostsAsRead;
|
||||
private int mWindowWidth;
|
||||
private ConcatAdapter mConcatAdapter;
|
||||
private PostDetailRecyclerViewAdapter mPostAdapter;
|
||||
@ -292,6 +297,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
||||
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
||||
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
|
||||
mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
|
||||
if (savedInstanceState == null) {
|
||||
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
|
||||
viewPostDetailFragmentId = System.currentTimeMillis();
|
||||
@ -1087,12 +1093,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
}
|
||||
}
|
||||
|
||||
private void tryMarkingPostAsRead() {
|
||||
if (mMarkPostsAsRead && !mPost.isRead()) {
|
||||
mPost.markAsRead(true);
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, mPost.getId());
|
||||
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mRecyclerView != null) {
|
||||
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
|
||||
}
|
||||
tryMarkingPostAsRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1173,6 +1188,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
@Override
|
||||
public void onParsePostSuccess(Post post) {
|
||||
mPost = post;
|
||||
tryMarkingPostAsRead();
|
||||
|
||||
setupMenu();
|
||||
|
||||
@ -1758,6 +1774,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
@Override
|
||||
public void fetchSuccess(Post post) {
|
||||
mPost = post;
|
||||
tryMarkingPostAsRead();
|
||||
if (mPostAdapter != null) {
|
||||
mPostAdapter.updatePost(post);
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
|
||||
@ -26,54 +25,7 @@ import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
*/
|
||||
|
||||
public class ParsePost {
|
||||
public static void parsePosts(Executor executor, Handler handler, String response, int nPosts,
|
||||
PostFilter postFilter, List<ReadPost> readPostList,
|
||||
ParsePostsListingListener parsePostsListingListener) {
|
||||
executor.execute(() -> {
|
||||
LinkedHashSet<Post> newPosts = new LinkedHashSet<>();
|
||||
try {
|
||||
JSONObject jsonResponse = new JSONObject(response);
|
||||
JSONArray allData = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
String lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
||||
|
||||
//Posts listing
|
||||
int size;
|
||||
if (nPosts < 0 || nPosts > allData.length()) {
|
||||
size = allData.length();
|
||||
} else {
|
||||
size = nPosts;
|
||||
}
|
||||
|
||||
HashSet<ReadPost> readPostHashSet = null;
|
||||
if (readPostList != null) {
|
||||
readPostHashSet = new HashSet<>(readPostList);
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
try {
|
||||
if (allData.getJSONObject(i).getString(JSONUtils.KIND_KEY).equals("t3")) {
|
||||
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||
Post post = parseBasicData(data);
|
||||
if (readPostHashSet != null && readPostHashSet.contains(ReadPost.convertPost(post))) {
|
||||
post.markAsRead(false);
|
||||
}
|
||||
if (PostFilter.isPostAllowed(post, postFilter)) {
|
||||
newPosts.add(post);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
handler.post(() -> parsePostsListingListener.onParsePostsListingSuccess(newPosts, lastItem));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
handler.post(parsePostsListingListener::onParsePostsListingFail);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter, List<String> readPostList) {
|
||||
LinkedHashSet<Post> newPosts = new LinkedHashSet<>();
|
||||
try {
|
||||
JSONObject jsonResponse = new JSONObject(response);
|
||||
@ -87,7 +39,7 @@ public class ParsePost {
|
||||
size = nPosts;
|
||||
}
|
||||
|
||||
HashSet<ReadPost> readPostHashSet = null;
|
||||
HashSet<String> readPostHashSet = null;
|
||||
if (readPostList != null) {
|
||||
readPostHashSet = new HashSet<>(readPostList);
|
||||
}
|
||||
@ -96,7 +48,7 @@ public class ParsePost {
|
||||
if (allData.getJSONObject(i).getString(JSONUtils.KIND_KEY).equals("t3")) {
|
||||
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||
Post post = parseBasicData(data);
|
||||
if (readPostHashSet != null && readPostHashSet.contains(ReadPost.convertPost(post))) {
|
||||
if (readPostHashSet != null && readPostHashSet.contains(post.getId())) {
|
||||
post.markAsRead(false);
|
||||
}
|
||||
if (PostFilter.isPostAllowed(post, postFilter)) {
|
||||
|
@ -54,7 +54,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private List<ReadPost> readPostList;
|
||||
private List<String> readPostList;
|
||||
private String userWhere;
|
||||
private String multiRedditPath;
|
||||
private LinkedHashSet<Post> postLinkedHashSet;
|
||||
@ -62,7 +62,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -79,7 +79,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String path, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -117,7 +117,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
|
||||
String where, List<ReadPost> readPostList) {
|
||||
String where, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -136,7 +136,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, String query, String trendingSource, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
|
@ -23,7 +23,6 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.SortType;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
@ -41,7 +40,7 @@ public class PostViewModel extends ViewModel {
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
private List<String> readPostList;
|
||||
private MutableLiveData<Boolean> currentlyReadPostIdsLiveData = new MutableLiveData<>();
|
||||
|
||||
private LiveData<PagingData<Post>> posts;
|
||||
@ -54,7 +53,7 @@ public class PostViewModel extends ViewModel {
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -95,7 +94,7 @@ public class PostViewModel extends ViewModel {
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -139,7 +138,7 @@ public class PostViewModel extends ViewModel {
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, String username,
|
||||
int postType, SortType sortType, PostFilter postFilter, String userWhere,
|
||||
List<ReadPost> readPostList) {
|
||||
List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -183,7 +182,7 @@ public class PostViewModel extends ViewModel {
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
|
||||
String trendingSource, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -290,12 +289,12 @@ public class PostViewModel extends ViewModel {
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
private String userWhere;
|
||||
private List<ReadPost> readPostList;
|
||||
private List<String> readPostList;
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -312,7 +311,7 @@ public class PostViewModel extends ViewModel {
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -331,7 +330,7 @@ public class PostViewModel extends ViewModel {
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, String username, int postType,
|
||||
SortType sortType, PostFilter postFilter, String where, List<ReadPost> readPostList) {
|
||||
SortType sortType, PostFilter postFilter, String where, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@ -350,7 +349,7 @@ public class PostViewModel extends ViewModel {
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
|
||||
int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
int postType, SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
|
@ -10,7 +10,6 @@ import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.account.Account;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
|
||||
@Entity(tableName = "read_posts", primaryKeys = {"username", "id"},
|
||||
foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||
@ -23,10 +22,6 @@ public class ReadPost implements Parcelable {
|
||||
@ColumnInfo(name = "id")
|
||||
private String id;
|
||||
|
||||
public static ReadPost convertPost(Post post) {
|
||||
return new ReadPost("temp", post.getId());
|
||||
}
|
||||
|
||||
public ReadPost(@NonNull String username, @NonNull String id) {
|
||||
this.username = username;
|
||||
this.id = id;
|
||||
|
@ -58,4 +58,10 @@
|
||||
android:orderInCategory="9"
|
||||
android:title="@string/action_share"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_go_to_wiki_activity"
|
||||
android:orderInCategory="10"
|
||||
android:title="@string/action_go_to_wiki"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
@ -1190,6 +1190,8 @@
|
||||
<string name="app_lock_timeout_6_hours">6 hours</string>
|
||||
<string name="app_lock_timeout_12_hours">12 hours</string>
|
||||
<string name="app_lock_timeout_24_hours">24 hours</string>
|
||||
|
||||
<string name="go_to_top">Go To Top</string>
|
||||
<string name="action_go_to_wiki">Go to Wiki</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user