모든 기기에서 로그아웃 추가
This commit is contained in:
parent
a75217ee09
commit
68f2896031
|
@ -1,7 +1,10 @@
|
|||
package kr.co.vividnext.sodalive.network
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import kr.co.vividnext.sodalive.audio_content.AudioContentPlayService
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.user.login.LoginActivity
|
||||
import okhttp3.Authenticator
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
|
@ -12,7 +15,16 @@ class TokenAuthenticator(
|
|||
) : Authenticator {
|
||||
override fun authenticate(route: Route?, response: Response): Request? {
|
||||
if (response.code == 401) {
|
||||
context.startService(
|
||||
Intent(context, AudioContentPlayService::class.java).apply {
|
||||
action = AudioContentPlayService.MusicAction.STOP.name
|
||||
}
|
||||
)
|
||||
|
||||
SharedPreferenceManager.clear()
|
||||
val intent = Intent(context, LoginActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
return null
|
||||
|
|
|
@ -35,6 +35,19 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>(ActivitySettingsB
|
|||
)
|
||||
}
|
||||
|
||||
private val logoutAllDialog: SodaDialog by lazy {
|
||||
SodaDialog(
|
||||
activity = this,
|
||||
layoutInflater = layoutInflater,
|
||||
title = "알림",
|
||||
desc = "모든 기기에서 로그아웃 하시겠어요?",
|
||||
confirmButtonTitle = "확인",
|
||||
confirmButtonClick = { logoutAllDevice() },
|
||||
cancelButtonTitle = "취소",
|
||||
cancelButtonClick = {}
|
||||
)
|
||||
}
|
||||
|
||||
private val viewModel: SettingsViewModel by inject()
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
|
@ -101,6 +114,10 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>(ActivitySettingsB
|
|||
logoutDialog.show(screenWidth)
|
||||
}
|
||||
|
||||
binding.tvLogOutAll.setOnClickListener {
|
||||
logoutAllDialog.show(screenWidth)
|
||||
}
|
||||
|
||||
binding.tvSignOut.paintFlags = binding.tvSignOut.paintFlags.or(Paint.UNDERLINE_TEXT_FLAG)
|
||||
binding.tvSignOut.setOnClickListener {
|
||||
startActivity(Intent(applicationContext, SignOutActivity::class.java))
|
||||
|
@ -134,4 +151,18 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>(ActivitySettingsB
|
|||
startActivity(Intent(applicationContext, SplashActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
private fun logoutAllDevice() {
|
||||
startService(
|
||||
Intent(applicationContext, AudioContentPlayService::class.java).apply {
|
||||
action = AudioContentPlayService.MusicAction.STOP.name
|
||||
}
|
||||
)
|
||||
|
||||
viewModel.logoutAllDevice() {
|
||||
SharedPreferenceManager.clear()
|
||||
finishAffinity()
|
||||
startActivity(Intent(applicationContext, SplashActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,4 +44,31 @@ class SettingsViewModel(private val userRepository: UserRepository) : BaseViewMo
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun logoutAllDevice(onSuccess: () -> Unit) {
|
||||
compositeDisposable.add(
|
||||
userRepository.logoutAllDevice(token = "Bearer ${SharedPreferenceManager.token}")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
if (it.success) {
|
||||
onSuccess()
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,4 +98,7 @@ interface UserApi {
|
|||
|
||||
@POST("/member/logout")
|
||||
fun logout(@Header("Authorization") authHeader: String): Single<ApiResponse<Any>>
|
||||
|
||||
@POST("/member/logout/all")
|
||||
fun logoutAll(@Header("Authorization") authHeader: String): Single<ApiResponse<Any>>
|
||||
}
|
||||
|
|
|
@ -78,4 +78,5 @@ class UserRepository(private val userApi: UserApi) {
|
|||
) = userApi.signOut(request, authHeader = token)
|
||||
|
||||
fun logout(token: String) = userApi.logout(authHeader = token)
|
||||
fun logoutAllDevice(token: String) = userApi.logoutAll(authHeader = token)
|
||||
}
|
||||
|
|
|
@ -271,6 +271,17 @@
|
|||
android:textColor="@color/color_eeeeee"
|
||||
android:textSize="14.7sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_log_out_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="26.7dp"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:text="모든 기기에서 로그아웃"
|
||||
android:textColor="@color/color_777777"
|
||||
android:textSize="14.7sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sign_out"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -281,7 +292,6 @@
|
|||
android:text="회원탈퇴"
|
||||
android:textColor="@color/color_777777"
|
||||
android:textSize="14.7sp" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue