diff --git a/app/src/main/java/com/saulhdev/feeder/MainActivity.kt b/app/src/main/java/com/saulhdev/feeder/MainActivity.kt index 651a1813..8019e9bc 100644 --- a/app/src/main/java/com/saulhdev/feeder/MainActivity.kt +++ b/app/src/main/java/com/saulhdev/feeder/MainActivity.kt @@ -135,7 +135,7 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner { }.launch(intent.getParcelableExtra("import")) } - else -> { + else -> { registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { launchOpmlExporter() finish() @@ -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() { @@ -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 diff --git a/app/src/main/java/com/saulhdev/feeder/NFApplication.kt b/app/src/main/java/com/saulhdev/feeder/NFApplication.kt index 29f496a3..9529dfb5 100644 --- a/app/src/main/java/com/saulhdev/feeder/NFApplication.kt +++ b/app/src/main/java/com/saulhdev/feeder/NFApplication.kt @@ -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 @@ -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 @@ -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() @@ -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() diff --git a/app/src/main/java/com/saulhdev/feeder/compose/components/FeedItem.kt b/app/src/main/java/com/saulhdev/feeder/compose/components/FeedItem.kt index 04a0d38c..478c47a6 100644 --- a/app/src/main/java/com/saulhdev/feeder/compose/components/FeedItem.kt +++ b/app/src/main/java/com/saulhdev/feeder/compose/components/FeedItem.kt @@ -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( diff --git a/app/src/main/java/com/saulhdev/feeder/compose/pages/PreferencesPage.kt b/app/src/main/java/com/saulhdev/feeder/compose/pages/PreferencesPage.kt index ca9f4ce9..93aafcc2 100644 --- a/app/src/main/java/com/saulhdev/feeder/compose/pages/PreferencesPage.kt +++ b/app/src/main/java/com/saulhdev/feeder/compose/pages/PreferencesPage.kt @@ -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 @@ -66,7 +67,7 @@ fun PreferencesPage() { ) val themePrefs = listOf( prefs.overlayTheme, - prefs.cardBackground, + //prefs.cardBackground, prefs.overlayTransparency, ) val debugPrefs = listOf( diff --git a/app/src/main/java/com/saulhdev/feeder/compose/pages/SourcesPage.kt b/app/src/main/java/com/saulhdev/feeder/compose/pages/SourcesPage.kt index 5c37f81c..0fdd16b2 100644 --- a/app/src/main/java/com/saulhdev/feeder/compose/pages/SourcesPage.kt +++ b/app/src/main/java/com/saulhdev/feeder/compose/pages/SourcesPage.kt @@ -168,8 +168,8 @@ fun SourcesPage() { ) }, onRemoveAction = { - showDialog.value = true removeItem.value = item + showDialog.value = true } ) } diff --git a/app/src/main/java/com/saulhdev/feeder/db/ArticleRepository.kt b/app/src/main/java/com/saulhdev/feeder/db/ArticleRepository.kt index 4d5c1721..de760822 100644 --- a/app/src/main/java/com/saulhdev/feeder/db/ArticleRepository.kt +++ b/app/src/main/java/com/saulhdev/feeder/db/ArticleRepository.kt @@ -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 = articleDao.findFeedById(feed.id) + val list: List = 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 { - return articleDao.loadFeeds() + return feedSourceDao.loadFeeds() } fun getFeedById(id: Long): Flow { - 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) } } @@ -141,7 +143,7 @@ class ArticleRepository(context: Context) { fun getBookmarkedArticlesMap(): Flow> = feedArticleDao.allBookmarked.mapLatest { it.associateWith { fa -> - articleDao.findFeedById(fa.feedId).first() + feedSourceDao.findFeedById(fa.feedId).first() } } } \ No newline at end of file diff --git a/app/src/main/java/com/saulhdev/feeder/launcherapi/OverlayThemeHolder.kt b/app/src/main/java/com/saulhdev/feeder/launcherapi/OverlayThemeHolder.kt index de45937b..54f29dad 100644 --- a/app/src/main/java/com/saulhdev/feeder/launcherapi/OverlayThemeHolder.kt +++ b/app/src/main/java/com/saulhdev/feeder/launcherapi/OverlayThemeHolder.kt @@ -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 @@ -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 */ @@ -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 */ @@ -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) - } } } \ No newline at end of file diff --git a/app/src/main/java/com/saulhdev/feeder/overlay/ComposeOverlayView.kt b/app/src/main/java/com/saulhdev/feeder/overlay/ComposeOverlayView.kt index c8ddbbda..32cb47f5 100644 --- a/app/src/main/java/com/saulhdev/feeder/overlay/ComposeOverlayView.kt +++ b/app/src/main/java/com/saulhdev/feeder/overlay/ComposeOverlayView.kt @@ -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) : @@ -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) } } diff --git a/app/src/main/java/com/saulhdev/feeder/preference/FeedPreferences.kt b/app/src/main/java/com/saulhdev/feeder/preference/FeedPreferences.kt index ee2c70c4..cf006184 100644 --- a/app/src/main/java/com/saulhdev/feeder/preference/FeedPreferences.kt +++ b/app/src/main/java/com/saulhdev/feeder/preference/FeedPreferences.kt @@ -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 @@ -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( diff --git a/app/src/main/java/com/saulhdev/feeder/sync/RssLocalSync.kt b/app/src/main/java/com/saulhdev/feeder/sync/RssLocalSync.kt index 2c6b0ebf..f0f3070a 100644 --- a/app/src/main/java/com/saulhdev/feeder/sync/RssLocalSync.kt +++ b/app/src/main/java/com/saulhdev/feeder/sync/RssLocalSync.kt @@ -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(), @@ -169,7 +169,7 @@ private suspend fun syncFeed( }.let { when { it.icon?.startsWith("data") == true -> it.copy(icon = null) - else -> it + else -> it } } @@ -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, @@ -253,6 +254,6 @@ internal suspend fun feedsToSync( feedDao.loadFeed(feedId)?.let { listOf(it) } ?: emptyList() }*/ - else -> repository.loadFeeds() + else -> repository.loadFeeds() } } diff --git a/app/src/main/java/com/saulhdev/feeder/utils/OverlayBridge.kt b/app/src/main/java/com/saulhdev/feeder/utils/OverlayBridge.kt index 9fe5ebcb..88e96098 100644 --- a/app/src/main/java/com/saulhdev/feeder/utils/OverlayBridge.kt +++ b/app/src/main/java/com/saulhdev/feeder/utils/OverlayBridge.kt @@ -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) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2a1d80fb..431574c3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -119,4 +119,5 @@ Service Other Web browser not found + Overlay \ No newline at end of file