Skip to content

Commit d8a8d6d

Browse files
authored
Save to MediaStore/Downloads (#61)
* Save to MediaStore/Downloads - Patch 1 * Save to MediaStore/Downloads - Patch 2 * Save to MediaStore/Downloads - Patch 3 * Save to MediaStore/Downloads - Patch 4 * Save to MediaStore/Downloads - Patch 5
1 parent ea1f85f commit d8a8d6d

File tree

51 files changed

+591
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+591
-45
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<manifest xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
34

45
<uses-feature
56
android:name="android.hardware.camera"
@@ -10,6 +11,15 @@
1011
<uses-permission android:name="android.permission.INTERNET" />
1112
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1213

14+
<uses-permission
15+
android:name="android.permission.READ_EXTERNAL_STORAGE"
16+
android:maxSdkVersion="32" />
17+
18+
<uses-permission
19+
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
20+
android:maxSdkVersion="31"
21+
tools:ignore="ScopedStorage" />
22+
1323
<application
1424
android:name=".AiStableDiffusionClientApp"
1525
android:icon="@mipmap/ic_launcher"

app/src/main/java/com/shifthackz/aisdv1/app/AiStableDiffusionClientApp.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.shifthackz.aisdv1.app
22

33
import android.app.Application
4+
import android.os.StrictMode
5+
import android.os.StrictMode.VmPolicy
46
import com.shifthackz.aisdv1.app.di.featureModule
57
import com.shifthackz.aisdv1.app.di.preferenceModule
68
import com.shifthackz.aisdv1.app.di.providersModule
@@ -17,10 +19,12 @@ import org.koin.android.ext.koin.androidContext
1719
import org.koin.core.context.startKoin
1820
import timber.log.Timber
1921

22+
2023
class AiStableDiffusionClientApp : Application() {
2124

2225
override fun onCreate() {
2326
super.onCreate()
27+
StrictMode.setVmPolicy(VmPolicy.Builder().build())
2428
initializeKoin()
2529
initializeLogging()
2630
}

app/src/main/java/com/shifthackz/aisdv1/app/di/ProvidersModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import com.shifthackz.aisdv1.core.common.appbuild.BuildVersion
77
import com.shifthackz.aisdv1.core.common.file.FileProviderDescriptor
88
import com.shifthackz.aisdv1.core.common.links.LinksProvider
99
import com.shifthackz.aisdv1.core.common.schedulers.SchedulersProvider
10-
import com.shifthackz.aisdv1.domain.authorization.AuthorizationCredentials
11-
import com.shifthackz.aisdv1.domain.authorization.AuthorizationStore
10+
import com.shifthackz.aisdv1.domain.feature.auth.AuthorizationCredentials
11+
import com.shifthackz.aisdv1.domain.feature.auth.AuthorizationStore
1212
import com.shifthackz.aisdv1.domain.preference.PreferenceManager
1313
import com.shifthackz.aisdv1.network.qualifiers.ApiUrlProvider
1414
import com.shifthackz.aisdv1.network.qualifiers.CredentialsProvider

app/src/main/res/xml/file_provider_paths.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010

1111
<external-path name="media" path="." />
1212
<external-path name="external_files" path="."/>
13+
<external-path name="external" path="."/>
1314
</paths>

core/common/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ android {
1010
}
1111

1212
dependencies {
13+
implementation androidx.core
1314
implementation di.koinCore
1415
implementation reactive.rxjava
1516
implementation log.timber

core/ui/src/main/java/com/shifthackz/aisdv1/core/extensions/UriExtensions.kt renamed to core/common/src/main/java/com/shifthackz/aisdv1/core/common/extensions/UriExtensions.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
package com.shifthackz.aisdv1.core.extensions
1+
package com.shifthackz.aisdv1.core.common.extensions
22

33
import android.content.Context
44
import android.content.Intent
55
import android.net.Uri
6+
import android.os.Build
7+
import androidx.annotation.ChecksSdkIntAtLeast
68
import androidx.core.content.FileProvider
79
import java.io.File
810

911
private const val APP_MARKET_PACKAGE = "com.shifthackz.aisdv1.app"
1012

13+
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S_V2)
14+
fun shouldUseNewMediaStore(): Boolean {
15+
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2
16+
}
17+
1118
fun Context.uriFromFile(file: File, fileProviderPath: String): Uri {
1219
return FileProvider.getUriForFile(this, fileProviderPath, file)
1320
}

core/ui/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ android {
1616
}
1717

1818
dependencies {
19+
api project(":core:common")
1920
api platform(androidx.composeBom)
2021
api androidx.composeRuntime
2122
api androidx.composeMaterial3

core/ui/src/main/java/com/shifthackz/aisdv1/core/sharing/SharingExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.shifthackz.aisdv1.core.sharing
33
import android.content.Context
44
import android.content.Intent
55
import android.net.Uri
6-
import com.shifthackz.aisdv1.core.extensions.uriFromFile
6+
import com.shifthackz.aisdv1.core.common.extensions.uriFromFile
77
import java.io.File
88

99
fun Context.shareText(

data/data.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
implementation project(":network")
1818
implementation project(":storage")
1919
implementation di.koinCore
20+
implementation di.koinAndroid
2021
implementation reactive.rxkotlin
2122
implementation google.gson
2223
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package com.shifthackz.aisdv1.data.core
22

3+
import com.shifthackz.aisdv1.core.imageprocessing.Base64ToBitmapConverter
34
import com.shifthackz.aisdv1.domain.datasource.GenerationResultDataSource
45
import com.shifthackz.aisdv1.domain.entity.AiGenerationResult
6+
import com.shifthackz.aisdv1.domain.gateway.MediaStoreGateway
57
import com.shifthackz.aisdv1.domain.preference.PreferenceManager
68
import io.reactivex.rxjava3.core.Single
79

810
internal abstract class CoreGenerationRepository(
11+
mediaStoreGateway: MediaStoreGateway,
12+
base64ToBitmapConverter: Base64ToBitmapConverter,
913
private val localDataSource: GenerationResultDataSource.Local,
1014
private val preferenceManager: PreferenceManager,
11-
) {
15+
) : CoreMediaStoreRepository(preferenceManager, mediaStoreGateway, base64ToBitmapConverter) {
1216

1317
protected fun insertGenerationResult(ai: AiGenerationResult): Single<AiGenerationResult> {
1418
if (!preferenceManager.autoSaveAiResults) return Single.just(ai)
1519
return localDataSource
1620
.insert(ai)
17-
.map { id -> ai.copy(id) }
21+
.flatMap { id -> exportToMediaStore(ai).andThen(Single.just(ai.copy(id))) }
1822
}
1923
}

0 commit comments

Comments
 (0)