Skip to content

Commit

Permalink
Clean up (& remove cardBG pref for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Aug 10, 2024
1 parent 3d2b4fb commit b3004db
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 84 deletions.
41 changes: 16 additions & 25 deletions app/src/main/java/com/saulhdev/feeder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {
}.launch(intent.getParcelableExtra("import"))
}

else -> {
else -> {
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
launchOpmlExporter()
finish()
Expand All @@ -162,34 +162,25 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {
}

private fun observePrefs() {
var recreate = false
val oldTheme = prefs.overlayTheme.getValue()
val oldTransparency = prefs.overlayTransparency.getValue()
//val oldCardBackground = prefs.cardBackground.getValue()

prefs.overlayTheme.get().asLiveData().observe(this) {
isDarkTheme = when (it) {
"auto_system" -> isSystemDark()
"dark" -> true
else -> false
if (it != oldTheme) {
recreate()
}
recreate = true
}
prefs.overlayTransparency.get().asLiveData().observe(this) {
recreate = true
}
prefs.cardBackground.get().asLiveData().observe(this) {
recreate = true
}

if (recreate) {
recreate()
recreate = false
}
}

private fun isSystemDark(): Boolean {
return when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> true
Configuration.UI_MODE_NIGHT_NO -> false
else -> false
if (it != oldTransparency) {
recreate()
}
}
/*prefs.cardBackground.get().asLiveData().observe(this) {
if (it != oldCardBackground) {
recreate()
}
}*/
}

override fun onRestart() {
Expand Down Expand Up @@ -230,7 +221,7 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {
workManager.enqueueUniquePeriodicWork(
"feeder_periodic_3",
when (replace) {
true -> ExistingPeriodicWorkPolicy.UPDATE
true -> ExistingPeriodicWorkPolicy.UPDATE
false -> ExistingPeriodicWorkPolicy.KEEP
},
syncWork
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/java/com/saulhdev/feeder/NFApplication.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saulhdev.feeder

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.lifecycle.SavedStateHandle
Expand All @@ -26,6 +27,7 @@ import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.core.context.GlobalContext
import org.koin.core.context.startKoin
import org.koin.dsl.module
import java.lang.ref.WeakReference

Expand Down Expand Up @@ -73,11 +75,6 @@ class NFApplication : MultiDexApplication() {
super.onCreate()
instance = this
AndroidThreeTen.init(this)
GlobalContext.startKoin {
androidLogger()
androidContext(this@NFApplication)
modules(coreModule, dataModule, modelModule)
}
DynamicColors.applyToActivitiesIfAvailable(
this,
DynamicColorsOptions.Builder()
Expand All @@ -87,6 +84,16 @@ class NFApplication : MultiDexApplication() {
PluginFetcher.init(this)
}

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)

startKoin {
androidLogger()
androidContext(this@NFApplication)
modules(coreModule, dataModule, modelModule)
}
}

override fun onTerminate() {
super.onTerminate()
GlobalContext.get().close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ fun FeedItem(
mutableStateOf(feed.isEnabled)
}
val backgroundColor by animateColorAsState(
targetValue = if (isEnabled) MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceContainer, label = ""
targetValue = if (isEnabled) MaterialTheme.colorScheme.surfaceContainerHighest
else MaterialTheme.colorScheme.surfaceContainerLowest, label = ""
)

ListItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fun PreferencesPage() {
val title = stringResource(id = R.string.title_settings)
ViewWithActionBar(
title = title,
showBackButton = false,
) { paddingValues ->
val prefs = FeedPreferences.getInstance(LocalContext.current)
val navController = LocalNavController.current
Expand All @@ -66,7 +67,7 @@ fun PreferencesPage() {
)
val themePrefs = listOf(
prefs.overlayTheme,
prefs.cardBackground,
//prefs.cardBackground,
prefs.overlayTransparency,
)
val debugPrefs = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ fun SourcesPage() {
)
},
onRemoveAction = {
showDialog.value = true
removeItem.value = item
showDialog.value = true
}
)
}
Expand Down
34 changes: 18 additions & 16 deletions app/src/main/java/com/saulhdev/feeder/db/ArticleRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,56 @@ import java.net.URL

class ArticleRepository(context: Context) {
private val scope = CoroutineScope(Dispatchers.IO) + CoroutineName("FeedArticleRepository")
private val articleDao = NeoFeedDb.getInstance(context).feedSourceDao()
private val feedSourceDao = NeoFeedDb.getInstance(context).feedSourceDao()

fun insertFeed(feed: Feed) {
scope.launch {
articleDao.insert(feed)
feedSourceDao.insert(feed)
}
}

fun updateFeed(title: String, url: URL, fullTextByDefault: Boolean, isEnabled: Boolean) {
scope.launch {
val feed = articleDao.getFeedByURL(url)
feed.title = title
feed.url = url
feed.fullTextByDefault = fullTextByDefault
feed.isEnabled = isEnabled
articleDao.update(feed)
val feed = feedSourceDao.getFeedByURL(url)
.copy(
title = title,
url = url,
fullTextByDefault = fullTextByDefault,
isEnabled = isEnabled
)
feedSourceDao.update(feed)
}
}

fun updateFeed(feed: Feed) {
scope.launch {
val list: List<Feed> = articleDao.findFeedById(feed.id)
val list: List<Feed> = feedSourceDao.findFeedById(feed.id)
if (list.isNotEmpty()) {
feed.lastSync = ZonedDateTime.now().toInstant()
articleDao.update(feed)
feedSourceDao.update(feed)
}
}
}

suspend fun getFeed(feedId: Long): Feed = articleDao.loadFeedById(feedId)
suspend fun getFeed(feedId: Long): Feed = feedSourceDao.loadFeedById(feedId)

fun getAllFeeds(): List<Feed> {
return articleDao.loadFeeds()
return feedSourceDao.loadFeeds()
}

fun getFeedById(id: Long): Flow<Feed> {
return articleDao.getFeedById(id)
return feedSourceDao.getFeedById(id)
}

fun setCurrentlySyncingOn(feedId: Long, syncing: Boolean) {
scope.launch {
articleDao.setCurrentlySyncingOn(feedId, syncing)
feedSourceDao.setCurrentlySyncingOn(feedId, syncing)
}
}

fun setCurrentlySyncingOn(feedId: Long, syncing: Boolean, lastSync: Instant) {
scope.launch {
articleDao.setCurrentlySyncingOn(feedId, syncing, lastSync)
feedSourceDao.setCurrentlySyncingOn(feedId, syncing, lastSync)
}
}

Expand Down Expand Up @@ -141,7 +143,7 @@ class ArticleRepository(context: Context) {
fun getBookmarkedArticlesMap(): Flow<Map<FeedArticle, Feed>> =
feedArticleDao.allBookmarked.mapLatest {
it.associateWith { fa ->
articleDao.findFeedById(fa.feedId).first()
feedSourceDao.findFeedById(fa.feedId).first()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.saulhdev.feeder.launcherapi

import android.content.Context
import android.util.SparseIntArray
import androidx.core.content.ContextCompat
import com.saulhdev.feeder.R
import com.saulhdev.feeder.overlay.OverlayView
import com.saulhdev.feeder.preference.FeedPreferences
import com.saulhdev.feeder.theme.Theming
Expand All @@ -21,11 +19,6 @@ class OverlayThemeHolder(private val context: Context, private val overlay: Over
*/
var currentTheme = Theming.defaultDarkThemeColors

/**
* Card background
*/
var cardBgPref = prefs.cardBackground.getValue()

/**
* If we should apply light statusbar/navbar
*/
Expand All @@ -41,16 +34,6 @@ class OverlayThemeHolder(private val context: Context, private val overlay: Over
*/
var systemColors = false

/**
* Parses [cardBgPref] into color integer
*/
private val cardBackground: Int
get() = when (cardBgPref) {
"theme" -> currentTheme.get(Theming.Colors.CARD_BG.ordinal)
"dark" -> ContextCompat.getColor(context, R.color.card_bg_dark)
else -> ContextCompat.getColor(context, R.color.card_bg)
}

/**
* Replaces the color mapping ([currentTheme]) with config-specified values
*/
Expand All @@ -61,9 +44,5 @@ class OverlayThemeHolder(private val context: Context, private val overlay: Over
isSNApplied = false
overlay.window.decorView.clearLightFlags()
}

if (cardBgPref != "theme") {
currentTheme.put(Theming.Colors.CARD_BG.ordinal, cardBackground)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.saulhdev.feeder.MainActivity
import com.saulhdev.feeder.R
import com.saulhdev.feeder.compose.pages.OverlayPage
import com.saulhdev.feeder.theme.AppTheme
import com.saulhdev.feeder.utils.isDarkTheme
import org.koin.java.KoinJavaComponent.inject

class ComposeOverlayView(val context: Context) :
Expand Down Expand Up @@ -86,7 +87,9 @@ class ComposeOverlayView(val context: Context) :
composeView = rootView.findViewById(R.id.compose_view)
composeView.setContent {
navController = rememberNavController()
AppTheme {
AppTheme(
darkTheme = context.isDarkTheme
) {
OverlayPage(navController = navController)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ import com.saulhdev.feeder.icon.phosphor.Graph
import com.saulhdev.feeder.icon.phosphor.Hash
import com.saulhdev.feeder.icon.phosphor.Info
import com.saulhdev.feeder.icon.phosphor.PaintRoller
import com.saulhdev.feeder.icon.phosphor.SelectionBackground
import com.saulhdev.feeder.icon.phosphor.SubtractSquare
import com.saulhdev.feeder.icon.phosphor.WifiHigh
import com.saulhdev.feeder.utils.getBackgroundOptions
import com.saulhdev.feeder.utils.getItemsPerFeed
import com.saulhdev.feeder.utils.getSyncFrequency
import com.saulhdev.feeder.utils.getThemes
Expand Down Expand Up @@ -79,14 +77,14 @@ class FeedPreferences private constructor(val context: Context) {
specialOutputs = { "${(it * 100).roundToInt()}%" }
)

var cardBackground = StringSelectionPref(
/*var cardBackground = StringSelectionPref(
titleId = R.string.pref_card_bg,
icon = Phosphor.SelectionBackground,
key = OVERLAY_CARD_BACKGROUND,
dataStore = dataStore,
defaultValue = "theme",
entries = getBackgroundOptions(context)
)
)*/

/* Sources */
var sources = StringPref(
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/java/com/saulhdev/feeder/sync/RssLocalSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private suspend fun syncFeed(
throw ResponseFailure("${response.code} when fetching ${feedSql.title}: ${feedSql.url}")
}

else -> {
else -> {
Log.d(TAG, "Fetching correct ${feedSql.title}")
feedParser.parseFeedResponse(
url = response.request.url.toUrl(),
Expand All @@ -169,7 +169,7 @@ private suspend fun syncFeed(
}.let {
when {
it.icon?.startsWith("data") == true -> it.copy(icon = null)
else -> it
else -> it
}
}

Expand Down Expand Up @@ -197,11 +197,12 @@ private suspend fun syncFeed(
}
}
}
feedSql.title = feedSql.title

feedSql.feedImage = feed.icon?.let { sloppyLinkToStrictURLNoThrows(it) }
?: feedSql.feedImage
repository.updateFeed(feedSql)
repository.updateFeed(feedSql.copy(
title = feedSql.title,
feedImage = feed.icon?.let { sloppyLinkToStrictURLNoThrows(it) }
?: feedSql.feedImage
))

val ids = repository.getItemsToBeCleanedFromFeed(
feedId = feedSql.id,
Expand Down Expand Up @@ -253,6 +254,6 @@ internal suspend fun feedsToSync(
feedDao.loadFeed(feedId)?.let { listOf(it) } ?: emptyList()
}*/

else -> repository.loadFeeds()
else -> repository.loadFeeds()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OverlayBridge {

interface OverlayBridgeCallback {
fun applyNewTheme(value: String)
fun applyNewCardBg(value: String)
//fun applyNewCardBg(value: String)
fun applyCompactCard(value: Boolean)
fun applySysColors(value: Boolean)
fun applyNewTransparency(value: Float)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@
<string name="title_service">Service</string>
<string name="title_other">Other</string>
<string name="no_activity_for_link">Web browser not found</string>
<string name="title_overlay">Overlay</string>
</resources>

0 comments on commit b3004db

Please sign in to comment.