Merge branch 'kiwix:develop' into issue#2719

This commit is contained in:
Dhiraj Chauhan 2021-11-25 18:34:23 +05:30 committed by GitHub
commit aeeb5278cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 295 additions and 15 deletions

View File

@ -15,7 +15,7 @@ jobs:
coverageReport:
strategy:
matrix:
api-level: [21, 21]
api-level: [21, 21, 30]
fail-fast: false
runs-on: macOS-latest
steps:

View File

@ -10,7 +10,7 @@ jobs:
instrumentation_tests:
strategy:
matrix:
api-level: [21, 22, 23, 24, 25, 27, 28]
api-level: [21, 22, 23, 24, 25, 27, 28, 30]
fail-fast: false
runs-on: macOS-latest
steps:

View File

@ -11,7 +11,7 @@
<ID>MagicNumber:ShareFiles.kt$ShareFiles$24</ID>
<ID>MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$5</ID>
<ID>MagicNumber:ZimManageViewModel.kt$ZimManageViewModel$500</ID>
<ID>MagicNumber:ZimHostFragment.kt$ZimHostFragment$4</ID>
<ID>NestedBlockDepth:LocalLibraryFragment.kt$LocalLibraryFragment$checkPermissions</ID>
<ID>NestedBlockDepth:PeerGroupHandshake.kt$PeerGroupHandshake$readHandshakeAndExchangeMetaData</ID>
<ID>NestedBlockDepth:ReceiverHandShake.kt$ReceiverHandShake$exchangeFileTransferMetadata</ID>
<ID>PackageNaming:AvailableSpaceCalculator.kt$package org.kiwix.kiwixmobile.zim_manager.library_view</ID>

View File

@ -6,6 +6,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<queries>
<intent>

View File

@ -20,7 +20,9 @@ package org.kiwix.kiwixmobile.nav.destination.library
import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
@ -31,6 +33,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
@ -49,9 +52,12 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.navigateToSettings
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.REQUEST_STORAGE_PERMISSION
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
@ -69,6 +75,7 @@ class LocalLibraryFragment : BaseFragment() {
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil
@Inject lateinit var dialogShower: DialogShower
private var actionMode: ActionMode? = null
private val disposable = CompositeDisposable()
@ -202,7 +209,27 @@ class LocalLibraryFragment : BaseFragment() {
REQUEST_STORAGE_PERMISSION
)
} else {
requestFileSystemCheck()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
// We already have permission!!
requestFileSystemCheck()
} else {
if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) {
// We should only ask for first time, If the users wants to revoke settings
// then they can directly toggle this feature from settings screen
sharedPreferenceUtil.manageExternalFilesPermissionDialog = false
// Show Dialog and Go to settings to give permission
dialogShower.show(
KiwixDialog.ManageExternalFilesPermissionDialog,
{
this.activity?.let(FragmentActivity::navigateToSettings)
}
)
}
}
} else {
requestFileSystemCheck()
}
}
}

View File

