1- /*
2- * This file is part of HyperCeiler.
3-
4- * HyperCeiler is free software: you can redistribute it and/or modify
5- * it under the terms of the GNU Affero General Public License as
6- * published by the Free Software Foundation, either version 3 of the
7- * License.
8-
9- * This program is distributed in the hope that it will be useful,
10- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12- * GNU Affero General Public License for more details.
13-
14- * You should have received a copy of the GNU Affero General Public License
15- * along with this program. If not, see <https://www.gnu.org/licenses/>.
16-
17- * Copyright (C) 2023-2024 HyperCeiler Contributions
18- */
191package com .sevtinge .hyperceiler .ui .activity ;
202
213import static com .sevtinge .hyperceiler .utils .Helpers .isModuleActive ;
224import static com .sevtinge .hyperceiler .utils .devicesdk .MiDeviceAppUtilsKt .isPad ;
235import static com .sevtinge .hyperceiler .utils .devicesdk .SystemSDKKt .isMoreHyperOSVersion ;
246import static com .sevtinge .hyperceiler .utils .log .LogManager .IS_LOGGER_ALIVE ;
25- import static com .sevtinge .hyperceiler .utils .log .LogManager .LOGGER_CHECKER_ERR_CODE ;
267import static com .sevtinge .hyperceiler .utils .log .LogManager .isLoggerAlive ;
278
289import android .content .Context ;
3112import android .os .Bundle ;
3213import android .os .Handler ;
3314
15+ import androidx .annotation .NonNull ;
3416import androidx .annotation .Nullable ;
17+ import androidx .preference .Preference ;
18+ import androidx .preference .PreferenceFragmentCompat ;
3519
3620import com .sevtinge .hyperceiler .BuildConfig ;
3721import com .sevtinge .hyperceiler .R ;
3822import com .sevtinge .hyperceiler .callback .IResult ;
3923import com .sevtinge .hyperceiler .prefs .PreferenceHeader ;
4024import com .sevtinge .hyperceiler .safe .CrashData ;
41- import com .sevtinge .hyperceiler .ui .activity .base .HyperCeilerTabActivity ;
25+ import com .sevtinge .hyperceiler .ui .activity .base .NaviBaseActivity ;
26+ import com .sevtinge .hyperceiler .ui .fragment .main .ContentFragment ;
4227import com .sevtinge .hyperceiler .utils .BackupUtils ;
28+ import com .sevtinge .hyperceiler .utils .DialogHelper ;
4329import com .sevtinge .hyperceiler .utils .Helpers ;
4430import com .sevtinge .hyperceiler .utils .LanguageHelper ;
4531import com .sevtinge .hyperceiler .utils .PropUtils ;
5440import java .util .Map ;
5541
5642import fan .appcompat .app .AlertDialog ;
43+ import fan .appcompat .app .Fragment ;
44+ import fan .navigator .Navigator ;
45+ import fan .navigator .NavigatorStrategy ;
46+ import fan .navigator .navigatorinfo .NavigatorInfoProvider ;
47+ import fan .navigator .navigatorinfo .UpdateFragmentNavInfo ;
48+ import fan .preference .PreferenceFragment ;
5749
58- public class MainActivity extends HyperCeilerTabActivity implements IResult {
50+ public class HyperCeilerTabActivity extends NaviBaseActivity
51+ implements PreferenceFragment .OnPreferenceStartFragmentCallback , IResult {
5952
6053 private Handler handler ;
6154 private Context context ;
6255
6356 private ArrayList <String > appCrash = new ArrayList <>();
6457
6558 @ Override
66- public void onCreate (Bundle savedInstanceState ) {
59+ protected void onCreate (@ Nullable Bundle savedInstanceState ) {
6760 IS_LOGGER_ALIVE = isLoggerAlive ();
6861 SharedPreferences mPrefs = PrefsUtils .mSharedPreferences ;
6962 int count = Integer .parseInt (mPrefs .getString ("prefs_key_settings_app_language" , "-1" ));
@@ -74,16 +67,10 @@ public void onCreate(Bundle savedInstanceState) {
7467 context = this ;
7568 int def = Integer .parseInt (PrefsUtils .mSharedPreferences .getString ("prefs_key_log_level" , "3" ));
7669 super .onCreate (savedInstanceState );
77- new Thread (() -> SearchHelper .getAllMods (MainActivity . this , savedInstanceState != null )).start ();
70+ new Thread (() -> SearchHelper .getAllMods (context , savedInstanceState != null )).start ();
7871 Helpers .checkXposedActivateState (this );
7972 if (!IS_LOGGER_ALIVE && isModuleActive && BuildConfig .BUILD_TYPE != "release" && !mPrefs .getBoolean ("prefs_key_development_close_log_alert_dialog" , false )) {
80- handler .post (() -> new AlertDialog .Builder (context )
81- .setCancelable (false )
82- .setTitle (getResources ().getString (R .string .warn ))
83- .setMessage (getResources ().getString (R .string .headtip_notice_dead_logger_errcode , LOGGER_CHECKER_ERR_CODE ))
84- .setHapticFeedbackEnabled (true )
85- .setPositiveButton (android .R .string .ok , null )
86- .show ());
73+ handler .post (() -> DialogHelper .showLogServiceWarnDialog (context ));
8774 }
8875 ShellInit .init (this );
8976 PropUtils .setProp ("persist.hyperceiler.log.level" , ProjectApi .isCanary () ? (def != 3 && def != 4 ? 3 : def ) : def );
@@ -114,26 +101,15 @@ public void onCreate(Bundle savedInstanceState) {
114101 msg = msg .replace ("[" , "" );
115102 msg = msg .replace ("]" , "" );
116103 msg = msg .replaceAll ("^\\ s+|\\ s+$" , "" );
117- new AlertDialog .Builder (MainActivity .this )
118- .setTitle (R .string .safe_mode_later_title )
119- .setMessage (msg )
120- .setHapticFeedbackEnabled (true )
121- .setCancelable (false )
122- .setPositiveButton (R .string .safe_mode_cancel , (dialog , which ) -> {
123- ShellInit .getShell ().run ("setprop persist.hyperceiler.crash.report \" \" " ).sync ();
124- PrefsUtils .mSharedPreferences .edit ().remove ("prefs_key_system_ui_safe_mode_enable" ).apply ();
125- PrefsUtils .mSharedPreferences .edit ().remove ("prefs_key_home_safe_mode_enable" ).apply ();
126- PrefsUtils .mSharedPreferences .edit ().remove ("prefs_key_system_settings_safe_mode_enable" ).apply ();
127- PrefsUtils .mSharedPreferences .edit ().remove ("prefs_key_security_center_safe_mode_enable" ).apply ();
128- PrefsUtils .mSharedPreferences .edit ().remove ("prefs_key_demo_safe_mode_enable" ).apply ();
129- dialog .dismiss ();
130- })
131- .setNegativeButton (R .string .safe_mode_ok , (dialog , which ) -> dialog .dismiss ())
132- .show ();
104+ DialogHelper .showSafeModeDialog (context , msg );
133105 }
134106 }, 600 );
135107 }
136108
109+ private boolean haveCrashReport () {
110+ return !appCrash .isEmpty ();
111+ }
112+
137113 @ Override
138114 public void error (String reason ) {
139115 handler .post (() -> new AlertDialog .Builder (context )
@@ -145,18 +121,87 @@ public void error(String reason) {
145121 .show ());
146122 }
147123
124+ @ Override
125+ public int getBottomTabMenu () {
126+ return R .menu .bottom_nav_menu ;
127+ }
148128
149- private boolean haveCrashReport () {
150- return !appCrash .isEmpty ();
129+ @ Override
130+ public int getNavigationOptionMenu () {
131+ return 0 ;
151132 }
152133
153134 @ Override
154- public void onDestroy () {
155- ShellInit .destroy ();
156- ThreadPoolManager .shutdown ();
157- PreferenceHeader .mUninstallApp .clear ();
158- PreferenceHeader .mDisableOrHiddenApp .clear ();
159- super .onDestroy ();
135+ public Bundle getNavigatorInitArgs () {
136+ NavigatorStrategy navigatorStrategy = new NavigatorStrategy ();
137+ navigatorStrategy .setCompactMode (Navigator .Mode .C );
138+ navigatorStrategy .setRegularMode (Navigator .Mode .C );
139+ navigatorStrategy .setLargeMode (Navigator .Mode .C );
140+ Bundle bundle = new Bundle ();
141+ bundle .putParcelable ("miuix:navigatorStrategy" , navigatorStrategy );
142+ return bundle ;
143+ }
144+
145+ @ Override
146+ public NavigatorInfoProvider getBottomTabMenuNavInfoProvider () {
147+ return id -> {
148+ Bundle bundle = new Bundle ();
149+ if (id == 1000 ) {
150+ bundle .putInt ("page" , 0 );
151+ } else if (id == 1001 ) {
152+ bundle .putInt ("page" , 1 );
153+ } else if (id == 1002 ) {
154+ bundle .putInt ("page" , 2 );
155+ } else {
156+ return null ;
157+ }
158+ return new UpdateFragmentNavInfo (id , getDefaultContentFragment (), bundle );
159+ };
160+ }
161+
162+ @ Override
163+ public Class <? extends Fragment > getDefaultContentFragment () {
164+ return ContentFragment .class ;
165+ }
166+
167+ @ Override
168+ public void onCreatePrimaryNavigation (Navigator navigator , Bundle bundle ) {
169+ UpdateFragmentNavInfo navInfoToHome = getUpdateFragmentNavInfo (0 );
170+ UpdateFragmentNavInfo navInfoToWidget = getUpdateFragmentNavInfo (1 );
171+ UpdateFragmentNavInfo navInfoToList = getUpdateFragmentNavInfo (2 );
172+ newLabel (getString (R .string .navigation_home_title ), navInfoToHome );
173+ newLabel (getString (R .string .navigation_settings_title ), navInfoToWidget );
174+ newLabel (getString (R .string .navigation_about_title ), navInfoToList );
175+ navigator .navigate (navInfoToHome );
176+ }
177+
178+ @ Override
179+ public void onCreateOtherNavigation (Navigator navigator , Bundle bundle ) {
180+
181+ }
182+
183+ private UpdateFragmentNavInfo getUpdateFragmentNavInfo (int position ) {
184+ Bundle bundle = new Bundle ();
185+ bundle .putInt ("page" , position );
186+ return new UpdateFragmentNavInfo (position , getDefaultContentFragment (), bundle );
187+ }
188+
189+ @ Override
190+ public boolean onPreferenceStartFragment (@ NonNull PreferenceFragmentCompat caller , @ NonNull Preference pref ) {
191+ mProxy .onStartSettingsForArguments (SubSettings .class , pref , false );
192+ return true ;
193+ }
194+
195+ @ Override
196+ protected void onNewIntent (Intent intent ) {
197+ super .onNewIntent (intent );
198+ requestCta ();
199+ }
200+
201+ private void requestCta () {
202+ /*if (!CtaUtils.isCtaEnabled(this)) {
203+ CtaUtils.showCtaDialog(this, REQUEST_CODE);
204+ }*/
160205 }
161206
162207 public void test () {
@@ -171,18 +216,6 @@ public void test() {
171216 AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString());*/
172217 }
173218
174- private void requestCta () {
175- /*if (!CtaUtils.isCtaEnabled(this)) {
176- CtaUtils.showCtaDialog(this, REQUEST_CODE);
177- }*/
178- }
179-
180- @ Override
181- protected void onNewIntent (Intent intent ) {
182- super .onNewIntent (intent );
183- requestCta ();
184- }
185-
186219 @ Override
187220 protected void onActivityResult (int requestCode , int resultCode , @ Nullable Intent data ) {
188221 super .onActivityResult (requestCode , resultCode , data );
@@ -218,4 +251,12 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
218251 }
219252 }
220253
254+ @ Override
255+ public void onDestroy () {
256+ ShellInit .destroy ();
257+ ThreadPoolManager .shutdown ();
258+ PreferenceHeader .mUninstallApp .clear ();
259+ PreferenceHeader .mDisableOrHiddenApp .clear ();
260+ super .onDestroy ();
261+ }
221262}
0 commit comments