Skip to content

Commit

Permalink
Merge upstream commits
Browse files Browse the repository at this point in the history
  • Loading branch information
MOldtime committed Dec 1, 2024
2 parents c961819 + 4beb2df commit b927288
Show file tree
Hide file tree
Showing 137 changed files with 501 additions and 196 deletions.
14 changes: 13 additions & 1 deletion app/src/main/cpp/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"POT-Creation-Date: 2022-02-14 18:51+0800\n"
"PO-Revision-Date: 2022-03-18 22:18+0000\n"
"Last-Translator: Ettore Atalan <[email protected]>, 2022\n"
"Language-Team: German (https://www.transifex.com/fcitx/teams/12005/de/)\n"
"Language-Team: German (https://app.transifex.com/fcitx/teams/12005/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand All @@ -28,6 +28,12 @@ msgstr "Worthinweis"
msgid "Enable word hint"
msgstr "Worthinweis aktivieren"

msgid "Enable word hint when using physical keyboard"
msgstr ""

msgid "Disable word hint based on editor attributes"
msgstr ""

msgid "Word hint page size"
msgstr "Seitengröße des Worthinweises"

Expand All @@ -36,3 +42,9 @@ msgstr ""

msgid "Insert space between words"
msgstr ""

msgid "Android Toast & Notification"
msgstr ""

msgid "Hidden Notifications"
msgstr ""
12 changes: 12 additions & 0 deletions app/src/main/cpp/po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ msgstr ""
msgid "Enable word hint"
msgstr ""

msgid "Enable word hint when using physical keyboard"
msgstr ""

msgid "Disable word hint based on editor attributes"
msgstr ""

msgid "Word hint page size"
msgstr ""

Expand All @@ -36,3 +42,9 @@ msgstr ""

msgid "Insert space between words"
msgstr "Insertar espacio entre palabras"

msgid "Android Toast & Notification"
msgstr ""

msgid "Hidden Notifications"
msgstr ""
3 changes: 3 additions & 0 deletions app/src/main/cpp/po/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ msgstr "単語ヒント"
msgid "Enable word hint"
msgstr "単語ヒントを有効にする"

msgid "Enable word hint when using physical keyboard"
msgstr ""

msgid "Disable word hint based on editor attributes"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/cpp/po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ msgstr "Подсказка слова"
msgid "Enable word hint"
msgstr "Включить подсказку слова"

msgid "Enable word hint when using physical keyboard"
msgstr "Включить подсказки слов при использовании физической клавиатуры"

msgid "Disable word hint based on editor attributes"
msgstr "Отключить подсказки слов в зависимости от свойств редактора"

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/cpp/po/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# Translators:
# Potato Hatsue, 2022
# rocka, 2024
# Yiyu Liu, 2024
#
msgid ""
msgstr ""
"Project-Id-Version: fcitx5-android\n"
"Report-Msgid-Bugs-To: https://github.com/fcitx5-android/fcitx5-android/issues\n"
"POT-Creation-Date: 2022-02-14 18:51+0800\n"
"PO-Revision-Date: 2022-03-18 22:18+0000\n"
"Last-Translator: rocka, 2024\n"
"Last-Translator: Yiyu Liu, 2024\n"
"Language-Team: Chinese (China) (https://app.transifex.com/fcitx/teams/12005/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand All @@ -29,6 +30,9 @@ msgstr "单词提示"
msgid "Enable word hint"
msgstr "启用单词提示"

msgid "Enable word hint when using physical keyboard"
msgstr "在使用物理键盘时启用单词提示"

msgid "Disable word hint based on editor attributes"
msgstr "根据编辑器属性禁用单词提示"

Expand Down
14 changes: 8 additions & 6 deletions app/src/main/cpp/po/zh_TW.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
# Translators:
# 黃柏諺 <[email protected]>, 2022
# Jia-Bin, 2022
# rocka, 2022
# Lau YeeYu, 2024
# Yiyu Liu, 2024
#
msgid ""
msgstr ""
"Project-Id-Version: fcitx5-android\n"
"Report-Msgid-Bugs-To: https://github.com/fcitx5-android/fcitx5-android/issues\n"
"POT-Creation-Date: 2022-02-14 18:51+0800\n"
"PO-Revision-Date: 2022-03-18 22:18+0000\n"
"Last-Translator: Lau YeeYu, 2024\n"
"Last-Translator: Yiyu Liu, 2024\n"
"Language-Team: Chinese (Taiwan) (https://app.transifex.com/fcitx/teams/12005/zh_TW/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand All @@ -26,16 +25,19 @@ msgid "Android Keyboard"
msgstr "Android 鍵盤"

msgid "Word hint"
msgstr "單字提示"
msgstr "字詞提示"

msgid "Enable word hint"
msgstr "啟用單字提示"
msgstr "啟用字詞提示"

msgid "Enable word hint when using physical keyboard"
msgstr "在使用物理鍵盤時啟用字詞提示"

