-
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 #658 from bounswe/development
Development
- Loading branch information
Showing
254 changed files
with
24,566 additions
and
1,497 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
49 changes: 49 additions & 0 deletions
49
...tion-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivityViewModel.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,49 @@ | ||
package com.bounswe.predictionpolls | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.bounswe.predictionpolls.common.Result | ||
import com.bounswe.predictionpolls.domain.profile.GetCurrentUserProfileUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
|
||
data class MainActivityState(val points: Int? = null) | ||
|
||
@HiltViewModel | ||
class MainActivityViewModel @Inject constructor(private val fetchCurrentUserProfileUseCase: GetCurrentUserProfileUseCase) : | ||
ViewModel() { | ||
|
||
|
||
private val _state = MutableStateFlow(MainActivityState()) | ||
val state = _state.asStateFlow() | ||
|
||
|
||
init { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
fetchCurrentUserProfile() | ||
} | ||
} | ||
|
||
|
||
|
||
suspend fun fetchCurrentUserProfile() { | ||
when (val result = fetchCurrentUserProfileUseCase()) { | ||
is Result.Success -> { | ||
val profileInfo = result.data | ||
_state.update { | ||
it.copy(points = profileInfo.points) | ||
} | ||
} | ||
|
||
is Result.Error -> { | ||
// handle error | ||
} | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
.../android/app/src/main/java/com/bounswe/predictionpolls/data/editProfile/EditProfileApi.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,42 @@ | ||
package com.bounswe.predictionpolls.data.editProfile | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import retrofit2.http.Body | ||
import retrofit2.http.Multipart | ||
import retrofit2.http.PATCH | ||
import retrofit2.http.POST | ||
import retrofit2.http.Part | ||
import java.io.File | ||
|
||
|
||
interface EditProfileApi { | ||
|
||
@Multipart | ||
@POST("profiles/profilePhoto") | ||
suspend fun uploadProfilePhoto( | ||
@Part image: MultipartBody.Part, | ||
@Part("caption") caption: RequestBody | ||
) | ||
|
||
@PATCH("profiles") | ||
suspend fun updateProfile(@Body body: EditProfileRequest) | ||
} | ||
|
||
|
||
data class EditProfileRequest( | ||
val userId: Int?, | ||
val username: String?, | ||
val email: String?, | ||
@SerializedName("profile_picture") | ||
val profilePicture: String?, | ||
val points: Int?, | ||
val biography: String?, | ||
val birthday: String?, | ||
val isHidden: Boolean? | ||
) | ||
|
||
fun prepareFilePart(file: File): RequestBody = file.asRequestBody("image/*".toMediaTypeOrNull()) |
32 changes: 32 additions & 0 deletions
32
...d/app/src/main/java/com/bounswe/predictionpolls/data/editProfile/EditProfileRepository.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,32 @@ | ||
package com.bounswe.predictionpolls.data.editProfile | ||
|
||
import android.util.Log | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class EditProfileRepository @Inject constructor( | ||
private val editProfileApi: EditProfileApi | ||
) { | ||
|
||
suspend fun uploadProfilePhoto(file: File, caption: String) { | ||
|
||
// Create RequestBody instances for image and caption | ||
val requestFile = RequestBody.create("image/*".toMediaTypeOrNull(), file) | ||
val imageBody = MultipartBody.Part.createFormData("image", file.name, requestFile) | ||
val captionBody = RequestBody.create("text/plain".toMediaTypeOrNull(), caption) | ||
|
||
try { | ||
editProfileApi.uploadProfilePhoto(imageBody, captionBody) | ||
} catch (error: Exception) { | ||
// Handle network error | ||
Log.e("TAG", "uploadProfilePhoto: $error", ) | ||
} | ||
} | ||
|
||
suspend fun updateProfile(body: EditProfileRequest) { | ||
editProfileApi.updateProfile(body) | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...on-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/profile/ProfileApi.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 |
---|---|---|
@@ -1,14 +1,30 @@ | ||
package com.bounswe.predictionpolls.data.profile | ||
|
||
import com.bounswe.predictionpolls.data.profile.model.FollowRequest | ||
import com.bounswe.predictionpolls.data.profile.model.GetFollowersRequest | ||
import com.bounswe.predictionpolls.data.profile.model.ProfileInfoResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Query | ||
|
||
interface ProfileApi { | ||
|
||
@GET("profiles") | ||
suspend fun fetchProfileInfo(@Query("username") username: String): ProfileInfoResponse | ||
|
||
@POST("profiles/follow") | ||
suspend fun followUser(@Body followRequest: FollowRequest) | ||
|
||
@POST("profiles/unfollow") | ||
suspend fun unfollowUser(@Body followRequest: FollowRequest) | ||
|
||
@POST("profiles/follower") | ||
suspend fun fetchFollowers(@Body getFollowersRequest: GetFollowersRequest): FollowerResponse | ||
|
||
@POST("profiles/followed") | ||
suspend fun fetchFollowed(@Body getFollowersRequest: GetFollowersRequest): FollowerResponse | ||
|
||
@GET("profiles/myProfile") | ||
suspend fun fetchCurrentUserProfileInfo(): ProfileInfoResponse | ||
} |
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.