Skip to content

Commit

Permalink
fix: 设置界面 超时单位错误
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Aug 27, 2023
1 parent 937ac4f commit 7c12ee3
Show file tree
Hide file tree
Showing 20 changed files with 620 additions and 49 deletions.
12 changes: 8 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("kotlin-kapt")
id("kotlin-parcelize")
id("com.google.devtools.ksp")
id("com.mikepenz.aboutlibraries.plugin")
}

static def buildTime() {
Expand Down Expand Up @@ -183,7 +184,7 @@ dependencies {
//noinspection GradleDependency
implementation 'com.google.android.material:material:1.9.0-beta01'

implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.2'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'

Expand All @@ -199,7 +200,7 @@ dependencies {

// RecyclerView
implementation 'com.github.liangjingkanji:BRV:1.4.3'
implementation "androidx.recyclerview:recyclerview:1.3.0"
implementation "androidx.recyclerview:recyclerview:1.3.1"
implementation 'me.zhanghai.android.fastscroll:library:1.2.0'

implementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'
Expand Down Expand Up @@ -230,8 +231,8 @@ dependencies {
implementation("com.hankcs:hanlp:portable-1.8.4")

// Media
implementation("androidx.media3:media3-exoplayer:1.1.0")
implementation("androidx.media3:media3-ui:1.1.0")
implementation("androidx.media3:media3-exoplayer:1.1.1")
implementation("androidx.media3:media3-ui:1.1.1")

// https://github.com/gyf-dev/ImmersionBar
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
Expand All @@ -240,6 +241,9 @@ dependencies {
// https://github.com/FunnySaltyFish/ComposeDataSaver
implementation "com.github.FunnySaltyFish.ComposeDataSaver:data-saver:v1.1.5"

implementation("com.mikepenz:aboutlibraries-core:${about_lib_version}")
implementation("com.mikepenz:aboutlibraries-compose:${about_lib_version}")

def accompanistVersion = "0.33.0-alpha"
implementation("com.google.accompanist:accompanist-systemuicontroller:${accompanistVersion}")
implementation("com.google.accompanist:accompanist-navigation-animation:${accompanistVersion}")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
<data android:pathPattern=".*\\.JS" />
</intent-filter>
</activity>

<activity android:name=".compose.LibrariesActivity" />
<activity
android:name=".compose.ComposeMainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.github.jing332.tts_server_android.compose

import android.content.Intent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.core.net.toUri
import com.github.jing332.tts_server_android.BuildConfig
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.widgets.AppDialog

@Composable
fun AboutDialog(onDismissRequest: () -> Unit) {
val context = LocalContext.current

AppDialog(
onDismissRequest = onDismissRequest,
title = {
Row {
Image(
painter = painterResource(id = R.mipmap.ic_launcher_round),
contentDescription = "Logo",
modifier = Modifier.align(Alignment.CenterVertically)
)
Text(
stringResource(id = R.string.app_name),
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(start = 8.dp)
)
}
},
content = {
fun openUrl(uri: String) {
context.startActivity(
Intent(Intent.ACTION_VIEW).apply {
data = uri.toUri()
}
)
}

Column {
SelectionContainer {
Column {
Text("APP - ${BuildConfig.VERSION_NAME}(${BuildConfig.VERSION_CODE})")
}
}
HorizontalDivider(Modifier.padding(vertical = 8.dp))
Text(
"Github - TTS Server",
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.Bold,
modifier = Modifier
.clickable {
openUrl("https://github.com/jing332/tts-server-android")
}
.padding(vertical = 8.dp)
.fillMaxWidth()
)
}
},
buttons = {
TextButton(onClick = {
onDismissRequest()
context.startActivity(
Intent(context, LibrariesActivity::class.java).setAction(Intent.ACTION_VIEW)
)
}) {
Text(text = stringResource(id = R.string.open_source_license))
}

TextButton(onClick = onDismissRequest) {
Text(stringResource(id = R.string.confirm))
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.github.jing332.tts_server_android.compose

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.widgets.AppDialog
import com.github.jing332.tts_server_android.compose.widgets.Markdown
import com.github.jing332.tts_server_android.utils.ClipboardUtils

@Preview
@Composable
private fun PreviewAppUpdateDialog() {
var show by remember { androidx.compose.runtime.mutableStateOf(true) }
if (show)
AppUpdateDialog(
onDismissRequest = {
show = false
}, version = "1.0.0", content = "## 更新内容\n\n- 123", downloadUrl = "url"
)

}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppUpdateDialog(
onDismissRequest: () -> Unit,
version: String,
content: String,
downloadUrl: String
) {
val context = LocalContext.current
fun openDownloadUrl(url: String) {
ClipboardUtils.copyText("TTS Server", url)
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}

AppDialog(onDismissRequest = onDismissRequest,
title = {
Text(
stringResource(id = R.string.check_update),
style = MaterialTheme.typography.titleLarge,
)
},
content = {
Column {
Text(
text = version,
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.align(Alignment.CenterHorizontally)
)

val scrollState = rememberScrollState()
Column(
Modifier
.padding(8.dp)
.verticalScroll(scrollState),
verticalArrangement = Arrangement.Center
) {
Markdown(
content = content,
modifier = Modifier
.padding(4.dp),
)

Spacer(modifier = Modifier.height(12.dp))

}
}
},
buttons = {
Row {
TextButton(onClick = { openDownloadUrl(downloadUrl) }) {
Text("下载(Github)")
}
TextButton(onClick = { openDownloadUrl("https://ghproxy.com/${downloadUrl}") }) {
Text("下载(ghproxy加速)")
}
}
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.jing332.tts_server_android.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import com.drake.net.utils.withIO
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.model.updater.AppUpdateChecker
import com.github.jing332.tts_server_android.model.updater.UpdateResult
import com.github.jing332.tts_server_android.utils.longToast

@Composable
internal fun AutoUpdateCheckerDialog(showUpdateToast: Boolean = true) {
val context = LocalContext.current
var showDialog by remember { mutableStateOf<UpdateResult?>(null) }
if (showDialog != null) {
val ret = showDialog!!
LaunchedEffect(ret) {
if (showUpdateToast && ret.hasUpdate())
context.longToast(R.string.new_version_available, ret.version)
}
AppUpdateDialog(
onDismissRequest = { showDialog = null },
version = ret.version,
content = ret.content,
downloadUrl = ret.downloadUrl,
)
}

LaunchedEffect(Unit) {
val result = try {
withIO { AppUpdateChecker.checkUpdate() }
} catch (e: Exception) {
context.longToast(context.getString(R.string.check_update_failed) + "\n$e")
null
}
if (result?.hasUpdate() == true) showDialog = result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowCircleUp
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
Expand All @@ -35,7 +36,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
Expand All @@ -47,6 +47,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -66,7 +67,6 @@ import androidx.navigation.Navigator
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.drake.net.utils.withIO
import com.github.jing332.tts_server_android.BuildConfig
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.nav.NavRoutes
Expand All @@ -76,11 +76,11 @@ import com.github.jing332.tts_server_android.compose.nav.settings.SettingsScreen
import com.github.jing332.tts_server_android.compose.nav.systts.SystemTtsScreen
import com.github.jing332.tts_server_android.compose.nav.systts.edit.TtsEditContainerScreen
import com.github.jing332.tts_server_android.compose.theme.AppTheme
import com.github.jing332.tts_server_android.conf.AppConfig
import com.github.jing332.tts_server_android.constant.AppConst
import com.github.jing332.tts_server_android.data.appDb
import com.github.jing332.tts_server_android.data.entities.systts.SystemTts
import com.github.jing332.tts_server_android.model.speech.tts.ITextToSpeechEngine
import com.github.jing332.tts_server_android.utils.MyTools
import com.github.jing332.tts_server_android.utils.clone
import com.github.jing332.tts_server_android.utils.longToast
import kotlinx.coroutines.launch
Expand All @@ -89,6 +89,7 @@ import java.util.Locale

val LocalNavController = compositionLocalOf<NavHostController> { error("No nav controller") }
val LocalDrawerState = compositionLocalOf<DrawerState> { error("No drawer state") }
val LocalTriggerAppUpdateChecker = staticCompositionLocalOf { mutableStateOf(false) }

fun Context.asAppCompatActivity(): AppCompatActivity {
return this as? AppCompatActivity ?: error("Context is not an AppCompatActivity")
Expand All @@ -100,6 +101,11 @@ class ComposeMainActivity : AppCompatActivity() {

setContent {
AppTheme {
if (LocalTriggerAppUpdateChecker.current.value || AppConfig.isAutoCheckUpdateEnabled.value){
AutoUpdateCheckerDialog(LocalTriggerAppUpdateChecker.current.value)
LocalTriggerAppUpdateChecker.current.value = false
}

NavHostScreen()
}
}
Expand Down Expand Up @@ -278,17 +284,29 @@ fun NavDrawerContent(
.padding(vertical = 16.dp, horizontal = 4.dp)
)

val triggerUpdate = LocalTriggerAppUpdateChecker.current
NavigationDrawerItem(
icon = { Icon(Icons.Default.ArrowCircleUp, null) },
label = { Text(stringResource(id = R.string.check_update)) },
selected = false,
onClick = {
scope.launch {
drawerState.close()
withIO { MyTools.checkUpdate(context, true) }
triggerUpdate.value = true
}
}
)

var showAboutDialog by remember { mutableStateOf(false) }
if (showAboutDialog)
AboutDialog { showAboutDialog = false }

NavigationDrawerItem(
icon = { Icon(Icons.Default.Info, null) },
label = { Text(stringResource(id = R.string.about)) },
selected = false,
onClick = { showAboutDialog = true }
)
}
}

Expand Down
Loading

0 comments on commit 7c12ee3

Please sign in to comment.