Added «Double click translation» with external translator.
This commit is contained in:
parent
7f8f7daa23
commit
3aefb37935
6 changed files with 112 additions and 3 deletions
|
|
@ -330,6 +330,7 @@ private fun ReaderScreen(
|
|||
) { line ->
|
||||
ReaderTextParagraph(
|
||||
line = line.second,
|
||||
context = context,
|
||||
fontFamily = fontFamily,
|
||||
fontColor = fontColor,
|
||||
lineHeight = lineHeight,
|
||||
|
|
@ -337,6 +338,9 @@ private fun ReaderScreen(
|
|||
fontSize = mainState.value.fontSize!!.sp,
|
||||
sidePadding = sidePadding,
|
||||
paragraphIndentation = mainState.value.paragraphIndentation!!,
|
||||
doubleClickTranslationEnabled = mainState.value.doubleClickTranslation!!,
|
||||
toolbarHidden = toolbarHidden,
|
||||
onEvent = onEvent
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
package ua.acclorite.book_story.presentation.screens.reader.components
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
|
|
@ -15,13 +20,16 @@ import androidx.compose.ui.text.font.FontStyle
|
|||
import androidx.compose.ui.text.style.LineBreak
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import ua.acclorite.book_story.R
|
||||
import ua.acclorite.book_story.domain.model.FontWithName
|
||||
import ua.acclorite.book_story.domain.model.ReaderLine
|
||||
import ua.acclorite.book_story.presentation.screens.reader.data.ReaderEvent
|
||||
|
||||
/**
|
||||
* Reader Text Paragraph item.
|
||||
*
|
||||
* @param line Current line.
|
||||
* @param context Context.
|
||||
* @param fontFamily Line's font family.
|
||||
* @param fontColor Line's font color.
|
||||
* @param lineHeight Line's line height.
|
||||
|
|
@ -29,17 +37,25 @@ import ua.acclorite.book_story.domain.model.ReaderLine
|
|||
* @param fontSize Line's font size.
|
||||
* @param sidePadding Line's side padding.
|
||||
* @param paragraphIndentation Whether Paragraph Indentation is enabled for this line.
|
||||
* @param doubleClickTranslationEnabled Whether Double Click Translation is enabled.
|
||||
* @param toolbarHidden Whether selection toolBar is hidden.
|
||||
* @param onEvent [ReaderEvent] callback.
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun LazyItemScope.ReaderTextParagraph(
|
||||
line: ReaderLine,
|
||||
context: Context,
|
||||
fontFamily: FontWithName,
|
||||
fontColor: Color,
|
||||
lineHeight: TextUnit,
|
||||
fontStyle: FontStyle,
|
||||
fontSize: TextUnit,
|
||||
sidePadding: Dp,
|
||||
paragraphIndentation: Boolean
|
||||
paragraphIndentation: Boolean,
|
||||
doubleClickTranslationEnabled: Boolean,
|
||||
toolbarHidden: Boolean,
|
||||
onEvent: (ReaderEvent) -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
|
|
@ -58,6 +74,39 @@ fun LazyItemScope.ReaderTextParagraph(
|
|||
|
||||
append(line.line)
|
||||
},
|
||||
modifier = Modifier.then(
|
||||
if (
|
||||
doubleClickTranslationEnabled &&
|
||||
toolbarHidden
|
||||
) {
|
||||
Modifier.combinedClickable(
|
||||
interactionSource = null,
|
||||
indication = null,
|
||||
onDoubleClick = {
|
||||
onEvent(
|
||||
ReaderEvent.OnOpenTranslator(
|
||||
textToTranslate = line.line,
|
||||
context = context as ComponentActivity,
|
||||
noAppsFound = {
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.error_no_translator),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
)
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
onEvent(
|
||||
ReaderEvent.OnShowHideMenu(context = context as ComponentActivity)
|
||||
)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
),
|
||||
style = TextStyle(
|
||||
fontFamily = fontFamily.font,
|
||||
fontStyle = fontStyle,
|
||||
|
|
|
|||
|
|
@ -249,6 +249,34 @@ fun ReaderSettingsBottomSheet(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Spacer(modifier = Modifier.height(22.dp))
|
||||
}
|
||||
item {
|
||||
CategoryTitle(
|
||||
title = stringResource(id = R.string.translator_reader_settings),
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
item {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
item {
|
||||
SwitchWithTitle(
|
||||
selected = mainState.value.doubleClickTranslation!!,
|
||||
title = stringResource(id = R.string.translator_double_click_to_translate_option),
|
||||
description = stringResource(id = R.string.translator_double_click_to_translate_option_desc),
|
||||
onClick = {
|
||||
onMainEvent(
|
||||
MainEvent.OnChangeDoubleClickTranslation(
|
||||
!mainState.value.doubleClickTranslation!!
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (page == 1) {
|
||||
|
|
|
|||
|
|
@ -238,6 +238,34 @@ private fun ReaderSettings(
|
|||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Spacer(modifier = Modifier.height(22.dp))
|
||||
}
|
||||
item {
|
||||
CategoryTitle(
|
||||
title = stringResource(id = R.string.translator_reader_settings),
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
item {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
item {
|
||||
SwitchWithTitle(
|
||||
selected = state.value.doubleClickTranslation!!,
|
||||
title = stringResource(id = R.string.translator_double_click_to_translate_option),
|
||||
description = stringResource(id = R.string.translator_double_click_to_translate_option_desc),
|
||||
onClick = {
|
||||
onMainEvent(
|
||||
MainEvent.OnChangeDoubleClickTranslation(
|
||||
!state.value.doubleClickTranslation!!
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
item { Spacer(modifier = Modifier.height(48.dp)) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@
|
|||
<string name="appearance_settings">Зовнішній вигляд</string>
|
||||
<string name="appearance_settings_desc">Тема, кольори</string>
|
||||
<string name="reader_settings">Читач</string>
|
||||
<string name="reader_settings_desc">Перекладач, шрифт, текст</string>
|
||||
<string name="reader_settings_desc">Шрифт, текст, перекладач</string>
|
||||
|
||||
<!-- Settings subcategories -->
|
||||
<string name="font_reader_settings">Шрифт</string>
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@
|
|||
<string name="appearance_settings">Appearance</string>
|
||||
<string name="appearance_settings_desc">Theme, colors</string>
|
||||
<string name="reader_settings">Reader</string>
|
||||
<string name="reader_settings_desc">Translator, font, text</string>
|
||||
<string name="reader_settings_desc">Font, text, translator</string>
|
||||
|
||||
<!-- Settings subcategories -->
|
||||
<string name="font_reader_settings">Font</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue