Continue playing videos after orientation. Deleting all subreddits and users is now available in advanced settings.

This commit is contained in:
Alex Ning 2020-03-29 10:46:55 +08:00
parent a5a5e6dac2
commit ea27af4080
6 changed files with 129 additions and 3 deletions

View File

@ -267,7 +267,8 @@
<activity
android:name=".Activity.ViewVideoActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.ActionBar.Transparent" />
android:theme="@style/AppTheme.ActionBar.Transparent"
android:configChanges="orientation|screenSize|layoutDirection" />
<activity
android:name=".Activity.ViewPostDetailActivity"
android:parentActivityName=".Activity.MainActivity"

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -643,7 +643,7 @@
<string name="color_picker">Color Picker</string>
<string name="invalid_color">Invalid Color</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="delete_all_subreddits_success">Delete all subreddits successful</string>
<string name="delete_all_users_success">Delete all users successful</string>
</resources>