1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-01-27 09:11:23 +01:00

簡易投稿メニューを追加

This commit is contained in:
tateisu 2019-04-13 05:19:15 +09:00
parent 24b26de8a7
commit af06ea5bce
9 changed files with 362 additions and 10 deletions

View File

@ -29,10 +29,7 @@ import com.google.android.material.navigation.NavigationView
import jp.juggler.subwaytooter.action.*
import jp.juggler.subwaytooter.api.*
import jp.juggler.subwaytooter.api.entity.*
import jp.juggler.subwaytooter.dialog.AccountPicker
import jp.juggler.subwaytooter.dialog.ActionsDialog
import jp.juggler.subwaytooter.dialog.DlgTextInput
import jp.juggler.subwaytooter.dialog.ProgressDialogEx
import jp.juggler.subwaytooter.dialog.*
import jp.juggler.subwaytooter.span.MyClickableSpan
import jp.juggler.subwaytooter.span.MyClickableSpanClickCallback
import jp.juggler.subwaytooter.table.AcctColor
@ -146,6 +143,7 @@ class ActMain : AppCompatActivity()
private lateinit var llQuickTootBar : View
private lateinit var etQuickToot : MyEditText
private lateinit var btnQuickToot : ImageButton
private lateinit var btnQuickTootMenu : ImageButton
lateinit var post_helper : PostHelper
class PhoneEnv {
@ -718,9 +716,32 @@ class ActMain : AppCompatActivity()
R.id.btnToot -> Action_Account.openPost(this@ActMain)
R.id.btnQuickToot -> performQuickPost(null)
R.id.btnQuickTootMenu -> performQuickTootMenu()
}
}
private val dlgQuickTootMenu = DlgQuickTootMenu(this, object : DlgQuickTootMenu.Callback {
override fun onMacro(text : String) {
val editable = etQuickToot.text
if(editable?.isNotEmpty() ==true) {
val start = etQuickToot.selectionStart
val end = etQuickToot.selectionEnd
editable.replace(start, end, text)
etQuickToot.requestFocus()
etQuickToot.setSelection(start + text.length)
}else{
etQuickToot.setText(text)
etQuickToot.requestFocus()
etQuickToot.setSelection(text.length)
}
}
})
private fun performQuickTootMenu() {
dlgQuickTootMenu.toggle()
}
private fun performQuickPost(account : SavedAccount?) {
if(account == null) {
phoneTab({ env ->
@ -1335,6 +1356,7 @@ class ActMain : AppCompatActivity()
llQuickTootBar = findViewById(R.id.llQuickTootBar)
etQuickToot = findViewById(R.id.etQuickToot)
btnQuickToot = findViewById(R.id.btnQuickToot)
btnQuickTootMenu = findViewById(R.id.btnQuickTootMenu)
if(! Pref.bpQuickTootBar(pref)) {
llQuickTootBar.visibility = View.GONE
@ -1343,6 +1365,7 @@ class ActMain : AppCompatActivity()
btnToot.setOnClickListener(this)
btnMenu.setOnClickListener(this)
btnQuickToot.setOnClickListener(this)
btnQuickTootMenu.setOnClickListener(this)
if(Pref.bpDontUseActionButtonWithQuickTootBar(pref)) {
etQuickToot.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
@ -2318,9 +2341,9 @@ class ActMain : AppCompatActivity()
val accessInto = opener.accessInfo
val whoRef = opener.whoRef
val whoAcct = if(whoRef != null ){
val whoAcct = if(whoRef != null) {
accessInto?.getFullAcct(whoRef.get())
}else{
} else {
null
}
@ -2344,9 +2367,6 @@ class ActMain : AppCompatActivity()
return
}
// ステータスページをアプリから開く
m = TootStatus.reStatusPage.matcher(opener.url)
if(m.find()) {
@ -2558,6 +2578,7 @@ class ActMain : AppCompatActivity()
btnMenu.backgroundDrawable = getAdaptiveRippleDrawable(colorBg, colorRipple)
btnToot.backgroundDrawable = getAdaptiveRippleDrawable(colorBg, colorRipple)
btnQuickToot.backgroundDrawable = getAdaptiveRippleDrawable(colorBg, colorRipple)
btnQuickTootMenu.backgroundDrawable = getAdaptiveRippleDrawable(colorBg, colorRipple)
val csl = ColorStateList.valueOf(
footer_button_fg_color.notZero()
@ -2566,6 +2587,7 @@ class ActMain : AppCompatActivity()
btnToot.imageTintList = csl
btnMenu.imageTintList = csl
btnQuickToot.imageTintList = csl
btnQuickTootMenu.imageTintList = csl
var c = footer_tab_bg_color.notZero()
?: getAttributeColor(this, R.attr.colorColumnStripBackground)

View File

@ -483,6 +483,8 @@ object Pref {
val spTimeZone = StringPref("TimeZone","")
val spQuickTootMacro = StringPref("QuickTootMacro","")
// long
val lpTabletTootDefaultAccount = LongPref("tablet_toot_default_account", - 1L)

View File

@ -0,0 +1,122 @@
package jp.juggler.subwaytooter.dialog
import android.annotation.SuppressLint
import android.app.Dialog
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import jp.juggler.subwaytooter.ActMain
import jp.juggler.subwaytooter.Pref
import jp.juggler.subwaytooter.R
import jp.juggler.subwaytooter.put
import jp.juggler.util.dismissSafe
import java.lang.ref.WeakReference
import android.view.Gravity
class DlgQuickTootMenu(
internal val activity : ActMain,
internal val callback : Callback
) {
companion object {
val etTextIds = arrayOf(
R.id.etText0,
R.id.etText1,
R.id.etText2,
R.id.etText3,
R.id.etText4,
R.id.etText5
)
val btnTextIds = arrayOf(
R.id.btnText0,
R.id.btnText1,
R.id.btnText2,
R.id.btnText3,
R.id.btnText4,
R.id.btnText5
)
}
interface Callback {
fun onMacro(text:String)
}
var dialogRef : WeakReference<Dialog>? = null
fun toggle() {
val dialog = dialogRef?.get()
if(dialog != null && dialog.isShowing) {
dialog.dismissSafe()
} else {
show()
}
}
val etText = arrayOfNulls<EditText>(6)
@SuppressLint("InflateParams")
fun show(){
val view = activity.layoutInflater.inflate(R.layout.dlg_quick_toot_menu, null, false)
view.findViewById<Button>(R.id.btnCancel).setOnClickListener {
val dialog = dialogRef?.get()
if( dialog != null && dialog.isShowing) {
dialog.dismissSafe()
}
}
val btnListener :View.OnClickListener = View.OnClickListener{ v ->
val text = etText[v.tag as? Int ?: 0]?.text?.toString()
if(text!= null) {
dialogRef?.get()?.dismissSafe()
callback.onMacro(text)
}
}
val strings = loadStrings()
val size = etText.size
for(i in 0 until size ){
val et :EditText = view.findViewById(etTextIds[i])
val btn : Button = view.findViewById(btnTextIds[i])
btn.tag = i
btn.setOnClickListener(btnListener)
etText[i] = et
et.setText( if( i >= strings.size){
""
}else{
strings[i]
})
}
val dialog = Dialog(activity)
this.dialogRef = WeakReference(dialog)
dialog.setCanceledOnTouchOutside(true)
dialog.setContentView(view)
dialog.setOnDismissListener { saveStrings() }
dialog.window?.apply{
val wlp = attributes
wlp.gravity = Gravity.BOTTOM or Gravity.START
wlp.flags = wlp.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv()
attributes = wlp
setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
}
dialog.show()
}
private fun loadStrings() =
Pref.spQuickTootMacro(activity.pref).split("\n")
private fun saveStrings() = activity.pref
.edit()
.put(
Pref.spQuickTootMacro,
etText.joinToString("\n") {
(it?.text?.toString() ?: "").replace("\n", " ")
}
)
.apply()
}

View File

@ -366,7 +366,7 @@ class CustomEmojiCache(internal val context : Context) {
)
return b
} catch(ex : Throwable) {
log.e(ex, "decodeSVG failed.")
log.e(ex, "decodeSVG failed. $url")
}
return null
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M14,2L6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6zM16,18L8,18v-2h8v2zM16,14L8,14v-2h8v2zM13,9L13,3.5L18.5,9L13,9z"/>
</vector>

View File

@ -123,6 +123,14 @@
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/btnQuickTootMenu"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/quick_toot_menu"
app:srcCompat="@drawable/ic_description"
/>
<jp.juggler.subwaytooter.view.MyEditText
android:id="@+id/etQuickToot"
android:layout_width="0dp"

View File

@ -0,0 +1,185 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<jp.juggler.subwaytooter.view.MaxHeightScrollView
android:id="@+id/llColumnSetting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
app:maxHeight="240dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/etText0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="6dp"
android:inputType="text"
/>
<Button
android:id="@+id/btnText0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="@string/input"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/etText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="6dp"
android:inputType="text"
/>
<Button
android:id="@+id/btnText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="@string/input"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/etText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="6dp"
android:inputType="text"
/>
<Button
android:id="@+id/btnText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="@string/input"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/etText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="6dp"
android:inputType="text"
/>
<Button
android:id="@+id/btnText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="@string/input"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/etText4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:layout_marginEnd="6dp"
/>
<Button
android:id="@+id/btnText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="@string/input"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/etText5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:layout_marginEnd="6dp"
/>
<Button
android:id="@+id/btnText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="@string/input"
/>
</LinearLayout>
</LinearLayout>
</jp.juggler.subwaytooter.view.MaxHeightScrollView>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btnCancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
/>
</LinearLayout>
</LinearLayout>

View File

@ -890,5 +890,7 @@
<string name="hashtag_of_from">Hashtag :#%1$s (%2$sから)</string>
<string name="boost_with_visibility">公開範囲を指定してブースト</string>
<string name="confirm_private_boost_from">このトゥートを %1$s からブーストしますか? 全てのフォロワーに公開されます</string>
<string name="quick_toot_menu">簡易投稿メニュー</string>
<string name="input">Input</string>
</resources>

View File

@ -885,5 +885,7 @@
<string name="hashtag_of_from">Hashtag :#%1$s from %2$s</string>
<string name="boost_with_visibility">Boost with visibility</string>
<string name="confirm_private_boost_from">Boost this status from %1$s ? It\'s shown to all followers.</string>
<string name="quick_toot_menu">Quick toot menu</string>
<string name="input">Input</string>
</resources>