Skip to content
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
1 change: 0 additions & 1 deletion androidVariant/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ dependencies {
implementation(libs.bundles.android.compose)
implementation(libs.compose.ui)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.compose.material3)
implementation(libs.androidx.activity.compose)
debugImplementation(libs.compose.ui.tooling)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.comixedproject.variant.android.view.HomeView
import org.comixedproject.variant.platform.Log
import org.comixedproject.variant.viewmodel.VariantViewModel
import org.koin.androidx.compose.koinViewModel

private const val TAG = "MainActivity"

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -40,11 +48,61 @@ class MainActivity : ComponentActivity() {
variantViewModel.setLibraryDirectory(directory)

VariantTheme {
val comicBook by variantViewModel.comicBook.collectAsState()
val comicBookList by variantViewModel.comicBookList.collectAsState()
val loading by variantViewModel.loading.collectAsState()
val browsingState by variantViewModel.browsingState.collectAsState()
val selectionMode by variantViewModel.selectionMode.collectAsState()
val selectionList by variantViewModel.selectionList.collectAsState()

val coroutineScope = rememberCoroutineScope()

Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
HomeView()
HomeView(
comicBook,
comicBookList,
browsingState,
loading,
selectionMode,
selectionList,
variantViewModel.address,
variantViewModel.username,
variantViewModel.password,
onLoadDirectory = { path, reload ->
coroutineScope.launch(Dispatchers.IO) {
Log.debug(TAG, "Loading directory: ${path} reload=${reload}")
variantViewModel.loadDirectory(path, reload)
}
},
onDownloadFile = { path, filename ->
coroutineScope.launch(Dispatchers.IO) {
Log.debug(TAG, "Downloading file: ${path} filename=${filename}")
variantViewModel.downloadFile(path, filename)
}
},
onReadComicBook = { comicBook ->
variantViewModel.readComicBook(comicBook)
},
onSetSelectionMode = { enabled ->
variantViewModel.setSelectMode(enabled)
},
onUpdateSelection = { comicBook ->
variantViewModel.updateSelectionList(comicBook.path)
},
onDeleteSelections = {
coroutineScope.launch(Dispatchers.Unconfined) {
variantViewModel.deleteSelections()
}
},
onSaveSettings = { address, username, password ->
variantViewModel.address = address
variantViewModel.username = username
variantViewModel.password = password
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

package org.comixedproject.variant.android.view

enum class AppDestination {
COMICS,
BROWSE,
SETTINGS
import org.comixedproject.variant.android.R

enum class AppDestination(val icon: Int, val label: Int) {
COMICS(R.drawable.ic_comic_library, R.string.comicsDestinationLabel),
BROWSE(R.drawable.ic_browse_library, R.string.browseServerDestinationLabel),
SETTINGS(R.drawable.ic_settings, R.string.settingsDestinationLabel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,105 +18,161 @@

package org.comixedproject.variant.android.view

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.comixedproject.variant.android.COMIC_BOOK_LIST
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.android.view.comics.ComicBookView
import org.comixedproject.variant.android.view.reading.ReadingView
import org.comixedproject.variant.android.view.server.ServerView
import org.comixedproject.variant.android.view.settings.SettingsView
import org.comixedproject.variant.model.library.ComicBook
import org.comixedproject.variant.platform.Log
import org.comixedproject.variant.viewmodel.VariantViewModel
import org.koin.androidx.compose.koinViewModel
import org.comixedproject.variant.viewmodel.BrowsingState

private const val TAG = "HomeView"

@Composable
fun HomeView() {
val variantViewModel: VariantViewModel = koinViewModel()
fun HomeView(
comicBook: ComicBook?,
comicBookList: List<ComicBook>,
browsingState: BrowsingState,
loading: Boolean,
selectionMode: Boolean,
selectionList: List<String>,
address: String, username: String, password: String,
onLoadDirectory: (String, Boolean) -> Unit,
onDownloadFile: (String, String) -> Unit,
onReadComicBook: (ComicBook?) -> Unit,
onSetSelectionMode: (Boolean) -> Unit,
onUpdateSelection: (ComicBook) -> Unit,
onDeleteSelections: () -> Unit,
onSaveSettings: (String, String, String) -> Unit
) {
var currentDestination by remember { mutableStateOf(AppDestination.COMICS) }
val coroutineScope = rememberCoroutineScope()
val comicBookList by variantViewModel.comicBookList.collectAsState()
val selectionMode by variantViewModel.selectionMode.collectAsState()
val selectionList by variantViewModel.selectionList.collectAsState()
val comicBook by variantViewModel.comicBook.collectAsState()

Scaffold(
topBar = {
VariantTopAppBar(
onBrowseComics = { currentDestination = AppDestination.COMICS },
onBrowseServer = {
coroutineScope.launch(Dispatchers.IO) {
variantViewModel.loadDirectory(
variantViewModel.browsingState.value.currentPath,
false
)
}
currentDestination = AppDestination.BROWSE
},
onUpdateSettings = { currentDestination = AppDestination.SETTINGS })
},
topBar = { VariantTopAppBar() },
content = { padding ->
when (currentDestination) {
AppDestination.COMICS ->
if (comicBook != null) {
ReadingView(
comicBook!!,
modifier = Modifier.padding(padding),
onStopReading = { variantViewModel.readComicBook(null) }
)
} else {
ComicBookView(
comicBookList,
selectionMode,
selectionList,
onSetSelectionMode = {
Log.info(TAG, "Setting selection mode: ${it}")
variantViewModel.setSelectMode(it)
NavigationSuiteScaffold(
navigationSuiteItems = {
AppDestination.entries.forEach {
item(
icon = {
Icon(
painterResource(it.icon),
contentDescription = stringResource(it.label)
)
},
onComicBookClicked = { comicBook ->
if (selectionMode) {
Log.info(
TAG,
"Toggling comic book selection: ${comicBook.path}"
)
variantViewModel.updateSelectionList(comicBook.path)
} else {
Log.info(TAG, "Reading comic book: ${comicBook.filename}")
variantViewModel.readComicBook(comicBook)
label = { Text(stringResource(it.label)) },
selected = it == currentDestination,
onClick = {
if (it == AppDestination.BROWSE
) {
onLoadDirectory(browsingState.currentPath, false)
}
},
onDeleteComics = {
coroutineScope.launch(Dispatchers.IO) {
variantViewModel.deleteSelections()
}
},
modifier = Modifier.padding(padding)
currentDestination = it
}
)
}
},
modifier = Modifier.padding(padding)
) {
when (currentDestination) {
AppDestination.COMICS ->
if (comicBook != null) {
ReadingView(
comicBook,
onStopReading = { onReadComicBook(null) },
modifier = Modifier
.fillMaxSize()
)
} else {
ComicBookView(
comicBookList,
selectionMode,
selectionList,
onSetSelectionMode = {
Log.info(TAG, "Setting selection mode: ${it}")
onSetSelectionMode(it)
},
onComicBookClicked = { comicBook ->
if (selectionMode) {
Log.info(
TAG,
"Toggling comic book selection: ${comicBook.path}"
)
onUpdateSelection(comicBook)
} else {
Log.info(TAG, "Reading comic book: ${comicBook.filename}")
onReadComicBook(comicBook)
}
},
onDeleteComics = { onDeleteSelections() },
modifier = Modifier
.fillMaxSize()
)
}

AppDestination.BROWSE -> ServerView(
browsingState, comicBookList, loading,
onLoadDirectory = { path, reload -> onLoadDirectory(path, reload) },
onDownloadFile = { path, filename -> onDownloadFile(path, filename) },
modifier = Modifier
.fillMaxSize()
)

AppDestination.BROWSE -> ServerView(modifier = Modifier.padding(padding))
AppDestination.SETTINGS -> SettingsView(onCloseSettings = {
currentDestination = AppDestination.COMICS
}, modifier = Modifier.padding(padding))
AppDestination.SETTINGS -> SettingsView(
address, username, password,
onSaveSettings = { address, username, password ->
Log.info(
TAG,
"Updating server settings: address=${address} username=${username} password=${
password.first()
}*****"
)
onSaveSettings(address, username, password)
currentDestination = AppDestination.COMICS
},
modifier = Modifier
.fillMaxSize()
)
}
}
}
)
})
}

@Composable
@Preview
fun HomeViewPreview() {
VariantTheme { HomeView() }
VariantTheme {
HomeView(
COMIC_BOOK_LIST.get(0),
COMIC_BOOK_LIST,
BrowsingState("", "", "", listOf(), listOf()),
false,
false,
listOf(),
"http://www.comixedproject.org:7171", "reader@comixedproject.org", "my!password",
onLoadDirectory = { _, _ -> },
onDownloadFile = { _, _ -> },
onReadComicBook = { _ -> },
onSetSelectionMode = { _ -> },
onUpdateSelection = { _ -> },
onDeleteSelections = { }, onSaveSettings = { _, _, _ -> }
)
}
}
Loading