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