Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ fun DesktopApp(
.background(MaterialTheme.colorScheme.background)
) {
Navigation(
isDarkTheme = colorTheme.isDarkTheme(),
startDestination = startDestination,
notesMenuInjection = notesMenuInjection,
sideMenuKmpInjector = sideMenuInjector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
Expand Down Expand Up @@ -90,6 +92,8 @@ fun NavigationGraph(

val navigationViewModel = viewModel { MobileNavigationViewModel() }

val colorTheme by uiConfigViewModel.listenForColorTheme { "disconnected_user" }.collectAsState()

AppMobile(
startDestination = startDestination,
navController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fun AppMobile(
) { padding ->
Box(modifier = Modifier.padding(padding)) {
Navigation(
isDarkTheme = colorTheme.isDarkTheme(),
startDestination = startDestination,
notesMenuInjection = notesMenuInjection,
navController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.window.ComposeUIViewController
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.rememberNavController
import io.writeopia.auth.core.token.AppBearerTokenHandler
import io.writeopia.auth.di.AuthInjection
import io.writeopia.auth.navigation.authNavigation
import io.writeopia.common.utils.NotesNavigation
import io.writeopia.editor.di.EditorKmpInjector
import io.writeopia.features.search.di.KmpSearchInjection
import io.writeopia.mobile.AppMobile
import io.writeopia.navigation.MobileNavigationViewModel
import io.writeopia.common.utils.NotesNavigation
import io.writeopia.notemenu.di.NotesMenuKmpInjection
import io.writeopia.notemenu.di.UiConfigurationInjector
import io.writeopia.notemenu.navigation.navigateToNotes
import io.writeopia.sdk.network.injector.ConnectionInjector
import io.writeopia.sqldelight.database.DatabaseCreation
import io.writeopia.sqldelight.database.DatabaseFactory
import io.writeopia.sqldelight.database.driver.DriverFactory
Expand Down Expand Up @@ -55,25 +53,9 @@ fun MainViewController() = ComposeUIViewController {
NotesMenuKmpInjection.mobile(sqlDelightDaoInjector)
}

val connectionInjection =
remember {
ConnectionInjector(
bearerTokenHandler = AppBearerTokenHandler,
baseUrl = "https://writeopia.io/api",
disableWebsocket = true
)
}

val editorInjector = EditorKmpInjector.mobile(
sqlDelightDaoInjector,
connectionInjection,
uiConfigurationInjector.provideUiConfigurationRepository(),
)
val editorInjector = EditorKmpInjector.mobile(sqlDelightDaoInjector)

val authInjection = AuthInjection(
connectionInjection,
sqlDelightDaoInjector
)
val authInjection = AuthInjection(sqlDelightDaoInjector)
val navigationViewModel = viewModel { MobileNavigationViewModel() }

val navController = rememberNavController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import io.writeopia.notemenu.navigation.notesMenuNavigation
@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
fun Navigation(
isDarkTheme: Boolean,
startDestination: String = Destinations.AUTH_MENU_INNER_NAVIGATION.id,
navController: NavHostController = rememberNavController(),
notesMenuInjection: NotesMenuInjection,
Expand Down Expand Up @@ -62,6 +63,7 @@ fun Navigation(
}

editorNavigation(
isDarkTheme = isDarkTheme,
navigateBack = {
navController.navigateUp()
},
Expand Down
5,850 changes: 2,946 additions & 2,904 deletions application/core/resources/config/ktlint/baseline.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@
<string name="ok">ok</string>
<string name="summarize">Summarize</string>
<string name="action_points">Action Points</string>
<string name="highlight">Highlighting</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@
<string name="ok">Confirmar</string>
<string name="summarize">Resumir</string>
<string name="action_points">Acionáveis</string>
<string name="highlight">Marca texto</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@
<string name="ok">ok</string>
<string name="summarize">Summarize</string>
<string name="action_points">Action Points</string>
<string name="highlight">Highlighting</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import writeopia.application.core.resources.generated.resources.favorite
import writeopia.application.core.resources.generated.resources.favorites
import writeopia.application.core.resources.generated.resources.folder
import writeopia.application.core.resources.generated.resources.font
import writeopia.application.core.resources.generated.resources.highlight
import writeopia.application.core.resources.generated.resources.home
import writeopia.application.core.resources.generated.resources.image
import writeopia.application.core.resources.generated.resources.import_file
Expand Down Expand Up @@ -171,6 +172,9 @@ object WrStrings {
@Composable
fun text() = stringResource(Res.string.text)

@Composable
fun highlighting() = stringResource(Res.string.highlight)

@Composable
fun insert() = stringResource(Res.string.insert)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const val NOTE_EDITION_SCREEN_TITLE_TEST_TAG = "noteEditionScreenTitle"

@Composable
internal fun NoteEditorScreen(
isDarkTheme: Boolean,
documentId: String?,
title: String?,
noteEditorViewModel: NoteEditorViewModel,
Expand Down Expand Up @@ -144,6 +145,7 @@ internal fun NoteEditorScreen(
.background(MaterialTheme.colorScheme.background)
) {
TextEditor(
isDarkTheme = isDarkTheme,
noteEditorViewModel,
DefaultDrawersAndroid,
Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import io.writeopia.editor.features.editor.viewmodel.NoteEditorViewModel
actual fun TextEditorScreen(
documentId: String?,
title: String?,
isDarkTheme: Boolean,
noteEditorViewModel: NoteEditorViewModel,
navigateBack: () -> Unit,
playPresentation: () -> Unit,
onDocumentLinkClick: (String) -> Unit,
modifier: Modifier
) {
NoteEditorScreen(
isDarkTheme = isDarkTheme,
documentId = documentId,
title = title,
noteEditorViewModel = noteEditorViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.coroutines.flow.collectLatest

@Composable
internal fun TextEditor(
isDarkTheme: Boolean,
noteEditorViewModel: NoteEditorViewModel,
drawersFactory: DrawersFactory,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -69,6 +70,7 @@ internal fun TextEditor(
defaultBorder = clipShape,
onHeaderClick = noteEditorViewModel::onHeaderClick,
editable = isEditable,
isDarkTheme = isDarkTheme,
groupsBackgroundColor = Color.Transparent,
drawConfig = DrawConfigFactory.getDrawConfig(),
fontFamily = fontFamily,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import kotlinx.coroutines.launch

@Composable
fun AppTextEditor(
isDarkTheme: Boolean,
manager: WriteopiaStateManager,
viewModel: NoteEditorViewModel,
drawersFactory: DrawersFactory,
Expand All @@ -52,6 +53,7 @@ fun AppTextEditor(

Box(modifier) {
TextEditor(
isDarkTheme = isDarkTheme,
viewModel,
drawersFactory,
onDocumentLinkClick = onDocumentLinkClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.writeopia.ui.drawer.factory.DrawersFactory

@Composable
fun DesktopNoteEditorScreen(
isDarkTheme: Boolean,
documentId: String?,
noteEditorViewModel: NoteEditorViewModel,
drawersFactory: DrawersFactory,
Expand Down Expand Up @@ -59,6 +60,7 @@ fun DesktopNoteEditorScreen(
.padding(end = 56.dp),
content = {
AppTextEditor(
isDarkTheme = isDarkTheme,
noteEditorViewModel.writeopiaManager,
noteEditorViewModel,
drawersFactory = drawersFactory,
Expand All @@ -77,6 +79,7 @@ fun DesktopNoteEditorScreen(
modifier = Modifier
.padding(horizontal = 10.dp, vertical = 40.dp)
.align(Alignment.TopEnd),
isDarkTheme,
fontStyleSelected = { noteEditorViewModel.fontFamily },
isEditableState = noteEditorViewModel.isEditable,
isFavorite = noteEditorViewModel.notFavorite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
Expand All @@ -21,6 +23,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -58,6 +61,7 @@ import kotlinx.coroutines.flow.StateFlow
@Composable
fun SideEditorOptions(
modifier: Modifier = Modifier,
isDarkTheme: Boolean,
fontStyleSelected: () -> StateFlow<Font>,
isEditableState: StateFlow<Boolean>,
isFavorite: StateFlow<Boolean>,
Expand Down Expand Up @@ -131,6 +135,7 @@ fun SideEditorOptions(

OptionsType.TEXT_OPTIONS -> {
TextOptions(
isDarkTheme,
boldClick,
checkItemClick,
listItemClick,
Expand Down Expand Up @@ -381,6 +386,49 @@ private fun TextChanges(spanClick: (Span) -> Unit) {
}
}

@Composable
private fun HighlightText(isDarkTheme: Boolean, spanClick: (Span) -> Unit) {
Row(
modifier = Modifier.horizontalOptionsRow(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly
) {
val colors = if (isDarkTheme) {
listOf(
Span.HIGHLIGHT_RED to Color(0xFFD32F2F),
Span.HIGHLIGHT_GREEN to Color(0xFF2E7D32),
Span.HIGHLIGHT_YELLOW to Color(0xFFF9A825)
)
} else {
listOf(
Span.HIGHLIGHT_RED to Color(0xFFE57373),
Span.HIGHLIGHT_GREEN to Color.Green,
Span.HIGHLIGHT_YELLOW to Color.Yellow
)
}

colors.forEach { (span, color) ->
Box(
modifier = Modifier.weight(1F)
.size(32.dp)
.clickableWithoutGettingFocus {
spanClick(span)
},
) {
Box(
modifier = Modifier.size(16.dp)
.align(Alignment.Center)
.background(color, CircleShape)
.clip(CircleShape)
.clickableWithoutGettingFocus {
spanClick(span)
}
)
}
}
}
}

@Composable
private fun IconAndText(text: String, iconImage: ImageVector, click: () -> Unit) {
Row(
Expand Down Expand Up @@ -553,6 +601,7 @@ internal fun FontOptions(

@Composable
private fun TextOptions(
isDarkTheme: Boolean,
spanClick: (Span) -> Unit,
checkItemClick: () -> Unit,
listItemClick: () -> Unit,
Expand All @@ -576,6 +625,11 @@ private fun TextOptions(
TextChanges(spanClick)
Spacer(modifier = Modifier.height(8.dp))

Title(WrStrings.highlighting())
Spacer(modifier = Modifier.height(4.dp))
HighlightText(isDarkTheme, spanClick)
Spacer(modifier = Modifier.height(8.dp))

Title(WrStrings.insert())
Spacer(modifier = Modifier.height(4.dp))
InsertCommand(checkItemClick, listItemClick, codeBlockClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.writeopia.editor.features.editor.viewmodel.NoteEditorViewModel
expect fun TextEditorScreen(
documentId: String?,
title: String?,
isDarkTheme: Boolean,
noteEditorViewModel: NoteEditorViewModel,
navigateBack: () -> Unit,
playPresentation: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class NoteEditorKmpViewModel(
}
}

private var isDarkTheme: Boolean = true

/**
* This property defines if the document should be edited (you can write in it, for example)
*/
Expand Down Expand Up @@ -250,6 +252,10 @@ class NoteEditorKmpViewModel(
writeopiaManager.deleteSelection()
}

override fun setTheme(isDarkTheme: Boolean) {
this.isDarkTheme = isDarkTheme
}

override fun handleBackAction(navigateBack: () -> Unit) {
when {
showGlobalMenu.value -> {
Expand Down Expand Up @@ -510,7 +516,7 @@ class NoteEditorKmpViewModel(
.map { storyStep ->
val text = storyStep.text ?: ""

Spans.createStringWithSpans(text, storyStep.spans)
Spans.createStringWithSpans(text, storyStep.spans, isDarkTheme)
}.reduce { acc, annotatedString ->
acc + lineBreak + annotatedString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ interface NoteEditorViewModel : BackstackInform, BackstackHandler {
fun toggleFavorite()

fun receiveExternalFile(files: List<ExternalFile>, position: Int)

fun setTheme(isDarkTheme: Boolean)
}

data class ShareDocument(val content: String, val title: String, val type: String)
Loading