[app] Show snackbar for compiling result (#96)
This commit is contained in:
parent
9290615644
commit
ec3c982f3d
|
|
@ -263,7 +263,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
activity.startActivity(launchIntent);
|
||||
}
|
||||
} else if (itemId == R.id.app_menu_compile_speed) {
|
||||
CompileDialogFragment.speed(activity, activity.getSupportFragmentManager(), info);
|
||||
CompileDialogFragment.speed(activity.getSupportFragmentManager(), info);
|
||||
} else if (itemId == R.id.app_menu_store) {
|
||||
Uri uri = Uri.parse("market://details?id=" + info.packageName);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
|
|
|
|||
|
|
@ -187,6 +187,10 @@ public class AppListActivity extends BaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public void makeSnackBar(String text, @Snackbar.Duration int duration) {
|
||||
Snackbar.make(binding.snackbar, text, duration).show();
|
||||
}
|
||||
|
||||
public void makeSnackBar(@StringRes int text, @Snackbar.Duration int duration) {
|
||||
Snackbar.make(binding.snackbar, text, duration).show();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,15 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatDialogFragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
|
@ -23,25 +25,19 @@ import java.lang.ref.WeakReference;
|
|||
import io.github.lsposed.manager.App;
|
||||
import io.github.lsposed.manager.R;
|
||||
import io.github.lsposed.manager.databinding.FragmentCompileDialogBinding;
|
||||
import io.github.lsposed.manager.util.ToastUtil;
|
||||
import io.github.lsposed.manager.ui.activity.AppListActivity;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CompileDialogFragment extends AppCompatDialogFragment {
|
||||
|
||||
// TODO:
|
||||
private static final String[] COMPILE_RESET_COMMAND = new String[]{"cmd", "package", "compile", "-f", "-m", "speed", ""};
|
||||
|
||||
private static final String KEY_APP_INFO = "app_info";
|
||||
private static final String KEY_MSG = "msg";
|
||||
private ApplicationInfo appInfo;
|
||||
|
||||
public CompileDialogFragment() {
|
||||
}
|
||||
|
||||
public static void speed(Context context, FragmentManager fragmentManager, ApplicationInfo info) {
|
||||
public static void speed(FragmentManager fragmentManager, ApplicationInfo info) {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelable(KEY_APP_INFO, info);
|
||||
arguments.putString(KEY_MSG, context.getString(R.string.compile_speed_msg));
|
||||
CompileDialogFragment fragment = new CompileDialogFragment();
|
||||
fragment.setArguments(arguments);
|
||||
fragment.setCancelable(false);
|
||||
|
|
@ -59,18 +55,15 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
|
|||
if (appInfo == null) {
|
||||
throw new IllegalStateException("appInfo should not be null.");
|
||||
}
|
||||
String msg = arguments.getString(KEY_MSG, getString(R.string.compile_speed_msg));
|
||||
|
||||
FragmentCompileDialogBinding binding = FragmentCompileDialogBinding.inflate(LayoutInflater.from(requireActivity()), null, false);
|
||||
final PackageManager pm = requireContext().getPackageManager();
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext())
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setIcon(appInfo.loadIcon(pm))
|
||||
.setTitle(appInfo.loadLabel(pm))
|
||||
.setCancelable(false);
|
||||
FragmentCompileDialogBinding binding = FragmentCompileDialogBinding.inflate(LayoutInflater.from(requireContext()), null, false);
|
||||
builder.setView(binding.getRoot());
|
||||
binding.message.setText(msg);
|
||||
AlertDialog alertDialog = builder.create();
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
return alertDialog;
|
||||
.setView(binding.getRoot());
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -83,11 +76,7 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
|
|||
command[6] = appInfo.packageName;
|
||||
new CompileTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, command);
|
||||
} else {
|
||||
try {
|
||||
dismissAllowingStateLoss();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dismissAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,9 +90,6 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(String... commands) {
|
||||
if (outerRef.get() == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec(commands);
|
||||
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
|
|
@ -138,19 +124,25 @@ public class CompileDialogFragment extends AppCompatDialogFragment {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
try {
|
||||
outerRef.get().dismissAllowingStateLoss();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Context context = App.getInstance();
|
||||
String text;
|
||||
if (result.length() == 0) {
|
||||
ToastUtil.showLongToast(context, R.string.compile_failed);
|
||||
text = context.getString(R.string.compile_failed);
|
||||
} else if (result.length() >= 5 && "Error".equals(result.substring(0, 5))) {
|
||||
ToastUtil.showLongToast(context, context.getString(R.string.compile_failed_with_info) + " " + result.substring(6));
|
||||
text = context.getString(R.string.compile_failed_with_info) + " " + result.substring(6);
|
||||
} else {
|
||||
ToastUtil.showLongToast(context, R.string.done);
|
||||
text = context.getString(R.string.compile_done);
|
||||
}
|
||||
CompileDialogFragment fragment = outerRef.get();
|
||||
if (fragment != null) {
|
||||
fragment.dismissAllowingStateLoss();
|
||||
AppListActivity activity = (AppListActivity) fragment.getActivity();
|
||||
if (activity != null && activity.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
activity.makeSnackBar(text, Snackbar.LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
package io.github.lsposed.manager.util;
|
||||
|
||||
public abstract class Singleton<T> {
|
||||
|
||||
private T mInstance;
|
||||
|
||||
protected abstract T create();
|
||||
|
||||
public final T get() {
|
||||
synchronized (this) {
|
||||
if (mInstance == null) {
|
||||
mInstance = create();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package io.github.lsposed.manager.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
public class ToastUtil {
|
||||
|
||||
public static void showShortToast(Context context, @StringRes int resId) {
|
||||
Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static void showLongToast(Context context, @StringRes int resId) {
|
||||
Toast.makeText(context, resId, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public static void showLongToast(Context context, String msg) {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,5 +21,6 @@
|
|||
android:id="@+id/message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical" />
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/compile_speed_msg" />
|
||||
</LinearLayout>
|
||||
|
|
@ -139,4 +139,5 @@
|
|||
<string name="menu_backup">备份</string>
|
||||
<string name="menu_restore">恢复</string>
|
||||
<string name="xposed_module_updated_notification_content">%s 已更新</string>
|
||||
<string name="compile_done">优化完成</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -80,10 +80,9 @@
|
|||
<string name="android_sdk" translatable="false">Android %2$s (%1$s, API %3$d)</string>
|
||||
<string name="not_logcat">This is the LSPosed Framework and modules log\nif you need a Android logcat, you can try our Log Catcher Magisk module</string>
|
||||
|
||||
<string name="done">Done!</string>
|
||||
|
||||
<!-- LSPd related -->
|
||||
<string name="compile_speed_msg">Optimizing …</string>
|
||||
<string name="compile_speed_msg">Optimizing…</string>
|
||||
<string name="compile_done">Optimization complete.</string>
|
||||
|
||||
<string name="about_source" translatable="false">https://github.com/LSPosed/LSPosed/</string>
|
||||
|
||||
|
|
@ -92,7 +91,7 @@
|
|||
<string name="pref_title_disable_verbose_log">Disable verbose logs</string>
|
||||
<string name="logs_cannot_read">Cannot read log: \n</string>
|
||||
<string name="app_launch">Launch it</string>
|
||||
<string name="compile_failed">Optimization failed or return value is empty</string>
|
||||
<string name="compile_failed">Optimization failed or return value is empty.</string>
|
||||
<string name="compile_failed_with_info">Optimization failed: </string>
|
||||
<string name="not_installed">Not installed</string>
|
||||
<string name="pure_black_dark_theme">Use the pure black dark theme</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue