Skip to content

Commit

Permalink
Add bookmark button on reader mode - Fix #319
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Jan 4, 2025
1 parent d68532c commit df9668b
Show file tree
Hide file tree
Showing 25 changed files with 441 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import com.prof18.feedflow.android.readermode.ReaderModeViewModel
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.shared.di.getWith
Expand All @@ -14,7 +13,6 @@ import com.prof18.feedflow.shared.domain.feedsync.FeedSyncRepository
import com.prof18.feedflow.shared.ui.utils.coilImageLoader
import org.koin.android.ext.android.inject
import org.koin.androidx.workmanager.koin.workManagerFactory
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module

class FeedFlowApp : Application() {
Expand Down Expand Up @@ -69,12 +67,6 @@ class FeedFlowApp : Application() {
)
}
single { appConfig }
viewModel {
ReaderModeViewModel(
readerModeExtractor = get(),
settingsRepository = get(),
)
}
},
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ import com.prof18.feedflow.android.editfeed.toFeedSource
import com.prof18.feedflow.android.feedsourcelist.FeedSourceListScreen
import com.prof18.feedflow.android.home.HomeScreen
import com.prof18.feedflow.android.readermode.ReaderModeScreen
import com.prof18.feedflow.android.readermode.ReaderModeViewModel
import com.prof18.feedflow.android.search.SearchScreen
import com.prof18.feedflow.android.settings.SettingsScreen
import com.prof18.feedflow.android.settings.about.AboutScreen
import com.prof18.feedflow.android.settings.about.LicensesScreen
import com.prof18.feedflow.android.settings.importexport.ImportExportScreen
import com.prof18.feedflow.core.model.FeedItemId
import com.prof18.feedflow.core.model.FeedSource
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncMessageQueue
import com.prof18.feedflow.shared.domain.model.SyncResult
import com.prof18.feedflow.shared.presentation.EditFeedViewModel
import com.prof18.feedflow.shared.presentation.ReaderModeViewModel
import com.prof18.feedflow.shared.ui.utils.LocalFeedFlowStrings
import com.prof18.feedflow.shared.ui.utils.ProvideFeedFlowStrings
import com.prof18.feedflow.shared.ui.utils.rememberFeedFlowStrings
Expand Down Expand Up @@ -243,6 +244,9 @@ class MainActivity : ComponentActivity() {
onUpdateFontSize = { newFontSize ->
readerModeViewModel.updateFontSize(newFontSize)
},
onBookmarkClick = { feedItemId: FeedItemId, isBookmarked: Boolean ->
readerModeViewModel.updateBookmarkStatus(feedItemId, isBookmarked)
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.multiplatform.webview.web.WebViewNavigator
import com.multiplatform.webview.web.rememberWebViewNavigator
import com.multiplatform.webview.web.rememberWebViewStateWithHTMLData
import com.prof18.feedflow.android.BrowserManager
import com.prof18.feedflow.core.model.FeedItemId
import com.prof18.feedflow.core.model.ReaderModeState
import com.prof18.feedflow.shared.domain.ReaderColors
import com.prof18.feedflow.shared.domain.getReaderModeStyledHtml
Expand All @@ -31,6 +32,7 @@ internal fun ReaderModeScreen(
readerModeState: ReaderModeState,
fontSize: Int,
onUpdateFontSize: (Int) -> Unit,
onBookmarkClick: (FeedItemId, Boolean) -> Unit,
navigateBack: () -> Unit,
) {
val browserManager = koinInject<BrowserManager>()
Expand Down Expand Up @@ -80,6 +82,7 @@ internal fun ReaderModeScreen(
navigator = navigator,
)
},
onBookmarkClick = onBookmarkClick,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ data class FeedItemUrlInfo(
val url: String,
val title: String?,
val openOnlyOnBrowser: Boolean = false,
val isBookmarked: Boolean,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.prof18.feedflow.core.model

data class ReaderModeData(
val id: FeedItemId,
val title: String?,
val content: String,
val url: String,
val fontSize: Int,
val isBookmarked: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ package com.prof18.feedflow.core.model
sealed interface ReaderModeState {
data object Loading : ReaderModeState
data class Success(val readerModeData: ReaderModeData) : ReaderModeState
data class HtmlNotAvailable(val url: String) : ReaderModeState
data class HtmlNotAvailable(
val url: String,
val id: String,
val isBookmarked: Boolean,
) : ReaderModeState

val getIsBookmarked: Boolean
get() = when (this) {
is Loading -> false
is Success -> readerModeData.isBookmarked
is HtmlNotAvailable -> isBookmarked
}
}
1 change: 0 additions & 1 deletion desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ kotlin {
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)

implementation(libs.flexmark.html2md.converter)
implementation(libs.multiplatform.markdown.renderer.m3)
implementation(libs.multiplatform.markdown.renderer.coil)
implementation(libs.voyager.navigator)
Expand Down
13 changes: 0 additions & 13 deletions desktopApp/src/jvmMain/kotlin/com/prof18/feedflow/desktop/di/DI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package com.prof18.feedflow.desktop.di
import coil3.PlatformContext
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.desktop.BrowserManager
import com.prof18.feedflow.desktop.reaadermode.MarkdownToHtmlConverter
import com.prof18.feedflow.desktop.reaadermode.ReaderModeViewModel
import com.prof18.feedflow.desktop.versionchecker.NewVersionChecker
import com.prof18.feedflow.shared.di.getWith
import com.prof18.feedflow.shared.di.initKoinDesktop
import com.prof18.feedflow.shared.ui.utils.coilImageLoader
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter
import org.koin.core.Koin
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.module

object DI {
Expand All @@ -36,15 +32,6 @@ object DI {
)
}

single {
MarkdownToHtmlConverter(
converter = FlexmarkHtmlConverter.builder().build(),
dispatcherProvider = get(),
)
}

factoryOf(::ReaderModeViewModel)

factory {
BrowserManager(
settingsRepository = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import com.mikepenz.markdown.coil3.Coil3ImageTransformerImpl
import com.mikepenz.markdown.m3.Markdown
import com.mikepenz.markdown.m3.markdownTypography
import com.prof18.feedflow.core.model.FeedItemId
import com.prof18.feedflow.core.model.FeedItemUrlInfo
import com.prof18.feedflow.desktop.desktopViewModel
import com.prof18.feedflow.desktop.di.DI
import com.prof18.feedflow.desktop.openInBrowser
import com.prof18.feedflow.shared.presentation.ReaderModeViewModel
import com.prof18.feedflow.shared.ui.readermode.ReaderModeContent
import com.prof18.feedflow.shared.ui.style.Spacing
import com.prof18.feedflow.shared.ui.utils.LocalFeedFlowStrings
Expand Down Expand Up @@ -78,8 +80,6 @@ internal data class ReaderModeScreen(
},
fontSize = fontSize,
onFontSizeChange = {


readerModeViewModel.updateFontSize(it)
},
readerModeSuccessView = { contentPadding, successState ->
Expand All @@ -88,7 +88,7 @@ internal data class ReaderModeScreen(
.padding(contentPadding)
.verticalScroll(rememberScrollState()),

) {
) {
Text(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -118,6 +118,9 @@ internal data class ReaderModeScreen(
)
}
},
onBookmarkClick = { feedItemId: FeedItemId, isBookmarked: Boolean ->
readerModeViewModel.updateBookmarkStatus(feedItemId, isBookmarked)
},
)
}
}
Loading

0 comments on commit df9668b

Please sign in to comment.