Refine code
This commit is contained in:
parent
248676e573
commit
f7e72e2d89
4 changed files with 23 additions and 20 deletions
17
app/src/main/kotlin/cn/super12138/todo/utils/VersionUtils.kt
Normal file
17
app/src/main/kotlin/cn/super12138/todo/utils/VersionUtils.kt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package cn.super12138.todo.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
|
||||
object VersionUtils {
|
||||
fun getAppVersion(context: Context): String {
|
||||
val pkgInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
val verName = pkgInfo.versionName
|
||||
val verCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
pkgInfo.longVersionCode.toInt()
|
||||
} else {
|
||||
pkgInfo.versionCode
|
||||
}
|
||||
return "$verName($verCode)"
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import cn.super12138.todo.constant.Constants
|
||||
import cn.super12138.todo.databinding.ActivityAboutBinding
|
||||
import cn.super12138.todo.utils.VersionUtils
|
||||
import cn.super12138.todo.utils.showToast
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
|
||||
|
|
@ -19,14 +20,7 @@ class AboutActivity : BaseActivity() {
|
|||
binding = ActivityAboutBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val pkgInfo = packageManager.getPackageInfo(packageName, 0)
|
||||
val verName = pkgInfo.versionName
|
||||
val verCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
pkgInfo.longVersionCode.toInt()
|
||||
} else {
|
||||
pkgInfo.versionCode
|
||||
}
|
||||
binding.appVersion.text = "$verName($verCode)"
|
||||
binding.appVersion.text = VersionUtils.getAppVersion(this)
|
||||
|
||||
binding.toolBar.setNavigationOnClickListener {
|
||||
finish()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import androidx.core.view.ViewCompat
|
|||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import cn.super12138.todo.databinding.ActivityCrashBinding
|
||||
import cn.super12138.todo.utils.VersionUtils
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
|
|
@ -42,17 +43,8 @@ class CrashActivity : BaseActivity() {
|
|||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
val formattedDateTime = formatter.format(currentDateTime)
|
||||
|
||||
val pkgInfo = packageManager.getPackageInfo(packageName, 0)
|
||||
val verName = pkgInfo.versionName
|
||||
val verCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
pkgInfo.longVersionCode.toInt()
|
||||
} else {
|
||||
pkgInfo.versionCode
|
||||
}
|
||||
val mergeVer = "$verName($verCode)"
|
||||
|
||||
val deviceInfo = StringBuilder().apply {
|
||||
append("ToDo version: ").append(mergeVer).append('\n')
|
||||
append("ToDo version: ").append(VersionUtils.getAppVersion(this@CrashActivity)).append('\n')
|
||||
append("Brand: ").append("").append(deviceBrand).append('\n')
|
||||
append("Model: ").append(deviceModel).append('\n')
|
||||
append("Device SDK: ").append(sdkLevel).append('\n').append('\n')
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".views.crash.CrashActivity">
|
||||
|
||||
<ScrollView
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
android:textIsSelectable="true"
|
||||
android:textSize="13sp" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/exit_app"
|
||||
|
|
|
|||
Loading…
Reference in a new issue