-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: JunJangE <[email protected]>
- Loading branch information
Showing
24 changed files
with
388 additions
and
2 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
17 changes: 17 additions & 0 deletions
17
android/app/src/main/java/com/happy/friendogly/data/repository/OnboardingRepositoryImpl.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,17 @@ | ||
package com.happy.friendogly.data.repository | ||
|
||
import com.happy.friendogly.data.source.OnboardingDataSource | ||
import com.happy.friendogly.domain.repository.OnboardingRepository | ||
import javax.inject.Inject | ||
|
||
class OnboardingRepositoryImpl | ||
@Inject | ||
constructor( | ||
private val source: OnboardingDataSource, | ||
) : OnboardingRepository { | ||
override suspend fun isShown(): Result<Boolean> = source.isShown() | ||
|
||
override suspend fun setShown(isShown: Boolean): Result<Unit> = source.setShown(isShown) | ||
|
||
override suspend fun deleteIsShown(): Result<Unit> = source.deleteShown() | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/data/source/OnboardingDataSource.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,9 @@ | ||
package com.happy.friendogly.data.source | ||
|
||
interface OnboardingDataSource { | ||
suspend fun isShown(): Result<Boolean> | ||
|
||
suspend fun setShown(isShown: Boolean): Result<Unit> | ||
|
||
suspend fun deleteShown(): Result<Unit> | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/com/happy/friendogly/domain/repository/OnboardingRepository.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,9 @@ | ||
package com.happy.friendogly.domain.repository | ||
|
||
interface OnboardingRepository { | ||
suspend fun isShown(): Result<Boolean> | ||
|
||
suspend fun setShown(isShown: Boolean): Result<Unit> | ||
|
||
suspend fun deleteIsShown(): Result<Unit> | ||
} |
12 changes: 12 additions & 0 deletions
12
...oid/app/src/main/java/com/happy/friendogly/domain/usecase/DeleteOnboardingShownUseCase.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.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.OnboardingRepository | ||
import javax.inject.Inject | ||
|
||
class DeleteOnboardingShownUseCase | ||
@Inject | ||
constructor( | ||
private val repository: OnboardingRepository, | ||
) { | ||
suspend operator fun invoke(): Result<Unit> = repository.deleteIsShown() | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/com/happy/friendogly/domain/usecase/GetOnboardingShownUseCase.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.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.OnboardingRepository | ||
import javax.inject.Inject | ||
|
||
class GetOnboardingShownUseCase | ||
@Inject | ||
constructor( | ||
private val repository: OnboardingRepository, | ||
) { | ||
suspend operator fun invoke(): Result<Boolean> = repository.isShown() | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/com/happy/friendogly/domain/usecase/SetOnboardingShownUseCase.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.happy.friendogly.domain.usecase | ||
|
||
import com.happy.friendogly.domain.repository.OnboardingRepository | ||
import javax.inject.Inject | ||
|
||
class SetOnboardingShownUseCase | ||
@Inject | ||
constructor( | ||
private val repository: OnboardingRepository, | ||
) { | ||
suspend operator fun invoke(isShown: Boolean): Result<Unit> = repository.setShown(isShown) | ||
} |
47 changes: 47 additions & 0 deletions
47
android/app/src/main/java/com/happy/friendogly/local/di/OnboardingModule.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,47 @@ | ||
package com.happy.friendogly.local.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.map | ||
import java.io.IOException | ||
|
||
class OnboardingModule(val context: Context) { | ||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = DATA_STORE_NAME) | ||
|
||
private val key = booleanPreferencesKey(IS_ONBOARDING) | ||
|
||
var isShown: Flow<Boolean> = | ||
context.dataStore.data.catch { exception -> | ||
if (exception is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw exception | ||
} | ||
}.map { preferences -> | ||
preferences[key] ?: false | ||
} | ||
|
||
suspend fun setShown(value: Boolean) { | ||
context.dataStore.edit { preferences -> | ||
preferences[key] = value | ||
} | ||
} | ||
|
||
suspend fun deleteIsShown() { | ||
context.dataStore.edit { prefs -> | ||
prefs.remove(key) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val IS_ONBOARDING = "IS_ONBOARDING_SHOWN" | ||
private const val DATA_STORE_NAME = "onboardingDataStore" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
android/app/src/main/java/com/happy/friendogly/local/source/OnboardingDataSourceImpl.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.happy.friendogly.local.source | ||
|
||
import com.happy.friendogly.data.source.OnboardingDataSource | ||
import com.happy.friendogly.local.di.OnboardingModule | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class OnboardingDataSourceImpl | ||
@Inject | ||
constructor( | ||
private val onboardingModule: OnboardingModule, | ||
) : OnboardingDataSource { | ||
override suspend fun isShown(): Result<Boolean> = | ||
runCatching { | ||
onboardingModule.isShown.first() | ||
} | ||
|
||
override suspend fun setShown(isShown: Boolean): Result<Unit> = | ||
runCatching { | ||
onboardingModule.setShown(isShown) | ||
} | ||
|
||
override suspend fun deleteShown(): Result<Unit> = | ||
runCatching { | ||
onboardingModule.deleteIsShown() | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
...ain/java/com/happy/friendogly/presentation/ui/playground/onboarding/OnboardingActivity.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,23 @@ | ||
package com.happy.friendogly.presentation.ui.playground.onboarding | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
import com.happy.friendogly.databinding.ActivityOnboardingBinding | ||
|
||
class OnboardingActivity : AppCompatActivity() { | ||
lateinit var binding: ActivityOnboardingBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityOnboardingBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
initOnboardingPager() | ||
} | ||
|
||
private fun initOnboardingPager() { | ||
binding.vpDescExplain.adapter = OnboardingAdapter(this) | ||
TabLayoutMediator(binding.tlDescIndicator, binding.vpDescExplain) { tab, position -> | ||
}.attach() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...main/java/com/happy/friendogly/presentation/ui/playground/onboarding/OnboardingAdapter.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,17 @@ | ||
package com.happy.friendogly.presentation.ui.playground.onboarding | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
|
||
class OnboardingAdapter( | ||
fragmentActivity: FragmentActivity, | ||
) : FragmentStateAdapter(fragmentActivity) { | ||
override fun getItemCount(): Int = 3 | ||
|
||
override fun createFragment(position: Int): Fragment { | ||
return OnboardingFragment().apply { | ||
arguments = OnboardingFragment.getBundle(position) | ||
} | ||
} | ||
} |
Oops, something went wrong.