Skip to content

Commit

Permalink
Merge pull request #28 from teamcadi/taeho
Browse files Browse the repository at this point in the history
Taeho
  • Loading branch information
bbaktaeho authored Feb 26, 2021
2 parents 31fcdd8 + 14628f3 commit de8bac2
Show file tree
Hide file tree
Showing 26 changed files with 639 additions and 243 deletions.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name="com.example.noogabab.presentation.ui.main.setting.SettingsActivity">
</activity>

<service
android:name=".NoogabobFirebaseMessagingService"
Expand All @@ -33,6 +31,7 @@
<activity android:name=".presentation.ui.main.album.AlbumDetailActivity" />
<activity android:name=".presentation.ui.main.timeline.TimelineActivity" />
<activity android:name=".presentation.ui.start.createGroup.CreateGroupActivity" />
<activity android:name=".presentation.ui.main.setting.SettingsActivity" />
<activity
android:name=".presentation.ui.start.enterGroup.EnterGroupActivity"
android:windowSoftInputMode="adjustPan" />
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/com/example/noogabab/data/api/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.noogabab.data.api
import com.example.noogabab.data.api.model.*
import com.example.noogabab.data.api.request.CreateGroupRequest
import com.example.noogabab.data.api.request.CreateUserRequest
import com.example.noogabab.data.api.request.FeedRequest
import com.example.noogabab.util.NetworkConstants
import okhttp3.RequestBody
import retrofit2.http.*
Expand Down Expand Up @@ -65,12 +66,23 @@ interface ApiService {
)
suspend fun getDog(@Header("key") key: String): GetDogModel

@GET(NetworkConstants.URL_DOGS_MEAL_LATEST)
suspend fun getMealLatest(@Path("dogId") dogId: Int): MealLatestModel

@PUT(NetworkConstants.URL_DOGS_DOG)
suspend fun modifyDog()

@POST(NetworkConstants.URL_DOGS_MEAL)
suspend fun feedMealDog()
suspend fun feedMealDog(
@Header("key") key: String,
@Path("dogId") dogId: Int,
@Body feed: FeedRequest
): FeedModel

@POST(NetworkConstants.URL_DOGS_SNACK)
suspend fun feedSnackDog()
suspend fun feedSnackDog(
@Header("key") key: String,
@Path("dogId") dogId: Int,
@Body feed: FeedRequest
): FeedModel
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/noogabab/data/api/model/FeedModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.noogabab.data.api.model


import com.google.gson.annotations.SerializedName

data class FeedModel(
@SerializedName("data")
val data: Any?,
@SerializedName("message")
val message: String,
@SerializedName("success")
val success: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.noogabab.data.api.model


import com.google.gson.annotations.SerializedName

data class MealLatestModel(
@SerializedName("data")
val content: String?,
@SerializedName("message")
val message: String,
@SerializedName("success")
val success: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.noogabab.data.api.request

import com.google.gson.annotations.SerializedName

data class FeedRequest(
@SerializedName("userId")
val userId: Int,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.example.noogabab.domain.repository

import com.example.noogabab.data.api.ApiService
import com.example.noogabab.data.api.request.FeedRequest
import okhttp3.Headers
import javax.inject.Inject

class DogRepository @Inject constructor(private val apiService: ApiService) {
suspend fun getDog(key: String) = apiService.getDog(key)
suspend fun getMealLatest(dogId: Int) = apiService.getMealLatest(dogId)
suspend fun feedMeal(key: String, dogId: Int, feed: FeedRequest) = apiService.feedMealDog(key, dogId, feed)
suspend fun feedSnack(key: String, dogId: Int, feed: FeedRequest) = apiService.feedSnackDog(key, dogId, feed)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.noogabab.domain.usecase

import com.example.noogabab.data.api.model.FeedModel
import com.example.noogabab.data.api.model.GetDogModel
import com.example.noogabab.data.api.model.MealLatestModel
import com.example.noogabab.data.api.model.ResultData
import com.example.noogabab.data.api.request.FeedRequest
import com.example.noogabab.domain.repository.DogRepository
import javax.inject.Inject

Expand All @@ -11,4 +14,19 @@ class DogUseCase @Inject constructor(private val dogRepository: DogRepository) {
return if (dog.success) ResultData.Success(dog)
else ResultData.Failed(dog.message)
}
suspend fun getMealLatest(dogId: Int): ResultData<MealLatestModel> {
val mealLatest = dogRepository.getMealLatest(dogId)
return if (mealLatest.success) ResultData.Success(mealLatest)
else ResultData.Failed(mealLatest.message)
}
suspend fun feedMeal(key: String, dogId: Int, feed: FeedRequest): ResultData<FeedModel> {
val res = dogRepository.feedMeal(key, dogId, feed)
return if (res.success) ResultData.Success(res)
else ResultData.Failed(res.message)
}
suspend fun feedSnack(key: String, dogId: Int, feed: FeedRequest): ResultData<FeedModel> {
val res = dogRepository.feedSnack(key, dogId, feed)
return if (res.success) ResultData.Success(res)
else ResultData.Failed(res.message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.widget.Toast
import androidx.annotation.IdRes
import androidx.core.app.ActivityCompat
import androidx.core.view.get
import androidx.fragment.app.Fragment
import com.example.noogabab.R
import com.example.noogabab.presentation.ui.main.album.AlbumFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ class MainViewModel @ViewModelInject constructor(private val groupUseCase: Group
_currentLatestTimeline.value= "로딩 중"
_currentDogProfile.value = null
}

fun getChart(key: String, groupId: Int, type: String, date: String) =
liveData {
emit(ResultData.Loading())
emit(groupUseCase.getGroupStatistics(key, groupId, type, date))
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.noogabab.presentation.ui.main.chart

import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.formatter.ValueFormatter
import com.github.mikephil.charting.utils.ViewPortHandler
import java.text.DecimalFormat

class ChartValueFormatter: ValueFormatter {
override fun getFormattedValue(
value: Float,
entry: Entry?,
dataSetIndex: Int,
viewPortHandler: ViewPortHandler?
): String {
return ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.example.noogabab.presentation.ui.main.chart

import android.annotation.SuppressLint
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.example.noogabab.data.api.model.ResultData
import com.example.noogabab.domain.usecase.GroupUseCase
import kotlin.collections.ArrayList

class ChartViewModel @ViewModelInject constructor(private val groupUseCase: GroupUseCase): ViewModel() {
private val _currentWeekXGroups = MutableLiveData<ArrayList<String>>()
private val _currentWeekYBobs = MutableLiveData<FloatArray>()
private val _currentWeekYSnacks = MutableLiveData<FloatArray>()
private val _currentMonthXGroups = MutableLiveData<ArrayList<String>>()
private val _currentMonthYBobs = MutableLiveData<FloatArray>()
private val _currentMonthYSnacks = MutableLiveData<FloatArray>()
private val _currentWeekDate = MutableLiveData<String>()
private val _currentMonthDate = MutableLiveData<String>()

init {
_currentWeekXGroups.value = ArrayList<String>()
_currentWeekYBobs.value = floatArrayOf()
_currentWeekYSnacks.value = floatArrayOf()
_currentMonthXGroups.value = ArrayList<String>()
_currentMonthYBobs.value = floatArrayOf()
_currentMonthYSnacks.value = floatArrayOf()
_currentWeekDate.value = "1970-12-10"
_currentMonthDate.value = "1970-12-10"
}

fun getStatistics(key: String, groupId: Int, type: String, date: String) = liveData {
emit(ResultData.Loading())
emit(groupUseCase.getGroupStatistics(key, groupId, type, date))
}

val currentWeekXGroups: LiveData<ArrayList<String>>
get() = _currentWeekXGroups

val currentWeekDate: LiveData<String>
get() = _currentWeekDate

val currentWeekYBobs: FloatArray?
get() = _currentWeekYBobs.value

val currentWeekYSnacks: FloatArray?
get() = _currentWeekYSnacks.value

val currentMonthXGroups: LiveData<ArrayList<String>>
get() = _currentMonthXGroups

val currentMonthDate: LiveData<String>
get() = _currentMonthDate

val currentMonthYBobs: FloatArray?
get() = _currentMonthYBobs.value

val currentMonthYSnacks: FloatArray?
get() = _currentMonthYSnacks.value

fun updateChart(xGroups: ArrayList<String>, yBobs: FloatArray, ySnacks: FloatArray, type: String) {
when(type) {
"week" -> {
_currentWeekYBobs.value = yBobs
_currentWeekYSnacks.value = ySnacks
_currentWeekXGroups.value = xGroups // 마지막에 위치시킴
}
"month" -> {
_currentMonthYBobs.value = yBobs
_currentMonthYSnacks.value = ySnacks
_currentMonthXGroups.value = xGroups
}
}

}

fun updateDate(input: String, type: String) {
if (type == "week") _currentWeekDate.value = input
else if (type == "month") _currentMonthDate.value = input
}
}
Loading

0 comments on commit de8bac2

Please sign in to comment.