mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 02:18:04 -04:00
Merge pull request #3 from kiwix/develop
update my local branch approved
This commit is contained in:
commit
a0799e8ff0
@ -55,8 +55,8 @@ import org.kiwix.kiwixmobile.ActivityExtensionsKt;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.core.base.BaseActivity;
|
||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent;
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.local_file_transfer.adapter.WifiP2pDelegate;
|
||||
import org.kiwix.kiwixmobile.local_file_transfer.adapter.WifiPeerListAdapter;
|
||||
|
||||
|
@ -42,8 +42,8 @@ import android.widget.Toast
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.BuildConfig
|
||||
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.FileTransferConfirmation
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.FileTransferConfirmation
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.local_file_transfer.FileItem.FileStatus
|
||||
import org.kiwix.kiwixmobile.local_file_transfer.KiwixWifiP2pBroadcastReceiver.P2pEventListener
|
||||
|
@ -139,4 +139,6 @@ class KiwixMainActivity : CoreMainActivity() {
|
||||
bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getIconResId() = R.mipmap.ic_launcher
|
||||
}
|
||||
|
@ -294,8 +294,6 @@ class KiwixReaderFragment : CoreReaderFragment() {
|
||||
private fun getSharedPrefSettings() =
|
||||
activity?.getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
|
||||
|
||||
override fun getIconResId() = R.mipmap.ic_launcher
|
||||
|
||||
override fun createNewTab() {
|
||||
newMainPageTab()
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ import org.kiwix.kiwixmobile.core.BuildConfig
|
||||
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
||||
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.ConnectivityReporter
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.ServerUtils
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate
|
||||
@ -244,7 +244,8 @@ 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,
|
||||
::openWifiSettings,
|
||||
{}
|
||||
|
@ -25,8 +25,8 @@ import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
||||
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteZims
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteZims
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
||||
|
@ -43,9 +43,9 @@ import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel
|
||||
import org.kiwix.kiwixmobile.core.extensions.snack
|
||||
import org.kiwix.kiwixmobile.core.utils.BookUtils
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.StopDownload
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.WifiOnly
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.YesNoDialog.StopDownload
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.YesNoDialog.WifiOnly
|
||||
import org.kiwix.kiwixmobile.core.utils.NetworkUtils
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
||||
|
@ -30,8 +30,8 @@ import org.kiwix.kiwixmobile.core.main.MainMenu.Factory
|
||||
import org.kiwix.kiwixmobile.core.main.MainMenu.MenuClickListener
|
||||
import org.kiwix.kiwixmobile.core.main.MainRepositoryActions
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
|
||||
@Module
|
||||
abstract class ActivityModule {
|
||||
|
@ -57,8 +57,8 @@ import org.kiwix.kiwixmobile.core.CoreApp;
|
||||
import org.kiwix.kiwixmobile.core.R;
|
||||
import org.kiwix.kiwixmobile.core.R2;
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,7 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
|
||||
import org.kiwix.kiwixmobile.core.extensions.browserIntent
|
||||
import org.kiwix.kiwixmobile.core.help.HelpActivity
|
||||
import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.RateDialogHandler
|
||||
import javax.inject.Inject
|
||||
|
||||
const val KIWIX_SUPPORT_URL = "https://www.kiwix.org/support"
|
||||
@ -48,6 +49,7 @@ const val ZIM_FILE_URI_KEY = "zimFileUri"
|
||||
abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
||||
|
||||
@Inject lateinit var externalLinkOpener: ExternalLinkOpener
|
||||
@Inject lateinit var rateDialogHandler: RateDialogHandler
|
||||
protected lateinit var drawerToggle: ActionBarDrawerToggle
|
||||
|
||||
abstract val navController: NavController
|
||||
@ -65,6 +67,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
rateDialogHandler.checkForRateDialog(getIconResId())
|
||||
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||
configureActivityBasedOn(destination)
|
||||
}
|
||||
@ -218,4 +221,6 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
||||
}
|
||||
|
||||
abstract fun openPage(pageUrl: String, zimFilePath: String = "")
|
||||
|
||||
protected abstract fun getIconResId(): Int
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.core.main;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
@ -112,11 +111,10 @@ import org.kiwix.kiwixmobile.core.reader.ZimFileReader;
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
|
||||
import org.kiwix.kiwixmobile.core.search.SearchActivity;
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchInPreviousScreen;
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener;
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.NetworkUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
|
||||
import org.kiwix.kiwixmobile.core.utils.StyleUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils;
|
||||
@ -240,8 +238,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
private ActionMode actionMode = null;
|
||||
private KiwixWebView tempWebViewForUndo;
|
||||
private File tempZimFileForUndo;
|
||||
private RateAppCounter visitCounterPref;
|
||||
private int tempVisitCount;
|
||||
private boolean isFirstRun;
|
||||
protected ActionBar actionBar;
|
||||
private TableDrawerAdapter tableDrawerAdapter;
|
||||
@ -338,8 +334,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
tableDrawerRight =
|
||||
tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list);
|
||||
|
||||
checkForRateDialog();
|
||||
|
||||
addFileReader();
|
||||
setupTabsAdapter();
|
||||
setTableDrawerInfo();
|
||||
@ -644,59 +638,6 @@ public abstract class CoreReaderFragment extends BaseFragment
|
||||
return Super.ShouldNotCall;
|
||||
}
|
||||
|
||||
private void checkForRateDialog() {
|
||||
isFirstRun = sharedPreferenceUtil.getPrefIsFirstRun();
|
||||
visitCounterPref = new RateAppCounter(getActivity());
|
||||
tempVisitCount = visitCounterPref.getCount();
|
||||
++tempVisitCount;
|
||||
visitCounterPref.setCount(tempVisitCount);
|
||||
|
||||
if (tempVisitCount >= 10
|
||||
&& !visitCounterPref.getNoThanksState()
|
||||
&& NetworkUtils.isNetworkAvailable(getActivity()) && !BuildConfig.DEBUG) {
|
||||
showRateDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void showRateDialog() {
|
||||
alertDialogShower.show(new KiwixDialog.ShowRate(getIconResId()),
|
||||
() -> {
|
||||
visitCounterPref.setNoThanksState(true);
|
||||
goToRateApp();
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
() -> {
|
||||
visitCounterPref.setNoThanksState(true);
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
() -> {
|
||||
tempVisitCount = 0;
|
||||
visitCounterPref.setCount(tempVisitCount);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected abstract int getIconResId();
|
||||
|
||||
private void goToRateApp() {
|
||||
Uri kiwixLocalMarketUri = Uri.parse("market://details?id=" + getActivity().getPackageName());
|
||||
Uri kiwixBrowserMarketUri =
|
||||
Uri.parse("http://play.google.com/store/apps/details?id=" + getActivity().getPackageName());
|
||||
|
||||
Intent goToMarket = new Intent(Intent.ACTION_VIEW, kiwixLocalMarketUri);
|
||||
|
||||
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
|
||||
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
|
||||
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
|
||||
try {
|
||||
startActivity(goToMarket);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, kiwixBrowserMarketUri));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTitle() {
|
||||
if (isAdded()) {
|
||||
actionBar.setTitle(getValidTitle(zimReaderContainer.getZimFileTitle()));
|
||||
|
@ -15,31 +15,18 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.core.main;
|
||||
package org.kiwix.kiwixmobile.core.main
|
||||
|
||||
import android.content.Context;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import android.content.Context
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
|
||||
public class FileReader {
|
||||
|
||||
public String readFile(String filePath, Context context) {
|
||||
try {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
InputStream json = context.getAssets().open(filePath);
|
||||
BufferedReader in =
|
||||
new BufferedReader(new InputStreamReader(json, "UTF-8"));
|
||||
String str;
|
||||
|
||||
while ((str = in.readLine()) != null) {
|
||||
buf.append(str);
|
||||
}
|
||||
|
||||
in.close();
|
||||
return buf.toString();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
class FileReader {
|
||||
fun readFile(filePath: String?, context: Context): String = try {
|
||||
context.assets.open(filePath)
|
||||
.bufferedReader()
|
||||
.use(BufferedReader::readText)
|
||||
} catch (e: IOException) {
|
||||
"".also { e.printStackTrace() }
|
||||
}
|
||||
}
|
@ -26,9 +26,9 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkItem
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.PageState
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllBookmarks
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedBookmarks
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllBookmarks
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedBookmarks
|
||||
import javax.inject.Inject
|
||||
|
||||
data class ShowDeleteBookmarksDialog(
|
||||
|
@ -25,9 +25,9 @@ import org.kiwix.kiwixmobile.core.dao.PageDao
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent
|
||||
import org.kiwix.kiwixmobile.core.page.history.viewmodel.HistoryState
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllHistory
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllHistory
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedHistory
|
||||
import javax.inject.Inject
|
||||
|
||||
data class ShowDeleteHistoryDialog(
|
||||
|
@ -24,8 +24,8 @@ import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.search.SearchActivity
|
||||
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.Action
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSearch
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSearch
|
||||
import javax.inject.Inject
|
||||
|
||||
data class ShowDeleteSearchDialog(
|
||||
|
@ -46,8 +46,8 @@ import org.kiwix.kiwixmobile.core.CoreApp;
|
||||
import org.kiwix.kiwixmobile.core.NightModeConfig;
|
||||
import org.kiwix.kiwixmobile.core.R;
|
||||
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.dialog.DialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
|
||||
|
||||
|
@ -22,6 +22,8 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||
import javax.inject.Inject
|
||||
|
||||
class ExternalLinkOpener @Inject constructor(
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@ -16,14 +16,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.utils
|
||||
package org.kiwix.kiwixmobile.core.utils.dialog
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
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) {
|
||||
create(dialog, *clickListeners).show()
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.core.utils
|
||||
package org.kiwix.kiwixmobile.core.utils.dialog
|
||||
|
||||
import android.app.Dialog
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@ -16,8 +16,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.utils
|
||||
package org.kiwix.kiwixmobile.core.utils.dialog
|
||||
|
||||
import android.app.Activity
|
||||
import android.net.wifi.WifiConfiguration
|
||||
import android.view.View
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
@ -127,17 +128,22 @@ sealed class KiwixDialog(
|
||||
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
|
||||
),
|
||||
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),
|
||||
constructor(icon: Int?, activity: Activity) : this(
|
||||
listOf(
|
||||
activity.getString(R.string.rate_dialog_msg_1),
|
||||
activity.getString(R.string.app_name),
|
||||
activity.getString(R.string.rate_dialog_msg_2)
|
||||
),
|
||||
icon
|
||||
)
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.main;
|
||||
package org.kiwix.kiwixmobile.core.utils.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.core.utils.dialog
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.annotation.IdRes
|
||||
import org.kiwix.kiwixmobile.core.BuildConfig
|
||||
import org.kiwix.kiwixmobile.core.di.ActivityScope
|
||||
import org.kiwix.kiwixmobile.core.utils.NetworkUtils
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import javax.inject.Inject
|
||||
|
||||
const val VISITS_REQUIRED_TO_SHOW_RATE_DIALOG = 10
|
||||
|
||||
@ActivityScope
|
||||
class RateDialogHandler @Inject constructor(
|
||||
private val activity: Activity,
|
||||
private val sharedPreferenceUtil: SharedPreferenceUtil,
|
||||
private val alertDialogShower: AlertDialogShower
|
||||
) {
|
||||
private var visitCounterPref: RateAppCounter? = null
|
||||
private var tempVisitCount = 0
|
||||
private var isFirstRun = false
|
||||
|
||||
private fun showRateDialog(iconResId: Int) {
|
||||
alertDialogShower.show(
|
||||
KiwixDialog.ShowRate(iconResId, activity),
|
||||
{
|
||||
visitCounterPref?.noThanksState = true
|
||||
goToRateApp(activity)
|
||||
},
|
||||
{
|
||||
visitCounterPref?.noThanksState = true
|
||||
},
|
||||
{
|
||||
tempVisitCount = 0
|
||||
visitCounterPref?.count = tempVisitCount
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun checkForRateDialog(@IdRes iconResId: Int) {
|
||||
isFirstRun = sharedPreferenceUtil.prefIsFirstRun
|
||||
visitCounterPref = RateAppCounter(activity)
|
||||
tempVisitCount = visitCounterPref?.count!!
|
||||
++tempVisitCount
|
||||
visitCounterPref?.count = tempVisitCount
|
||||
if (shouldShowRateDialog() && NetworkUtils.isNetworkAvailable(activity)) {
|
||||
showRateDialog(iconResId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldShowRateDialog(): Boolean {
|
||||
return tempVisitCount >= VISITS_REQUIRED_TO_SHOW_RATE_DIALOG &&
|
||||
visitCounterPref?.noThanksState == false && !BuildConfig.DEBUG
|
||||
}
|
||||
|
||||
private fun goToRateApp(activity: Activity) {
|
||||
val kiwixLocalMarketUri =
|
||||
Uri.parse("market://details?id=${activity.packageName}")
|
||||
val kiwixBrowserMarketUri =
|
||||
Uri.parse("http://play.google.com/store/apps/details?id=${activity.packageName}")
|
||||
val goToMarket = Intent(Intent.ACTION_VIEW, kiwixLocalMarketUri)
|
||||
goToMarket.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NO_HISTORY or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET or
|
||||
Intent.FLAG_ACTIVITY_MULTIPLE_TASK
|
||||
)
|
||||
try {
|
||||
activity.startActivity(goToMarket)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
activity.startActivity(Intent(Intent.ACTION_VIEW, kiwixBrowserMarketUri))
|
||||
}
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@
|
||||
<!--Remap legacy AppCompat attributes to MaterialComponent attributes-->
|
||||
<item name="colorPrimaryDark">?colorPrimaryVariant</item>
|
||||
<item name="colorAccent">?colorSecondary</item>
|
||||
<item name="android:navigationBarColor">@color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
|
@ -30,9 +30,9 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark
|
||||
import org.kiwix.kiwixmobile.core.page.bookmarkState
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllBookmarks
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedBookmarks
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllBookmarks
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedBookmarks
|
||||
|
||||
internal class ShowDeleteBookmarksDialogTest {
|
||||
val effects = mockk<PublishProcessor<SideEffect<*>>>(relaxed = true)
|
||||
|
@ -12,9 +12,9 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.page.historyItem
|
||||
import org.kiwix.kiwixmobile.core.page.historyState
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllHistory
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllHistory
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedHistory
|
||||
|
||||
internal class ShowDeleteHistoryDialogTest {
|
||||
val effects = mockk<PublishProcessor<SideEffect<*>>>(relaxed = true)
|
||||
|
@ -28,8 +28,8 @@ import org.kiwix.kiwixmobile.core.search.SearchActivity
|
||||
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem.RecentSearchListItem
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.Action
|
||||
import org.kiwix.kiwixmobile.core.search.viewmodel.Action.ConfirmedDelete
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSearch
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSearch
|
||||
|
||||
internal class ShowDeleteSearchDialogTest {
|
||||
|
||||
|
@ -30,6 +30,8 @@ import io.mockk.verify
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||
|
||||
internal class ExternalLinkOpenerTest {
|
||||
private val sharedPreferenceUtil: SharedPreferenceUtil = mockk()
|
||||
|
@ -98,4 +98,6 @@ class CustomMainActivity : CoreMainActivity() {
|
||||
val bundle = bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath)
|
||||
navigate(R.id.customReaderFragment, bundle)
|
||||
}
|
||||
|
||||
override fun getIconResId() = R.mipmap.ic_launcher
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
|
||||
import org.kiwix.kiwixmobile.core.main.CoreReaderFragment
|
||||
import org.kiwix.kiwixmobile.core.main.MainMenu
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_PREFIX
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_ARTICLES
|
||||
@ -189,8 +189,6 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
menu.findItem(R.id.menu_host_books)?.isVisible = false
|
||||
}
|
||||
|
||||
override fun getIconResId() = R.mipmap.ic_launcher
|
||||
|
||||
private fun enforcedLanguage(): Boolean {
|
||||
val currentLocaleCode = Locale.getDefault().toString()
|
||||
if (BuildConfig.ENFORCED_LANG.isNotEmpty() && BuildConfig.ENFORCED_LANG != currentLocaleCode) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user