From 440e39570cf6ae5335ad85f2ad4befca738f7e42 Mon Sep 17 00:00:00 2001 From: Pranav Pandey Date: Thu, 25 Jul 2024 04:45:25 +0530 Subject: [PATCH] Dynamic theme 4.6.0 Dynamic utils 4.6.1. Dynamic locale 2.5.0. Dynamic toasts 4.3.0. Dynamic preferences 2.4.0. Add support for product flavors. --- build.gradle | 10 +++++----- .../dynamic/support/DynamicApplication.java | 11 +++++++++-- .../support/activity/DynamicSystemActivity.java | 12 ++++++++++-- .../dialog/fragment/DynamicDialogFragment.java | 12 ++++++++++-- .../support/fragment/DynamicFragment.java | 14 +++++++++++--- .../support/listener/DynamicListener.java | 5 +++-- .../dynamic/support/popup/base/DynamicPopup.java | 11 +++++++++-- .../preview/activity/DynamicPreviewActivity.java | 4 ++-- .../setting/theme/ThemeReceiverPreference.java | 10 +++++++--- .../dynamic/support/theme/DynamicTheme.java | 11 +++++++++-- .../support/theme/DynamicThemeHandler.java | 16 ++++++++++++++-- .../support/theme/view/DynamicPresetsView.java | 5 +++-- 12 files changed, 92 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 87095a7964..5d53c4d188 100644 --- a/build.gradle +++ b/build.gradle @@ -21,16 +21,16 @@ buildscript { 'targetSdk' : 35, 'buildTools' : '35.0.0', 'multidex' : '2.0.1', - 'dynamic' : '4.5.1', + 'dynamic' : '4.6.1', 'fragment' : '1.7.0', 'flexbox' : '3.0.0', 'kotlin' : '1.9.24', - 'locale' : '2.4.0', + 'locale' : '2.5.0', 'material' : '1.12.0', - 'preferences' : '2.3.1', + 'preferences' : '2.4.0', 'swiperefresh': '1.1.0', - 'theme' : '4.5.1', - 'toasts' : '4.2.1', + 'theme' : '4.6.0', + 'toasts' : '4.3.0', 'work' : '2.8.1' ] diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java index 5d0e4406bc..7b7dd6c67b 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/DynamicApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import com.pranavpandey.android.dynamic.locale.DynamicLocaleUtils; import com.pranavpandey.android.dynamic.preferences.DynamicPreferences; import com.pranavpandey.android.dynamic.support.listener.DynamicListener; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; import com.pranavpandey.android.dynamic.support.listener.DynamicResolver; import com.pranavpandey.android.dynamic.support.model.DynamicAppTheme; import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; @@ -44,6 +45,7 @@ import com.pranavpandey.android.dynamic.theme.Theme; import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; import com.pranavpandey.android.dynamic.util.loader.DynamicLoader; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; import java.util.Locale; @@ -52,7 +54,7 @@ * and to perform theme change operations. */ public abstract class DynamicApplication extends Application - implements androidx.work.Configuration.Provider, DynamicLocale, + implements androidx.work.Configuration.Provider, DynamicProductFlavor, DynamicLocale, DynamicListener, SharedPreferences.OnSharedPreferenceChangeListener { /** @@ -196,6 +198,11 @@ public float getFontScale() { : DynamicTheme.getInstance().getDefault(false).getFontScaleRelative(); } + @Override + public @DynamicFlavor String getProductFlavor() { + return DynamicFlavor.DEFAULT; + } + @Override public @NonNull Context getContext() { return mContext != null ? mContext : getBaseContext() != null diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java index f5328da8e6..e00cbbf93e 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,6 +66,7 @@ import com.pranavpandey.android.dynamic.support.R; import com.pranavpandey.android.dynamic.support.intent.DynamicIntent; import com.pranavpandey.android.dynamic.support.listener.DynamicListener; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; import com.pranavpandey.android.dynamic.support.listener.DynamicTransitionListener; import com.pranavpandey.android.dynamic.support.motion.DynamicMotion; import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; @@ -84,6 +85,7 @@ import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; import com.pranavpandey.android.dynamic.util.DynamicViewUtils; import com.pranavpandey.android.dynamic.util.DynamicWindowUtils; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; import java.io.Serializable; import java.util.HashMap; @@ -100,7 +102,7 @@ */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public abstract class DynamicSystemActivity extends AppCompatActivity - implements DynamicLocale, DynamicListener, DynamicTransitionListener, + implements DynamicProductFlavor, DynamicLocale, DynamicListener, DynamicTransitionListener, SharedPreferences.OnSharedPreferenceChangeListener { /** @@ -1645,6 +1647,11 @@ public void onDestroy() { super.onDestroy(); } + @Override + public @DynamicFlavor String getProductFlavor() { + return DynamicTheme.getInstance().getProductFlavor(); + } + @Override public @NonNull Context getContext() { return mContext != null ? mContext : getBaseContext(); @@ -1782,6 +1789,7 @@ protected void updateTaskDescription(@ColorInt int color) { } } + @SuppressLint("MissingSuperCall") @Override public void onBackPressed() { finishActivity(); diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/dialog/fragment/DynamicDialogFragment.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/dialog/fragment/DynamicDialogFragment.java index e65561f994..cb853f8a2b 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/dialog/fragment/DynamicDialogFragment.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/dialog/fragment/DynamicDialogFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,8 +41,11 @@ import com.pranavpandey.android.dynamic.support.Dynamic; import com.pranavpandey.android.dynamic.support.activity.DynamicSystemActivity; import com.pranavpandey.android.dynamic.support.dialog.DynamicDialog; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; +import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; import com.pranavpandey.android.dynamic.support.util.DynamicResourceUtils; import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; /** * Base dialog fragment to provide all the functionality of {@link DynamicDialog} inside a @@ -52,7 +55,7 @@ * @see #onCustomiseDialog(DynamicDialog, View, Bundle) */ public class DynamicDialogFragment extends AppCompatDialogFragment - implements SharedPreferences.OnSharedPreferenceChangeListener { + implements DynamicProductFlavor, SharedPreferences.OnSharedPreferenceChangeListener { /** * Default button color. it will be used internally if there is no button color is applied. @@ -233,6 +236,11 @@ public boolean onKey(DialogInterface dialogInterface, protected void onCustomiseDialog(@NonNull DynamicDialog alertDialog, @Nullable View view, @Nullable Bundle savedInstanceState) { } + @Override + public @DynamicFlavor String getProductFlavor() { + return DynamicTheme.getInstance().getProductFlavor(); + } + /** * Returns whether to register a shared preferences listener for this fragment. * diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/fragment/DynamicFragment.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/fragment/DynamicFragment.java index 78e0c81378..593b1aa6a7 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/fragment/DynamicFragment.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/fragment/DynamicFragment.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,12 +53,15 @@ import com.pranavpandey.android.dynamic.support.activity.DynamicStateActivity; import com.pranavpandey.android.dynamic.support.activity.DynamicSystemActivity; import com.pranavpandey.android.dynamic.support.listener.DynamicLifecycle; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; import com.pranavpandey.android.dynamic.support.listener.DynamicSearchListener; import com.pranavpandey.android.dynamic.support.listener.DynamicTransitionListener; import com.pranavpandey.android.dynamic.support.motion.DynamicMotion; +import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; import com.pranavpandey.android.dynamic.support.util.DynamicMenuUtils; import com.pranavpandey.android.dynamic.support.util.DynamicResourceUtils; import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; /** * Base fragment class to provide basic functionality and to work with the {@link DynamicActivity}. @@ -66,8 +69,8 @@ */ @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) -public class DynamicFragment extends Fragment implements DynamicLifecycle, - DynamicTransitionListener, DynamicSearchListener, MenuProvider, +public class DynamicFragment extends Fragment implements DynamicProductFlavor, + DynamicLifecycle, DynamicTransitionListener, DynamicSearchListener, MenuProvider, SharedPreferences.OnSharedPreferenceChangeListener { /** @@ -584,6 +587,11 @@ public void onSaveInstanceState(@NonNull Bundle outState) { mSearchViewExpanded); } + @Override + public @DynamicFlavor String getProductFlavor() { + return DynamicTheme.getInstance().getProductFlavor(); + } + /** * Get the current saved instance state for this fragment. * diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/listener/DynamicListener.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/listener/DynamicListener.java index 4531859c39..47f6136ee2 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/listener/DynamicListener.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/listener/DynamicListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,11 +32,12 @@ import com.pranavpandey.android.dynamic.theme.AppTheme; import com.pranavpandey.android.dynamic.theme.DynamicColors; import com.pranavpandey.android.dynamic.theme.Theme; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; /** * An interface to listen the dynamic change events. */ -public interface DynamicListener { +public interface DynamicListener extends DynamicProductFlavor { /** * Returns the context used by this listener. diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/popup/base/DynamicPopup.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/popup/base/DynamicPopup.java index c5ba6ed829..723f8ad744 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/popup/base/DynamicPopup.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/popup/base/DynamicPopup.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,12 +39,14 @@ import com.pranavpandey.android.dynamic.support.Dynamic; import com.pranavpandey.android.dynamic.support.R; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; import com.pranavpandey.android.dynamic.support.motion.DynamicMotion; import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; import com.pranavpandey.android.dynamic.support.util.DynamicResourceUtils; import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; import com.pranavpandey.android.dynamic.util.DynamicViewUtils; import com.pranavpandey.android.dynamic.util.DynamicWindowUtils; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -53,7 +55,7 @@ * Base {@link PopupWindow} to provide the basic functionality to its descendants. *

Extend this class to create popup windows according to the requirements. */ -public abstract class DynamicPopup { +public abstract class DynamicPopup implements DynamicProductFlavor { /** * Interface to hold the view types supported by the popup. @@ -419,4 +421,9 @@ public void dismiss() { getPopupWindow().dismiss(); } } + + @Override + public @DynamicFlavor String getProductFlavor() { + return DynamicTheme.getInstance().getProductFlavor(); + } } diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/preview/activity/DynamicPreviewActivity.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/preview/activity/DynamicPreviewActivity.java index dddae134aa..a0da8e98fe 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/preview/activity/DynamicPreviewActivity.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/preview/activity/DynamicPreviewActivity.java @@ -238,8 +238,8 @@ public void onPreviewClick() { DynamicLinkUtils.viewUrl(DynamicPreviewActivity.this, getPreview().getInfo()); } else { - DynamicLinkUtils.share(DynamicPreviewActivity.this, - (String) getTitle(), getPreview().getInfo(), null); + DynamicLinkUtils.share(DynamicPreviewActivity.this, (String) getTitle(), + getPreview().getInfo(), null, getProductFlavor()); } } diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/setting/theme/ThemeReceiverPreference.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/setting/theme/ThemeReceiverPreference.java index ea7d22a0bd..32de2d2dcb 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/setting/theme/ThemeReceiverPreference.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/setting/theme/ThemeReceiverPreference.java @@ -28,6 +28,7 @@ import com.pranavpandey.android.dynamic.support.R; import com.pranavpandey.android.dynamic.support.permission.DynamicPermissions; import com.pranavpandey.android.dynamic.support.setting.base.DynamicSpinnerPreference; +import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; import com.pranavpandey.android.dynamic.theme.ThemeContract; import com.pranavpandey.android.dynamic.util.DynamicLinkUtils; import com.pranavpandey.android.dynamic.util.DynamicPackageUtils; @@ -55,6 +56,9 @@ public ThemeReceiverPreference(@NonNull Context context, protected void onInflate() { super.onInflate(); + setDescription(String.format(getContext().getString(R.string.ads_theme_presets_desc_app), + getContext().getString(R.string.ads_theme_presets_app)), false); + setActionButton(getContext().getString(R.string.ads_perm_info_required), new View.OnClickListener() { @Override @@ -64,8 +68,8 @@ public void onClick(View v) { DynamicPermissions.getInstance().isGranted( ThemeContract.Preset.RECEIVER_PERMISSIONS, true); } else { - DynamicLinkUtils.viewInGooglePlay(getContext(), - ThemeContract.Preset.AUTHORITY); + DynamicLinkUtils.viewApp(getContext(), ThemeContract.Preset.AUTHORITY, + DynamicTheme.getInstance().getProductFlavor()); } } }); @@ -81,7 +85,7 @@ protected void onUpdate() { Dynamic.setVisibility(getActionView(), DynamicPermissions.getInstance().isGranted( ThemeContract.Preset.RECEIVER_PERMISSIONS, false) ? GONE :VISIBLE); } else { - Dynamic.setText(getActionView(), R.string.ads_info_google_play); + Dynamic.setText(getActionView(), R.string.ads_download); Dynamic.setVisibility(getDescriptionView(), VISIBLE); Dynamic.setVisibility(getActionView(), VISIBLE); } diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicTheme.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicTheme.java index ab840c8fdd..a56c9c2870 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicTheme.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicTheme.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,7 @@ import com.pranavpandey.android.dynamic.support.Dynamic; import com.pranavpandey.android.dynamic.support.R; import com.pranavpandey.android.dynamic.support.listener.DynamicListener; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; import com.pranavpandey.android.dynamic.support.listener.DynamicResolver; import com.pranavpandey.android.dynamic.support.model.DynamicAppTheme; import com.pranavpandey.android.dynamic.support.model.DynamicRemoteTheme; @@ -74,6 +75,7 @@ import com.pranavpandey.android.dynamic.util.DynamicTaskUtils; import com.pranavpandey.android.dynamic.util.DynamicUnitUtils; import com.pranavpandey.android.dynamic.util.concurrent.DynamicResult; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -91,7 +93,7 @@ * heavily dependent on this class to generate colors dynamically. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) -public class DynamicTheme implements DynamicListener, DynamicResolver { +public class DynamicTheme implements DynamicProductFlavor, DynamicListener, DynamicResolver { /** * Constant values for the theme styles version. @@ -1635,6 +1637,11 @@ public void clearDynamicListeners() { getDynamicThemes().clear(); } + @Override + public @DynamicFlavor String getProductFlavor() { + return getHandler().getProductFlavor(); + } + @Override public @NonNull Context getContext() { return getHandler().getContext(); diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicThemeHandler.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicThemeHandler.java index 874889750f..b1f0fca20c 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicThemeHandler.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/DynamicThemeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Pranav Pandey + * Copyright 2018-2024 Pranav Pandey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ import com.pranavpandey.android.dynamic.theme.AppTheme; import com.pranavpandey.android.dynamic.theme.DynamicColors; import com.pranavpandey.android.dynamic.theme.Theme; +import com.pranavpandey.android.dynamic.util.product.DynamicFlavor; +import com.pranavpandey.android.dynamic.util.product.DynamicProductFlavor; import java.util.List; @@ -38,7 +40,7 @@ * * @see Looper#getMainLooper() */ -public class DynamicThemeHandler extends Handler implements DynamicListener { +public class DynamicThemeHandler extends Handler implements DynamicProductFlavor, DynamicListener { /** * Message constant to post the dynamic theme changes. @@ -263,6 +265,16 @@ public void clearListeners() { } } + @Override + public @DynamicFlavor String getProductFlavor() { + DynamicListener listener; + if ((listener = resolveListener(false)) == null) { + return DynamicFlavor.DEFAULT; + } + + return listener.getProductFlavor(); + } + @Override public @NonNull Context getContext() { DynamicListener listener; diff --git a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/view/DynamicPresetsView.java b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/view/DynamicPresetsView.java index 4847acc09a..f9b29ac277 100644 --- a/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/view/DynamicPresetsView.java +++ b/dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/view/DynamicPresetsView.java @@ -43,6 +43,7 @@ import com.pranavpandey.android.dynamic.support.motion.DynamicMotion; import com.pranavpandey.android.dynamic.support.permission.DynamicPermissions; import com.pranavpandey.android.dynamic.support.recyclerview.DynamicRecyclerViewNested; +import com.pranavpandey.android.dynamic.support.theme.DynamicTheme; import com.pranavpandey.android.dynamic.support.theme.adapter.DynamicPresetsAdapter; import com.pranavpandey.android.dynamic.support.util.DynamicLayoutUtils; import com.pranavpandey.android.dynamic.support.view.base.DynamicItemView; @@ -177,8 +178,8 @@ public void onClick(View v) { loadPresets(); } } else { - DynamicLinkUtils.viewInGooglePlay(getContext(), - ThemeContract.Preset.AUTHORITY); + DynamicLinkUtils.viewApp(getContext(), ThemeContract.Preset.AUTHORITY, + DynamicTheme.getInstance().getProductFlavor()); } } });