@ -49,11 +49,13 @@ import org.kiwix.kiwixmobile.core.downloader.Downloader
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel
import org.kiwix.kiwixmobile.core.extensions.closeKeyboard
import org.kiwix.kiwixmobile.core.extensions.snack
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.utils.BookUtils
import org.kiwix.kiwixmobile.core.utils.NetworkUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.SimpleRecyclerViewScrollListener
import org.kiwix.kiwixmobile.core.utils.SimpleTextListener
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
@ -141,6 +143,13 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
zimManageViewModel.shouldShowWifiOnlyDialog.value = false
}
})
// hides keyboard when scrolled
libraryList.addOnScrollListener(SimpleRecyclerViewScrollListener { _, newState ->
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
libraryList.closeKeyboard()
}
})
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {

View File

@ -18,10 +18,15 @@
package org.kiwix.kiwixmobile.settings
import android.os.Build
import android.os.Bundle
import android.os.Environment
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.navigateToSettings
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.Companion.PREF_STORAGE
@ -31,6 +36,7 @@ class KiwixPrefsFragment : CorePrefsFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
super.onCreatePreferences(savedInstanceState, rootKey)
setUpLanguageChooser(SharedPreferenceUtil.PREF_LANG)
setMangeExternalStoragePermission()
}
override fun setStorage() {
@ -43,4 +49,34 @@ class KiwixPrefsFragment : CorePrefsFragment() {
private fun internalStorage(): String? =
ContextCompat.getExternalFilesDirs(requireContext(), null).firstOrNull()?.path
private fun setMangeExternalStoragePermission() {
val permissionPref = findPreference<Preference>(PREF_MANAGE_EXTERNAL_STORAGE_PERMISSION)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
showPermissionPreference()
val externalStorageManager = Environment.isExternalStorageManager()
if (externalStorageManager) {
permissionPref!!.setSummary(org.kiwix.kiwixmobile.core.R.string.allowed)
} else {
permissionPref!!.setSummary(org.kiwix.kiwixmobile.core.R.string.not_allowed)
}
permissionPref.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
activity?.let(FragmentActivity::navigateToSettings)
true
}
}
}
private fun showPermissionPreference() {
val preferenceCategory = findPreference<PreferenceCategory>(
PREF_PERMISSION
)
preferenceCategory!!.isVisible = true
}
companion object {
const val PREF_MANAGE_EXTERNAL_STORAGE_PERMISSION =
"pref_manage_external_storage"
}
}

View File

@ -0,0 +1,27 @@
<!--
~ Kiwix Android
~ Copyright (c) 2021 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/>.
~
-->
<vector android:height="200dp"
android:viewportHeight="1256"
android:viewportWidth="1256"
android:width="200dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<path android:fillColor="#FFFFFF" android:pathData="M1165,764.1c-8.3,-36.4 -68.5,-141.3 -191.6,-234.4c-22.5,-17.1 -42.8,-31.3 -59.7,-42.6c24.6,-105.3 -103.3,-232.3 -228.1,-172.5C596,230.3 496.1,195.9 404.2,197.3c-243.3,3.4 -431,256.9 -229.1,498.8c0.1,0.1 0.2,0.2 0.4,0.4c3.1,3.7 6.3,7.4 9.5,11.1c13.1,15.7 21.8,29.6 29.2,54.1L274.4,959h-21.3c-19.6,0 -35.6,15.9 -35.6,35.6h80.8l135.8,64.2c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8H484c0,-19.6 -15.9,-35.6 -35.6,-35.6h-92.8c-16.2,0 -30.6,-10.6 -35.3,-26.1l-47.7,-156.7c-11.9,-41.2 15.4,-68.1 41.1,-71.3c23.4,-2.9 35.2,12.2 46.2,48.8l42.4,139H381c-19.6,0 -35.6,15.9 -35.6,35.6h80.8L562,992.6c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8h75.1c7.6,12.9 16.9,25.1 28,36.1c70,70 183.7,70 253.7,0s70,-183.7 0,-253.7s-183.7,-70 -253.7,0c-49.2,49.2 -63.9,120 -43.9,182h-85c-16.2,0 -30.6,-10.6 -35.3,-26.1L378,635.4l12,-6.4c167.1,-70.1 345.8,55.1 470.2,-65.2c0.3,-0.3 0.6,-0.6 0.8,-0.8c15.4,-14 30.8,-28.3 76.3,0.2c49,30.7 157.1,110.8 206.1,247.8C1143.5,811 1173.2,800.4 1165,764.1zM821.2,460.6c-0.4,-18.7 -15.6,-33.7 -34.5,-33.7c-19,0 -34.5,15.4 -34.5,34.5c0,10.4 4.6,19.6 11.8,25.9c-25,-4.8 -43.8,-26.6 -43.8,-52.9c0,-29.8 24.1,-53.9 53.9,-53.9c29.8,0 53.9,24.1 53.9,53.9C828,443.9 825.5,452.8 821.2,460.6z"
tools:ignore="VectorPath"/>
</vector>

View File

@ -0,0 +1,27 @@
<!--
~ Kiwix Android
~ Copyright (c) 2021 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/>.
~
-->
<!-- changes for API 23 and lower -->
<vector android:height="100dp"
android:viewportHeight="1256"
android:viewportWidth="1256"
android:width="100dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<path android:fillColor="#FFFFFF" android:pathData="M1165,764.1c-8.3,-36.4 -68.5,-141.3 -191.6,-234.4c-22.5,-17.1 -42.8,-31.3 -59.7,-42.6c24.6,-105.3 -103.3,-232.3 -228.1,-172.5C596,230.3 496.1,195.9 404.2,197.3c-243.3,3.4 -431,256.9 -229.1,498.8c0.1,0.1 0.2,0.2 0.4,0.4c3.1,3.7 6.3,7.4 9.5,11.1c13.1,15.7 21.8,29.6 29.2,54.1L274.4,959h-21.3c-19.6,0 -35.6,15.9 -35.6,35.6h80.8l135.8,64.2c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8H484c0,-19.6 -15.9,-35.6 -35.6,-35.6h-92.8c-16.2,0 -30.6,-10.6 -35.3,-26.1l-47.7,-156.7c-11.9,-41.2 15.4,-68.1 41.1,-71.3c23.4,-2.9 35.2,12.2 46.2,48.8l42.4,139H381c-19.6,0 -35.6,15.9 -35.6,35.6h80.8L562,992.6c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8h75.1c7.6,12.9 16.9,25.1 28,36.1c70,70 183.7,70 253.7,0s70,-183.7 0,-253.7s-183.7,-70 -253.7,0c-49.2,49.2 -63.9,120 -43.9,182h-85c-16.2,0 -30.6,-10.6 -35.3,-26.1L378,635.4l12,-6.4c167.1,-70.1 345.8,55.1 470.2,-65.2c0.3,-0.3 0.6,-0.6 0.8,-0.8c15.4,-14 30.8,-28.3 76.3,0.2c49,30.7 157.1,110.8 206.1,247.8C1143.5,811 1173.2,800.4 1165,764.1zM821.2,460.6c-0.4,-18.7 -15.6,-33.7 -34.5,-33.7c-19,0 -34.5,15.4 -34.5,34.5c0,10.4 4.6,19.6 11.8,25.9c-25,-4.8 -43.8,-26.6 -43.8,-52.9c0,-29.8 24.1,-53.9 53.9,-53.9c29.8,0 53.9,24.1 53.9,53.9C828,443.9 825.5,452.8 821.2,460.6z"
tools:ignore="VectorPath"/>
</vector>

View File

@ -21,9 +21,6 @@
android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@color/mine_shaft_gray900" />
<item>
<bitmap
android:gravity="center"
android:src="@drawable/kiwix_icon_with_title" />
</item>
<item android:drawable="@drawable/kiwix_icon"
android:gravity="center"/>
</layer-list>

View File

@ -0,0 +1,29 @@
<!--
~ Kiwix Android
~ Copyright (c) 2021 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/>.
~
-->
<vector android:height="200dp"
android:viewportHeight="1256"
android:viewportWidth="1256"
android:width="200dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<path android:fillColor="#010101"
android:pathData="M1165,764.1c-8.3,-36.4 -68.5,-141.3 -191.6,-234.4c-22.5,-17.1 -42.8,-31.3 -59.7,-42.6c24.6,-105.3 -103.3,-232.3 -228.1,-172.5C596,230.3 496.1,195.9 404.2,197.3c-243.3,3.4 -431,256.9 -229.1,498.8c0.1,0.1 0.2,0.2 0.4,0.4c3.1,3.7 6.3,7.4 9.5,11.1c13.1,15.7 21.8,29.6 29.2,54.1L274.4,959h-21.3c-19.6,0 -35.6,15.9 -35.6,35.6h80.8l135.8,64.2c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8H484c0,-19.6 -15.9,-35.6 -35.6,-35.6h-92.8c-16.2,0 -30.6,-10.6 -35.3,-26.1l-47.7,-156.7c-11.9,-41.2 15.4,-68.1 41.1,-71.3c23.4,-2.9 35.2,12.2 46.2,48.8l42.4,139h-21.3c-19.6,0 -35.6,15.9 -35.6,35.6h80.8l135.8,64.2c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8h75.1c7.6,12.9 16.9,25.1 28,36.1c70,70 183.7,70 253.7,0s70,-183.7 0,-253.7s-183.7,-70 -253.7,0c-49.2,49.2 -63.9,120 -43.9,182h-85c-16.2,0 -30.6,-10.6 -35.3,-26.1L378,635.4l12,-6.4c167.1,-70.1 345.8,55.1 470.2,-65.2c0.3,-0.3 0.6,-0.6 0.8,-0.8c15.4,-14 30.8,-28.3 76.3,0.2c49,30.7 157.1,110.8 206.1,247.8C1143.5,811 1173.2,800.4 1165,764.1zM821.2,460.6c-0.4,-18.7 -15.6,-33.7 -34.5,-33.7c-19,0 -34.5,15.4 -34.5,34.5c0,10.4 4.6,19.6 11.8,25.9c-25,-4.8 -43.8,-26.6 -43.8,-52.9c0,-29.8 24.1,-53.9 53.9,-53.9c29.8,0 53.9,24.1 53.9,53.9C828,443.9 825.5,452.8 821.2,460.6z"
tools:ignore="VectorPath"
/>
</vector>

View File

@ -0,0 +1,29 @@
<!--
~ Kiwix Android
~ Copyright (c) 2021 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/>.
~
-->
<!-- changes for API 23 and lower -->
<vector android:height="100dp"
android:viewportHeight="1256"
android:viewportWidth="1256"
android:width="100dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<path android:fillColor="#010101"
android:pathData="M1165,764.1c-8.3,-36.4 -68.5,-141.3 -191.6,-234.4c-22.5,-17.1 -42.8,-31.3 -59.7,-42.6c24.6,-105.3 -103.3,-232.3 -228.1,-172.5C596,230.3 496.1,195.9 404.2,197.3c-243.3,3.4 -431,256.9 -229.1,498.8c0.1,0.1 0.2,0.2 0.4,0.4c3.1,3.7 6.3,7.4 9.5,11.1c13.1,15.7 21.8,29.6 29.2,54.1L274.4,959h-21.3c-19.6,0 -35.6,15.9 -35.6,35.6h80.8l135.8,64.2c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8H484c0,-19.6 -15.9,-35.6 -35.6,-35.6h-92.8c-16.2,0 -30.6,-10.6 -35.3,-26.1l-47.7,-156.7c-11.9,-41.2 15.4,-68.1 41.1,-71.3c23.4,-2.9 35.2,12.2 46.2,48.8l42.4,139h-21.3c-19.6,0 -35.6,15.9 -35.6,35.6h80.8l135.8,64.2c8.4,-17.8 0.8,-39 -16.9,-47.3l-35.6,-16.8h75.1c7.6,12.9 16.9,25.1 28,36.1c70,70 183.7,70 253.7,0s70,-183.7 0,-253.7s-183.7,-70 -253.7,0c-49.2,49.2 -63.9,120 -43.9,182h-85c-16.2,0 -30.6,-10.6 -35.3,-26.1L378,635.4l12,-6.4c167.1,-70.1 345.8,55.1 470.2,-65.2c0.3,-0.3 0.6,-0.6 0.8,-0.8c15.4,-14 30.8,-28.3 76.3,0.2c49,30.7 157.1,110.8 206.1,247.8C1143.5,811 1173.2,800.4 1165,764.1zM821.2,460.6c-0.4,-18.7 -15.6,-33.7 -34.5,-33.7c-19,0 -34.5,15.4 -34.5,34.5c0,10.4 4.6,19.6 11.8,25.9c-25,-4.8 -43.8,-26.6 -43.8,-52.9c0,-29.8 24.1,-53.9 53.9,-53.9c29.8,0 53.9,24.1 53.9,53.9C828,443.9 825.5,452.8 821.2,460.6z"
tools:ignore="VectorPath"
/>
</vector>

