From e0eb72977694109051a6523c7192bf88685ec16f Mon Sep 17 00:00:00 2001 From: sictiru Date: Tue, 17 Sep 2024 11:35:53 -0700 Subject: [PATCH] #1891 Handle Android 9 and below for OPML file export --- .../NewsBlur/app/src/main/AndroidManifest.xml | 215 +++++++++--------- .../newsblur/activity/ImportExportActivity.kt | 34 ++- .../app/src/main/res/values/strings.xml | 4 +- 3 files changed, 149 insertions(+), 104 deletions(-) diff --git a/clients/android/NewsBlur/app/src/main/AndroidManifest.xml b/clients/android/NewsBlur/app/src/main/AndroidManifest.xml index 1f5645a034..f8dcce0211 100644 --- a/clients/android/NewsBlur/app/src/main/AndroidManifest.xml +++ b/clients/android/NewsBlur/app/src/main/AndroidManifest.xml @@ -1,22 +1,25 @@ - + - + + + android:dataExtractionRules="@xml/data_extraction_rules" + android:fullBackupContent="@xml/backupscheme" + android:fullBackupOnly="true" + android:icon="@drawable/logo" + android:label="@string/newsblur" + android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"> + android:theme="@style/splashScreen"> - @@ -48,143 +52,139 @@ + android:label="@string/get_started" + android:noHistory="true" /> + android:alwaysRetainTaskState="true" + android:launchMode="singleTask" /> + android:label="@string/profile" /> + android:label="@string/settings" /> + android:label="@string/menu_widget" + android:launchMode="singleTask" /> - + + android:launchMode="singleTask" /> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + android:label="@string/mute_sites" + android:launchMode="singleTask" /> - + - + android:exported="false" + android:permission="android.permission.BIND_JOB_SERVICE" /> - - - - - - - + + + + - - - - + + - + android:exported="false"> + - + - - - - - - - - + + + + + + + + + + + + - - - - + + + + + - - + + + + - - - - - - - - + + + + + + + + + - + android:theme="@style/Theme.Translucent" + android:windowSoftInputMode="adjustResize"> diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ImportExportActivity.kt b/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ImportExportActivity.kt index 3f1b2c4c77..2c92973fd6 100644 --- a/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ImportExportActivity.kt +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ImportExportActivity.kt @@ -1,12 +1,16 @@ package com.newsblur.activity +import android.Manifest import android.app.Activity import android.content.Intent +import android.content.pm.PackageManager import android.net.Uri +import android.os.Build import android.os.Bundle import android.webkit.MimeTypeMap import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.content.ContextCompat import com.google.android.material.snackbar.Snackbar import com.newsblur.R import com.newsblur.databinding.ActivityImportExportBinding @@ -40,6 +44,16 @@ class ImportExportActivity : NbActivity() { } } + // used for Android 9 and below + private val requestWriteStoragePermissionLauncher = registerForActivityResult( + ActivityResultContracts.RequestPermission()) { isGranted -> + if (isGranted) { + exportOpmlFile() + } else { + Toast.makeText(this, R.string.write_storage_permission_opml, Toast.LENGTH_LONG).show() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityImportExportBinding.inflate(layoutInflater) @@ -55,7 +69,13 @@ class ImportExportActivity : NbActivity() { private fun setupListeners() { binding.btnUpload.setOnClickListener { pickOpmlFile() } - binding.btnDownload.setOnClickListener { exportOpmlFile() } + binding.btnDownload.setOnClickListener { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { + checkAndRequestWriteStoragePermission() + } else { + exportOpmlFile() + } + } } private fun pickOpmlFile() { @@ -131,4 +151,16 @@ class ImportExportActivity : NbActivity() { override fun handleUpdate(updateType: Int) { // ignore } + + // Android 9 and below + private fun checkAndRequestWriteStoragePermission() { + if (ContextCompat.checkSelfPermission( + this, + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_GRANTED) { + exportOpmlFile() + } else { + requestWriteStoragePermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) + } + } } \ No newline at end of file diff --git a/clients/android/NewsBlur/app/src/main/res/values/strings.xml b/clients/android/NewsBlur/app/src/main/res/values/strings.xml index 6eda5fa25b..48387ba01c 100644 --- a/clients/android/NewsBlur/app/src/main/res/values/strings.xml +++ b/clients/android/NewsBlur/app/src/main/res/values/strings.xml @@ -745,7 +745,9 @@ Permissions is required for posting notifications Notifications permission must be added manually in the app\'s settings before trying again to enable notifications - + + Write storage permission is required for OPML export + Story marked as saved Story marked as unsaved Story marked as read