クラッシュレポート対応、リファクタ
This commit is contained in:
parent
71b2fa2145
commit
a01cfd9d6c
|
@ -30,7 +30,7 @@ object Pref {
|
|||
}
|
||||
|
||||
abstract fun put(editor : SharedPreferences.Editor, v : T)
|
||||
abstract fun invoke(pref: SharedPreferences) : T
|
||||
abstract fun invoke(pref : SharedPreferences) : T
|
||||
|
||||
operator fun invoke(context : Context) : T {
|
||||
return invoke(pref(context))
|
||||
|
@ -38,8 +38,11 @@ object Pref {
|
|||
|
||||
}
|
||||
|
||||
class BooleanPref(key : String, private val defVal : Boolean, val id : Int) :
|
||||
BasePref<Boolean>(key) {
|
||||
class BooleanPref(
|
||||
key : String,
|
||||
private val defVal : Boolean,
|
||||
val id : Int
|
||||
) : BasePref<Boolean>(key) {
|
||||
|
||||
override operator fun invoke(pref : SharedPreferences) : Boolean {
|
||||
return pref.getBoolean(key, defVal)
|
||||
|
@ -83,8 +86,11 @@ object Pref {
|
|||
}
|
||||
}
|
||||
|
||||
class StringPref(key : String, private val defVal : String, val skipImport : Boolean = false) :
|
||||
BasePref<String>(key) {
|
||||
class StringPref(
|
||||
key : String,
|
||||
private val defVal : String,
|
||||
val skipImport : Boolean = false
|
||||
) : BasePref<String>(key) {
|
||||
|
||||
override operator fun invoke(pref : SharedPreferences) : String {
|
||||
return pref.getString(key, defVal)
|
||||
|
@ -95,8 +101,6 @@ object Pref {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// boolean
|
||||
|
||||
val bpAllowNonSpaceBeforeEmojiShortcode = BooleanPref(
|
||||
|
|
|
@ -21,7 +21,6 @@ import jp.juggler.subwaytooter.R
|
|||
import jp.juggler.subwaytooter.util.LogCategory
|
||||
import jp.juggler.subwaytooter.util.Utils
|
||||
|
||||
|
||||
object LoginForm {
|
||||
private val log = LogCategory("LoginForm")
|
||||
|
||||
|
@ -29,7 +28,14 @@ object LoginForm {
|
|||
|
||||
@SuppressLint("InflateParams")
|
||||
fun showLoginForm(
|
||||
activity : Activity, instanceArg : String?, callback : LoginFormCallback
|
||||
activity : Activity,
|
||||
instanceArg : String?,
|
||||
onClickOk : (
|
||||
dialog : Dialog,
|
||||
instance : String,
|
||||
bPseudoAccount : Boolean,
|
||||
bInputAccessToken : Boolean
|
||||
) -> Unit
|
||||
) {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dlg_account_add, null, false)
|
||||
val etInstance :AutoCompleteTextView = view.findViewById(R.id.etInstance)
|
||||
|
@ -65,7 +71,7 @@ object LoginForm {
|
|||
Utils.showToast(activity, true, R.string.instance_not_need_slash)
|
||||
return@OnClickListener
|
||||
}
|
||||
callback(dialog, instance, cbPseudoAccount.isChecked, cbInputAccessToken.isChecked)
|
||||
onClickOk(dialog, instance, cbPseudoAccount.isChecked, cbInputAccessToken.isChecked)
|
||||
})
|
||||
view.findViewById<View>(R.id.btnCancel).setOnClickListener { dialog.cancel() }
|
||||
|
||||
|
|
|
@ -17,7 +17,12 @@ import jp.juggler.subwaytooter.util.Utils
|
|||
object ReportForm {
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
fun showReportForm(activity : Activity, who : TootAccount, status : TootStatus?, callback : ReportFormCallback) {
|
||||
fun showReportForm(
|
||||
activity : Activity,
|
||||
who : TootAccount,
|
||||
status : TootStatus?,
|
||||
onClickOk : (dialog : Dialog, comment : String) -> Unit
|
||||
) {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dlg_report_user, null, false)
|
||||
|
||||
val tvUser = view.findViewById<TextView>(R.id.tvUser)
|
||||
|
@ -36,7 +41,7 @@ object ReportForm {
|
|||
return@OnClickListener
|
||||
}
|
||||
|
||||
callback(dialog, comment)
|
||||
onClickOk(dialog, comment)
|
||||
})
|
||||
view.findViewById<View>(R.id.btnCancel).setOnClickListener { dialog.cancel() }
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package jp.juggler.subwaytooter.dialog
|
||||
|
||||
import android.app.Dialog
|
||||
|
||||
typealias LoginFormCallback = (dialog : Dialog, instance : String, bPseudoAccount : Boolean, bInputAccessToken : Boolean) -> Unit
|
||||
typealias ReportFormCallback = (dialog : Dialog, comment : String) -> Unit
|
|
@ -40,10 +40,16 @@ class EmojiImageSpan(context : Context, private val res_id : Int) : ReplacementS
|
|||
this.context = context.applicationContext
|
||||
}
|
||||
|
||||
private fun getImageSize(paint:Paint) = (0.5f + scale_ratio * paint.textSize).toInt()
|
||||
|
||||
override fun getSize(
|
||||
paint : Paint, text : CharSequence, @IntRange(from = 0) start : Int, @IntRange(from = 0) end : Int, fm : Paint.FontMetricsInt?
|
||||
paint : Paint,
|
||||
text : CharSequence,
|
||||
@IntRange(from = 0) start : Int,
|
||||
@IntRange(from = 0) end : Int,
|
||||
fm : Paint.FontMetricsInt?
|
||||
) : Int {
|
||||
val size = (0.5f + scale_ratio * paint.textSize).toInt()
|
||||
val size = getImageSize(paint)
|
||||
|
||||
if(fm != null) {
|
||||
val c_descent = (0.5f + size * descent_ratio).toInt()
|
||||
|
@ -57,14 +63,22 @@ class EmojiImageSpan(context : Context, private val res_id : Int) : ReplacementS
|
|||
}
|
||||
|
||||
override fun draw(
|
||||
canvas : Canvas, text : CharSequence, start : Int, end : Int, x : Float, top : Int, baseline : Int, bottom : Int, paint : Paint
|
||||
canvas : Canvas,
|
||||
text : CharSequence,
|
||||
start : Int,
|
||||
end : Int,
|
||||
x : Float,
|
||||
top : Int,
|
||||
baseline : Int,
|
||||
bottom : Int,
|
||||
paint : Paint
|
||||
) {
|
||||
val size = (0.5f + scale_ratio * paint.textSize).toInt()
|
||||
val d = cachedDrawable ?: return
|
||||
|
||||
val size = getImageSize(paint)
|
||||
val c_descent = (0.5f + size * descent_ratio).toInt()
|
||||
val transY = baseline - size + c_descent
|
||||
|
||||
val d = cachedDrawable ?: return
|
||||
|
||||
canvas.save()
|
||||
canvas.translate(x, transY.toFloat())
|
||||
d.setBounds(0, 0, size, size)
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.text.style.CharacterStyle
|
|||
class HighlightSpan(val color_fg : Int, val color_bg : Int) : CharacterStyle() {
|
||||
|
||||
override fun updateDrawState(ds : TextPaint) {
|
||||
// super.updateDrawState( ds );
|
||||
if(color_fg != 0) ds.color = color_fg
|
||||
if(color_bg != 0) ds.bgColor = color_bg
|
||||
}
|
||||
|
|
|
@ -9,9 +9,14 @@ import java.lang.ref.WeakReference
|
|||
import jp.juggler.subwaytooter.table.AcctColor
|
||||
import jp.juggler.subwaytooter.util.LinkClickContext
|
||||
|
||||
typealias MyClickableSpanClickCallback = (widget : View, span : MyClickableSpan)->Unit
|
||||
|
||||
class MyClickableSpan internal constructor(
|
||||
val lcc : LinkClickContext, val text : String, val url : String, ac : AcctColor?, val tag : Any?
|
||||
class MyClickableSpan(
|
||||
val lcc : LinkClickContext,
|
||||
val text : String,
|
||||
val url : String,
|
||||
ac : AcctColor?,
|
||||
val tag : Any?
|
||||
) : ClickableSpan() {
|
||||
|
||||
companion object {
|
||||
|
@ -22,7 +27,6 @@ class MyClickableSpan internal constructor(
|
|||
val color_bg : Int
|
||||
|
||||
init {
|
||||
|
||||
if(ac != null) {
|
||||
this.color_fg = ac.color_fg
|
||||
this.color_bg = ac.color_bg
|
||||
|
@ -33,20 +37,13 @@ class MyClickableSpan internal constructor(
|
|||
}
|
||||
|
||||
override fun onClick( view : View) {
|
||||
val cb = link_callback?.get()
|
||||
if( cb != null ) cb(view,this )
|
||||
link_callback?.get()?.invoke(view,this )
|
||||
}
|
||||
|
||||
override fun updateDrawState(ds : TextPaint) {
|
||||
super.updateDrawState(ds)
|
||||
|
||||
if(color_fg != 0) {
|
||||
ds.color = color_fg
|
||||
}
|
||||
if(color_bg != 0) {
|
||||
ds.bgColor = color_bg
|
||||
}
|
||||
|
||||
if(color_fg != 0) ds.color = color_fg
|
||||
if(color_bg != 0) ds.bgColor = color_bg
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,13 +42,20 @@ class NetworkEmojiSpan internal constructor(private val url : String) : Replacem
|
|||
fun delayInvalidate(delay : Long)
|
||||
}
|
||||
|
||||
fun setInvalidateCallback(draw_target_tag : Any, invalidate_callback : InvalidateCallback) {
|
||||
fun setInvalidateCallback(
|
||||
draw_target_tag : Any,
|
||||
invalidate_callback : InvalidateCallback
|
||||
) {
|
||||
this.refDrawTarget = WeakReference(draw_target_tag)
|
||||
this.invalidate_callback = invalidate_callback
|
||||
}
|
||||
|
||||
override fun getSize(
|
||||
paint : Paint, text : CharSequence, @IntRange(from = 0) start : Int, @IntRange(from = 0) end : Int, fm : Paint.FontMetricsInt?
|
||||
paint : Paint,
|
||||
text : CharSequence,
|
||||
@IntRange(from = 0) start : Int,
|
||||
@IntRange(from = 0) end : Int,
|
||||
fm : Paint.FontMetricsInt?
|
||||
) : Int {
|
||||
val size = (0.5f + scale_ratio * paint.textSize).toInt()
|
||||
|
||||
|
@ -64,7 +71,15 @@ class NetworkEmojiSpan internal constructor(private val url : String) : Replacem
|
|||
}
|
||||
|
||||
override fun draw(
|
||||
canvas : Canvas, text : CharSequence, start : Int, end : Int, x : Float, top : Int, baseline : Int, bottom : Int, textPaint : Paint
|
||||
canvas : Canvas,
|
||||
text : CharSequence,
|
||||
start : Int,
|
||||
end : Int,
|
||||
x : Float,
|
||||
top : Int,
|
||||
baseline : Int,
|
||||
bottom : Int,
|
||||
textPaint : Paint
|
||||
) {
|
||||
val invalidate_callback = this.invalidate_callback
|
||||
if(invalidate_callback == null) {
|
||||
|
@ -73,7 +88,7 @@ class NetworkEmojiSpan internal constructor(private val url : String) : Replacem
|
|||
}
|
||||
|
||||
// APNGデータの取得
|
||||
val frames = App1.custom_emoji_cache.getFrames( refDrawTarget, url){
|
||||
val frames = App1.custom_emoji_cache.getFrames(refDrawTarget, url) {
|
||||
invalidate_callback.delayInvalidate(0)
|
||||
} ?: return
|
||||
|
||||
|
@ -104,7 +119,7 @@ class NetworkEmojiSpan internal constructor(private val url : String) : Replacem
|
|||
|
||||
// 少し後に描画しなおす
|
||||
val delay = mFrameFindResult.delay
|
||||
if(delay != Long.MAX_VALUE && !Pref.bpDisableEmojiAnimation(App1.pref)) {
|
||||
if(delay != Long.MAX_VALUE && ! Pref.bpDisableEmojiAnimation(App1.pref)) {
|
||||
invalidate_callback.delayInvalidate(delay)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package jp.juggler.subwaytooter.span
|
||||
|
||||
import android.view.View
|
||||
|
||||
typealias MyClickableSpanClickCallback = (widget : View, span : MyClickableSpan)->Unit
|
|
@ -1,34 +0,0 @@
|
|||
// emojiOne フォントを使っていた時代の遺物
|
||||
//package jp.juggler.subwaytooter.util
|
||||
//
|
||||
//import android.graphics.Paint
|
||||
//import android.graphics.Typeface
|
||||
//import android.text.TextPaint
|
||||
//import android.text.style.MetricAffectingSpan
|
||||
//
|
||||
//class EmojiSpan(private val typeface : Typeface) : MetricAffectingSpan() {
|
||||
//
|
||||
// override fun updateDrawState(drawState : TextPaint) {
|
||||
// apply(drawState)
|
||||
// }
|
||||
//
|
||||
// override fun updateMeasureState(paint : TextPaint) {
|
||||
// apply(paint)
|
||||
// }
|
||||
//
|
||||
// private fun apply(paint : Paint) {
|
||||
// val oldTypeface = paint.typeface
|
||||
// val oldStyle = oldTypeface?.style ?: 0
|
||||
// val fakeStyle = oldStyle and typeface.getStyle().inv()
|
||||
//
|
||||
// if(fakeStyle and Typeface.BOLD != 0) {
|
||||
// paint.isFakeBoldText = true
|
||||
// }
|
||||
//
|
||||
// if(fakeStyle and Typeface.ITALIC != 0) {
|
||||
// paint.textSkewX = - 0.25f
|
||||
// }
|
||||
//
|
||||
// paint.typeface = typeface
|
||||
// }
|
||||
//}
|
Loading…
Reference in New Issue