Skip permissions checking for saving and loading files
At some point I refactored to an API that doesn't require any permissions at all but never removed the permissions check. This corrects that
This commit is contained in:
parent
13bfe236a3
commit
c5355d1565
5 changed files with 62 additions and 57 deletions
|
@ -46,8 +46,8 @@ android {
|
|||
applicationId = "com.wbrawner.simplemarkdown"
|
||||
minSdk = 23
|
||||
targetSdk = 33
|
||||
versionCode = 35
|
||||
versionName = "0.8.13"
|
||||
versionCode = 39
|
||||
versionName = "0.8.15"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunnerArguments["clearPackageData"] = "true"
|
||||
buildConfigField("boolean", "ENABLE_CUSTOM_CSS", "true")
|
||||
|
@ -134,7 +134,7 @@ android.productFlavors.forEach { flavor ->
|
|||
dependencies {
|
||||
implementation("com.android.billingclient:billing:5.1.0")
|
||||
implementation("com.google.android.play:core-ktx:1.8.1")
|
||||
implementation("com.google.firebase:firebase-crashlytics:18.3.3")
|
||||
implementation("com.google.firebase:firebase-crashlytics:18.3.5")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
|
|
|
@ -57,11 +57,16 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_edit, menu)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
menu.findItem(R.id.action_save_as)?.setAlphabeticShortcut('S', KeyEvent.META_CTRL_ON or KeyEvent.META_SHIFT_ON)
|
||||
menu.findItem(R.id.action_save_as)
|
||||
?.setAlphabeticShortcut('S', KeyEvent.META_CTRL_ON or KeyEvent.META_SHIFT_ON)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? =
|
||||
inflater.inflate(R.layout.fragment_main, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -92,6 +97,7 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
drawerLayout.open()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_save -> {
|
||||
Timber.d("Save clicked")
|
||||
lifecycleScope.launch {
|
||||
|
@ -107,38 +113,46 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
}
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_save_as -> {
|
||||
Timber.d("Save as clicked")
|
||||
requestFileOp(REQUEST_SAVE_FILE)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_share -> {
|
||||
Timber.d("Share clicked")
|
||||
val shareIntent = Intent(Intent.ACTION_SEND)
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, viewModel.markdownUpdates.value)
|
||||
shareIntent.type = "text/plain"
|
||||
startActivity(Intent.createChooser(
|
||||
startActivity(
|
||||
Intent.createChooser(
|
||||
shareIntent,
|
||||
getString(R.string.share_file)
|
||||
))
|
||||
)
|
||||
)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_load -> {
|
||||
Timber.d("Load clicked")
|
||||
requestFileOp(REQUEST_OPEN_FILE)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_new -> {
|
||||
Timber.d("New clicked")
|
||||
promptSaveOrDiscardChanges()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_lock_swipe -> {
|
||||
Timber.d("Lock swiping clicked")
|
||||
item.isChecked = !item.isChecked
|
||||
pager!!.setSwipeLocked(item.isChecked)
|
||||
true
|
||||
}
|
||||
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +162,8 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
Plausible.pageView("")
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val enableErrorReports = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val enableErrorReports =
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
.getBoolean(getString(R.string.pref_key_error_reports_enabled), true)
|
||||
Timber.d("MainFragment started. Error reports enabled? $enableErrorReports")
|
||||
errorHandler.enable(enableErrorReports)
|
||||
|
@ -219,6 +234,7 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
REQUEST_SAVE_FILE -> {
|
||||
if (resultCode != Activity.RESULT_OK || data?.data == null) {
|
||||
Timber.w(
|
||||
|
@ -270,19 +286,6 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
}
|
||||
|
||||
private fun requestFileOp(requestType: Int) {
|
||||
val context = context ?: run {
|
||||
Timber.w("File op requested but context was null, aborting")
|
||||
return
|
||||
}
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Timber.i("Storage permission not granted, requesting")
|
||||
requestPermissions(
|
||||
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
requestType
|
||||
)
|
||||
return
|
||||
}
|
||||
val intent = when (requestType) {
|
||||
REQUEST_SAVE_FILE -> {
|
||||
Timber.d("Requesting save op")
|
||||
|
@ -291,6 +294,7 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
putExtra(Intent.EXTRA_TITLE, viewModel.fileName.value)
|
||||
}
|
||||
}
|
||||
|
||||
REQUEST_OPEN_FILE -> {
|
||||
Timber.d("Requesting open op")
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
|
@ -302,6 +306,7 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
Timber.w("Ignoring unknown file op request: $requestType")
|
||||
null
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
|
||||
<application>
|
||||
|
|
|
@ -7,9 +7,9 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:7.4.0")
|
||||
classpath("com.android.tools.build:gradle:7.4.2")
|
||||
classpath("com.google.gms:google-services:4.3.15")
|
||||
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.2")
|
||||
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.4")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
|
||||
classpath("com.osacky.flank.gradle:fladle:0.17.4")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue