From 25bd7c3fc3cb797d3372712a7fd00608b44cc550 Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Thu, 23 Nov 2023 10:29:26 -0500 Subject: [PATCH] Added displaying the list of OPDS server entries [#3] * Added dependency on Napier for logging. * Bumped JDK to 17. --- composeApp/build.gradle.kts | 9 +- composeApp/src/commonMain/kotlin/App.kt | 44 +++++---- .../variant/model/OPDSServerEntry.kt | 27 ++++++ .../repository/OPDSServerRepository.kt | 95 +++++++++++++++++++ .../OPDSServerRepositoryTest.kt | 33 +++++++ gradle/libs.versions.toml | 2 + 6 files changed, 189 insertions(+), 21 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/org/comixedproject/variant/model/OPDSServerEntry.kt create mode 100644 composeApp/src/commonMain/kotlin/org/comixedproject/variant/repository/OPDSServerRepository.kt create mode 100644 composeApp/src/commonTest/kotlin/org.comixedproject.variant.repository/OPDSServerRepositoryTest.kt diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 133df6f..47d101b 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -11,7 +11,7 @@ kotlin { androidTarget { compilations.all { kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" } } } @@ -46,6 +46,7 @@ kotlin { implementation(compose.material) @OptIn(ExperimentalComposeLibrary::class) implementation(compose.components.resources) + implementation(libs.napier) } commonTest.dependencies { implementation(libs.kotlin.test) @@ -66,7 +67,7 @@ android { minSdk = libs.versions.android.minSdk.get().toInt() targetSdk = libs.versions.android.targetSdk.get().toInt() versionCode = 1 - versionName = "1.0" + versionName = "0.0.1.0" } buildFeatures { compose = true @@ -85,8 +86,8 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } dependencies { debugImplementation(libs.compose.ui.tooling) diff --git a/composeApp/src/commonMain/kotlin/App.kt b/composeApp/src/commonMain/kotlin/App.kt index 498452c..f584a67 100644 --- a/composeApp/src/commonMain/kotlin/App.kt +++ b/composeApp/src/commonMain/kotlin/App.kt @@ -16,11 +16,12 @@ * along with this program. If not, see */ -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material.Button +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.Card import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -28,29 +29,38 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import io.github.aakira.napier.DebugAntilog +import io.github.aakira.napier.Napier +import org.comixedproject.variant.repository.OPDSServerRepository import org.jetbrains.compose.resources.ExperimentalResourceApi -import org.jetbrains.compose.resources.painterResource @OptIn(ExperimentalResourceApi::class) @Composable fun App() { + Napier.base(DebugAntilog()) + MaterialTheme { var greetingText by remember { mutableStateOf("ComiXed Prestige!") } var showImage by remember { mutableStateOf(false) } - Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { - Button(onClick = { - greetingText = "ComiXed Prestige" - showImage = !showImage - }) { - Text(greetingText) - } - AnimatedVisibility(showImage) { - Image( - painterResource("compose-multiplatform.xml"), - null - ) + + val opdsServerRepository = OPDSServerRepository() + + LazyColumn { + items(opdsServerRepository.getAllEntries()) { entry -> + Card(modifier = Modifier.fillMaxWidth()) { + Column(modifier = Modifier.fillMaxWidth()) { + Row(modifier = Modifier.fillMaxWidth()) { + Text(text = entry.name) + } + Row(modifier = Modifier.fillMaxWidth()) { + Text(text = entry.url) + } + Row(modifier = Modifier.fillMaxWidth()) { + Text(text = entry.username) + } + } + } } } } diff --git a/composeApp/src/commonMain/kotlin/org/comixedproject/variant/model/OPDSServerEntry.kt b/composeApp/src/commonMain/kotlin/org/comixedproject/variant/model/OPDSServerEntry.kt new file mode 100644 index 0000000..b5b30e1 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/comixedproject/variant/model/OPDSServerEntry.kt @@ -0,0 +1,27 @@ +/* + * Variant - A digital comic book reading application for iPad, Android, and desktops. + * Copyright (C) 2023, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package org.comixedproject.variant.model; + +/** + * OPDSServerEntry represents a single OPDS server. + * + * @author Darryl L. Pierce + */ +data class OPDSServerEntry(val name: String, val url: String, val username: String, val password: String) { +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/org/comixedproject/variant/repository/OPDSServerRepository.kt b/composeApp/src/commonMain/kotlin/org/comixedproject/variant/repository/OPDSServerRepository.kt new file mode 100644 index 0000000..77467cd --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/comixedproject/variant/repository/OPDSServerRepository.kt @@ -0,0 +1,95 @@ +/* + * Variant - A digital comic book reading application for iPad, Android, and desktops. + * Copyright (C) 2023, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package org.comixedproject.variant.repository; + +import io.github.aakira.napier.Napier +import org.comixedproject.variant.model.OPDSServerEntry + +/** + * OPDSServerRepository provides methods for storing and retrieving instanes of {@link OPDSServerEntry}. + * + * @author Darryl L. Pierce + */ +class OPDSServerRepository { + fun getAllEntries(): List { + Napier.d { "Loading the list of server entries" } + return listOf( + OPDSServerEntry( + "First Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Second Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Third Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Fourth Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Fifth Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Sixth Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Seventh Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Eighth Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Ninth Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ), + OPDSServerEntry( + "Tenth Entry", + "http://localhost:7171/opds", + "comixedreader@localhost", + "comixedreader" + ) + ); + } +} \ No newline at end of file diff --git a/composeApp/src/commonTest/kotlin/org.comixedproject.variant.repository/OPDSServerRepositoryTest.kt b/composeApp/src/commonTest/kotlin/org.comixedproject.variant.repository/OPDSServerRepositoryTest.kt new file mode 100644 index 0000000..9b27881 --- /dev/null +++ b/composeApp/src/commonTest/kotlin/org.comixedproject.variant.repository/OPDSServerRepositoryTest.kt @@ -0,0 +1,33 @@ +/* + * Variant - A digital comic book reading application for iPad, Android, and desktops. + * Copyright (C) 2023, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package org.comixedproject.variant.repository; + +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertNotNull + +class OPDSServerRepositoryTest { + + @Test fun testGetAllEntries() { + val result = OPDSServerRepository().getAllEntries() + + assertNotNull(result) + assertFalse(result.isEmpty()) + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8c245ef..9039b74 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,7 @@ androidx-test-junit = "1.1.5" androidx-espresso-core = "3.5.1" kotlin = "1.9.20" junit = "4.13.2" +napier = "2.6.1" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -32,6 +33,7 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version androidx-material = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" } androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } +napier = { module = "io.github.aakira:napier", version.ref = "napier" } [plugins] jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }