Skip to content

Commit

Permalink
Merge pull request #231 from KieronQuinn/release/2.3.3
Browse files Browse the repository at this point in the history
2.3.3
  • Loading branch information
KieronQuinn authored Feb 9, 2024
2 parents 52b6ec8 + 76956d1 commit 787a12d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ plugins {
apply plugin: 'com.google.android.gms.oss-licenses-plugin'

String DEFAULT_MANIFEST = "266:https://storage.googleapis.com/music-iq-db/updatable_ytm_db/20240128-030108/manifest.json"
String DEFAULT_MANIFEST_V3 = "3073:https://storage.googleapis.com/music-iq-db/updatable_db_v3/20240128-030108/manifest.json"
String DEFAULT_MANIFEST_V3 = "3074:https://storage.googleapis.com/music-iq-db/updatable_db_v3/20240204-030052/manifest.json"

def tagName = '2.3.2'
def version = 232
def tagName = '2.3.3'
def version = 233

def getKeystoreProperties() {
def properties = new Properties()
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 232,
"versionName": "2.3.2",
"versionCode": 233,
"versionName": "2.3.3",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,12 @@ class ShizukuService: IShellProxy.Stub() {
}
}

private fun grantRestrictedSettings() {
runCommand("cmd appops set ${BuildConfig.APPLICATION_ID} ACCESS_RESTRICTED_SETTINGS allow")
}

init {
grantRestrictedSettings()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.kieronquinn.app.ambientmusicmod.components.notifications.Notification
import com.kieronquinn.app.ambientmusicmod.components.notifications.NotificationId
import com.kieronquinn.app.ambientmusicmod.components.notifications.createNotification
import com.kieronquinn.app.ambientmusicmod.repositories.BackupRestoreRepository
import com.kieronquinn.app.ambientmusicmod.repositories.BackupRestoreRepository.BackupState
import com.kieronquinn.app.ambientmusicmod.repositories.SettingsRepository
import com.kieronquinn.app.ambientmusicmod.repositories.SettingsRepository.LastBackup
import com.kieronquinn.app.ambientmusicmod.repositories.SettingsRepository.PeriodicBackupInterval
Expand Down Expand Up @@ -136,7 +137,7 @@ class PeriodicBackupWorker(
if(!settingsRepository.periodicBackupEnabled.get()) return@launch
createBackup().collect {
when(it){
is BackupRestoreRepository.BackupState.BackupComplete -> {
is BackupState.BackupComplete -> {
if (it.result == BackupRestoreRepository.BackupResult.SUCCESS) {
notificationManager.cancel(NotificationId.BACKUP.ordinal)
deleteTempFileIfExists()
Expand All @@ -156,43 +157,41 @@ class PeriodicBackupWorker(
}

private fun createBackup() = flow {
val uri = getBackupUri()
val backupFolder = getBackupFolder() ?: run {
emit(BackupState.BackupComplete(BackupRestoreRepository.BackupResult.FAILED_TO_WRITE))
return@flow
}
backupFolder.renameExistingBackupIfExists()
val uri = backupFolder.createFile("application/ammbkp", PERIODIC_BACKUP_NAME)?.uri
if(uri != null) {
backupRepository.createBackup(uri).collect {
emit(it)
}
}else{
emit(BackupRestoreRepository.BackupState.BackupComplete(BackupRestoreRepository.BackupResult.FAILED_TO_WRITE))
emit(BackupState.BackupComplete(BackupRestoreRepository.BackupResult.FAILED_TO_WRITE))
}
}

private suspend fun getBackupFolder(): DocumentFile? {
val uri = settingsRepository.periodicBackupUri.get().takeIf { it.isNotBlank() }
?: return null
return try {
val folder = DocumentFile.fromTreeUri(context, Uri.parse(uri)) ?: return null
folder.createRenamingIfExists("application/ammbkp", PERIODIC_BACKUP_NAME)
DocumentFile.fromTreeUri(context, Uri.parse(uri))
}catch (e: Exception){
null
}
}

private suspend fun getBackupUri(): Uri? {
return getBackupFolder()?.uri
}

private fun DocumentFile.createRenamingIfExists(
mimeType: String, fileName: String
): DocumentFile? {
findFile(fileName)?.renameTo(PERIODIC_BACKUP_NAME_TMP)
return createFile(mimeType, fileName)
private fun DocumentFile.renameExistingBackupIfExists() {
findFile(PERIODIC_BACKUP_NAME)?.renameTo(PERIODIC_BACKUP_NAME_TMP)
}

private suspend fun deleteTempFileIfExists() {
getBackupFolder()?.findFile(PERIODIC_BACKUP_NAME)?.delete()
getBackupFolder()?.findFile(PERIODIC_BACKUP_NAME_TMP)?.delete()
}

private suspend fun restoreTempFileIfExists() {
getBackupFolder()?.findFile(PERIODIC_BACKUP_NAME)?.delete()
getBackupFolder()?.findFile(PERIODIC_BACKUP_NAME_TMP)?.renameTo(PERIODIC_BACKUP_NAME)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/appwidgetprovider_41.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="250dp"
android:minHeight="40dp"
android:widgetCategory="home_screen|keyguard"
android:previewImage="@drawable/widget_preview_4_1"
android:resizeMode="horizontal"
android:minResizeWidth="250dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/appwidgetprovider_42.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="250dp"
android:minHeight="110dp"
android:widgetCategory="home_screen|keyguard"
android:previewImage="@drawable/widget_preview_4_2"
android:resizeMode="horizontal"
android:minResizeWidth="250dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/appwidgetprovider_dynamic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:minHeight="40dp"
android:minResizeWidth="180dp"
android:minResizeHeight="40dp"
android:widgetCategory="home_screen|keyguard"
android:previewLayout="@layout/widget_preview"
android:resizeMode="horizontal|vertical"
android:targetCellWidth="4"
Expand Down

0 comments on commit 787a12d

Please sign in to comment.