Merge pull request #3417 from kiwix/Issue#3336

Fixes of ProgressDialog is deprecated
This commit is contained in:
Kelson 2023-06-23 07:03:38 +02:00 committed by GitHub
commit b00c3ecc9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 9 deletions

View File

@ -20,7 +20,8 @@ package org.kiwix.kiwixmobile.webserver
import android.Manifest
import android.Manifest.permission.POST_NOTIFICATIONS
import android.app.ProgressDialog
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.ComponentName
import android.content.Context
import android.content.Intent
@ -54,6 +55,7 @@ import org.kiwix.kiwixmobile.core.utils.ServerUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.StartServer
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter
@ -85,7 +87,7 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
private var hotspotService: HotspotService? = null
private var ip: String? = null
private lateinit var serviceConnection: ServiceConnection
private var progressDialog: ProgressDialog? = null
private var dialog: Dialog? = null
private var activityZimHostBinding: ActivityZimHostBinding? = null
private val selectedBooksPath: ArrayList<String>
get() {
@ -271,12 +273,14 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
}
}
@SuppressLint("InflateParams")
private fun startKiwixHotspot() {
progressDialog = ProgressDialog.show(
requireActivity(),
getString(R.string.progress_dialog_starting_server), "",
true
)
if (dialog == null) {
val dialogView: View =
layoutInflater.inflate(R.layout.item_custom_spinner, null)
dialog = alertDialogShower.create(StartServer { dialogView })
}
dialog?.show()
requireActivity().startService(createHotspotIntent(ACTION_CHECK_IP_ADDRESS))
}
@ -450,7 +454,7 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
}
override fun onIpAddressValid() {
progressDialog?.dismiss()
dialog?.dismiss()
requireActivity().startService(
createHotspotIntent(ACTION_START_SERVER).putStringArrayListExtra(
SELECTED_ZIM_PATHS_KEY, selectedBooksPath
@ -459,7 +463,7 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
}
override fun onIpAddressInvalid() {
progressDialog?.dismiss()
dialog?.dismiss()
toast(R.string.server_failed_message, Toast.LENGTH_SHORT)
}

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Kiwix Android
~ Copyright (c) 2023 Kiwix <android.kiwix.org>
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
~
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:indeterminate="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -22,6 +22,7 @@ import android.app.Activity
import android.view.View
import org.kiwix.kiwixmobile.core.R
@Suppress("LongParameterList")
sealed class KiwixDialog(
val title: Int?,
val message: Int?,
@ -227,6 +228,14 @@ sealed class KiwixDialog(
getView = customGetView
)
data class StartServer(val customGetView: (() -> View)?) : KiwixDialog(
R.string.progress_dialog_starting_server,
null,
R.string.empty_string,
null,
getView = customGetView
)
object NotesDiscardConfirmation : KiwixDialog(
null,
R.string.confirmation_alert_dialog_message,

View File

@ -338,4 +338,5 @@
<string name="navigation_history_cleared">Navigation History Cleared</string>
<string name="go_to_settings_label">Go to Settings</string>
<string name="request_notification_permission_message">To perform this action, please grant notification access</string>
<string name="empty_string" />
</resources>