diff --git a/app/src/main/java/org/kiwix/kiwixmobile/utils/AlertDialogShower.kt b/app/src/main/java/org/kiwix/kiwixmobile/utils/AlertDialogShower.kt index eeb38f78b..50b7b3919 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/utils/AlertDialogShower.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/utils/AlertDialogShower.kt @@ -3,6 +3,7 @@ package org.kiwix.kiwixmobile.utils import android.app.Activity import android.app.AlertDialog import org.kiwix.kiwixmobile.R +import org.kiwix.kiwixmobile.utils.KiwixDialog.StartHotspotManually import javax.inject.Inject class AlertDialogShower @Inject constructor( @@ -33,6 +34,14 @@ class AlertDialogShower @Inject constructor( ?.invoke() } } + if (dialog === StartHotspotManually) { + dialog.neutralMessage?.let { + setNeutralButton(it) { _, _ -> + clickListeners.getOrNull(2) + ?.invoke() + } + } + } } .show() } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/utils/KiwixDialog.kt b/app/src/main/java/org/kiwix/kiwixmobile/utils/KiwixDialog.kt index 5dd872ac3..a6ebe9953 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/utils/KiwixDialog.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/utils/KiwixDialog.kt @@ -8,11 +8,12 @@ sealed class KiwixDialog( val title: Int?, val message: Int, val positiveMessage: Int, - val negativeMessage: Int? + val negativeMessage: Int?, + val neutralMessage: Int? ) { data class DeleteZim(override val args: Array) : KiwixDialog( - null, R.string.delete_zim_body, R.string.delete, R.string.no + null, R.string.delete_zim_body, R.string.delete, R.string.no, null ), HasBodyFormatArgs { constructor(bookOnDisk: BookOnDisk) : this(arrayOf(bookOnDisk.book.title)) @@ -31,25 +32,30 @@ sealed class KiwixDialog( } object LocationPermissionRationale : KiwixDialog( - null, R.string.permission_rationale_location, android.R.string.yes, android.R.string.cancel + null, + R.string.permission_rationale_location, + android.R.string.yes, + android.R.string.cancel, + null ) object StoragePermissionRationale : KiwixDialog( - null, R.string.request_storage, android.R.string.yes, android.R.string.cancel + null, R.string.request_storage, android.R.string.yes, android.R.string.cancel, null ) object EnableWifiP2pServices : KiwixDialog( - null, R.string.request_enable_wifi, R.string.yes, android.R.string.no + null, R.string.request_enable_wifi, R.string.yes, android.R.string.no, null ) object EnableLocationServices : KiwixDialog( - null, R.string.request_enable_location, R.string.yes, android.R.string.no + null, R.string.request_enable_location, R.string.yes, android.R.string.no, null ) object TurnOffHotspotManually : KiwixDialog( R.string.hotspot_failed_title, R.string.hotspot_failed_message, R.string.go_to_wifi_settings_label, + null, null ) @@ -57,6 +63,7 @@ sealed class KiwixDialog( R.string.hotspot_turned_on, R.string.hotspot_details_message, android.R.string.ok, + null, null ), HasBodyFormatArgs { constructor(wifiConfiguration: WifiConfiguration) : this( @@ -67,8 +74,16 @@ sealed class KiwixDialog( ) } + object StartHotspotManually : KiwixDialog( + R.string.hotspot_dialog_title, + R.string.hotspot_dialog_message, + R.string.go_to_settings_label, + null, + R.string.hotspot_dialog_neutral_button + ) + data class FileTransferConfirmation(override val args: Array) : KiwixDialog( - null, R.string.transfer_to, R.string.yes, android.R.string.cancel + null, R.string.transfer_to, R.string.yes, android.R.string.cancel, null ), HasBodyFormatArgs { constructor(selectedPeerDeviceName: String) : this(arrayOf(selectedPeerDeviceName)) } @@ -76,7 +91,7 @@ sealed class KiwixDialog( open class YesNoDialog( title: Int, message: Int - ) : KiwixDialog(title, message, R.string.yes, R.string.no) { + ) : KiwixDialog(title, message, R.string.yes, R.string.no, null) { object StopDownload : YesNoDialog( R.string.confirm_stop_download_title, R.string.confirm_stop_download_msg ) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java index 484fd3109..f7ac3ad6e 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java @@ -304,25 +304,26 @@ public class ZimHostActivity extends BaseActivity implements //Advice user to turn on hotspot manually for API<26 private void startHotspotManuallyDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this, dialogStyle()); - builder.setPositiveButton(getString(R.string.go_to_settings_label), - (dialog, id) -> launchTetheringSettingsScreen()); - - builder.setNeutralButton(getString(R.string.hotspot_dialog_neutral_button), (dialog, id) -> { - - progressDialog = - ProgressDialog.show(this, getString(R.string.progress_dialog_starting_server), "", - true); - pollForValidIpAddress(); - }); - - builder.setTitle(getString(R.string.hotspot_dialog_title)); - builder.setMessage( - getString(R.string.hotspot_dialog_message) + alertDialogShower.show(KiwixDialog.StartHotspotManually.INSTANCE, + new Function0() { + @Override public Unit invoke() { + launchTetheringSettingsScreen(); + return Unit.INSTANCE; + } + }, + null, + new Function0() { + @Override public Unit invoke() { + progressDialog = + ProgressDialog.show(ZimHostActivity.this, + getString(R.string.progress_dialog_starting_server), "", + true); + pollForValidIpAddress(); + return Unit.INSTANCE; + } + } ); - AlertDialog dialog = builder.create(); - dialog.show(); } //Keeps checking if hotspot has been turned using the ip address with an interval of 1 sec