Minor usecase improvements
This commit is contained in:
@@ -20,9 +20,21 @@
|
||||
package com.aurora.store.data.event
|
||||
|
||||
sealed class BusEvent {
|
||||
data class InstallEvent(var packageName: String, var error: String = String()) : BusEvent()
|
||||
data class UninstallEvent(var packageName: String, var error: String = String()) : BusEvent()
|
||||
data class Blacklisted(var packageName: String, var error: String = String()) : BusEvent()
|
||||
data class InstallEvent(
|
||||
var packageName: String,
|
||||
var extra: String? = ""
|
||||
) : BusEvent()
|
||||
|
||||
data class UninstallEvent(
|
||||
var packageName: String,
|
||||
var extra: String? = ""
|
||||
) : BusEvent()
|
||||
|
||||
data class Blacklisted(
|
||||
var packageName: String,
|
||||
var error: String? = ""
|
||||
) : BusEvent()
|
||||
|
||||
data class GoogleAAS(
|
||||
var success: Boolean,
|
||||
var email: String = String(),
|
||||
@@ -30,15 +42,15 @@ sealed class BusEvent {
|
||||
) : BusEvent()
|
||||
}
|
||||
|
||||
sealed class SessionEvent {
|
||||
sealed class InstallerEvent {
|
||||
data class Success(
|
||||
var packageName: String? = "",
|
||||
var extra: String? = ""
|
||||
) : SessionEvent()
|
||||
) : InstallerEvent()
|
||||
|
||||
data class Failed(
|
||||
var packageName: String? = "",
|
||||
var error: String? = "",
|
||||
var extra: String? = ""
|
||||
) : SessionEvent()
|
||||
) : InstallerEvent()
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import android.os.Build
|
||||
import android.os.IBinder
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.SessionEvent
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.util.Log
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
@@ -65,12 +65,12 @@ class InstallerService : Service() {
|
||||
private fun postStatus(status: Int, packageName: String?, extra: String?) {
|
||||
when (status) {
|
||||
PackageInstaller.STATUS_SUCCESS -> {
|
||||
EventBus.getDefault().post(SessionEvent.Success(packageName, "Success"))
|
||||
EventBus.getDefault().post(InstallerEvent.Success(packageName, "Success"))
|
||||
}
|
||||
else -> {
|
||||
val errorString = getErrorString(status)
|
||||
Log.e("$packageName : $errorString")
|
||||
EventBus.getDefault().post(SessionEvent.Failed(packageName, errorString, extra))
|
||||
EventBus.getDefault().post(InstallerEvent.Failed(packageName, errorString, extra))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,8 @@ package com.aurora.store.data.installer
|
||||
|
||||
import android.content.Context
|
||||
import com.aurora.extensions.isLAndAbove
|
||||
import com.aurora.extensions.toast
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.SessionEvent
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.util.Log
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
@@ -52,7 +51,7 @@ class RootInstaller(context: Context) : InstallerBase(context) {
|
||||
xInstallLegacy(packageName, it)
|
||||
}
|
||||
} else {
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
context.getString(R.string.installer_status_failure),
|
||||
context.getString(R.string.installer_root_unavailable)
|
||||
@@ -91,7 +90,7 @@ class RootInstaller(context: Context) : InstallerBase(context) {
|
||||
|
||||
if (!shellResult.isSuccess) {
|
||||
removeFromInstallQueue(packageName)
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
context.getString(R.string.installer_status_failure),
|
||||
parseError(shellResult)
|
||||
@@ -100,7 +99,7 @@ class RootInstaller(context: Context) : InstallerBase(context) {
|
||||
}
|
||||
} else {
|
||||
removeFromInstallQueue(packageName)
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
context.getString(R.string.installer_status_failure),
|
||||
context.getString(R.string.installer_root_unavailable)
|
||||
@@ -109,7 +108,7 @@ class RootInstaller(context: Context) : InstallerBase(context) {
|
||||
}
|
||||
} else {
|
||||
removeFromInstallQueue(packageName)
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
context.getString(R.string.installer_status_failure),
|
||||
context.getString(R.string.installer_status_failure_session)
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.aurora.services.IPrivilegedCallback
|
||||
import com.aurora.services.IPrivilegedService
|
||||
import com.aurora.store.BuildConfig
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.SessionEvent
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
@@ -70,7 +70,7 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
||||
xInstall(packageName, uriList)
|
||||
}
|
||||
else -> {
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
context.getString(R.string.installer_status_failure),
|
||||
context.getString(R.string.installer_service_unavailable)
|
||||
@@ -108,7 +108,7 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
||||
EventBus
|
||||
.getDefault()
|
||||
.post(
|
||||
SessionEvent.Failed(
|
||||
InstallerEvent.Failed(
|
||||
packageName,
|
||||
e.localizedMessage,
|
||||
e.stackTraceToString()
|
||||
@@ -118,7 +118,7 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
||||
}
|
||||
} else {
|
||||
Log.e(context.getString(R.string.installer_service_misconfigured))
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
context.getString(R.string.installer_status_failure),
|
||||
context.getString(R.string.installer_service_misconfigured)
|
||||
|
||||
@@ -29,7 +29,7 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.FileProvider
|
||||
import com.aurora.extensions.isNAndAbove
|
||||
import com.aurora.store.BuildConfig
|
||||
import com.aurora.store.data.event.SessionEvent
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.util.Log
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
@@ -102,7 +102,7 @@ class SessionInstaller(context: Context) : InstallerBase(context) {
|
||||
} catch (e: Exception) {
|
||||
session.abandon()
|
||||
removeFromInstallQueue(packageName)
|
||||
val event = SessionEvent.Failed(
|
||||
val event = InstallerEvent.Failed(
|
||||
packageName,
|
||||
e.localizedMessage,
|
||||
e.stackTraceToString()
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.aurora.store.data.event.BusEvent.UninstallEvent
|
||||
import com.aurora.store.data.installer.AppInstaller
|
||||
import com.aurora.store.util.PathUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.isExternalStorageEnable
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.File
|
||||
|
||||
@@ -39,19 +40,20 @@ open class PackageManagerReceiver : BroadcastReceiver() {
|
||||
|
||||
when (intent.action) {
|
||||
Intent.ACTION_PACKAGE_ADDED -> {
|
||||
EventBus.getDefault()
|
||||
.post(InstallEvent(packageName, ""))
|
||||
|
||||
//Clear installation queue
|
||||
AppInstaller(context)
|
||||
.getPreferredInstaller()
|
||||
.removeFromInstallQueue(packageName)
|
||||
EventBus.getDefault().post(InstallEvent(packageName, ""))
|
||||
}
|
||||
|
||||
Intent.ACTION_PACKAGE_REMOVED -> {
|
||||
EventBus.getDefault().post(UninstallEvent(packageName, ""))
|
||||
}
|
||||
Intent.ACTION_PACKAGE_REMOVED -> EventBus.getDefault()
|
||||
.post(UninstallEvent(packageName, ""))
|
||||
}
|
||||
|
||||
clearNotification(context, packageName)
|
||||
//Clear installation queue
|
||||
AppInstaller(context)
|
||||
.getPreferredInstaller()
|
||||
.removeFromInstallQueue(packageName)
|
||||
|
||||
//clearNotification(context, packageName)
|
||||
|
||||
val isAutoDeleteAPKEnabled = Preferences.getBoolean(
|
||||
context,
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.aurora.extensions.isLAndAbove
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.downloader.DownloadManager
|
||||
import com.aurora.store.data.event.SessionEvent
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.data.installer.AppInstaller
|
||||
import com.aurora.store.data.receiver.DownloadCancelReceiver
|
||||
import com.aurora.store.data.receiver.DownloadPauseReceiver
|
||||
@@ -361,12 +361,12 @@ class NotificationService : Service() {
|
||||
@Subscribe()
|
||||
fun onEventMainThread(event: Any) {
|
||||
when (event) {
|
||||
is SessionEvent.Success -> {
|
||||
is InstallerEvent.Success -> {
|
||||
val app = appMap[event.packageName.hashCode()]
|
||||
if (app != null)
|
||||
notifyInstallationStatus(app, event.extra)
|
||||
}
|
||||
is SessionEvent.Failed -> {
|
||||
is InstallerEvent.Failed -> {
|
||||
val app = appMap[event.packageName.hashCode()]
|
||||
if (app != null)
|
||||
notifyInstallationStatus(app, event.error)
|
||||
|
||||
@@ -21,9 +21,9 @@ package com.aurora.store.util
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import com.aurora.extensions.isLAndAbove
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.File
|
||||
import com.aurora.extensions.isLAndAbove
|
||||
|
||||
fun Context.getInternalBaseDirectory(): String {
|
||||
return filesDir.path
|
||||
@@ -33,7 +33,7 @@ object PathUtil {
|
||||
|
||||
private fun getDownloadDirectory(context: Context): String {
|
||||
return if (isLAndAbove()) {
|
||||
if (Preferences.getBoolean(context, Preferences.PREFERENCE_DOWNLOAD_EXTERNAL))
|
||||
if (context.isExternalStorageEnable())
|
||||
getExternalPath()
|
||||
else
|
||||
context.getInternalBaseDirectory() + "/Downloads"
|
||||
@@ -79,4 +79,8 @@ object PathUtil {
|
||||
val obbDir = getObbDownloadPath(context, app)
|
||||
return "$obbDir/${file.name}"
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isExternalStorageEnable(): Boolean {
|
||||
return Preferences.getBoolean(this, Preferences.PREFERENCE_DOWNLOAD_EXTERNAL)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ import com.aurora.store.R
|
||||
import com.aurora.store.data.downloader.DownloadManager
|
||||
import com.aurora.store.data.downloader.RequestBuilder
|
||||
import com.aurora.store.data.event.BusEvent
|
||||
import com.aurora.store.data.event.SessionEvent
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.data.installer.AppInstaller
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
@@ -114,7 +114,7 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
attachActions()
|
||||
}
|
||||
}
|
||||
is SessionEvent.Failed -> {
|
||||
is InstallerEvent.Failed -> {
|
||||
if (app.packageName == event.packageName) {
|
||||
InstallErrorDialogSheet.newInstance(
|
||||
app,
|
||||
|
||||
@@ -20,12 +20,44 @@
|
||||
package com.aurora.store.view.ui.preferences
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.Preferences
|
||||
|
||||
|
||||
class DownloadPreference : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.preferences_download, rootKey)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val downloadExternalPreference: SwitchPreferenceCompat? =
|
||||
findPreference(Preferences.PREFERENCE_DOWNLOAD_EXTERNAL)
|
||||
|
||||
val autoDeletePreference: SwitchPreferenceCompat? =
|
||||
findPreference(Preferences.PREFERENCE_AUTO_DELETE)
|
||||
|
||||
|
||||
downloadExternalPreference?.let { switchPreferenceCompat ->
|
||||
switchPreferenceCompat.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val checked = newValue.toString().toBoolean()
|
||||
autoDeletePreference?.let {
|
||||
if (checked) {
|
||||
it.isEnabled = true
|
||||
} else {
|
||||
it.isEnabled = false
|
||||
it.isChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user