Skip to content

Commit bb6487f

Browse files
committed
Changed the main user interface and icons [#66]
* Changed Android to use NavigationSuiteScaffold. * Changed all icons to use project-specific SVG images.
1 parent 90c1647 commit bb6487f

69 files changed

Lines changed: 586 additions & 186 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

androidVariant/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ dependencies {
4444
implementation(libs.bundles.android.compose)
4545
implementation(libs.compose.ui)
4646
implementation(libs.compose.ui.tooling.preview)
47-
implementation(libs.compose.material3)
4847
implementation(libs.androidx.activity.compose)
4948
debugImplementation(libs.compose.ui.tooling)
5049

androidVariant/src/main/java/org/comixedproject/variant/android/MainActivity.kt

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ import androidx.activity.compose.setContent
2424
import androidx.compose.foundation.layout.fillMaxSize
2525
import androidx.compose.material3.MaterialTheme
2626
import androidx.compose.material3.Surface
27+
import androidx.compose.runtime.collectAsState
28+
import androidx.compose.runtime.getValue
29+
import androidx.compose.runtime.rememberCoroutineScope
2730
import androidx.compose.ui.Modifier
31+
import kotlinx.coroutines.Dispatchers
32+
import kotlinx.coroutines.launch
2833
import org.comixedproject.variant.android.view.HomeView
34+
import org.comixedproject.variant.platform.Log
2935
import org.comixedproject.variant.viewmodel.VariantViewModel
3036
import org.koin.androidx.compose.koinViewModel
3137

38+
private const val TAG = "MainActivity"
39+
3240
class MainActivity : ComponentActivity() {
3341
override fun onCreate(savedInstanceState: Bundle?) {
3442
super.onCreate(savedInstanceState)
@@ -40,11 +48,61 @@ class MainActivity : ComponentActivity() {
4048
variantViewModel.setLibraryDirectory(directory)
4149

4250
VariantTheme {
51+
val comicBook by variantViewModel.comicBook.collectAsState()
52+
val comicBookList by variantViewModel.comicBookList.collectAsState()
53+
val loading by variantViewModel.loading.collectAsState()
54+
val browsingState by variantViewModel.browsingState.collectAsState()
55+
val selectionMode by variantViewModel.selectionMode.collectAsState()
56+
val selectionList by variantViewModel.selectionList.collectAsState()
57+
58+
val coroutineScope = rememberCoroutineScope()
59+
4360
Surface(
4461
modifier = Modifier.fillMaxSize(),
4562
color = MaterialTheme.colorScheme.background
4663
) {
47-
HomeView()
64+
HomeView(
65+
comicBook,
66+
comicBookList,
67+
browsingState,
68+
loading,
69+
selectionMode,
70+
selectionList,
71+
variantViewModel.address,
72+
variantViewModel.username,
73+
variantViewModel.password,
74+
onLoadDirectory = { path, reload ->
75+
coroutineScope.launch(Dispatchers.IO) {
76+
Log.debug(TAG, "Loading directory: ${path} reload=${reload}")
77+
variantViewModel.loadDirectory(path, reload)
78+
}
79+
},
80+
onDownloadFile = { path, filename ->
81+
coroutineScope.launch(Dispatchers.IO) {
82+
Log.debug(TAG, "Downloading file: ${path} filename=${filename}")
83+
variantViewModel.downloadFile(path, filename)
84+
}
85+
},
86+
onReadComicBook = { comicBook ->
87+
variantViewModel.readComicBook(comicBook)
88+
},
89+
onSetSelectionMode = { enabled ->
90+
variantViewModel.setSelectMode(enabled)
91+
},
92+
onUpdateSelection = { comicBook ->
93+
variantViewModel.updateSelectionList(comicBook.path)
94+
},
95+
onDeleteSelections = {
96+
coroutineScope.launch(Dispatchers.Unconfined) {
97+
variantViewModel.deleteSelections()
98+
}
99+
},
100+
onSaveSettings = { address, username, password ->
101+
variantViewModel.address = address
102+
variantViewModel.username = username
103+
variantViewModel.password = password
104+
}
105+
)
48106
}
49107
}
50108
}

androidVariant/src/main/java/org/comixedproject/variant/android/view/AppDestination.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
package org.comixedproject.variant.android.view
2020

21-
enum class AppDestination {
22-
COMICS,
23-
BROWSE,
24-
SETTINGS
21+
import org.comixedproject.variant.android.R
22+
23+
enum class AppDestination(val icon: Int, val label: Int) {
24+
COMICS(R.drawable.ic_comic_library, R.string.comicsDestinationLabel),
25+
BROWSE(R.drawable.ic_browse_library, R.string.browseServerDestinationLabel),
26+
SETTINGS(R.drawable.ic_settings, R.string.settingsDestinationLabel)
2527
}

androidVariant/src/main/java/org/comixedproject/variant/android/view/HomeView.kt

Lines changed: 123 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,105 +18,161 @@
1818

1919
package org.comixedproject.variant.android.view
2020

21+
import androidx.compose.foundation.layout.fillMaxSize
2122
import androidx.compose.foundation.layout.padding
23+
import androidx.compose.material3.Icon
2224
import androidx.compose.material3.Scaffold
25+
import androidx.compose.material3.Text
26+
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
2327
import androidx.compose.runtime.Composable
24-
import androidx.compose.runtime.collectAsState
2528
import androidx.compose.runtime.getValue
2629
import androidx.compose.runtime.mutableStateOf
2730
import androidx.compose.runtime.remember
28-
import androidx.compose.runtime.rememberCoroutineScope
2931
import androidx.compose.runtime.setValue
3032
import androidx.compose.ui.Modifier
33+
import androidx.compose.ui.res.painterResource
34+
import androidx.compose.ui.res.stringResource
3135
import androidx.compose.ui.tooling.preview.Preview
32-
import kotlinx.coroutines.Dispatchers
33-
import kotlinx.coroutines.launch
36+
import org.comixedproject.variant.android.COMIC_BOOK_LIST
3437
import org.comixedproject.variant.android.VariantTheme
3538
import org.comixedproject.variant.android.view.comics.ComicBookView
3639
import org.comixedproject.variant.android.view.reading.ReadingView
3740
import org.comixedproject.variant.android.view.server.ServerView
3841
import org.comixedproject.variant.android.view.settings.SettingsView
42+
import org.comixedproject.variant.model.library.ComicBook
3943
import org.comixedproject.variant.platform.Log
40-
import org.comixedproject.variant.viewmodel.VariantViewModel
41-
import org.koin.androidx.compose.koinViewModel
44+
import org.comixedproject.variant.viewmodel.BrowsingState
4245

4346
private const val TAG = "HomeView"
4447

4548
@Composable
46-
fun HomeView() {
47-
val variantViewModel: VariantViewModel = koinViewModel()
49+
fun HomeView(
50+
comicBook: ComicBook?,
51+
comicBookList: List<ComicBook>,
52+
browsingState: BrowsingState,
53+
loading: Boolean,
54+
selectionMode: Boolean,
55+
selectionList: List<String>,
56+
address: String, username: String, password: String,
57+
onLoadDirectory: (String, Boolean) -> Unit,
58+
onDownloadFile: (String, String) -> Unit,
59+
onReadComicBook: (ComicBook?) -> Unit,
60+
onSetSelectionMode: (Boolean) -> Unit,
61+
onUpdateSelection: (ComicBook) -> Unit,
62+
onDeleteSelections: () -> Unit,
63+
onSaveSettings: (String, String, String) -> Unit
64+
) {
4865
var currentDestination by remember { mutableStateOf(AppDestination.COMICS) }
49-
val coroutineScope = rememberCoroutineScope()
50-
val comicBookList by variantViewModel.comicBookList.collectAsState()
51-
val selectionMode by variantViewModel.selectionMode.collectAsState()
52-
val selectionList by variantViewModel.selectionList.collectAsState()
53-
val comicBook by variantViewModel.comicBook.collectAsState()
5466

5567
Scaffold(
56-
topBar = {
57-
VariantTopAppBar(
58-
onBrowseComics = { currentDestination = AppDestination.COMICS },
59-
onBrowseServer = {
60-
coroutineScope.launch(Dispatchers.IO) {
61-
variantViewModel.loadDirectory(
62-
variantViewModel.browsingState.value.currentPath,
63-
false
64-
)
65-
}
66-
currentDestination = AppDestination.BROWSE
67-
},
68-
onUpdateSettings = { currentDestination = AppDestination.SETTINGS })
69-
},
68+
topBar = { VariantTopAppBar() },
7069
content = { padding ->
71-
when (currentDestination) {
72-
AppDestination.COMICS ->
73-
if (comicBook != null) {
74-
ReadingView(
75-
comicBook!!,
76-
modifier = Modifier.padding(padding),
77-
onStopReading = { variantViewModel.readComicBook(null) }
78-
)
79-
} else {
80-
ComicBookView(
81-
comicBookList,
82-
selectionMode,
83-
selectionList,
84-
onSetSelectionMode = {
85-
Log.info(TAG, "Setting selection mode: ${it}")
86-
variantViewModel.setSelectMode(it)
70+
NavigationSuiteScaffold(
71+
navigationSuiteItems = {
72+
AppDestination.entries.forEach {
73+
item(
74+
icon = {
75+
Icon(
76+
painterResource(it.icon),
77+
contentDescription = stringResource(it.label)
78+
)
8779
},
88-
onComicBookClicked = { comicBook ->
89-
if (selectionMode) {
90-
Log.info(
91-
TAG,
92-
"Toggling comic book selection: ${comicBook.path}"
93-
)
94-
variantViewModel.updateSelectionList(comicBook.path)
95-
} else {
96-
Log.info(TAG, "Reading comic book: ${comicBook.filename}")
97-
variantViewModel.readComicBook(comicBook)
80+
label = { Text(stringResource(it.label)) },
81+
selected = it == currentDestination,
82+
onClick = {
83+
if (it == AppDestination.BROWSE
84+
) {
85+
onLoadDirectory(browsingState.currentPath, false)
9886
}
99-
},
100-
onDeleteComics = {
101-
coroutineScope.launch(Dispatchers.IO) {
102-
variantViewModel.deleteSelections()
103-
}
104-
},
105-
modifier = Modifier.padding(padding)
87+
currentDestination = it
88+
}
10689
)
10790
}
91+
},
92+
modifier = Modifier.padding(padding)
93+
) {
94+
when (currentDestination) {
95+
AppDestination.COMICS ->
96+
if (comicBook != null) {
97+
ReadingView(
98+
comicBook,
99+
onStopReading = { onReadComicBook(null) },
100+
modifier = Modifier
101+
.fillMaxSize()
102+
)
103+
} else {
104+
ComicBookView(
105+
comicBookList,
106+
selectionMode,
107+
selectionList,
108+
onSetSelectionMode = {
109+
Log.info(TAG, "Setting selection mode: ${it}")
110+
onSetSelectionMode(it)
111+
},
112+
onComicBookClicked = { comicBook ->
113+
if (selectionMode) {
114+
Log.info(
115+
TAG,
116+
"Toggling comic book selection: ${comicBook.path}"
117+
)
118+
onUpdateSelection(comicBook)
119+
} else {
120+
Log.info(TAG, "Reading comic book: ${comicBook.filename}")
121+
onReadComicBook(comicBook)
122+
}
123+
},
124+
onDeleteComics = { onDeleteSelections() },
125+
modifier = Modifier
126+
.fillMaxSize()
127+
)
128+
}
129+
130+
AppDestination.BROWSE -> ServerView(
131+
browsingState, comicBookList, loading,
132+
onLoadDirectory = { path, reload -> onLoadDirectory(path, reload) },
133+
onDownloadFile = { path, filename -> onDownloadFile(path, filename) },
134+
modifier = Modifier
135+
.fillMaxSize()
136+
)
108137

109-
AppDestination.BROWSE -> ServerView(modifier = Modifier.padding(padding))
110-
AppDestination.SETTINGS -> SettingsView(onCloseSettings = {
111-
currentDestination = AppDestination.COMICS
112-
}, modifier = Modifier.padding(padding))
138+
AppDestination.SETTINGS -> SettingsView(
139+
address, username, password,
140+
onSaveSettings = { address, username, password ->
141+
Log.info(
142+
TAG,
143+
"Updating server settings: address=${address} username=${username} password=${
144+
password.first()
145+
}*****"
146+
)
147+
onSaveSettings(address, username, password)
148+
currentDestination = AppDestination.COMICS
149+
},
150+
modifier = Modifier
151+
.fillMaxSize()
152+
)
153+
}
113154
}
114-
}
115-
)
155+
})
116156
}
117157

118158
@Composable
119159
@Preview
120160
fun HomeViewPreview() {
121-
VariantTheme { HomeView() }
161+
VariantTheme {
162+
HomeView(
163+
COMIC_BOOK_LIST.get(0),
164+
COMIC_BOOK_LIST,
165+
BrowsingState("", "", "", listOf(), listOf()),
166+
false,
167+
false,
168+
listOf(),
169+
"http://www.comixedproject.org:7171", "reader@comixedproject.org", "my!password",
170+
onLoadDirectory = { _, _ -> },
171+
onDownloadFile = { _, _ -> },
172+
onReadComicBook = { _ -> },
173+
onSetSelectionMode = { _ -> },
174+
onUpdateSelection = { _ -> },
175+
onDeleteSelections = { }, onSaveSettings = { _, _, _ -> }
176+
)
177+
}
122178
}

0 commit comments

Comments
 (0)