Skip to content

Commit c0139cb

Browse files
authored
Merge pull request #8 from ezn24/codex/update-version-number-with-build-date-6pi8fv
Persist last output folder, clear default input, embed logs, black launcher foreground, and time-based versioning
2 parents c58adb3 + 89826fe commit c0139cb

3 files changed

Lines changed: 42 additions & 44 deletions

File tree

app/src/main/java/com/github/ezn24/TransYou/MainActivity.kt

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import androidx.compose.material3.SnackbarHostState
4444
import androidx.compose.material3.Surface
4545
import androidx.compose.material3.Switch
4646
import androidx.compose.material3.Text
47-
import androidx.compose.material3.TextButton
4847
import androidx.compose.material3.TopAppBar
4948
import androidx.compose.runtime.Composable
5049
import androidx.compose.runtime.getValue
@@ -60,7 +59,6 @@ import androidx.compose.ui.platform.LocalContext
6059
import androidx.compose.ui.res.stringResource
6160
import androidx.compose.ui.text.input.KeyboardType
6261
import androidx.compose.ui.unit.dp
63-
import androidx.compose.ui.window.Dialog
6462
import androidx.core.os.LocaleListCompat
6563
import androidx.datastore.preferences.core.Preferences
6664
import androidx.datastore.preferences.core.booleanPreferencesKey
@@ -180,7 +178,10 @@ private fun AppScaffold(settingsRepository: SettingsRepository) {
180178
.padding(padding),
181179
) {
182180
composable(Routes.Transcode.route) {
183-
TranscodeScreen(snackbarHostState = snackbarHostState)
181+
TranscodeScreen(
182+
snackbarHostState = snackbarHostState,
183+
settingsRepository = settingsRepository,
184+
)
184185
}
185186
composable(Routes.Settings.route) {
186187
SettingsScreen(settingsRepository = settingsRepository)
@@ -197,15 +198,16 @@ private enum class Routes(val route: String) {
197198
@Composable
198199
private fun TranscodeScreen(
199200
snackbarHostState: SnackbarHostState,
201+
settingsRepository: SettingsRepository,
200202
) {
201203
val context = LocalContext.current
202204
val coroutineScope = rememberCoroutineScope()
203205
val logEntries = remember { mutableStateListOf<String>() }
204206
var isTranscoding by rememberSaveable { mutableStateOf(false) }
205-
var showLogs by rememberSaveable { mutableStateOf(false) }
207+
val persistedOutputFolder by settingsRepository.lastOutputFolderFlow.collectAsStateWithLifecycle("")
206208

207-
var inputFile by rememberSaveable { mutableStateOf("/storage/emulated/0/Movies/input.mov") }
208-
var outputFolder by rememberSaveable { mutableStateOf("/storage/emulated/0/Movies") }
209+
var inputFile by rememberSaveable { mutableStateOf("") }
210+
var outputFolder by rememberSaveable(persistedOutputFolder) { mutableStateOf(persistedOutputFolder) }
209211
var outputNamePattern by rememberSaveable { mutableStateOf(OutputNamePattern.DATE_ONLY) }
210212
var customNameTemplate by rememberSaveable { mutableStateOf("{input_file_name}.convert.{input_format}.to.{output_format}") }
211213
var customDateFormat by rememberSaveable { mutableStateOf("yyyyMMdd") }
@@ -238,6 +240,7 @@ private fun TranscodeScreen(
238240
onResult = { uri ->
239241
if (uri != null) {
240242
outputFolder = uri.toString()
243+
coroutineScope.launch { settingsRepository.setLastOutputFolder(outputFolder) }
241244
}
242245
},
243246
)
@@ -326,7 +329,10 @@ private fun TranscodeScreen(
326329
SectionCard(title = stringResource(id = R.string.section_output)) {
327330
OutlinedTextField(
328331
value = outputFolder,
329-
onValueChange = { outputFolder = it },
332+
onValueChange = {
333+
outputFolder = it
334+
coroutineScope.launch { settingsRepository.setLastOutputFolder(it) }
335+
},
330336
label = { Text(stringResource(id = R.string.output_folder)) },
331337
modifier = Modifier.fillMaxWidth(),
332338
)
@@ -490,17 +496,20 @@ private fun TranscodeScreen(
490496
}
491497
}
492498

493-
SectionCard(title = stringResource(id = R.string.section_command)) {
494-
TextButton(onClick = { showLogs = true }) {
495-
Text(text = stringResource(id = R.string.view_logs))
496-
}
497-
Spacer(modifier = Modifier.height(12.dp))
498-
if (logEntries.isEmpty()) {
499-
Text(text = stringResource(id = R.string.log_empty))
500-
} else {
501-
logEntries.takeLast(8).forEach { entry ->
502-
Text(text = entry)
503-
}
499+
Card(modifier = Modifier.fillMaxWidth()) {
500+
Column(modifier = Modifier.padding(16.dp)) {
501+
OutlinedTextField(
502+
value = if (logEntries.isEmpty()) {
503+
stringResource(id = R.string.log_empty)
504+
} else {
505+
logEntries.takeLast(8).joinToString(separator = "\n")
506+
},
507+
onValueChange = {},
508+
label = { Text(text = stringResource(id = R.string.log_title)) },
509+
modifier = Modifier.fillMaxWidth(),
510+
readOnly = true,
511+
minLines = 6,
512+
)
504513
}
505514
}
506515

@@ -586,30 +595,7 @@ private fun TranscodeScreen(
586595
}
587596
}
588597

589-
if (showLogs) {
590-
Dialog(onDismissRequest = { showLogs = false }) {
591-
Card(modifier = Modifier.fillMaxWidth()) {
592-
Column(modifier = Modifier.padding(16.dp)) {
593-
Text(
594-
text = stringResource(id = R.string.log_title),
595-
style = MaterialTheme.typography.titleMedium,
596-
)
597-
Spacer(modifier = Modifier.height(12.dp))
598-
if (logEntries.isEmpty()) {
599-
Text(text = stringResource(id = R.string.log_empty))
600-
} else {
601-
logEntries.forEach { entry ->
602-
Text(text = entry)
603-
}
604-
}
605-
Spacer(modifier = Modifier.height(12.dp))
606-
FilledTonalButton(onClick = { showLogs = false }) {
607-
Text(text = stringResource(id = R.string.close))
608-
}
609-
}
610-
}
611-
}
612-
}
598+
613599
}
614600

615601
@Composable
@@ -756,6 +742,7 @@ private class SettingsRepository(private val context: Context) {
756742
private val themeKey = stringPreferencesKey("theme_mode")
757743
private val pureBlackKey = booleanPreferencesKey("pure_black")
758744
private val languageKey = stringPreferencesKey("language")
745+
private val lastOutputFolderKey = stringPreferencesKey("last_output_folder")
759746

760747
val themeModeFlow: Flow<ThemeMode> = context.dataStore.data.map { prefs ->
761748
val value = prefs[themeKey]
@@ -771,6 +758,10 @@ private class SettingsRepository(private val context: Context) {
771758
AppLanguage.entries.firstOrNull { it.name == value } ?: AppLanguage.SYSTEM
772759
}
773760

761+
val lastOutputFolderFlow: Flow<String> = context.dataStore.data.map { prefs ->
762+
prefs[lastOutputFolderKey] ?: ""
763+
}
764+
774765
suspend fun setThemeMode(mode: ThemeMode) {
775766
updatePreference(themeKey, mode.name)
776767
}
@@ -783,6 +774,10 @@ private class SettingsRepository(private val context: Context) {
783774
updatePreference(languageKey, language.name)
784775
}
785776

777+
suspend fun setLastOutputFolder(path: String) {
778+
updatePreference(lastOutputFolderKey, path)
779+
}
780+
786781
private suspend fun <T> updatePreference(key: Preferences.Key<T>, value: T) {
787782
context.dataStore.edit { prefs ->
788783
prefs[key] = value

app/src/main/res/drawable/ic_launcher_foreground.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
android:viewportWidth="108"
55
android:viewportHeight="108">
66
<path
7-
android:fillColor="#1B1B1B"
7+
android:fillColor="#000000"
88
android:pathData="M37,44h34a3,3 0 0 1 3,3v0a3,3 0 0 1 -3,3h-34a3,3 0 0 1 -3,-3v0a3,3 0 0 1 3,-3z" />
99
<path
10-
android:fillColor="#1B1B1B"
10+
android:fillColor="#000000"
1111
android:pathData="M37,58h34a3,3 0 0 1 3,3v0a3,3 0 0 1 -3,3h-34a3,3 0 0 1 -3,-3v0a3,3 0 0 1 3,-3z" />
1212
</vector>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<color name="ic_launcher_background">@android:color/system_accent1_200</color>
3+
</resources>

0 commit comments

Comments
 (0)