parent
f3faec8432
commit
05be2855d8
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.sync.status
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "StubSyncSubscriber"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub implementation of [SyncSubscriber]
|
||||||
|
*/
|
||||||
|
class StubSyncSubscriber @Inject constructor() : SyncSubscriber {
|
||||||
|
override suspend fun subscribe() {
|
||||||
|
Log.d(TAG, "Subscribing to sync")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.sync.status
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to backend requested synchronization
|
||||||
|
*/
|
||||||
|
interface SyncSubscriber {
|
||||||
|
suspend fun subscribe()
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.sync.di
|
||||||
|
|
||||||
|
import com.google.firebase.ktx.Firebase
|
||||||
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
|
import com.google.firebase.messaging.ktx.messaging
|
||||||
|
import com.google.samples.apps.nowinandroid.core.data.util.SyncManager
|
||||||
|
import com.google.samples.apps.nowinandroid.sync.status.FirebaseSyncSubscriber
|
||||||
|
import com.google.samples.apps.nowinandroid.sync.status.SyncSubscriber
|
||||||
|
import com.google.samples.apps.nowinandroid.sync.status.WorkManagerSyncManager
|
||||||
|
import dagger.Binds
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface SyncModule {
|
||||||
|
@Binds
|
||||||
|
fun bindsSyncStatusMonitor(
|
||||||
|
syncStatusMonitor: WorkManagerSyncManager,
|
||||||
|
): SyncManager
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
fun bindsSyncSubscriber(
|
||||||
|
syncSubscriber: FirebaseSyncSubscriber,
|
||||||
|
): SyncSubscriber
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideFirebaseMessaging(): FirebaseMessaging = Firebase.messaging
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.sync.status
|
||||||
|
|
||||||
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
|
import com.google.samples.apps.nowinandroid.sync.initializers.SYNC_TOPIC
|
||||||
|
import kotlinx.coroutines.tasks.await
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of [SyncSubscriber] that subscribes to the FCM [SYNC_TOPIC]
|
||||||
|
*/
|
||||||
|
class FirebaseSyncSubscriber @Inject constructor(
|
||||||
|
private val firebaseMessaging: FirebaseMessaging,
|
||||||
|
) : SyncSubscriber {
|
||||||
|
override suspend fun subscribe() {
|
||||||
|
firebaseMessaging
|
||||||
|
.subscribeToTopic(SYNC_TOPIC)
|
||||||
|
.await()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue