Skip to content

Commit

Permalink
优化代码结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan095 committed May 19, 2024
1 parent 390c2a9 commit 61de7ca
Show file tree
Hide file tree
Showing 12 changed files with 830 additions and 18 deletions.
13 changes: 12 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".ui.HyperCeilerTabActivity"
android:exported="true"
android:theme="@style/NavigatorActivityTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
</intent-filter>
</activity>

<activity
android:name=".ui.MainActivity"
android:exported="true"
Expand Down Expand Up @@ -95,7 +106,7 @@
android:name=".ui.LauncherActivity"
android:exported="true"
android:label="@string/app_name"
android:targetActivity=".ui.MainActivity"
android:targetActivity=".ui.HyperCeilerTabActivity"
tools:ignore="DiscouragedApi,LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.sevtinge.hyperceiler.ui;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;

import androidx.annotation.Nullable;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.callback.IResult;
import com.sevtinge.hyperceiler.prefs.PreferenceHeader;
import com.sevtinge.hyperceiler.safe.CrashData;
import com.sevtinge.hyperceiler.ui.base.HyperCeilerTabBaseActivity;
import com.sevtinge.hyperceiler.utils.BackupUtils;
import com.sevtinge.hyperceiler.utils.Helpers;
import com.sevtinge.hyperceiler.utils.LanguageHelper;
import com.sevtinge.hyperceiler.utils.PropUtils;
import com.sevtinge.hyperceiler.utils.ThreadPoolManager;
import com.sevtinge.hyperceiler.utils.api.ProjectApi;
import com.sevtinge.hyperceiler.utils.prefs.PrefsUtils;
import com.sevtinge.hyperceiler.utils.search.SearchHelper;
import com.sevtinge.hyperceiler.utils.shell.ShellInit;

import java.util.ArrayList;

import fan.appcompat.app.AlertDialog;

