V1.0.5(6) 增加重试按钮

This commit is contained in:
litingting 2024-08-23 16:08:20 +08:00
parent d14c57fb95
commit e7d7a4e7eb
4 changed files with 89 additions and 30 deletions

View File

@ -6,6 +6,7 @@ import android.content.SharedPreferences
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.DataSource
@ -80,7 +81,6 @@ class DownloadActivity :
} }
private fun initTitle() { private fun initTitle() {
binding.bgName.text = "Keyboard background" binding.bgName.text = "Keyboard background"
} }
@ -100,6 +100,7 @@ class DownloadActivity :
} }
private fun initStyleList() { private fun initStyleList() {
retryBtnStatus(false)
val listOf = mutableListOf<String>() val listOf = mutableListOf<String>()
backgroundEntity.skinNumber.let { backgroundEntity.skinNumber.let {
for (i in 0 until 5) { for (i in 0 until 5) {
@ -114,7 +115,7 @@ class DownloadActivity :
val keyAdapter = KeyAdapter(this, defaultStyle, listOf) { val keyAdapter = KeyAdapter(this, defaultStyle, listOf) {
selectedStyle = it + 1 selectedStyle = it + 1
if (appliedSkinNumber == backgroundEntity.skinNumber.toString()) { if (appliedSkinNumber == backgroundEntity.skinNumber.toString()) {
updateBtn(appliedSkinStyle == selectedStyle) updateBtn(if (appliedSkinStyle == selectedStyle) 0 else 1)
} }
} }
binding.listRecycler.run { binding.listRecycler.run {
@ -126,35 +127,49 @@ class DownloadActivity :
} }
private fun initButton() { private fun initButton() {
binding.downloadBack.setOnClickListener(this) binding.downloadBack.setOnClickListener(this)
binding.btnDownload.setOnClickListener(this) binding.btnDownload.setOnClickListener(this)
binding.imLike.setOnClickListener(this) binding.imLike.setOnClickListener(this)
binding.btnRetry.setOnClickListener(this)
} }
/** /**
* isApplied 是否已经apply * 0 已经apply 2 下载失败置灰
*/ */
private fun updateBtn(isApplied: Boolean) { private fun updateBtn(type: Int) {
binding.btnDownload.isSelected = isApplied
binding.btnDownload.isEnabled = !isApplied when (type) {
if (isApplied) { 0 -> {
binding.btnDownload.isSelected = true
binding.btnDownload.isEnabled = false
binding.btnDownload.text = getString(R.string.applied) binding.btnDownload.text = getString(R.string.applied)
} else { }
1 -> {
binding.btnDownload.isSelected = false
binding.btnDownload.isEnabled = true
binding.btnDownload.text = getString(R.string.apply) binding.btnDownload.text = getString(R.string.apply)
} }
2 -> {
binding.btnDownload.isSelected = true
binding.btnDownload.isEnabled = false
binding.btnDownload.text = getString(R.string.apply)
}
}
} }
private fun initImg() { private fun initImg() {
appliedSkinNumber = sp.getString(AppConstant.KEY_CUR_Skin_Number, "") ?: run { "-1" } appliedSkinNumber = sp.getString(AppConstant.KEY_CUR_Skin_Number, "") ?: run { "-1" }
appliedSkinStyle = sp.getInt(AppConstant.KEY_CUR_STYLE, -1) appliedSkinStyle = sp.getInt(AppConstant.KEY_CUR_STYLE, -1)
if (appliedSkinNumber == backgroundEntity.skinNumber.toString()) { // if (appliedSkinNumber == backgroundEntity.skinNumber.toString()) {
updateBtn(appliedSkinStyle == selectedStyle) // updateBtn(if (appliedSkinStyle == selectedStyle) 0 else 1)
}else{ // } else {
updateBtn(false) // updateBtn(1)
} // }
binding.imLike.isSelected = backgroundEntity.like binding.imLike.isSelected = backgroundEntity.like
try { try {
Glide Glide
@ -181,13 +196,26 @@ class DownloadActivity :
} }
binding.btnRetry->{
binding.downloadProgress.visibility = View.VISIBLE
initDownload()
}
binding.imLike -> { binding.imLike -> {
AdManager.showTopOn(this@DownloadActivity){ AdManager.showTopOn(this@DownloadActivity) {
binding.imLike.isSelected = !binding.imLike.isSelected binding.imLike.isSelected = !binding.imLike.isSelected
if(binding.imLike.isSelected){ if (binding.imLike.isSelected) {
Toast.makeText(this@DownloadActivity,getString(R.string.add_success),Toast.LENGTH_SHORT).show() Toast.makeText(
}else{ this@DownloadActivity,
Toast.makeText(this@DownloadActivity,getString(R.string.cancel_success),Toast.LENGTH_SHORT).show() getString(R.string.add_success),
Toast.LENGTH_SHORT
).show()
} else {
Toast.makeText(
this@DownloadActivity,
getString(R.string.cancel_success),
Toast.LENGTH_SHORT
).show()
} }
} }
@ -235,7 +263,10 @@ class DownloadActivity :
putInt(AppConstant.KEY_CUR_STYLE, selectedStyle) putInt(AppConstant.KEY_CUR_STYLE, selectedStyle)
putString(AppConstant.KEY_CUR_Bg, backgroundEntity.coverPath) putString(AppConstant.KEY_CUR_Bg, backgroundEntity.coverPath)
apply() apply()
Log.d(App.TAG, "------putConfig ----skin_Number = ${ backgroundEntity.skinNumber} style=${selectedStyle} ") Log.d(
App.TAG,
"------putConfig ----skin_Number = ${backgroundEntity.skinNumber} style=${selectedStyle} "
)
} }
binding.downloadProgress.visibility = View.GONE binding.downloadProgress.visibility = View.GONE
@ -318,11 +349,21 @@ class DownloadActivity :
unzipPath = str unzipPath = str
binding.downloadProgress.visibility = View.GONE binding.downloadProgress.visibility = View.GONE
if (isSuccess) { if (isSuccess) {
initStyleList() initStyleList()
} else { } else {
Toast.makeText(this, getString(R.string.reenter), Toast.LENGTH_LONG).show() retryBtnStatus(true)
Toast.makeText(this, getString(R.string.reenter), Toast.LENGTH_SHORT).show()
} }
} }
private fun retryBtnStatus(showRetry:Boolean){
binding.btnRetry.isVisible = showRetry
if(showRetry){
updateBtn(2)
}else{
updateBtn(1)
}
}
} }

View File

@ -13,7 +13,7 @@ class LoadingActivity : BaseActivity() {
private var countDownTimer: CountDownTimer?= null private var countDownTimer: CountDownTimer?= null
private val time = 12000L private val time = 13000L
override fun onUI() { override fun onUI() {
countDownTimer = AdManager.showWelcomeAd(this@LoadingActivity, time, { millisUntilFinished -> countDownTimer = AdManager.showWelcomeAd(this@LoadingActivity, time, { millisUntilFinished ->
val percentage: Float = 100 - millisUntilFinished.toFloat() / time * 100 val percentage: Float = 100 - millisUntilFinished.toFloat() / time * 100

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
@ -44,12 +43,12 @@
android:textSize="18sp" /> android:textSize="18sp" />
<ImageView <ImageView
android:id="@+id/im_like"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="40dp" android:layout_height="40dp"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="15dp"
android:paddingTop="5dp" android:paddingTop="5dp"
android:id="@+id/im_like" android:paddingEnd="15dp"
android:paddingBottom="5dp" android:paddingBottom="5dp"
android:src="@drawable/selector_like" /> android:src="@drawable/selector_like" />
</LinearLayout> </LinearLayout>
@ -100,7 +99,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_marginStart="70dp" android:layout_marginStart="70dp"
android:layout_marginTop="50dp" android:layout_marginTop="30dp"
android:layout_marginEnd="70dp" android:layout_marginEnd="70dp"
android:background="@drawable/selector_step" android:background="@drawable/selector_step"
android:gravity="center" android:gravity="center"
@ -108,6 +107,24 @@
android:textColor="@color/step_text_color" android:textColor="@color/step_text_color"
android:textSize="19sp" /> android:textSize="19sp" />
<TextView
android:id="@+id/btn_retry"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginStart="70dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="70dp"
android:layout_marginBottom="10dp"
android:background="@drawable/selector_step"
android:gravity="center"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="@string/retry"
android:visibility="gone"
android:textColor="@color/step_text_color"
android:textSize="19sp" />
</LinearLayout> </LinearLayout>

View File

@ -19,7 +19,7 @@
<string name="unEnable">If the keyboard is not enabled, please set it in the settings</string> <string name="unEnable">If the keyboard is not enabled, please set it in the settings</string>
<string name="succ_apply">Application successful</string> <string name="succ_apply">Application successful</string>
<string name="fail_apply">Application failed, please try again</string> <string name="fail_apply">Application failed, please try again</string>
<string name="reenter">Download failed, please re-enter this page</string> <string name="reenter">Please check your network connection and try again</string>
<string name="slect_key">Please select the following button background</string> <string name="slect_key">Please select the following button background</string>
<string name="display">Display</string> <string name="display">Display</string>
<string name="display_et">Enter text to see the effect</string> <string name="display_et">Enter text to see the effect</string>
@ -27,6 +27,7 @@
<string name="app_privacy">Privacy Policy</string> <string name="app_privacy">Privacy Policy</string>
<string name="add_success">Added to favorites successfully</string> <string name="add_success">Added to favorites successfully</string>
<string name="cancel_success">Successfully canceled the collection</string> <string name="cancel_success">Successfully canceled the collection</string>
<string name="retry">Retry</string>
<string name="delete_res">skin_%s_delete_emoji.png</string> <string name="delete_res">skin_%s_delete_emoji.png</string>
<string name="caps_res">skin_%s_caps_enabled.png</string> <string name="caps_res">skin_%s_caps_enabled.png</string>