msgid "Disable word hint based on editor attributes"
msgstr "依據編輯器屬性禁用字詞提示"

msgid "Word hint page size"
msgstr "單字提示頁大小"
msgstr "字詞提示頁大小"

msgid "Choose key modifier"
msgstr "選詞修飾鍵"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* SPDX-FileCopyrightText: Copyright 2021-2023 Fcitx5 for Android Contributors
* SPDX-FileCopyrightText: Copyright 2021-2024 Fcitx5 for Android Contributors
*/
package org.fcitx.fcitx5.android.input.candidates.expanded

Expand All @@ -13,7 +13,7 @@ class CandidatesPagingSource(val fcitx: FcitxConnection, val total: Int, val off
PagingSource<Int, String>() {

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, String> {
// use candidate index for key, null means load from beginning (including offset)
// use candidate index for key, null means load from beginning (with offset)
val startIndex = params.key ?: offset
val pageSize = params.loadSize
Timber.d("getCandidates(offset=$startIndex, limit=$pageSize)")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* SPDX-FileCopyrightText: Copyright 2021-2023 Fcitx5 for Android Contributors
* SPDX-FileCopyrightText: Copyright 2021-2024 Fcitx5 for Android Contributors
*/
package org.fcitx.fcitx5.android.input.candidates.expanded

Expand All @@ -10,7 +10,12 @@ import androidx.constraintlayout.widget.ConstraintLayout
import org.fcitx.fcitx5.android.R
import org.fcitx.fcitx5.android.data.theme.Theme
import org.fcitx.fcitx5.android.data.theme.ThemeManager
import org.fcitx.fcitx5.android.input.keyboard.*
import org.fcitx.fcitx5.android.input.keyboard.BackspaceKey
import org.fcitx.fcitx5.android.input.keyboard.BaseKeyboard
import org.fcitx.fcitx5.android.input.keyboard.ImageKeyView
import org.fcitx.fcitx5.android.input.keyboard.ImageLayoutSwitchKey
import org.fcitx.fcitx5.android.input.keyboard.KeyDef
import org.fcitx.fcitx5.android.input.keyboard.ReturnKey
import splitties.views.backgroundColor
import splitties.views.dsl.constraintlayout.bottomOfParent
import splitties.views.dsl.constraintlayout.lParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ import splitties.views.dsl.core.matchParent

abstract class GridPagingCandidateViewAdapter(theme: Theme) : PagingCandidateViewAdapter(theme) {

companion object {
// 20f here is chosen randomly, since we only care about the ratio
private const val TEXT_SIZE = 20f
}

// cache measureWidth
private val measuredWidths = LruCache<String, Float>(200)
private val measuredWidths = object : LruCache<String, Float>(200) {
private val cachedPaint = Paint().apply { textSize = TEXT_SIZE }
private val cachedRect = Rect()
override fun create(key: String): Float {
cachedPaint.getTextBounds(key, 0, key.length, cachedRect)
return cachedRect.width() / TEXT_SIZE
}
}

fun measureWidth(position: Int): Float {
val candidate = getItem(position) ?: return 0f
return measuredWidths[candidate] ?: run {
val paint = Paint()
val bounds = Rect()
// 20f here is chosen randomly, since we only care about the ratio
paint.textSize = 20f
paint.getTextBounds(candidate, 0, candidate.length, bounds)
(bounds.width() / 20f).also { measuredWidths.put(candidate, it) }
}
return measuredWidths[candidate]
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CandidateViewHolder {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* SPDX-FileCopyrightText: Copyright 2021-2023 Fcitx5 for Android Contributors
* SPDX-FileCopyrightText: Copyright 2021-2024 Fcitx5 for Android Contributors
*/

package org.fcitx.fcitx5.android.input.candidates.expanded.window

import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RectShape
import android.view.View
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.fcitx.fcitx5.android.daemon.launchOnReady
import org.fcitx.fcitx5.android.data.prefs.AppPrefs
Expand All @@ -26,10 +24,10 @@ import org.fcitx.fcitx5.android.input.bar.KawaiiBarComponent
import org.fcitx.fcitx5.android.input.broadcast.InputBroadcastReceiver
import org.fcitx.fcitx5.android.input.broadcast.ReturnKeyDrawableComponent
import org.fcitx.fcitx5.android.input.candidates.CandidateViewHolder
import org.fcitx.fcitx5.android.input.candidates.horizontal.HorizontalCandidateComponent
import org.fcitx.fcitx5.android.input.candidates.expanded.PagingCandidateViewAdapter
import org.fcitx.fcitx5.android.input.candidates.expanded.CandidatesPagingSource
import org.fcitx.fcitx5.android.input.candidates.expanded.ExpandedCandidateLayout
import org.fcitx.fcitx5.android.input.candidates.expanded.PagingCandidateViewAdapter
import org.fcitx.fcitx5.android.input.candidates.horizontal.HorizontalCandidateComponent
import org.fcitx.fcitx5.android.input.dependency.fcitx
import org.fcitx.fcitx5.android.input.dependency.inputMethodService
import org.fcitx.fcitx5.android.input.dependency.theme
Expand Down Expand Up @@ -57,7 +55,6 @@ abstract class BaseExpandedCandidateWindow<T : BaseExpandedCandidateWindow<T>> :

protected val disableAnimation by AppPrefs.getInstance().advanced.disableAnimation

private lateinit var lifecycleCoroutineScope: LifecycleCoroutineScope
private lateinit var candidateLayout: ExpandedCandidateLayout

protected val dividerDrawable by lazy {
Expand Down Expand Up @@ -98,13 +95,19 @@ abstract class BaseExpandedCandidateWindow<T : BaseExpandedCandidateWindow<T>> :
private var offsetJob: Job? = null

private val candidatesPager by lazy {
Pager(PagingConfig(pageSize = 48)) {
CandidatesPagingSource(
fcitx,
total = horizontalCandidate.adapter.total,
offset = adapter.offset
)
}
Pager(
config = PagingConfig(
pageSize = 48,
enablePlaceholders = false
),
pagingSourceFactory = {
CandidatesPagingSource(
fcitx,
total = horizontalCandidate.adapter.total,
offset = adapter.offset
)
}
)
}
private var candidatesSubmitJob: Job? = null

Expand All @@ -113,19 +116,23 @@ abstract class BaseExpandedCandidateWindow<T : BaseExpandedCandidateWindow<T>> :
abstract fun nextPage()

override fun onAttached() {
lifecycleCoroutineScope = candidateLayout.findViewTreeLifecycleOwner()!!.lifecycleScope
bar.expandButtonStateMachine.push(ExpandedCandidatesAttached)
candidateLayout.embeddedKeyboard.also {
it.onReturnDrawableUpdate(returnKeyDrawable.resourceId)
it.keyActionListener = keyActionListener
}
offsetJob = lifecycleCoroutineScope.launch {
offsetJob = service.lifecycleScope.launch {
horizontalCandidate.expandedCandidateOffset.collect {
updateCandidatesWithOffset(it)
if (it <= 0) {
windowManager.attachWindow(KeyboardWindow)
} else {
candidateLayout.resetPosition()
adapter.refreshWithOffset(it)
}
}
}
candidatesSubmitJob = lifecycleCoroutineScope.launch {
candidatesPager.flow.collect {
candidatesSubmitJob = service.lifecycleScope.launch {
candidatesPager.flow.collectLatest {
adapter.submitData(it)
}
}
Expand All @@ -141,19 +148,6 @@ abstract class BaseExpandedCandidateWindow<T : BaseExpandedCandidateWindow<T>> :
}
}

private fun updateCandidatesWithOffset(offset: Int) {
val candidates = horizontalCandidate.adapter.candidates
if (candidates.isEmpty()) {
windowManager.attachWindow(KeyboardWindow)
} else {
// adapter.refreshWithOffset(if (horizontalCandidate.adapter.currentPage > 1) 0 else 0)
adapter.refreshWithOffset(offset)
lifecycleCoroutineScope.launch(Dispatchers.Main) {
candidateLayout.resetPosition()
}
}
}

override fun onDetached() {
bar.expandButtonStateMachine.push(
ExpandedCandidatesDetached,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* SPDX-FileCopyrightText: Copyright 2021-2023 Fcitx5 for Android Contributors
* SPDX-FileCopyrightText: Copyright 2021-2024 Fcitx5 for Android Contributors
*/

package org.fcitx.fcitx5.android.input.candidates.expanded.window
Expand Down Expand Up @@ -59,9 +59,9 @@ class FlexboxExpandedCandidateWindow :
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
this@FlexboxExpandedCandidateWindow.layoutManager.apply {
pageUpBtn.isEnabled = findFirstCompletelyVisibleItemPosition() != 0
pageUpBtn.isEnabled = findFirstCompletelyVisibleItemPosition() > 0
pageDnBtn.isEnabled =
findLastCompletelyVisibleItemPosition() != itemCount - 1
findLastCompletelyVisibleItemPosition() < itemCount - 1
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* SPDX-FileCopyrightText: Copyright 2021-2023 Fcitx5 for Android Contributors
* SPDX-FileCopyrightText: Copyright 2021-2024 Fcitx5 for Android Contributors
*/

package org.fcitx.fcitx5.android.input.candidates.expanded.window
Expand Down Expand Up @@ -53,9 +53,9 @@ class GridExpandedCandidateWindow :
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
(recyclerView.layoutManager as GridLayoutManager).apply {
pageUpBtn.isEnabled = findFirstCompletelyVisibleItemPosition() != 0
pageUpBtn.isEnabled = findFirstCompletelyVisibleItemPosition() > 0
pageDnBtn.isEnabled =
findLastCompletelyVisibleItemPosition() != itemCount - 1
findLastCompletelyVisibleItemPosition() < itemCount - 1
}
}
})
Expand Down
Loading

0 comments on commit b927288

Please sign in to comment.