From 64bf15604fdd21ff481a8d02e25057d6088d96b5 Mon Sep 17 00:00:00 2001 From: MoralNorm <732388462@qq.com> Date: Wed, 7 Feb 2024 18:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4Tips=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hyperceiler/prefs/TipsPreference.java | 36 +++++++++++++++++++ .../hyperceiler/ui/base/BaseActivity.java | 4 --- .../ui/base/BaseSettingsActivity.java | 10 ++++-- .../ui/base/NavigationActivity.java | 9 +---- .../hyperceiler/ui/base/SettingsActivity.java | 2 +- .../fragment/base/BasePreferenceFragment.java | 8 ++--- .../ui/fragment/base/FragmentProxy.java | 2 +- .../ui/fragment/base/NavigatorFragment.java | 2 +- .../base/TabNavigatorContentFragment.java | 30 ++-------------- .../navigation/AboutPageFragment.java | 2 +- .../navigation/HomePageFragment.java | 26 +++++++++++--- .../navigation/SettingsPageFragment.java | 2 +- app/src/main/res/xml/prefs_main.xml | 10 +++--- 13 files changed, 80 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/com/sevtinge/hyperceiler/prefs/TipsPreference.java rename app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/{ => base}/navigation/AboutPageFragment.java (98%) rename app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/{ => base}/navigation/HomePageFragment.java (85%) rename app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/{ => base}/navigation/SettingsPageFragment.java (98%) diff --git a/app/src/main/java/com/sevtinge/hyperceiler/prefs/TipsPreference.java b/app/src/main/java/com/sevtinge/hyperceiler/prefs/TipsPreference.java new file mode 100644 index 0000000000..f362babd4a --- /dev/null +++ b/app/src/main/java/com/sevtinge/hyperceiler/prefs/TipsPreference.java @@ -0,0 +1,36 @@ +package com.sevtinge.hyperceiler.prefs; + +import android.content.Context; +import android.util.AttributeSet; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.sevtinge.hyperceiler.ui.MainActivityContextHelper; + +import fan.preference.Preference; + +public class TipsPreference extends Preference { + + MainActivityContextHelper mainActivityContextHelper; + + public TipsPreference(@NonNull Context context) { + this(context, null); + } + + public TipsPreference(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public TipsPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + setEnabled(false); + updateTips(); + } + + public void updateTips() { + mainActivityContextHelper = new MainActivityContextHelper(getContext()); + String tip = mainActivityContextHelper.getRandomTip(); + setSummary("Tips: " + tip); + } +} diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseActivity.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseActivity.java index e4ee37ad22..caf7e1ecd7 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseActivity.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseActivity.java @@ -68,10 +68,6 @@ protected void hideActionBar() { getAppCompatActionBar().hide(); } - public void setDisplayHomeAsUpEnabled(boolean isEnable) { - getAppCompatActionBar().setDisplayHomeAsUpEnabled(isEnable); - } - /*public void setActionBarEndView(View view) { getAppCompatActionBar().setEndView(view); }*/ diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseSettingsActivity.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseSettingsActivity.java index e410ad18d4..8c90f05712 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseSettingsActivity.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/BaseSettingsActivity.java @@ -32,12 +32,13 @@ import java.util.List; import fan.appcompat.app.AlertDialog; +import fan.external.view.weatherview.HolidayTheme; +import fan.external.view.weatherview.HolidayThemeHelper; public abstract class BaseSettingsActivity extends BaseActivity { private String initialFragmentName; public Fragment mFragment; - public static List mActivityList = new ArrayList<>(); @Override public void onCreate(Bundle savedInstanceState) { @@ -52,12 +53,17 @@ public void onCreate(Bundle savedInstanceState) { protected void createUiFromIntent(Bundle savedInstanceState, Intent intent) { mProxy.setupContentView(); - mActivityList.add(this); Fragment targetFragment = mProxy.getTargetFragment(this, initialFragmentName, savedInstanceState); if (targetFragment != null) { targetFragment.setArguments(mProxy.getArguments(intent)); setFragment(targetFragment); } + HolidayThemeHelper.setup(this, + findViewById(R.id.weather_view), + findViewById(R.id.holiday_header), + HolidayTheme.THEME_AUTO, + getWindowManager().getDefaultDisplay().getRotation() + ); } public void showRestartSystemDialog() { diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java index 99e6e078da..df4a3725c3 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java @@ -32,20 +32,13 @@ import fan.preference.PreferenceFragment; import fan.preference.internal.compat.PreferenceFragmentCompat; -public abstract class NavigationActivity extends BaseActivity implements PreferenceFragment.OnPreferenceStartFragmentCallback { +public abstract class NavigationActivity extends SettingsActivity implements PreferenceFragment.OnPreferenceStartFragmentCallback { public abstract int getBottomTabMenu(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.settings_sub); - HolidayThemeHelper.setup(this, - findViewById(R.id.weather_view), - findViewById(R.id.holiday_header), - HolidayTheme.THEME_AUTO, - getWindowManager().getDefaultDisplay().getRotation() - ); setFragment(new TabNavigatorContentFragment()); /*setRestartView(view -> DialogHelper.showRestartDialog(this));*/ } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/SettingsActivity.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/SettingsActivity.java index ec2247e64e..85a8b3a7b3 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/SettingsActivity.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/SettingsActivity.java @@ -22,6 +22,7 @@ import androidx.annotation.NonNull; +import com.sevtinge.hyperceiler.R; import com.sevtinge.hyperceiler.ui.SubSettings; import com.sevtinge.hyperceiler.ui.fragment.framework.OtherSettings; import com.sevtinge.hyperceiler.ui.fragment.home.HomeDockSettings; @@ -31,7 +32,6 @@ import com.sevtinge.hyperceiler.ui.fragment.various.AlertDialogSettings; import fan.preference.Preference; -import fan.preference.internal.compat.PreferenceFragmentCompat; import fan.preference.internal.compat.PreferenceFragmentCompat2; public abstract class SettingsActivity extends BaseSettingsActivity implements fan.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/BasePreferenceFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/BasePreferenceFragment.java index d037790fcd..d092a44fd1 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/BasePreferenceFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/BasePreferenceFragment.java @@ -41,14 +41,10 @@ public class BasePreferenceFragment extends PreferenceFragmentCompat { - private PreferenceManager mPreferenceManager; - @Override public void onCreatePreferences(Bundle bundle, String s) { - mPreferenceManager = getPreferenceManager(); - mPreferenceManager.setSharedPreferencesName(PrefsUtils.mPrefsName); - mPreferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE); - mPreferenceManager.setStorageDeviceProtected(); + FragmentProxy mProxy = new FragmentProxy(this); + mProxy.onCreatePreferenceManager(getPreferenceManager()); } public void setTitle(int titleResId) { diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/FragmentProxy.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/FragmentProxy.java index 66dd39921f..91bd59a759 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/FragmentProxy.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/FragmentProxy.java @@ -18,7 +18,7 @@ public class FragmentProxy { public FragmentProxy(Fragment fragment) { } - public void onCreatePreferences(PreferenceManager preferenceManager) { + public void onCreatePreferenceManager(PreferenceManager preferenceManager) { preferenceManager.setSharedPreferencesName(PrefsUtils.mPrefsName); preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE); preferenceManager.setStorageDeviceProtected(); diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/NavigatorFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/NavigatorFragment.java index 316db184a7..1a0c74c884 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/NavigatorFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/NavigatorFragment.java @@ -20,7 +20,7 @@ public abstract class NavigatorFragment extends PreferenceFragment { @Override public void onCreatePreferences(@Nullable Bundle bundle, @Nullable String s) { FragmentProxy mProxy = new FragmentProxy(this); - mProxy.onCreatePreferences(getPreferenceManager()); + mProxy.onCreatePreferenceManager(getPreferenceManager()); if (getContentResId() != 0) { setPreferencesFromResource(getContentResId(), s); initPrefs(); diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/TabNavigatorContentFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/TabNavigatorContentFragment.java index e194ffbacb..771f9eee51 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/TabNavigatorContentFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/TabNavigatorContentFragment.java @@ -2,8 +2,6 @@ import android.graphics.Color; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; @@ -22,11 +20,10 @@ import com.sevtinge.hyperceiler.R; import com.sevtinge.hyperceiler.data.adapter.ModSearchAdapter; import com.sevtinge.hyperceiler.data.adapter.NavigationPagerAdapter; -import com.sevtinge.hyperceiler.ui.MainActivityContextHelper; import com.sevtinge.hyperceiler.ui.SubSettings; -import com.sevtinge.hyperceiler.ui.fragment.navigation.AboutPageFragment; -import com.sevtinge.hyperceiler.ui.fragment.navigation.HomePageFragment; -import com.sevtinge.hyperceiler.ui.fragment.navigation.SettingsPageFragment; +import com.sevtinge.hyperceiler.ui.fragment.base.navigation.AboutPageFragment; +import com.sevtinge.hyperceiler.ui.fragment.base.navigation.HomePageFragment; +import com.sevtinge.hyperceiler.ui.fragment.base.navigation.SettingsPageFragment; import com.sevtinge.hyperceiler.utils.Helpers; import com.sevtinge.hyperceiler.utils.SearchModeHelper; import com.sevtinge.hyperceiler.utils.SettingLauncherHelper; @@ -80,19 +77,6 @@ public void afterTextChanged(Editable s) { AboutPageFragment mAboutPage = new AboutPageFragment(); NavigationPagerAdapter mNavigationPagerAdapter; List mFragmentList = new ArrayList<>(); - MainActivityContextHelper mainActivityContextHelper; - Handler mHandler = new Handler() { - @Override - public void handleMessage(@NonNull Message msg) { - super.handleMessage(msg); - if (msg.what == 0x11) { - updateSearchHint();//在这里写需要刷新完成的代码 - removeMessages(0x11); - sendEmptyMessageDelayed(0x11, 10000);//这里想几秒刷新一次就写几秒*/ - } - } - }; - @Override public void onCreate(Bundle bundle) { @@ -115,8 +99,6 @@ public void onViewCreated(View view, Bundle bundle) { super.onViewCreated(view, bundle); initSearchView(view); initNavigationView(view); - Message message = mHandler.obtainMessage(0x11); - mHandler.sendMessageDelayed(message, 3000); } private void initSearchView(View view) { @@ -131,12 +113,6 @@ private void initSearchView(View view) { mSearchAdapter.setOnItemClickListener(onSearchItemClickListener); } - private void updateSearchHint() { - mainActivityContextHelper = new MainActivityContextHelper(requireContext()); - String randomTip = mainActivityContextHelper.getRandomTip(); - mSearchInputView.setHint("Tip: " + randomTip); - } - private void initNavigationView(View view) { mFragmentPage = view.findViewById(R.id.frame_page); mNavigationView = view.findViewById(R.id.navigation); diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/AboutPageFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/AboutPageFragment.java similarity index 98% rename from app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/AboutPageFragment.java rename to app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/AboutPageFragment.java index f890ebb765..2143e542a9 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/AboutPageFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/AboutPageFragment.java @@ -1,4 +1,4 @@ -package com.sevtinge.hyperceiler.ui.fragment.navigation; +package com.sevtinge.hyperceiler.ui.fragment.base.navigation; import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion; diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/HomePageFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/HomePageFragment.java similarity index 85% rename from app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/HomePageFragment.java rename to app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/HomePageFragment.java index 5d238b7661..c030c3234f 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/HomePageFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/HomePageFragment.java @@ -1,4 +1,4 @@ -package com.sevtinge.hyperceiler.ui.fragment.navigation; +package com.sevtinge.hyperceiler.ui.fragment.base.navigation; import static com.sevtinge.hyperceiler.utils.api.VoyagerApisKt.isPad; import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getBaseOs; @@ -7,6 +7,8 @@ import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; @@ -22,6 +24,7 @@ import com.sevtinge.hyperceiler.R; import com.sevtinge.hyperceiler.data.ModData; import com.sevtinge.hyperceiler.data.adapter.ModSearchAdapter; +import com.sevtinge.hyperceiler.prefs.TipsPreference; import com.sevtinge.hyperceiler.ui.MainActivityContextHelper; import com.sevtinge.hyperceiler.ui.SubSettings; import com.sevtinge.hyperceiler.ui.fragment.base.NavigatorFragment; @@ -47,10 +50,23 @@ public class HomePageFragment extends NavigatorFragment { Preference mAod; Preference mGuardProvider; Preference mMirror; - Preference mTip; Preference mHeadtipWarn; + + TipsPreference mTips; MainActivityContextHelper mainActivityContextHelper; + Handler mHandler = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + super.handleMessage(msg); + if (msg.what == 0x11) { + mTips.updateTips();//在这里写需要刷新完成的代码 + removeMessages(0x11); + sendEmptyMessageDelayed(0x11, 6000);//这里想几秒刷新一次就写几秒*/ + } + } + }; + @Override public int getContentResId() { return R.xml.prefs_main; @@ -60,6 +76,8 @@ public int getContentResId() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().hide(); + Message message = mHandler.obtainMessage(0x11); + mHandler.sendMessageDelayed(message, 6000); } @Override @@ -71,8 +89,8 @@ public void initPrefs() { mAod = findPreference("prefs_key_aod"); mGuardProvider = findPreference("prefs_key_guardprovider"); mMirror = findPreference("prefs_key_mirror"); - mTip = findPreference("prefs_key_tip"); mHeadtipWarn = findPreference("prefs_key_headtip_warn"); + mTips = findPreference("prefs_key_tips"); mPowerSetting.setVisible(!isAndroidVersion(30)); mMTB.setVisible(!isAndroidVersion(30)); @@ -96,8 +114,6 @@ public void initPrefs() { } mainActivityContextHelper = new MainActivityContextHelper(requireContext()); - String randomTip = mainActivityContextHelper.getRandomTip(); - mTip.setSummary("Tip: " + randomTip); isOfficialRom(); if(!getIsOfficialRom()) isSignPass(); diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/SettingsPageFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/SettingsPageFragment.java similarity index 98% rename from app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/SettingsPageFragment.java rename to app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/SettingsPageFragment.java index e899862608..f48420e216 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/navigation/SettingsPageFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/base/navigation/SettingsPageFragment.java @@ -1,4 +1,4 @@ -package com.sevtinge.hyperceiler.ui.fragment.navigation; +package com.sevtinge.hyperceiler.ui.fragment.base.navigation; import android.app.Activity; import android.content.ComponentName; diff --git a/app/src/main/res/xml/prefs_main.xml b/app/src/main/res/xml/prefs_main.xml index 8402563e2f..2265c08449 100644 --- a/app/src/main/res/xml/prefs_main.xml +++ b/app/src/main/res/xml/prefs_main.xml @@ -2,6 +2,10 @@ + + + - -