Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Aug 14, 2024
1 parent 9cd0204 commit 1a0a518
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,18 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.google.accompanist.web.AccompanistWebViewClient
import com.google.accompanist.web.LoadingState
import com.google.accompanist.web.WebView
import com.google.accompanist.web.rememberWebViewNavigator
import com.google.accompanist.web.rememberWebViewState
import com.saulhdev.feeder.compose.navigation.preferenceGraph
import com.saulhdev.feeder.utils.urlDecode

@Composable
fun ComposeWebView(
pageUrl: String
) {
// TODO migrate to ??!
val url by remember { mutableStateOf(pageUrl) }
val state = rememberWebViewState(url = url)
val navigator = rememberWebViewNavigator()
Expand Down Expand Up @@ -126,18 +121,4 @@ fun ComposeWebView(

}
}
}

fun NavGraphBuilder.webViewerGraph(route: String) {
preferenceGraph(route, { }) { subRoute ->
composable(
route = subRoute("{url}"),
arguments = listOf(navArgument("url") { type = NavType.StringType })
) { backStackEntry ->
val url = backStackEntry.arguments?.getString("url")?.urlDecode()
if (url != null) {
ComposeWebView(pageUrl = url)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkHorizontally
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -37,7 +36,6 @@ import com.saulhdev.feeder.compose.navigation.NavItem
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.launch

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun NonSlidePager(
modifier: Modifier = Modifier,
Expand All @@ -49,7 +47,6 @@ fun NonSlidePager(
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SlidePager(
modifier: Modifier = Modifier,
Expand All @@ -61,7 +58,6 @@ fun SlidePager(
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun PagerNavBar(pageItems: List<NavItem>, pagerState: PagerState) {
val scope = rememberCoroutineScope()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ sealed class NavItem(
NavItem(R.string.title_settings, Phosphor.GearSix, Routes.SETTINGS, {
PreferencesPage()
})

data object Sources :
NavItem(R.string.title_sources, Phosphor.Graph, Routes.SOURCES, {
SourcesPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import androidx.compose.runtime.compositionLocalOf
import androidx.navigation.NamedNavArgument
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink

// TODO consider removing

inline fun NavGraphBuilder.preferenceGraph(
route: String,
crossinline root: @Composable () -> Unit,
crossinline block: NavGraphBuilder.(subRoute: (String) -> String) -> Unit = { }
) {
val subRoute: (String) -> String = { name -> "$route$name/" }
val subRoute: (String) -> String = { name -> "$route/$name/" }
composable(route = route) {
CompositionLocalProvider(LocalRoute provides route) {
root()
Expand All @@ -46,10 +49,15 @@ inline fun NavGraphBuilder.preferenceGraphWithArgs(
crossinline root: @Composable (Bundle?) -> Unit,
crossinline block: NavGraphBuilder.(subRoute: (String) -> String) -> Unit = { }
) {
val subRoute: (String) -> String = { name -> "$route$name/" }
val subRoute: (String) -> String = { name -> "$route/$name/" }
composable(
route = route + suffix,
route = "$route$suffix",
arguments = args,
deepLinks = listOf(
navDeepLink {
uriPattern = "$NAV_BASE$route$suffix"
}
)
) {
CompositionLocalProvider(LocalRoute provides route) {
root(it.arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ fun saveFeed(results: List<SearchResult>, repository: ArticleRepository) {
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AddFeedView(
feedUrl: String = "",
Expand Down Expand Up @@ -210,7 +209,6 @@ fun AddFeedView(
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SearchFeedUI(
feedUrl: String,
Expand Down Expand Up @@ -330,7 +328,6 @@ fun SearchingIndicator() {
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchResultView(
title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.saulhdev.feeder.MainActivity
import com.saulhdev.feeder.R
import com.saulhdev.feeder.compose.components.RoundButton
import com.saulhdev.feeder.compose.components.ViewWithActionBar
import com.saulhdev.feeder.compose.components.WithBidiDeterminedLayoutDirection
import com.saulhdev.feeder.compose.navigation.Routes
import com.saulhdev.feeder.compose.navigation.preferenceGraph
import com.saulhdev.feeder.db.ArticleRepository
import com.saulhdev.feeder.icon.phosphor.ArrowSquareOut
import com.saulhdev.feeder.icon.phosphor.ShareNetwork
Expand Down Expand Up @@ -227,18 +222,4 @@ fun NotFoundView() {
Column(modifier = Modifier.padding(16.dp)) {
Text(text = stringResource(id = R.string.article_not_found))
}
}

fun NavGraphBuilder.articleGraph(route: String) {
preferenceGraph(route, { }) { subRoute ->
composable(
route = subRoute("{id}"),
arguments = listOf(navArgument("id") { type = NavType.LongType })
) { backStackEntry ->
val id = backStackEntry.arguments?.getLong("id") ?: 0
if (id != 0L) {
ArticleScreen(articleId = id)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester.Companion.createRefs
import androidx.compose.ui.focus.focusRequester
Expand All @@ -49,15 +48,10 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.saulhdev.feeder.R
import com.saulhdev.feeder.compose.components.ComposeSwitchView
import com.saulhdev.feeder.compose.components.ViewWithActionBar
import com.saulhdev.feeder.compose.navigation.LocalNavController
import com.saulhdev.feeder.compose.navigation.preferenceGraph
import com.saulhdev.feeder.compose.util.interceptKey
import com.saulhdev.feeder.models.EditFeedViewState
import com.saulhdev.feeder.viewmodel.EditFeedViewModel
Expand Down Expand Up @@ -92,7 +86,6 @@ fun EditFeedPage(feedId: Long = -1) {
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun EditFeedView(
viewState: EditFeedViewState,
Expand Down Expand Up @@ -216,21 +209,4 @@ fun EditFeedView(
}
}
}
}

fun NavGraphBuilder.editFeedGraph(route: String) {
preferenceGraph(route, { }) { subRoute ->
composable(
route = subRoute("{feedId}"),
arguments = listOf(
navArgument("feedId") { type = NavType.LongType }
)
) { backStackEntry ->
val args = backStackEntry.arguments!!
val feedId = args.getLong("feedId")
EditFeedPage(
feedId = feedId
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.saulhdev.feeder.compose.pages

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.rememberPagerState
Expand All @@ -13,7 +12,6 @@ import com.saulhdev.feeder.compose.components.SlidePager
import com.saulhdev.feeder.compose.navigation.NavItem
import kotlinx.collections.immutable.persistentListOf

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MainPage(pageIndex: Int = 0) {
val pages = persistentListOf(
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/saulhdev/feeder/feed/FeedAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class FeedAdapter : RecyclerView.Adapter<FeedAdapter.FeedViewHolder>() {
private var theme: SparseIntArray? = null

fun replace(new: List<FeedItem>) {
list = new
notifyDataSetChanged()
if (new != list) {
list = new
notifyDataSetChanged()
}
}

fun setTheme(theme: SparseIntArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,6 @@ class FeedPreferences private constructor(val context: Context) {
defaultValue = setOf()
)

var overlay = StringPref(
titleId = R.string.app_name,
icon = Phosphor.Info,
key = OVERLAY,
dataStore = dataStore,
route = "/${Routes.OVERLAY}/"
)

var about = StringPref(
titleId = R.string.title_about,
icon = Phosphor.Info,
Expand Down
35 changes: 2 additions & 33 deletions app/src/main/java/com/saulhdev/feeder/utils/HFPluginService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ import android.os.Bundle
import android.os.IBinder
import com.saulhdev.feeder.db.ArticleRepository
import com.saulhdev.feeder.db.models.Feed
import com.saulhdev.feeder.models.StoryCardContent
import com.saulhdev.feeder.sdk.FeedCategory
import com.saulhdev.feeder.sdk.FeedItem
import com.saulhdev.feeder.sdk.FeedItemType
import com.saulhdev.feeder.sdk.IFeedInterface
import com.saulhdev.feeder.sdk.IFeedInterfaceCallback
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Date
import org.koin.java.KoinJavaComponent.inject

class HFPluginService : Service(), CoroutineScope by MainScope() {
Expand All @@ -43,38 +38,12 @@ class HFPluginService : Service(), CoroutineScope by MainScope() {

feedList.forEach { feed ->
repository.getFeedArticles(feed).forEach { article ->
list.add(
FeedItem(
id = article.id,
title = "${feed.title} [RSS]",
type = FeedItemType.STORY_CARD,
content = StoryCardContent(
title = article.title,
text = article.description,
background_url = article.imageUrl ?: "",
link = article.link ?: "",
source = FeedCategory(
feed.url.toString(),
feed.title,
Color.GREEN,
feed.feedImage.toString()
)
),
bookmarked = article.bookmarked,
time = Date.from(
ZonedDateTime.parse(
article.pubDate.toString(),
DateTimeFormatter.ISO_ZONED_DATE_TIME
).toInstant()
).time
)
)
list.add(FeedItem(article, feed))
}

}
}

callback.onFeedReceive(list)
callback.onFeedReceive(list) // TODO Simplify
}
}

Expand Down

0 comments on commit 1a0a518

Please sign in to comment.