アプリ設定/挙動に「追加ボタンを強制的に折り返す」を追加

This commit is contained in:
tateisu 2019-07-11 09:05:14 +09:00
parent ded779ea7e
commit f8e7469d00
5 changed files with 82 additions and 37 deletions

View File

@ -400,6 +400,13 @@ object Pref {
R.id.swShowTranslateButton
)
val bpForceWrapAdditionalButtons = BooleanPref(
"ForceWrapAdditionalButtons",
false,
R.id.swForceWrapAdditionalButtons
)
// int

View File

@ -215,13 +215,50 @@ internal class StatusButtons(
relation
}
val forceWrapAdditionalButtons = Pref.bpForceWrapAdditionalButtons(activity.pref)
var optionalButtonFirst : View? = null
var optionalButtonCount = 0
fun showCustomShare(target : CustomShareTarget, b : ImageButton) {
val (label, icon) = CustomShare.getCache(target)
?: error("showCustomShare: invalid target")
if(vg(b, label != null || icon != null)) {
b.isEnabled = true
b.contentDescription = label ?: "?"
b.setImageDrawable(
icon ?: createColoredDrawable(
activity,
R.drawable.ic_question,
color_normal,
Styler.boost_alpha
)
)
if(forceWrapAdditionalButtons) {
++ optionalButtonCount
if(optionalButtonFirst == null) {
optionalButtonFirst = b
}
}
}
}
fun setWrap(b : ImageButton) {
(b.layoutParams as? FlexboxLayout.LayoutParams)
?.isWrapBefore = optionalButtonCount >= 1 && b == optionalButtonFirst
}
if(vg(btnTranslate, Pref.bpShowTranslateButton(activity.pref))) {
showCustomShare(CustomShareTarget.Translate, btnTranslate)
}
showCustomShare(CustomShareTarget.CustomShare1, btnCustomShare1)
showCustomShare(CustomShareTarget.CustomShare2, btnCustomShare2)
showCustomShare(CustomShareTarget.CustomShare3, btnCustomShare3)
setWrap(btnTranslate)
setWrap(btnCustomShare1)
setWrap(btnCustomShare2)
setWrap(btnCustomShare3)
}
private fun setButton(
@ -246,41 +283,24 @@ internal class StatusButtons(
b.isEnabled = enabled
}
private fun setButton(
b : ImageButton,
enabled : Boolean,
color : Int,
drawableId : Int,
contentDescription : String
) {
val alpha = Styler.boost_alpha
val d = createColoredDrawable(
activity,
drawableId,
color,
alpha
)
b.setImageDrawable(d)
b.contentDescription = contentDescription
b.isEnabled = enabled
}
private fun showCustomShare(target : CustomShareTarget, b : ImageButton) {
val (label, icon) = CustomShare.getCache(target) ?: error("showCustomShare: invalid target")
if(vg(b, label != null || icon != null)) {
b.isEnabled = true
b.contentDescription = label ?: "?"
b.setImageDrawable(
icon ?: createColoredDrawable(
activity,
R.drawable.ic_question,
color_normal,
Styler.boost_alpha
)
)
}
}
// private fun setButton(
// b : ImageButton,
// enabled : Boolean,
// color : Int,
// drawableId : Int,
// contentDescription : String
// ) {
// val alpha = Styler.boost_alpha
// val d = createColoredDrawable(
// activity,
// drawableId,
// color,
// alpha
// )
// b.setImageDrawable(d)
// b.contentDescription = contentDescription
// b.isEnabled = enabled
// }
override fun onClick(v : View) {
@ -697,7 +717,7 @@ class StatusButtonsViewHolder(
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
}
}
}

View File

@ -416,5 +416,21 @@
<View style="@style/setting_divider"/>
<TextView
style="@style/setting_row_label"
android:text="@string/force_wrap_additional_buttons"
/>
<LinearLayout style="@style/setting_row_form">
<Switch
android:id="@+id/swForceWrapAdditionalButtons"
style="@style/setting_horizontal_stretch"
/>
</LinearLayout>
<View style="@style/setting_divider"/>
</LinearLayout>
</ScrollView>

View File

@ -917,5 +917,6 @@
<string name="custom_share_button_2">カスタム共有ボタン2</string>
<string name="custom_share_button_3">カスタム共有ボタン3</string>
<string name="custom_share_app_not_found">共有先のアプリがインストールされていません。「アプリ設定/挙動」を確認してください</string>
<string name="force_wrap_additional_buttons">追加ボタンを強制的に折り返す</string>
</resources>

View File

@ -910,5 +910,6 @@
<string name="custom_share_button_2">Custom share button 2</string>
<string name="custom_share_button_3">Custom share button 3</string>
<string name="custom_share_app_not_found">the share target app is not installed. please configure it in \"App setting/behavior\".</string>
<string name="force_wrap_additional_buttons">Force wrap additional buttons</string>
</resources>