Skip to content

Commit

Permalink
[FEAT] #8 - 홈 > 오늘의 실천 사항 / [FIX] #6 - 교육 탭 Error 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Aug 5, 2023
1 parent f7ec3f8 commit 7bfbe7f
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class SignUpActivity : AppCompatActivity() {

GloabalApplication.prefs.setString("accessToken", accessToken)
GloabalApplication.prefs.setString("refreshToken", refreshToken)
GloabalApplication.prefs.setString("name", name!!)

val intent = Intent(this, DoneSignUpActivity::class.java)
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ssjm.sw_hackathon.education

import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
Expand Down Expand Up @@ -28,6 +29,17 @@ class EducationFragment : Fragment() {
lateinit var viewPagers: ViewPager
lateinit var tabLayouts: TabLayout

override fun onResume() {
super.onResume()

// 서울시 어르신 취업지원센터 교육정보 개수 조회
apiGetEducationCount(
addEducationCount = {
addEducationCount(it)
}
)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/com/ssjm/sw_hackathon/goalApi/GoalApiUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ssjm.sw_hackathon.goalApi

import android.content.ContentValues
import android.util.Log
import com.ssjm.sw_hackathon.apiClient.ApiClient
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTask
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTasksResponse
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTasksService
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import java.time.LocalDate

// api 통신을 위한 retrofit
private val retrofit: Retrofit = ApiClient.getInstance()

fun apiGetDailyTasks(
date: LocalDate,
setDailyTask: (dailyTasks: MutableList<GetDailyTask>) -> Unit
) {
retrofit.create(GetDailyTasksService::class.java)
.getDailyTasksGoal(date = date)
.enqueue(object : Callback<GetDailyTasksResponse> {
override fun onResponse(call: Call<GetDailyTasksResponse>, response: Response<GetDailyTasksResponse>) {
Log.d(ContentValues.TAG, "daily 실천 사항 조회 결과 -------------------------------------------")
Log.d(ContentValues.TAG, "onResponse: ${response.body().toString()}")

if(response.body() != null) {
setDailyTask(response.body()!!.data)
}
}

override fun onFailure(call: Call<GetDailyTasksResponse>, t: Throwable) {
Log.d(ContentValues.TAG, "daily 실천 사항 조회 결과 fail -------------------------------------------")
Log.e(ContentValues.TAG, "onFailure: ${t.message}")
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ssjm.sw_hackathon.goalApi.getDailyTasks

import com.google.gson.annotations.SerializedName

data class GetDailyTasksResponse(
@SerializedName("success")
val success: Boolean,

@SerializedName("code")
val code: Int,

@SerializedName("message")
val message: String,

@SerializedName("data")
val data: MutableList<GetDailyTask>,
)

data class GetDailyTask(
@SerializedName("id")
val id: Int,

@SerializedName("name")
val name: String,

@SerializedName("days")
val days: MutableList<String>,

@SerializedName("status")
val status: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ssjm.sw_hackathon.goalApi.getDailyTasks

import com.ssjm.sw_hackathon.token.GloabalApplication
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Path
import retrofit2.http.Query
import java.time.LocalDate

private var accessTokenValue: String = "Bearer " + GloabalApplication.prefs.getString("accessToken", "")
private var refreshTokenValue: String = GloabalApplication.prefs.getString("refreshToken", "")
private var goalIdValue: Int = GloabalApplication.prefs.getInt("goalId", 0)

interface GetDailyTasksService {
@GET("goals/{goal_id}/daily-tasks")
fun getDailyTasksGoal(
@Header("Authorization") authorization: String = accessTokenValue, // 로그인으로 발급받은 AccessToken: JWT {발급받은 토큰} 형태로 입력
@Header("refresh-token") refreshToken: String = refreshTokenValue, // 로그인으로 발급받은 RefreshToken
@Path("goal_id") goalId: Int = goalIdValue,
@Query("date") date: LocalDate
): Call<GetDailyTasksResponse>
}
45 changes: 43 additions & 2 deletions app/src/main/java/com/ssjm/sw_hackathon/home/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.ssjm.sw_hackathon.home

import android.os.Build
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.navigation.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.ssjm.sw_hackathon.R
Expand All @@ -14,8 +16,12 @@ import com.ssjm.sw_hackathon.education.recycler.EducationItem
import com.ssjm.sw_hackathon.education.recycler.EducationItemInterface
import com.ssjm.sw_hackathon.educationApi.EducationRow
import com.ssjm.sw_hackathon.educationApi.apiGetEducationInfo
import com.ssjm.sw_hackathon.goalApi.apiGetDailyTasks
import com.ssjm.sw_hackathon.goalApi.getDailyTasks.GetDailyTask
import com.ssjm.sw_hackathon.home.recycler.HomeTodoAdapter
import com.ssjm.sw_hackathon.home.recycler.HomeTodoItem
import com.ssjm.sw_hackathon.token.GloabalApplication
import java.time.LocalDate

// 메인 탭
class HomeFragment : Fragment() {
Expand All @@ -33,6 +39,9 @@ class HomeFragment : Fragment() {
// RecyclerView Adapter
private lateinit var educationAdapter: EducationAdapter

// 커버 이미지
private var coverImages: MutableList<String> = mutableListOf("note1", "barista2", "note2", "barista1")

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -42,13 +51,29 @@ class HomeFragment : Fragment() {
return binding.root
}

@RequiresApi(Build.VERSION_CODES.O)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// 목표, 이름 설정
var name: String = GloabalApplication.prefs.getString("name", "")
var goal: String = GloabalApplication.prefs.getString("goal", "")

binding.textName.text = name
binding.textName2.text = name
binding.textJob.text = goal

initRecycler()

addTodo(HomeTodoItem("note1", "노트에 필사하기", "66일째 실천중", mutableListOf("", "")))
addTodo(HomeTodoItem("barista2", "실기 학원", "32일째 실천중", mutableListOf("", "")))
//addTodo(HomeTodoItem("note1", "노트에 필사하기", "66일째 실천중", mutableListOf("월", "수")))
//addTodo(HomeTodoItem("barista2", "실기 학원", "32일째 실천중", mutableListOf("화", "목")))

apiGetDailyTasks(
LocalDate.now().minusDays(1),
setDailyTask = {
setDailyTasks(it)
}
)

apiGetEducationInfo(
20,
Expand Down Expand Up @@ -91,6 +116,22 @@ class HomeFragment : Fragment() {
homeTodoAdapter.notifyDataSetChanged()
}

// 오늘의 할 일 받아와서 세팅
private fun setDailyTasks(tasks: MutableList<GetDailyTask>) {
binding.textTodoCount.text = "(" + tasks.size.toString() + ")"

for(i: Int in 0..(tasks.size - 1)) {
addTodo(
HomeTodoItem(
coverImages[i],
tasks[i].name,
"1일째 실천중",
tasks[i].days
)
)
}
}

private fun addEducationItems(educationItems: MutableList<EducationRow>?) {
if(educationItems != null) {
for(education in educationItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class ThirdOnBoardFragment : Fragment() {
private fun saveGoalAndTask(goalId: Int) {
Log.d("Test", "----------------------------------------------------------")

GloabalApplication.prefs.setString("goal", goal!!)
GloabalApplication.prefs.setInt("goalId", goalId)

activity?.setFragment(EndOnBoardFragment())
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7bfbe7f

Please sign in to comment.