mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-11 16:37:18 -04:00
Merge pull request #1686 from kiwix/feature/macgills/1673-permission-denied-forever
Feature/macgills/1673 permission denied forever
This commit is contained in:
commit
1e2eaf51c9
@ -45,6 +45,7 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) : Di
|
||||
?.invoke()
|
||||
}
|
||||
}
|
||||
setCancelable(dialog.cancelable)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ sealed class KiwixDialog(
|
||||
val title: Int?,
|
||||
val message: Int,
|
||||
val positiveMessage: Int,
|
||||
val negativeMessage: Int?
|
||||
val negativeMessage: Int?,
|
||||
val cancelable: Boolean = true
|
||||
) {
|
||||
|
||||
data class DeleteZim(override val args: List<Any>) : KiwixDialog(
|
||||
@ -64,6 +65,14 @@ sealed class KiwixDialog(
|
||||
null
|
||||
)
|
||||
|
||||
object ReadPermissionRequired : KiwixDialog(
|
||||
R.string.storage_permission_denied,
|
||||
R.string.grant_read_storage_permission,
|
||||
R.string.go_to_permissions,
|
||||
null,
|
||||
cancelable = false
|
||||
)
|
||||
|
||||
data class ShowHotspotDetails(override val args: List<Any>) : KiwixDialog(
|
||||
R.string.hotspot_turned_on,
|
||||
R.string.hotspot_details_message,
|
||||
|
@ -289,6 +289,9 @@
|
||||
<string name="tag_vid">Vid</string>
|
||||
<string name="tag_text_only">Text Only</string>
|
||||
<string name="tag_short_text">Short Text</string>
|
||||
<string name="storage_permission_denied">Storage Permission Denied</string>
|
||||
<string name="grant_read_storage_permission">This app requires the ability to read storage to function. Please grant the permission in your settings</string>
|
||||
<string name="go_to_permissions">Go to Settings</string>
|
||||
<string-array name="pref_night_modes_entries">
|
||||
<item>On</item>
|
||||
<item>Off</item>
|
||||
|
@ -20,16 +20,22 @@ package org.kiwix.kiwixmobile.custom.main
|
||||
|
||||
import android.Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager.PERMISSION_DENIED
|
||||
import android.net.Uri
|
||||
import android.os.Build.VERSION_CODES
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
|
||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.main.WebViewCallback
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||
import org.kiwix.kiwixmobile.core.utils.DialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
||||
import org.kiwix.kiwixmobile.custom.BuildConfig
|
||||
import org.kiwix.kiwixmobile.custom.R
|
||||
@ -44,6 +50,7 @@ const val REQUEST_READ_FOR_OBB = 5002
|
||||
|
||||
class CustomMainActivity : CoreMainActivity() {
|
||||
@Inject lateinit var customFileValidator: CustomFileValidator
|
||||
@Inject lateinit var dialogShower: DialogShower
|
||||
|
||||
override fun showHomePage() {
|
||||
Log.e("CustomMain", "tried to show home page")
|
||||
@ -94,10 +101,25 @@ class CustomMainActivity : CoreMainActivity() {
|
||||
grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if (requestCode == REQUEST_READ_FOR_OBB) {
|
||||
if (permissions.isNotEmpty() && permissions[0] == READ_EXTERNAL_STORAGE) {
|
||||
if (readStorageHasBeenPermanentlyDenied(grantResults)) {
|
||||
dialogShower.show(KiwixDialog.ReadPermissionRequired, ::goToSettings)
|
||||
} else {
|
||||
openObbOrZim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun goToSettings() {
|
||||
startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
|
||||
data = Uri.fromParts("package", packageName, null)
|
||||
})
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.JELLY_BEAN)
|
||||
private fun readStorageHasBeenPermanentlyDenied(grantResults: IntArray) =
|
||||
grantResults[0] == PERMISSION_DENIED &&
|
||||
!ActivityCompat.shouldShowRequestPermissionRationale(this, READ_EXTERNAL_STORAGE)
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
val onCreateOptionsMenu = super.onCreateOptionsMenu(menu)
|
||||
|
Loading…
x
Reference in New Issue
Block a user