- decodeRingtonePickerResult() で ActivityResult.resultCode をチェックする
- Intent.intOrNull() を Intent.int() にリネーム - 投稿直後に 疑似トーストの popupWindow.showAtLocation に失敗する
This commit is contained in:
parent
c1afdbc0ab
commit
03058b25b2
|
@ -154,8 +154,7 @@ class ActAccountSetting : AppCompatActivity(),
|
|||
}
|
||||
|
||||
private val arNotificationSound = ActivityResultHandler(log) { r ->
|
||||
if (r.isNotOk) return@ActivityResultHandler
|
||||
r.data?.decodeRingtonePickerResult()?.let { uri ->
|
||||
r.decodeRingtonePickerResult()?.let { uri ->
|
||||
notificationSoundUri = uri.toString()
|
||||
saveUIToData()
|
||||
// Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), uri);
|
||||
|
|
|
@ -55,8 +55,7 @@ class ActHighlightWordEdit
|
|||
private var bBusy = false
|
||||
|
||||
private val arNotificationSound = ActivityResultHandler(log) { r ->
|
||||
if (r.isNotOk) return@ActivityResultHandler
|
||||
r.data?.decodeRingtonePickerResult()?.let { uri ->
|
||||
r.decodeRingtonePickerResult()?.let { uri ->
|
||||
item.sound_uri = uri.toString()
|
||||
item.sound_type = HighlightWord.SOUND_TYPE_CUSTOM
|
||||
showSound()
|
||||
|
|
|
@ -223,7 +223,7 @@ class ActMain : AppCompatActivity(),
|
|||
val arColumnColor = ActivityResultHandler(log) { r ->
|
||||
if (r.isNotOk) return@ActivityResultHandler
|
||||
appState.saveColumnList()
|
||||
r.data?.intOrNull(ActColumnCustomize.EXTRA_COLUMN_INDEX)
|
||||
r.data?.int(ActColumnCustomize.EXTRA_COLUMN_INDEX)
|
||||
?.let { appState.column(it) }
|
||||
?.let {
|
||||
it.fireColumnColor()
|
||||
|
@ -238,7 +238,7 @@ class ActMain : AppCompatActivity(),
|
|||
val arLanguageFilter = ActivityResultHandler(log) { r ->
|
||||
if (r.isNotOk) return@ActivityResultHandler
|
||||
appState.saveColumnList()
|
||||
r.data?.intOrNull(ActLanguageFilter.EXTRA_COLUMN_INDEX)
|
||||
r.data?.int(ActLanguageFilter.EXTRA_COLUMN_INDEX)
|
||||
?.let { appState.column(it) }
|
||||
?.onLanguageFilterChanged()
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ class ActMain : AppCompatActivity(),
|
|||
r.data?.getIntegerArrayListExtra(ActColumnList.EXTRA_ORDER)
|
||||
?.takeIf { isOrderChanged(it) }
|
||||
?.let { setColumnsOrder(it) }
|
||||
r.data?.intOrNull(ActColumnList.EXTRA_SELECTION)
|
||||
r.data?.int(ActColumnList.EXTRA_SELECTION)
|
||||
?.takeIf { it in 0 until appState.columnCount }
|
||||
?.let { scrollToColumn(it) }
|
||||
}
|
||||
|
|
|
@ -62,8 +62,7 @@ class ActNickname : AppCompatActivity(), View.OnClickListener, ColorPickerDialog
|
|||
private var loadingBusy = false
|
||||
|
||||
private val arNotificationSound = ActivityResultHandler(log) { r ->
|
||||
if (r.isNotOk) return@ActivityResultHandler
|
||||
r.data?.decodeRingtonePickerResult()?.let { uri ->
|
||||
r.decodeRingtonePickerResult()?.let { uri ->
|
||||
notificationSoundUri = uri.toString()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,27 @@ import android.content.Intent
|
|||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.activity.result.ActivityResult
|
||||
|
||||
/**
|
||||
* API 33 でget() が deprecatedになる?
|
||||
* API 33 で Bundle.get() が deprecatedになる。
|
||||
* type safeにするべきだが、過去の使い方にもよるかな…
|
||||
*/
|
||||
fun Bundle.getRaw(key: String) = get(key)
|
||||
|
||||
fun Intent.decodeRingtonePickerResult() =
|
||||
extras?.getRaw(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as? Uri
|
||||
/**
|
||||
* Ringtone pickerの処理結果のUriまたはnull
|
||||
*/
|
||||
fun ActivityResult.decodeRingtonePickerResult() =
|
||||
when {
|
||||
isNotOk -> null
|
||||
else -> data?.extras?.getRaw(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as? Uri
|
||||
}
|
||||
|
||||
fun Bundle.intOrNull(key: String) =
|
||||
/**
|
||||
* Bundleからキーを指定してint値またはnullを得る
|
||||
*/
|
||||
fun Bundle.int(key: String) =
|
||||
when (val v = getRaw(key)) {
|
||||
null -> null
|
||||
is Number -> v.toInt()
|
||||
|
@ -21,7 +32,10 @@ fun Bundle.intOrNull(key: String) =
|
|||
else -> null
|
||||
}
|
||||
|
||||
fun Bundle.longOrNull(key: String) =
|
||||
/**
|
||||
* Bundleからキーを指定してlong値またはnullを得る
|
||||
*/
|
||||
fun Bundle.long(key: String) =
|
||||
when (val v = getRaw(key)) {
|
||||
null -> null
|
||||
is Number -> v.toLong()
|
||||
|
@ -29,5 +43,12 @@ fun Bundle.longOrNull(key: String) =
|
|||
else -> null
|
||||
}
|
||||
|
||||
fun Intent.intOrNull(key: String) = extras?.intOrNull(key)
|
||||
fun Intent.longOrNull(key: String) = extras?.longOrNull(key)
|
||||
/**
|
||||
* IntentのExtrasからキーを指定してint値またはnullを得る
|
||||
*/
|
||||
fun Intent.int(key: String) = extras?.int(key)
|
||||
|
||||
/**
|
||||
* IntentのExtrasからキーを指定してlong値またはnullを得る
|
||||
*/
|
||||
fun Intent.long(key: String) = extras?.long(key)
|
||||
|
|
|
@ -86,7 +86,7 @@ fun initializeToastUtils(app: Application) {
|
|||
suspend fun Animation.startAndAwait(duration: Long, v: View) =
|
||||
try {
|
||||
withTimeout(duration + 333L) {
|
||||
suspendCancellableCoroutine<Unit> { cont ->
|
||||
suspendCancellableCoroutine { cont ->
|
||||
v.clearAnimation()
|
||||
this@startAndAwait.duration = duration
|
||||
this@startAndAwait.fillAfter = true
|
||||
|
@ -102,6 +102,7 @@ suspend fun Animation.startAndAwait(duration: Long, v: View) =
|
|||
}
|
||||
} catch (ex: TimeoutCancellationException) {
|
||||
log.w(ex, "startAndAwait timeout.")
|
||||
Unit
|
||||
}
|
||||
|
||||
private fun showPopup(activity: Activity, bLong: Boolean, message: String) {
|
||||
|
@ -128,9 +129,10 @@ private fun showPopup(activity: Activity, bLong: Boolean, message: String) {
|
|||
} catch (ex: Throwable) {
|
||||
log.trace(ex, "dismiss failed.")
|
||||
}
|
||||
lastPopup = WeakReference(popupWindow)
|
||||
|
||||
lastPopup = null
|
||||
popupWindow.showAtLocation(rootView, Gravity.CENTER, 0, 0)
|
||||
lastPopup = WeakReference(popupWindow)
|
||||
|
||||
launchMain {
|
||||
|
||||
|
|
Loading…
Reference in New Issue