Skip to content
Snippets Groups Projects
Commit 91429f1b authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fix a crash

parent 580813df
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,8 @@ import android.util.Printer
class AndroidHandlerThread(name: String) : HandlerThread(name) {
@Volatile
private var handler: Handler? = null
private var handler: Handler? =
null
fun started(): AndroidHandlerThread {
onCreate()
......@@ -41,97 +42,130 @@ class AndroidHandlerThread(name: String) : HandlerThread(name) {
}
}
fun handleMessage(msg: Message)
= handler?.handleMessage(msg) ?: throw RuntimeException("Thread not started")
fun handleMessage(msg: Message) =
started().let { handler?.handleMessage(msg) }
?: throw RuntimeException("Thread not started")
fun dispatchMessage(msg: Message)
= handler?.dispatchMessage(msg) ?: throw RuntimeException("Thread not started")
fun dispatchMessage(msg: Message) =
started().let { handler?.dispatchMessage(msg) }
?: throw RuntimeException("Thread not started")
fun getMessageName(message: Message): String
= handler?.getMessageName(message) ?: throw RuntimeException("Thread not started")
fun getMessageName(message: Message): String =
started().let { handler?.getMessageName(message) }
?: throw RuntimeException("Thread not started")
fun obtainMessage(): Message
= handler?.obtainMessage() ?: throw RuntimeException("Thread not started")
fun obtainMessage(): Message =
started().let { handler?.obtainMessage() }
?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int): Message
= handler?.obtainMessage(what) ?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int): Message =
started().let { handler?.obtainMessage(what) }
?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int, obj: Any): Message
= handler?.obtainMessage(what, obj) ?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int, obj: Any): Message =
started().let { handler?.obtainMessage(what, obj) }
?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int, arg1: Int, arg2: Int): Message
= handler?.obtainMessage(what, arg1, arg2) ?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int, arg1: Int, arg2: Int): Message =
started().let { handler?.obtainMessage(what, arg1, arg2) }
?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int, arg1: Int, arg2: Int, obj: Any): Message
= handler?.obtainMessage(what, arg1, arg2, obj) ?: throw RuntimeException("Thread not started")
fun obtainMessage(what: Int, arg1: Int, arg2: Int, obj: Any): Message =
started().let { handler?.obtainMessage(what, arg1, arg2, obj) }
?: throw RuntimeException("Thread not started")
fun post(r: () -> Unit): Boolean
= handler?.post(r) ?: throw RuntimeException("Thread not started")
fun post(r: () -> Unit): Boolean =
started().let { handler?.post(r) }
?: throw RuntimeException("Thread not started")
fun postAtTime(r: () -> Unit, uptimeMillis: Long): Boolean
= handler?.postAtTime(r, uptimeMillis) ?: throw RuntimeException("Thread not started")
fun postAtTime(r: () -> Unit, uptimeMillis: Long): Boolean =
started().let { handler?.postAtTime(r, uptimeMillis) }
?: throw RuntimeException("Thread not started")
fun postAtTime(r: () -> Unit, token: Any, uptimeMillis: Long): Boolean
= handler?.postAtTime(r, token, uptimeMillis) ?: throw RuntimeException("Thread not started")
fun postAtTime(r: () -> Unit, token: Any, uptimeMillis: Long): Boolean =
started().let { handler?.postAtTime(r, token, uptimeMillis) }
?: throw RuntimeException("Thread not started")
fun postDelayed(r: () -> Unit, delayMillis: Long): Boolean
= handler?.postDelayed(r, delayMillis) ?: throw RuntimeException("Thread not started")
fun postDelayed(r: () -> Unit, delayMillis: Long): Boolean =
started().let { handler?.postDelayed(r, delayMillis) }
?: throw RuntimeException("Thread not started")
fun postAtFrontOfQueue(r: () -> Unit): Boolean
= handler?.postAtFrontOfQueue(r) ?: throw RuntimeException("Thread not started")
fun postAtFrontOfQueue(r: () -> Unit): Boolean =
started().let { handler?.postAtFrontOfQueue(r) }
?: throw RuntimeException("Thread not started")
fun removeCallbacks(r: () -> Unit)
= handler?.removeCallbacks(r) ?: throw RuntimeException("Thread not started")
fun removeCallbacks(r: () -> Unit) =
started().let { handler?.removeCallbacks(r) }
?: throw RuntimeException("Thread not started")
fun removeCallbacks(r: () -> Unit, token: Any)
= handler?.removeCallbacks(r, token) ?: throw RuntimeException("Thread not started")
fun removeCallbacks(r: () -> Unit, token: Any) =
started().let { handler?.removeCallbacks(r, token) }
?: throw RuntimeException("Thread not started")
fun sendMessage(msg: Message): Boolean
= handler?.sendMessage(msg) ?: throw RuntimeException("Thread not started")
fun sendMessage(msg: Message): Boolean =
started().let { handler?.sendMessage(msg) }
?: throw RuntimeException("Thread not started")
fun sendEmptyMessage(what: Int): Boolean
= handler?.sendEmptyMessage(what) ?: throw RuntimeException("Thread not started")
fun sendEmptyMessage(what: Int): Boolean =
started().let { handler?.sendEmptyMessage(what) }
?: throw RuntimeException("Thread not started")
fun sendEmptyMessageDelayed(what: Int, delayMillis: Long): Boolean
= handler?.sendEmptyMessageDelayed(what, delayMillis) ?: throw RuntimeException(
fun sendEmptyMessageDelayed(what: Int, delayMillis: Long): Boolean =
started().let { handler?.sendEmptyMessageDelayed(what, delayMillis) }
?: throw RuntimeException(
"Thread not started"
)
fun sendEmptyMessageAtTime(what: Int, uptimeMillis: Long): Boolean
= handler?.sendEmptyMessageAtTime(what, uptimeMillis) ?: throw RuntimeException(
fun sendEmptyMessageAtTime(what: Int, uptimeMillis: Long): Boolean =
started().let { handler?.sendEmptyMessageAtTime(what, uptimeMillis) }
?: throw RuntimeException(
"Thread not started"
)
fun sendMessageDelayed(msg: Message, delayMillis: Long): Boolean
= handler?.sendMessageDelayed(msg, delayMillis) ?: throw RuntimeException("Thread not started")
fun sendMessageDelayed(msg: Message, delayMillis: Long): Boolean =
started().let { handler?.sendMessageDelayed(msg, delayMillis) }
?: throw RuntimeException("Thread not started")
fun sendMessageAtTime(msg: Message, uptimeMillis: Long): Boolean
= handler?.sendMessageAtTime(msg, uptimeMillis) ?: throw RuntimeException("Thread not started")
fun sendMessageAtTime(msg: Message, uptimeMillis: Long): Boolean =
started().let { handler?.sendMessageAtTime(msg, uptimeMillis) }
?: throw RuntimeException("Thread not started")
fun sendMessageAtFrontOfQueue(msg: Message): Boolean
= handler?.sendMessageAtFrontOfQueue(msg) ?: throw RuntimeException("Thread not started")
fun sendMessageAtFrontOfQueue(msg: Message): Boolean =
started().let { handler?.sendMessageAtFrontOfQueue(msg) }
?: throw RuntimeException("Thread not started")
fun removeMessages(what: Int)
= handler?.removeMessages(what) ?: throw RuntimeException("Thread not started")
fun removeMessages(what: Int) =
started().let { handler?.removeMessages(what) }
?: throw RuntimeException("Thread not started")
fun removeMessages(what: Int, `object`: Any)
= handler?.removeMessages(what, `object`) ?: throw RuntimeException("Thread not started")
fun removeMessages(what: Int, `object`: Any) =
started().let { handler?.removeMessages(what, `object`) }
?: throw RuntimeException("Thread not started")
fun removeCallbacksAndMessages(token: Any)
= handler?.removeCallbacksAndMessages(token) ?: throw RuntimeException("Thread not started")
fun removeCallbacksAndMessages(token: Any) =
started().let { handler?.removeCallbacksAndMessages(token) }
?: throw RuntimeException("Thread not started")
fun hasMessages(what: Int): Boolean
= handler?.hasMessages(what) ?: throw RuntimeException("Thread not started")
fun hasMessages(what: Int): Boolean =
started().let { handler?.hasMessages(what) }
?: throw RuntimeException("Thread not started")
fun hasMessages(what: Int, `object`: Any): Boolean
= handler?.hasMessages(what, `object`) ?: throw RuntimeException("Thread not started")
fun hasMessages(what: Int, `object`: Any): Boolean =
started().let { handler?.hasMessages(what, `object`) }
?: throw RuntimeException("Thread not started")
val handlerLooper: Looper
get() = handler?.looper ?: throw RuntimeException("Thread not started")
get()
fun dump(pw: Printer, prefix: String)
= handler?.dump(pw, prefix) ?: throw RuntimeException("Thread not started")
=
started().let { handler?.looper }
?: throw RuntimeException("Thread not started")
override fun toString(): String
= handler?.toString() ?: throw RuntimeException("Thread not started")
fun dump(pw: Printer, prefix: String) =
started().let { handler?.dump(pw, prefix) }
?: throw RuntimeException("Thread not started")
override fun toString(): String =
started().let { handler?.toString() }
?: throw RuntimeException("Thread not started")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment