Skip to content

Commit

Permalink
更换部分图标、当未获取到安装包大小时分享字符串不显示大小、Json 详情对话框显示标题、报错对话框文案优化 (#31)
Browse files Browse the repository at this point in the history
- 优化:更换设置、用户协议和报错图标,新增 Json 详情对话框图标
- 修复:当未获取到安装包大小时分享字符串显示大小为“-0.00 MB”的问题
- 优化:Json 详情对话框显示“Json 详情”标题
- 优化:报错对话框文案

---

- 代码中去除部分 if-else 单行语句的大括号
  • Loading branch information
ArcticFoxPro authored Apr 5, 2024
1 parent f5b407c commit 302fbc0
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 84 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = gitCommitCount
versionName = "1.2.3-$gitCommitHash"
versionName = "1.2.4-$gitCommitHash"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
97 changes: 44 additions & 53 deletions app/src/main/java/com/xiaoniu/qqversionlist/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class MainActivity : AppCompatActivity() {
return (dp * resources.displayMetrics.density).toInt()
}

// 未来可期的 px to dp 函数
// private fun Context.pxToDp(px: Int): Int {
// return (px / resources.displayMetrics.density).toInt()
// }
Expand All @@ -110,16 +111,16 @@ class MainActivity : AppCompatActivity() {
// 对于每一项都添加底部间距
bottom = space
// 如果不是第一行,则添加顶部间距
if (parent.getChildAdapterPosition(view) != 0) {
top = space
}
if (parent.getChildAdapterPosition(view) != 0) top = space

}
}
}


