Skip to content

Commit

Permalink
Merge pull request #43 from MateusRodCosta/dev
Browse files Browse the repository at this point in the history
Version 1.4.1
  • Loading branch information
MateusRodCosta authored Nov 28, 2024
2 parents a5c7b4b + 53599da commit 10428ec
Show file tree
Hide file tree
Showing 55 changed files with 469 additions and 163 deletions.
6 changes: 6 additions & 0 deletions .idea/copyright/AGPL.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.995.0)
aws-sdk-core (3.211.0)
aws-partitions (1.1014.0)
aws-sdk-core (3.214.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.95.0)
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.169.0)
aws-sdk-s3 (1.174.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -154,17 +154,17 @@ GEM
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.6.2)
json (2.7.4)
json (2.8.2)
jwt (2.9.3)
base64
mini_magick (4.13.2)
mini_mime (1.1.5)
multi_json (1.15.0)
multipart-post (2.4.1)
nanaimo (0.3.0)
nanaimo (0.4.0)
naturally (2.2.1)
nkf (0.2.0)
optparse (0.5.0)
optparse (0.6.0)
os (1.1.4)
plist (3.7.1)
public_suffix (6.0.1)
Expand Down Expand Up @@ -199,12 +199,12 @@ GEM
uber (0.1.0)
unicode-display_width (2.6.0)
word_wrap (1.0.0)
xcodeproj (1.25.1)
xcodeproj (1.27.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
minSdk = 26
//noinspection OldTargetApi
targetSdk = 34
versionCode = 25
versionName = "1.4.0"
versionCode = 26
versionName = "1.4.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,31 @@ import androidx.activity.enableEdgeToEdge
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.LaunchedEffect
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import com.mateusrodcosta.apps.share2storage.model.UriData
import com.mateusrodcosta.apps.share2storage.screens.DetailsScreen
import com.mateusrodcosta.apps.share2storage.screens.DetailsScreenSkipped
import com.mateusrodcosta.apps.share2storage.utils.CreateDocumentWithInitialUri
import com.mateusrodcosta.apps.share2storage.utils.SharedPreferenceKeys
import com.mateusrodcosta.apps.share2storage.utils.SharedPreferencesDefaultValues
import com.mateusrodcosta.apps.share2storage.utils.getUriData
import com.mateusrodcosta.apps.share2storage.utils.saveFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.time.DurationUnit
import kotlin.time.toDuration

class DetailsActivity : ComponentActivity() {
private lateinit var createFile: ActivityResultLauncher<String>
private var uriData: UriData? = null
private lateinit var fileUri: Uri
private lateinit var uriData: UriData

private var skipFileDetails: Boolean = false
private var defaultSaveLocation: Uri? = null
private var showFilePreview: Boolean = true
private var shouldSkipFilePicker: Boolean = false
private var skipFileDetails: Boolean = false
private var shouldShowFilePreview: Boolean = true

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -62,72 +65,103 @@ class DetailsActivity : ComponentActivity() {
getPreferences()
handleIntent(intent)
val launchFilePicker = {
createFile.launch(uriData?.displayName ?: "")
if (shouldSkipFilePicker) {
lifecycleScope.launch {
val dir = DocumentFile.fromTreeUri(applicationContext, defaultSaveLocation!!)
val file = dir!!.createFile(uriData.type, uriData.displayName)

if (file?.uri != null) handleFileSave(file.uri, fileUri)
}
} else {
createFile.launch(uriData.displayName)
}
Unit
}

setContent {
val windowSizeClass = calculateWindowSizeClass(this)

DetailsScreen(
uriData = uriData,
windowSizeClass = windowSizeClass,
launchFilePicker = launchFilePicker,
)
if (skipFileDetails) {
LaunchedEffect(key1 = Unit) {
launchFilePicker()
}
DetailsScreenSkipped()
} else {
DetailsScreen(
uriData = uriData,
windowSizeClass = windowSizeClass,
launchFilePicker = launchFilePicker,
)
}
}

if (skipFileDetails) launchFilePicker()
}

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

skipFileDetails =
sharedPreferences.getBoolean(SharedPreferenceKeys.SKIP_FILE_DETAILS_KEY, false)
Log.d("details] skipFileDetails", skipFileDetails.toString())

val defaultSaveLocationRaw =
sharedPreferences.getString(SharedPreferenceKeys.DEFAULT_SAVE_LOCATION_KEY, null)
Log.d("details] defaultSaveLocationRaw", defaultSaveLocationRaw.toString())
defaultSaveLocation = if (defaultSaveLocationRaw != null) Uri.parse(defaultSaveLocationRaw)
else null
val defaultSaveLocation =
if (defaultSaveLocationRaw != null) Uri.parse(defaultSaveLocationRaw)
else null
Log.d("details] defaultSaveLocation", defaultSaveLocation.toString())
this.defaultSaveLocation = defaultSaveLocation

val skipFilePicker = sharedPreferences.getBoolean(
SharedPreferenceKeys.SKIP_FILE_PICKER_KEY,
SharedPreferencesDefaultValues.SKIP_FILE_PICKER_DEFAULT
)
Log.d("details] skipFilePicker", skipFilePicker.toString())
// Only skip file picker if both a default folder is set and "Skip File Picker is selected"
this.shouldSkipFilePicker = defaultSaveLocation != null && skipFilePicker

showFilePreview =
sharedPreferences.getBoolean(SharedPreferenceKeys.SHOW_FILE_PREVIEW_KEY, true)

val skipFileDetails = sharedPreferences.getBoolean(
SharedPreferenceKeys.SKIP_FILE_DETAILS_KEY,
SharedPreferencesDefaultValues.SKIP_FILE_DETAILS_DEFAULT
)
Log.d("details] skipFileDetails", skipFileDetails.toString())
this.skipFileDetails = skipFileDetails

val showFilePreview = sharedPreferences.getBoolean(
SharedPreferenceKeys.SHOW_FILE_PREVIEW_KEY,
SharedPreferencesDefaultValues.SHOW_FILE_PREVIEW_DEFAULT
)
Log.d("details] showFilePreview", showFilePreview.toString())
this.shouldShowFilePreview = !skipFileDetails && showFilePreview
}

private fun handleIntent(intent: Intent?) {
var fileUri: Uri? = null
if (intent?.action == Intent.ACTION_SEND) {
fileUri =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) intent.getParcelableExtra(
Intent.EXTRA_STREAM, Uri::class.java
)
else @Suppress("DEPRECATION") intent.getParcelableExtra(Intent.EXTRA_STREAM)
Log.d("fileUri ACTION_SEND", fileUri.toString())
}
// ACTION_VIEW intents interceptor
if (intent?.action == Intent.ACTION_VIEW) {
fileUri = intent.data
Log.d("fileUri ACTION_VIEW", fileUri.toString())
}

if (fileUri != null) uriData =
getUriData(contentResolver, fileUri, getPreview = showFilePreview)
if (uriData != null) {
createFile = registerForActivityResult(
CreateDocumentWithInitialUri(uriData?.type ?: "*/*", defaultSaveLocation)
) { uri ->
val fileUri: Uri? = if (intent?.action == Intent.ACTION_SEND) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) intent.getParcelableExtra(
Intent.EXTRA_STREAM, Uri::class.java
)
else @Suppress("DEPRECATION") intent.getParcelableExtra(Intent.EXTRA_STREAM)
} else if (intent?.action == Intent.ACTION_VIEW) intent.data
else null
Log.d("fileUri", "Action: ${intent?.action}, uri: $fileUri")

if (fileUri == null) return
this.fileUri = fileUri
val uriData = getUriData(contentResolver, fileUri, getPreview = shouldShowFilePreview)
if (uriData == null) return
this.uriData = uriData

createFile = registerForActivityResult(
CreateDocumentWithInitialUri(uriData.type, defaultSaveLocation)
) { uri ->
if (uri == null) {
if (skipFileDetails) finish()
} else {
lifecycleScope.launch {
handleFileSave(uri, fileUri)
}
}
}
}

private suspend fun handleFileSave(uri: Uri?, fileUri: Uri?) {
if (uri == null || fileUri == null) return
private suspend fun handleFileSave(uri: Uri, fileUri: Uri) {
return withContext(Dispatchers.IO) {
val isSuccess = saveFile(baseContext, uri, fileUri)

Expand All @@ -141,11 +175,9 @@ class DetailsActivity : ComponentActivity() {
).show()
}

if (skipFileDetails) {
delay(1.toDuration(DurationUnit.SECONDS))
if (skipFileDetails || shouldSkipFilePicker) {
finish()
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class MainActivity : ComponentActivity() {
LaunchedEffect(key1 = Unit) {
if (isAppPreference) navController.navigate("settings")
}

AppNavigation(navController, settingsViewModel, windowSizeClass)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 - 2023 Mateus Rodrigues Costa
* Copyright (C) 2022 - 2024 Mateus Rodrigues Costa
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -25,7 +25,6 @@ class SampleUriDataProvider : PreviewParameterProvider<UriData?> {
"21. Setting Sail, Coming Home (End Theme).flac", "audio/flac", 35280673, null
),
UriData("03. Lonely Rolling Star (Missing You).flac", "audio/flac", 41123343, null),
UriData(null, null, null, null),
null,
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 - 2023 Mateus Rodrigues Costa
* Copyright (C) 2022 - 2024 Mateus Rodrigues Costa
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -20,8 +20,8 @@ package com.mateusrodcosta.apps.share2storage.model
import android.graphics.Bitmap

data class UriData(
val displayName: String?,
val type: String?,
val size: Long?,
val displayName: String,
val type: String,
val size: Long,
val previewImage: Bitmap?
)
Loading

0 comments on commit 10428ec

Please sign in to comment.