Skip to content

Commit 10428ec

Browse files
Merge pull request #43 from MateusRodCosta/dev
Version 1.4.1
2 parents a5c7b4b + 53599da commit 10428ec

File tree

55 files changed

+469
-163
lines changed

Some content is hidden

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

55 files changed

+469
-163
lines changed

.idea/copyright/AGPL.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gemfile.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ GEM
1010
artifactory (3.0.17)
1111
atomos (0.1.3)
1212
aws-eventstream (1.3.0)
13-
aws-partitions (1.995.0)
14-
aws-sdk-core (3.211.0)
13+
aws-partitions (1.1014.0)
14+
aws-sdk-core (3.214.0)
1515
aws-eventstream (~> 1, >= 1.3.0)
1616
aws-partitions (~> 1, >= 1.992.0)
1717
aws-sigv4 (~> 1.9)
1818
jmespath (~> 1, >= 1.6.1)
19-
aws-sdk-kms (1.95.0)
19+
aws-sdk-kms (1.96.0)
2020
aws-sdk-core (~> 3, >= 3.210.0)
2121
aws-sigv4 (~> 1.5)
22-
aws-sdk-s3 (1.169.0)
22+
aws-sdk-s3 (1.174.0)
2323
aws-sdk-core (~> 3, >= 3.210.0)
2424
aws-sdk-kms (~> 1)
2525
aws-sigv4 (~> 1.5)
@@ -154,17 +154,17 @@ GEM
154154
domain_name (~> 0.5)
155155
httpclient (2.8.3)
156156
jmespath (1.6.2)
157-
json (2.7.4)
157+
json (2.8.2)
158158
jwt (2.9.3)
159159
base64
160160
mini_magick (4.13.2)
161161
mini_mime (1.1.5)
162162
multi_json (1.15.0)
163163
multipart-post (2.4.1)
164-
nanaimo (0.3.0)
164+
nanaimo (0.4.0)
165165
naturally (2.2.1)
166166
nkf (0.2.0)
167-
optparse (0.5.0)
167+
optparse (0.6.0)
168168
os (1.1.4)
169169
plist (3.7.1)
170170
public_suffix (6.0.1)
@@ -199,12 +199,12 @@ GEM
199199
uber (0.1.0)
200200
unicode-display_width (2.6.0)
201201
word_wrap (1.0.0)
202-
xcodeproj (1.25.1)
202+
xcodeproj (1.27.0)
203203
CFPropertyList (>= 2.3.3, < 4.0)
204204
atomos (~> 0.1.3)
205205
claide (>= 1.0.2, < 2.0)
206206
colored2 (~> 3.1)
207-
nanaimo (~> 0.3.0)
207+
nanaimo (~> 0.4.0)
208208
rexml (>= 3.3.6, < 4.0)
209209
xcpretty (0.3.0)
210210
rouge (~> 2.0.7)

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
minSdk = 26
2626
//noinspection OldTargetApi
2727
targetSdk = 34
28-
versionCode = 25
29-
versionName = "1.4.0"
28+
versionCode = 26
29+
versionName = "1.4.1"
3030

3131
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3232
}

app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,31 @@ import androidx.activity.enableEdgeToEdge
3131
import androidx.activity.result.ActivityResultLauncher
3232
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
3333
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
34+
import androidx.compose.runtime.LaunchedEffect
35+
import androidx.documentfile.provider.DocumentFile
3436
import androidx.lifecycle.lifecycleScope
3537
import androidx.preference.PreferenceManager
3638
import com.mateusrodcosta.apps.share2storage.model.UriData
3739
import com.mateusrodcosta.apps.share2storage.screens.DetailsScreen
40+
import com.mateusrodcosta.apps.share2storage.screens.DetailsScreenSkipped
3841
import com.mateusrodcosta.apps.share2storage.utils.CreateDocumentWithInitialUri
3942
import com.mateusrodcosta.apps.share2storage.utils.SharedPreferenceKeys
43+
import com.mateusrodcosta.apps.share2storage.utils.SharedPreferencesDefaultValues
4044
import com.mateusrodcosta.apps.share2storage.utils.getUriData
4145
import com.mateusrodcosta.apps.share2storage.utils.saveFile
4246
import kotlinx.coroutines.Dispatchers
43-
import kotlinx.coroutines.delay
4447
import kotlinx.coroutines.launch
4548
import kotlinx.coroutines.withContext
46-
import kotlin.time.DurationUnit
47-
import kotlin.time.toDuration
4849

4950
class DetailsActivity : ComponentActivity() {
5051
private lateinit var createFile: ActivityResultLauncher<String>
51-
private var uriData: UriData? = null
52+
private lateinit var fileUri: Uri
53+
private lateinit var uriData: UriData
5254

53-
private var skipFileDetails: Boolean = false
5455
private var defaultSaveLocation: Uri? = null
55-
private var showFilePreview: Boolean = true
56+
private var shouldSkipFilePicker: Boolean = false
57+
private var skipFileDetails: Boolean = false
58+
private var shouldShowFilePreview: Boolean = true
5659

5760
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
5861
override fun onCreate(savedInstanceState: Bundle?) {
@@ -62,72 +65,103 @@ class DetailsActivity : ComponentActivity() {
6265
getPreferences()
6366
handleIntent(intent)
6467
val launchFilePicker = {
65-
createFile.launch(uriData?.displayName ?: "")
68+
if (shouldSkipFilePicker) {
69+
lifecycleScope.launch {
70+
val dir = DocumentFile.fromTreeUri(applicationContext, defaultSaveLocation!!)
71+
val file = dir!!.createFile(uriData.type, uriData.displayName)
72+
73+
if (file?.uri != null) handleFileSave(file.uri, fileUri)
74+
}
75+
} else {
76+
createFile.launch(uriData.displayName)
77+
}
78+
Unit
6679
}
6780

6881
setContent {
6982
val windowSizeClass = calculateWindowSizeClass(this)
7083

71-
DetailsScreen(
72-
uriData = uriData,
73-
windowSizeClass = windowSizeClass,
74-
launchFilePicker = launchFilePicker,
75-
)
84+
if (skipFileDetails) {
85+
LaunchedEffect(key1 = Unit) {
86+
launchFilePicker()
87+
}
88+
DetailsScreenSkipped()
89+
} else {
90+
DetailsScreen(
91+
uriData = uriData,
92+
windowSizeClass = windowSizeClass,
93+
launchFilePicker = launchFilePicker,
94+
)
95+
}
7696
}
77-
78-
if (skipFileDetails) launchFilePicker()
7997
}
8098

8199
private fun getPreferences() {
82100
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
83101

84-
skipFileDetails =
85-
sharedPreferences.getBoolean(SharedPreferenceKeys.SKIP_FILE_DETAILS_KEY, false)
86-
Log.d("details] skipFileDetails", skipFileDetails.toString())
87-
88102
val defaultSaveLocationRaw =
89103
sharedPreferences.getString(SharedPreferenceKeys.DEFAULT_SAVE_LOCATION_KEY, null)
90104
Log.d("details] defaultSaveLocationRaw", defaultSaveLocationRaw.toString())
91-
defaultSaveLocation = if (defaultSaveLocationRaw != null) Uri.parse(defaultSaveLocationRaw)
92-
else null
105+
val defaultSaveLocation =
106+
if (defaultSaveLocationRaw != null) Uri.parse(defaultSaveLocationRaw)
107+
else null
93108
Log.d("details] defaultSaveLocation", defaultSaveLocation.toString())
109+
this.defaultSaveLocation = defaultSaveLocation
110+
111+
val skipFilePicker = sharedPreferences.getBoolean(
112+
SharedPreferenceKeys.SKIP_FILE_PICKER_KEY,
113+
SharedPreferencesDefaultValues.SKIP_FILE_PICKER_DEFAULT
114+
)
115+
Log.d("details] skipFilePicker", skipFilePicker.toString())
116+
// Only skip file picker if both a default folder is set and "Skip File Picker is selected"
117+
this.shouldSkipFilePicker = defaultSaveLocation != null && skipFilePicker
94118

95-
showFilePreview =
96-
sharedPreferences.getBoolean(SharedPreferenceKeys.SHOW_FILE_PREVIEW_KEY, true)
119+
120+
val skipFileDetails = sharedPreferences.getBoolean(
121+
SharedPreferenceKeys.SKIP_FILE_DETAILS_KEY,
122+
SharedPreferencesDefaultValues.SKIP_FILE_DETAILS_DEFAULT
123+
)
124+
Log.d("details] skipFileDetails", skipFileDetails.toString())
125+
this.skipFileDetails = skipFileDetails
126+
127+
val showFilePreview = sharedPreferences.getBoolean(
128+
SharedPreferenceKeys.SHOW_FILE_PREVIEW_KEY,
129+
SharedPreferencesDefaultValues.SHOW_FILE_PREVIEW_DEFAULT
130+
)
97131
Log.d("details] showFilePreview", showFilePreview.toString())
132+
this.shouldShowFilePreview = !skipFileDetails && showFilePreview
98133
}
99134

100135
private fun handleIntent(intent: Intent?) {
101-
var fileUri: Uri? = null
102-
if (intent?.action == Intent.ACTION_SEND) {
103-
fileUri =
104-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) intent.getParcelableExtra(
105-
Intent.EXTRA_STREAM, Uri::class.java
106-
)
107-
else @Suppress("DEPRECATION") intent.getParcelableExtra(Intent.EXTRA_STREAM)
108-
Log.d("fileUri ACTION_SEND", fileUri.toString())
109-
}
110-
// ACTION_VIEW intents interceptor
111-
if (intent?.action == Intent.ACTION_VIEW) {
112-
fileUri = intent.data
113-
Log.d("fileUri ACTION_VIEW", fileUri.toString())
114-
}
115-
116-
if (fileUri != null) uriData =
117-
getUriData(contentResolver, fileUri, getPreview = showFilePreview)
118-
if (uriData != null) {
119-
createFile = registerForActivityResult(
120-
CreateDocumentWithInitialUri(uriData?.type ?: "*/*", defaultSaveLocation)
121-
) { uri ->
136+
val fileUri: Uri? = if (intent?.action == Intent.ACTION_SEND) {
137+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) intent.getParcelableExtra(
138+
Intent.EXTRA_STREAM, Uri::class.java
139+
)
140+
else @Suppress("DEPRECATION") intent.getParcelableExtra(Intent.EXTRA_STREAM)
141+
} else if (intent?.action == Intent.ACTION_VIEW) intent.data
142+
else null
143+
Log.d("fileUri", "Action: ${intent?.action}, uri: $fileUri")
144+
145+
if (fileUri == null) return
146+
this.fileUri = fileUri
147+
val uriData = getUriData(contentResolver, fileUri, getPreview = shouldShowFilePreview)
148+
if (uriData == null) return
149+
this.uriData = uriData
150+
151+
createFile = registerForActivityResult(
152+
CreateDocumentWithInitialUri(uriData.type, defaultSaveLocation)
153+
) { uri ->
154+
if (uri == null) {
155+
if (skipFileDetails) finish()
156+
} else {
122157
lifecycleScope.launch {
123158
handleFileSave(uri, fileUri)
124159
}
125160
}
126161
}
127162
}
128163

129-
private suspend fun handleFileSave(uri: Uri?, fileUri: Uri?) {
130-
if (uri == null || fileUri == null) return
164+
private suspend fun handleFileSave(uri: Uri, fileUri: Uri) {
131165
return withContext(Dispatchers.IO) {
132166
val isSuccess = saveFile(baseContext, uri, fileUri)
133167

@@ -141,11 +175,9 @@ class DetailsActivity : ComponentActivity() {
141175
).show()
142176
}
143177

144-
if (skipFileDetails) {
145-
delay(1.toDuration(DurationUnit.SECONDS))
178+
if (skipFileDetails || shouldSkipFilePicker) {
146179
finish()
147180
}
148181
}
149-
150182
}
151183
}

app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class MainActivity : ComponentActivity() {
6565
LaunchedEffect(key1 = Unit) {
6666
if (isAppPreference) navController.navigate("settings")
6767
}
68-
6968
AppNavigation(navController, settingsViewModel, windowSizeClass)
7069
}
7170
}

app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/model/SampleUriDataProvider.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 - 2023 Mateus Rodrigues Costa
2+
* Copyright (C) 2022 - 2024 Mateus Rodrigues Costa
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Affero General Public License as
@@ -25,7 +25,6 @@ class SampleUriDataProvider : PreviewParameterProvider<UriData?> {
2525
"21. Setting Sail, Coming Home (End Theme).flac", "audio/flac", 35280673, null
2626
),
2727
UriData("03. Lonely Rolling Star (Missing You).flac", "audio/flac", 41123343, null),
28-
UriData(null, null, null, null),
2928
null,
3029
)
3130
}

app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/model/UriData.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 - 2023 Mateus Rodrigues Costa
2+
* Copyright (C) 2022 - 2024 Mateus Rodrigues Costa
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Affero General Public License as
@@ -20,8 +20,8 @@ package com.mateusrodcosta.apps.share2storage.model
2020
import android.graphics.Bitmap
2121

2222
data class UriData(
23-
val displayName: String?,
24-
val type: String?,
25-
val size: Long?,
23+
val displayName: String,
24+
val type: String,
25+
val size: Long,
2626
val previewImage: Bitmap?
2727
)

0 commit comments

Comments
 (0)