Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mod] #62 뒤로가기 로직 개선 및 SharedPreferences 값 초기화 #63

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ class MotivooStorageImpl @Inject constructor(@ApplicationContext context: Contex
}
}

override fun logout() {
val userData = pref.edit()
userData.remove(USER_ID)
userData.remove(ACCESS_TOKEN)
userData.remove(REFRESH_TOKEN)
userData.remove(INVITE_CODE)
userData.remove(IS_LOGIN)
userData.apply()
}

companion object {
private const val FILE_NAME = "MtDataStore"
private const val NAME = "name"
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/sopt/motivoo/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ object RetrofitModule {

@Provides
@Singleton
fun providesRetrofit(okHttpClient: OkHttpClient): Retrofit {
return Retrofit.Builder().baseUrl(BASE_URL).client(okHttpClient).addConverterFactory(
Json.asConverterFactory("application/json".toMediaType()),
fun providesRetrofit(okHttpClient: OkHttpClient, json: Json): Retrofit =
Retrofit.Builder().baseUrl(BASE_URL).client(okHttpClient).addConverterFactory(
json.asConverterFactory("application/json".toMediaType()),
).build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ interface MotivooStorage {
var otherId: Long
var myGoalStepCount: Int
var otherGoalStepCount: Int
fun logout()
fun clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SplashFragment : BindingFragment<FragmentSplashBinding>(R.layout.fragment_

private fun showSplash() {
lifecycleScope.launch {
delay(1500)
delay(2000)
navigateToNextFragment()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class AuthViewModel @Inject constructor(
authRepository.postLogout()
.onSuccess {
_logoutState.value = UiState.Success(true)
motivooStorage.logout()
}.onFailure { throwable ->
_logoutState.value = UiState.Failure(throwable.message.toString())
}
Expand All @@ -82,6 +83,7 @@ class AuthViewModel @Inject constructor(
authRepository.deleteWithDraw()
.onSuccess {
_withDrawState.value = UiState.Success(true)
motivooStorage.clear()
}.onFailure { throwable ->
_withDrawState.value = UiState.Failure(throwable.message.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.animation.AnimationUtils
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -49,11 +50,27 @@ class GetInviteCodeFragment :
collectData()
checkMatching()
clickBackButton()
backPressed()
}

private fun backPressed() {
requireActivity().onBackPressedDispatcher.addCallback(
viewLifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (motivooStorage.isFinishedOnboarding) {
passedOnboardingClickBackButton()
} else {
afterOnboardingClickBackButton()
}
}
}
)
}

private fun clickBackButton() {
binding.includeGetInviteCodeToolbar.tvToolbarBack.setOnSingleClickListener {
if (motivooStorage.isFinishedOnboarding) passedOnboardingClickBackButton() else afterOnboardingClickBackButton()
backPressed()
}
}

Expand Down Expand Up @@ -100,19 +117,17 @@ class GetInviteCodeFragment :
}

private fun afterOnboardingClickBackButton() {
binding.includeGetInviteCodeToolbar.tvToolbarBack.setOnSingleClickListener {
val navController = findNavController()
val startDestinationId = navController.findStartDestination().id
val navOptions = NavOptions.Builder()
.setPopUpTo(startDestinationId, true)
.build()

findNavController().navigate(
R.id.action_getInviteCodeFragment_to_startMotivooFragment,
null,
navOptions
)
}
val navController = findNavController()
val startDestinationId = navController.findStartDestination().id
val navOptions = NavOptions.Builder()
.setPopUpTo(startDestinationId, true)
.build()

findNavController().navigate(
R.id.action_getInviteCodeFragment_to_startMotivooFragment,
null,
navOptions
)
}

private fun setClipboard() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class OnboardingViewModel @Inject constructor(

private val _isPostOnboardingInfoSuccess = MutableStateFlow<UiState<Boolean>>(UiState.Loading)
val isPostOnboardingInfoSuccess get() = _isPostOnboardingInfoSuccess.asStateFlow()

fun setDoExerciseType(doExerciseType: DoExerciseType) {
_doExerciseType.value = doExerciseType
viewModelScope.launch {
Expand Down Expand Up @@ -186,7 +185,7 @@ class OnboardingViewModel @Inject constructor(
}
}

fun resetOnboardingFinishedState() {
private fun resetOnboardingFinishedState() {
_isPostOnboardingInfoSuccess.value = UiState.Loading
}
}
17 changes: 7 additions & 10 deletions app/src/main/res/layout/fragment_splash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="@string/motivoo_logo"
android:src="@drawable/ic_motivoo_splash"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lav_splash_lottie"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/splash_view_lottie" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
524 changes: 524 additions & 0 deletions app/src/main/res/raw/splash_view_lottie.json

Large diffs are not rendered by default.

Loading