Skip to content

Commit

Permalink
Improve OverlayPage UI
Browse files Browse the repository at this point in the history
Signed-off-by: Saul Henriquez <[email protected]>
  • Loading branch information
saulhdev committed Aug 8, 2023
1 parent afdb3e4 commit 58afa1d
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 23 deletions.
159 changes: 136 additions & 23 deletions app/src/main/java/com/saulhdev/feeder/compose/pages/OverlayPage.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,84 @@
/*
* This file is part of Neo Feed
* Copyright (c) 2023 Saul Henriquez <[email protected]>
*
* 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 <https://www.gnu.org/licenses/>.
*/

package com.saulhdev.feeder.compose.pages

import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Divider
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.saulhdev.feeder.NFApplication
import com.saulhdev.feeder.R
import com.saulhdev.feeder.compose.components.ArticleItem
import com.saulhdev.feeder.compose.components.OverflowMenu
import com.saulhdev.feeder.compose.components.ViewWithActionBar
import com.saulhdev.feeder.compose.icon.Phosphor
import com.saulhdev.feeder.compose.icon.phosphor.CloudArrowDown
import com.saulhdev.feeder.compose.icon.phosphor.CloudArrowUp
import com.saulhdev.feeder.compose.navigation.LocalNavController
import com.saulhdev.feeder.compose.navigation.Routes
import com.saulhdev.feeder.db.ArticleRepository
import com.saulhdev.feeder.models.exportOpml
import com.saulhdev.feeder.models.importOpml
import com.saulhdev.feeder.plugin.PluginConnector
import com.saulhdev.feeder.sdk.FeedItem
import com.saulhdev.feeder.sync.SyncRestClient
import com.saulhdev.feeder.utils.ApplicationCoroutineScope
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import org.kodein.di.compose.LocalDI
import org.kodein.di.instance
import java.time.LocalDateTime

@Composable
fun OverlayPage() {
/*val context = LocalContext.current
val context = LocalContext.current
val navController = LocalNavController.current
val di = LocalDI.current
val localTime = LocalDateTime.now().toString().replace(":", "_").substring(0, 19)

val repository = ArticleRepository(context)
val articles = SyncRestClient(context)
val repository = ArticleRepository(context)
val scope = CoroutineScope(Dispatchers.IO) + CoroutineName("NeoFeedSync")
val feedList = remember { arrayListOf<FeedItem>() }
*/
LaunchedEffect(key1 = null) {
/*scope.launch {
val feedList: SnapshotStateList<FeedItem> = remember { mutableStateListOf() }

LaunchedEffect(key1 = true) {
scope.launch {
val feeds = repository.getAllFeeds()
for (feed in feeds) {
articles.getArticleList(feed)
Expand All @@ -32,53 +87,107 @@ fun OverlayPage() {
PluginConnector.getFeedAsItLoads(0, { feed ->
feedList.addAll(feed)
}) {
feedList.sortByDescending { it.time }
feedList.sortedByDescending { it.time }
}
}
}

val opmlImporter = rememberLauncherForActivityResult(
ActivityResultContracts.OpenDocument()
) { uri ->
if (uri != null) {
val applicationCoroutineScope: ApplicationCoroutineScope by di.instance()
applicationCoroutineScope.launch {
importOpml(di, uri)
}
}*/
}
}

val opmlExporter = rememberLauncherForActivityResult(
ActivityResultContracts.CreateDocument("application/xml")
) { uri ->
if (uri != null) {
val applicationCoroutineScope: ApplicationCoroutineScope by di.instance()
applicationCoroutineScope.launch {
exportOpml(di, uri)
}
}
}

ViewWithActionBar(
title = stringResource(id = R.string.app_name),
floatingActionButton = { },
showBackButton = false,
actions = {
OverflowMenu {
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.title_settings))
Text(text = stringResource(id = R.string.action_reload))
},

onClick = {
hideMenu()
//navController.navigate(Routes.SETTINGS)
//refreshFeed()
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_settings_outline_28),
painter = painterResource(id = R.drawable.ic_replay_24),
contentDescription = null,
)
}
)
Divider()
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.action_reload))
Text(text = stringResource(id = R.string.sources_import_opml))
},
onClick = {
hideMenu()
opmlImporter.launch(arrayOf("text/plain", "text/xml", "text/opml", "*/*"))
},
leadingIcon = {
Icon(
Phosphor.CloudArrowDown,
contentDescription = null,
)
}
)
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.sources_export_opml))
},
onClick = {
hideMenu()
opmlExporter.launch("NF-${localTime}.opml")
},
leadingIcon = {
Icon(
Phosphor.CloudArrowUp,
contentDescription = null,
)
}
)
Divider()

DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.title_settings))
},
onClick = {
hideMenu()
//refreshFeed()
navController.navigate(Routes.SETTINGS)
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_replay_24),
painter = painterResource(id = R.drawable.ic_settings_outline_28),
contentDescription = null,
)
}
)

DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.action_restart))
},

onClick = {
hideMenu()
NFApplication.instance.restart(false)
Expand All @@ -93,20 +202,24 @@ fun OverlayPage() {
}
}
) { paddingValues ->
/*LazyColumn(
LazyColumn(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.primary)
.padding(
top = paddingValues.calculateTopPadding(),
bottom = paddingValues.calculateBottomPadding(), start = 8.dp, end = 8.dp
bottom = paddingValues.calculateBottomPadding(),
start = 8.dp,
end = 8.dp
)
) {
items(feedList.size) { index ->
val article = feedList[index]
ArticleItem(article = article, repository = repository)
val item = feedList[index]
ArticleItem(
article = item,
repository = repository
)
Spacer(modifier = Modifier.height(8.dp))
}
}*/
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/values-v27/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme" parent="HFBaseTheme">
<item name="android:statusBarColor">?colorSurface</item>
<item name="android:windowLightStatusBar">@bool/isLight</item>
<item name="android:windowLightNavigationBar">@bool/isLight</item>
</style>
</resources>

0 comments on commit 58afa1d

Please sign in to comment.