Skip to content

Commit 39ae0e0

Browse files
authored
Implemented Logout Feature
Log out implemented
2 parents c84ab21 + cf77c10 commit 39ae0e0

File tree

12 files changed

+58
-5
lines changed

12 files changed

+58
-5
lines changed

app/src/main/java/com/github/code/gambit/data/local/CacheDataSource.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface CacheDataSource {
99
suspend fun insertFiles(files: List<File>): Long
1010
suspend fun getFiles(): List<File>
1111
suspend fun deleteFile(fileId: String): Int
12+
suspend fun deleteFiles(): Int
1213
suspend fun insertUrls(urls: List<Url>): Long
1314
suspend fun getUrls(fileId: String): List<Url>
1415
suspend fun insertFileMetaData(fileMetaData: FileMetaData, uuid: String)

app/src/main/java/com/github/code/gambit/data/local/CacheDataSourceImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ constructor(
3636
return fileDao.deleteFile(fileId)
3737
}
3838

39+
override suspend fun deleteFiles(): Int {
40+
return fileDao.deleteFiles()
41+
}
42+
3943
override suspend fun insertUrls(urls: List<Url>): Long {
4044
val res = urlDao.insertUrls(urlCacheMapper.mapToEntityList(urls))
4145
return res.size.toLong()

app/src/main/java/com/github/code/gambit/data/local/FileDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ interface FileDao {
2020

2121
@Query("DELETE FROM files WHERE id = :id")
2222
suspend fun deleteFile(id: String): Int
23+
24+
@Query("DELETE FROM files")
25+
suspend fun deleteFiles(): Int
2326
}

app/src/main/java/com/github/code/gambit/data/remote/services/auth/AuthService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.github.code.gambit.helper.auth.AuthData
88
interface AuthService {
99
suspend fun login(authData: AuthData): ServiceResult<Unit>
1010
suspend fun signUp(authData: AuthData): ServiceResult<Unit>
11+
suspend fun logOut(): ServiceResult<Unit>
1112
suspend fun resetPassword(oldPassword: String, newPassword: String): ServiceResult<Unit>
1213
suspend fun updateUserName(fullName: String): ServiceResult<String>
1314
suspend fun confirmSignUp(authData: AuthData): ServiceResult<Unit>

app/src/main/java/com/github/code/gambit/data/remote/services/auth/AuthServiceImpl.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class AuthServiceImpl : AuthService {
4040
}
4141
}
4242

43+
override suspend fun logOut(): ServiceResult<Unit> {
44+
return try {
45+
Amplify.Auth.signOut()
46+
ServiceResult.Success(Unit)
47+
} catch (e: AuthException) {
48+
ServiceResult.Error(e)
49+
}
50+
}
51+
4352
override suspend fun resetPassword(oldPassword: String, newPassword: String): ServiceResult<Unit> {
4453
return try {
4554
val result = Amplify.Auth.updatePassword(oldPassword, newPassword)

app/src/main/java/com/github/code/gambit/repositories/profile/ProfileRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ interface ProfileRepository {
99
suspend fun getUser(): Flow<ServiceResult<User>>
1010
suspend fun updateUserName(name: String): ServiceResult<String>
1111
suspend fun updateUserPassword(oldPassword: String, newPassword: String): ServiceResult<Boolean>
12+
suspend fun logOut(): ServiceResult<Unit>
1213
}

app/src/main/java/com/github/code/gambit/repositories/profile/ProfileRepositoryImpl.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,13 @@ constructor(
7373
ServiceResult.Error(e)
7474
}
7575
}
76+
77+
override suspend fun logOut(): ServiceResult<Unit> {
78+
return try {
79+
authService.logOut()
80+
return ServiceResult.Success(Unit)
81+
} catch (exception: Exception) {
82+
ServiceResult.Error(exception)
83+
}
84+
}
7685
}

app/src/main/java/com/github/code/gambit/ui/fragment/profile/ProfileFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
9393
viewModel.setEvent(ProfileEvent.UpdateDisplayNameEvent(newName))
9494
}
9595
}
96+
binding.logOutButton.setOnClickListener {
97+
viewModel.setEvent(ProfileEvent.LogOut)
98+
}
9699
changePasswordListener1 = View.OnClickListener {
97100
binding.passwordContainer.show()
98101
binding.cancelButton.show()

app/src/main/java/com/github/code/gambit/ui/fragment/profile/ProfileViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ constructor(private val profileRepository: ProfileRepository) : ViewModel() {
2626
fun setEvent(event: ProfileEvent) {
2727
viewModelScope.launch {
2828
when (event) {
29+
ProfileEvent.LogOut -> {
30+
when (val it = profileRepository.logOut()) {
31+
is ServiceResult.Error -> postError(it.exception)
32+
is ServiceResult.Success -> postError(Exception("LOG OUT SUCCESS"))
33+
}
34+
}
2935
ProfileEvent.GetUserInfoEvent -> {
3036
_profileState.postValue(ProfileState.Loading)
3137
profileRepository.getUser().onEach {
@@ -67,6 +73,7 @@ constructor(private val profileRepository: ProfileRepository) : ViewModel() {
6773
}
6874

6975
sealed class ProfileEvent {
76+
object LogOut : ProfileEvent()
7077
object GetUserInfoEvent : ProfileEvent()
7178
data class UpdatePasswordEvent(val oldPassword: String, val newPassword: String) : ProfileEvent()
7279
data class UpdateDisplayNameEvent(val name: String) : ProfileEvent()

app/src/main/res/layout/fragment_profile.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,27 @@
172172
</com.google.android.material.textfield.TextInputLayout>
173173
</LinearLayout>
174174

175+
<Button
176+
android:id="@+id/log_out_button"
177+
style="@style/profile_button_theme"
178+
android:layout_width="wrap_content"
179+
android:layout_height="36dp"
180+
android:text="@string/log_out"
181+
app:layout_constraintBottom_toBottomOf="parent"
182+
app:layout_constraintEnd_toEndOf="parent"
183+
app:layout_constraintStart_toStartOf="parent"
184+
app:layout_constraintTop_toBottomOf="@+id/password_container" />
185+
175186
<Button
176187
android:id="@+id/change_password_button"
177-
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
188+
style="@style/profile_button_theme"
178189
android:layout_width="wrap_content"
179190
android:layout_height="36dp"
180191
android:text="@string/change_password"
181-
android:textAllCaps="true"
182-
android:textColor="@color/secondary"
183-
android:textSize="12sp"
184192
app:layout_constraintBottom_toTopOf="@+id/password_container"
185193
app:layout_constraintEnd_toEndOf="parent"
186194
app:layout_constraintStart_toStartOf="parent"
187195
app:layout_constraintTop_toBottomOf="@id/storage_used_card"
188-
app:strokeColor="@color/secondary"
189196
android:layout_marginTop="64dp"/>
190197

191198
<Button

0 commit comments

Comments
 (0)