Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added browsing a server's directory of items [#8] #61

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions androidVariant/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ dependencies {
implementation(libs.bundles.compose)
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
implementation(libs.readium.shared)
implementation(libs.readium.opds)
implementation(libs.readium.streamer)

testImplementation(libs.bundles.unit.tests)
androidTestImplementation(composeBom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ package org.comixedproject.variant.android
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import org.comixedproject.variant.android.ui.RootView
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.comixedproject.variant.android.ui.HomeView
import org.comixedproject.variant.android.viewmodel.ServerLinkViewModel
import org.comixedproject.variant.android.viewmodel.ServerViewModel

/**
* <code>MainActivity</code> is the main class for the Android implementation of Variant.
*
* @author Darryl L. Pierce
*/
class MainActivity : ComponentActivity() {
private val serverViewModel: ServerViewModel by viewModels()
private val serverLinkViewModel: ServerLinkViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -37,7 +49,23 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
RootView()
val serverList by serverViewModel.serverList.collectAsStateWithLifecycle()
val linkList by serverLinkViewModel.displayLinkList.collectAsStateWithLifecycle()

HomeView(
serverList,
serverViewModel,
linkList,
serverLinkViewModel,
onSaveServer = { serverId, name, url, username, password ->
serverViewModel.onSaveServer(
serverId,
name,
url,
username,
password
)
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,32 @@ package org.comixedproject.variant.android
import android.app.Application
import android.content.Context
import org.comixedproject.variant.shared.initKoin
import org.comixedproject.variant.shared.model.VariantViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.Koin
import org.koin.dsl.module

lateinit var koin: Koin

/**
* <code>VariantApp</code> provides an application class for Variant.
*
* @author Darryl L. Pierce
*/
class VariantApp : Application() {

override fun onCreate() {
super.onCreate()

initKoin(
VariantApp.appContext = applicationContext

koin = initKoin(
appModule = module {
single<Context> { this@VariantApp }

},
viewModelsModule = module {
viewModel {
VariantViewModel(get(), get())
}
})
viewModelsModule = module { }).koin
}

companion object {
lateinit var appContext: Context
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
* <code>VariantTheme</code> provides the application's theme.
*
* @author Darryl L. Pierce
*/
@Composable
fun VariantTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Variant - A digital comic book reading application for the iPad and Android tablets.
* Copyright (C) 2024, 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 <http://www.gnu.org/licenses>
*/

package org.comixedproject.variant.android.ui

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import org.comixedproject.variant.android.R

/**
* <code>BottomBarItem</code> defines an item displayed on the bottom bat of the main application view.
*
* @author Darryl L. Pierce
*/
enum class BottomBarItem(val label: Int, val icon: ImageVector, val screen: NavigationScreen) {
ServerList(R.string.serverButtonLabel, Icons.Filled.AccountBox, NavigationScreen.Servers),
ComicList(
R.string.comicsButtonLabel,
Icons.AutoMirrored.Filled.List,
NavigationScreen.ComicList
),
Settings(R.string.settingsButtonLabel, Icons.Filled.Settings, NavigationScreen.Settings);

companion object {
val all = values()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.variant.android.ui.server
package org.comixedproject.variant.android.ui

import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
Expand All @@ -31,18 +31,21 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavDestination
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.android.ui.BottomBarItems


/**
* <code>BottomBarView</code> composes the view of items displayed on the main application's bottom bar.
*
* @author Darryl L. Pierce
*/
@Composable
fun BottomBar(
fun BottomBarView(
currentDestination: NavDestination?,
onScreenChange: (route: String) -> Unit
) {
var selectedItem by remember { mutableIntStateOf(0) }

NavigationBar {
BottomBarItems.all.forEachIndexed { index, item ->
BottomBarItem.all.forEachIndexed { index, item ->
NavigationBarItem(selected = selectedItem == index,
onClick = {
selectedItem = index
Expand All @@ -63,6 +66,6 @@ fun BottomBar(
@Composable
fun BottomBarPreview() {
VariantTheme {
BottomBar(null, onScreenChange = {})
BottomBarView(null, onScreenChange = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@

package org.comixedproject.variant.android.ui

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
Expand All @@ -37,40 +41,51 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import org.comixedproject.variant.android.R
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.android.ui.server.BottomBar
import org.comixedproject.variant.android.ui.server.BrowseServerScreen
import org.comixedproject.variant.android.ui.server.ServerManagementScreen
import org.comixedproject.variant.shared.model.server.AcquisitionLink
import org.comixedproject.variant.android.ui.server.BrowseServerView
import org.comixedproject.variant.android.ui.server.ServerManagementView
import org.comixedproject.variant.android.viewmodel.ServerLinkViewModel
import org.comixedproject.variant.android.viewmodel.ServerViewModel
import org.comixedproject.variant.shared.model.server.Server
import org.comixedproject.variant.shared.model.server.ServerLink
import org.comixedproject.variant.shared.platform.Logger

private const val TAG = "HomeScreen"

/**
* <code>HomeView</code> composes the primary view for the application.
*
* @author Darryl L. Pierce
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
servers: List<Server>,
displayLinks: List<AcquisitionLink>,
allLinks: List<AcquisitionLink>,
onSaveServer: (Server) -> Unit,
onLoadDirectory: (Server, String, Boolean) -> Unit
fun HomeView(
serverList: List<Server>,
serverViewModel: ServerViewModel,
linkList: List<ServerLink>,
serverLinkViewModel: ServerLinkViewModel,
onSaveServer: (Long?, String, String, String, String) -> Unit
) {
val navController = rememberNavController()

Scaffold(
topBar = {
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
),
navigationIcon = {
Icon(imageVector = Icons.Filled.Menu, contentDescription = "Menu",
modifier = Modifier.clickable { })
},
title = {
Text(stringResource(id = R.string.appNameAndVersion))
}
var title = stringResource(id = R.string.appName)
Text(title)
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = colorScheme.primaryContainer,
titleContentColor = colorScheme.primary
)
)
},
bottomBar = {
BottomBar(currentDestination = navController.currentBackStackEntryAsState().value?.destination,
BottomBarView(currentDestination = navController.currentBackStackEntryAsState().value?.destination,
onScreenChange = { route -> navController.navigate(route) })
},
) { padding ->
Expand All @@ -87,11 +102,13 @@ fun HomeScreen(
composable(
route = NavigationScreen.Servers.route
) {
ServerManagementScreen(
servers = servers,
onSaveServer = { server -> onSaveServer(server) },
ServerManagementView(
servers = serverList,
onSaveServer = onSaveServer,
onBrowseServer = { server ->
navController.navigate("servers?serverId=${server.id}&linkId=")
serverLinkViewModel.loadServerDirectory(server, server.url, false)
serverLinkViewModel.directory = server.url
navController.navigate("servers?serverId=${server.serverId}")
},
onDeleteServer = { }
)
Expand All @@ -100,26 +117,26 @@ fun HomeScreen(
route = NavigationScreen.BrowseServer.route,
arguments = NavigationScreen.BrowseServer.navArguments
) { entry ->
val serverId = entry.arguments?.getString("serverId")
val linkId = entry.arguments?.getString("linkId").orEmpty()
Logger.d(TAG, "serverId=${serverId} linkId=${linkId}")
servers.find { server -> server.id == serverId }?.let { server ->
var directory = ""
if (linkId.isNotEmpty()) {
allLinks.find { link -> link.id == linkId }
?.let { link ->
directory = link.link
}
}

onLoadDirectory(server, directory, false)
val serverId = entry.arguments?.getLong(NAVARG_SERVER_ID)
Logger.d(TAG, "serverId=${serverId} directory=${serverLinkViewModel.directory}")
val currentServer =
serverList.firstOrNull { server -> server.serverId == serverId }

BrowseServerScreen(
server = server,
acquisitionLinks = displayLinks,
directory,
if (currentServer != null) {
BrowseServerView(
server = currentServer,
serverLinks = linkList.filter { link -> link.serverId == currentServer.serverId }
.filter { link -> link.directory == serverLinkViewModel.directory }
.toList(),
serverLinkViewModel.directory,
onLoadDirectory = { target, selectedLink ->
navController.navigate("servers?serverId=${target.id}&linkId=${selectedLink.id}")
serverLinkViewModel.loadServerDirectory(
target,
selectedLink.href,
false
)
serverLinkViewModel.directory = selectedLink.href
navController.navigate("servers?serverId=${target.serverId}")
})
}
}
Expand All @@ -136,14 +153,20 @@ fun HomeScreen(

@Preview
@Composable
fun HomeScreenPreview() {
fun HomeSPreview() {
VariantTheme {
HomeScreen(
emptyList(),
emptyList(),
HomeView(
listOf(
Server(null, "Server 1", "", "", ""),
Server(null, "Server 2", "", "", ""),
Server(null, "Server 3", "", "", ""),
Server(null, "Server 4", "", "", ""),
Server(null, "Server 5", "", "", "")
),
ServerViewModel(),
emptyList(),
onSaveServer = { },
onLoadDirectory = { _, _, _ -> }
ServerLinkViewModel(),
onSaveServer = { _, _, _, _, _ -> }
)
}
}
Loading
Loading