ネットワーク接続の状態が変化した時にカスタム絵文字のエラーキャッシュを破棄する
This commit is contained in:
parent
76c15e4858
commit
a93c4bd132
|
@ -141,7 +141,10 @@ class AppState(internal val context : Context, internal val pref : SharedPrefere
|
|||
this.handler = Handler()
|
||||
this.density = context.resources.displayMetrics.density
|
||||
this.stream_reader = StreamReader(context, handler, pref)
|
||||
this.networkTracker = NetworkStateTracker(context)
|
||||
this.networkTracker = NetworkStateTracker(context){
|
||||
App1.custom_emoji_cache.onNetworkChanged()
|
||||
App1.custom_emoji_lister.onNetworkChanged()
|
||||
}
|
||||
loadColumnList()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package jp.juggler.subwaytooter.api.entity
|
||||
|
||||
import android.content.Context
|
||||
import android.os.SystemClock
|
||||
import jp.juggler.subwaytooter.App1
|
||||
import jp.juggler.subwaytooter.Pref
|
||||
|
@ -368,5 +369,6 @@ class TootInstance(parser : TootParser, src : JSONObject) {
|
|||
client.instance = tmpInstance // must be last.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,11 @@ class CustomEmojiCache(internal val context : Context) {
|
|||
workers.add(worker)
|
||||
}
|
||||
}
|
||||
|
||||
// ネットワーク接続が切り替わったタイミングでエラーキャッシュをクリアする
|
||||
fun onNetworkChanged() {
|
||||
cache_error.clear()
|
||||
}
|
||||
|
||||
// カラムのリロードボタンを押したタイミングでエラーキャッシュをクリアする
|
||||
fun clearErrorCache() {
|
||||
|
|
|
@ -66,6 +66,11 @@ class CustomEmojiLister(internal val context : Context) {
|
|||
worker.start()
|
||||
}
|
||||
|
||||
// ネットワーク接続が変化したらエラーキャッシュをクリア
|
||||
fun onNetworkChanged() {
|
||||
cache_error.clear()
|
||||
}
|
||||
|
||||
private fun getCached(now : Long, instance : String) : CacheItem? {
|
||||
|
||||
// 成功キャッシュ
|
||||
|
@ -147,6 +152,8 @@ class CustomEmojiLister(internal val context : Context) {
|
|||
return dst
|
||||
}
|
||||
|
||||
|
||||
|
||||
private inner class Worker : WorkerBase() {
|
||||
|
||||
override fun cancel() {
|
||||
|
|
|
@ -7,7 +7,8 @@ import jp.juggler.util.LogCategory
|
|||
import java.lang.RuntimeException
|
||||
|
||||
class NetworkStateTracker(
|
||||
val context : Context
|
||||
val context : Context,
|
||||
val onConnectionStateChanged:()->Unit
|
||||
|
||||
) : ConnectivityManager.NetworkCallback() {
|
||||
|
||||
|
@ -62,6 +63,7 @@ class NetworkStateTracker(
|
|||
log.e(ex, "getNetworkCapabilities failed.")
|
||||
}
|
||||
log.d("onAvailable $network $nc")
|
||||
onConnectionStateChanged()
|
||||
}
|
||||
|
||||
// Called when the network the framework connected to for this request changes capabilities but still satisfies the stated need.
|
||||
|
@ -72,23 +74,27 @@ class NetworkStateTracker(
|
|||
) {
|
||||
super.onCapabilitiesChanged(network, networkCapabilities)
|
||||
log.d("onCapabilitiesChanged $network, $networkCapabilities")
|
||||
onConnectionStateChanged()
|
||||
}
|
||||
|
||||
// Called when the network the framework connected to for this request changes LinkProperties.
|
||||
override fun onLinkPropertiesChanged(network : Network, linkProperties : LinkProperties) {
|
||||
super.onLinkPropertiesChanged(network, linkProperties)
|
||||
log.d("onLinkPropertiesChanged $network, $linkProperties")
|
||||
onConnectionStateChanged()
|
||||
}
|
||||
|
||||
override fun onLosing(network : Network, maxMsToLive : Int) {
|
||||
super.onLosing(network, maxMsToLive)
|
||||
log.d("onLosing $network, $maxMsToLive")
|
||||
onConnectionStateChanged()
|
||||
}
|
||||
|
||||
// Called when the framework has a hard loss of the network or when the graceful failure ends.
|
||||
override fun onLost(network : Network) {
|
||||
super.onLost(network)
|
||||
log.d("onLost $network")
|
||||
onConnectionStateChanged()
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue