diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-03-29 02:46:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-03-29 02:46:55 +0000 |
commit | ea27af4080ff6056dd260501cc91b8b2ac4f716f (patch) | |
tree | f59fd11890dd88a914bc09e9f536b9c00ef72438 /app/src/main/java/ml | |
parent | a5a5e6dac24ad08cf57abfcf16551832265fa425 (diff) | |
download | infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.tar infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.tar.gz infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.tar.bz2 infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.tar.lz infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.tar.xz infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.tar.zst infinity-for-reddit-ea27af4080ff6056dd260501cc91b8b2ac4f716f.zip |
Continue playing videos after orientation. Deleting all subreddits and users is now available in advanced settings.
Diffstat (limited to '')
4 files changed, 125 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 17b2be5c..bdc69bcd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -46,6 +46,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment; import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; +import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; @@ -149,4 +150,6 @@ public interface AppComponent { void inject(CustomThemeListingActivity customThemeListingActivity); void inject(SidebarFragment sidebarFragment); + + void inject(AdvancedPreferenceFragment advancedPreferenceFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSubredditsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSubredditsAsyncTask.java new file mode 100644 index 00000000..db39f9c1 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSubredditsAsyncTask.java @@ -0,0 +1,33 @@ +package ml.docilealligator.infinityforreddit.AsyncTask; + +import android.os.AsyncTask; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllSubredditsAsyncTask extends AsyncTask<Void, Void, Void> { + + private RedditDataRoomDatabase redditDataRoomDatabase; + private DeleteAllSubredditsAsyncTaskListener deleteAllSubredditsAsyncTaskListener; + + public interface DeleteAllSubredditsAsyncTaskListener { + void success(); + } + + public DeleteAllSubredditsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, + DeleteAllSubredditsAsyncTaskListener deleteAllSubredditsAsyncTaskListener) { + this.redditDataRoomDatabase = redditDataRoomDatabase; + this.deleteAllSubredditsAsyncTaskListener = deleteAllSubredditsAsyncTaskListener; + } + + @Override + protected Void doInBackground(Void... voids) { + redditDataRoomDatabase.subredditDao().deleteAllSubreddits(); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + deleteAllSubredditsAsyncTaskListener.success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllUsersAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllUsersAsyncTask.java new file mode 100644 index 00000000..d73f749c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllUsersAsyncTask.java @@ -0,0 +1,33 @@ +package ml.docilealligator.infinityforreddit.AsyncTask; + +import android.os.AsyncTask; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class DeleteAllUsersAsyncTask extends AsyncTask<Void, Void, Void> { + + private RedditDataRoomDatabase redditDataRoomDatabase; + private DeleteAllUsersAsyncTaskListener deleteAllUsersAsyncTaskListener; + + public interface DeleteAllUsersAsyncTaskListener { + void success(); + } + + public DeleteAllUsersAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, + DeleteAllUsersAsyncTaskListener deleteAllUsersAsyncTaskListener) { + this.redditDataRoomDatabase = redditDataRoomDatabase; + this.deleteAllUsersAsyncTaskListener = deleteAllUsersAsyncTaskListener; + } + + @Override + protected Void doInBackground(Void... voids) { + redditDataRoomDatabase.userDao().deleteAllUsers(); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + deleteAllUsersAsyncTaskListener.success(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java index 7af72c72..5101e60c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java @@ -1,12 +1,25 @@ package ml.docilealligator.infinityforreddit.Settings; +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; +import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import javax.inject.Inject; +import javax.inject.Named; + +import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllSubredditsAsyncTask; +import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllUsersAsyncTask; +import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; /** @@ -14,13 +27,56 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; */ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + private Activity activity; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.advanced_preferences, rootKey); + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + Preference deleteSubredditsPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SUBREDDITS_DATA_IN_DATABASE); Preference deleteUsersPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_USERS_DATA_IN_DATABASE); Preference deleteSortTypePreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE); Preference deletePostLaoutPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE); + + deleteSubredditsPreference.setOnPreferenceClickListener(preference -> { + new DeleteAllSubredditsAsyncTask(mRedditDataRoomDatabase, + () -> Toast.makeText(activity, R.string.delete_all_subreddits_success, Toast.LENGTH_SHORT).show()).execute(); + return true; + }); + + deleteUsersPreference.setOnPreferenceClickListener(preference -> { + new DeleteAllUsersAsyncTask(mRedditDataRoomDatabase, + () -> Toast.makeText(activity, R.string.delete_all_users_success, Toast.LENGTH_SHORT).show()).execute(); + return true; + }); + + deleteSortTypePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + + return false; + } + }); + + deletePostLaoutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + + return false; + } + }); + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (AppCompatActivity) context; } } |