-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PageinationUi to indicate if candidates page has prev or next
- Loading branch information
1 parent
faac441
commit b449368
Showing
5 changed files
with
113 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/osfans/trime/ime/candidates/popup/PaginationUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2015 - 2024 Rime community | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package com.osfans.trime.ime.candidates.popup | ||
|
||
import android.content.Context | ||
import android.content.res.ColorStateList | ||
import android.widget.ImageView | ||
import androidx.annotation.DrawableRes | ||
import com.osfans.trime.R | ||
import com.osfans.trime.core.RimeProto | ||
import com.osfans.trime.data.theme.ColorManager | ||
import com.osfans.trime.data.theme.Theme | ||
import com.osfans.trime.util.styledFloat | ||
import splitties.dimensions.dp | ||
import splitties.resources.drawable | ||
import splitties.views.dsl.constraintlayout.before | ||
import splitties.views.dsl.constraintlayout.centerVertically | ||
import splitties.views.dsl.constraintlayout.constraintLayout | ||
import splitties.views.dsl.constraintlayout.endOfParent | ||
import splitties.views.dsl.constraintlayout.lParams | ||
import splitties.views.dsl.core.Ui | ||
import splitties.views.dsl.core.add | ||
import splitties.views.dsl.core.imageView | ||
import splitties.views.imageDrawable | ||
|
||
class PaginationUi( | ||
override val ctx: Context, | ||
val theme: Theme, | ||
) : Ui { | ||
private fun createIcon( | ||
@DrawableRes icon: Int, | ||
) = imageView { | ||
imageTintList = ColorStateList.valueOf(ColorManager.getColor("key_text_color")!!) | ||
imageDrawable = drawable(icon) | ||
scaleType = ImageView.ScaleType.CENTER_CROP | ||
} | ||
|
||
private val prevIcon = createIcon(R.drawable.ic_baseline_arrow_left_24) | ||
private val nextIcon = createIcon(R.drawable.ic_baseline_arrow_right_24) | ||
|
||
private val disabledAlpha = ctx.styledFloat(android.R.attr.disabledAlpha) | ||
|
||
override val root = | ||
constraintLayout { | ||
val w = dp(10) | ||
val h = dp(20) | ||
add( | ||
nextIcon, | ||
lParams(w, h) { | ||
centerVertically() | ||
endOfParent() | ||
}, | ||
) | ||
add( | ||
prevIcon, | ||
lParams(w, h) { | ||
centerVertically() | ||
before(nextIcon) | ||
}, | ||
) | ||
} | ||
|
||
fun update(menu: RimeProto.Context.Menu) { | ||
prevIcon.alpha = if (menu.pageNumber != 0) 1f else disabledAlpha | ||
nextIcon.alpha = if (!menu.isLastPage) 1f else disabledAlpha | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
||
<path android:fillColor="@android:color/white" android:pathData="M14,7l-5,5 5,5V7z"/> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
||
<path android:fillColor="@android:color/white" android:pathData="M10,17l5,-5 -5,-5v10z"/> | ||
|
||
</vector> |