Fix some issues of custom themes.

This commit is contained in:
Alex Ning 2020-03-28 20:18:25 +08:00
parent 01b2a04057
commit 188d58b5da
2 changed files with 22 additions and 13 deletions

View File

@ -9,6 +9,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
@ -268,7 +269,8 @@ public class CustomThemeListingActivity extends BaseActivity implements
new InsertCustomThemeAsyncTask.InsertCustomThemeAsyncTaskListener() { new InsertCustomThemeAsyncTask.InsertCustomThemeAsyncTaskListener() {
@Override @Override
public void success() { public void success() {
Snackbar.make(coordinatorLayout, R.string.import_theme_success, Snackbar.LENGTH_SHORT).show(); Toast.makeText(CustomThemeListingActivity.this, R.string.import_theme_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new RecreateActivityEvent());
} }
@Override @Override

View File

@ -39,24 +39,31 @@ public class InsertCustomThemeAsyncTask extends AsyncTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
if (customTheme.isLightTheme) {
redditDataRoomDatabase.customThemeDao().unsetLightTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences);
}
if (customTheme.isDarkTheme) {
redditDataRoomDatabase.customThemeDao().unsetDarkTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences);
}
if (customTheme.isAmoledTheme) {
redditDataRoomDatabase.customThemeDao().unsetAmoledTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences);
}
if (checkDuplicate) { if (checkDuplicate) {
if (redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name) != null) { if (redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name) != null) {
isDuplicate = true; isDuplicate = true;
return null; return null;
} }
} }
CustomTheme previousTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(customTheme.name);
if (customTheme.isLightTheme) {
redditDataRoomDatabase.customThemeDao().unsetLightTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences);
} else if (previousTheme.isLightTheme) {
lightThemeSharedPreferences.edit().clear().apply();
}
if (customTheme.isDarkTheme) {
redditDataRoomDatabase.customThemeDao().unsetDarkTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences);
} else if (previousTheme.isDarkTheme) {
darkThemeSharedPreferences.edit().clear().apply();
}
if (customTheme.isAmoledTheme) {
redditDataRoomDatabase.customThemeDao().unsetAmoledTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences);
} else if (previousTheme.isAmoledTheme) {
amoledThemeSharedPreferences.edit().clear().apply();
}
redditDataRoomDatabase.customThemeDao().insert(customTheme); redditDataRoomDatabase.customThemeDao().insert(customTheme);
return null; return null;
} }