private fun showUADialog(agreed: Boolean) {

// 屏幕高度获取
val screenHeight = Resources.getSystem().displayMetrics.heightPixels

//用户协议,传参内容表示先前是否同意过协议
Expand All @@ -128,20 +129,25 @@ class MainActivity : AppCompatActivity() {
val dialogUA =
MaterialAlertDialogBuilder(this)
.setTitle("用户协议")
.setIcon(R.drawable.file_user_line)
.setIcon(R.drawable.file_text_line)
.setView(userAgreementBinding.root)
.setCancelable(false)
.create()

val constraintSet = ConstraintSet()
constraintSet.clone(userAgreementBinding.userAgreement)

// 屏幕方向判断,不同方向分别设置相应的约束布局用户协议子项高度
val currentConfig = resources.configuration
if (currentConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
constraintSet.constrainHeight(R.id.UA_text, screenHeight / 6)
} else if (currentConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
constraintSet.constrainHeight(R.id.UA_text, screenHeight / 2)
}
if (currentConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) constraintSet.constrainHeight(
R.id.UA_text,
screenHeight / 6
)
else if (currentConfig.orientation == Configuration.ORIENTATION_PORTRAIT) constraintSet.constrainHeight(
R.id.UA_text,
screenHeight / 2
)


constraintSet.applyTo(userAgreementBinding.userAgreement)

Expand All @@ -152,12 +158,9 @@ class MainActivity : AppCompatActivity() {

userAgreementBinding.uaButtonDisagree.setOnClickListener {
SpUtil.putInt("userAgreement", 0)
//不同意直接退出程序
finish()
}
if (agreed) {
userAgreementBinding.uaButtonDisagree.text = "撤回同意并退出"
finish() // 不同意直接退出程序
}
if (agreed) userAgreementBinding.uaButtonDisagree.text = "撤回同意并退出"

dialogUA.show()
}
Expand All @@ -169,13 +172,10 @@ class MainActivity : AppCompatActivity() {

//这里的“getInt: userAgreement”的值代表着用户协议修订版本,后续更新协议版本后也需要在下面一行把“judgeUARead”+1,以此类推
val judgeUARead = 1
if (SpUtil.getInt("userAgreement", 0) != judgeUARead) {
showUADialog(false)
}
if (SpUtil.getInt("userAgreement", 0) != judgeUARead) showUADialog(false)

// 进度条动画
// https://github.com/material-components/material-components-android/blob/master/docs/components/ProgressIndicator.md

binding.progressLine.apply {
showAnimationBehavior = LinearProgressIndicator.SHOW_NONE
hideAnimationBehavior = LinearProgressIndicator.HIDE_ESCAPE
Expand Down Expand Up @@ -205,8 +205,8 @@ class MainActivity : AppCompatActivity() {
}
withContext(Dispatchers.Main) {
versionAdapter.setData(qqVersion)
//currentQQVersion = qqVersion.first().versionNumber
//大版本号也放持久化存储了,否则猜版 Shortcut 因为加载过快而获取不到东西
// 舍弃 currentQQVersion = qqVersion.first().versionNumber
// 大版本号也放持久化存储了,否则猜版 Shortcut 因为加载过快而获取不到东西
SpUtil.putString(
"versionBig", qqVersion.first().versionNumber
)
Expand All @@ -229,11 +229,8 @@ class MainActivity : AppCompatActivity() {
binding.rvContent.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (dy > 0) {
binding.btnGuess.shrink()
} else if (dy < 0) {
binding.btnGuess.extend()
}
if (dy > 0) binding.btnGuess.shrink()
else if (dy < 0) binding.btnGuess.extend()
}
})

Expand Down Expand Up @@ -262,7 +259,7 @@ class MainActivity : AppCompatActivity() {
message.length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
val aboutDialog = MaterialAlertDialogBuilder(this)
MaterialAlertDialogBuilder(this)
.setTitle("关于")
.setIcon(R.drawable.information_line)
.setMessage(message)
Expand Down Expand Up @@ -359,6 +356,7 @@ class MainActivity : AppCompatActivity() {
}
})

// 舍弃
// dialogGuessBinding.spinnerVersion.setOnFocusChangeListener { _, hasFocus ->
// if (hasFocus) {
// val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
Expand Down Expand Up @@ -399,9 +397,9 @@ class MainActivity : AppCompatActivity() {
if (versionSmall != 0) {
SpUtil.putInt("versionSmall", versionSmall)
}/*我偷懒了,因为我上面也有偷懒逻辑,
为了防止 null,我在正式版猜版时默认填入了 0,
但是我没处理下面涉及到持久化存储逻辑的语句,就把 0 存进去了,
覆盖了原来的 15xxx 的持久化存储*/
为了防止 null,我在正式版猜版时默认填入了 0,
但是我没处理下面涉及到持久化存储逻辑的语句,就把 0 存进去了,
覆盖了原来的 15xxx 的持久化存储*/

guessUrl(versionBig, versionSmall, mode)

Expand Down Expand Up @@ -438,12 +436,9 @@ class MainActivity : AppCompatActivity() {
}


/**
* 获取文件大小(以MB为单位)
*
* @param urlString 文件的URL字符串
* @param callback 回调函数,接收文件大小(以MB为单位)作为参数
*/
/*获取文件大小(以MB为单位)
@param urlString 文件的URL字符串
@param callback 回调函数,接收文件大小(以MB为单位)作为参数*/
private fun getFileSizeInMB(urlString: String, callback: (String) -> Unit) {
CoroutineScope(Dispatchers.IO).launch {
try {
Expand All @@ -461,13 +456,14 @@ class MainActivity : AppCompatActivity() {
e.printStackTrace()
withContext(Dispatchers.Main) {
callback("Error")
dialogError(e)
}
}
}
}


//https://downv6.qq.com/qqweb/QQ_1/android_apk/Android_8.9.75.XXXXX_64.apk
// https://downv6.qq.com/qqweb/QQ_1/android_apk/Android_8.9.75.XXXXX_64.apk
private fun guessUrl(versionBig: String, versionSmall: Int, mode: String) {
// 绑定 AlertDialog 加载对话框布局
val dialogLoadingBinding = DialogLoadingBinding.inflate(layoutInflater)
Expand All @@ -484,7 +480,7 @@ class MainActivity : AppCompatActivity() {
fun updateProgressDialogMessage(newMessage: String) {
dialogLoadingBinding.loadingMessage.text = newMessage
if (!progressDialog.isShowing) {
progressDialog.show()//更新文本后才显示对话框
progressDialog.show()// 更新文本后才显示对话框
}
}

Expand Down Expand Up @@ -545,11 +541,7 @@ class MainActivity : AppCompatActivity() {
vSmall += if (!SpUtil.getBoolean(
"guessNot5", false
)
) {
5
} else {
1
}
) 5 else 1
successMaterialDialog.dismiss()
status = STATUS_ONGOING
}
Expand All @@ -569,8 +561,13 @@ class MainActivity : AppCompatActivity() {
type = "text/plain"
putExtra(
Intent.EXTRA_TEXT,
if (mode == MODE_OFFICIAL) "Android QQ $versionBig 正式版(大小:$appSize MB)\n\n下载地址:$link"
else "Android QQ $versionBig.$vSmall 测试版(大小:$appSize MB)\n\n下载地址:$link"
if (appSize != "Error" && appSize != "-0.00" && appSize != "0.00") {
if (mode == MODE_OFFICIAL) "Android QQ $versionBig 正式版(大小:$appSize MB)\n\n下载地址:$link"
else "Android QQ $versionBig.$vSmall 测试版(大小:$appSize MB)\n\n下载地址:$link"
} else {
if (mode == MODE_OFFICIAL) "Android QQ $versionBig 正式版\n\n下载地址:$link"
else "Android QQ $versionBig.$vSmall 测试版\n\n下载地址:$link"
}
)
}
startActivity(
Expand All @@ -590,7 +587,7 @@ class MainActivity : AppCompatActivity() {
Environment.DIRECTORY_DOWNLOADS,
"Android_QQ_${versionBig}.${vSmall}_64.apk"
)
} else if (mode == MODE_OFFICIAL){
} else if (mode == MODE_OFFICIAL) {
request1.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
"Android_QQ_${versionBig}_64.apk"
Expand All @@ -608,11 +605,7 @@ class MainActivity : AppCompatActivity() {
vSmall += if (!SpUtil.getBoolean(
"guessNot5", false
)
) {
5
} else {
1
}
) 5 else 1
}
}

Expand All @@ -621,9 +614,7 @@ class MainActivity : AppCompatActivity() {
}

STATUS_END -> {
if (mode != MODE_OFFICIAL) {
showToast("已停止猜测")
}
if (mode != MODE_OFFICIAL) showToast("已停止猜测")
progressDialog.dismiss()
break
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/xiaoniu/qqversionlist/ui/VersionAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.core.view.setPadding
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.xiaoniu.qqversionlist.R
import com.xiaoniu.qqversionlist.data.QQVersionBean
import com.xiaoniu.qqversionlist.databinding.ItemVersionBinding
import com.xiaoniu.qqversionlist.databinding.ItemVersionDetailBinding
Expand Down Expand Up @@ -187,8 +187,12 @@ class VersionAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
val tv = TextView(context).apply {
text = s
setTextIsSelectable(true)
setPadding(100)
setPadding(100, 50, 100, 100)
}
MaterialAlertDialogBuilder(context).setView(tv).show()
MaterialAlertDialogBuilder(context)
.setView(tv)
.setTitle("Json 详情")
.setIcon(R.drawable.braces_line)
.show()
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/xiaoniu/qqversionlist/util/InfoUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ object InfoUtil {
fun Activity.dialogError(e: Exception) {
runOnUiThread {
MaterialAlertDialogBuilder(this)
.setTitle("程序出错,可前往 GitHub 反馈")
.setIcon(R.drawable.error_warning_line)
.setMessage(e.stackTraceToString())
.setTitle("程序出错")
.setIcon(R.drawable.alert_line)
.setMessage("如需反馈,请前往 GitHub 仓库报告 Issue(s) 并随附以下信息:\n\n" + e.stackTraceToString())
.setPositiveButton("确定", null)
.setCancelable(false)
.setNeutralButton("复制", null)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/alert_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12.8659 3.00017L22.3922 19.5002C22.6684 19.9785 22.5045 20.5901 22.0262 20.8662C21.8742 20.954 21.7017 21.0002 21.5262 21.0002H2.47363C1.92135 21.0002 1.47363 20.5525 1.47363 20.0002C1.47363 19.8246 1.51984 19.6522 1.60761 19.5002L11.1339 3.00017C11.41 2.52187 12.0216 2.358 12.4999 2.63414C12.6519 2.72191 12.7782 2.84815 12.8659 3.00017ZM4.20568 19.0002H19.7941L11.9999 5.50017L4.20568 19.0002ZM10.9999 16.0002H12.9999V18.0002H10.9999V16.0002ZM10.9999 9.00017H12.9999V14.0002H10.9999V9.00017Z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/braces_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M4,18V14.3C4,13.472 3.328,12.8 2.5,12.8H2V11.2H2.5C3.328,11.2 4,10.528 4,9.7V6C4,4.343 5.343,3 7,3H8V5H7C6.448,5 6,5.448 6,6V10.1C6,10.986 5.424,11.737 4.626,12C5.424,12.263 6,13.014 6,13.9V18C6,18.552 6.448,19 7,19H8V21H7C5.343,21 4,19.657 4,18ZM20,14.3V18C20,19.657 18.657,21 17,21H16V19H17C17.552,19 18,18.552 18,18V13.9C18,13.014 18.576,12.263 19.374,12C18.576,11.737 18,10.986 18,10.1V6C18,5.448 17.552,5 17,5H16V3H17C18.657,3 20,4.343 20,6V9.7C20,10.528 20.672,11.2 21.5,11.2H22V12.8H21.5C20.672,12.8 20,13.472 20,14.3Z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/clipboard_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M7,4V2H17V4H20.007C20.555,4 21,4.445 21,4.993V21.007C21,21.555 20.555,22 20.007,22H3.993C3.445,22 3,21.555 3,21.007V4.993C3,4.445 3.445,4 3.993,4H7ZM7,6H5V20H19V6H17V8H7V6ZM9,4V6H15V4H9Z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M3,19H21V21H3V19ZM13,13.172L19.071,7.101L20.485,8.515L12,17L3.515,8.515L4.929,7.101L11,13.172V2H13V13.172Z"
android:pathData="M3 19H21V21H3V19ZM13 13.1716L19.0711 7.1005L20.4853 8.51472L12 17L3.51472 8.51472L4.92893 7.1005L11 13.1716V2H13V13.1716Z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/error_warning_line.xml

This file was deleted.

9 changes: 9 additions & 0 deletions app/src/main/res/drawable/file_text_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21 8V20.9932C21 21.5501 20.5552 22 20.0066 22H3.9934C3.44495 22 3 21.556 3 21.0082V2.9918C3 2.45531 3.4487 2 4.00221 2H14.9968L21 8ZM19 9H14V4H5V20H19V9ZM8 7H11V9H8V7ZM8 11H16V13H8V11ZM8 15H16V17H8V15Z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/file_user_line.xml

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/res/drawable/settings_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,1L21.5,6.5V17.5L12,23L2.5,17.5V6.5L12,1ZM12,3.311L4.5,7.653V16.347L12,20.689L19.5,16.347V7.653L12,3.311ZM12,16C9.791,16 8,14.209 8,12C8,9.791 9.791,8 12,8C14.209,8 16,9.791 16,12C16,14.209 14.209,16 12,16ZM12,14C13.105,14 14,13.105 14,12C14,10.895 13.105,10 12,10C10.895,10 10,10.895 10,12C10,13.105 10.895,14 12,14Z"
android:pathData="M17.5 2.47363L23 11.9999L17.5 21.5262H6.5L1 11.9999L6.5 2.47363H17.5ZM16.3453 4.47363H7.6547L3.3094 11.9999L7.6547 19.5262H16.3453L20.6906 11.9999L16.3453 4.47363ZM8.63398 8.16979L10.366 7.16979L15.366 15.83L13.634 16.83L8.63398 8.16979Z"
android:fillColor="?attr/colorControlNormal"/>
</vector>
Loading

0 comments on commit 302fbc0

Please sign in to comment.