Skip to content

Commit 34ab7a9

Browse files
committed
🐛 🎨
[Update] - Improved the recovery mode. [Fix] - fixed #151
1 parent 83c67b6 commit 34ab7a9

9 files changed

Lines changed: 63 additions & 126 deletions

File tree

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ android {
1515
applicationId = "me.rosuh.easywatermark"
1616
minSdk = (Apps.minSdk)
1717
targetSdk = (Apps.targetSdk)
18-
versionCode = 20702
19-
versionName = "2.7.2"
18+
versionCode = 20703
19+
versionName = "2.7.3"
2020
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2121
setProperty("archivesBaseName", "$applicationId-v$versionName($versionCode)")
2222
}

app/src/main/java/me/rosuh/easywatermark/MyApp.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import android.annotation.SuppressLint
44
import android.app.Application
55
import android.content.Context
66
import android.content.Intent
7-
import android.content.res.Configuration
87
import android.util.Log
98
import androidx.core.content.edit
109
import dagger.hilt.android.HiltAndroidApp
1110
import kotlinx.coroutines.*
1211
import me.rosuh.cmonet.CMonet
1312
import me.rosuh.easywatermark.data.repo.WaterMarkRepository
14-
import me.rosuh.easywatermark.ui.theme.ThemeManager
1513
import javax.inject.Inject
1614
import kotlin.system.exitProcess
1715

