mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Update: Make Common a file
This commit is contained in:
parent
1ec70dd1a8
commit
4b39477b36
@ -1,6 +1,5 @@
|
|||||||
package com.looker.droidify
|
package com.looker.droidify
|
||||||
|
|
||||||
object Common {
|
|
||||||
const val NOTIFICATION_CHANNEL_SYNCING = "syncing"
|
const val NOTIFICATION_CHANNEL_SYNCING = "syncing"
|
||||||
const val NOTIFICATION_CHANNEL_UPDATES = "updates"
|
const val NOTIFICATION_CHANNEL_UPDATES = "updates"
|
||||||
const val NOTIFICATION_CHANNEL_DOWNLOADING = "downloading"
|
const val NOTIFICATION_CHANNEL_DOWNLOADING = "downloading"
|
||||||
@ -10,4 +9,4 @@ object Common {
|
|||||||
const val NOTIFICATION_ID_DOWNLOADING = 3
|
const val NOTIFICATION_ID_DOWNLOADING = 3
|
||||||
|
|
||||||
const val JOB_ID_SYNC = 1
|
const val JOB_ID_SYNC = 1
|
||||||
}
|
|
||||||
|
@ -104,19 +104,19 @@ class MainApplication : Application(), ImageLoaderFactory {
|
|||||||
|
|
||||||
private fun updateSyncJob(force: Boolean) {
|
private fun updateSyncJob(force: Boolean) {
|
||||||
val jobScheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
|
val jobScheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||||
val reschedule = force || !jobScheduler.allPendingJobs.any { it.id == Common.JOB_ID_SYNC }
|
val reschedule = force || !jobScheduler.allPendingJobs.any { it.id == JOB_ID_SYNC }
|
||||||
if (reschedule) {
|
if (reschedule) {
|
||||||
val autoSync = Preferences[Preferences.Key.AutoSync]
|
val autoSync = Preferences[Preferences.Key.AutoSync]
|
||||||
when (autoSync) {
|
when (autoSync) {
|
||||||
Preferences.AutoSync.Never -> {
|
Preferences.AutoSync.Never -> {
|
||||||
jobScheduler.cancel(Common.JOB_ID_SYNC)
|
jobScheduler.cancel(JOB_ID_SYNC)
|
||||||
}
|
}
|
||||||
Preferences.AutoSync.Wifi, Preferences.AutoSync.Always -> {
|
Preferences.AutoSync.Wifi, Preferences.AutoSync.Always -> {
|
||||||
val period = 12 * 60 * 60 * 1000L // 12 hours
|
val period = 12 * 60 * 60 * 1000L // 12 hours
|
||||||
val wifiOnly = autoSync == Preferences.AutoSync.Wifi
|
val wifiOnly = autoSync == Preferences.AutoSync.Wifi
|
||||||
jobScheduler.schedule(JobInfo
|
jobScheduler.schedule(JobInfo
|
||||||
.Builder(
|
.Builder(
|
||||||
Common.JOB_ID_SYNC,
|
JOB_ID_SYNC,
|
||||||
ComponentName(this, SyncService.Job::class.java)
|
ComponentName(this, SyncService.Job::class.java)
|
||||||
)
|
)
|
||||||
.setRequiredNetworkType(if (wifiOnly) JobInfo.NETWORK_TYPE_UNMETERED else JobInfo.NETWORK_TYPE_ANY)
|
.setRequiredNetworkType(if (wifiOnly) JobInfo.NETWORK_TYPE_UNMETERED else JobInfo.NETWORK_TYPE_ANY)
|
||||||
|
@ -9,10 +9,7 @@ import android.content.Intent
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.ContextThemeWrapper
|
import android.view.ContextThemeWrapper
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.looker.droidify.BuildConfig
|
import com.looker.droidify.*
|
||||||
import com.looker.droidify.Common
|
|
||||||
import com.looker.droidify.MainActivity
|
|
||||||
import com.looker.droidify.R
|
|
||||||
import com.looker.droidify.content.Cache
|
import com.looker.droidify.content.Cache
|
||||||
import com.looker.droidify.content.Preferences
|
import com.looker.droidify.content.Preferences
|
||||||
import com.looker.droidify.entity.Release
|
import com.looker.droidify.entity.Release
|
||||||
@ -119,7 +116,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
|||||||
} else {
|
} else {
|
||||||
cancelTasks(packageName)
|
cancelTasks(packageName)
|
||||||
cancelCurrentTask(packageName)
|
cancelCurrentTask(packageName)
|
||||||
notificationManager.cancel(task.notificationTag, Common.NOTIFICATION_ID_DOWNLOADING)
|
notificationManager.cancel(task.notificationTag, NOTIFICATION_ID_DOWNLOADING)
|
||||||
tasks += task
|
tasks += task
|
||||||
if (currentTask == null) {
|
if (currentTask == null) {
|
||||||
handleDownload()
|
handleDownload()
|
||||||
@ -151,7 +148,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
|||||||
|
|
||||||
if (Android.sdk(26)) {
|
if (Android.sdk(26)) {
|
||||||
NotificationChannel(
|
NotificationChannel(
|
||||||
Common.NOTIFICATION_CHANNEL_DOWNLOADING,
|
NOTIFICATION_CHANNEL_DOWNLOADING,
|
||||||
getString(R.string.downloading), NotificationManager.IMPORTANCE_LOW
|
getString(R.string.downloading), NotificationManager.IMPORTANCE_LOW
|
||||||
)
|
)
|
||||||
.apply { setShowBadge(false) }
|
.apply { setShowBadge(false) }
|
||||||
@ -208,9 +205,9 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
|||||||
|
|
||||||
private fun showNotificationError(task: Task, errorType: ErrorType) {
|
private fun showNotificationError(task: Task, errorType: ErrorType) {
|
||||||
notificationManager.notify(task.notificationTag,
|
notificationManager.notify(task.notificationTag,
|
||||||
Common.NOTIFICATION_ID_DOWNLOADING,
|
NOTIFICATION_ID_DOWNLOADING,
|
||||||
NotificationCompat
|
NotificationCompat
|
||||||
.Builder(this, Common.NOTIFICATION_CHANNEL_DOWNLOADING)
|
.Builder(this, NOTIFICATION_CHANNEL_DOWNLOADING)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_warning)
|
.setSmallIcon(android.R.drawable.stat_sys_warning)
|
||||||
.setColor(
|
.setColor(
|
||||||
@ -275,8 +272,8 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
|||||||
|
|
||||||
private fun showNotificationInstall(task: Task) {
|
private fun showNotificationInstall(task: Task) {
|
||||||
notificationManager.notify(
|
notificationManager.notify(
|
||||||
task.notificationTag, Common.NOTIFICATION_ID_DOWNLOADING, NotificationCompat
|
task.notificationTag, NOTIFICATION_ID_DOWNLOADING, NotificationCompat
|
||||||
.Builder(this, Common.NOTIFICATION_CHANNEL_DOWNLOADING)
|
.Builder(this, NOTIFICATION_CHANNEL_DOWNLOADING)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||||
.setColor(
|
.setColor(
|
||||||
@ -373,7 +370,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
|||||||
|
|
||||||
private val stateNotificationBuilder by lazy {
|
private val stateNotificationBuilder by lazy {
|
||||||
NotificationCompat
|
NotificationCompat
|
||||||
.Builder(this, Common.NOTIFICATION_CHANNEL_DOWNLOADING)
|
.Builder(this, NOTIFICATION_CHANNEL_DOWNLOADING)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||||
.setColor(
|
.setColor(
|
||||||
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
||||||
@ -395,7 +392,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
|||||||
private fun publishForegroundState(force: Boolean, state: State) {
|
private fun publishForegroundState(force: Boolean, state: State) {
|
||||||
if (force || currentTask != null) {
|
if (force || currentTask != null) {
|
||||||
currentTask = currentTask?.copy(lastState = state)
|
currentTask = currentTask?.copy(lastState = state)
|
||||||
startForeground(Common.NOTIFICATION_ID_SYNCING, stateNotificationBuilder.apply {
|
startForeground(NOTIFICATION_ID_SYNCING, stateNotificationBuilder.apply {
|
||||||
when (state) {
|
when (state) {
|
||||||
is State.Connecting -> {
|
is State.Connecting -> {
|
||||||
setContentTitle(getString(R.string.downloading_FORMAT, state.name))
|
setContentTitle(getString(R.string.downloading_FORMAT, state.name))
|
||||||
|
@ -13,10 +13,7 @@ import android.text.style.ForegroundColorSpan
|
|||||||
import android.view.ContextThemeWrapper
|
import android.view.ContextThemeWrapper
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.looker.droidify.BuildConfig
|
import com.looker.droidify.*
|
||||||
import com.looker.droidify.Common
|
|
||||||
import com.looker.droidify.MainActivity
|
|
||||||
import com.looker.droidify.R
|
|
||||||
import com.looker.droidify.content.Preferences
|
import com.looker.droidify.content.Preferences
|
||||||
import com.looker.droidify.database.Database
|
import com.looker.droidify.database.Database
|
||||||
import com.looker.droidify.entity.ProductItem
|
import com.looker.droidify.entity.ProductItem
|
||||||
@ -116,7 +113,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
fun setUpdateNotificationBlocker(fragment: Fragment?) {
|
fun setUpdateNotificationBlocker(fragment: Fragment?) {
|
||||||
updateNotificationBlockerFragment = fragment?.let(::WeakReference)
|
updateNotificationBlockerFragment = fragment?.let(::WeakReference)
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
notificationManager.cancel(Common.NOTIFICATION_ID_UPDATES)
|
notificationManager.cancel(NOTIFICATION_ID_UPDATES)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,13 +156,13 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
|
|
||||||
if (Android.sdk(26)) {
|
if (Android.sdk(26)) {
|
||||||
NotificationChannel(
|
NotificationChannel(
|
||||||
Common.NOTIFICATION_CHANNEL_SYNCING,
|
NOTIFICATION_CHANNEL_SYNCING,
|
||||||
getString(R.string.syncing), NotificationManager.IMPORTANCE_LOW
|
getString(R.string.syncing), NotificationManager.IMPORTANCE_LOW
|
||||||
)
|
)
|
||||||
.apply { setShowBadge(false) }
|
.apply { setShowBadge(false) }
|
||||||
.let(notificationManager::createNotificationChannel)
|
.let(notificationManager::createNotificationChannel)
|
||||||
NotificationChannel(
|
NotificationChannel(
|
||||||
Common.NOTIFICATION_CHANNEL_UPDATES,
|
NOTIFICATION_CHANNEL_UPDATES,
|
||||||
getString(R.string.updates), NotificationManager.IMPORTANCE_LOW
|
getString(R.string.updates), NotificationManager.IMPORTANCE_LOW
|
||||||
)
|
)
|
||||||
.let(notificationManager::createNotificationChannel)
|
.let(notificationManager::createNotificationChannel)
|
||||||
@ -213,8 +210,8 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
|
|
||||||
private fun showNotificationError(repository: Repository, exception: Exception) {
|
private fun showNotificationError(repository: Repository, exception: Exception) {
|
||||||
notificationManager.notify(
|
notificationManager.notify(
|
||||||
"repository-${repository.id}", Common.NOTIFICATION_ID_SYNCING, NotificationCompat
|
"repository-${repository.id}", NOTIFICATION_ID_SYNCING, NotificationCompat
|
||||||
.Builder(this, Common.NOTIFICATION_CHANNEL_SYNCING)
|
.Builder(this, NOTIFICATION_CHANNEL_SYNCING)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_warning)
|
.setSmallIcon(android.R.drawable.stat_sys_warning)
|
||||||
.setColor(
|
.setColor(
|
||||||
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
||||||
@ -240,7 +237,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
|
|
||||||
private val stateNotificationBuilder by lazy {
|
private val stateNotificationBuilder by lazy {
|
||||||
NotificationCompat
|
NotificationCompat
|
||||||
.Builder(this, Common.NOTIFICATION_CHANNEL_SYNCING)
|
.Builder(this, NOTIFICATION_CHANNEL_SYNCING)
|
||||||
.setSmallIcon(R.drawable.ic_sync)
|
.setSmallIcon(R.drawable.ic_sync)
|
||||||
.setColor(
|
.setColor(
|
||||||
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
||||||
@ -263,7 +260,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
if (force || currentTask?.lastState != state) {
|
if (force || currentTask?.lastState != state) {
|
||||||
currentTask = currentTask?.copy(lastState = state)
|
currentTask = currentTask?.copy(lastState = state)
|
||||||
if (started == Started.MANUAL) {
|
if (started == Started.MANUAL) {
|
||||||
startForeground(Common.NOTIFICATION_ID_SYNCING, stateNotificationBuilder.apply {
|
startForeground(NOTIFICATION_ID_SYNCING, stateNotificationBuilder.apply {
|
||||||
when (state) {
|
when (state) {
|
||||||
is State.Connecting -> {
|
is State.Connecting -> {
|
||||||
setContentTitle(getString(R.string.syncing_FORMAT, state.name))
|
setContentTitle(getString(R.string.syncing_FORMAT, state.name))
|
||||||
@ -420,8 +417,8 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
val maxUpdates = 5
|
val maxUpdates = 5
|
||||||
fun <T> T.applyHack(callback: T.() -> Unit): T = apply(callback)
|
fun <T> T.applyHack(callback: T.() -> Unit): T = apply(callback)
|
||||||
notificationManager.notify(
|
notificationManager.notify(
|
||||||
Common.NOTIFICATION_ID_UPDATES, NotificationCompat
|
NOTIFICATION_ID_UPDATES, NotificationCompat
|
||||||
.Builder(this, Common.NOTIFICATION_CHANNEL_UPDATES)
|
.Builder(this, NOTIFICATION_CHANNEL_UPDATES)
|
||||||
.setSmallIcon(R.drawable.ic_new_releases)
|
.setSmallIcon(R.drawable.ic_new_releases)
|
||||||
.setContentTitle(getString(R.string.new_updates_available))
|
.setContentTitle(getString(R.string.new_updates_available))
|
||||||
.setContentText(
|
.setContentText(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user