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 @@ -9,4 +9,7 @@ class SettingRepository @Inject constructor() {

fun hideOCRAreaAfterTranslated(): Boolean =
SettingManager.hideRecognizedResultAfterTranslated

fun limitResultViewMaxWidth(): Boolean =
SettingManager.limitResultViewMaxWidth
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tw.firemaples.onscreenocr.data.usecase

import tw.firemaples.onscreenocr.data.repo.SettingRepository
import javax.inject.Inject

class GetLimitResultViewMaxWidthUseCase @Inject constructor(
private val settingRepository: SettingRepository,
) {
operator fun invoke(): Boolean = settingRepository.limitResultViewMaxWidth()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
Expand Down Expand Up @@ -97,6 +98,11 @@ fun ResultViewContent(
ResultPanel(
modifier = Modifier
.padding(16.dp)
.run {
if (state.limitMaxWidth)
widthIn(max = 300.dp)
else this
}
.calculateOffset(
highlightUnion = state.highlightUnion,
offset = targetOffset,
Expand Down Expand Up @@ -462,10 +468,11 @@ private fun ResultViewContentPreview() {
val state = ResultViewState(
highlightArea = listOf(areaRect),
highlightUnion = areaRect,
limitMaxWidth = true,
textSearchEnabled = true,
ocrState = OCRState(
showProcessing = true,
ocrText = "Test OCR text",
showProcessing = false,
ocrText = "Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text Test OCR text ",
),
translationState = TranslationState(
showTranslationArea = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.launch
import tw.firemaples.onscreenocr.R
import tw.firemaples.onscreenocr.data.usecase.GetCurrentTranslationLangUseCase
import tw.firemaples.onscreenocr.data.usecase.GetHidingOCRAreaAfterTranslatedUseCase
import tw.firemaples.onscreenocr.data.usecase.GetLimitResultViewMaxWidthUseCase
import tw.firemaples.onscreenocr.data.usecase.GetResultViewFontSizeUseCase
import tw.firemaples.onscreenocr.data.usecase.GetShowTextSelectorOnResultViewUseCase
import tw.firemaples.onscreenocr.data.usecase.SetShowTextSelectorOnResultViewUseCase
Expand Down Expand Up @@ -50,6 +51,7 @@ interface ResultViewModel {
}

data class ResultViewState(
val limitMaxWidth: Boolean = true,
val textSearchEnabled: Boolean = false,
val fontSize: Float = Constants.DEFAULT_RESULT_WINDOW_FONT_SIZE,
val highlightArea: List<Rect> = listOf(),
Expand Down Expand Up @@ -97,6 +99,7 @@ class ResultViewModelImpl @Inject constructor(
getShowTextSelectorOnResultViewUseCase: GetShowTextSelectorOnResultViewUseCase,
private val setShowTextSelectorOnResultViewUseCase: SetShowTextSelectorOnResultViewUseCase,
getResultViewFontSizeUseCase: GetResultViewFontSizeUseCase,
private val getLimitResultViewMaxWidthUseCase: GetLimitResultViewMaxWidthUseCase,
private val getCurrentTranslationLangUseCase: GetCurrentTranslationLangUseCase,
private val getHidingOCRAreaAfterTranslatedUseCase: GetHidingOCRAreaAfterTranslatedUseCase,
) : ResultViewModel {
Expand Down Expand Up @@ -144,6 +147,12 @@ class ResultViewModelImpl @Inject constructor(
this@ResultViewModelImpl.croppedBitmap = navState.bitmap
}

state.update {
it.copy(
limitMaxWidth = getLimitResultViewMaxWidthUseCase.invoke(),
)
}

when (navState) {
is NavState.TextRecognizing ->
state.update {
Expand Down Expand Up @@ -208,7 +217,8 @@ class ResultViewModelImpl @Inject constructor(
val providerName = context.getString(providerType.nameRes)
"${context.getString(R.string.text_translated_by)} $providerName"
} else null
val showRecognitionArea = getHidingOCRAreaAfterTranslatedUseCase.invoke().not()
val showRecognitionArea =
getHidingOCRAreaAfterTranslatedUseCase.invoke().not()

state.update {
it.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object SettingManager {
private const val PREF_AUTO_COPY_OCR_RESULT = "pref_auto_copy_ocr_result"
private const val PREF_HIDE_RECOGNIZED_RESULT_AFTER_TRANSLATED =
"pref_hide_recognized_result_after_translated"
private const val PREF_LIMIT_RESULT_VIEW_MAX_WIDTH = "pref_limit_result_view_max_width"

private const val PREF_SAVE_LAST_SELECTION_AREA = "pref_save_last_selection_area"
private const val PREF_EXIT_APP_WHILE_SPEN_INSERTED = "pref_exit_app_while_spen_inserted"
Expand Down Expand Up @@ -108,6 +109,9 @@ object SettingManager {
val hideRecognizedResultAfterTranslated: Boolean
get() = preferences.getBoolean(PREF_HIDE_RECOGNIZED_RESULT_AFTER_TRANSLATED, false)

val limitResultViewMaxWidth: Boolean
get() = preferences.getBoolean(PREF_LIMIT_RESULT_VIEW_MAX_WIDTH, true)

val saveLastSelectionArea: Boolean
get() = preferences.getBoolean(PREF_SAVE_LAST_SELECTION_AREA, true)

Expand Down
3 changes: 3 additions & 0 deletions main/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@
<string name="pref_summary_on_keep_media_projection_resources">维持相关资源直到重启程式</string>
<string name="pref_summary_off_keep_media_projection_resources">每次使用后释放相关资源</string>
<string name="pref_screenshot">萤幕截图</string>
<string name="pref_limit_result_view_max_width">限制最大宽度</string>
<string name="pref_summary_on_limit_result_view_max_width">限制最大宽度至 300dp</string>
<string name="pref_summary_off_limit_result_view_max_width">依内容自动调整宽度</string>
</resources>
3 changes: 3 additions & 0 deletions main/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@
<string name="pref_summary_on_keep_media_projection_resources">維持相關資源直到重啟程式</string>
<string name="pref_summary_off_keep_media_projection_resources">每次使用後釋放相關資源</string>
<string name="pref_screenshot">螢幕截圖</string>
<string name="pref_limit_result_view_max_width">限制最大寬度</string>
<string name="pref_summary_on_limit_result_view_max_width">限制最大寬度至 300dp</string>
<string name="pref_summary_off_limit_result_view_max_width">不限制寬度</string>
</resources>
3 changes: 3 additions & 0 deletions main/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<string name="pref_summary_on_keep_media_projection_resources">Keep the resources until restart</string>
<string name="pref_summary_off_keep_media_projection_resources">Release the resources after used</string>
<string name="pref_title_keep_media_projection_resources">Keep MediaProjection resources</string>
<string name="pref_limit_result_view_max_width">Limit the max width</string>
<string name="pref_summary_on_limit_result_view_max_width">Limit the max width to 300dp</string>
<string name="pref_summary_off_limit_result_view_max_width">Dynamic width based on the content</string>

<string name="menu_setting">Setting</string>
<string name="menu_privacy_policy">Privacy Policy</string>
Expand Down
8 changes: 7 additions & 1 deletion main/src/main/res/xml/perference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
android:defaultValue="false"
android:key="pref_hide_recognized_result_after_translated"
android:title="@string/pref_hide_recognized_result_after_translated" />
<SwitchPreference
android:defaultValue="true"
android:key="pref_limit_result_view_max_width"
android:summaryOff="@string/pref_summary_off_limit_result_view_max_width"
android:summaryOn="@string/pref_summary_on_limit_result_view_max_width"
android:title="@string/pref_limit_result_view_max_width" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_other_settings">
Expand All @@ -112,4 +118,4 @@
android:key="pref_exit_app_while_spen_inserted"
android:title="@string/pref_exit_app_while_spen_inserted" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>