Merge pull request #3 from kiwix/develop

update my local branch approved
This commit is contained in:
Abhay Garg 2020-08-21 15:07:45 +05:30 committed by GitHub
commit a0799e8ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 182 additions and 143 deletions

View File

@ -55,8 +55,8 @@ import org.kiwix.kiwixmobile.ActivityExtensionsKt;
import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.core.base.BaseActivity; import org.kiwix.kiwixmobile.core.base.BaseActivity;
import org.kiwix.kiwixmobile.core.di.components.CoreComponent; import org.kiwix.kiwixmobile.core.di.components.CoreComponent;
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower; import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower;
import org.kiwix.kiwixmobile.core.utils.KiwixDialog; 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.WifiP2pDelegate;
import org.kiwix.kiwixmobile.local_file_transfer.adapter.WifiPeerListAdapter; import org.kiwix.kiwixmobile.local_file_transfer.adapter.WifiPeerListAdapter;

View File

@ -42,8 +42,8 @@ import android.widget.Toast
import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.BuildConfig import org.kiwix.kiwixmobile.core.BuildConfig
import org.kiwix.kiwixmobile.core.extensions.toast 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.KiwixDialog.FileTransferConfirmation import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.FileTransferConfirmation
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.local_file_transfer.FileItem.FileStatus import org.kiwix.kiwixmobile.local_file_transfer.FileItem.FileStatus
import org.kiwix.kiwixmobile.local_file_transfer.KiwixWifiP2pBroadcastReceiver.P2pEventListener import org.kiwix.kiwixmobile.local_file_transfer.KiwixWifiP2pBroadcastReceiver.P2pEventListener

View File

@ -139,4 +139,6 @@ class KiwixMainActivity : CoreMainActivity() {
bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath) bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath)
) )
} }
override fun getIconResId() = R.mipmap.ic_launcher
} }

View File

@ -294,8 +294,6 @@ class KiwixReaderFragment : CoreReaderFragment() {
private fun getSharedPrefSettings() = private fun getSharedPrefSettings() =
activity?.getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0) activity?.getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
override fun getIconResId() = R.mipmap.ic_launcher
override fun createNewTab() { override fun createNewTab() {
newMainPageTab() newMainPageTab()
} }

View File

@ -37,9 +37,9 @@ import org.kiwix.kiwixmobile.core.BuildConfig
import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.BaseActivity
import org.kiwix.kiwixmobile.core.di.components.CoreComponent import org.kiwix.kiwixmobile.core.di.components.CoreComponent
import org.kiwix.kiwixmobile.core.extensions.toast 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.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.utils.ServerUtils
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate 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 // Advice user to turn on hotspot manually for API<26
private fun startHotspotManuallyDialog() { private fun startHotspotManuallyDialog() {
alertDialogShower.show(KiwixDialog.StartHotspotManually, alertDialogShower.show(
KiwixDialog.StartHotspotManually,
::launchTetheringSettingsScreen, ::launchTetheringSettingsScreen,
::openWifiSettings, ::openWifiSettings,
{} {}

View File

@ -25,8 +25,8 @@ import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewBookDao
import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteZims import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteZims
import org.kiwix.kiwixmobile.core.utils.files.FileUtils import org.kiwix.kiwixmobile.core.utils.files.FileUtils
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.kiwixActivityComponent

View File

@ -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.ActivityExtensions.viewModel
import org.kiwix.kiwixmobile.core.extensions.snack import org.kiwix.kiwixmobile.core.extensions.snack
import org.kiwix.kiwixmobile.core.utils.BookUtils import org.kiwix.kiwixmobile.core.utils.BookUtils
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.StopDownload import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.YesNoDialog.StopDownload
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.WifiOnly import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.YesNoDialog.WifiOnly
import org.kiwix.kiwixmobile.core.utils.NetworkUtils import org.kiwix.kiwixmobile.core.utils.NetworkUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.kiwixActivityComponent

View File

@ -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.MainMenu.MenuClickListener
import org.kiwix.kiwixmobile.core.main.MainRepositoryActions import org.kiwix.kiwixmobile.core.main.MainRepositoryActions
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
@Module @Module
abstract class ActivityModule { abstract class ActivityModule {

View File

@ -57,8 +57,8 @@ import org.kiwix.kiwixmobile.core.CoreApp;
import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.R;
import org.kiwix.kiwixmobile.core.R2; import org.kiwix.kiwixmobile.core.R2;
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer; import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower; import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower;
import org.kiwix.kiwixmobile.core.utils.KiwixDialog; import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog;
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
/** /**

View File

@ -39,6 +39,7 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
import org.kiwix.kiwixmobile.core.extensions.browserIntent import org.kiwix.kiwixmobile.core.extensions.browserIntent
import org.kiwix.kiwixmobile.core.help.HelpActivity import org.kiwix.kiwixmobile.core.help.HelpActivity
import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener
import org.kiwix.kiwixmobile.core.utils.dialog.RateDialogHandler
import javax.inject.Inject import javax.inject.Inject
const val KIWIX_SUPPORT_URL = "https://www.kiwix.org/support" 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 { abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
@Inject lateinit var externalLinkOpener: ExternalLinkOpener @Inject lateinit var externalLinkOpener: ExternalLinkOpener
@Inject lateinit var rateDialogHandler: RateDialogHandler
protected lateinit var drawerToggle: ActionBarDrawerToggle protected lateinit var drawerToggle: ActionBarDrawerToggle
abstract val navController: NavController abstract val navController: NavController
@ -65,6 +67,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
rateDialogHandler.checkForRateDialog(getIconResId())
navController.addOnDestinationChangedListener { _, destination, _ -> navController.addOnDestinationChangedListener { _, destination, _ ->
configureActivityBasedOn(destination) configureActivityBasedOn(destination)
} }
@ -218,4 +221,6 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
} }
abstract fun openPage(pageUrl: String, zimFilePath: String = "") abstract fun openPage(pageUrl: String, zimFilePath: String = "")
protected abstract fun getIconResId(): Int
} }

View File

@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.core.main;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; 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.reader.ZimReaderContainer;
import org.kiwix.kiwixmobile.core.search.SearchActivity; import org.kiwix.kiwixmobile.core.search.SearchActivity;
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchInPreviousScreen; import org.kiwix.kiwixmobile.core.search.viewmodel.effects.SearchInPreviousScreen;
import org.kiwix.kiwixmobile.core.utils.DialogShower; import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower;
import org.kiwix.kiwixmobile.core.utils.ExternalLinkOpener; 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.LanguageUtils;
import org.kiwix.kiwixmobile.core.utils.NetworkUtils;
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
import org.kiwix.kiwixmobile.core.utils.StyleUtils; import org.kiwix.kiwixmobile.core.utils.StyleUtils;
import org.kiwix.kiwixmobile.core.utils.files.FileUtils; import org.kiwix.kiwixmobile.core.utils.files.FileUtils;
@ -240,8 +238,6 @@ public abstract class CoreReaderFragment extends BaseFragment
private ActionMode actionMode = null; private ActionMode actionMode = null;
private KiwixWebView tempWebViewForUndo; private KiwixWebView tempWebViewForUndo;
private File tempZimFileForUndo; private File tempZimFileForUndo;
private RateAppCounter visitCounterPref;
private int tempVisitCount;
private boolean isFirstRun; private boolean isFirstRun;
protected ActionBar actionBar; protected ActionBar actionBar;
private TableDrawerAdapter tableDrawerAdapter; private TableDrawerAdapter tableDrawerAdapter;
@ -338,8 +334,6 @@ public abstract class CoreReaderFragment extends BaseFragment
tableDrawerRight = tableDrawerRight =
tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list); tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list);
checkForRateDialog();
addFileReader(); addFileReader();
setupTabsAdapter(); setupTabsAdapter();
setTableDrawerInfo(); setTableDrawerInfo();
@ -644,59 +638,6 @@ public abstract class CoreReaderFragment extends BaseFragment
return Super.ShouldNotCall; 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() { private void updateTitle() {
if (isAdded()) { if (isAdded()) {
actionBar.setTitle(getValidTitle(zimReaderContainer.getZimFileTitle())); actionBar.setTitle(getValidTitle(zimReaderContainer.getZimFileTitle()));

View File

@ -15,31 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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 android.content.Context
import java.io.BufferedReader; import java.io.BufferedReader
import java.io.InputStream; import java.io.IOException
import java.io.InputStreamReader;
public class FileReader { class FileReader {
fun readFile(filePath: String?, context: Context): String = try {
public String readFile(String filePath, Context context) { context.assets.open(filePath)
try { .bufferedReader()
StringBuilder buf = new StringBuilder(); .use(BufferedReader::readText)
InputStream json = context.getAssets().open(filePath); } catch (e: IOException) {
BufferedReader in = "".also { e.printStackTrace() }
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 "";
}
} }
} }

View File

@ -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.bookmark.adapter.BookmarkItem
import org.kiwix.kiwixmobile.core.page.viewmodel.PageState import org.kiwix.kiwixmobile.core.page.viewmodel.PageState
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllBookmarks import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllBookmarks
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedBookmarks import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedBookmarks
import javax.inject.Inject import javax.inject.Inject
data class ShowDeleteBookmarksDialog( data class ShowDeleteBookmarksDialog(

View File

@ -25,9 +25,9 @@ import org.kiwix.kiwixmobile.core.dao.PageDao
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent
import org.kiwix.kiwixmobile.core.page.history.viewmodel.HistoryState import org.kiwix.kiwixmobile.core.page.history.viewmodel.HistoryState
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllHistory import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllHistory
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedHistory
import javax.inject.Inject import javax.inject.Inject
data class ShowDeleteHistoryDialog( data class ShowDeleteHistoryDialog(

View File

@ -24,8 +24,8 @@ import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.search.SearchActivity import org.kiwix.kiwixmobile.core.search.SearchActivity
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem
import org.kiwix.kiwixmobile.core.search.viewmodel.Action import org.kiwix.kiwixmobile.core.search.viewmodel.Action
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSearch import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSearch
import javax.inject.Inject import javax.inject.Inject
data class ShowDeleteSearchDialog( data class ShowDeleteSearchDialog(

View File

@ -46,8 +46,8 @@ import org.kiwix.kiwixmobile.core.CoreApp;
import org.kiwix.kiwixmobile.core.NightModeConfig; import org.kiwix.kiwixmobile.core.NightModeConfig;
import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.R;
import org.kiwix.kiwixmobile.core.main.AddNoteDialog; import org.kiwix.kiwixmobile.core.main.AddNoteDialog;
import org.kiwix.kiwixmobile.core.utils.DialogShower; import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower;
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.LanguageUtils;
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;

View File

@ -22,6 +22,8 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.toast 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 import javax.inject.Inject
class ExternalLinkOpener @Inject constructor( class ExternalLinkOpener @Inject constructor(

View File

@ -1,6 +1,6 @@
/* /*
* Kiwix Android * 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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * 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.Activity
import android.app.Dialog import android.app.Dialog
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import javax.inject.Inject import javax.inject.Inject
class AlertDialogShower @Inject constructor(private val activity: Activity) : DialogShower { class AlertDialogShower @Inject constructor(private val activity: Activity) :
DialogShower {
override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit) { override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit) {
create(dialog, *clickListeners).show() create(dialog, *clickListeners).show()
} }

View File

@ -1,6 +1,6 @@
/* /*
* Kiwix Android * 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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * 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/>. * 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 import android.app.Dialog

View File

@ -1,6 +1,6 @@
/* /*
* Kiwix Android * 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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * 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.net.wifi.WifiConfiguration
import android.view.View import android.view.View
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
@ -127,7 +128,8 @@ sealed class KiwixDialog(
neutralMessage = R.string.do_not_ask_anymore neutralMessage = R.string.do_not_ask_anymore
) )
data class ShowRate(override val args: List<Any>, val customIcon: Int?) : KiwixDialog( data class ShowRate(override val args: List<Any>, val customIcon: Int?) :
KiwixDialog(
R.string.rate_dialog_title, R.string.rate_dialog_title,
R.string.triple_arg_format_string, R.string.triple_arg_format_string,
R.string.rate_dialog_positive, R.string.rate_dialog_positive,
@ -136,8 +138,12 @@ sealed class KiwixDialog(
neutralMessage = R.string.rate_dialog_neutral neutralMessage = R.string.rate_dialog_neutral
), ),
HasBodyFormatArgs { HasBodyFormatArgs {
constructor(icon: Int?) : this( constructor(icon: Int?, activity: Activity) : this(
listOf(R.string.rate_dialog_msg_1, R.string.app_name, R.string.rate_dialog_msg_2), listOf(
activity.getString(R.string.rate_dialog_msg_1),
activity.getString(R.string.app_name),
activity.getString(R.string.rate_dialog_msg_2)
),
icon icon
) )
} }

View File

@ -16,7 +16,7 @@
* *
*/ */
package org.kiwix.kiwixmobile.core.main; package org.kiwix.kiwixmobile.core.utils.dialog;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;

View File

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

View File

@ -90,6 +90,7 @@
<!--Remap legacy AppCompat attributes to MaterialComponent attributes--> <!--Remap legacy AppCompat attributes to MaterialComponent attributes-->
<item name="colorPrimaryDark">?colorPrimaryVariant</item> <item name="colorPrimaryDark">?colorPrimaryVariant</item>
<item name="colorAccent">?colorSecondary</item> <item name="colorAccent">?colorSecondary</item>
<item name="android:navigationBarColor">@color/black</item>
</style> </style>

View File

@ -30,9 +30,9 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.page.bookmark import org.kiwix.kiwixmobile.core.page.bookmark
import org.kiwix.kiwixmobile.core.page.bookmarkState import org.kiwix.kiwixmobile.core.page.bookmarkState
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllBookmarks import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllBookmarks
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedBookmarks import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedBookmarks
internal class ShowDeleteBookmarksDialogTest { internal class ShowDeleteBookmarksDialogTest {
val effects = mockk<PublishProcessor<SideEffect<*>>>(relaxed = true) val effects = mockk<PublishProcessor<SideEffect<*>>>(relaxed = true)

View File

@ -12,9 +12,9 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.page.historyItem import org.kiwix.kiwixmobile.core.page.historyItem
import org.kiwix.kiwixmobile.core.page.historyState import org.kiwix.kiwixmobile.core.page.historyState
import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems import org.kiwix.kiwixmobile.core.page.viewmodel.effects.DeletePageItems
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllHistory import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteAllHistory
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSelectedHistory
internal class ShowDeleteHistoryDialogTest { internal class ShowDeleteHistoryDialogTest {
val effects = mockk<PublishProcessor<SideEffect<*>>>(relaxed = true) val effects = mockk<PublishProcessor<SideEffect<*>>>(relaxed = true)

View File

@ -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.adapter.SearchListItem.RecentSearchListItem
import org.kiwix.kiwixmobile.core.search.viewmodel.Action import org.kiwix.kiwixmobile.core.search.viewmodel.Action
import org.kiwix.kiwixmobile.core.search.viewmodel.Action.ConfirmedDelete import org.kiwix.kiwixmobile.core.search.viewmodel.Action.ConfirmedDelete
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSearch import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.DeleteSearch
internal class ShowDeleteSearchDialogTest { internal class ShowDeleteSearchDialogTest {

View File

@ -30,6 +30,8 @@ import io.mockk.verify
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.toast 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 { internal class ExternalLinkOpenerTest {
private val sharedPreferenceUtil: SharedPreferenceUtil = mockk() private val sharedPreferenceUtil: SharedPreferenceUtil = mockk()

View File

@ -98,4 +98,6 @@ class CustomMainActivity : CoreMainActivity() {
val bundle = bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath) val bundle = bundleOf(PAGE_URL_KEY to pageUrl, ZIM_FILE_URI_KEY to zimFilePath)
navigate(R.id.customReaderFragment, bundle) navigate(R.id.customReaderFragment, bundle)
} }
override fun getIconResId() = R.mipmap.ic_launcher
} }

View File

@ -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.CoreReaderFragment
import org.kiwix.kiwixmobile.core.main.MainMenu import org.kiwix.kiwixmobile.core.main.MainMenu
import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_PREFIX import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_PREFIX
import org.kiwix.kiwixmobile.core.utils.DialogShower import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
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.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.TAG_CURRENT_ARTICLES 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 menu.findItem(R.id.menu_host_books)?.isVisible = false
} }
override fun getIconResId() = R.mipmap.ic_launcher
private fun enforcedLanguage(): Boolean { private fun enforcedLanguage(): Boolean {
val currentLocaleCode = Locale.getDefault().toString() val currentLocaleCode = Locale.getDefault().toString()
if (BuildConfig.ENFORCED_LANG.isNotEmpty() && BuildConfig.ENFORCED_LANG != currentLocaleCode) { if (BuildConfig.ENFORCED_LANG.isNotEmpty() && BuildConfig.ENFORCED_LANG != currentLocaleCode) {