fix #122, 選択してコピー画面に残ってたMSP検索ボタンを翻訳ボタンに変更
This commit is contained in:
parent
206098676c
commit
58d03c3d36
|
@ -5,8 +5,11 @@ import android.content.Intent
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import jp.juggler.subwaytooter.action.CustomShare
|
||||
import jp.juggler.subwaytooter.action.CustomShareTarget
|
||||
import jp.juggler.subwaytooter.api.entity.TootAccount
|
||||
import jp.juggler.subwaytooter.api.entity.TootStatus
|
||||
import jp.juggler.subwaytooter.table.MutedWord
|
||||
|
@ -58,6 +61,7 @@ class ActText : AppCompatActivity(), View.OnClickListener {
|
|||
}
|
||||
|
||||
private lateinit var etText : EditText
|
||||
private lateinit var btnTranslate : Button
|
||||
|
||||
private val selection : String
|
||||
get() {
|
||||
|
@ -97,6 +101,7 @@ class ActText : AppCompatActivity(), View.OnClickListener {
|
|||
|
||||
etText.setSelection(content_start, content_end)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal fun initUI() {
|
||||
|
@ -107,13 +112,13 @@ class ActText : AppCompatActivity(), View.OnClickListener {
|
|||
Styler.fixHorizontalMargin(findViewById(R.id.svContent))
|
||||
|
||||
etText = findViewById(R.id.etText)
|
||||
btnTranslate = findViewById(R.id.btnTranslate)
|
||||
|
||||
btnTranslate.setOnClickListener(this)
|
||||
findViewById<View>(R.id.btnCopy).setOnClickListener(this)
|
||||
findViewById<View>(R.id.btnSearch).setOnClickListener(this)
|
||||
findViewById<View>(R.id.btnSend).setOnClickListener(this)
|
||||
findViewById<View>(R.id.btnMuteWord).setOnClickListener(this)
|
||||
|
||||
findViewById<View>(R.id.btnSearchMSP).setOnClickListener(this)
|
||||
findViewById<View>(R.id.btnSearchTS).setOnClickListener(this)
|
||||
|
||||
val btnKeywordFilter : View = findViewById(R.id.btnKeywordFilter)
|
||||
|
@ -133,7 +138,11 @@ class ActText : AppCompatActivity(), View.OnClickListener {
|
|||
|
||||
R.id.btnMuteWord -> muteWord()
|
||||
|
||||
R.id.btnSearchMSP -> searchToot(RESULT_SEARCH_MSP)
|
||||
R.id.btnTranslate -> CustomShare.invoke(
|
||||
this,
|
||||
selection,
|
||||
CustomShareTarget.Translate
|
||||
)
|
||||
|
||||
R.id.btnSearchTS -> searchToot(RESULT_SEARCH_TS)
|
||||
|
||||
|
@ -176,7 +185,7 @@ class ActText : AppCompatActivity(), View.OnClickListener {
|
|||
|
||||
}
|
||||
|
||||
private fun searchToot(resultCode : Int) {
|
||||
private fun searchToot(@Suppress("SameParameterValue") resultCode : Int) {
|
||||
val sv = selection
|
||||
if(sv.isEmpty()) {
|
||||
showToast(this, false, "please select search keyword")
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.*
|
|||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.Drawable
|
||||
import jp.juggler.subwaytooter.ActMain
|
||||
import jp.juggler.subwaytooter.App1
|
||||
import jp.juggler.subwaytooter.Pref
|
||||
import jp.juggler.subwaytooter.R
|
||||
import jp.juggler.subwaytooter.api.entity.TootStatus
|
||||
|
@ -23,7 +24,8 @@ object CustomShare {
|
|||
|
||||
private val log = LogCategory("CustomShare")
|
||||
|
||||
private const val translate_app_component_default = "com.google.android.apps.translate/com.google.android.apps.translate.TranslateActivity"
|
||||
private const val translate_app_component_default =
|
||||
"com.google.android.apps.translate/com.google.android.apps.translate.TranslateActivity"
|
||||
|
||||
// convert "pkgName/className" string to ComponentName object.
|
||||
private fun String.cn() : ComponentName? {
|
||||
|
@ -92,7 +94,35 @@ object CustomShare {
|
|||
}
|
||||
|
||||
fun invoke(
|
||||
activity : ActMain,
|
||||
context : Context,
|
||||
text : String,
|
||||
target : CustomShareTarget
|
||||
) {
|
||||
try {
|
||||
// convert "pkgName/className" string to ComponentName object.
|
||||
val cn = getCustomShareComponentName(App1.pref, target)
|
||||
if(cn == null) {
|
||||
showToast(context, true, R.string.custom_share_app_not_found)
|
||||
return
|
||||
}
|
||||
|
||||
val intent = Intent()
|
||||
intent.action = Intent.ACTION_SEND
|
||||
intent.type = "text/plain"
|
||||
intent.putExtra(Intent.EXTRA_TEXT, text)
|
||||
intent.component = cn
|
||||
context.startActivity(intent)
|
||||
} catch(ex : ActivityNotFoundException) {
|
||||
log.trace(ex)
|
||||
showToast(context, true, R.string.custom_share_app_not_found)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
showToast(context, ex, "invoke() failed.")
|
||||
}
|
||||
}
|
||||
|
||||
fun invoke(
|
||||
context : Context,
|
||||
access_info : SavedAccount,
|
||||
status : TootStatus?,
|
||||
target : CustomShareTarget
|
||||
|
@ -101,33 +131,24 @@ object CustomShare {
|
|||
|
||||
try {
|
||||
// convert "pkgName/className" string to ComponentName object.
|
||||
val cn = getCustomShareComponentName(activity.pref, target)
|
||||
val cn = getCustomShareComponentName(App1.pref, target)
|
||||
if(cn == null) {
|
||||
showToast(activity,true,R.string.custom_share_app_not_found)
|
||||
showToast(context, true, R.string.custom_share_app_not_found)
|
||||
return
|
||||
}
|
||||
|
||||
val sv = TootTextEncoder.encodeStatusForTranslate(activity, access_info, status)
|
||||
|
||||
val intent = Intent()
|
||||
intent.action = Intent.ACTION_SEND
|
||||
intent.type = "text/plain"
|
||||
intent.putExtra(Intent.EXTRA_TEXT, sv)
|
||||
intent.component = cn
|
||||
activity.startActivity(intent)
|
||||
} catch( ex: ActivityNotFoundException ){
|
||||
log.trace(ex)
|
||||
showToast(activity, true, R.string.custom_share_app_not_found)
|
||||
val sv = TootTextEncoder.encodeStatusForTranslate(context, access_info, status)
|
||||
invoke(context, sv, target)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
showToast(activity, ex, "invoke() failed.")
|
||||
showToast(context, ex, "invoke() failed.")
|
||||
}
|
||||
}
|
||||
|
||||
private val cache = HashMap<CustomShareTarget, Pair<CharSequence?, Drawable?>>()
|
||||
|
||||
fun getCache(target:CustomShareTarget) = cache[target]
|
||||
|
||||
fun getCache(target : CustomShareTarget) = cache[target]
|
||||
|
||||
fun reloadCache(context : Context, pref : SharedPreferences) {
|
||||
val pm = context.packageManager
|
||||
CustomShareTarget.values().forEach { target ->
|
||||
|
|
|
@ -79,10 +79,10 @@
|
|||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSearchMSP"
|
||||
android:id="@+id/btnTranslate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/toot_search_msp"
|
||||
android:text="@string/translate"
|
||||
android:textAllCaps="false"
|
||||
/>
|
||||
|
||||
|
|
Loading…
Reference in New Issue