Add ktlint, reformat files

This commit is contained in:
Syer10
2021-04-26 20:16:35 -04:00
parent 3a83037104
commit 91c93b5982
83 changed files with 320 additions and 278 deletions

View File

@@ -27,5 +27,4 @@ object AppScope : Scope by KTP.openRootScope() {
inline fun <reified T> getInstance(): T {
return getInstance(T::class.java)
}
}
}

View File

@@ -14,4 +14,4 @@ class GenericsProvider<T>(private val cls: Class<T>, val scope: Scope = AppScope
override fun get(): T {
return scope.getInstance(cls)
}
}
}

View File

@@ -13,4 +13,4 @@ import toothpick.config.Module
*/
inline fun <reified B> Module.bindInstance(instance: B) {
bind(B::class.java).toInstance(instance)
}
}

View File

@@ -50,5 +50,4 @@ class DataUriStringSource(private val data: String) : Source {
override fun close() {
}
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.common.io
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okio.BufferedSink
@@ -29,4 +28,4 @@ suspend fun Source.copyTo(sink: BufferedSink) {
sink.use { it.writeAll(source) }
}
}
}
}

View File

@@ -80,4 +80,4 @@ class LazyPreferenceStore(
): Preference<T> {
return lazyStore.value.getJsonObject(key, defaultValue, serializer)
}
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.common.prefs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
@@ -57,5 +56,4 @@ interface Preference<T> {
* current value and receive preference updates.
*/
fun stateIn(scope: CoroutineScope): StateFlow<T>
}
}

View File

