mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Still implementing custom themes.
This commit is contained in:
parent
3dca261dea
commit
6ad725762b
@ -18,6 +18,9 @@ import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@ -28,11 +31,13 @@ import ml.docilealligator.infinityforreddit.AsyncTask.ChangeThemeNameAsyncTask;
|
||||
import ml.docilealligator.infinityforreddit.AsyncTask.DeleteThemeAsyncTask;
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel;
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
|
||||
import ml.docilealligator.infinityforreddit.Fragment.CustomThemeOptionsBottomSheetFragment;
|
||||
import ml.docilealligator.infinityforreddit.Fragment.SelectBaseThemeBottomSheetFragment;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils;
|
||||
|
||||
public class CustomThemeListingActivity extends BaseActivity implements CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener {
|
||||
|
||||
@ -51,6 +56,15 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh
|
||||
RedditDataRoomDatabase redditDataRoomDatabase;
|
||||
@Inject
|
||||
CustomThemeWrapper customThemeWrapper;
|
||||
@Inject
|
||||
@Named("light_theme")
|
||||
SharedPreferences lightThemeSharedPreferences;
|
||||
@Inject
|
||||
@Named("dark_theme")
|
||||
SharedPreferences darkThemeSharedPreferences;
|
||||
@Inject
|
||||
@Named("amoled_theme")
|
||||
SharedPreferences amoledThemeSharedPreferences;
|
||||
public CustomThemeViewModel customThemeViewModel;
|
||||
|
||||
@Override
|
||||
@ -62,6 +76,8 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
applyCustomTheme();
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
@ -125,7 +141,7 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(themeNameEditText.getWindowToken(), 0);
|
||||
}
|
||||
new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldName, themeNameEditText.getText().toString());
|
||||
new ChangeThemeNameAsyncTask(redditDataRoomDatabase, oldName, themeNameEditText.getText().toString()).execute();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
if (imm != null) {
|
||||
@ -142,6 +158,37 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTh
|
||||
|
||||
@Override
|
||||
public void delete(String name) {
|
||||
new DeleteThemeAsyncTask(redditDataRoomDatabase, name).execute();
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.delete_theme)
|
||||
.setMessage(getString(R.string.delete_theme_dialog_message, name))
|
||||
.setPositiveButton(R.string.yes, (dialogInterface, i)
|
||||
-> new DeleteThemeAsyncTask(redditDataRoomDatabase, name, (isLightTheme, isDarkTheme, isAmoledTheme) -> {
|
||||
if (isLightTheme) {
|
||||
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(
|
||||
CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), lightThemeSharedPreferences);
|
||||
}
|
||||
if (isDarkTheme) {
|
||||
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(
|
||||
CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), darkThemeSharedPreferences);
|
||||
}
|
||||
if (isAmoledTheme) {
|
||||
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(
|
||||
CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), amoledThemeSharedPreferences);
|
||||
}
|
||||
EventBus.getDefault().post(new RecreateActivityEvent());
|
||||
}).execute())
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) {
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor()));
|
||||
applyFABTheme(fab, R.drawable.ic_add_bottom_app_bar_24dp);
|
||||
applyFABTheme(fab, R.drawable.ic_add_day_night_24dp);
|
||||
}
|
||||
|
||||
private void getCurrentAccountAndBindView() {
|
||||
|
@ -258,6 +258,6 @@ public class MultiRedditListingActivity extends BaseActivity {
|
||||
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
|
||||
mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
|
||||
mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
|
||||
applyFABTheme(fab, R.drawable.ic_add_bottom_app_bar_24dp);
|
||||
applyFABTheme(fab, R.drawable.ic_add_day_night_24dp);
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
multiRedditBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
messageBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
profileBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
applyFABTheme(fab, R.drawable.ic_add_bottom_app_bar_24dp);
|
||||
applyFABTheme(fab, R.drawable.ic_add_day_night_24dp);
|
||||
unsubscribedColor = mCustomThemeWrapper.getUnsubscribed();
|
||||
subscribedColor = mCustomThemeWrapper.getSubscribed();
|
||||
}
|
||||
|
@ -2,20 +2,43 @@ package ml.docilealligator.infinityforreddit.AsyncTask;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
|
||||
public class DeleteThemeAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private RedditDataRoomDatabase redditDataRoomDatabase;
|
||||
private String themeName;
|
||||
private DeleteThemeAsyncTaskListener deleteThemeAsyncTaskListener;
|
||||
private boolean isLightTheme = false;
|
||||
private boolean isDarkTheme = false;
|
||||
private boolean isAmoledTheme = false;
|
||||
|
||||
public DeleteThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String themeName) {
|
||||
public interface DeleteThemeAsyncTaskListener {
|
||||
void success(boolean isLightTheme, boolean isDarkTheme, boolean isAmoledTheme);
|
||||
}
|
||||
|
||||
public DeleteThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String themeName,
|
||||
DeleteThemeAsyncTaskListener deleteThemeAsyncTaskListener) {
|
||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||
this.themeName = themeName;
|
||||
this.deleteThemeAsyncTaskListener = deleteThemeAsyncTaskListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
CustomTheme customTheme = redditDataRoomDatabase.customThemeDao().getCustomTheme(themeName);
|
||||
if (customTheme != null) {
|
||||
isLightTheme = customTheme.isLightTheme;
|
||||
isDarkTheme = customTheme.isDarkTheme;
|
||||
isAmoledTheme = customTheme.isAmoledTheme;
|
||||
redditDataRoomDatabase.customThemeDao().deleteCustomTheme(themeName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
deleteThemeAsyncTaskListener.success(isLightTheme, isDarkTheme, isAmoledTheme);
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:layout_gravity="bottom|end"
|
||||
app:backgroundTint="?attr/colorPrimaryLightTheme"
|
||||
app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp"
|
||||
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -78,7 +78,7 @@
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:layout_gravity="bottom|end"
|
||||
app:backgroundTint="?attr/colorPrimaryLightTheme"
|
||||
app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp"
|
||||
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -201,7 +201,7 @@
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="?attr/colorPrimaryLightTheme"
|
||||
app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp"
|
||||
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
||||
app:tint="@android:color/white"
|
||||
app:layout_anchor="@id/bottom_navigation_view_subreddit_detail_activity" />
|
||||
|
||||
|
@ -132,7 +132,7 @@
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="?attr/colorPrimaryLightTheme"
|
||||
app:srcCompat="@drawable/ic_add_bottom_app_bar_24dp"
|
||||
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
||||
app:tint="@android:color/white"
|
||||
app:layout_anchor="@id/bottom_navigation_main_activity" />
|
||||
|
||||
|
@ -29,6 +29,6 @@
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="32dp"
|
||||
android:src="@drawable/ic_add_24dp" />
|
||||
android:src="@drawable/ic_add_day_night_24dp" />
|
||||
|
||||
</LinearLayout>
|
@ -29,7 +29,7 @@
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="32dp"
|
||||
android:src="@drawable/ic_add_24dp"
|
||||
android:src="@drawable/ic_add_day_night_24dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<ImageView
|
||||
|
@ -365,7 +365,7 @@
|
||||
<string name="settings_customize_dark_theme_title">Dark Theme</string>
|
||||
<string name="settings_customize_amoled_theme_title">Amoled Theme</string>
|
||||
<string name="settings_manage_themes_title">Manage Themes</string>
|
||||
<string name="settings_custom_theme_cannot_apply_to_settings_page_title">Custom themes cannot be applied to settings page.</string>
|
||||
<string name="settings_custom_theme_cannot_apply_to_settings_page_title">Custom themes cannot be applied to settings page (except toolbar, status bar and navigation bar).</string>
|
||||
|
||||
<string name="no_link_available">Cannot get the link</string>
|
||||
|
||||
@ -617,6 +617,7 @@
|
||||
<string name="edit_theme_name">Edit Theme Name</string>
|
||||
<string name="edit_theme">Edit Theme</string>
|
||||
<string name="delete_theme">Delete Theme</string>
|
||||
<string name="delete_theme_dialog_message">Are you sure to delete %1$s?</string>
|
||||
<string name="share_theme">Share Theme</string>
|
||||
<string name="change_theme_name">Change Name</string>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user