-
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 branch 'main' into frontend for updating friendlist
- Loading branch information
Showing
19 changed files
with
838 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -460,18 +460,9 @@ fun HarmonyHubApp( | |
|
||
composable(route = HarmonyHubScreen.Friends.name) { | ||
FriendsScreen( | ||
friends = listOf( | ||
Friend("Anh", "[email protected]", R.drawable.hip), | ||
Friend("Minh", "[email protected]", R.drawable.hip) | ||
), | ||
onBackButtonClicked = { navController.popBackStack() }, | ||
onAddButtonClicked = { }, | ||
onUnfriendClicked = { }, | ||
onWatchPlaylistClicked = { }, | ||
friendRequests = listOf( | ||
Friend("Anh", "[email protected]", R.drawable.hip), | ||
Friend("Minh", "[email protected]", R.drawable.hip) | ||
) | ||
) | ||
|
||
} | ||
|
393 changes: 381 additions & 12 deletions
393
app/src/main/java/com/example/harmonyhub/data/repository/UserDataRepoImpl.kt
Large diffs are not rendered by default.
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
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/example/harmonyhub/presentation/viewmodel/FriendListViewModel.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,74 @@ | ||
package com.example.harmonyhub.presentation.viewmodel | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.example.harmonyhub.domain.repository.UserDataRepo | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class FriendListViewModel @Inject constructor( | ||
private val userRepo: UserDataRepo, | ||
): ViewModel() { | ||
|
||
private val _dataFetchingState = MutableLiveData<FriendListFetchingState>() | ||
val dataFetchingState: MutableLiveData<FriendListFetchingState> get() = _dataFetchingState | ||
|
||
init { | ||
resetDataFetchingState() | ||
} | ||
|
||
fun resetDataFetchingState() { | ||
_dataFetchingState.value = FriendListFetchingState.Pending | ||
} | ||
|
||
fun searchForEmail(email: String) { | ||
val emailPattern = "[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}" | ||
|
||
if (!email.matches(emailPattern.toRegex())) { | ||
_dataFetchingState.value = FriendListFetchingState.Error("Invalid email format") | ||
return | ||
} | ||
|
||
userRepo.searchForEmail(email) { state -> | ||
_dataFetchingState.value = state | ||
} | ||
} | ||
|
||
fun getFriendRequests() { | ||
userRepo.getFriendRequests { state -> | ||
_dataFetchingState.value = state | ||
} | ||
} | ||
|
||
fun acceptFriendRequest(uid: String) { | ||
userRepo.acceptFriendRequest(uid) { state -> | ||
_dataFetchingState.value = state | ||
} | ||
} | ||
|
||
fun declineFriendRequest(uid: String) { | ||
userRepo.declineFriendRequest(uid) { state -> | ||
_dataFetchingState.value = state | ||
} | ||
} | ||
|
||
fun getFriends() { | ||
userRepo.getFriends { state -> | ||
_dataFetchingState.value = state | ||
} | ||
} | ||
|
||
fun removeFriend(uid: String) { | ||
userRepo.removeFriend(uid) { state -> | ||
_dataFetchingState.value = state | ||
} | ||
} | ||
} | ||
|
||
sealed class FriendListFetchingState { | ||
object Pending : FriendListFetchingState() | ||
data class Success(val data: Any) : FriendListFetchingState() | ||
data class SuccessOnGetFriends(val data: Any) : FriendListFetchingState() | ||
data class Error(val message: String) : FriendListFetchingState() | ||
} |
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
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
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.