replace from "app setting/behavior/Force wrap additional buttons" to "app setting/behavior/Additional buttons position".

This commit is contained in:
tateisu 2019-07-22 01:10:23 +09:00
parent 3d4f886035
commit 68296b8ede
6 changed files with 251 additions and 161 deletions

View File

@ -110,6 +110,7 @@ class ActAppSettingChild : AppCompatActivity()
private var spUITheme : Spinner? = null
private var spResizeImage : Spinner? = null
private var spRefreshAfterToot : Spinner? = null
private var spAdditionalButtonsPosition : Spinner? = null
private var spDefaultAccount : Spinner? = null
private var spRepliesCount : Spinner? = null
private var spVisibilityStyle : Spinner? = null
@ -346,6 +347,14 @@ class ActAppSettingChild : AppCompatActivity()
, getString(R.string.dont_refresh)
)
spAdditionalButtonsPosition = initSpinner(
R.id.spAdditionalButtonsPosition
, getString(R.string.top)
, getString(R.string.bottom)
, getString(R.string.start)
, getString(R.string.end)
)
spDefaultAccount = findViewById<Spinner>(R.id.spDefaultAccount)?.also {
it.adapter = AccountAdapter()
it.onItemSelectedListener = this@ActAppSettingChild
@ -573,7 +582,7 @@ class ActAppSettingChild : AppCompatActivity()
spUITheme?.setSelection(Pref.ipUiTheme(pref))
spResizeImage?.setSelection(Pref.ipResizeImage(pref))
spRefreshAfterToot?.setSelection(Pref.ipRefreshAfterToot(pref))
spAdditionalButtonsPosition?.setSelection(Pref.ipAdditionalButtonsPosition(pref))
spDefaultAccount?.setSelection(
(spDefaultAccount?.adapter as? AccountAdapter)
@ -585,7 +594,6 @@ class ActAppSettingChild : AppCompatActivity()
(spTimeZone?.adapter as? TimeZoneAdapter)
?.getIndexFromId(Pref.spTimeZone(pref))
?: 0
)
footer_button_bg_color = Pref.ipFooterButtonBgColor(pref)
@ -696,6 +704,8 @@ class ActAppSettingChild : AppCompatActivity()
)
}
fun putFontSize(fp : FloatPref, et : EditText?) {
et ?: return
e.put(fp, parseFontSize(et.text.toString().trim()))
@ -750,6 +760,7 @@ class ActAppSettingChild : AppCompatActivity()
putSpinner(Pref.ipUiTheme, spUITheme)
putSpinner(Pref.ipResizeImage, spResizeImage)
putSpinner(Pref.ipRefreshAfterToot, spRefreshAfterToot)
putSpinner(Pref.ipAdditionalButtonsPosition, spAdditionalButtonsPosition)
fun putIf(hasUi : Boolean, sp : IntPref, value : Int) {
if(! hasUi) return
@ -1175,10 +1186,10 @@ class ActAppSettingChild : AppCompatActivity()
R.id.btnCustomShare2Edit -> openCustomShareChooser(CustomShareTarget.CustomShare2)
R.id.btnCustomShare3Edit -> openCustomShareChooser(CustomShareTarget.CustomShare3)
R.id.btnTranslateAppComponentReset -> setCustomShare(CustomShareTarget.Translate,"")
R.id.btnCustomShare1Reset -> setCustomShare(CustomShareTarget.CustomShare1,"")
R.id.btnCustomShare2Reset -> setCustomShare(CustomShareTarget.CustomShare2,"")
R.id.btnCustomShare3Reset -> setCustomShare(CustomShareTarget.CustomShare3,"")
R.id.btnTranslateAppComponentReset -> setCustomShare(CustomShareTarget.Translate, "")
R.id.btnCustomShare1Reset -> setCustomShare(CustomShareTarget.CustomShare1, "")
R.id.btnCustomShare2Reset -> setCustomShare(CustomShareTarget.CustomShare2, "")
R.id.btnCustomShare3Reset -> setCustomShare(CustomShareTarget.CustomShare3, "")
}
}
@ -1757,19 +1768,19 @@ class ActAppSettingChild : AppCompatActivity()
if(isDestroyed) return
val cn = ChooseReceiver.lastComponentName
if(cn != null ) {
if(cn != null) {
ChooseReceiver.lastComponentName = null
setCustomShare(customShareTarget,"${cn.packageName}/${cn.className}")
setCustomShare(customShareTarget, "${cn.packageName}/${cn.className}")
}
}
private fun setCustomShare(target : CustomShareTarget?, value : String){
private fun setCustomShare(target : CustomShareTarget?, value : String) {
target ?: return
val sp : StringPref
val tv : TextView?
when(target) {
CustomShareTarget.Translate -> {

View File

@ -400,14 +400,6 @@ object Pref {
R.id.swShowTranslateButton
)
val bpForceWrapAdditionalButtons = BooleanPref(
"ForceWrapAdditionalButtons",
false,
R.id.swForceWrapAdditionalButtons
)
// int
val ipBackButtonAction = IntPref("back_button_action", 0)
@ -432,11 +424,19 @@ object Pref {
const val RAT_REFRESH_DONT_SCROLL = 1
const val RAT_DONT_REFRESH = 2
val ipVisibilityStyle = IntPref("ipVisibilityStyle", 0)
@Suppress("unused")
const val VS_BY_ACCOUNT = 0
const val VS_MASTODON = 1
const val VS_MISSKEY = 2
val ipVisibilityStyle = IntPref("ipVisibilityStyle", VS_BY_ACCOUNT)
const val ABP_TOP = 0
@Suppress("unused")
const val ABP_BOTTOM = 1
const val ABP_START = 2
const val ABP_END = 3
val ipAdditionalButtonsPosition = IntPref( "AdditionalButtonsPosition",ABP_END)
val ipFooterButtonBgColor = IntPref("footer_button_bg_color", 0)
val ipFooterButtonFgColor = IntPref("footer_button_fg_color", 0)

View File

@ -215,7 +215,6 @@ internal class StatusButtons(
relation
}
val forceWrapAdditionalButtons = Pref.bpForceWrapAdditionalButtons(activity.pref)
var optionalButtonFirst : View? = null
var optionalButtonCount = 0
@ -234,19 +233,13 @@ internal class StatusButtons(
Styler.boost_alpha
)
)
if(forceWrapAdditionalButtons) {
++ optionalButtonCount
if(optionalButtonFirst == null) {
optionalButtonFirst = b
}
++ 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)
@ -255,10 +248,77 @@ internal class StatusButtons(
showCustomShare(CustomShareTarget.CustomShare2, btnCustomShare2)
showCustomShare(CustomShareTarget.CustomShare3, btnCustomShare3)
setWrap(btnTranslate)
setWrap(btnCustomShare1)
setWrap(btnCustomShare2)
setWrap(btnCustomShare3)
val lpConversation = btnConversation.layoutParams as? FlexboxLayout.LayoutParams
val updateAdditionalButton : (btn : ImageButton) -> Unit
when(Pref.ipAdditionalButtonsPosition(activity.pref)) {
Pref.ABP_TOP -> {
// 1行目に追加ボタンが並ぶ
updateAdditionalButton = { btn ->
(btn.layoutParams as? FlexboxLayout.LayoutParams)?.let { lp ->
lp.isWrapBefore = false
lp.startMargin = when(btn) {
optionalButtonFirst -> 0
else -> holder.marginBetween
}
}
}
// 2行目は通常ボタンが並ぶ
// 2行目最初のボタンのstartMarginは追加ボタンの有無で変化する
lpConversation?.startMargin = 0
lpConversation?.isWrapBefore = (optionalButtonCount != 0)
}
Pref.ABP_START -> {
// 始端に追加ボタンが並ぶ
updateAdditionalButton = { btn ->
(btn.layoutParams as? FlexboxLayout.LayoutParams)?.let { lp ->
lp.isWrapBefore = false
lp.startMargin = when(btn) {
optionalButtonFirst -> 0
else -> holder.marginBetween
}
}
}
// 続いて通常ボタンが並ぶ
lpConversation?.startMargin = holder.marginBetween
lpConversation?.isWrapBefore = false
}
Pref.ABP_END -> {
// 始端に通常ボタンが並ぶ
lpConversation?.startMargin = 0
lpConversation?.isWrapBefore = false
// 続いて追加ボタンが並ぶ
updateAdditionalButton = { btn ->
(btn.layoutParams as? FlexboxLayout.LayoutParams)?.let { lp ->
lp.isWrapBefore = false
lp.startMargin = holder.marginBetween
}
}
}
else /* Pref.ABP_BOTTOM */ -> {
// 1行目は通常ボタンが並ぶ
lpConversation?.startMargin = 0
lpConversation?.isWrapBefore = false
// 2行目は追加ボタンが並ぶ
updateAdditionalButton = { btn ->
(btn.layoutParams as? FlexboxLayout.LayoutParams)?.let { lp ->
lp.isWrapBefore = btn == optionalButtonFirst
lp.startMargin = when(btn) {
optionalButtonFirst -> 0
else -> holder.marginBetween
}
}
}
}
}
updateAdditionalButton(btnTranslate)
updateAdditionalButton(btnCustomShare1)
updateAdditionalButton(btnCustomShare2)
updateAdditionalButton(btnCustomShare3)
}
private fun setButton(
@ -543,7 +603,7 @@ class StatusButtonsViewHolder(
) {
private val buttonHeight = ActMain.boostButtonSize
private val marginBetween = (ActMain.boostButtonSize.toFloat() * 0.05f + 0.5f).toInt()
internal val marginBetween = (ActMain.boostButtonSize.toFloat() * 0.05f + 0.5f).toInt()
val paddingH = (buttonHeight.toFloat() * 0.1f + 0.5f).toInt()
val paddingV = (buttonHeight.toFloat() * 0.1f + 0.5f).toInt()
@ -576,64 +636,22 @@ class StatusButtonsViewHolder(
flexWrap = FlexWrap.WRAP
this.justifyContent = justifyContent
btnConversation = imageButton {
fun normalButtons() {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
contentDescription = context.getString(R.string.conversation_view)
btnConversation = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
contentDescription = context.getString(R.string.conversation_view)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
imageResource = R.drawable.ic_forum
}.lparams(buttonHeight, buttonHeight)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
imageResource = R.drawable.ic_forum
}.lparams(buttonHeight, buttonHeight)
btnReply = customView<CountImageButton> {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
minimumWidth = buttonHeight
}.lparams(wrapContent, buttonHeight) {
startMargin = marginBetween
}
btnBoost = customView<CountImageButton> {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
minimumWidth = buttonHeight
}.lparams(wrapContent, buttonHeight) {
startMargin = marginBetween
}
btnFavourite = customView<CountImageButton> {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
minimumWidth = buttonHeight
}.lparams(wrapContent, buttonHeight) {
startMargin = marginBetween
}
llFollow2 = frameLayout {
lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
btnFollow2 = imageButton {
btnReply = customView<CountImageButton> {
background = ContextCompat.getDrawable(
context,
@ -641,83 +659,140 @@ class StatusButtonsViewHolder(
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
contentDescription = context.getString(R.string.follow)
}.lparams(matchParent, matchParent)
minimumWidth = buttonHeight
}.lparams(wrapContent, buttonHeight) {
startMargin = marginBetween
}
ivFollowedBy2 = imageView {
btnBoost = customView<CountImageButton> {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
minimumWidth = buttonHeight
}.lparams(wrapContent, buttonHeight) {
startMargin = marginBetween
}
btnFavourite = customView<CountImageButton> {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
minimumWidth = buttonHeight
}.lparams(wrapContent, buttonHeight) {
startMargin = marginBetween
}
llFollow2 = frameLayout {
lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
btnFollow2 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
contentDescription = context.getString(R.string.follow)
}.lparams(matchParent, matchParent)
ivFollowedBy2 = imageView {
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
}.lparams(matchParent, matchParent)
}
btnMore = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
}.lparams(matchParent, matchParent)
contentDescription = context.getString(R.string.more)
imageResource = R.drawable.ic_more
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
}
btnMore = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
fun additionalButtons() {
btnTranslate = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
contentDescription = context.getString(R.string.more)
imageResource = R.drawable.ic_more
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
btnTranslate = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
btnCustomShare1 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
btnCustomShare1 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
btnCustomShare2 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
btnCustomShare3 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
}
btnCustomShare2 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
when(Pref.ipAdditionalButtonsPosition(activity.pref)) {
Pref.ABP_TOP, Pref.ABP_START -> {
additionalButtons()
normalButtons()
}
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
else -> {
normalButtons()
additionalButtons()
}
}
btnCustomShare3 = imageButton {
background = ContextCompat.getDrawable(
context,
R.drawable.btn_bg_transparent
)
setPadding(paddingH, paddingV, paddingH, paddingV)
scaleType = ImageView.ScaleType.FIT_CENTER
}.lparams(buttonHeight, buttonHeight) {
startMargin = marginBetween
}
}
}
}

View File

@ -418,13 +418,13 @@
<TextView
style="@style/setting_row_label"
android:text="@string/force_wrap_additional_buttons"
android:text="@string/additional_buttons_position"
/>
<LinearLayout style="@style/setting_row_form">
<Switch
android:id="@+id/swForceWrapAdditionalButtons"
<Spinner
android:id="@+id/spAdditionalButtonsPosition"
style="@style/setting_horizontal_stretch"
/>

View File

@ -918,6 +918,8 @@
<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>
<string name="additional_buttons_position">追加ボタンの位置(アプリ再起動が必要)</string>
<string name="top"></string>
<string name="bottom"></string>
</resources>

View File

@ -911,6 +911,8 @@
<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>
<string name="additional_buttons_position">Additional buttons position (app restart required)</string>
<string name="top">Top</string>
<string name="bottom">Bottom</string>
</resources>