Commit a15369fd authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix injections

parent c74bbdeb
...@@ -6,7 +6,6 @@ import android.content.Intent ...@@ -6,7 +6,6 @@ import android.content.Intent
import android.media.MediaScannerConnection import android.media.MediaScannerConnection
import android.os.IBinder import android.os.IBinder
import androidx.core.math.MathUtils.clamp import androidx.core.math.MathUtils.clamp
import androidx.lifecycle.LifecycleObserver
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi import com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi
...@@ -16,7 +15,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.FileEntity ...@@ -16,7 +15,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.FileEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.TourFileJunctionEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.TourFileJunctionEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.fromRaw import com.biganto.visual.roompark.data.repository.db.requrey.model.fromRaw
import com.biganto.visual.roompark.data.repository.file.FileModule import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.data.service.lifecycle.AppLifecycleListener import com.biganto.visual.roompark.data.service.lifecycle.ForegroundLifecycleObserver
import com.biganto.visual.roompark.data.service.notification.NotificationCenter import com.biganto.visual.roompark.data.service.notification.NotificationCenter
import com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState import com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState
import com.biganto.visual.roomparkvr.data.repository.db.requery.model.TourPreviewEntity import com.biganto.visual.roomparkvr.data.repository.db.requery.model.TourPreviewEntity
...@@ -68,7 +67,7 @@ class DownloadManagerService @Inject constructor( ...@@ -68,7 +67,7 @@ class DownloadManagerService @Inject constructor(
lateinit var notificationsCenter: NotificationCenter lateinit var notificationsCenter: NotificationCenter
@Inject @Inject
lateinit var appLifeCycle: AppLifecycleListener lateinit var appLifeCycle: ForegroundLifecycleObserver
//endregion //endregion
...@@ -489,7 +488,7 @@ class DownloadManagerService @Inject constructor( ...@@ -489,7 +488,7 @@ class DownloadManagerService @Inject constructor(
disposable.add( disposable.add(
checkService checkService
.subscribe { .subscribe {
if (!appLifeCycle.IsAppForeground if (!appLifeCycle.isAppForeground
&& !hasTasks && !hasTasks
&& !activeDownloading.get()) { && !activeDownloading.get()) {
stopForeground(true) stopForeground(true)
......
...@@ -8,14 +8,15 @@ import androidx.lifecycle.Lifecycle ...@@ -8,14 +8,15 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent import androidx.lifecycle.OnLifecycleEvent
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class AppLifecycleListener : LifecycleObserver { class AppLifecycleListener @Inject constructor(): ForegroundLifecycleObserver {
private var isForeground=false private var isForeground=false
val IsAppForeground : Boolean override val isAppForeground : Boolean
get() = isForeground get() = isForeground
...@@ -31,3 +32,7 @@ class AppLifecycleListener : LifecycleObserver { ...@@ -31,3 +32,7 @@ class AppLifecycleListener : LifecycleObserver {
isForeground=false isForeground=false
} }
} }
interface ForegroundLifecycleObserver : LifecycleObserver{
val isAppForeground : Boolean
}
\ No newline at end of file
package com.biganto.visual.roompark.data.service.notification package com.biganto.visual.roompark.data.service.notification
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.Notification import android.app.*
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
...@@ -35,8 +32,23 @@ const val NOTIFICATION_INTENT_STOP_SERVICE_ACTION="STOP_DOWNLOADS_SERVICE" ...@@ -35,8 +32,23 @@ const val NOTIFICATION_INTENT_STOP_SERVICE_ACTION="STOP_DOWNLOADS_SERVICE"
const val PENDING_REQUEST_CODE=0 const val PENDING_REQUEST_CODE=0
interface INotificationCenter{
fun indeterminateProgressMessage(progress:Int=0
,progressMax:Int=0
,message: String)
fun completeProgressMessage(message: String)
fun donwloadServiceProgressNotfication(progress:Int=0
,progressMax:Int=0
,indeterminate:Boolean=true
,message: String)
}
@Singleton @Singleton
class NotificationCenter @Inject constructor(val context: Context) { class NotificationCenter @Inject constructor(val context: Application) : INotificationCenter{
private val updateProgressNotificationDelay_Milliseconds= 333 private val updateProgressNotificationDelay_Milliseconds= 333
private var lastTimeProgressNotificationUpdated = 0L private var lastTimeProgressNotificationUpdated = 0L
...@@ -82,9 +94,9 @@ class NotificationCenter @Inject constructor(val context: Context) { ...@@ -82,9 +94,9 @@ class NotificationCenter @Inject constructor(val context: Context) {
fun indeterminateProgressMessage(progress:Int=0 override fun indeterminateProgressMessage(progress:Int
,progressMax:Int=0 , progressMax:Int
,message: String) { , message: String) {
if (progress!=0) if (progress!=0)
if (System.currentTimeMillis()-lastTimeProgressNotificationUpdated if (System.currentTimeMillis()-lastTimeProgressNotificationUpdated
<updateProgressNotificationDelay_Milliseconds) <updateProgressNotificationDelay_Milliseconds)
...@@ -93,14 +105,14 @@ class NotificationCenter @Inject constructor(val context: Context) { ...@@ -93,14 +105,14 @@ class NotificationCenter @Inject constructor(val context: Context) {
donwloadServiceProgressNotfication(progress, progressMax, true, message) donwloadServiceProgressNotfication(progress, progressMax, true, message)
} }
fun completeProgressMessage(message: String){ override fun completeProgressMessage(message: String){
donwloadServiceProgressNotfication(indeterminate = false,message = message) donwloadServiceProgressNotfication(indeterminate = false,message = message)
} }
fun donwloadServiceProgressNotfication(progress:Int=0 override fun donwloadServiceProgressNotfication(progress:Int
,progressMax:Int=0 , progressMax:Int
,indeterminate:Boolean=true , indeterminate:Boolean
,message: String){ , message: String){
val pendingIntent = PendingIntent.getActivity(context val pendingIntent = PendingIntent.getActivity(context
, PENDING_REQUEST_CODE , PENDING_REQUEST_CODE
......
...@@ -10,8 +10,8 @@ import com.biganto.visual.roompark.data.repository.api.room_park.IRoomParkApi ...@@ -10,8 +10,8 @@ import com.biganto.visual.roompark.data.repository.api.room_park.IRoomParkApi
import com.biganto.visual.roompark.data.repository.db.IDb import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.DbModule import com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import com.biganto.visual.roompark.data.repository.file.FileModule import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.data.service.lifecycle.AppLifecycleListener import com.biganto.visual.roompark.data.service.lifecycle.ForegroundLifecycleObserver
import com.biganto.visual.roompark.data.service.notification.NotificationCenter import com.biganto.visual.roompark.data.service.notification.INotificationCenter
import com.biganto.visual.roompark.domain.contract.* import com.biganto.visual.roompark.domain.contract.*
import dagger.BindsInstance import dagger.BindsInstance
import dagger.Component import dagger.Component
...@@ -66,9 +66,9 @@ interface AppComponent : AndroidInjector<RoomParkApplication>{ ...@@ -66,9 +66,9 @@ interface AppComponent : AndroidInjector<RoomParkApplication>{
fun provideTour():TourContract fun provideTour():TourContract
fun provideLifeCycle(): AppLifecycleListener fun provideLifeCycle(): ForegroundLifecycleObserver
fun provideNotifivations():NotificationCenter fun provideNotifivations(): INotificationCenter
fun provideAppContext():Application fun provideAppContext():Application
......
...@@ -11,6 +11,8 @@ import com.biganto.visual.roompark.data.repository.db.IDb ...@@ -11,6 +11,8 @@ import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.DbModule import com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import com.biganto.visual.roompark.data.repository.db.requrey.RequeryRepository import com.biganto.visual.roompark.data.repository.db.requrey.RequeryRepository
import com.biganto.visual.roompark.data.service.lifecycle.AppLifecycleListener import com.biganto.visual.roompark.data.service.lifecycle.AppLifecycleListener
import com.biganto.visual.roompark.data.service.lifecycle.ForegroundLifecycleObserver
import com.biganto.visual.roompark.data.service.notification.INotificationCenter
import com.biganto.visual.roompark.data.service.notification.NotificationCenter import com.biganto.visual.roompark.data.service.notification.NotificationCenter
import com.biganto.visual.roompark.domain.contract.* import com.biganto.visual.roompark.domain.contract.*
import dagger.Binds import dagger.Binds
...@@ -73,13 +75,14 @@ abstract class DataModule { ...@@ -73,13 +75,14 @@ abstract class DataModule {
@Binds @Binds
abstract fun provideRoomParkApi(roomParkApi:RetrofitRepository): IRoomParkApi abstract fun provideRoomParkApi(roomParkApi:RetrofitRepository): IRoomParkApi
@Singleton @Singleton
@Binds @Binds
abstract fun provideLifecycleObserver(obs:AppLifecycleListener): AppLifecycleListener abstract fun provideNotyCenter(center: NotificationCenter): INotificationCenter
@Singleton @Singleton
@Binds @Binds
abstract fun provideNotyCenter(center:NotificationCenter): NotificationCenter abstract fun provideLifecycleObserver(obs:AppLifecycleListener): ForegroundLifecycleObserver
@Singleton @Singleton
@Binds @Binds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment