Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prevent misoperation #228

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ object ConfigData {
/** 启用应用配置模板 */
val ENABLE_APP_CONFIG_TEMPLATE = PrefsData("_enable_app_config_template", false)

/** 启用对话框防误触 */
val ENABLE_PREVENT_MISOPERATION_FOR_DIALOG = PrefsData("_enable_prevent_misoperation_for_dialog", false)

/** 禁止异常堆栈内容自动换行 */
val DISABLE_AUTO_WRAP_ERROR_STACK_TRACE = PrefsData("_disable_auto_wrap_error_stack_trace", false)

Expand Down Expand Up @@ -194,6 +197,16 @@ object ConfigData {
putBoolean(ENABLE_APP_CONFIG_TEMPLATE, value)
}

/**
* 是否启用对话框防误触
* @return [Boolean]
*/
var isEnablePreventMisoperation
get() = getBoolean(ENABLE_PREVENT_MISOPERATION_FOR_DIALOG)
set(value) {
putBoolean(ENABLE_PREVENT_MISOPERATION_FOR_DIALOG, value)
}

/**
* 是否启用 Material 3 风格的错误对话框
* @return [Boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
onInitialize { binding.mgrAppsConfigsTemplateButton.isVisible = it }
onChanged { reinitialize() }
}
binding.errorsDialogPreventMisoperationSwitch.bind(ConfigData.ENABLE_PREVENT_MISOPERATION_FOR_DIALOG)
binding.enableMaterial3AppErrorsDialogSwitch.bind(ConfigData.ENABLE_MATERIAL3_STYLE_APP_ERRORS_DIALOG)
/** 设置匿名统计 */
binding.appAnalyticsConfigItem.isVisible = AppAnalyticsTool.isAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ package com.fankes.apperrorstracking.utils.factory

import android.app.Dialog
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.os.postDelayed
import androidx.viewbinding.ViewBinding
import com.fankes.apperrorstracking.data.ConfigData
import com.fankes.apperrorstracking.locale.locale
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.progressindicator.CircularProgressIndicator
Expand Down Expand Up @@ -82,6 +87,8 @@ class DialogBuilder<VB : ViewBinding>(
/** 自定义布局 */
private var customLayoutView: View? = null

private val mainHandler = Handler(Looper.getMainLooper())

/**
* 获取 [DialogBuilder] 绑定布局对象
* @return [VB]
Expand Down Expand Up @@ -191,6 +198,16 @@ class DialogBuilder<VB : ViewBinding>(
customLayoutView?.let { setView(it) }
dialogInstance = this
setOnCancelListener { onCancel?.invoke() }
if (ConfigData.isEnablePreventMisoperation) {
setOnShowListener {
window?.run {
addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
mainHandler.postDelayed(1000) {
clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
}
}
}
}
}?.show()
}
}
Expand Down
26 changes: 25 additions & 1 deletion module-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,30 @@
android:text="@string/apps_config_template_tip"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />

<com.fankes.apperrorstracking.ui.widget.MaterialSwitch
android:id="@+id/errors_dialog_prevent_misoperation_switch"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="5dp"
android:text="@string/errors_dialog_prevent_misoperation"
android:textAllCaps="false"
android:textColor="@color/colorTextGray"
android:textSize="15sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:text="@string/errors_dialog_prevent_misoperation_tip"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
</LinearLayout>

<LinearLayout
Expand Down Expand Up @@ -730,4 +754,4 @@
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions module-app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
<string name="are_you_sure_apply_site_apps">你确定要一次性应用设置给 %1$s 个应用吗?</string>
<string name="errors_dialog_always_show_reopen">错误对话框始终显示“重新打开”选项</string>
<string name="errors_dialog_always_show_reopen_tip">启用后,在使用对话框显示应用异常时,非首次异常时也将显示“重新打开”选项,若当前异常非主进程或应用无法打开则依然不会显示此选项。</string>
<string name="errors_dialog_prevent_misoperation">错误对话框防误触</string>
<string name="errors_dialog_prevent_misoperation_tip">启用后,错误对话框弹出前 1s 内不会响应点击事件</string>
<string name="developer_notice_tip">此模块专为 Android 开发者而打造。\n\n在可能的无法连接电脑,不能进行 ADB 调试的时候,可通过此模块来快速捕获任意已安装应用的任意异常,以便快速定位问题。\n\n应用发生崩溃的错误日志对开发者来说是无价的财富,若你不是开发者,你依然可以安装此模块,以便给开发者提供更多异常信息快速解决问题。</string>
<string name="developer_notice">使用说明</string>
<string name="fast_restart_problem">部分定制系统使用快速重启后可能会发生错误,仍然要继续吗?</string>
Expand Down
4 changes: 3 additions & 1 deletion module-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
<string name="are_you_sure_apply_site_apps">Are you sure you want to apply settings to %1$s apps at once?</string>
<string name="errors_dialog_always_show_reopen">Error dialog always shows \"Reopen App\"</string>
<string name="errors_dialog_always_show_reopen_tip">After enabling, when using the dialog to display application exceptions, the \"Reopen App\" option will also be displayed when the errors is not the first time. If the current errors is not the main process or the application cannot be opened, this option will still not be displayed.</string>
<string name="errors_dialog_prevent_misoperation">Prevent misoperation of error dialog</string>
<string name="errors_dialog_prevent_misoperation_tip">After enabling, the error dialog will not respond to click events within 1s after popping up</string>
<string name="developer_notice_tip">This module is specially designed for Android developers.\n\nWhen it is possible that the computer cannot be connected and ADB cannot be performed, this module can be used to quickly capture any exception of any installed apps, so as to quickly locate the problem.\n\nThe error log of apps crashing is an invaluable asset for developers. If you are not a developer, you can still install this module to provide developers with more exception information to quickly solve problems.</string>
<string name="developer_notice">Instructions</string>
<string name="warning">Warning</string>
Expand Down Expand Up @@ -158,4 +160,4 @@
<string name="stack_trace_share_system_build_id">System Build ID</string>
<string name="stack_trace_share_package_name">App Package Name</string>
<string name="stack_trace_share_other">Other Requirement</string>
</resources>
</resources>
Loading