diff --git a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/LocalFileTransferActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/LocalFileTransferActivity.java
index fb1c9d6c1..4f5d53903 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/LocalFileTransferActivity.java
+++ b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/LocalFileTransferActivity.java
@@ -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;
diff --git a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/WifiDirectManager.kt b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/WifiDirectManager.kt
index f6e9c7f7e..e1170ef5d 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/WifiDirectManager.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/WifiDirectManager.kt
@@ -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
diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt
index ddca80f18..188f24d0c 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt
@@ -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
}
diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt
index bd5384d24..a23355649 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt
@@ -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()
}
diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.kt
index 093e88737..50a0592ad 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.kt
@@ -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,
{}
diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/effects/DeleteFiles.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/effects/DeleteFiles.kt
index d77c55aba..0f721e125 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/effects/DeleteFiles.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/fileselect_view/effects/DeleteFiles.kt
@@ -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
diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt
index 91f9114ac..67a4dfd03 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt
@@ -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
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityModule.kt
index fb22e7059..e4216652a 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityModule.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityModule.kt
@@ -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 {
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.java
index a30f38375..7112343a6 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.java
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.java
@@ -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;
/**
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt
index 949e94dbb..59215b890 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt
@@ -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
}
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java
index 58f9efe79..5f5236352 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.java
@@ -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()));
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt
similarity index 52%
rename from core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.java
rename to core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt
index 5b5e3b473..da66d2f5e 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.java
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt
@@ -15,31 +15,18 @@
* along with this program. If not, see .
*
*/
-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() }
}
}
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialog.kt
index 50704f0b7..72502dbb2 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialog.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialog.kt
@@ -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(
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialog.kt
index 3ce859b47..9d833fd6e 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialog.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialog.kt
@@ -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(
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialog.kt
index 6076a1021..dd1f676bd 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialog.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialog.kt
@@ -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(
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java b/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java
index 2beb09112..4c65d2405 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.java
@@ -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;
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpener.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpener.kt
index 57e0894b4..a5c804ee2 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpener.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpener.kt
@@ -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(
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/AlertDialogShower.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/AlertDialogShower.kt
similarity index 94%
rename from core/src/main/java/org/kiwix/kiwixmobile/core/utils/AlertDialogShower.kt
rename to core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/AlertDialogShower.kt
index f5d8daaf1..ea1cd53ae 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/AlertDialogShower.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/AlertDialogShower.kt
@@ -1,6 +1,6 @@
/*
* Kiwix Android
- * Copyright (c) 2019 Kiwix
+ * Copyright (c) 2020 Kiwix
* 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()
}
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/DialogShower.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/DialogShower.kt
similarity index 90%
rename from core/src/main/java/org/kiwix/kiwixmobile/core/utils/DialogShower.kt
rename to core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/DialogShower.kt
index 17dde08aa..88196166e 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/DialogShower.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/DialogShower.kt
@@ -1,6 +1,6 @@
/*
* Kiwix Android
- * Copyright (c) 2019 Kiwix
+ * Copyright (c) 2020 Kiwix
* 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 .
*
*/
-package org.kiwix.kiwixmobile.core.utils
+package org.kiwix.kiwixmobile.core.utils.dialog
import android.app.Dialog
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt
similarity index 90%
rename from core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt
rename to core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt
index b1131196c..724307f75 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/KiwixDialog.kt
@@ -1,6 +1,6 @@
/*
* Kiwix Android
- * Copyright (c) 2019 Kiwix
+ * Copyright (c) 2020 Kiwix
* 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, 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, 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
)
}
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/RateAppCounter.java b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java
similarity index 97%
rename from core/src/main/java/org/kiwix/kiwixmobile/core/main/RateAppCounter.java
rename to core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java
index 819becf91..c75e9d057 100644
--- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/RateAppCounter.java
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java
@@ -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;
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateDialogHandler.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateDialogHandler.kt
new file mode 100644
index 000000000..eea5e9cf9
--- /dev/null
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateDialogHandler.kt
@@ -0,0 +1,93 @@
+/*
+ * Kiwix Android
+ * Copyright (c) 2020 Kiwix
+ * 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 .
+ *
+ */
+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))
+ }
+ }
+}
diff --git a/core/src/main/res/values/themes.xml b/core/src/main/res/values/themes.xml
index be5f7474f..2ef6b0cc4 100644
--- a/core/src/main/res/values/themes.xml
+++ b/core/src/main/res/values/themes.xml
@@ -90,6 +90,7 @@
- ?colorPrimaryVariant
- ?colorSecondary
+ - @color/black
diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialogTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialogTest.kt
index 6271a13d0..97fb95cb1 100644
--- a/core/src/test/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialogTest.kt
+++ b/core/src/test/java/org/kiwix/kiwixmobile/core/page/bookmark/viewmodel/effects/ShowDeleteBookmarksDialogTest.kt
@@ -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>>(relaxed = true)
diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialogTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialogTest.kt
index b314e3e02..4ef94fca9 100644
--- a/core/src/test/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialogTest.kt
+++ b/core/src/test/java/org/kiwix/kiwixmobile/core/page/history/viewmodel/effects/ShowDeleteHistoryDialogTest.kt
@@ -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>>(relaxed = true)
diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialogTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialogTest.kt
index 64896a2de..b75872298 100644
--- a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialogTest.kt
+++ b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/ShowDeleteSearchDialogTest.kt
@@ -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 {
diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpenerTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpenerTest.kt
index b29ea45d6..daef60f7d 100644
--- a/core/src/test/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpenerTest.kt
+++ b/core/src/test/java/org/kiwix/kiwixmobile/core/utils/ExternalLinkOpenerTest.kt
@@ -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()
diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt
index bffcd3b39..c38d293b4 100644
--- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt
+++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt
@@ -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
}
diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt
index a92a239d4..8977759de 100644
--- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt
+++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt
@@ -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) {