-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from TimerTiTi/82-setting
close #82 setting
- Loading branch information
Showing
48 changed files
with
1,440 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
id("titi.android.library-no-hilt") | ||
} | ||
|
||
android { | ||
namespace = "com.titi.app.data.notification.api" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
12 changes: 12 additions & 0 deletions
12
...fication/api/src/main/kotlin/com/titi/app/data/notification/api/NotificationRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.titi.app.data.notification.api | ||
|
||
import com.titi.app.data.notification.api.model.NotificationRepositoryModel | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface NotificationRepository { | ||
suspend fun setNotification(notificationRepositoryModel: NotificationRepositoryModel) | ||
|
||
fun getNotificationFlow(): Flow<NotificationRepositoryModel> | ||
|
||
suspend fun getNotification(): NotificationRepositoryModel | ||
} |
7 changes: 7 additions & 0 deletions
7
...i/src/main/kotlin/com/titi/app/data/notification/api/model/NotificationRepositoryModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.titi.app.data.notification.api.model | ||
|
||
data class NotificationRepositoryModel( | ||
val timerFiveMinutesBeforeTheEnd: Boolean = true, | ||
val timerBeforeTheEnd: Boolean = true, | ||
val stopwatch: Boolean = true, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
id("titi.android.data.local") | ||
} | ||
|
||
android { | ||
namespace = "com.titi.app.data.notification.impl" | ||
} | ||
|
||
dependencies { | ||
implementation(project(":data:notification:api")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
19 changes: 19 additions & 0 deletions
19
...tification/impl/src/main/kotlin/com/titi/app/data/notification/impl/di/DataStoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.titi.app.data.notification.impl.di | ||
|
||
import android.content.Context | ||
import com.titi.app.data.notification.impl.local.NotificationDataStore | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object DataStoreModule { | ||
@Provides | ||
@Singleton | ||
fun provideNotificationDataStore(@ApplicationContext context: Context) = | ||
NotificationDataStore(context) | ||
} |
19 changes: 19 additions & 0 deletions
19
...ification/impl/src/main/kotlin/com/titi/app/data/notification/impl/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.titi.app.data.notification.impl.di | ||
|
||
import com.titi.app.data.notification.api.NotificationRepository | ||
import com.titi.app.data.notification.impl.repository.NotificationRepositoryImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal interface RepositoryModule { | ||
@Binds | ||
@Singleton | ||
fun provideNotificationRepository( | ||
notificationRepositoryImpl: NotificationRepositoryImpl, | ||
): NotificationRepository | ||
} |
37 changes: 37 additions & 0 deletions
37
...n/impl/src/main/kotlin/com/titi/app/data/notification/impl/local/NotificationDataStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.titi.app.data.notification.impl.local | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import com.titi.app.core.util.fromJson | ||
import com.titi.app.core.util.readFlowValue | ||
import com.titi.app.core.util.readValue | ||
import com.titi.app.core.util.storeValue | ||
import com.titi.app.core.util.toJson | ||
import com.titi.app.data.notification.impl.local.model.NotificationEntity | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
internal class NotificationDataStore(context: Context) { | ||
private val dataStore: DataStore<Preferences> = context.dataStore | ||
|
||
suspend fun setNotification(notificationEntity: NotificationEntity) { | ||
dataStore.storeValue(NOTIFICATION_KEY, notificationEntity.toJson()) | ||
} | ||
|
||
fun getNotificationFlow(): Flow<NotificationEntity?> = | ||
dataStore.readFlowValue(NOTIFICATION_KEY).map { it?.fromJson() } | ||
|
||
suspend fun getNotification(): NotificationEntity? = | ||
dataStore.readValue(NOTIFICATION_KEY)?.fromJson() | ||
|
||
companion object { | ||
private const val NOTIFICATION_PREF_NAME = "notificationPrefName" | ||
private val NOTIFICATION_KEY = stringPreferencesKey("notificationKey") | ||
|
||
private val Context.dataStore: DataStore<Preferences> | ||
by preferencesDataStore(NOTIFICATION_PREF_NAME) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...mpl/src/main/kotlin/com/titi/app/data/notification/impl/local/model/NotificationEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.titi.app.data.notification.impl.local.model | ||
|
||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class NotificationEntity( | ||
val timerFiveMinutesBeforeTheEnd: Boolean, | ||
val timerBeforeTheEnd: Boolean, | ||
val stopwatch: Boolean, | ||
) |
10 changes: 10 additions & 0 deletions
10
...mpl/src/main/kotlin/com/titi/app/data/notification/impl/mapper/LocalToRepositoryMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.titi.app.data.notification.impl.mapper | ||
|
||
import com.titi.app.data.notification.api.model.NotificationRepositoryModel | ||
import com.titi.app.data.notification.impl.local.model.NotificationEntity | ||
|
||
internal fun NotificationEntity.toRepositoryModel() = NotificationRepositoryModel( | ||
timerFiveMinutesBeforeTheEnd = timerFiveMinutesBeforeTheEnd, | ||
timerBeforeTheEnd = timerBeforeTheEnd, | ||
stopwatch = stopwatch, | ||
) |
10 changes: 10 additions & 0 deletions
10
...mpl/src/main/kotlin/com/titi/app/data/notification/impl/mapper/RepositoryToLocalMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.titi.app.data.notification.impl.mapper | ||
|
||
import com.titi.app.data.notification.api.model.NotificationRepositoryModel | ||
import com.titi.app.data.notification.impl.local.model.NotificationEntity | ||
|
||
internal fun NotificationRepositoryModel.toLocalModel() = NotificationEntity( | ||
timerFiveMinutesBeforeTheEnd = timerFiveMinutesBeforeTheEnd, | ||
timerBeforeTheEnd = timerBeforeTheEnd, | ||
stopwatch = stopwatch, | ||
) |
27 changes: 27 additions & 0 deletions
27
.../main/kotlin/com/titi/app/data/notification/impl/repository/NotificationRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.titi.app.data.notification.impl.repository | ||
|
||
import com.titi.app.data.notification.api.NotificationRepository | ||
import com.titi.app.data.notification.api.model.NotificationRepositoryModel | ||
import com.titi.app.data.notification.impl.local.NotificationDataStore | ||
import com.titi.app.data.notification.impl.mapper.toLocalModel | ||
import com.titi.app.data.notification.impl.mapper.toRepositoryModel | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
internal class NotificationRepositoryImpl @Inject constructor( | ||
private val notificationDataStore: NotificationDataStore, | ||
) : NotificationRepository { | ||
override suspend fun setNotification(notificationRepositoryModel: NotificationRepositoryModel) { | ||
notificationDataStore.setNotification(notificationRepositoryModel.toLocalModel()) | ||
} | ||
|
||
override fun getNotificationFlow(): Flow<NotificationRepositoryModel> = | ||
notificationDataStore.getNotificationFlow() | ||
.map { it?.toRepositoryModel() ?: NotificationRepositoryModel() } | ||
|
||
override suspend fun getNotification(): NotificationRepositoryModel { | ||
return notificationDataStore.getNotification()?.toRepositoryModel() | ||
?: NotificationRepositoryModel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.