-
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.
[MIN-44] feat: Home화면 API 구현 및 데이터바인딩 적용(#20)
- Loading branch information
Showing
20 changed files
with
266 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="80dp" | ||
android:height="80dp" | ||
android:viewportWidth="80" | ||
android:viewportHeight="80"> | ||
<group> | ||
<clip-path | ||
android:pathData="M80,40C80,62.091 62.091,80 40,80C17.909,80 0,62.091 0,40C0,17.909 17.909,0 40,0C62.091,0 80,17.909 80,40Z"/> | ||
<path | ||
android:pathData="M0,0h80v80h-80z" | ||
android:fillColor="#FFDB94"/> | ||
<path | ||
android:pathData="M24.753,53.765C26.608,55.62 28.719,56.712 29.792,57.124C43.659,62.458 47.325,59.825 49.521,58.247C49.631,58.168 49.736,58.093 49.839,58.021C56.197,53.57 60.882,44.844 62.028,37.296C62.582,33.642 62.134,30.122 60.311,26.897C58.754,24.144 55.945,21.038 52.844,20.03C49.009,18.783 44.579,20.667 41.838,23.334C41.096,24.056 40.357,24.897 39.698,25.817C37.105,23.234 32.642,22.297 29.228,22.476C23.798,22.76 20.119,27.205 18.311,31.967C16.319,37.215 18.157,41.68 20.203,46.648C20.255,46.776 20.308,46.905 20.361,47.034C22.002,51.025 23.505,52.522 24.613,53.626C24.661,53.673 24.707,53.719 24.753,53.765ZM39.698,25.817C38.343,27.71 37.327,29.937 37.327,32.145C37.327,33.708 38.192,38.04 40.664,36.187C43.239,34.255 42.239,29.756 40.923,27.416C40.59,26.825 40.176,26.293 39.698,25.817Z" | ||
android:fillColor="#ffffff" | ||
android:fillType="evenOdd"/> | ||
<path | ||
android:strokeWidth="1" | ||
android:pathData="M39.698,25.817C37.105,23.234 32.642,22.297 29.228,22.476C23.798,22.76 20.119,27.205 18.311,31.967C16.319,37.215 18.157,41.68 20.203,46.648C20.255,46.776 20.308,46.905 20.361,47.034C22.002,51.025 23.505,52.522 24.613,53.626C24.661,53.673 24.707,53.719 24.753,53.765C26.608,55.62 28.719,56.712 29.792,57.124C43.659,62.458 47.325,59.825 49.521,58.247C49.631,58.168 49.736,58.093 49.839,58.021C56.197,53.57 60.882,44.844 62.028,37.296C62.582,33.642 62.134,30.122 60.311,26.897C58.754,24.144 55.945,21.038 52.844,20.03C49.009,18.783 44.579,20.667 41.838,23.334C41.096,24.056 40.357,24.897 39.698,25.817ZM39.698,25.817C38.343,27.71 37.327,29.937 37.327,32.145C37.327,33.708 38.192,38.04 40.664,36.187C43.239,34.255 42.239,29.756 40.923,27.416C40.59,26.825 40.176,26.293 39.698,25.817Z" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:strokeWidth="1" | ||
android:pathData="M32.166,40C31.703,40.463 31.339,40.893 31,41.458" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:strokeWidth="1" | ||
android:pathData="M48,40C48.967,40 49.654,41.332 50.041,42.041" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:strokeWidth="1" | ||
android:pathData="M36,46.146C36.389,47.028 37.61,47.627 38.243,47.944C39.957,48.8 41.395,49.199 43.046,48.106C43.833,47.584 44.227,47.028 45.038,46" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
</group> | ||
</vector> |
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
8 changes: 8 additions & 0 deletions
8
common/src/main/java/com/example/common/data/dto/HomeResponse.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,8 @@ | ||
package com.example.common.data.dto | ||
|
||
import com.example.common.data.entity.HomeData | ||
|
||
data class HomeResponse( | ||
val data: HomeData, | ||
val success: Boolean | ||
) |
57 changes: 57 additions & 0 deletions
57
common/src/main/java/com/example/common/data/entity/HomeData.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,57 @@ | ||
package com.example.common.data.entity | ||
|
||
data class HomeData( | ||
val couple: Couple, | ||
val newStory: NewStory, | ||
val widgets: List<Widget> | ||
) | ||
|
||
|
||
data class Couple( | ||
val me: Me, | ||
val mine: Mine, | ||
val name: String, | ||
val startDate: String | ||
) | ||
|
||
|
||
data class NewStory( | ||
val date: String, | ||
val postId: Int, | ||
val region: String, | ||
val thumbnailImage: String | ||
) | ||
|
||
|
||
data class Mine( | ||
val birthday: String, | ||
val description: String, | ||
val gender: String, | ||
val instaId: String, | ||
val nickname: String, | ||
val profileImage: String | ||
) | ||
|
||
|
||
data class Me( | ||
val birthday: String, | ||
val description: String, | ||
val gender: String, | ||
val instaId: String, | ||
val nickname: String, | ||
val profileImage: String | ||
) | ||
|
||
|
||
data class Widget( | ||
val Id: Int, | ||
val color: String, | ||
val heigth: Int, | ||
val name: String, | ||
val order: Int, | ||
val type: String, | ||
val widget: WidgetX, | ||
val width: Int | ||
) | ||
|
||
class WidgetX |
17 changes: 13 additions & 4 deletions
17
common/src/main/java/com/example/common/data/source/UserService.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,25 +1,34 @@ | ||
package com.example.common.data.source | ||
|
||
import com.example.common.data.dto.CodeRequest | ||
import com.example.common.data.dto.HomeResponse | ||
import com.example.common.data.dto.UserInfoRequest | ||
import com.example.common.data.dto.NullResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.POST | ||
|
||
interface UserService { | ||
|
||
@POST("api/v1/user/info") | ||
suspend fun postUserInfo( | ||
@Header("Authorization") token : String, | ||
@Header("Authorization") token: String, | ||
@Body userInfoRequest: UserInfoRequest | ||
) : NullResponse | ||
): NullResponse | ||
|
||
|
||
@POST("api/v1/user/code") | ||
suspend fun postTargetCode( | ||
@Header("Authorization") token : String, | ||
@Header("Authorization") token: String, | ||
@Body userCodeRequest: CodeRequest | ||
) : NullResponse | ||
): NullResponse | ||
|
||
|
||
@GET("api/test/main/info") | ||
suspend fun getHomeInfo( | ||
@Header("Authorization") token: String, | ||
): HomeResponse | ||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
common/src/main/java/com/example/common/domain/usecase/UserUseCase.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,17 @@ | ||
package com.example.common.domain.usecase | ||
|
||
import com.example.common.data.dto.HomeResponse | ||
import com.example.common.data.source.UserService | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
//todo Singletone? | ||
@Singleton | ||
class UserUseCase @Inject constructor( | ||
private val userService: UserService | ||
) { | ||
// suspend fun getHomeData(token: String): HomeResponse { | ||
// return userService.getHomeInfo(token) | ||
// } | ||
} |
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,4 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
</manifest> |
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: 48 additions & 1 deletion
49
home/src/main/java/com/najudoryeong/mineme/home/HomeViewModel.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,7 +1,54 @@ | ||
package com.najudoryeong.mineme.home | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.databinding.Bindable | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.example.common.data.dto.HomeResponse | ||
import com.example.common.data.entity.HomeData | ||
import com.example.common.data.source.AuthService | ||
import com.example.common.data.source.UserService | ||
import com.example.common.domain.usecase.DataStoreUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
class HomeViewModel : ViewModel() { | ||
@HiltViewModel | ||
class HomeViewModel @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
private val userService: UserService, | ||
private val dataStoreUseCase: DataStoreUseCase | ||
) : ViewModel() { | ||
|
||
private val _isNewStory = MutableStateFlow(true) | ||
val isNewStory : StateFlow<Boolean> = _isNewStory | ||
|
||
private val _homeData = MutableStateFlow<HomeData?>(null) | ||
val homeData: StateFlow<HomeData?> = _homeData | ||
|
||
|
||
fun settingHomeData() { | ||
viewModelScope.launch { | ||
var a = dataStoreUseCase.bearerJsonWebToken.first() | ||
if (a == null) a = "bearer test" | ||
userService.getHomeInfo(a).let { | ||
if (it.success){ | ||
Log.d("TESTAPI","API넣음") | ||
if (it.data.newStory.postId == -1){ | ||
_isNewStory.value = true | ||
} | ||
_homeData.value = it.data | ||
|
||
} else { | ||
Log.d("TESTAPI","API실패") | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.