From 44c758204cff2b7b7b41fc5ccef7727457941d48 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 26 Dec 2020 19:18:37 +0800 Subject: Use Executor to save read posts. Hide the fab and the bottom app bar when scrolling comments in ViewUserDetailActivity. --- .../activities/AccountSavedThingActivity.java | 6 +- .../activities/CustomizePostFilterActivity.java | 2 + .../activities/FilteredPostsActivity.java | 8 +- .../infinityforreddit/activities/MainActivity.java | 5 +- .../activities/PostFilterPreferenceActivity.java | 6 +- .../activities/PostFilterUsageListingActivity.java | 12 +++ .../activities/ViewMultiRedditDetailActivity.java | 6 +- .../activities/ViewSubredditDetailActivity.java | 5 +- .../activities/ViewUserDetailActivity.java | 5 +- ...ilterFragmentPostFilterRecyclerViewAdapter.java | 85 ---------------------- .../adapters/PostFilterRecyclerViewAdapter.java | 85 ++++++++++++++++++++++ .../fragments/CommentsListingFragment.java | 24 ++++-- .../postfilter/DeletePostFilter.java | 7 +- .../postfilter/PostFilterDao.java | 4 +- .../infinityforreddit/readpost/FetchReadPosts.java | 46 ------------ .../infinityforreddit/readpost/InsertReadPost.java | 26 ++----- 16 files changed, 158 insertions(+), 174 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FilterFragmentPostFilterRecyclerViewAdapter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index a87c10d0..e7349698 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -30,6 +30,8 @@ import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -87,6 +89,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT SharedPreferences mPostLayoutSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; private SlidrInterface mSlidrInterface; @@ -340,7 +344,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT @Override public void markPostAsRead(Post post) { - InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } private class SectionsPagerAdapter extends FragmentStateAdapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java index 3c2d675d..04d19eda 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -245,6 +245,8 @@ public class CustomizePostFilterActivity extends BaseActivity { postTypeGifCheckBox.setChecked(postFilter.containGifType); postTypeVideoCheckBox.setChecked(postFilter.containVideoType); postTypeGalleryCheckBox.setChecked(postFilter.containGalleryType); + onlyNSFWSwitch.setChecked(postFilter.onlyNSFW); + onlySpoilerSwitch.setChecked(postFilter.onlySpoiler); titleExcludesStringsTextInputEditText.setText(postFilter.postTitleExcludesStrings); titleExcludesRegexTextInputEditText.setText(postFilter.postTitleExcludesRegex); excludesSubredditsTextInputEditText.setText(postFilter.excludeSubreddits); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index a9040052..a4ea7760 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -24,6 +24,8 @@ import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -33,7 +35,6 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; -import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; @@ -51,6 +52,7 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; +import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -92,6 +94,8 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec SharedPreferences mPostLayoutSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private boolean isInLazyMode = false; private boolean mNullAccessToken = false; private String mAccessToken; @@ -537,7 +541,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec @Override public void markPostAsRead(Post post) { - InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 042d39db..6fa85ca5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -58,6 +58,7 @@ import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import javax.inject.Inject; @@ -198,6 +199,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb SharedPreferences bottomAppBarSharedPreference; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; private AppBarLayout.LayoutParams params; @@ -1318,7 +1321,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public void markPostAsRead(Post post) { - InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } private class SectionsPagerAdapter extends FragmentStateAdapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java index 94597df6..ebcc8453 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java @@ -24,7 +24,7 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.adapters.FilterFragmentPostFilterRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.adapters.PostFilterRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostFilterOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.postfilter.DeletePostFilter; @@ -53,7 +53,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { @Inject Executor executor; public PostFilterViewModel postFilterViewModel; - private FilterFragmentPostFilterRecyclerViewAdapter adapter; + private PostFilterRecyclerViewAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -75,7 +75,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { startActivity(intent); }); - adapter = new FilterFragmentPostFilterRecyclerViewAdapter(postFilter -> { + adapter = new PostFilterRecyclerViewAdapter(postFilter -> { PostFilterOptionsBottomSheetFragment postFilterOptionsBottomSheetFragment = new PostFilterOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java index 08ee8829..482b1171 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java @@ -4,9 +4,11 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.os.Bundle; +import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; +import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.lifecycle.ViewModelProvider; @@ -180,6 +182,16 @@ public class PostFilterUsageListingActivity extends BaseActivity { DeletePostFilterUsage.deletePostFilterUsage(redditDataRoomDatabase, executor, postFilterUsage); } + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + + return false; + } + @Override protected SharedPreferences getDefaultSharedPreferences() { return sharedPreferences; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index bcb0a40d..abcd21bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -23,6 +23,8 @@ import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -91,6 +93,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT SharedPreferences mPostLayoutSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private boolean mNullAccessToken = false; private String mAccessToken; private String mAccountName; @@ -366,6 +370,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void markPostAsRead(Post post) { - InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 7d0ea592..c23e310e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -54,6 +54,7 @@ import org.greenrobot.eventbus.Subscribe; import java.text.SimpleDateFormat; import java.util.Locale; +import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -190,6 +191,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp SharedPreferences bottomAppBarSharedPreference; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; public SubredditViewModel mSubredditViewModel; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; @@ -1246,7 +1249,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public void markPostAsRead(Post post) { - InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } private class SectionsPagerAdapter extends FragmentStateAdapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index ef190443..53c5ace1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -57,6 +57,7 @@ import org.greenrobot.eventbus.Subscribe; import java.text.SimpleDateFormat; import java.util.Locale; +import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; @@ -192,6 +193,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele SharedPreferences bottomAppBarSharedPreference; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; public UserViewModel userViewModel; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; @@ -1272,7 +1275,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override public void markPostAsRead(Post post) { - InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FilterFragmentPostFilterRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FilterFragmentPostFilterRecyclerViewAdapter.java deleted file mode 100644 index a7cc4981..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FilterFragmentPostFilterRecyclerViewAdapter.java +++ /dev/null @@ -1,85 +0,0 @@ -package ml.docilealligator.infinityforreddit.adapters; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.List; - -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.postfilter.PostFilter; - -public class FilterFragmentPostFilterRecyclerViewAdapter extends RecyclerView.Adapter { - - private static final int VIEW_TYPE_HEADER = 1; - private static final int VIEW_TYPE_POST_FILTER = 2; - - private final OnItemClickListener onItemClickListener; - private List postFilterList; - - public interface OnItemClickListener { - void onItemClick(PostFilter postFilter); - } - - public FilterFragmentPostFilterRecyclerViewAdapter(OnItemClickListener onItemClickListener) { - this.onItemClickListener = onItemClickListener; - } - - @Override - public int getItemViewType(int position) { - if (position == 0) { - return VIEW_TYPE_HEADER; - } - return VIEW_TYPE_POST_FILTER; - } - - @NonNull - @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - if (viewType == VIEW_TYPE_HEADER) { - return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_fragment_header, parent, false)); - } else { - return new PostFilterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter, parent, false)); - } - } - - @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof PostFilterViewHolder) { - ((PostFilterViewHolder) holder).textView.setText(postFilterList.get(position - 1).name); - } - } - - @Override - public int getItemCount() { - return postFilterList == null ? 1 : 1 + postFilterList.size(); - } - - public void setPostFilterList(List postFilterList) { - this.postFilterList = postFilterList; - notifyDataSetChanged(); - } - - private class PostFilterViewHolder extends RecyclerView.ViewHolder { - TextView textView; - - public PostFilterViewHolder(@NonNull View itemView) { - super(itemView); - textView = (TextView) itemView; - itemView.setOnClickListener(view -> { - onItemClickListener.onItemClick(postFilterList.get(getAdapterPosition() - 1)); - }); - } - } - - private static class HeaderViewHolder extends RecyclerView.ViewHolder { - - public HeaderViewHolder(@NonNull View itemView) { - super(itemView); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java new file mode 100644 index 00000000..344e968c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java @@ -0,0 +1,85 @@ +package ml.docilealligator.infinityforreddit.adapters; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.postfilter.PostFilter; + +public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter { + + private static final int VIEW_TYPE_HEADER = 1; + private static final int VIEW_TYPE_POST_FILTER = 2; + + private final OnItemClickListener onItemClickListener; + private List postFilterList; + + public interface OnItemClickListener { + void onItemClick(PostFilter postFilter); + } + + public PostFilterRecyclerViewAdapter(OnItemClickListener onItemClickListener) { + this.onItemClickListener = onItemClickListener; + } + + @Override + public int getItemViewType(int position) { + if (position == 0) { + return VIEW_TYPE_HEADER; + } + return VIEW_TYPE_POST_FILTER; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + if (viewType == VIEW_TYPE_HEADER) { + return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_fragment_header, parent, false)); + } else { + return new PostFilterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter, parent, false)); + } + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof PostFilterViewHolder) { + ((PostFilterViewHolder) holder).textView.setText(postFilterList.get(position - 1).name); + } + } + + @Override + public int getItemCount() { + return postFilterList == null ? 1 : 1 + postFilterList.size(); + } + + public void setPostFilterList(List postFilterList) { + this.postFilterList = postFilterList; + notifyDataSetChanged(); + } + + private class PostFilterViewHolder extends RecyclerView.ViewHolder { + TextView textView; + + public PostFilterViewHolder(@NonNull View itemView) { + super(itemView); + textView = (TextView) itemView; + itemView.setOnClickListener(view -> { + onItemClickListener.onItemClick(postFilterList.get(getAdapterPosition() - 1)); + }); + } + } + + private static class HeaderViewHolder extends RecyclerView.ViewHolder { + + public HeaderViewHolder(@NonNull View itemView) { + super(itemView); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java index 75ed77db..af34d5a3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java @@ -36,17 +36,18 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.activities.BaseActivity; -import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.comment.CommentViewModel; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; +import ml.docilealligator.infinityforreddit.comment.CommentViewModel; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -289,6 +290,19 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni mCommentRecyclerView.setAdapter(mAdapter); + if (mActivity instanceof PostFragmentContentScrollingInterface) { + mCommentRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + ((PostFragmentContentScrollingInterface) mActivity).contentScrollDown(); + } else if (dy < 0) { + ((PostFragmentContentScrollingInterface) mActivity).contentScrollUp(); + } + } + }); + } + CommentViewModel.Factory factory; if (mAccessToken == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/DeletePostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/DeletePostFilter.java index 468c0498..0ed06ba8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/DeletePostFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/DeletePostFilter.java @@ -6,11 +6,6 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class DeletePostFilter { public static void deletePostFilter(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, PostFilter postFilter) { - executor.execute(new Runnable() { - @Override - public void run() { - redditDataRoomDatabase.postFilterDao().deletePostFilter(postFilter); - } - }); + executor.execute(() -> redditDataRoomDatabase.postFilterDao().deletePostFilter(postFilter)); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterDao.java index 6595db38..05a27120 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterDao.java @@ -26,6 +26,8 @@ public interface PostFilterDao { @Query("SELECT * FROM post_filter") LiveData> getAllPostFiltersLiveData(); - @Query("SELECT * FROM post_filter WHERE post_filter.name IN (SELECT post_filter_usage.name FROM post_filter_usage WHERE usage = :usage AND name_of_usage = :nameOfUsage)") + @Query("SELECT * FROM post_filter WHERE post_filter.name IN " + + "(SELECT post_filter_usage.name FROM post_filter_usage WHERE (usage = :usage AND name_of_usage = :nameOfUsage) " + + "OR (usage =:usage AND name_of_usage = '--'))") List getValidPostFilters(int usage, String nameOfUsage); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java deleted file mode 100644 index e76fd959..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java +++ /dev/null @@ -1,46 +0,0 @@ -package ml.docilealligator.infinityforreddit.readpost; - -import android.os.AsyncTask; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class FetchReadPosts { - - public interface FetchReadPostsListener { - void success(ArrayList readPosts); - } - - public static void fetchReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, String username, - FetchReadPostsListener fetchReadPostsListener) { - new FetchAllReadPostsAsyncTask(redditDataRoomDatabase, username, fetchReadPostsListener).execute(); - } - - private static class FetchAllReadPostsAsyncTask extends AsyncTask { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private String username; - private FetchReadPostsListener fetchReadPostsListener; - private ArrayList readPosts; - - private FetchAllReadPostsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username, - FetchReadPostsListener fetchReadPostsListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.username = username; - this.fetchReadPostsListener = fetchReadPostsListener; - } - - @Override - protected Void doInBackground(Void... voids) { - readPosts = (ArrayList) redditDataRoomDatabase.readPostDao().getAllReadPosts(username); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - fetchReadPostsListener.success(readPosts); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java index 60ddffe2..be548700 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java @@ -1,28 +1,13 @@ package ml.docilealligator.infinityforreddit.readpost; -import android.os.AsyncTask; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class InsertReadPost { - public static void insertReadPost(RedditDataRoomDatabase redditDataRoomDatabase, String username, String postId) { - new InsertReadPostAsyncTask(redditDataRoomDatabase, username, postId).execute(); - } - - private static class InsertReadPostAsyncTask extends AsyncTask { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private String username; - private String postId; - - public InsertReadPostAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username, String postId) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.username = username; - this.postId = postId; - } - - @Override - protected Void doInBackground(Void... voids) { + public static void insertReadPost(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, + String username, String postId) { + executor.execute(() -> { ReadPostDao readPostDao = redditDataRoomDatabase.readPostDao(); if (readPostDao.getReadPostsCount() > 500) { readPostDao.deleteOldestReadPosts(username); @@ -30,7 +15,6 @@ public class InsertReadPost { if (username != null && !username.equals("")) { readPostDao.insert(new ReadPost(username, postId)); } - return null; - } + }); } } -- cgit v1.2.3