@@ -57,7 +57,6 @@ interface PreferenceStore {
deserializer: (String) -> T
): Preference<T>
/**
* Returns preference of type [T] for this [key]. The [serializer] must be provided.
*/
@@ -67,7 +66,6 @@ interface PreferenceStore {
serializer: KSerializer<T>,
serializersModule: SerializersModule = EmptySerializersModule
): Preference<T>
}
/**
@@ -77,11 +75,16 @@ inline fun <reified T : Enum<T>> PreferenceStore.getEnum(
key: String,
defaultValue: T
): Preference<T> {
return getObject(key, defaultValue, { it.name }, {
try {
enumValueOf(it)
} catch (e: IllegalArgumentException) {
defaultValue
return getObject(
key,
defaultValue,
{ it.name },
{
try {
enumValueOf(it)
} catch (e: IllegalArgumentException) {
defaultValue
}
}
})
)
}

View File

@@ -11,4 +11,4 @@ import okio.ByteString.Companion.encode
fun String.decodeBase64() = decodeBase64()!!
fun String.md5() = encode().md5().hex()
fun String.md5() = encode().md5().hex()

View File

@@ -41,4 +41,4 @@ inline fun <T> MutableCollection<T>.removeFirst(predicate: (T) -> Boolean): T? {
}
}
return null
}
}

View File

@@ -40,4 +40,4 @@ object ImageUtil {
GIF("image/gif", "gif"),
WEBP("image/webp", "webp")
}
}
}

View File

@@ -95,5 +95,4 @@ internal class JvmPreference<T>(
override fun stateIn(scope: CoroutineScope): StateFlow<T> {
return changes().stateIn(scope, SharingStarted.Eagerly, get())
}
}
}

View File

@@ -87,7 +87,6 @@ internal class ObjectAdapter<T>(
override fun set(key: String, value: T, editor: ObservableSettings) {
editor.putString(key, serializer(value))
}
}
internal class JsonObjectAdapter<T>(
@@ -103,5 +102,4 @@ internal class JsonObjectAdapter<T>(
override fun set(key: String, value: T, editor: ObservableSettings) {
editor.encodeValue(serializer, key, value, serializersModule)
}
}
}

View File

@@ -82,5 +82,4 @@ class JvmPreferenceStore(private val preferences: ObservableSettings) : Preferen
val adapter = JsonObjectAdapter(defaultValue, serializer, serializersModule)
return JvmPreference(preferences, key, defaultValue, adapter)
}
}
}

View File

@@ -13,12 +13,12 @@ import java.util.prefs.Preferences
class PreferenceStoreFactory {
fun create(name: String? = null): PreferenceStore {
val userPreferences: Preferences = Preferences.userRoot()
val jvmPreferences = if (!name.isNullOrBlank()) {
JvmPreferencesSettings(Preferences.userRoot().node(name))
JvmPreferencesSettings(userPreferences.node(name))
} else {
JvmPreferencesSettings(Preferences.userRoot())
JvmPreferencesSettings(userPreferences)
}
return JvmPreferenceStore(jvmPreferences)
}
}
}

View File

@@ -13,4 +13,4 @@ class CatalogPreferences(private val preferenceStore: PreferenceStore) {
fun languages(): Preference<Set<String>> {
return preferenceStore.getStringSet("enabled_langs", setOf("en"))
}
}
}

View File

@@ -13,4 +13,4 @@ class ExtensionPreferences(private val preferenceStore: PreferenceStore) {
fun languages(): Preference<Set<String>> {
return preferenceStore.getStringSet("enabled_langs", setOf("all", "en"))
}
}
}

View File

@@ -19,4 +19,4 @@ class LibraryPreferences(private val preferenceStore: PreferenceStore) {
fun showAllCategory(): Preference<Boolean> {
return preferenceStore.getBoolean("show_all_category", false)
}
}
}

View File

@@ -17,4 +17,4 @@ enum class DisplayMode {
companion object {
val values = values()
}
}
}

View File

@@ -14,4 +14,4 @@ data class Category(
val order: Int,
val name: String,
val landing: Boolean
)
)

View File

@@ -25,4 +25,4 @@ data class Manga(
val source: Source?
) {
fun cover(serverUrl: String) = thumbnailUrl?.let { serverUrl + it }
}
}

View File

@@ -28,4 +28,4 @@ internal class HttpProvider @Inject constructor() : Provider<Http> {
}
}
}
}
}

View File

@@ -18,4 +18,4 @@ class ServerPreferences(private val preferenceStore: PreferenceStore) {
fun server(): Preference<String> {
return preferenceStore.getString("server_url", "http://localhost:4567")
}
}
}

View File

@@ -45,7 +45,7 @@ class ServerService @Inject constructor(
val logger = KotlinLogging.logger("Server")
val runtime = Runtime.getRuntime()
val jarFile = File(userDataDir,"Tachidesk.jar")
val jarFile = File(userDataDir, "Tachidesk.jar")
if (!jarFile.exists()) {
logger.info { "Copying server to resources" }
javaClass.getResourceAsStream("/Tachidesk.jar")?.buffered()?.use { input ->
@@ -59,7 +59,7 @@ class ServerService @Inject constructor(
val javaExeFile = File(javaLibraryPath, "java.exe")
val javaUnixFile = File(javaLibraryPath, "java")
val javaExePath = when {
javaExeFile.exists() ->'"' + javaExeFile.absolutePath + '"'
javaExeFile.exists() -> '"' + javaExeFile.absolutePath + '"'
javaUnixFile.exists() -> '"' + javaUnixFile.absolutePath + '"'
else -> "java"
}
@@ -69,9 +69,11 @@ class ServerService @Inject constructor(
process = runtime.exec("""$javaExePath -jar "${jarFile.absolutePath}"""").also {
reader = it.inputStream.bufferedReader()
}
runtime.addShutdownHook(thread(start = false) {
process?.destroy()
})
runtime.addShutdownHook(
thread(start = false) {
process?.destroy()
}
)
logger.info { "Server started successfully" }
var line: String?
while (reader.readLine().also { line = it } != null) {
@@ -87,7 +89,6 @@ class ServerService @Inject constructor(
logger.info { "Server closed" }
val exitVal = process?.waitFor()
logger.info { "Process exitValue: $exitVal" }
}
}.launchIn(GlobalScope)
}
@@ -98,4 +99,4 @@ class ServerService @Inject constructor(
STARTED,
FAILED;
}
}
}

View File

@@ -131,4 +131,4 @@ open class BaseInteractionHandler(
} while (attempt <= 3)
throw lastException
}
}
}

View File

@@ -29,7 +29,7 @@ import javax.inject.Inject
class CategoryInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
): BaseInteractionHandler(client, serverPreferences) {
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun getMangaCategories(mangaId: Long) = withContext(Dispatchers.IO) {
client.getRepeat<List<Category>>(
@@ -75,13 +75,13 @@ class CategoryInteractionHandler @Inject constructor(
suspend fun modifyCategory(categoryId: Long, name: String? = null, isLanding: Boolean? = null) = withContext(Dispatchers.IO) {
client.submitFormRepeat<HttpResponse>(
serverUrl + categoryModifyRequest(categoryId),
formParameters = Parameters.build {
if (name != null) {
append("name", name)
}
if (isLanding != null) {
append("isLanding", isLanding.toString())
}
formParameters = Parameters.build {
if (name != null) {
append("name", name)
}
if (isLanding != null) {
append("isLanding", isLanding.toString())
}
}
) {
method = HttpMethod.Patch
@@ -115,4 +115,4 @@ class CategoryInteractionHandler @Inject constructor(
)
}
suspend fun getMangaFromCategory(category: Category) = getMangaFromCategory(category.id)
}
}

View File

@@ -20,7 +20,7 @@ import javax.inject.Inject
class ChapterInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
): BaseInteractionHandler(client, serverPreferences) {
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun getChapters(mangaId: Long) = withContext(Dispatchers.IO) {
client.getRepeat<List<Chapter>>(
@@ -58,4 +58,4 @@ class ChapterInteractionHandler @Inject constructor(
suspend fun getPage(manga: Manga, chapterId: Long, pageNum: Int) = getPage(manga.id, chapterId, pageNum)
suspend fun getPage(manga: Manga, chapter: Chapter, pageNum: Int) = getPage(manga.id, chapter.id, pageNum)
}
}

View File

@@ -21,7 +21,7 @@ import javax.inject.Inject
class ExtensionInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
): BaseInteractionHandler(client, serverPreferences) {
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun getExtensionList() = withContext(Dispatchers.IO) {
client.getRepeat<List<Extension>>(
@@ -47,4 +47,4 @@ class ExtensionInteractionHandler @Inject constructor(
serverUrl + apkIconQuery(extension.apkName)
)
}
}
}

View File

@@ -20,7 +20,7 @@ import javax.inject.Inject
class LibraryInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
): BaseInteractionHandler(client, serverPreferences) {
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun getLibraryManga() = withContext(Dispatchers.IO) {
client.getRepeat<List<Manga>>(
@@ -43,4 +43,4 @@ class LibraryInteractionHandler @Inject constructor(
}
suspend fun removeMangaFromLibrary(manga: Manga) = removeMangaFromLibrary(manga.id)
}
}

View File

@@ -18,7 +18,7 @@ import javax.inject.Inject
class MangaInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
): BaseInteractionHandler(client, serverPreferences) {
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun getManga(mangaId: Long) = withContext(Dispatchers.IO) {
client.getRepeat<Manga>(
@@ -32,5 +32,4 @@ class MangaInteractionHandler @Inject constructor(
serverUrl + mangaThumbnailQuery(mangaId)
)
}
}
}

View File

@@ -25,7 +25,7 @@ import javax.inject.Inject
class SourceInteractionHandler @Inject constructor(
client: Http,
serverPreferences: ServerPreferences
): BaseInteractionHandler(client, serverPreferences) {
) : BaseInteractionHandler(client, serverPreferences) {
suspend fun getSourceList() = withContext(Dispatchers.IO) {
client.getRepeat<List<Source>>(
@@ -48,7 +48,8 @@ class SourceInteractionHandler @Inject constructor(
}
suspend fun getPopularManga(source: Source, pageNum: Int) = getPopularManga(
source.id, pageNum
source.id,
pageNum
)
suspend fun getLatestManga(sourceId: Long, pageNum: Int) = withContext(Dispatchers.IO) {
@@ -58,7 +59,8 @@ class SourceInteractionHandler @Inject constructor(
}
suspend fun getLatestManga(source: Source, pageNum: Int) = getLatestManga(
source.id, pageNum
source.id,
pageNum
)
// TODO: 2021-03-14
@@ -75,7 +77,9 @@ class SourceInteractionHandler @Inject constructor(
}
suspend fun getSearchResults(source: Source, searchTerm: String, pageNum: Int) = getSearchResults(
source.id, searchTerm, pageNum
source.id,
searchTerm,
pageNum
)
// TODO: 2021-03-14
@@ -86,4 +90,4 @@ class SourceInteractionHandler @Inject constructor(
}
suspend fun getFilterList(source: Source) = getFilterList(source.id)
}
}

View File

@@ -43,4 +43,4 @@ fun categoryDeleteRequest(categoryId: Long) =
@Get
fun getMangaInCategoryQuery(categoryId: Long) =
"/api/v1/category/$categoryId"
"/api/v1/category/$categoryId"

View File

@@ -16,4 +16,4 @@ fun getChapterQuery(mangaId: Long, chapterId: Long) =
@Get
fun getPageQuery(mangaId: Long, chapterId: Long, index: Int) =
"/api/v1/manga/$mangaId/chapter/$chapterId/page/$index"
"/api/v1/manga/$mangaId/chapter/$chapterId/page/$index"

View File

@@ -20,4 +20,4 @@ fun apkUninstallQuery(apkName: String) =
@Get
fun apkIconQuery(apkName: String) =
"/api/v1/extension/icon/$apkName"
"/api/v1/extension/icon/$apkName"

View File

@@ -16,4 +16,4 @@ fun removeMangaFromLibraryRequest(mangaId: Long) =
@Get
fun getLibraryQuery() =
"/api/v1/library/"
"/api/v1/library/"

View File

@@ -12,4 +12,4 @@ annotation class Post
annotation class Delete
annotation class Patch
annotation class Patch

View File

@@ -32,4 +32,4 @@ fun sourceSearchQuery(sourceId: Long, searchTerm: String, pageNum: Int) =
@Get
fun getFilterListQuery(sourceId: Long) =
"/api/v1/source/$sourceId/filters/"
"/api/v1/source/$sourceId/filters/"

View File

@@ -56,5 +56,4 @@ class UiPreferences(private val preferenceStore: PreferenceStore) {
fun dateFormat(): Preference<String> {
return preferenceStore.getString("date_format", "")
}
}
}

View File

@@ -12,9 +12,10 @@ import kotlinx.serialization.Serializable
@Serializable
enum class StartScreen {
Library,
Library,
// Updates,
// History,
Sources,
Extensions
Sources,
Extensions
}

View File

@@ -13,4 +13,4 @@ enum class ThemeMode {
/*System,*/
Light,
Dark,
}
}

View File

@@ -128,4 +128,4 @@ fun WindowDialog(
}
}
}
}
}

View File

@@ -99,16 +99,20 @@ fun ColorPickerDialog(
val showPresetsState by showPresets.collectAsState()
val currentColorState by currentColor.collectAsState()
Row(Modifier.fillMaxWidth().padding(8.dp)) {
TextButton(onClick = {
showPresets.value = !showPresetsState
}) {
TextButton(
onClick = {
showPresets.value = !showPresetsState
}
) {
Text(if (showPresetsState) "Custom" else "Presets")
}
Spacer(Modifier.weight(1f))
TextButton(onClick = {
onSelected(currentColorState)
it.close()
}) {
TextButton(
onClick = {
onSelected(currentColorState)
it.close()
}
) {
Text("Select")
}
}
@@ -181,7 +185,8 @@ private fun ColorPresetItem(
onClick: () -> Unit
) {
Box(
contentAlignment = Alignment.Center, modifier = Modifier
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.padding(4.dp)
.size(48.dp)
@@ -241,13 +246,15 @@ fun ColorPalette(
val saturationGradient = remember(hue, matrixSize) {
Brush.linearGradient(
colors = listOf(Color.White, hueToColor(hue)),
start = Offset(0f, 0f), end = Offset(matrixSize.width.toFloat(), 0f)
start = Offset(0f, 0f),
end = Offset(matrixSize.width.toFloat(), 0f)
)
}
val valueGradient = remember(matrixSize) {
Brush.linearGradient(
colors = listOf(Color.White, Color.Black),
start = Offset(0f, 0f), end = Offset(0f, matrixSize.height.toFloat())
start = Offset(0f, 0f),
end = Offset(0f, matrixSize.height.toFloat())
)
}
@@ -270,80 +277,82 @@ fun ColorPalette(
Column {
Text("") // TODO workaround: without this text, the color picker doesn't render correctly
Row(Modifier.height(IntrinsicSize.Max)) {
Box(Modifier
.aspectRatio(1f)
.weight(1f)
.onSizeChanged {
matrixSize = it
val hsv = selectedColor.toHsv()
matrixCursor = satValToCoordinates(hsv[1], hsv[2], it)
hueCursor = hueToCoordinate(hue, it)
}
.drawWithContent {
drawRect(brush = valueGradient)
drawRect(brush = saturationGradient, blendMode = BlendMode.Multiply)
drawRect(Color.LightGray, size = size, style = borderStroke)
drawCircle(
Color.Black,
radius = 8f,
center = matrixCursor,
style = cursorStroke
)
drawCircle(
Color.LightGray,
radius = 12f,
center = matrixCursor,
style = cursorStroke
)
}
.pointerInput(Unit) {
detectMove { offset ->
val safeOffset = offset.copy(
x = offset.x.coerceIn(0f, matrixSize.width.toFloat()),
y = offset.y.coerceIn(0f, matrixSize.height.toFloat())
)
matrixCursor = safeOffset
val newColor = matrixCoordinatesToColor(hue, safeOffset, matrixSize)
setSelectedColor(newColor)
Box(
Modifier
.aspectRatio(1f)
.weight(1f)
.onSizeChanged {
matrixSize = it
val hsv = selectedColor.toHsv()
matrixCursor = satValToCoordinates(hsv[1], hsv[2], it)
hueCursor = hueToCoordinate(hue, it)
}
}
)
Box(Modifier
.fillMaxHeight()
.requiredWidth(48.dp)
.padding(start = 8.dp)
.drawWithCache {
var h = 360f
val colors = MutableList(size.height.toInt()) {
hueToColor(h).also {
h -= 360f / size.height
}
}
val cursorSize = Size(size.width, 10f)
val cursorTopLeft = Offset(0f, hueCursor - (cursorSize.height / 2))
onDrawBehind {
colors.forEachIndexed { i, color ->
val pos = i.toFloat()
drawLine(color, Offset(0f, pos), Offset(size.width, pos))
}
.drawWithContent {
drawRect(brush = valueGradient)
drawRect(brush = saturationGradient, blendMode = BlendMode.Multiply)
drawRect(Color.LightGray, size = size, style = borderStroke)
drawRect(
cursorColor,
topLeft = cursorTopLeft,
size = cursorSize,
drawCircle(
Color.Black,
radius = 8f,
center = matrixCursor,
style = cursorStroke
)
drawCircle(
Color.LightGray,
radius = 12f,
center = matrixCursor,
style = cursorStroke
)
}
}
.pointerInput(Unit) {
detectMove { offset ->
val safeY = offset.y.coerceIn(0f, matrixSize.height.toFloat())
hueCursor = safeY
hue = hueCoordinatesToHue(safeY, matrixSize)
val newColor = matrixCoordinatesToColor(hue, matrixCursor, matrixSize)
setSelectedColor(newColor)
.pointerInput(Unit) {
detectMove { offset ->
val safeOffset = offset.copy(
x = offset.x.coerceIn(0f, matrixSize.width.toFloat()),
y = offset.y.coerceIn(0f, matrixSize.height.toFloat())
)
matrixCursor = safeOffset
val newColor = matrixCoordinatesToColor(hue, safeOffset, matrixSize)
setSelectedColor(newColor)
}
}
)
Box(
Modifier
.fillMaxHeight()
.requiredWidth(48.dp)
.padding(start = 8.dp)
.drawWithCache {
var h = 360f
val colors = MutableList(size.height.toInt()) {
hueToColor(h).also {
h -= 360f / size.height
}
}
val cursorSize = Size(size.width, 10f)
val cursorTopLeft = Offset(0f, hueCursor - (cursorSize.height / 2))
onDrawBehind {
colors.forEachIndexed { i, color ->
val pos = i.toFloat()
drawLine(color, Offset(0f, pos), Offset(size.width, pos))
}
drawRect(Color.LightGray, size = size, style = borderStroke)
drawRect(
cursorColor,
topLeft = cursorTopLeft,
size = cursorSize,
style = cursorStroke
)
}
}
.pointerInput(Unit) {
detectMove { offset ->
val safeY = offset.y.coerceIn(0f, matrixSize.height.toFloat())
hueCursor = safeY
hue = hueCoordinatesToHue(safeY, matrixSize)
val newColor = matrixCoordinatesToColor(hue, matrixCursor, matrixSize)
setSelectedColor(newColor)
}
}
}
)
}
Row(Modifier.padding(top = 8.dp), verticalAlignment = Alignment.Bottom) {
@@ -451,4 +460,3 @@ private val presetColors = listOf(
Color(0xFF607D8B), // BLUE GREY 500
Color(0xFF9E9E9E), // GREY 500
)

View File

@@ -51,4 +51,4 @@ private val ERROR_FACES = arrayOf(
fun getRandomErrorFace(): String {
return ERROR_FACES[Random.nextInt(ERROR_FACES.size)]
}
}

View File

@@ -94,4 +94,4 @@ private suspend fun getImage(client: Http, imageUrl: String, retries: Int = 3):
attempt++
} while (attempt <= retries)
throw lastException
}
}

View File

@@ -35,4 +35,4 @@ fun LoadingScreen(
}
}
}
}
}

View File

@@ -81,4 +81,4 @@ private val shadowGradient = Modifier.drawWithCache {
onDrawBehind {
drawRect(gradient)
}
}
}

View File

@@ -214,4 +214,4 @@ class PagerScope(
*/
val selectionState: PagerState.SelectionState
get() = state.selectionState
}
}

View File

@@ -36,8 +36,8 @@ fun Toolbar(
closable: Boolean,
modifier: Modifier = Modifier,
actions: @Composable RowScope.() -> Unit = {},
backgroundColor: Color = MaterialTheme.colors.primary, //CustomColors.current.bars,
contentColor: Color = MaterialTheme.colors.onPrimary, //CustomColors.current.onBars,
backgroundColor: Color = MaterialTheme.colors.primary, // CustomColors.current.bars,
contentColor: Color = MaterialTheme.colors.onPrimary, // CustomColors.current.onBars,
elevation: Dp = AppBarDefaults.TopAppBarElevation,
search: ((String) -> Unit)? = null
) {
@@ -86,4 +86,4 @@ fun Toolbar(
}
}*/
}
}
}

View File

@@ -139,9 +139,12 @@ fun EditTextPreference(
preference.value = editText.text
}
) {
OutlinedTextField(editText, onValueChange = {
editText = it
})
OutlinedTextField(
editText,
onValueChange = {
editText = it
}
)
}
}
)
@@ -177,31 +180,37 @@ private fun <T> ChoiceDialog(
onDismissRequest: () -> Unit = {},
onSelected: (T) -> Unit,
title: String,
buttons: @Composable (AppWindow) -> Unit = { }
buttons: @Composable (AppWindow) -> Unit = { }
) {
WindowDialog(onDismissRequest = onDismissRequest, buttons = buttons, title = title, content = {
LazyColumn {
items(items) { (value, text) ->
Row(
modifier = Modifier.requiredHeight(48.dp).fillMaxWidth().clickable(
onClick = {
onSelected(value)
it.close()
}),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = value == selected,
onClick = {
onSelected(value)
it.close()
},
)
Text(text = text, modifier = Modifier.padding(start = 24.dp))
WindowDialog(
onDismissRequest = onDismissRequest,
buttons = buttons,
title = title,
content = {
LazyColumn {
items(items) { (value, text) ->
Row(
modifier = Modifier.requiredHeight(48.dp).fillMaxWidth().clickable(
onClick = {
onSelected(value)
it.close()
}
),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = value == selected,
onClick = {
onSelected(value)
it.close()
},
)
Text(text = text, modifier = Modifier.padding(start = 24.dp))
}
}
}
}
})
)
}
@Composable

View File

@@ -38,4 +38,4 @@ object RandomColors {
fun random(): Color {
return colors[Random.nextInt(colors.size)]
}
}
}

View File

@@ -19,11 +19,13 @@ data class Theme(
val themes = listOf(
// Pure white
Theme(
1, lightColors()
1,
lightColors()
),
// Tachiyomi 0.x default colors
Theme(
2, lightColors(
2,
lightColors(
primary = Color(0xFF2979FF),
primaryVariant = Color(0xFF2979FF),
onPrimary = Color.White,
@@ -34,11 +36,13 @@ val themes = listOf(
),
// Tachiyomi 0.x dark theme
Theme(
3, darkColors()
3,
darkColors()
),
// AMOLED theme
Theme(
4, darkColors(
4,
darkColors(
primary = Color.Black,
onPrimary = Color.White,
background = Color.Black

View File

@@ -49,4 +49,4 @@ inline fun <reified VM : ViewModel> viewModel(
}
}
return viewModel
}
}

View File

@@ -77,4 +77,4 @@ fun openCreateDialog(
}
)
}
}
}

View File

@@ -142,15 +142,19 @@ private fun CategoryRow(
}
Spacer(modifier = Modifier.weight(1f))
IconButton(onClick = onRename) {
Icon(imageVector = Icons.Default.Edit,
contentDescription = null)
Icon(
imageVector = Icons.Default.Edit,
contentDescription = null
)
}
IconButton(onClick = onDelete) {
Icon(imageVector = Icons.Default.Delete,
contentDescription = null)
Icon(
imageVector = Icons.Default.Delete,
contentDescription = null
)
}
}
}
}
}
}
}

