Skip to content

Commit

Permalink
Added displaying a list of servers [#3]
Browse files Browse the repository at this point in the history
 * Android: Added the navigation suite scaffold.
 * iOS: Added the navigation view.
  • Loading branch information
mcpierce committed Jun 9, 2024
1 parent 63cd6d3 commit 1909806
Show file tree
Hide file tree
Showing 21 changed files with 640 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import org.comixedproject.variant.android.ui.HomeScreen

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -36,7 +36,7 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Text("Variant v0.1-SNAPSHOT")
HomeScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.model.server

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
class Server(val id: Int, val name: String, val url: String, val username: String) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.android.ui.server.ServerManagementScreen

@Composable
fun HomeScreen() {
val selectedItem = remember { mutableStateOf(Screens.ServerManagement) }
val navHost = rememberNavController()
val navBackStackEntry by navHost.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination

NavigationSuiteScaffold(
navigationSuiteItems = {
Screens.all.forEach { screen ->
item(
selected = selectedItem.value == screen,
onClick = { selectedItem.value = screen },
label = { Text(stringResource(id = screen.label)) },
icon = {
Icon(
imageVector = screen.icon,
contentDescription = stringResource(id = screen.label)
)
},
alwaysShowLabel = true
)
}
}
) {
Box(modifier = Modifier.fillMaxSize()) {
Surface(modifier = Modifier.align(Alignment.Center)) {
when (selectedItem.value) {
Screens.ServerManagement -> ServerManagementScreen()
Screens.ComicManagement -> Text("Comic Book Management")
Screens.Settings -> Text("Settings")
}
}
}
}
}

@Preview
@Composable
fun HomeScreenPreview() {
VariantTheme {
HomeScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.filled.List
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import org.comixedproject.variant.android.R

enum class Screens(val label: Int, val icon: ImageVector) {
ServerManagement(R.string.serverButtonLabel, Icons.Filled.List),
ComicManagement(R.string.comicsButtonLabel, Icons.Filled.PlayArrow),
Settings(R.string.settingsButtonLabel, Icons.Filled.Settings);

companion object {
val all = values()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.server

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.android.model.server.Server

@Composable
fun ServerList(servers: List<Server>, onServerSelect: (Server) -> Unit) {
LazyColumn {
items(servers) { server ->
ServerListItem(server, onClick = onServerSelect)
}
}
}

@Preview
@Composable
fun ServerListPreview() {
VariantTheme {
ServerList(
listOf(
Server(
id = 1,
name = "My Server",
url = "http://www.comixedproject.org:7171/opds",
username = "[email protected]"
), Server(
id = 2,
name = "My Server",
url = "http://www.comixedproject.org:7171/opds",
username = "[email protected]"
), Server(
id = 3,
name = "My Server",
url = "http://www.comixedproject.org:7171/opds",
username = "[email protected]"
), Server(
id = 4,
name = "My Server",
url = "http://www.comixedproject.org:7171/opds",
username = "[email protected]"
), Server(
id = 5,
name = "My Server",
url = "http://www.comixedproject.org:7171/opds",
username = "[email protected]"
)
),
onServerSelect = {})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.server

import androidx.compose.foundation.clickable
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.android.model.server.Server

@Composable
fun ServerListItem(server: Server, onClick: (Server) -> Unit) {
ListItem(
leadingContent = { Icon(Icons.Filled.Info, contentDescription = server.name) },
overlineContent = { Text(server.url) },
headlineContent = { Text(server.name) },
supportingContent = { Text(server.username) },
modifier = Modifier.clickable {
onClick(server)
}
)
}

@Preview
@Composable
fun ServerListItemPreview() {
VariantTheme {
ServerListItem(
server = Server(
id = 1,
name = "My Server",
url = "http://www.comixedproject.org:7171/opds",
username = "[email protected]"
),
onClick = {}
)
}
}
Loading

0 comments on commit 1909806

Please sign in to comment.