diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-12-26 11:18:37 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-12-26 11:18:37 +0000 |
commit | 44c758204cff2b7b7b41fc5ccef7727457941d48 (patch) | |
tree | b2e9de017c41187935173b3b4f75df87ecdbf414 | |
parent | 60908860b790d69cedd8fde5d734875633a611a6 (diff) | |
download | infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.tar infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.tar.gz infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.tar.bz2 infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.tar.lz infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.tar.xz infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.tar.zst infinity-for-reddit-44c758204cff2b7b7b41fc5ccef7727457941d48.zip |
Use Executor to save read posts. Hide the fab and the bottom app bar when scrolling comments in ViewUserDetailActivity.
15 files changed, 75 insertions, 91 deletions
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; @@ -181,6 +183,16 @@ public class PostFilterUsageListingActivity extends BaseActivity { } @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/PostFilterRecyclerViewAdapter.java index a7cc4981..344e968c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FilterFragmentPostFilterRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java @@ -13,7 +13,7 @@ import java.util.List; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; -public class FilterFragmentPostFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { +public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int VIEW_TYPE_HEADER = 1; private static final int VIEW_TYPE_POST_FILTER = 2; @@ -25,7 +25,7 @@ public class FilterFragmentPostFilterRecyclerViewAdapter extends RecyclerView.Ad void onItemClick(PostFilter postFilter); } - public FilterFragmentPostFilterRecyclerViewAdapter(OnItemClickListener onItemClickListener) { + public PostFilterRecyclerViewAdapter(OnItemClickListener onItemClickListener) { this.onItemClickListener = onItemClickListener; } 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<List<PostFilter>> 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<PostFilter> 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<ReadPost> readPosts); - } - - public static void fetchReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, String username, - FetchReadPostsListener fetchReadPostsListener) { - new FetchAllReadPostsAsyncTask(redditDataRoomDatabase, username, fetchReadPostsListener).execute(); - } - - private static class FetchAllReadPostsAsyncTask extends AsyncTask<Void, Void, Void> { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private String username; - private FetchReadPostsListener fetchReadPostsListener; - private ArrayList<ReadPost> 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<ReadPost>) 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<Void, Void, Void> { - - 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; - } + }); } } |