New cache system
Refactoring Separation into libraries
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.meloda.concurrent">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.meloda.concurrent
|
||||
|
||||
class EventInfo<T> constructor(var key: String, var data: T? = null)
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.meloda.concurrent
|
||||
|
||||
import android.os.Process
|
||||
|
||||
class LowThread(runnable: Runnable?) : Thread(runnable) {
|
||||
|
||||
override fun run() {
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND)
|
||||
super.run()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.meloda.concurrent
|
||||
|
||||
object TaskManager {
|
||||
|
||||
private const val TAG = "TaskManager"
|
||||
|
||||
private val listeners = arrayListOf<OnEventListener>()
|
||||
|
||||
fun addOnEventListener(listener: OnEventListener) {
|
||||
listeners.add(listener)
|
||||
}
|
||||
|
||||
fun removeOnEventListener(listener: OnEventListener?) {
|
||||
listeners.remove(listener)
|
||||
}
|
||||
|
||||
fun execute(runnable: Runnable?) {
|
||||
LowThread(runnable).start()
|
||||
}
|
||||
|
||||
fun sendEvent(eventInfo: EventInfo<*>) {
|
||||
for (listener in listeners) {
|
||||
listener.onNewEvent(eventInfo)
|
||||
}
|
||||
}
|
||||
|
||||
interface OnEventListener {
|
||||
fun onNewEvent(info: EventInfo<*>)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user