View File

@@ -116,4 +116,4 @@ class CategoriesMenuViewModel @Inject constructor(
fun Category.toMenuCategory() = MenuCategory(id, order, name, landing)
data class MenuCategory(val id: Long? = null, var order: Int, val name: String, val landing: Boolean = false)
}
}

View File

@@ -123,7 +123,6 @@ fun ExtensionItem(
}
}
}
}
Button(
{
@@ -134,4 +133,4 @@ fun ExtensionItem(
Text(if (extension.installed) "Uninstall" else "Install")
}
}
}
}

View File

@@ -22,7 +22,7 @@ class ExtensionsMenuViewModel @Inject constructor(
private val extensionHandler: ExtensionInteractionHandler,
serverPreferences: ServerPreferences,
private val extensionPreferences: ExtensionPreferences
): ViewModel() {
) : ViewModel() {
private val logger = KotlinLogging.logger {}
val serverUrl = serverPreferences.server().stateIn(scope)
@@ -33,7 +33,6 @@ class ExtensionsMenuViewModel @Inject constructor(
private val _isLoading = MutableStateFlow(true)
val isLoading = _isLoading.asStateFlow()
init {
scope.launch {
getExtensions()
@@ -76,4 +75,4 @@ class ExtensionsMenuViewModel @Inject constructor(
getExtensions()
}
}
}
}

View File

@@ -44,4 +44,4 @@ fun LibraryMangaBadges(
}
}
private val BadgesInnerPadding = Modifier.padding(horizontal = 3.dp, vertical = 1.dp)
private val BadgesInnerPadding = Modifier.padding(horizontal = 3.dp, vertical = 1.dp)

View File

@@ -50,12 +50,11 @@ fun LibraryScreen(onClickManga: (Long) -> Unit = { openMangaMenu(it) }) {
val displayMode by vm.displayMode.collectAsState()
val isLoading by vm.isLoading.collectAsState()
val serverUrl by vm.serverUrl.collectAsState()
//val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
// val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
if (categories.isEmpty()) {
LoadingScreen(isLoading)
} else {
/*ModalBottomSheetLayout(
sheetState = sheetState,
sheetContent = { *//*LibrarySheet()*//* }
@@ -77,7 +76,7 @@ fun LibraryScreen(onClickManga: (Long) -> Unit = { openMangaMenu(it) }) {
}
)*/
LibraryTabs(
visible = true, //vm.showCategoryTabs,
visible = true, // vm.showCategoryTabs,
categories = categories,
selectedPage = selectedCategoryIndex,
onPageChanged = vm::setSelectedPage
@@ -171,4 +170,4 @@ private fun LibraryPager(
else -> Box {}
}
}
}
}

View File

@@ -35,7 +35,7 @@ class LibraryScreenViewModel @Inject constructor(
private val categoryHandler: CategoryInteractionHandler,
libraryPreferences: LibraryPreferences,
serverPreferences: ServerPreferences,
): ViewModel() {
) : ViewModel() {
val serverUrl = serverPreferences.server().stateIn(scope)
private val library = Library(MutableStateFlow(emptyList()), mutableMapOf())
@@ -78,7 +78,6 @@ class LibraryScreenViewModel @Inject constructor(
}
}
fun setSelectedPage(page: Int) {
_selectedCategoryIndex.value = page
}
@@ -88,8 +87,6 @@ class LibraryScreenViewModel @Inject constructor(
}
companion object {
val defaultCategory = Category(0, 0, "Default",true)
val defaultCategory = Category(0, 0, "Default", true)
}
}

View File

@@ -70,11 +70,12 @@ private fun LibraryMangaCompactGridItem(
TextStyle(letterSpacing = 0.sp, fontFamily = FontFamily.SansSerif, fontSize = 14.sp)
)
Box(modifier = Modifier.padding(4.dp)
.fillMaxWidth()
.aspectRatio(3f / 4f)
.clip(MaterialTheme.shapes.medium)
.clickable(onClick = onClick)
Box(
modifier = Modifier.padding(4.dp)
.fillMaxWidth()
.aspectRatio(3f / 4f)
.clip(MaterialTheme.shapes.medium)
.clickable(onClick = onClick)
) {
if (cover != null) {
KtorImage(cover, contentScale = ContentScale.Crop)
@@ -105,4 +106,4 @@ private val shadowGradient = Modifier.drawWithCache {
onDrawBehind {
drawRect(gradient)
}
}
}

View File

@@ -58,7 +58,6 @@ import compose.icons.fontawesomeicons.regular.Map
fun MainMenu() {
val vm = viewModel<MainViewModel>()
Surface {
Router<Route>("TopLevel", Route.Library) { backStack ->
Row {
Surface(elevation = 2.dp) {
@@ -124,7 +123,6 @@ fun MainMenu() {
}
}
}
}
}
@@ -135,7 +133,7 @@ fun MainMenuItem(menu: TopLevelMenus, selected: Boolean, onClick: (Route) -> Uni
backgroundColor = if (!selected) {
Color.Transparent
} else {
MaterialTheme.colors.primary.copy(0.30F)
MaterialTheme.colors.primary.copy(0.30F)
},
contentColor = Color.Transparent,
elevation = 0.dp
@@ -160,19 +158,21 @@ sealed class Route {
object Library : Route()
object Sources : Route()
object Extensions : Route()
data class Manga(val mangaId: Long): Route()
data class Manga(val mangaId: Long) : Route()
object Settings : Route()
object SettingsGeneral : Route()
object SettingsAppearance : Route()
object SettingsLibrary : Route()
object SettingsReader : Route()
/*object SettingsDownloads : Route()
object SettingsTracking : Route()*/
object SettingsBrowse : Route()
object SettingsBackup : Route()
object SettingsServer : Route()
/*object SettingsSecurity : Route()
object SettingsParentalControls : Route()*/
object SettingsAdvanced : Route()
}
}

View File

@@ -12,6 +12,6 @@ import javax.inject.Inject
class MainViewModel @Inject constructor(
uiPreferences: UiPreferences
): ViewModel() {
) : ViewModel() {
val startScreen = uiPreferences.startScreen().get()
}
}

View File

@@ -79,4 +79,4 @@ fun main() {
}
}
}
}
}

View File

@@ -153,9 +153,9 @@ private fun Cover(manga: Manga, serverUrl: String, modifier: Modifier = Modifier
}
sealed class MangaMenu {
data class MangaMenuManga(val manga: Manga): MangaMenu()
data class MangaMenuManga(val manga: Manga) : MangaMenu()
data class MangaMenuChapter(val chapter: Chapter): MangaMenu()
data class MangaMenuChapter(val chapter: Chapter) : MangaMenu()
}
@Composable
@@ -195,4 +195,4 @@ fun ChapterItem(chapter: Chapter, format: (Date) -> String) {
}
}
}
}
}

View File

@@ -91,7 +91,6 @@ class MangaMenuViewModel @Inject constructor(
refreshMangaAsync(it.id).await()
}
}
}
private fun getDateFormat(format: String): DateFormat = when (format) {
@@ -100,4 +99,4 @@ class MangaMenuViewModel @Inject constructor(
}
data class Params(val mangaId: Long)
}
}

View File

@@ -80,7 +80,7 @@ fun SettingsAppearance(navController: BackStack<Route>) {
ChoicePreference(
preference = vm.themeMode,
choices = mapOf(
//ThemeMode.System to R.string.follow_system_settings,
// ThemeMode.System to R.string.follow_system_settings,
ThemeMode.Light to "Light",
ThemeMode.Dark to "Dark"
),
@@ -94,24 +94,29 @@ fun SettingsAppearance(navController: BackStack<Route>) {
)
LazyRow(modifier = Modifier.padding(horizontal = 8.dp)) {
items(themesForCurrentMode) { theme ->
ThemeItem(theme, onClick = {
(if (isLight) vm.lightTheme else vm.darkTheme).value = it.id
activeColors.primaryStateFlow.value = it.colors.primary
activeColors.secondaryStateFlow.value = it.colors.secondary
})
ThemeItem(
theme,
onClick = {
(if (isLight) vm.lightTheme else vm.darkTheme).value = it.id
activeColors.primaryStateFlow.value = it.colors.primary
activeColors.secondaryStateFlow.value = it.colors.secondary
}
)
}
}
}
item {
ColorPreference(
preference = activeColors.primaryStateFlow, title = "Color primary",
preference = activeColors.primaryStateFlow,
title = "Color primary",
subtitle = "Displayed most frequently across your app",
unsetColor = MaterialTheme.colors.primary
)
}
item {
ColorPreference(
preference = activeColors.secondaryStateFlow, title = "Color secondary",
preference = activeColors.secondaryStateFlow,
title = "Color secondary",
subtitle = "Accents select parts of the UI",
unsetColor = MaterialTheme.colors.secondary
)
@@ -132,7 +137,9 @@ private fun ThemeItem(
Color.White.copy(alpha = 0.15f)
}
Surface(
elevation = 4.dp, color = theme.colors.background, shape = borders,
elevation = 4.dp,
color = theme.colors.background,
shape = borders,
modifier = Modifier
.size(100.dp, 160.dp)
.padding(8.dp)
@@ -159,9 +166,10 @@ private fun ThemeItem(
disabledBackgroundColor = theme.colors.primary
)
)
Surface(Modifier
.size(24.dp)
.align(Alignment.BottomEnd),
Surface(
Modifier
.size(24.dp)
.align(Alignment.BottomEnd),
shape = MaterialTheme.shapes.small.copy(CornerSize(percent = 50)),
color = theme.colors.secondary,
elevation = 6.dp,

View File

@@ -23,7 +23,7 @@ import javax.inject.Inject
class SettingsServerViewModel @Inject constructor(
private val serverPreferences: ServerPreferences
): ViewModel() {
) : ViewModel() {
val host = serverPreferences.host().asStateIn(scope)
val serverUrl = serverPreferences.server().asStateIn(scope)
}

View File

@@ -86,7 +86,6 @@ fun SourcesMenu(bundle: Bundle, onMangaClick: (Long) -> Unit) {
}
}
val selectedSource: Source? = selectedSourceTab
BundleScope("Sources") {
if (selectedSource != null) {

View File

@@ -27,7 +27,7 @@ class SourcesMenuViewModel @Inject constructor(
private val sourceHandler: SourceInteractionHandler,
serverPreferences: ServerPreferences,
catalogPreferences: CatalogPreferences
): ViewModel() {
) : ViewModel() {
private val logger = KotlinLogging.logger {}
val serverUrl = serverPreferences.server().stateIn(scope)
@@ -115,4 +115,4 @@ class SourcesMenuViewModel @Inject constructor(
const val SOURCE_TABS_KEY = "source_tabs"
const val SELECTED_SOURCE_TAB = "selected_tab"
}
}
}

View File

@@ -95,7 +95,6 @@ fun SourceCategory(
}
}
@Composable
fun SourceItem(
source: Source,
@@ -113,4 +112,4 @@ fun SourceItem(
Spacer(Modifier.height(4.dp))
Text("${source.name} (${source.lang})", color = MaterialTheme.colors.onBackground)
}
}
}

View File

@@ -95,7 +95,6 @@ private fun MangaTable(
}
}
LazyVerticalGrid(GridCells.Adaptive(160.dp)) {
items(mangas) { manga ->
MangaGridItem(
@@ -109,4 +108,4 @@ private fun MangaTable(
}
}
}
}
}

View File

@@ -28,7 +28,7 @@ class SourceScreenViewModel @Inject constructor(
private val sourceHandler: SourceInteractionHandler,
private val mangaHandler: MangaInteractionHandler,
serverPreferences: ServerPreferences
): ViewModel() {
) : ViewModel() {
private lateinit var source: Source
private lateinit var bundle: Bundle
@@ -99,7 +99,7 @@ class SourceScreenViewModel @Inject constructor(
}
fun setMode(toLatest: Boolean) {
if (isLatest.value != toLatest){
if (isLatest.value != toLatest) {
_isLatest.value = toLatest
bundle.remove(MANGAS_KEY)
bundle.remove(NEXT_PAGE_KEY)
@@ -123,4 +123,4 @@ class SourceScreenViewModel @Inject constructor(
const val PAGE_NUM_KEY = "next_page"
const val IS_LATEST_KEY = "is_latest"
}
}
}

View File

@@ -8,4 +8,4 @@ package ca.gosyer.util.compose
import androidx.compose.ui.graphics.Color
val Long.color get() = Color(this)
val Long.color get() = Color(this)

View File

@@ -21,4 +21,4 @@ fun imageFromFile(file: File): ImageBitmap {
suspend fun imageFromUrl(client: Http, url: String): ImageBitmap {
return Image.makeFromEncoded(client.get<HttpResponse>(url).readBytes()).asImageBitmap()
}
}

View File

@@ -13,4 +13,4 @@ import com.github.zsoltk.compose.savedinstancestate.LocalSavedInstanceState
@Composable
fun <T> State<T>.persistent(key: String) {
val bundle = LocalSavedInstanceState.current
}
}

View File

@@ -33,4 +33,4 @@ fun ThemedWindow(
content()
}
}
}
}

View File

@@ -18,4 +18,4 @@ val userDataDir: File by lazy {
File(appDirs.getUserDataDir("TachideskJUI", null, null)).also {
if (!it.exists()) it.mkdirs()
}
}
}

View File

@@ -27,4 +27,4 @@ fun <T> Flow<T>.asStateFlow(defaultValue: T, scope: CoroutineScope, dropFirst: B
}
}
return flow.asStateFlow()
}
}

View File

@@ -13,7 +13,7 @@ fun processFile() {
val strTmp = System.getProperty("java.io.tmpdir")
val file = File("$strTmp/TachideskJUI.pid")
//backup deletion
// backup deletion
if (file.exists()) {
file.delete()
}
@@ -21,4 +21,4 @@ fun processFile() {
file.writeText(pidFile.toString())
file.deleteOnExit()
}
}

View File

@@ -4,9 +4,7 @@ import kotlin.test.Test
class ExtensionInteractionTest {
@Test
fun `Install a extension`() {
}
}
}