mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 12:42:56 -04:00
Add StartHotspotManually in KiwixDialog
Add neutralMessage in KiwixDialog constructor Refactor code in KiwixDialog, AlertDialogShower
This commit is contained in:
parent
7ea9ada728
commit
3d84589e64
@ -3,6 +3,7 @@ package org.kiwix.kiwixmobile.utils
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
|
import org.kiwix.kiwixmobile.utils.KiwixDialog.StartHotspotManually
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AlertDialogShower @Inject constructor(
|
class AlertDialogShower @Inject constructor(
|
||||||
@ -33,6 +34,14 @@ class AlertDialogShower @Inject constructor(
|
|||||||
?.invoke()
|
?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dialog === StartHotspotManually) {
|
||||||
|
dialog.neutralMessage?.let {
|
||||||
|
setNeutralButton(it) { _, _ ->
|
||||||
|
clickListeners.getOrNull(2)
|
||||||
|
?.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,12 @@ sealed class KiwixDialog(
|
|||||||
val title: Int?,
|
val title: Int?,
|
||||||
val message: Int,
|
val message: Int,
|
||||||
val positiveMessage: Int,
|
val positiveMessage: Int,
|
||||||
val negativeMessage: Int?
|
val negativeMessage: Int?,
|
||||||
|
val neutralMessage: Int?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
data class DeleteZim(override val args: Array<out Any>) : KiwixDialog(
|
data class DeleteZim(override val args: Array<out Any>) : 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 {
|
), HasBodyFormatArgs {
|
||||||
constructor(bookOnDisk: BookOnDisk) : this(arrayOf(bookOnDisk.book.title))
|
constructor(bookOnDisk: BookOnDisk) : this(arrayOf(bookOnDisk.book.title))
|
||||||
|
|
||||||
@ -31,25 +32,30 @@ sealed class KiwixDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
object LocationPermissionRationale : 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(
|
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(
|
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(
|
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(
|
object TurnOffHotspotManually : KiwixDialog(
|
||||||
R.string.hotspot_failed_title,
|
R.string.hotspot_failed_title,
|
||||||
R.string.hotspot_failed_message,
|
R.string.hotspot_failed_message,
|
||||||
R.string.go_to_wifi_settings_label,
|
R.string.go_to_wifi_settings_label,
|
||||||
|
null,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,6 +63,7 @@ sealed class KiwixDialog(
|
|||||||
R.string.hotspot_turned_on,
|
R.string.hotspot_turned_on,
|
||||||
R.string.hotspot_details_message,
|
R.string.hotspot_details_message,
|
||||||
android.R.string.ok,
|
android.R.string.ok,
|
||||||
|
null,
|
||||||
null
|
null
|
||||||
), HasBodyFormatArgs {
|
), HasBodyFormatArgs {
|
||||||
constructor(wifiConfiguration: WifiConfiguration) : this(
|
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<out Any>) : KiwixDialog(
|
data class FileTransferConfirmation(override val args: Array<out Any>) : 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 {
|
), HasBodyFormatArgs {
|
||||||
constructor(selectedPeerDeviceName: String) : this(arrayOf(selectedPeerDeviceName))
|
constructor(selectedPeerDeviceName: String) : this(arrayOf(selectedPeerDeviceName))
|
||||||
}
|
}
|
||||||
@ -76,7 +91,7 @@ sealed class KiwixDialog(
|
|||||||
open class YesNoDialog(
|
open class YesNoDialog(
|
||||||
title: Int,
|
title: Int,
|
||||||
message: 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(
|
object StopDownload : YesNoDialog(
|
||||||
R.string.confirm_stop_download_title, R.string.confirm_stop_download_msg
|
R.string.confirm_stop_download_title, R.string.confirm_stop_download_msg
|
||||||
)
|
)
|
||||||
|
@ -304,25 +304,26 @@ public class ZimHostActivity extends BaseActivity implements
|
|||||||
|
|
||||||
//Advice user to turn on hotspot manually for API<26
|
//Advice user to turn on hotspot manually for API<26
|
||||||
private void startHotspotManuallyDialog() {
|
private void startHotspotManuallyDialog() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this, dialogStyle());
|
|
||||||
|
|
||||||
builder.setPositiveButton(getString(R.string.go_to_settings_label),
|
alertDialogShower.show(KiwixDialog.StartHotspotManually.INSTANCE,
|
||||||
(dialog, id) -> launchTetheringSettingsScreen());
|
new Function0<Unit>() {
|
||||||
|
@Override public Unit invoke() {
|
||||||
builder.setNeutralButton(getString(R.string.hotspot_dialog_neutral_button), (dialog, id) -> {
|
launchTetheringSettingsScreen();
|
||||||
|
return Unit.INSTANCE;
|
||||||
progressDialog =
|
}
|
||||||
ProgressDialog.show(this, getString(R.string.progress_dialog_starting_server), "",
|
},
|
||||||
true);
|
null,
|
||||||
pollForValidIpAddress();
|
new Function0<Unit>() {
|
||||||
});
|
@Override public Unit invoke() {
|
||||||
|
progressDialog =
|
||||||
builder.setTitle(getString(R.string.hotspot_dialog_title));
|
ProgressDialog.show(ZimHostActivity.this,
|
||||||
builder.setMessage(
|
getString(R.string.progress_dialog_starting_server), "",
|
||||||
getString(R.string.hotspot_dialog_message)
|
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
|
//Keeps checking if hotspot has been turned using the ip address with an interval of 1 sec
|
||||||
|
Loading…
x
Reference in New Issue
Block a user