-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
620 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/src/main/java/com/github/jing332/tts_server_android/compose/AboutDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
}) | ||
} |
103 changes: 103 additions & 0 deletions
103
app/src/main/java/com/github/jing332/tts_server_android/compose/AppUpdateDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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加速)") | ||
} | ||
} | ||
} | ||
) | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/github/jing332/tts_server_android/compose/AutoUpdateCheckerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.