-
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 pull request #77 from snuhcs-course/refactor/move-viewmodel
ViewModel 위치 변경
- Loading branch information
Showing
11 changed files
with
166 additions
and
152 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
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
29 changes: 29 additions & 0 deletions
29
frontend/app/src/main/java/com/example/frontend/viewmodel/FriendsViewModel.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,29 @@ | ||
package com.example.frontend.viewmodel | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.example.frontend.callback.FriendLocationCallback | ||
import com.example.frontend.model.UserWithLocationModel | ||
import com.example.frontend.repository.FriendsRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class FriendsViewModel @Inject constructor(private val repository: FriendsRepository) : | ||
ViewModel() { | ||
private val _friendsList = MutableLiveData<List<UserWithLocationModel>>() | ||
val friendsList: LiveData<List<UserWithLocationModel>> = _friendsList | ||
|
||
fun fetchFriends() { | ||
repository.getNearbyFriends(object : FriendLocationCallback { | ||
override fun onResult(result: List<UserWithLocationModel>) { | ||
_friendsList.postValue(result) | ||
} | ||
|
||
override fun onError(error: Throwable) { | ||
// Handle error | ||
} | ||
}) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
frontend/app/src/main/java/com/example/frontend/viewmodel/InviteFriendViewModel.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,18 @@ | ||
package com.example.frontend.viewmodel | ||
|
||
import androidx.compose.runtime.mutableStateMapOf | ||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
||
class InviteFriendViewModel : ViewModel() { | ||
|
||
private val _checkedStates = mutableStateMapOf<Long, Boolean>() | ||
private val _checkedStatesFlow = MutableStateFlow<Map<Long, Boolean>>(_checkedStates) | ||
|
||
val checkedStatesFlow = _checkedStatesFlow.asStateFlow() | ||
fun updateCheckedState(friendId: Long, isChecked: Boolean) { | ||
_checkedStates[friendId] = isChecked | ||
_checkedStatesFlow.value = _checkedStates.toMap() | ||
} | ||
} |
Oops, something went wrong.