Merge pull request #2 from kiwix/develop

Update
This commit is contained in:
Deborah Low 2020-02-27 22:29:55 +08:00 committed by GitHub
commit 03be00e101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 199 additions and 139 deletions

View File

@ -11,7 +11,7 @@ apply(from = rootProject.file("jacoco.gradle"))
ext { ext {
set("versionMajor", 3) set("versionMajor", 3)
set("versionMinor", 2) set("versionMinor", 2)
set("versionPatch", 0) set("versionPatch", 1)
} }
fun generateVersionName() = "${ext["versionMajor"]}.${ext["versionMinor"]}.${ext["versionPatch"]}" fun generateVersionName() = "${ext["versionMajor"]}.${ext["versionMinor"]}.${ext["versionPatch"]}"

View File

@ -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,
{}, {},
{ {

View File

@ -13,7 +13,7 @@ repositories {
dependencies { dependencies {
implementation("com.android.tools.build:gradle:3.5.3") implementation("com.android.tools.build:gradle:3.5.3")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61")
implementation("com.dicedmelon.gradle:jacoco-android:0.1.4") implementation("com.hiya:jacoco-android:0.2")
implementation("org.jlleitschuh.gradle:ktlint-gradle:9.2.1") implementation("org.jlleitschuh.gradle:ktlint-gradle:9.2.1")
implementation("com.google.apis:google-api-services-androidpublisher:v3-rev129-1.25.0") implementation("com.google.apis:google-api-services-androidpublisher:v3-rev129-1.25.0")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.5.1") implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.5.1")

View File

@ -263,7 +263,7 @@ object Libs {
*/ */
const val collection_ktx: String = "androidx.collection:collection-ktx:" + Versions.collection_ktx const val collection_ktx: String = "androidx.collection:collection-ktx:" + Versions.collection_ktx
const val jacoco_android: String = "com.dicedmelon.gradle:jacoco-android:" + const val jacoco_android: String = "com.hiya:jacoco-android:" +
Versions.jacoco_android Versions.jacoco_android
/** /**

View File

@ -55,7 +55,7 @@ object Versions {
const val collection_ktx: String = "1.1.0" const val collection_ktx: String = "1.1.0"
const val jacoco_android: String = "0.1.4" const val jacoco_android: String = "0.2"
const val junit_jupiter: String = "5.4.2" // available: "5.6.0" const val junit_jupiter: String = "5.4.2" // available: "5.6.0"

View File

@ -39,7 +39,7 @@ class AllProjectConfigurer {
target.plugins.apply("kotlin-android") target.plugins.apply("kotlin-android")
target.plugins.apply("kotlin-android-extensions") target.plugins.apply("kotlin-android-extensions")
target.plugins.apply("kotlin-kapt") target.plugins.apply("kotlin-kapt")
target.plugins.apply("jacoco-android") target.plugins.apply("com.hiya.jacoco-android")
target.plugins.apply("org.jlleitschuh.gradle.ktlint") target.plugins.apply("org.jlleitschuh.gradle.ktlint")
target.plugins.apply("io.gitlab.arturbosch.detekt") target.plugins.apply("io.gitlab.arturbosch.detekt")
} }
@ -52,12 +52,12 @@ class AllProjectConfigurer {
setMinSdkVersion(Config.minSdk) setMinSdkVersion(Config.minSdk)
setTargetSdkVersion(Config.targetSdk) setTargetSdkVersion(Config.targetSdk)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
} }
buildTypes { buildTypes {
getByName("debug") { getByName("debug") {
isTestCoverageEnabled = true isTestCoverageEnabled = true
multiDexEnabled = true
} }
} }

View File

@ -394,7 +394,7 @@ performance:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
SpreadOperator: SpreadOperator:
active: true active: false
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
UnnecessaryTemporaryInstantiation: UnnecessaryTemporaryInstantiation:
active: true active: true

View File

@ -17,13 +17,14 @@
*/ */
package org.kiwix.kiwixmobile.core; package org.kiwix.kiwixmobile.core;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.StrictMode; import android.os.StrictMode;
import android.util.Log; import android.util.Log;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
import androidx.multidex.MultiDexApplication; import androidx.multidex.MultiDex;
import com.jakewharton.threetenabp.AndroidThreeTen; import com.jakewharton.threetenabp.AndroidThreeTen;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -33,7 +34,7 @@ import org.kiwix.kiwixmobile.core.di.components.CoreComponent;
import org.kiwix.kiwixmobile.core.di.components.DaggerCoreComponent; import org.kiwix.kiwixmobile.core.di.components.DaggerCoreComponent;
import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor; import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor;
public abstract class CoreApp extends MultiDexApplication { public abstract class CoreApp extends Application {
private static CoreApp app; private static CoreApp app;
private static CoreComponent coreComponent; private static CoreComponent coreComponent;
@ -64,6 +65,9 @@ public abstract class CoreApp extends MultiDexApplication {
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
super.attachBaseContext(base); super.attachBaseContext(base);
if (BuildConfig.DEBUG) {
MultiDex.install(this);
}
app = this; app = this;
setCoreComponent(DaggerCoreComponent.builder() setCoreComponent(DaggerCoreComponent.builder()
.context(this) .context(this)

View File

@ -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 {

View File

@ -54,7 +54,6 @@ import org.kiwix.kiwixmobile.core.reader.ZimContentProvider
import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.search.SearchActivity import org.kiwix.kiwixmobile.core.search.SearchActivity
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity
import org.kiwix.kiwixmobile.core.utils.BookUtils import org.kiwix.kiwixmobile.core.utils.BookUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
@ -107,7 +106,6 @@ interface CoreComponent {
fun inject(application: CoreApp) fun inject(application: CoreApp)
fun inject(zimContentProvider: ZimContentProvider) fun inject(zimContentProvider: ZimContentProvider)
fun inject(kiwixWebView: KiwixWebView) fun inject(kiwixWebView: KiwixWebView)
fun inject(prefsFragment: CorePrefsFragment)
fun inject(storageSelectDialog: StorageSelectDialog) fun inject(storageSelectDialog: StorageSelectDialog)
fun inject(addNoteDialog: AddNoteDialog) fun inject(addNoteDialog: AddNoteDialog)

View File

@ -19,12 +19,13 @@
package org.kiwix.kiwixmobile.core.main; package org.kiwix.kiwixmobile.core.main;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import org.kiwix.kiwixmobile.core.R; import javax.inject.Inject;
import kotlin.Unit;
import org.kiwix.kiwixmobile.core.utils.DialogShower;
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
/** /**
@ -48,6 +49,8 @@ public class ConfirmationAlertDialogFragment extends DialogFragment {
private SharedPreferenceUtil sharedPreferenceUtil; private SharedPreferenceUtil sharedPreferenceUtil;
private int stringResourceId; private int stringResourceId;
private String parentDialogFragmentTAG; private String parentDialogFragmentTAG;
@Inject
protected DialogShower alertDialogShower;
public ConfirmationAlertDialogFragment(SharedPreferenceUtil sharedPreferenceUtil, public ConfirmationAlertDialogFragment(SharedPreferenceUtil sharedPreferenceUtil,
String parentDialogFragmentTAG, int stringResourceId) { String parentDialogFragmentTAG, int stringResourceId) {
@ -59,27 +62,20 @@ public class ConfirmationAlertDialogFragment extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
Fragment parentDialogFragment = getFragmentManager().findFragmentByTag(parentDialogFragmentTAG); Fragment parentDialogFragment = getFragmentManager().findFragmentByTag(parentDialogFragmentTAG);
return alertDialogShower.create(new KiwixDialog.ConfirmationAlertDialogFragment(stringResourceId),
return new AlertDialog.Builder(getActivity()).setMessage(stringResourceId) () -> {
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (parentDialogFragment != null) { if (parentDialogFragment != null) {
((UserClickListener) parentDialogFragment).onPositiveClick(); ((UserClickListener) parentDialogFragment).onPositiveClick();
} }
} return Unit.INSTANCE;
}) },
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { () -> {
@Override
public void onClick(DialogInterface dialog, int which) {
if (parentDialogFragment != null) { if (parentDialogFragment != null) {
((UserClickListener) parentDialogFragment).onNegativeClick(); ((UserClickListener) parentDialogFragment).onNegativeClick();
} }
return Unit.INSTANCE;
} }
}) );
.create();
} }
/** /**

View File

@ -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;
@ -109,7 +108,9 @@ import org.kiwix.kiwixmobile.core.reader.ZimFileReader;
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer; import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
import org.kiwix.kiwixmobile.core.search.SearchActivity; import org.kiwix.kiwixmobile.core.search.SearchActivity;
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchInPreviousScreen; import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchInPreviousScreen;
import org.kiwix.kiwixmobile.core.utils.DialogShower;
import org.kiwix.kiwixmobile.core.utils.DimenUtils; import org.kiwix.kiwixmobile.core.utils.DimenUtils;
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
import org.kiwix.kiwixmobile.core.utils.LanguageUtils; import org.kiwix.kiwixmobile.core.utils.LanguageUtils;
import org.kiwix.kiwixmobile.core.utils.NetworkUtils; import org.kiwix.kiwixmobile.core.utils.NetworkUtils;
import org.kiwix.kiwixmobile.core.utils.StyleUtils; import org.kiwix.kiwixmobile.core.utils.StyleUtils;
@ -213,6 +214,8 @@ public abstract class CoreMainActivity extends BaseActivity
protected NewBookmarksDao newBookmarksDao; protected NewBookmarksDao newBookmarksDao;
@Inject @Inject
protected NewBookDao newBookDao; protected NewBookDao newBookDao;
@Inject
protected DialogShower alertDialogShower;
private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) { private CountDownTimer hideBackToTopTimer = new CountDownTimer(1200, 1200) {
@Override @Override
@ -637,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();
@ -1074,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 },
}) null,
.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) {
@ -1364,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) {
@ -1688,9 +1677,8 @@ public abstract class CoreMainActivity extends BaseActivity
} }
protected void showOpenInNewTabDialog(String url) { protected void showOpenInNewTabDialog(String url) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); alertDialogShower.show(KiwixDialog.YesNoDialog.OpenInNewTab.INSTANCE,
() -> {
builder.setPositiveButton(android.R.string.yes, (dialog, id) -> {
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)
@ -1702,11 +1690,8 @@ public abstract class CoreMainActivity extends BaseActivity
} else { } else {
newTab(url); newTab(url);
} }
return Unit.INSTANCE;
}); });
builder.setNegativeButton(android.R.string.no, null);
builder.setMessage(getString(R.string.open_in_new_tab));
AlertDialog dialog = builder.create();
dialog.show();
} }
@Override @Override

View File

@ -144,7 +144,6 @@ class SearchActivity : BaseActivity() {
} }
private fun render(searchString: String) { private fun render(searchString: String) {
searchView.setQuery(searchString, false)
searchInTextMenuItem.isEnabled = searchString.isNotBlank() searchInTextMenuItem.isEnabled = searchString.isNotBlank()
} }

View File

@ -53,7 +53,6 @@ import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchIntentProcessin
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.ShowDeleteSearchDialog import org.kiwix.kiwixmobile.core.search.viewmodel.effects.ShowDeleteSearchDialog
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.ShowToast import org.kiwix.kiwixmobile.core.search.viewmodel.effects.ShowToast
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.StartSpeechInput import org.kiwix.kiwixmobile.core.search.viewmodel.effects.StartSpeechInput
import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
class SearchViewModel @Inject constructor( class SearchViewModel @Inject constructor(
@ -127,8 +126,7 @@ class SearchViewModel @Inject constructor(
searchResultsFromZimReader(), searchResultsFromZimReader(),
filter, filter,
Function3(this::reduce) Function3(this::reduce)
).debounce(100, MILLISECONDS) ).subscribe(state::postValue, Throwable::printStackTrace)
.subscribe(state::postValue, Throwable::printStackTrace)
private fun reduce( private fun reduce(
recentSearchResults: List<SearchListItem>, recentSearchResults: List<SearchListItem>,

View File

@ -33,7 +33,6 @@ import android.view.LayoutInflater;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import eu.mhutti1.utils.storage.StorageDevice; import eu.mhutti1.utils.storage.StorageDevice;
@ -50,6 +49,8 @@ import org.kiwix.kiwixmobile.core.NightModeConfig;
import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.R;
import org.kiwix.kiwixmobile.core.extensions.ContextExtensionsKt; import org.kiwix.kiwixmobile.core.extensions.ContextExtensionsKt;
import org.kiwix.kiwixmobile.core.main.AddNoteDialog; import org.kiwix.kiwixmobile.core.main.AddNoteDialog;
import org.kiwix.kiwixmobile.core.utils.DialogShower;
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
import org.kiwix.kiwixmobile.core.utils.LanguageUtils; import org.kiwix.kiwixmobile.core.utils.LanguageUtils;
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
@ -75,12 +76,17 @@ public abstract class CorePrefsFragment extends PreferenceFragment implements
protected StorageCalculator storageCalculator; protected StorageCalculator storageCalculator;
@Inject @Inject
protected NightModeConfig nightModeConfig; protected NightModeConfig nightModeConfig;
@Inject
protected DialogShower alertDialogShower;
private SliderPreference mSlider; private SliderPreference mSlider;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
CoreApp.getCoreComponent().inject(this); CoreApp.getCoreComponent()
.activityComponentBuilder()
.activity(getActivity())
.build()
.inject(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
@ -199,28 +205,20 @@ public abstract class CorePrefsFragment extends PreferenceFragment implements
} }
private void clearAllHistoryDialog() { private void clearAllHistoryDialog() {
new AlertDialog.Builder(getActivity()) alertDialogShower.show(KiwixDialog.ClearAllHistory.INSTANCE, () -> {
.setTitle(getResources().getString(R.string.clear_all_history_dialog_title))
.setMessage(getResources().getString(R.string.clear_recent_and_tabs_history_dialog))
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
presenter.clearHistory(); presenter.clearHistory();
CoreSettingsActivity.allHistoryCleared = true; CoreSettingsActivity.allHistoryCleared = true;
Toast.makeText(getActivity(), ContextExtensionsKt.toast(getActivity(), R.string.all_history_cleared_toast,
getResources().getString(R.string.all_history_cleared_toast), Toast.LENGTH_SHORT) Toast.LENGTH_SHORT);
.show(); return Unit.INSTANCE;
}) });
.setNegativeButton(android.R.string.no, (dialog, which) -> {
// do nothing
})
.setIcon(R.drawable.ic_warning)
.show();
} }
private void showClearAllNotesDialog() { private void showClearAllNotesDialog() {
new AlertDialog.Builder(getActivity()).setMessage(R.string.delete_notes_confirmation_msg) alertDialogShower.show(KiwixDialog.ClearAllNotes.INSTANCE, () -> {
.setNegativeButton(android.R.string.cancel, null) // Do nothing for 'Cancel' button clearAllNotes();
.setPositiveButton(R.string.yes, (dialog, which) -> clearAllNotes()) return Unit.INSTANCE;
.show(); });
} }
private void clearAllNotes() { private void clearAllNotes() {
@ -252,10 +250,7 @@ public abstract class CorePrefsFragment extends PreferenceFragment implements
view.getSettings().setJavaScriptEnabled(true); view.getSettings().setJavaScriptEnabled(true);
view.setBackgroundColor(0); view.setBackgroundColor(0);
} }
new AlertDialog.Builder(getActivity()) alertDialogShower.show(new KiwixDialog.OpenCredits(() -> view));
.setView(view)
.setPositiveButton(android.R.string.ok, null)
.show();
} }
@Override @Override

View File

@ -19,16 +19,21 @@
package org.kiwix.kiwixmobile.core.utils package org.kiwix.kiwixmobile.core.utils
import android.app.Activity import android.app.Activity
import android.app.Dialog
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 {
override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit) { override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit) {
AlertDialog.Builder(activity) create(dialog, *clickListeners).show()
}
override fun create(dialog: KiwixDialog, vararg clickListeners: () -> Unit): Dialog {
return AlertDialog.Builder(activity)
.apply { .apply {
dialog.title?.let(this::setTitle) dialog.title?.let(this::setTitle)
setMessage(activity.getString(dialog.message, *bodyArguments(dialog))) dialog.icon?.let(this::setIcon)
dialog.message?.let { setMessage(activity.getString(it, *bodyArguments(dialog))) }
setPositiveButton(dialog.positiveMessage) { _, _ -> setPositiveButton(dialog.positiveMessage) { _, _ ->
clickListeners.getOrNull(0) clickListeners.getOrNull(0)
?.invoke() ?.invoke()
@ -39,15 +44,16 @@ 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()
} }
} }
dialog.getView?.let { setView(it()) }
setCancelable(dialog.cancelable) setCancelable(dialog.cancelable)
} }
.show() .create()
} }
private fun bodyArguments(dialog: KiwixDialog) = private fun bodyArguments(dialog: KiwixDialog) =

View File

@ -17,9 +17,16 @@
*/ */
package org.kiwix.kiwixmobile.core.utils package org.kiwix.kiwixmobile.core.utils
import android.app.Dialog
interface DialogShower { interface DialogShower {
fun show( fun show(
dialog: KiwixDialog, dialog: KiwixDialog,
vararg clickListeners: (() -> Unit) vararg clickListeners: (() -> Unit)
) )
fun create(
dialog: KiwixDialog,
vararg clickListeners: (() -> Unit)
): Dialog
} }

View File

@ -19,15 +19,19 @@
package org.kiwix.kiwixmobile.core.utils package org.kiwix.kiwixmobile.core.utils
import android.net.wifi.WifiConfiguration import android.net.wifi.WifiConfiguration
import android.view.View
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
sealed class KiwixDialog( 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 cancelable: Boolean = true val cancelable: Boolean = true,
val icon: Int? = null,
val neutralMessage: Int? = null,
val getView: (() -> View)? = null
) { ) {
data class DeleteZim(override val args: List<Any>) : KiwixDialog( data class DeleteZim(override val args: List<Any>) : KiwixDialog(
@ -84,13 +88,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(
@ -103,6 +106,68 @@ 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 customIcon: Int?) : KiwixDialog(
R.string.rate_dialog_title,
R.string.triple_arg_format_string,
R.string.rate_dialog_positive,
R.string.no_thanks,
icon = customIcon,
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
)
object ClearAllNotes : KiwixDialog(
null,
R.string.delete_notes_confirmation_msg,
R.string.yes,
android.R.string.cancel
)
data class OpenCredits(val customGetView: (() -> View)?) : KiwixDialog(
null,
null,
android.R.string.ok,
null,
getView = customGetView
)
data class ConfirmationAlertDialogFragment(val customMessage: Int) : KiwixDialog(
null,
customMessage,
R.string.yes,
android.R.string.cancel
)
open class YesNoDialog( open class YesNoDialog(
title: Int, title: Int,
message: Int message: Int
@ -114,6 +179,10 @@ sealed class KiwixDialog(
object WifiOnly : YesNoDialog( object WifiOnly : YesNoDialog(
R.string.wifi_only_title, R.string.wifi_only_msg R.string.wifi_only_title, R.string.wifi_only_msg
) )
object OpenInNewTab : YesNoDialog(
R.string.open_in_new_tab, R.string.open_in_new_tab
)
} }
} }

View File

@ -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>

View File

@ -39,6 +39,7 @@
<style name="Widget.KiwixTheme.Chip.Choice.Static" parent="Widget.MaterialComponents.Chip.Choice"> <style name="Widget.KiwixTheme.Chip.Choice.Static" parent="Widget.MaterialComponents.Chip.Choice">
<item name="android:clickable">false</item> <item name="android:clickable">false</item>
<item name="android:textAlignment" tools:ignore="NewApi">center</item>
</style> </style>
<style name="list_item_title" parent="TextAppearance.KiwixTheme.Subtitle1" /> <style name="list_item_title" parent="TextAppearance.KiwixTheme.Subtitle1" />

View File

@ -1,6 +1,6 @@
#Sun Jun 16 15:57:45 CDT 2019 #Tue Feb 25 11:46:45 IST 2020
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip

View File

@ -51,10 +51,10 @@ task jacocoInstrumentationTestReport(type: JacocoReport, dependsOn: ['createDebu
includes: ['jacoco/testDebugUnitTest.exec', includes: ['jacoco/testDebugUnitTest.exec',
'outputs/code_coverage/debugAndroidTest/connected/**/*.ec']) 'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])
} }
sourceDirectories = files([javaSrc, kotlinSrc]) sourceDirectories.from = files(javaSrc, kotlinSrc)
classDirectories = files([javaClasses, kotlinClasses]) classDirectories.from = files(javaClasses, kotlinClasses)
print execution print execution
executionData = files(execution) executionData.from = files(execution)
doLast() { doLast() {
print "file://${reports.html.destination}/index.html" print "file://${reports.html.destination}/index.html"
} }