View File

@ -21,9 +21,6 @@
android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@color/alabaster_white" />
<item>
<bitmap
android:gravity="center"
android:src="@drawable/kiwix_icon_with_title" />
</item>
<item android:drawable="@drawable/kiwix_icon"
android:gravity="center"/>
</layer-list>

View File

@ -20,8 +20,20 @@ package org.kiwix.kiwixmobile.core
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.annotation.RequiresApi
object Intents {
@JvmStatic fun <T : Activity> internal(clazz: Class<T>): Intent =
Intent(clazz.canonicalName).setPackage(CoreApp.instance.packageName)
}
@RequiresApi(Build.VERSION_CODES.R)
fun Activity.navigateToSettings() {
val intent = Intent().apply {
action = Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
data = Uri.fromParts("package", packageName, null)
}
startActivity(intent)
}

View File

@ -19,6 +19,7 @@
package org.kiwix.kiwixmobile.core.extensions
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.fragment.app.Fragment
@ -41,4 +42,9 @@ fun Fragment.closeKeyboard() {
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
}
fun View.closeKeyboard() {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(windowToken, 0)
}
val Fragment.coreMainActivity get() = activity as CoreMainActivity

View File

@ -42,6 +42,7 @@ import kotlinx.android.synthetic.main.layout_toolbar.toolbar
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.base.BaseFragment
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
import org.kiwix.kiwixmobile.core.extensions.closeKeyboard
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
import org.kiwix.kiwixmobile.core.page.adapter.Page
@ -50,6 +51,7 @@ import org.kiwix.kiwixmobile.core.page.viewmodel.Action
import org.kiwix.kiwixmobile.core.page.viewmodel.PageState
import org.kiwix.kiwixmobile.core.page.viewmodel.PageViewModel
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.SimpleRecyclerViewScrollListener
import org.kiwix.kiwixmobile.core.utils.SimpleTextListener
import javax.inject.Inject
@ -135,6 +137,13 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
pageViewModel.actions.offer(Action.UserClickedShowAllToggle(isChecked))
}
pageViewModel.state.observe(viewLifecycleOwner, Observer(::render))
// hides keyboard when scrolled
recycler_view.addOnScrollListener(SimpleRecyclerViewScrollListener { _, newState ->
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
recycler_view.closeKeyboard()
}
})
}
override fun onCreateView(

View File

@ -62,6 +62,7 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme
public static final String PREF_CLEAR_ALL_HISTORY = "pref_clear_all_history";
public static final String PREF_CLEAR_ALL_NOTES = "pref_clear_all_notes";
public static final String PREF_CREDITS = "pref_credits";
public static final String PREF_PERMISSION = "pref_permissions";
private static final int ZOOM_OFFSET = 2;
private static final int ZOOM_SCALE = 25;
private static final String INTERNAL_TEXT_ZOOM = "text_zoom";
@ -174,6 +175,9 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme
versionPref.setSummary(getVersionName() + " Build: " + getVersionCode());
}
private int getVersionCode() {
try {
return getActivity().getPackageManager()
@ -282,4 +286,5 @@ public abstract class CorePrefsFragment extends PreferenceFragmentCompat impleme
}
return Unit.INSTANCE;
}
}

View File

@ -140,6 +140,13 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
fun updateNightMode() = nightModes.offer(nightMode)
var manageExternalFilesPermissionDialog: Boolean
get() = sharedPreferences.getBoolean(PREF_MANAGE_EXTERNAL_FILES, true)
set(prefManageExternalFilesPermissionDialog) =
sharedPreferences.edit {
putBoolean(PREF_MANAGE_EXTERNAL_FILES, prefManageExternalFilesPermissionDialog)
}
var hostedBooks: Set<String>
get() = sharedPreferences.getStringSet(PREF_HOSTED_BOOKS, null)?.toHashSet() ?: HashSet()
set(hostedBooks) {
@ -172,5 +179,6 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
const val PREF_NIGHT_MODE = "pref_night_mode"
private const val TEXT_ZOOM = "true_text_zoom"
private const val DEFAULT_ZOOM = 100
private const val PREF_MANAGE_EXTERNAL_FILES = "pref_manage_external_files"
}
}

View File

@ -0,0 +1,34 @@
/*
* Kiwix Android
* Copyright (c) 2021 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
import androidx.recyclerview.widget.RecyclerView
class SimpleRecyclerViewScrollListener(
private val onLayoutScrollListener: (RecyclerView, Int) -> Unit
) :
RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
onLayoutScrollListener(
recyclerView,
newState
)
}
}

View File

@ -84,6 +84,14 @@ sealed class KiwixDialog(
cancelable = false
)
object ManageExternalFilesPermissionDialog : KiwixDialog(
R.string.all_files_permission_needed,
R.string.all_files_permission_needed_message,
R.string.yes,
R.string.no,
cancelable = false
)
data class ShowHotspotDetails(override val args: List<Any>) : KiwixDialog(
R.string.hotspot_turned_on,
R.string.hotspot_details_message,

View File

@ -68,6 +68,7 @@
<string name="pref_clear_all_history_title">Clear history</string>
<string name="pref_clear_all_history_summary">Clear recent searches and tabs history</string>
<string name="pref_notes">Notes</string>
<string name="pref_permission">Permissions</string>
<string name="all_history_cleared">All History Cleared</string>
<string name="pref_clear_all_bookmarks_title">Clear bookmarks</string>
<string name="clear_all_history_dialog_title">Clear All History?</string>
@ -255,6 +256,7 @@
<string name="status" tools:keep="@string/status">Status</string>
<string name="pref_clear_all_notes_summary">Clears all notes on all articles</string>
<string name="pref_clear_all_notes_title">Clear all notes</string>
<string name="pref_allow_to_read_or_write_zim_files_on_sd_card">Allow to read and write ZIM files on SD card</string>
<string name="pref_text_zoom_summary">Change text size with 25\% increments.</string>
<string name="tag_pic">Pic</string>
<string name="tag_vid">Vid</string>
@ -289,6 +291,10 @@
<string name="close_drawer">Close Drawer</string>
<string name="how_to_update_content">How to update content?</string>
<string name="update_content_description">To update content (a zim file) you need to download the full latest version of this very same content. You can do that via the download section.</string>
<string name="all_files_permission_needed">All Files Permission Needed</string>
<string name="all_files_permission_needed_message">In order to access all the zim files across device we need to have All Files Permission</string>
<string name="allowed">Allowed</string>
<string name="not_allowed">Not allowed</string>
<string-array name="pref_night_modes_entries">
<item>@string/on</item>
<item>@string/off</item>

View File

@ -95,6 +95,18 @@
android:title="@string/pref_clear_all_notes_title"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_permissions"
android:title="@string/pref_permission"
app:isPreferenceVisible="false"
app:iconSpaceReserved="false">
<Preference
android:key="pref_manage_external_storage"
android:title="@string/pref_allow_to_read_or_write_zim_files_on_sd_card"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_language"

View File

@ -32,7 +32,7 @@ class CustomPrefsFragment : CorePrefsFragment() {
} else {
preferenceScreen.removePreference(findPreference("pref_language"))
}
preferenceScreen.removePreference(findPreference(PREF_WIFI_ONLY))
preferenceScreen.removePreferenceRecursively(PREF_WIFI_ONLY)
}
override fun setStorage() {