@@ -31,9 +29,7 @@ class MyApp : Application() {
3129

3230
override fun onCreate() {
3331
super.onCreate()
34-
val crashCount = sp.getInt(SP_KEY_CRASH_COUNT, 0)
35-
if (crashCount >= 2) {
36-
recoveryMode = true
32+
if (checkRecoveryMode()) {
3733
return
3834
} else {
3935
applicationScope.launch {
@@ -43,9 +39,26 @@ class MyApp : Application() {
4339
}
4440
}
4541

46-
override fun onConfigurationChanged(newConfig: Configuration) {
47-
ThemeManager.onConfigurationChanged(newConfig)
48-
super.onConfigurationChanged(newConfig)
42+
private fun checkRecoveryMode(): Boolean {
43+
val crashCount = sp.getInt(SP_KEY_CRASH_COUNT, 0)
44+
if (crashCount < CRASH_COUNT) {
45+
return false
46+
}
47+
val recoveryVersion = sp.getInt(SP_KEY_RECOVERY_VERSION, BuildConfig.VERSION_CODE - 1)
48+
if (recoveryVersion < BuildConfig.VERSION_CODE) {
49+
// maybe we fixed in this version
50+
recoveryMode = false
51+
sp.edit {
52+
putInt(SP_KEY_CRASH_COUNT, 0)
53+
putInt(SP_KEY_RECOVERY_VERSION, 0)
54+
}
55+
return false
56+
}
57+
recoveryMode = true
58+
sp.edit {
59+
putInt(SP_KEY_RECOVERY_VERSION, BuildConfig.VERSION_CODE)
60+
}
61+
return true
4962
}
5063

5164
fun launchSuccess() {
@@ -68,6 +81,7 @@ class MyApp : Application() {
6881
Log.e("MyApp", "uncaughtException: $fullStackTrace")
6982
sp.edit(true) {
7083
putInt(SP_KEY_CRASH_COUNT, sp.getInt(SP_KEY_CRASH_COUNT, 0) + 1)
84+
putInt(SP_KEY_RECOVERY_VERSION, BuildConfig.VERSION_CODE)
7185
putBoolean(KEY_IS_CRASH, true)
7286
putString(
7387
KEY_STACK_TRACE,
@@ -98,10 +112,13 @@ class MyApp : Application() {
98112
var recoveryMode = false
99113
private set
100114

115+
private const val CRASH_COUNT = 2
116+
101117
const val SP_NAME = "sp_water_mark_crash_info"
102118

103119
const val KEY_IS_CRASH = SP_NAME + "_key_is_crash"
104120
const val KEY_STACK_TRACE = SP_NAME + "_key_stack_trace"
105121
const val SP_KEY_CRASH_COUNT = SP_NAME + "_key_crash_count"
122+
const val SP_KEY_RECOVERY_VERSION = SP_NAME + "_key_recovery_version"
106123
}
107124
}

app/src/main/java/me/rosuh/easywatermark/ui/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class MainActivity : AppCompatActivity() {
161161
checkHadCrash()
162162
// Activity was recycled but dialog still showing in some case?
163163
SaveImageBSDialogFragment.safetyHide(this@MainActivity.supportFragmentManager)
164+
throw RuntimeException("test")
164165
}
165166

166167
private fun initRecoveryView() {

app/src/main/java/me/rosuh/easywatermark/ui/MainViewModel.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,22 @@ class MainViewModel @Inject constructor(
544544
// user do not saving crash info into external storage
545545
// So that wo just share the internal file
546546
val mainContent = """
547-
Dear developer, here are my crash info:
548-
549-
$crashInfo
550-
=====================
551-
APP:
552-
${BuildConfig.VERSION_CODE}, ${BuildConfig.VERSION_NAME}, ${BuildConfig.BUILD_TYPE}
553-
Devices:
554-
${Build.VERSION.RELEASE}, ${Build.VERSION.SDK_INT}, ${Build.DEVICE}, ${Build.MODEL}, ${Build.PRODUCT}, ${Build.MANUFACTURER}
555-
=====================
556-
${activity.getString(R.string.contributor_info)}
557-
=====================
558-
${System.currentTimeMillis().formatDate("yyy-MM-dd")}
559-
""".trimIndent()
547+
Dear developer, here are my crash info:
548+
```
549+
$crashInfo
550+
```
551+
---
552+
553+
APP:
554+
555+
${BuildConfig.VERSION_CODE}, ${BuildConfig.VERSION_NAME}, ${BuildConfig.BUILD_TYPE}
556+
557+
Devices:
558+
559+
${Build.VERSION.RELEASE}, ${Build.VERSION.SDK_INT}, ${Build.DEVICE}, ${Build.MODEL}, ${Build.PRODUCT}, ${Build.MANUFACTURER}
560+
561+
${System.currentTimeMillis().formatDate("yyy-MM-dd")}
562+
""".trimIndent()
560563
val intent = Intent(Intent.ACTION_SEND).apply {
561564
type = "message/rfc822"
562565
putExtra(Intent.EXTRA_EMAIL, arrayOf("hi@rosuh.me"))

app/src/main/java/me/rosuh/easywatermark/ui/theme/ThemeManager.kt

Lines changed: 0 additions & 85 deletions
This file was deleted.

app/src/main/java/me/rosuh/easywatermark/utils/ktx/ContextExtension.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import kotlinx.coroutines.launch
2121
import me.rosuh.cmonet.CMonet
2222
import me.rosuh.easywatermark.R
2323
import me.rosuh.easywatermark.ui.MainActivity
24-
import me.rosuh.easywatermark.ui.theme.ThemeManager
25-
import me.rosuh.easywatermark.ui.widget.RadioButton
2624

2725
fun Activity.isStoragePermissionGrated(): Boolean {
2826
val readGranted = ContextCompat.checkSelfPermission(

app/src/main/res/layout/activity_recovery.xml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
android:layout_marginTop="16dp"
2727
android:paddingStart="16dp"
2828
android:paddingEnd="16dp"
29-
android:text="糟糕,您似乎遇到了多次崩溃。现在已经自动进入恢复模式。以下是您的设备信息以及崩溃信息,辛苦您将其复制以后通过下列方式联系我们,将对解决问题非常有帮助。谢谢您!"
29+
android:text="@string/recovery_mode_tips"
3030
app:layout_constraintEnd_toEndOf="parent"
3131
app:layout_constraintStart_toStartOf="parent"
3232
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
3333

34-
3534
<ScrollView
3635
android:id="@+id/sv_info"
3736
android:layout_width="match_parent"
@@ -58,51 +57,49 @@
5857
android:layout_width="wrap_content"
5958
android:layout_height="wrap_content"
6059
android:layout_marginBottom="16dp"
61-
android:text="copy"
60+
android:text="@string/copy"
6261
app:layout_constraintBottom_toTopOf="@id/btn_email"
6362
app:layout_constraintEnd_toEndOf="parent"
6463
app:layout_constraintStart_toStartOf="parent" />
6564

6665
<com.google.android.material.button.MaterialButton
6766
android:id="@+id/btn_email"
67+
style="@style/Widget.Material3.Button.TextButton"
6868
android:layout_width="wrap_content"
6969
android:layout_height="wrap_content"
70-
android:layout_marginTop="16dp"
71-
android:layout_marginBottom="16dp"
7270
android:text="Send email"
73-
app:layout_constraintBottom_toTopOf="@id/btn_telegram"
74-
app:layout_constraintEnd_toEndOf="parent"
71+
app:layout_constraintBottom_toBottomOf="@+id/btn_telegram"
72+
app:layout_constraintEnd_toStartOf="@id/btn_telegram"
7573
app:layout_constraintStart_toStartOf="parent" />
7674

7775
<com.google.android.material.button.MaterialButton
7876
android:id="@+id/btn_telegram"
77+
style="@style/Widget.Material3.Button.TextButton"
7978
android:layout_width="wrap_content"
8079
android:layout_height="wrap_content"
81-
android:layout_marginTop="16dp"
82-
android:layout_marginBottom="16dp"
8380
android:text="Send Telegram"
84-
app:layout_constraintBottom_toTopOf="@id/btn_store"
85-
app:layout_constraintEnd_toEndOf="parent"
86-
app:layout_constraintStart_toStartOf="parent" />
81+
app:layout_constraintBottom_toBottomOf="@+id/btn_store"
82+
app:layout_constraintEnd_toStartOf="@id/btn_store"
83+
app:layout_constraintStart_toEndOf="@+id/btn_email" />
8784

8885
<com.google.android.material.button.MaterialButton
8986
android:id="@+id/btn_store"
87+
style="@style/Widget.Material3.Button.TextButton"
9088
android:layout_width="wrap_content"
9189
android:layout_height="wrap_content"
92-
android:layout_marginTop="16dp"
9390
android:layout_marginBottom="16dp"
9491
android:text="Jump to Store"
9592
app:layout_constraintBottom_toTopOf="@+id/btn_close_recovery_mode"
9693
app:layout_constraintEnd_toEndOf="parent"
97-
app:layout_constraintStart_toStartOf="parent" />
94+
app:layout_constraintStart_toEndOf="@+id/btn_telegram" />
9895

9996
<com.google.android.material.button.MaterialButton
10097
android:id="@+id/btn_close_recovery_mode"
10198
android:layout_width="wrap_content"
10299
android:layout_height="wrap_content"
103100
android:layout_marginTop="16dp"
104101
android:layout_marginBottom="48dp"
105-
android:text="关闭恢复模式"
102+
android:text="@string/turn_off_recovery_mode"
106103
app:layout_constraintBottom_toBottomOf="parent"
107104
app:layout_constraintEnd_toEndOf="parent"
108105
app:layout_constraintStart_toStartOf="parent" />

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@
106106
<string name="dialog_save_config_quality">质量</string>
107107
<string name="pick_via_system">Choose more...</string>
108108
<string name="gallery_pick_size">选择 %1$d</string>
109-
<string name="recovery_title">Recovery Mode</string>
109+
<string name="recovery_title">恢复模式</string>
110110
<string name="copy_success">复制成功</string>
111111
<string name="copy_failed">复制失败</string>
112112
<string name="telegram_not_found">Telegram 没有安装</string>
113113
<string name="store_not_found">好像没有安装商店</string>
114114
<string name="recovery_mode_closed">已关闭,重启后再试试看吧</string>
115+
<string name="copy">复制错误信息</string>
116+
<string name="recovery_mode_tips">糟糕,您似乎遇到了多次崩溃。现在已经自动进入恢复模式。以下是您的设备信息以及崩溃信息,辛苦您将其复制以后通过下列方式联系我们,将对解决问题非常有帮助。谢谢您!</string>
117+
<string name="turn_off_recovery_mode">关闭恢复模式</string>
115118

116119
</resources>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
<string name="telegram_not_found" translatable="false">Telegram is not installed.</string>
120120
<string name="store_not_found" translatable="false">Not Store was installed.</string>
121121
<string name="recovery_mode_closed" translatable="false">It\'s closed, please try again</string>
122+
<string name="copy" translatable="false">Copy error message</string>
123+
<string name="recovery_mode_tips" translatable="false">Oops, you seem to have experienced multiple crashes. It has now automatically entered recovery mode. Below is your device information and the crash information, it would be very helpful if you could copy it and contact us via the following methods to resolve the issue. Thank you!</string>
124+
<string name="turn_off_recovery_mode" translatable="false">Turn off recovery mode</string>
122125

123126

124127
</resources>

0 commit comments

Comments
 (0)