-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into stage/sandbox
- Loading branch information
Showing
30 changed files
with
456 additions
and
359 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
15 changes: 15 additions & 0 deletions
15
data/src/main/java/com/fakedevelopers/data/repository/LocalStorageRepositoryImpl.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,15 @@ | ||
package com.fakedevelopers.data.repository | ||
|
||
import com.fakedevelopers.data.source.LocalStorageDataSource | ||
import com.fakedevelopers.domain.repository.LocalStorageRepository | ||
import javax.inject.Inject | ||
|
||
class LocalStorageRepositoryImpl @Inject constructor( | ||
private val localStorageDataSource: LocalStorageDataSource | ||
) : LocalStorageRepository { | ||
override suspend fun getSearchHistory(): List<String> = | ||
localStorageDataSource.getSearchHistory() | ||
|
||
override suspend fun setSearchHistory(searchHistory: List<String>) = | ||
localStorageDataSource.setSearchHistory(searchHistory) | ||
} |
30 changes: 30 additions & 0 deletions
30
data/src/main/java/com/fakedevelopers/data/source/LocalStorageDataSource.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,30 @@ | ||
package com.fakedevelopers.data.source | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringSetPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class LocalStorageDataSource @Inject constructor( | ||
private val context: Context | ||
) { | ||
private val Context.datastore: DataStore<Preferences> by preferencesDataStore(name = "dataStore") | ||
private val searchHistoryKey = stringSetPreferencesKey(name = "search_history") | ||
|
||
suspend fun setSearchHistory(searchHistory: List<String>): Boolean = | ||
runCatching { | ||
context.datastore.edit { preferences -> | ||
preferences[searchHistoryKey] = searchHistory.toSet() | ||
} | ||
}.isSuccess | ||
|
||
suspend fun getSearchHistory(): List<String> = | ||
context.datastore.data.map { preferences -> | ||
preferences[searchHistoryKey]?.toList() ?: emptyList() | ||
}.first() | ||
} |
6 changes: 6 additions & 0 deletions
6
domain/src/main/java/com/fakedevelopers/domain/repository/LocalStorageRepository.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,6 @@ | ||
package com.fakedevelopers.domain.repository | ||
|
||
interface LocalStorageRepository { | ||
suspend fun getSearchHistory(): List<String> | ||
suspend fun setSearchHistory(searchHistory: List<String>): Boolean | ||
} |
11 changes: 11 additions & 0 deletions
11
domain/src/main/java/com/fakedevelopers/domain/usecase/GetSearchHistoryUseCase.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,11 @@ | ||
package com.fakedevelopers.domain.usecase | ||
|
||
import com.fakedevelopers.domain.repository.LocalStorageRepository | ||
import javax.inject.Inject | ||
|
||
class GetSearchHistoryUseCase @Inject constructor( | ||
private val repository: LocalStorageRepository | ||
) { | ||
suspend operator fun invoke(): List<String> = | ||
repository.getSearchHistory() | ||
} |
11 changes: 11 additions & 0 deletions
11
domain/src/main/java/com/fakedevelopers/domain/usecase/SetSearchHistoryUseCase.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,11 @@ | ||
package com.fakedevelopers.domain.usecase | ||
|
||
import com.fakedevelopers.domain.repository.LocalStorageRepository | ||
import javax.inject.Inject | ||
|
||
class SetSearchHistoryUseCase @Inject constructor( | ||
private val repository: LocalStorageRepository | ||
) { | ||
suspend operator fun invoke(searchHistory: List<String>): Boolean = | ||
repository.setSearchHistory(searchHistory) | ||
} |
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
17 changes: 0 additions & 17 deletions
17
presentation/src/main/java/com/fakedevelopers/presentation/api/datastore/DatastoreSetting.kt
This file was deleted.
Oops, something went wrong.
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.