diff --git a/app/src/main/java/jp/juggler/subwaytooter/ActAppSettingChild.kt b/app/src/main/java/jp/juggler/subwaytooter/ActAppSettingChild.kt index 4104be39..143460dd 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/ActAppSettingChild.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/ActAppSettingChild.kt @@ -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(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 -> { diff --git a/app/src/main/java/jp/juggler/subwaytooter/Pref.kt b/app/src/main/java/jp/juggler/subwaytooter/Pref.kt index 7b3d498f..138b4179 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/Pref.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/Pref.kt @@ -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) diff --git a/app/src/main/java/jp/juggler/subwaytooter/StatusButtons.kt b/app/src/main/java/jp/juggler/subwaytooter/StatusButtons.kt index 3a7d000d..8fb10551 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/StatusButtons.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/StatusButtons.kt @@ -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 { - - 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 { - - 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 { - 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 { 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 { + 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 { + 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 - } - } } } diff --git a/app/src/main/res/layout/act_app_setting_behavior.xml b/app/src/main/res/layout/act_app_setting_behavior.xml index e094c515..3656f3da 100644 --- a/app/src/main/res/layout/act_app_setting_behavior.xml +++ b/app/src/main/res/layout/act_app_setting_behavior.xml @@ -418,13 +418,13 @@ - diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 817cb86c..542d4c2c 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -918,6 +918,8 @@ カスタム共有ボタン2 カスタム共有ボタン3 共有先のアプリがインストールされていません。「アプリ設定/挙動」を確認してください - 追加ボタンを強制的に折り返す + 追加ボタンの位置(アプリ再起動が必要) + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 12706b03..a3fb5f1d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -911,6 +911,8 @@ Custom share button 2 Custom share button 3 the share target app is not installed. please configure it in \"App setting/behavior\". - Force wrap additional buttons + Additional buttons position (app restart required) + Top + Bottom \ No newline at end of file