public class HyperCeilerTabActivity extends HyperCeilerTabBaseActivity implements IResult {

private Handler handler;
private Context context;

private ArrayList<String> appCrash = new ArrayList<>();

@Override
protected void onCreate(Bundle bundle) {
SharedPreferences mPrefs = PrefsUtils.mSharedPreferences;
int count = Integer.parseInt(mPrefs.getString("prefs_key_settings_app_language", "-1"));
if (count != -1) {
LanguageHelper.setIndexLanguage(this, count, false);
}
handler = new Handler(this.getMainLooper());
context = this;
int def = Integer.parseInt(PrefsUtils.mSharedPreferences.getString("prefs_key_log_level", "3"));
super.onCreate(bundle);
new Thread(() -> SearchHelper.getAllMods(this, bundle != null)).start();
Helpers.checkXposedActivateState(this);
ShellInit.init(this);
PropUtils.setProp("persist.hyperceiler.log.level", ProjectApi.isCanary() ? (def != 3 && def != 4 ? 3 : def) : def);
appCrash = CrashData.toPkgList();
handler.postDelayed(() -> {
if (haveCrashReport()) {
new AlertDialog.Builder(this)
.setTitle(R.string.safe_mode_later_title)
.setMessage(appCrash.toString() + " " + getString(R.string.safe_mode_later_desc))
.setHapticFeedbackEnabled(true)
.setCancelable(false)
.setPositiveButton(R.string.safe_mode_cancel, (dialog, which) -> {
ShellInit.getShell().run("setprop persist.hyperceiler.crash.report \"\"").sync();
dialog.dismiss();
})
.setNegativeButton(R.string.safe_mode_ok, (dialog, which) -> dialog.dismiss())
.show();
}
}, 600);
}

@Override
public void error(String reason) {
handler.post(() -> new AlertDialog.Builder(context)
.setCancelable(false)
.setTitle(getResources().getString(R.string.tip))
.setMessage(getResources().getString(R.string.root))
.setHapticFeedbackEnabled(true)
.setPositiveButton(android.R.string.ok, null)
.show());
}

private boolean haveCrashReport() {
return !appCrash.isEmpty();
}

@Override
public void onDestroy() {
ShellInit.destroy();
ThreadPoolManager.shutdown();
PreferenceHeader.mUninstallApp.clear();
PreferenceHeader.mDisableOrHiddenApp.clear();
super.onDestroy();
}

public void test() {
/*boolean ls = shellExec.append("ls").sync().isResult();
AndroidLogUtils.LogI(ITAG.TAG, "ls: " + ls);
AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString() + shellExec.getError().toString());
boolean f = shellExec.append("for i in $(seq 1 500); do echo $i; done").isResult();
AndroidLogUtils.LogI(ITAG.TAG, "for: " + f);
AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString());
boolean k = shellExec.append("for i in $(seq 1 500); do echo $i; done").sync().isResult();
AndroidLogUtils.LogI(ITAG.TAG, "fork: " + k);
AndroidLogUtils.LogI(ITAG.TAG, shellExec.getOutPut().toString());*/
}

private void requestCta() {
/*if (!CtaUtils.isCtaEnabled(this)) {
CtaUtils.showCtaDialog(this, REQUEST_CODE);
}*/
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
requestCta();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data == null) return;
try {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
switch (requestCode) {
case BackupUtils.CREATE_DOCUMENT_CODE -> {
BackupUtils.handleCreateDocument(this, data.getData());
alert.setTitle(R.string.backup_success);
}
case BackupUtils.OPEN_DOCUMENT_CODE -> {
BackupUtils.handleReadDocument(this, data.getData());
alert.setTitle(R.string.rest_success);
}
default -> {
return;
}
}
alert.setPositiveButton(android.R.string.ok, (dialog, which) -> {
});
alert.show();
} catch (Exception e) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
switch (requestCode) {
case BackupUtils.CREATE_DOCUMENT_CODE -> alert.setTitle(R.string.backup_failed);
case BackupUtils.OPEN_DOCUMENT_CODE -> alert.setTitle(R.string.rest_failed);
}
alert.setMessage(e.toString());
alert.setPositiveButton(android.R.string.ok, (dialog, which) -> {
});
alert.show();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.sevtinge.hyperceiler.ui.base;

import android.os.Bundle;

import androidx.annotation.NonNull;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.ui.SubSettings;
import com.sevtinge.hyperceiler.ui.page.ContentFragment;
import com.sevtinge.hyperceiler.utils.SettingLauncherHelper;

import fan.appcompat.app.Fragment;
import fan.navigator.Navigator;
import fan.navigator.NavigatorStrategy;
import fan.navigator.app.NavigatorActivity;
import fan.navigator.navigatorinfo.NavigatorInfoProvider;
import fan.navigator.navigatorinfo.UpdateFragmentNavInfo;
import fan.preference.Preference;
import fan.preference.PreferenceFragment;
import fan.preference.core.PreferenceFragmentCompat;

public class HyperCeilerTabBaseActivity extends NavigatorActivity
implements PreferenceFragment.OnPreferenceStartFragmentCallback {

@Override
public int getBottomTabMenu() {
return R.menu.bottom_nav_menu;
}

@Override
public NavigatorInfoProvider getBottomTabMenuNavInfoProvider() {
Bundle bundle = new Bundle();
return i -> {
if (i == 1000) {
bundle.putInt("page", 0);
} else if (i == 1001) {
bundle.putInt("page", 1);
} else if (i == 1002) {
bundle.putInt("page", 2);
} else {
return null;
}
return new UpdateFragmentNavInfo(i, getDefaultContentFragment(), bundle);
};
}

@Override
public Class<? extends Fragment> getDefaultContentFragment() {
return ContentFragment.class;
}

@Override
public int getNavigationOptionMenu() {
return 0;
}

@Override
public Bundle getNavigatorInitArgs() {
NavigatorStrategy navigatorStrategy = new NavigatorStrategy();
navigatorStrategy.setLargeMode(Navigator.Mode.C);
Bundle bundle = new Bundle();
bundle.putParcelable("miuix:navigatorStrategy", navigatorStrategy);
return bundle;
}

@Override
public void onCreateOtherNavigation(Navigator navigator, Bundle bundle) {

}

@Override
public void onCreatePrimaryNavigation(Navigator navigator, Bundle bundle) {
UpdateFragmentNavInfo updateFragmentNavInfoToHome = getUpdateFragmentNavInfoToHome();
UpdateFragmentNavInfo updateFragmentNavInfoToSettings = updateFragmentNavInfoToSettings();
UpdateFragmentNavInfo updateFragmentNavInfoToClock = getUpdateFragmentNavInfoToAbout();
newLabel(getString(R.string.home), updateFragmentNavInfoToHome);
newLabel(getString(R.string.settings), updateFragmentNavInfoToSettings);
newLabel(getString(R.string.about), updateFragmentNavInfoToClock);
navigator.navigate(updateFragmentNavInfoToHome);
}

private UpdateFragmentNavInfo getUpdateFragmentNavInfoToHome() {
Bundle bundle = new Bundle();
bundle.putInt("page", 0);
return new UpdateFragmentNavInfo(1000, getDefaultContentFragment(), bundle);
}

private UpdateFragmentNavInfo updateFragmentNavInfoToSettings() {
Bundle bundle = new Bundle();
bundle.putInt("page", 1);
return new UpdateFragmentNavInfo(1001, getDefaultContentFragment(), bundle);
}

private UpdateFragmentNavInfo getUpdateFragmentNavInfoToAbout() {
Bundle bundle = new Bundle();
bundle.putInt("page", 2);
return new UpdateFragmentNavInfo(1002, getDefaultContentFragment(), bundle);
}

@Override
public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat preferenceFragmentCompat, @NonNull Preference preference) {
Bundle args = null;
String mFragmentName = preference.getFragment();
String mTitle = preference.getTitle().toString();
SettingLauncherHelper.onStartSettingsForArguments(this, SubSettings.class, mFragmentName, args, mTitle);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,4 @@ public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat prefe
mProxy.onStartSettingsForArguments(SubSettings.class, preference, false);
return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.restart) {
DialogHelper.showRestartDialog(this);
}
return super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 61de7ca

Please sign in to comment.