Add initial support for external storage

This commit is contained in:
Rahul Kumar Patel
2021-02-24 15:34:21 +05:30
parent 3d00fc7691
commit 55865d3ce5
9 changed files with 40 additions and 17 deletions

View File

@@ -21,7 +21,10 @@ package com.aurora.store
import android.Manifest
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.view.Menu
import android.view.MenuItem
import android.view.View
@@ -42,7 +45,7 @@ import com.aurora.store.databinding.ActivityMainBinding
import com.aurora.store.util.Log
import com.aurora.store.util.ViewUtil
import com.aurora.store.util.ViewUtil.getStyledAttribute
import com.aurora.store.util.extensions.isQAndAbove
import com.aurora.store.util.extensions.isRAndAbove
import com.aurora.store.util.extensions.load
import com.aurora.store.util.extensions.open
import com.aurora.store.view.ui.about.AboutActivity
@@ -97,16 +100,20 @@ class MainActivity : BaseActivity() {
attachSearch()
checkPermission()
checkStoragePermission()
}
private fun checkPermission() = runWithPermissions(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
) {
Log.i("External Storage Access Available")
Log.i("Required permissions available")
}
if (isQAndAbove()) {
//pickExternalFileDir()
private fun checkStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!Environment.isExternalStorageManager())
startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION))
}
}

View File

@@ -32,14 +32,18 @@ fun Context.getInternalBaseDirectory(): String {
object PathUtil {
private fun getDownloadDirectory(context: Context): String {
return if (isLAndAbove())
context.getInternalBaseDirectory() + "/Downloads"
else
return if (isLAndAbove()) {
if (Preferences.getBoolean(context, Preferences.PREFERENCE_DOWNLOAD_EXTERNAL))
getExternalPath()
else
context.getInternalBaseDirectory() + "/Downloads"
} else {
getExternalPath()
}
}
fun getPackageDirectory(context: Context, packageName: String): String {
return getDownloadDirectory(context) + "/$packageName"
return getDownloadDirectory(context) + "/Downloads/$packageName"
}
private fun getVersionDirectory(
@@ -59,11 +63,11 @@ object PathUtil {
}
fun getExternalPath(): String {
return Environment.getExternalStorageDirectory().toString() + "/Aurora/"
return Environment.getExternalStorageDirectory().toString() + "/Aurora/Store"
}
fun getBaseCopyDirectory(): String {
return "${getExternalPath()}/files/export/"
return "${getExternalPath()}/Exports/"
}
private fun getObbDownloadPath(context: Context, app: App): String {

View File

@@ -43,6 +43,7 @@ object Preferences {
const val INSTALLATION_ABANDON_SESSION = "INSTALLATION_ABANDON_SESSION"
const val PREFERENCE_DOWNLOAD_ACTIVE = "PREFERENCE_DOWNLOAD_ACTIVE"
const val PREFERENCE_DOWNLOAD_EXTERNAL = "PREFERENCE_DOWNLOAD_EXTERNAL"
const val PREFERENCE_DOWNLOAD_WIFI = "PREFERENCE_DOWNLOAD_WIFI"

View File

@@ -21,6 +21,7 @@ package com.aurora.store.util.extensions
import android.os.Build
import android.text.format.DateFormat
import androidx.annotation.RequiresApi
import java.util.*
fun Long.toDate(): String {
@@ -43,4 +44,8 @@ fun isPAndAbove(): Boolean {
fun isQAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
}
fun isRAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
}

View File

@@ -32,6 +32,7 @@ import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_AUTO_DELETE
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT
import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_ACTIVE
import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_EXTERNAL
import com.aurora.store.util.Preferences.PREFERENCE_FILTER_FDROID
import com.aurora.store.util.Preferences.PREFERENCE_FILTER_GOOGLE
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
@@ -149,13 +150,14 @@ class OnboardingActivity : BaseActivity() {
/*Downloader*/
save(PREFERENCE_DOWNLOAD_ACTIVE, 3)
save(PREFERENCE_DOWNLOAD_EXTERNAL, false)
/*Theme*/
save(PREFERENCE_THEME_TYPE, 0)
save(PREFERENCE_THEME_ACCENT, 0)
/*Installer*/
save(PREFERENCE_AUTO_DELETE, false)
save(PREFERENCE_AUTO_DELETE, true)
save(PREFERENCE_INSTALLER_ID, 0)
}

View File

@@ -34,7 +34,6 @@ import com.aurora.store.data.providers.BlacklistProvider
import com.aurora.store.databinding.SheetAppMenuBinding
import com.aurora.store.util.ApkCopier
import com.aurora.store.util.PackageUtil
import com.aurora.store.util.extensions.isQAndAbove
import com.aurora.store.util.extensions.openInfo
import com.aurora.store.util.extensions.toast
import com.livinglifetechway.quickpermissions_kotlin.runWithPermissions
@@ -87,11 +86,6 @@ class AppMenuSheet : BaseBottomSheet() {
menu.findItem(R.id.action_uninstall).isVisible = installed
menu.findItem(R.id.action_local).isVisible = installed
if (isQAndAbove()) {
//TODO: Add Scoped Storage Access
menu.findItem(R.id.action_local).isVisible = false
}
setNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.action_blacklist -> {