Skip to content

Commit

Permalink
Re-suppress for ProgressDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
imknown committed Nov 29, 2019
1 parent caf5569 commit c37f7ad
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.imknown.android.forefrontinfo.ui.settings

import android.app.ProgressDialog
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -224,7 +223,8 @@ class SettingsFragment : PreferenceFragmentCompat(), IFragmentView, CoroutineSco
}
}

private lateinit var progressDialog: ProgressDialog
@Suppress("DEPRECATION")
private lateinit var progressDialog: android.app.ProgressDialog

private fun showDownloadConfirmDialog(githubReleaseInfo: GithubReleaseInfo) {
val version = githubReleaseInfo.tag_name
Expand Down Expand Up @@ -270,14 +270,15 @@ class SettingsFragment : PreferenceFragmentCompat(), IFragmentView, CoroutineSco
}
}

@Suppress("DEPRECATION")
private suspend fun showProgressDialog(
title: String,
size: Int,
sizeInMb: Float
) = withContext(Dispatchers.Main) {
progressDialog = ProgressDialog(context)
progressDialog = android.app.ProgressDialog(context)
with(progressDialog) {
setProgressStyle(ProgressDialog.STYLE_HORIZONTAL)
setProgressStyle(android.app.ProgressDialog.STYLE_HORIZONTAL)
isIndeterminate = false
setCancelable(false)
setCanceledOnTouchOutside(false)
Expand All @@ -293,10 +294,7 @@ class SettingsFragment : PreferenceFragmentCompat(), IFragmentView, CoroutineSco
private suspend fun downloadApk(url: String, fileName: String, sizeInMb: Float) {
try {
GatewayApi.downloadApk(url, fileName, { readBytes, _ ->
progressDialog.setProgressNumberFormat(
String.format("%.2fM/%.2fM", readBytes / 1_048_576F, sizeInMb)
)
progressDialog.progress = readBytes.toInt()
setProgress(readBytes, sizeInMb)
}, { data ->
if (data.isEmpty()) {
showError(Exception(MyApplication.getMyString(R.string.about_check_for_update_network_empty_file)))
Expand All @@ -311,6 +309,14 @@ class SettingsFragment : PreferenceFragmentCompat(), IFragmentView, CoroutineSco
}
}

@Suppress("DEPRECATION")
private fun setProgress(readBytes: Long, sizeInMb: Float) {
progressDialog.setProgressNumberFormat(
String.format("%.2fM/%.2fM", readBytes / 1_048_576F, sizeInMb)
)
progressDialog.progress = readBytes.toInt()
}

private fun install(fileName: String) = launch {
withContext(Dispatchers.IO) {
val intent = Intent(Intent.ACTION_VIEW)
Expand Down

0 comments on commit c37f7ad

Please sign in to comment.