chore: update clear data ui confirmation
This commit is contained in:
@@ -39,9 +39,14 @@ import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.AppCompatCheckBox
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -49,6 +54,7 @@ import cc.ioctl.fragment.ExfriendListFragment
|
||||
import cc.ioctl.util.ExfriendManager
|
||||
import cc.ioctl.util.HostInfo
|
||||
import cc.ioctl.util.LayoutHelper
|
||||
import cc.ioctl.util.LayoutHelper.dip2px
|
||||
import cc.ioctl.util.Reflex
|
||||
import cc.ioctl.util.data.EventRecord
|
||||
import cc.ioctl.util.data.FriendRecord
|
||||
@@ -222,8 +228,9 @@ class TroubleshootFragment : BaseRootLayoutFragment() {
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
private val clickToResetDefaultConfig = confirmBeforeAction(
|
||||
"此操作将删除该模块的所有配置信息,包括屏蔽通知的群列表,但不包括历史好友列表.点击确认后请等待3秒后手动重启" + hostInfo.hostName + ".\n此操作不可恢复"
|
||||
private val clickToResetDefaultConfig = confirmTwiceBeforeAction(
|
||||
"此操作将删除该模块的所有配置信息,包括屏蔽通知的群列表,但不包括历史好友列表.点击确认后请等待3秒后手动重启" + hostInfo.hostName + ".\n此操作不可恢复",
|
||||
"删除所有配置信息"
|
||||
) {
|
||||
ConfigManager.getCache().apply {
|
||||
clear()
|
||||
@@ -237,12 +244,13 @@ class TroubleshootFragment : BaseRootLayoutFragment() {
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
private val clickToClearRecoveredFriends = confirmBeforeAction(
|
||||
private val clickToClearRecoveredFriends = confirmTwiceBeforeAction(
|
||||
"""
|
||||
此操作将删除当前账号(${getLongAccountUin()})下的 已恢复 的历史好友记录(记录可单独删除).
|
||||
如果因 BUG 大量好友被标记为已删除, 请先刷新好友列表, 然后再点击此按钮.
|
||||
此操作不可恢复
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
"删除已恢复的好友记录"
|
||||
) {
|
||||
val exm = ExfriendManager.getCurrent()
|
||||
val it: MutableIterator<*> = exm.events.entries.iterator()
|
||||
@@ -258,11 +266,12 @@ class TroubleshootFragment : BaseRootLayoutFragment() {
|
||||
Toasts.success(requireContext(), "操作成功")
|
||||
}
|
||||
|
||||
private val clickToClearAllFriends = confirmBeforeAction(
|
||||
private val clickToClearAllFriends = confirmTwiceBeforeAction(
|
||||
"此操作将删除当前账号(" + getLongAccountUin()
|
||||
+ ")下的 全部 的历史好友记录, 通常您不需要进行此操作. \n" +
|
||||
"如果您的历史好友列表中因bug出现大量好友,请在联系人列表下拉刷新后点击 删除标记为已恢复的好友. \n" +
|
||||
"此操作不可恢复"
|
||||
"此操作不可恢复",
|
||||
"删除所有好友记录"
|
||||
) {
|
||||
val uin = getLongAccountUin()
|
||||
if (uin < 10000) {
|
||||
@@ -303,6 +312,57 @@ class TroubleshootFragment : BaseRootLayoutFragment() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun confirmTwiceBeforeAction(
|
||||
confirmMessage: String,
|
||||
secondConfirmCheckBoxText: String,
|
||||
action: () -> Unit
|
||||
) = View.OnClickListener {
|
||||
val ctx = requireContext()
|
||||
val builder = AlertDialog.Builder(ctx)
|
||||
builder.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
try {
|
||||
action()
|
||||
} catch (e: Exception) {
|
||||
CustomDialog.createFailsafe(ctx)
|
||||
.setTitle(Reflex.getShortClassName(e))
|
||||
.setCancelable(true)
|
||||
.setMessage(e.toString())
|
||||
.ok().show()
|
||||
}
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel, null)
|
||||
builder.setCancelable(true)
|
||||
builder.setTitle("确认操作")
|
||||
// create a linear layout to hold the message and checkbox
|
||||
val layout = LinearLayout(ctx).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
val padding = ctx.resources.getDimension(androidx.appcompat.R.dimen.abc_dialog_padding_material).toInt()
|
||||
setPadding(padding, padding / 3, padding, 0)
|
||||
}
|
||||
val message = AppCompatTextView(ctx).apply {
|
||||
text = confirmMessage
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
setTextColor(ResourcesCompat.getColor(resources, R.color.firstTextColor, ctx.theme))
|
||||
}
|
||||
val checkBox = AppCompatCheckBox(ctx).apply {
|
||||
text = secondConfirmCheckBoxText
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
setTextColor(ResourcesCompat.getColor(resources, R.color.firstTextColor, ctx.theme))
|
||||
isClickable = true
|
||||
isChecked = false
|
||||
}
|
||||
layout.addView(message)
|
||||
layout.addView(checkBox)
|
||||
builder.setView(layout)
|
||||
val dialog = builder.show()
|
||||
// get positive button and set listener
|
||||
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
checkBox.setOnCheckedChangeListener { _, isChecked ->
|
||||
positiveButton.isEnabled = isChecked
|
||||
}
|
||||
positiveButton.isEnabled = false
|
||||
}
|
||||
|
||||
private fun actionOrShowError(action: () -> Unit) = View.OnClickListener {
|
||||
runOrShowError(action)
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ public class CustomDialog {
|
||||
Class clz_Lite = load("com/dataline/activities/LiteActivity");
|
||||
Field[] fs = clz_Lite.getDeclaredFields();
|
||||
for (Field f : fs) {
|
||||
if (Modifier.isPrivate(f.getModifiers()) && Dialog.class
|
||||
.isAssignableFrom(f.getType())) {
|
||||
if (Modifier.isPrivate(f.getModifiers()) && Dialog.class.isAssignableFrom(f.getType())) {
|
||||
clz_CustomDialog = f.getType();
|
||||
break;
|
||||
}
|
||||
@@ -72,8 +71,7 @@ public class CustomDialog {
|
||||
if (m_DialogUtil_a == null) {
|
||||
Method tmpa = null, tmpb = null;
|
||||
for (Method m : clz_DialogUtil.getDeclaredMethods()) {
|
||||
if (m.getReturnType().equals(clz_CustomDialog) && (Modifier
|
||||
.isPublic(m.getModifiers()))) {
|
||||
if (m.getReturnType().equals(clz_CustomDialog) && (Modifier.isPublic(m.getModifiers()))) {
|
||||
Class<?>[] argt = m.getParameterTypes();
|
||||
if (argt.length != 2) {
|
||||
continue;
|
||||
@@ -118,6 +116,11 @@ public class CustomDialog {
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context the context to create the dialog
|
||||
* @return a failsafe dialog builder
|
||||
* @deprecated use {@link androidx.appcompat.app.AlertDialog.Builder} with {@link CommonContextWrapper#createAppCompatContext(Context)} instead
|
||||
*/
|
||||
public static CustomDialog createFailsafe(Context context) {
|
||||
CustomDialog ref = new CustomDialog();
|
||||
// dark/light theme is already handled by CommonContextWrapper.createAppCompatContext(context)
|
||||
@@ -203,8 +206,7 @@ public class CustomDialog {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomDialog setPositiveButton(int text,
|
||||
@Nullable DialogInterface.OnClickListener listener) {
|
||||
public CustomDialog setPositiveButton(int text, @Nullable DialogInterface.OnClickListener listener) {
|
||||
Context ctx;
|
||||
if (failsafe) {
|
||||
ctx = mBuilder.getContext();
|
||||
@@ -215,8 +217,7 @@ public class CustomDialog {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomDialog setNegativeButton(int text,
|
||||
@Nullable DialogInterface.OnClickListener listener) {
|
||||
public CustomDialog setNegativeButton(int text, @Nullable DialogInterface.OnClickListener listener) {
|
||||
Context ctx;
|
||||
if (failsafe) {
|
||||
ctx = mBuilder.getContext();
|
||||
@@ -233,15 +234,13 @@ public class CustomDialog {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomDialog setPositiveButton(@NonNull String text,
|
||||
@Nullable DialogInterface.OnClickListener listener) {
|
||||
public CustomDialog setPositiveButton(@NonNull String text, @Nullable DialogInterface.OnClickListener listener) {
|
||||
if (!failsafe) {
|
||||
if (text != null && listener == null) {
|
||||
listener = new DummyCallback();
|
||||
}
|
||||
try {
|
||||
Reflex.invokeVirtual(mDialog, "setPositiveButton", text, listener, String.class,
|
||||
DialogInterface.OnClickListener.class);
|
||||
Reflex.invokeVirtual(mDialog, "setPositiveButton", text, listener, String.class, DialogInterface.OnClickListener.class);
|
||||
} catch (Exception e) {
|
||||
Log.e(e);
|
||||
}
|
||||
@@ -252,8 +251,7 @@ public class CustomDialog {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomDialog setNeutralButton(@NonNull String text,
|
||||
@Nullable DialogInterface.OnClickListener listener) {
|
||||
public CustomDialog setNeutralButton(@NonNull String text, @Nullable DialogInterface.OnClickListener listener) {
|
||||
if (!failsafe) {
|
||||
//They don't have a neutral button, sigh...
|
||||
} else {
|
||||
@@ -263,8 +261,7 @@ public class CustomDialog {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CustomDialog setNeutralButton(int text,
|
||||
@Nullable DialogInterface.OnClickListener listener) {
|
||||
public CustomDialog setNeutralButton(int text, @Nullable DialogInterface.OnClickListener listener) {
|
||||
if (!failsafe) {
|
||||
//They don't have a neutral button, sigh...
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user