Move companions to the end of the classes
This commit is contained in:
parent
2e6672db4f
commit
c9d4e2fd13
@ -19,11 +19,6 @@ import java.util.Calendar
|
|||||||
|
|
||||||
class SSEListener(val context: Context) : EventSourceListener() {
|
class SSEListener(val context: Context) : EventSourceListener() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
var lastEventDate: Calendar? = null
|
|
||||||
var keepalive = 900
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOpen(eventSource: EventSource, response: Response) {
|
override fun onOpen(eventSource: EventSource, response: Response) {
|
||||||
FailureHandler.newEventSource(context, eventSource)
|
FailureHandler.newEventSource(context, eventSource)
|
||||||
StartService.wakeLock?.let {
|
StartService.wakeLock?.let {
|
||||||
@ -101,4 +96,10 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||||||
Log.d(TAG, "Retrying in $delay s")
|
Log.d(TAG, "Retrying in $delay s")
|
||||||
RestartWorker.start(context, delay = delay)
|
RestartWorker.start(context, delay = delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var lastEventDate: Calendar? = null
|
||||||
|
var keepalive = 900
|
||||||
|
private set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,7 @@ private val delQueue = emptyList<String>().toMutableList()
|
|||||||
|
|
||||||
class RegisterBroadcastReceiver : BroadcastReceiver() {
|
class RegisterBroadcastReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
companion object {
|
private val WAKE_LOCK_TAG = "NextPush:RegisterBroadcastReceiver:lock"
|
||||||
private const val WAKE_LOCK_TAG = "NextPush:RegisterBroadcastReceiver:lock"
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent?) {
|
override fun onReceive(context: Context, intent: Intent?) {
|
||||||
wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).run {
|
wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).run {
|
||||||
@ -118,4 +115,8 @@ class RegisterBroadcastReceiver : BroadcastReceiver() {
|
|||||||
list.remove(token)
|
list.remove(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,22 +13,6 @@ private const val UNIQUE_WORK_TAG = "nextpush::RestartWorker::unique"
|
|||||||
|
|
||||||
class RestartWorker(ctx: Context, params: WorkerParameters) : Worker(ctx, params) {
|
class RestartWorker(ctx: Context, params: WorkerParameters) : Worker(ctx, params) {
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun start(context: Context, delay: Long? = null) {
|
|
||||||
val work = PeriodicWorkRequestBuilder<RestartWorker>(16, TimeUnit.MINUTES)
|
|
||||||
if (delay != null) {
|
|
||||||
lastEventDate = null
|
|
||||||
work.setInitialDelay(delay, TimeUnit.SECONDS)
|
|
||||||
}
|
|
||||||
val workManager = WorkManager.getInstance(context)
|
|
||||||
workManager.enqueueUniquePeriodicWork(
|
|
||||||
UNIQUE_WORK_TAG,
|
|
||||||
ExistingPeriodicWorkPolicy.REPLACE,
|
|
||||||
work.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
Log.d(TAG, "Working")
|
Log.d(TAG, "Working")
|
||||||
val currentDate = Calendar.getInstance()
|
val currentDate = Calendar.getInstance()
|
||||||
@ -48,4 +32,20 @@ class RestartWorker(ctx: Context, params: WorkerParameters) : Worker(ctx, params
|
|||||||
}
|
}
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun start(context: Context, delay: Long? = null) {
|
||||||
|
val work = PeriodicWorkRequestBuilder<RestartWorker>(16, TimeUnit.MINUTES)
|
||||||
|
if (delay != null) {
|
||||||
|
lastEventDate = null
|
||||||
|
work.setInitialDelay(delay, TimeUnit.SECONDS)
|
||||||
|
}
|
||||||
|
val workManager = WorkManager.getInstance(context)
|
||||||
|
workManager.enqueueUniquePeriodicWork(
|
||||||
|
UNIQUE_WORK_TAG,
|
||||||
|
ExistingPeriodicWorkPolicy.REPLACE,
|
||||||
|
work.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,36 +20,6 @@ import org.unifiedpush.distributor.nextpush.utils.TAG
|
|||||||
|
|
||||||
class StartService : Service() {
|
class StartService : Service() {
|
||||||
|
|
||||||
companion object StartServiceCompanion {
|
|
||||||
private const val WAKE_LOCK_TAG = "NextPush:StartService:lock"
|
|
||||||
|
|
||||||
private var service: StartService? = null
|
|
||||||
var isServiceStarted = false
|
|
||||||
private set
|
|
||||||
var wakeLock: PowerManager.WakeLock? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
fun startListener(context: Context) {
|
|
||||||
if (isServiceStarted && !FailureHandler.hasFailed()) return
|
|
||||||
Log.d(TAG, "Starting the Listener")
|
|
||||||
Log.d(TAG, "Service is started: $isServiceStarted")
|
|
||||||
Log.d(TAG, "nFails: ${FailureHandler.nFails}")
|
|
||||||
val serviceIntent = Intent(context, StartService::class.java)
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
context.startForegroundService(serviceIntent)
|
|
||||||
} else {
|
|
||||||
context.startService(serviceIntent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stopService(block: () -> Unit = {}) {
|
|
||||||
Log.d(TAG, "Stopping Service")
|
|
||||||
isServiceStarted = false
|
|
||||||
service?.stopSelf()
|
|
||||||
block()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val networkCallback = RestartNetworkCallback(this)
|
private val networkCallback = RestartNetworkCallback(this)
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? {
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
@ -109,4 +79,34 @@ class StartService : Service() {
|
|||||||
|
|
||||||
apiSync()
|
apiSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object StartServiceCompanion {
|
||||||
|
private const val WAKE_LOCK_TAG = "NextPush:StartService:lock"
|
||||||
|
|
||||||
|
private var service: StartService? = null
|
||||||
|
var isServiceStarted = false
|
||||||
|
private set
|
||||||
|
var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun startListener(context: Context) {
|
||||||
|
if (isServiceStarted && !FailureHandler.hasFailed()) return
|
||||||
|
Log.d(TAG, "Starting the Listener")
|
||||||
|
Log.d(TAG, "Service is started: $isServiceStarted")
|
||||||
|
Log.d(TAG, "nFails: ${FailureHandler.nFails}")
|
||||||
|
val serviceIntent = Intent(context, StartService::class.java)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(serviceIntent)
|
||||||
|
} else {
|
||||||
|
context.startService(serviceIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopService(block: () -> Unit = {}) {
|
||||||
|
Log.d(TAG, "Stopping Service")
|
||||||
|
isServiceStarted = false
|
||||||
|
service?.stopSelf()
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user