Skip to content

Commit

Permalink
[FEAT/#9, #11] 홈 화면 정보 조회 API 연결 및 캘린더 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Aug 7, 2022
1 parent 8c6a6bc commit 05a939b
Show file tree
Hide file tree
Showing 32 changed files with 306 additions and 17 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0' // 레트로핏 설치 (필수)
implementation 'com.squareup.retrofit2:converter-gson:2.9.0' // 컨버터 (선택)
implementation 'com.google.code.gson:gson:2.9.1' //GSON (선택)

// material-calendarview
implementation 'com.github.prolificinteractive:material-calendarview:2.0.1'
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.0'
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/ic_main"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/ic_main_round"
android:supportsRtl="true"
android:theme="@style/Theme.SujungVillageAdmin"
tools:targetApi="31">
Expand Down
Binary file added app/src/main/ic_main-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions app/src/main/java/kr/co/sujungvillage_admin/api/HomeService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kr.co.sujungvillage_admin.api

import kr.co.sujungvillage_admin.retrofit.HomeInfoResultDTO
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

interface HomeService {
// 관리자 홈 화면 정보 조회
@GET("/api/admin/home_info")
fun homeInfo(
@Header("user_id") userId: String,
@Query("year") year: String,
@Query("month") month: String,
): Call<HomeInfoResultDTO>
}
20 changes: 20 additions & 0 deletions app/src/main/java/kr/co/sujungvillage_admin/data/Home.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kr.co.sujungvillage_admin.retrofit

import com.google.gson.annotations.SerializedName
import java.io.Serializable

data class HomeInfoResultDTO(
@SerializedName("adminInfo")
val adminInfo: HomeAdminInfo,
@SerializedName("rollcallDays")
val rollcallDays: List<Int>,
): Serializable {}

data class HomeAdminInfo(
@SerializedName("name")
val name: String,
@SerializedName("dormitoryName")
val dormitory: String,
@SerializedName("description")
val description: String,
): Serializable {}
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
package kr.co.sujungvillage_admin.fragment

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.text.style.ForegroundColorSpan
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.prolificinteractive.materialcalendarview.CalendarDay
import com.prolificinteractive.materialcalendarview.DayViewDecorator
import com.prolificinteractive.materialcalendarview.DayViewFacade
import kr.co.sujungvillage_admin.AlarmActivity
import kr.co.sujungvillage_admin.NoticeActivity
import kr.co.sujungvillage_admin.R
import kr.co.sujungvillage_admin.RollCallActivity
import kr.co.sujungvillage_admin.databinding.FragmentHomeBinding
import kr.co.sujungvillage_admin.retrofit.HomeInfoResultDTO
import kr.co.sujungvillage_admin.retrofit.RetrofitBuilder
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class HomeFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding = FragmentHomeBinding.inflate(inflater, container, false)

// ★★★ 재사생 학번 불러오기
val userNum = "99990001"

// lottie 이미지 회전
binding.imgWave.rotationX = 180f

// 알림 버튼 연결
binding.btnAlarm.setOnClickListener {
var intent = Intent(this.activity, AlarmActivity::class.java)
startActivity(intent)
}

// 홈화면 주요 기능 버튼 연결
// 1. 공지사항 버튼 연결
Expand All @@ -29,13 +48,81 @@ class HomeFragment : Fragment() {
}
// 2. 상벌점 관리 버튼 연결
// 3. 점호 확인 버튼 연결
// 4. 재사생 관리 버튼 연결
// 5. 알람 버튼 연결
binding.btnAlarm.setOnClickListener {
var intent = Intent(this.activity, AlarmActivity::class.java)
binding.btnRollcall.setOnClickListener {
var intent = Intent(this.activity, RollCallActivity::class.java)
startActivity(intent)
}
// 4. 재사생 관리 버튼 연결

// 관리자 홈 화면 정보 조회 API 연결
RetrofitBuilder.homeApi.homeInfo(userNum, binding.calendar.currentDate.year.toString(), binding.calendar.currentDate.month.toString()).enqueue(object : Callback<HomeInfoResultDTO> {
override fun onResponse(call: Call<HomeInfoResultDTO>, response: Response<HomeInfoResultDTO>) {
Log.d("HOME_INFO", "홈 화면 정보 조회 성공")
Log.d("HOME_INFO", "user : " + response.body()?.adminInfo.toString())
Log.d("HOME_INFO", "roll-call days : " + response.body()?.rollcallDays.toString())

// 유저 정보 반영
binding.textName.text = response.body()?.adminInfo?.name
binding.textDormitory.text =
response.body()?.adminInfo?.dormitory + " 기숙사 " + response.body()?.adminInfo?.description + " 담당"

// 캘린더 정보 반영
val rollcallDecorator = RollcallDecorator(this@HomeFragment, response.body()!!.rollcallDays)
val todayDecorator = TodayDecorator(this@HomeFragment)
binding.calendar.addDecorators(rollcallDecorator, todayDecorator)
}

override fun onFailure(call: Call<HomeInfoResultDTO>, t: Throwable) {
Log.d("HOME_INFO", "홈 화면 정보 조회 실패")
Log.d("HOME_INFO", t.message.toString())
}
})

// 캘린더 좌우 버튼 연결
binding.calendar.setOnMonthChangedListener { widget, date ->
RetrofitBuilder.homeApi.homeInfo(userNum, date.year.toString(), date.month.toString()).enqueue(object : Callback<HomeInfoResultDTO> {
override fun onResponse(call: Call<HomeInfoResultDTO>, response: Response<HomeInfoResultDTO>) {
Log.d("HOME_INFO", "캘린더 정보 조회 성공")
Log.d("HOME_INFO", "roll-call days : " + response.body()?.rollcallDays.toString())

// 캘린더 정보 반영
val rollcallDecorator = RollcallDecorator(this@HomeFragment, response.body()!!.rollcallDays)
val todayDecorator = TodayDecorator(this@HomeFragment)
binding.calendar.addDecorators(rollcallDecorator, todayDecorator)
}

override fun onFailure(call: Call<HomeInfoResultDTO>, t: Throwable) {
Log.d("HOME_INFO", "캘린더 정보 조회 실패")
Log.d("HOME_INFO", t.message.toString())
}
})
}

return binding.root
}
}

// 점호일 커스텀 함수
class RollcallDecorator(context: HomeFragment, days: List<Int>) : DayViewDecorator {
val rollcallDrawable = context.resources.getDrawable(R.drawable.style_home_cal_rollcall)
val days = days

override fun shouldDecorate(day: CalendarDay?): Boolean { // 커스텀 여부 반환
return days.contains(day?.day)
}

override fun decorate(view: DayViewFacade?) { // 커스텀 설정
view?.setBackgroundDrawable(rollcallDrawable)
}
}

// 오늘 커스텀 함수
class TodayDecorator(context: HomeFragment) : DayViewDecorator {
override fun shouldDecorate(day: CalendarDay?): Boolean { // 커스텀 여부 반환
return return day?.equals(CalendarDay.today())!!
}

override fun decorate(view: DayViewFacade?) { // 커스텀 설정
view?.addSpan(object : ForegroundColorSpan(Color.parseColor("#FF9AE000")) {})
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
package kr.co.sujungvillage_admin.fragment

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kr.co.sujungvillage_admin.AlarmActivity
import kr.co.sujungvillage_admin.R
import kr.co.sujungvillage_admin.databinding.FragmentSettingBinding
import kr.co.sujungvillage_admin.retrofit.HomeInfoResultDTO
import kr.co.sujungvillage_admin.retrofit.RetrofitBuilder
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class SettingFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding = FragmentSettingBinding.inflate(inflater, container, false)

// ★★★ 재사생 학번 불러오기
val userNum = "99990001"

// 알림 버튼 연결
binding.btnAlarm.setOnClickListener {
var intent = Intent(this.activity, AlarmActivity::class.java)
startActivity(intent)
}

// 설정 화면 정보 조회 API 연결 (홈 화면 정보 조회 API 활용)
RetrofitBuilder.homeApi.homeInfo(userNum, "2022", "8").enqueue(object : Callback<HomeInfoResultDTO> {
override fun onResponse(call: Call<HomeInfoResultDTO>, response: Response<HomeInfoResultDTO>) {
Log.d("HOME_INFO", "설정 화면 정보 조회 성공")
Log.d("HOME_INFO", "user : " + response.body()?.adminInfo.toString())

// 유저 정보 반영
binding.textName.text = response.body()?.adminInfo?.name
binding.textCharge.text = "담당 : " + response.body()?.adminInfo?.dormitory + " " + response.body()?.adminInfo?.description
}

override fun onFailure(call: Call<HomeInfoResultDTO>, t: Throwable) {
Log.d("HOME_INFO", "홈 화면 정보 조회 실패")
Log.d("HOME_INFO", t.message.toString())
}
})

return binding.root
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package kr.co.sujungvillage_admin.retrofit

import com.google.gson.GsonBuilder
import kr.co.sujungvillage_admin.BuildConfig.BASE_URL
import kr.co.sujungvillage_admin.api.HomeService
import kr.co.sujungvillage_admin.api.NoticeService
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitBuilder {
// 사용할 API 인터페이스 선언
var noticeApi: NoticeService
var homeApi: HomeService

val gson = GsonBuilder().setLenient().create()

Expand All @@ -20,5 +22,6 @@ object RetrofitBuilder {
.build()

noticeApi = retrofit.create(NoticeService::class.java)
homeApi = retrofit.create(HomeService::class.java)
}
}
74 changes: 74 additions & 0 deletions app/src/main/res/drawable/ic_main_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/style_home_cal_rollcall.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="8.5dp"
android:bottom="8.5dp"
android:right="8.5dp"
android:left="8.5dp">
<shape>
<solid android:color="#CCD9F17B" />
<corners android:radius="100dp" />
</shape>
</item>
</layer-list>
Loading

0 comments on commit 05a939b

Please sign in to comment.