-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added displaying a list of servers [#3]
* Android: Added the navigation suite scaffold. * iOS: Added the navigation view.
- Loading branch information
Showing
21 changed files
with
640 additions
and
8 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
25 changes: 25 additions & 0 deletions
25
androidVariant/src/main/java/org/comixedproject/variant/android/model/server/Server.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,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 |
83 changes: 83 additions & 0 deletions
83
androidVariant/src/main/java/org/comixedproject/variant/android/ui/HomeScreen.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,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() | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
androidVariant/src/main/java/org/comixedproject/variant/android/ui/Screens.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,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() | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
androidVariant/src/main/java/org/comixedproject/variant/android/ui/server/ServerList.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,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 = {}) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
androidVariant/src/main/java/org/comixedproject/variant/android/ui/server/ServerListItem.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,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 = {} | ||
) | ||
} | ||
} |
Oops, something went wrong.