From c77cd4e19a01faee1127380a890efc4a3c571bdb Mon Sep 17 00:00:00 2001 From: gouri-panda Date: Thu, 20 Aug 2020 14:10:01 +0530 Subject: [PATCH 1/8] Convert FileReader.java file to kotlin --- .../main/{FileReader.java => FileReader.kt} | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) rename core/src/main/java/org/kiwix/kiwixmobile/core/main/{FileReader.java => FileReader.kt} (53%) 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 53% 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..f49a30fcc 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,28 @@ * 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; - -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); +import android.content.Context +import java.io.BufferedReader +import java.io.IOException +import java.io.InputStreamReader +class FileReader { + fun readFile(filePath: String?, context: Context): String { + return try { + val buf = StringBuilder() + val json = context.assets.open(filePath) + val bufferedReader = + BufferedReader(InputStreamReader(json, "UTF-8")) + var str: String? + while (bufferedReader.readLine().also { str = it } != null) { + buf.append(str) } - - in.close(); - return buf.toString(); - } catch (Exception e) { - return ""; + bufferedReader.close() + "$buf" + } catch (e: IOException) { + e.printStackTrace() + "" } } } From f82da5e62d06007a88ffb4d3cc5acd8af6d152f9 Mon Sep 17 00:00:00 2001 From: HissPirat Date: Thu, 20 Aug 2020 12:19:39 +0200 Subject: [PATCH 2/8] #2301 rate dialog now shows text instead of numbers --- .../core/main/CoreReaderFragment.java | 2 +- .../kiwixmobile/core/utils/KiwixDialog.kt | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) 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..50fdade15 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 @@ -659,7 +659,7 @@ public abstract class CoreReaderFragment extends BaseFragment } private void showRateDialog() { - alertDialogShower.show(new KiwixDialog.ShowRate(getIconResId()), + alertDialogShower.show(new KiwixDialog.ShowRate(getIconResId(), requireActivity()), () -> { visitCounterPref.setNoThanksState(true); goToRateApp(); diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt index b1131196c..46d2caefc 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/KiwixDialog.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.core.utils +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 ) } From c95cc583a5b05a7a819b5701ff50b452c3538397 Mon Sep 17 00:00:00 2001 From: HissPirat Date: Thu, 20 Aug 2020 12:45:17 +0200 Subject: [PATCH 3/8] #2301 moved rate dialog counting to core main --- .../kiwixmobile/main/KiwixMainActivity.kt | 2 + .../destination/reader/KiwixReaderFragment.kt | 2 - .../kiwixmobile/core/main/CoreMainActivity.kt | 67 +++++++++++++++++++ .../core/main/CoreReaderFragment.java | 59 ---------------- .../custom/main/CustomMainActivity.kt | 2 + .../custom/main/CustomReaderFragment.kt | 2 - 6 files changed, 71 insertions(+), 63 deletions(-) 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/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..6080e2548 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 @@ -17,7 +17,9 @@ */ package org.kiwix.kiwixmobile.core.main +import android.content.ActivityNotFoundException import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.ActionMode import android.view.Menu @@ -31,6 +33,7 @@ import androidx.navigation.NavController import androidx.navigation.NavDestination import androidx.navigation.NavDirections import com.google.android.material.navigation.NavigationView +import org.kiwix.kiwixmobile.core.BuildConfig import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions @@ -38,18 +41,28 @@ import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent 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.DialogShower import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener +import org.kiwix.kiwixmobile.core.utils.KiwixDialog.ShowRate +import org.kiwix.kiwixmobile.core.utils.NetworkUtils import javax.inject.Inject const val KIWIX_SUPPORT_URL = "https://www.kiwix.org/support" const val PAGE_URL_KEY = "pageUrl" const val ZIM_FILE_URI_KEY = "zimFileUri" +const val VISITS_REQUIRED_TO_SHOW_RATE_DIALOG = 10 abstract class CoreMainActivity : BaseActivity(), WebViewProvider { @Inject lateinit var externalLinkOpener: ExternalLinkOpener protected lateinit var drawerToggle: ActionBarDrawerToggle + @Inject + protected lateinit var alertDialogShower: DialogShower + private var visitCounterPref: RateAppCounter? = null + private var tempVisitCount = 0 + private var isFirstRun = false + abstract val navController: NavController abstract val drawerContainerLayout: DrawerLayout abstract val drawerNavView: NavigationView @@ -65,6 +78,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { override fun onStart() { super.onStart() + checkForRateDialog() navController.addOnDestinationChangedListener { _, destination, _ -> configureActivityBasedOn(destination) } @@ -218,4 +232,57 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { } abstract fun openPage(pageUrl: String, zimFilePath: String = "") + + private fun checkForRateDialog() { + isFirstRun = sharedPreferenceUtil.prefIsFirstRun + visitCounterPref = RateAppCounter(this) + tempVisitCount = visitCounterPref?.count!! + ++tempVisitCount + visitCounterPref?.count = tempVisitCount + if (canShowRateDialog()) { + showRateDialog() + } + } + + private fun canShowRateDialog(): Boolean { + return tempVisitCount >= VISITS_REQUIRED_TO_SHOW_RATE_DIALOG && + visitCounterPref?.noThanksState == false && + NetworkUtils.isNetworkAvailable(this) && !BuildConfig.DEBUG + } + + private fun showRateDialog() { + alertDialogShower.show(ShowRate(getIconResId(), this), + { + visitCounterPref?.noThanksState = true + goToRateApp() + }, + { + visitCounterPref?.noThanksState = true + }, + { + tempVisitCount = 0 + visitCounterPref?.count = tempVisitCount + } + ) + } + + protected abstract fun getIconResId(): Int + + private fun goToRateApp() { + val kiwixLocalMarketUri = + Uri.parse("market://details?id=$packageName") + val kiwixBrowserMarketUri = + Uri.parse("http://play.google.com/store/apps/details?id=$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 { + startActivity(goToMarket) + } catch (e: ActivityNotFoundException) { + startActivity(Intent(Intent.ACTION_VIEW, kiwixBrowserMarketUri)) + } + } } 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 50fdade15..6b2b7ca14 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; @@ -116,7 +115,6 @@ import org.kiwix.kiwixmobile.core.utils.DialogShower; import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener; import org.kiwix.kiwixmobile.core.utils.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(), requireActivity()), - () -> { - 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/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 fb2808883..fe2283a54 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 @@ -190,8 +190,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) { From 1f87c1817ec4a79339a752cbff009ee4bf8b8231 Mon Sep 17 00:00:00 2001 From: gouri-panda Date: Thu, 20 Aug 2020 15:11:29 +0530 Subject: [PATCH 4/8] added bufferReader Extension added bufferReader Extension added bufferReader Extension --- .../org/kiwix/kiwixmobile/core/main/FileReader.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt index f49a30fcc..ee2b300cf 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt @@ -20,20 +20,12 @@ package org.kiwix.kiwixmobile.core.main import android.content.Context import java.io.BufferedReader import java.io.IOException -import java.io.InputStreamReader + class FileReader { fun readFile(filePath: String?, context: Context): String { return try { - val buf = StringBuilder() val json = context.assets.open(filePath) - val bufferedReader = - BufferedReader(InputStreamReader(json, "UTF-8")) - var str: String? - while (bufferedReader.readLine().also { str = it } != null) { - buf.append(str) - } - bufferedReader.close() - "$buf" + return json.bufferedReader().use(BufferedReader::readText) } catch (e: IOException) { e.printStackTrace() "" From 1e0eeb0bf16d2f9a217b44b834330778b4eca8e8 Mon Sep 17 00:00:00 2001 From: gouri-panda Date: Thu, 20 Aug 2020 17:25:49 +0530 Subject: [PATCH 5/8] formated code --- .../org/kiwix/kiwixmobile/core/main/FileReader.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt index ee2b300cf..da66d2f5e 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/FileReader.kt @@ -22,13 +22,11 @@ import java.io.BufferedReader import java.io.IOException class FileReader { - fun readFile(filePath: String?, context: Context): String { - return try { - val json = context.assets.open(filePath) - return json.bufferedReader().use(BufferedReader::readText) - } catch (e: IOException) { - e.printStackTrace() - "" - } + fun readFile(filePath: String?, context: Context): String = try { + context.assets.open(filePath) + .bufferedReader() + .use(BufferedReader::readText) + } catch (e: IOException) { + "".also { e.printStackTrace() } } } From a915362e53846fb3fe4398e00b98f9560315c6c9 Mon Sep 17 00:00:00 2001 From: HissPirat Date: Thu, 20 Aug 2020 14:19:52 +0200 Subject: [PATCH 6/8] #2301 move rate dialog handling to class and created dialog package --- .../LocalFileTransferActivity.java | 4 +- .../local_file_transfer/WifiDirectManager.kt | 4 +- .../kiwixmobile/webserver/ZimHostActivity.kt | 7 +- .../fileselect_view/effects/DeleteFiles.kt | 4 +- .../library_view/LibraryFragment.kt | 6 +- .../core/di/modules/ActivityModule.kt | 4 +- .../kiwixmobile/core/main/AddNoteDialog.java | 4 +- .../kiwixmobile/core/main/CoreMainActivity.kt | 67 +------------- .../core/main/CoreReaderFragment.java | 4 +- .../effects/ShowDeleteBookmarksDialog.kt | 6 +- .../effects/ShowDeleteHistoryDialog.kt | 6 +- .../effects/ShowDeleteSearchDialog.kt | 4 +- .../core/settings/CorePrefsFragment.java | 4 +- .../core/utils/ExternalLinkOpener.kt | 2 + .../utils/{ => dialog}/AlertDialogShower.kt | 7 +- .../core/utils/{ => dialog}/DialogShower.kt | 4 +- .../core/utils/{ => dialog}/KiwixDialog.kt | 4 +- .../dialog}/RateAppCounter.java | 2 +- .../core/utils/dialog/RateDialogHandler.kt | 92 +++++++++++++++++++ .../effects/ShowDeleteBookmarksDialogTest.kt | 6 +- .../effects/ShowDeleteHistoryDialogTest.kt | 6 +- .../effects/ShowDeleteSearchDialogTest.kt | 4 +- .../core/utils/ExternalLinkOpenerTest.kt | 2 + .../custom/main/CustomReaderFragment.kt | 4 +- 24 files changed, 147 insertions(+), 110 deletions(-) rename core/src/main/java/org/kiwix/kiwixmobile/core/utils/{ => dialog}/AlertDialogShower.kt (94%) rename core/src/main/java/org/kiwix/kiwixmobile/core/utils/{ => dialog}/DialogShower.kt (90%) rename core/src/main/java/org/kiwix/kiwixmobile/core/utils/{ => dialog}/KiwixDialog.kt (98%) rename core/src/main/java/org/kiwix/kiwixmobile/core/{main => utils/dialog}/RateAppCounter.java (97%) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateDialogHandler.kt 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/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 6080e2548..274df8b5d 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 @@ -17,9 +17,7 @@ */ package org.kiwix.kiwixmobile.core.main -import android.content.ActivityNotFoundException import android.content.Intent -import android.net.Uri import android.os.Bundle import android.view.ActionMode import android.view.Menu @@ -33,7 +31,6 @@ import androidx.navigation.NavController import androidx.navigation.NavDestination import androidx.navigation.NavDirections import com.google.android.material.navigation.NavigationView -import org.kiwix.kiwixmobile.core.BuildConfig import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions @@ -41,10 +38,8 @@ import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent 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.DialogShower import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener -import org.kiwix.kiwixmobile.core.utils.KiwixDialog.ShowRate -import org.kiwix.kiwixmobile.core.utils.NetworkUtils +import org.kiwix.kiwixmobile.core.utils.dialog.RateDialogHandler import javax.inject.Inject const val KIWIX_SUPPORT_URL = "https://www.kiwix.org/support" @@ -55,14 +50,9 @@ const val VISITS_REQUIRED_TO_SHOW_RATE_DIALOG = 10 abstract class CoreMainActivity : BaseActivity(), WebViewProvider { @Inject lateinit var externalLinkOpener: ExternalLinkOpener + @Inject lateinit var rateDialogHandler: RateDialogHandler protected lateinit var drawerToggle: ActionBarDrawerToggle - @Inject - protected lateinit var alertDialogShower: DialogShower - private var visitCounterPref: RateAppCounter? = null - private var tempVisitCount = 0 - private var isFirstRun = false - abstract val navController: NavController abstract val drawerContainerLayout: DrawerLayout abstract val drawerNavView: NavigationView @@ -78,7 +68,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { override fun onStart() { super.onStart() - checkForRateDialog() + rateDialogHandler.checkForRateDialog(getIconResId()) navController.addOnDestinationChangedListener { _, destination, _ -> configureActivityBasedOn(destination) } @@ -233,56 +223,5 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { abstract fun openPage(pageUrl: String, zimFilePath: String = "") - private fun checkForRateDialog() { - isFirstRun = sharedPreferenceUtil.prefIsFirstRun - visitCounterPref = RateAppCounter(this) - tempVisitCount = visitCounterPref?.count!! - ++tempVisitCount - visitCounterPref?.count = tempVisitCount - if (canShowRateDialog()) { - showRateDialog() - } - } - - private fun canShowRateDialog(): Boolean { - return tempVisitCount >= VISITS_REQUIRED_TO_SHOW_RATE_DIALOG && - visitCounterPref?.noThanksState == false && - NetworkUtils.isNetworkAvailable(this) && !BuildConfig.DEBUG - } - - private fun showRateDialog() { - alertDialogShower.show(ShowRate(getIconResId(), this), - { - visitCounterPref?.noThanksState = true - goToRateApp() - }, - { - visitCounterPref?.noThanksState = true - }, - { - tempVisitCount = 0 - visitCounterPref?.count = tempVisitCount - } - ) - } - protected abstract fun getIconResId(): Int - - private fun goToRateApp() { - val kiwixLocalMarketUri = - Uri.parse("market://details?id=$packageName") - val kiwixBrowserMarketUri = - Uri.parse("http://play.google.com/store/apps/details?id=$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 { - startActivity(goToMarket) - } catch (e: ActivityNotFoundException) { - startActivity(Intent(Intent.ACTION_VIEW, kiwixBrowserMarketUri)) - } - } } 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 6b2b7ca14..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 @@ -111,9 +111,9 @@ 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.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.StyleUtils; 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 98% 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 46d2caefc..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,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.utils +package org.kiwix.kiwixmobile.core.utils.dialog import android.app.Activity import android.net.wifi.WifiConfiguration 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..656f73f5a --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateDialogHandler.kt @@ -0,0 +1,92 @@ +/* + * 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.main.VISITS_REQUIRED_TO_SHOW_RATE_DIALOG +import org.kiwix.kiwixmobile.core.utils.NetworkUtils +import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import javax.inject.Inject + +@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/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/CustomReaderFragment.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomReaderFragment.kt index fe2283a54..40856ae49 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 From 743414a383d08f7d21f31e3dd792bb767d5d2d52 Mon Sep 17 00:00:00 2001 From: HissPirat Date: Thu, 20 Aug 2020 14:24:15 +0200 Subject: [PATCH 7/8] #2301 moved constant to RateDialog class --- .../java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt | 1 - .../kiwix/kiwixmobile/core/utils/dialog/RateDialogHandler.kt | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) 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 274df8b5d..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 @@ -45,7 +45,6 @@ import javax.inject.Inject const val KIWIX_SUPPORT_URL = "https://www.kiwix.org/support" const val PAGE_URL_KEY = "pageUrl" const val ZIM_FILE_URI_KEY = "zimFileUri" -const val VISITS_REQUIRED_TO_SHOW_RATE_DIALOG = 10 abstract class CoreMainActivity : BaseActivity(), WebViewProvider { 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 index 656f73f5a..eea5e9cf9 100644 --- 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 @@ -24,11 +24,12 @@ 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.main.VISITS_REQUIRED_TO_SHOW_RATE_DIALOG 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, From 836293c9a46c6fb94becbaa2b708468440afc764 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 20 Aug 2020 20:24:45 +0530 Subject: [PATCH 8/8] #2287 - change OS NavigationBar color to black --- core/src/main/res/values/themes.xml | 1 + 1 file changed, 1 insertion(+) 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