mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-13 17:38:42 -04:00
Replace All dialogs in CoreMainActivity and Add 2 attributes in KiwixDialog
This commit is contained in:
parent
338b21f318
commit
b8cd709a7a
@ -84,7 +84,7 @@ class ZimHostActivity : BaseActivity(), ZimHostCallbacks, ZimHostContract.View {
|
||||
}
|
||||
}
|
||||
}
|
||||
as ArrayList<String>
|
||||
as ArrayList<String>
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -221,7 +221,7 @@ class ZimHostActivity : BaseActivity(), ZimHostCallbacks, ZimHostContract.View {
|
||||
// Advice user to turn on hotspot manually for API<26
|
||||
private fun startHotspotManuallyDialog() {
|
||||
|
||||
alertDialogShower.show(KiwixDialog.StartHotspotManually(),
|
||||
alertDialogShower.show(KiwixDialog.StartHotspotManually,
|
||||
::launchTetheringSettingsScreen,
|
||||
{},
|
||||
{
|
||||
|
@ -25,12 +25,14 @@ import org.kiwix.kiwixmobile.core.di.ActivityScope
|
||||
import org.kiwix.kiwixmobile.core.di.modules.ActivityModule
|
||||
import org.kiwix.kiwixmobile.core.search.SearchActivity
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.ShowDeleteSearchDialog
|
||||
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
|
||||
|
||||
@ActivityScope
|
||||
@Subcomponent(modules = [ActivityModule::class])
|
||||
interface CoreActivityComponent {
|
||||
fun inject(searchActivity: SearchActivity)
|
||||
fun inject(showDeleteSearchDialog: ShowDeleteSearchDialog)
|
||||
fun inject(corePrefsFragment: CorePrefsFragment)
|
||||
|
||||
@Subcomponent.Builder
|
||||
interface Builder {
|
||||
|
@ -53,7 +53,6 @@ import android.widget.Toast;
|
||||
import androidx.annotation.AnimRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.AppCompatButton;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
@ -87,7 +86,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONArray;
|
||||
import org.kiwix.kiwixmobile.core.BuildConfig;
|
||||
@ -217,7 +215,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
@Inject
|
||||
protected NewBookDao newBookDao;
|
||||
@Inject
|
||||
private AlertDialogShower alertDialogShower;
|
||||
protected AlertDialogShower alertDialogShower;
|
||||
|
||||
private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) {
|
||||
@Override
|
||||
@ -642,28 +640,22 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
}
|
||||
|
||||
private void showRateDialog() {
|
||||
String title = getString(R.string.rate_dialog_title);
|
||||
String message = getString(R.string.rate_dialog_msg_1) + " "
|
||||
+ getString(R.string.app_name)
|
||||
+ getString(R.string.rate_dialog_msg_2);
|
||||
String positive = getString(R.string.rate_dialog_positive);
|
||||
String negative = getString(R.string.no_thanks);
|
||||
String neutral = getString(R.string.rate_dialog_neutral);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(positive, (dialog, id) -> {
|
||||
alertDialogShower.show(new KiwixDialog.ShowRate(getIconResId()),
|
||||
() -> {
|
||||
visitCounterPref.setNoThanksState(true);
|
||||
goToRateApp();
|
||||
})
|
||||
.setNegativeButton(negative, (dialog, id) -> visitCounterPref.setNoThanksState(true))
|
||||
.setNeutralButton(neutral, (dialog, id) -> {
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
() -> {
|
||||
visitCounterPref.setNoThanksState(true);
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
() ->{
|
||||
tempVisitCount = 0;
|
||||
visitCounterPref.setCount(tempVisitCount);
|
||||
})
|
||||
.setIcon(ContextCompat.getDrawable(this, getIconResId()))
|
||||
.show();
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected abstract int getIconResId();
|
||||
@ -1079,21 +1071,20 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
}
|
||||
|
||||
private void externalLinkPopup(Intent intent) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.external_link_popup_dialog_title)
|
||||
.setMessage(R.string.external_link_popup_dialog_message)
|
||||
.setNegativeButton(android.R.string.no, (dialogInterface, i) -> {
|
||||
// do nothing
|
||||
})
|
||||
.setNeutralButton(R.string.do_not_ask_anymore, (dialogInterface, i) -> {
|
||||
alertDialogShower.show(KiwixDialog.ExternalLinkPopup.INSTANCE,
|
||||
() -> {
|
||||
startActivity(intent);
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
() -> Unit.INSTANCE,
|
||||
() -> {
|
||||
sharedPreferenceUtil.putPrefExternalLinkPopup(false);
|
||||
isExternalLinkPopup = false;
|
||||
|
||||
startActivity(intent);
|
||||
})
|
||||
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> startActivity(intent))
|
||||
.setIcon(R.drawable.ic_warning)
|
||||
.show();
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected void openZimFile(@NonNull File file) {
|
||||
@ -1369,14 +1360,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
private void contentsDrawerHint() {
|
||||
drawerLayout.postDelayed(() -> drawerLayout.openDrawer(GravityCompat.END), 500);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.hint_contents_drawer_message))
|
||||
.setPositiveButton(getString(R.string.got_it), (dialog, id) -> {
|
||||
})
|
||||
.setTitle(R.string.did_you_know)
|
||||
.setIcon(R.drawable.icon_question);
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
alertDialogShower.show(KiwixDialog.ContentsDrawerHint.INSTANCE);
|
||||
}
|
||||
|
||||
private void openArticle(String articleUrl) {
|
||||
@ -1694,7 +1678,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
|
||||
protected void showOpenInNewTabDialog(String url) {
|
||||
alertDialogShower.show(KiwixDialog.YesNoDialog.OpenInNewTab.INSTANCE,
|
||||
(Function0<Unit>) () -> {
|
||||
() -> {
|
||||
if (isOpenNewTabInBackground) {
|
||||
newTabInBackground(url);
|
||||
Snackbar.make(snackbarRoot, R.string.new_tab_snack_bar, Snackbar.LENGTH_LONG)
|
||||
|
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.core.utils
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.StartHotspotManually
|
||||
import javax.inject.Inject
|
||||
|
||||
class AlertDialogShower @Inject constructor(private val activity: Activity) : DialogShower {
|
||||
@ -28,7 +27,7 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) : Di
|
||||
AlertDialog.Builder(activity)
|
||||
.apply {
|
||||
dialog.title?.let(this::setTitle)
|
||||
dialog.icon?.let { setIcon(dialog.icon) }
|
||||
dialog.icon?.let(this::setIcon)
|
||||
setMessage(activity.getString(dialog.message, *bodyArguments(dialog)))
|
||||
setPositiveButton(dialog.positiveMessage) { _, _ ->
|
||||
clickListeners.getOrNull(0)
|
||||
@ -40,8 +39,8 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) : Di
|
||||
?.invoke()
|
||||
}
|
||||
}
|
||||
if (dialog is StartHotspotManually) {
|
||||
setNeutralButton(dialog.neutralMessage) { _, _ ->
|
||||
dialog.neutralMessage?.let {
|
||||
setNeutralButton(it) { _, _ ->
|
||||
clickListeners.getOrNull(2)
|
||||
?.invoke()
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ sealed class KiwixDialog(
|
||||
val positiveMessage: Int,
|
||||
val negativeMessage: Int?,
|
||||
val cancelable: Boolean = true,
|
||||
val icon: Int? = null
|
||||
val icon: Int? = null,
|
||||
val neutralMessage: Int? = null
|
||||
) {
|
||||
|
||||
data class DeleteZim(override val args: List<Any>) : KiwixDialog(
|
||||
@ -85,13 +86,12 @@ sealed class KiwixDialog(
|
||||
)
|
||||
}
|
||||
|
||||
data class StartHotspotManually(
|
||||
val neutralMessage: Int = R.string.hotspot_dialog_neutral_button
|
||||
) : KiwixDialog(
|
||||
object StartHotspotManually : KiwixDialog(
|
||||
R.string.hotspot_dialog_title,
|
||||
R.string.hotspot_dialog_message,
|
||||
R.string.go_to_settings,
|
||||
null
|
||||
null,
|
||||
neutralMessage = R.string.hotspot_dialog_neutral_button
|
||||
)
|
||||
|
||||
data class FileTransferConfirmation(override val args: List<Any>) : KiwixDialog(
|
||||
@ -104,6 +104,46 @@ sealed class KiwixDialog(
|
||||
null, R.string.delete_recent_search_item, R.string.delete, R.string.no
|
||||
)
|
||||
|
||||
object ContentsDrawerHint : KiwixDialog(
|
||||
R.string.did_you_know,
|
||||
R.string.hint_contents_drawer_message,
|
||||
R.string.got_it,
|
||||
null,
|
||||
icon = R.drawable.icon_question
|
||||
)
|
||||
|
||||
object ExternalLinkPopup : KiwixDialog(
|
||||
R.string.external_link_popup_dialog_title,
|
||||
R.string.external_link_popup_dialog_message,
|
||||
android.R.string.yes,
|
||||
android.R.string.no,
|
||||
icon = R.drawable.ic_warning,
|
||||
neutralMessage = R.string.do_not_ask_anymore
|
||||
)
|
||||
|
||||
data class ShowRate(override val args: List<Any>, val custom_icon: Int?) : KiwixDialog(
|
||||
R.string.rate_dialog_title,
|
||||
R.string.triple_arg_format_string,
|
||||
R.string.rate_dialog_positive,
|
||||
R.string.no_thanks,
|
||||
icon = custom_icon,
|
||||
neutralMessage = R.string.rate_dialog_neutral
|
||||
),
|
||||
HasBodyFormatArgs {
|
||||
constructor(icon: Int?) : this(
|
||||
listOf(R.string.rate_dialog_msg_1, R.string.app_name, R.string.rate_dialog_msg_2),
|
||||
icon
|
||||
)
|
||||
}
|
||||
|
||||
object ClearAllHistory : KiwixDialog(
|
||||
R.string.clear_all_history_dialog_title,
|
||||
R.string.clear_recent_and_tabs_history_dialog,
|
||||
R.string.yes,
|
||||
R.string.no,
|
||||
icon = R.drawable.ic_warning
|
||||
)
|
||||
|
||||
open class YesNoDialog(
|
||||
title: Int,
|
||||
message: Int
|
||||
|
@ -5,5 +5,5 @@
|
||||
<item>medium</item>
|
||||
<item>large</item>
|
||||
</string-array>
|
||||
|
||||
<string name="triple_arg_format_string" translatable="false">%s %s %s</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user