Skip to content

Commit

Permalink
[FEAT/#20] 점호 리스트 조회 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Aug 16, 2022
1 parent f2a8e3d commit ea6352c
Show file tree
Hide file tree
Showing 19 changed files with 499 additions and 256 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}

Properties properties = new Properties()
Expand Down Expand Up @@ -47,6 +48,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-messaging-ktx:23.0.7'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand All @@ -71,4 +73,9 @@ dependencies {

// swipe refresh layout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

// firebase
implementation platform('com.google.firebase:firebase-bom:30.3.2')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-messaging:23.0.7'
}
81 changes: 51 additions & 30 deletions app/src/main/java/kr/co/sujungvillage_admin/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import kr.co.sujungvillage_admin.base.hideKeyboard
import kr.co.sujungvillage_admin.data.LoginDTO
import kr.co.sujungvillage_admin.data.LoginResultDTO
Expand Down Expand Up @@ -47,40 +49,59 @@ class LoginActivity : AppCompatActivity() {
return@setOnClickListener
}

// 관리자 로그인 API 연결
var loginInfo = LoginDTO(binding.editId.text.toString(), binding.editPassword.text.toString())
RetrofitBuilder.loginApi.login(loginInfo).enqueue(object: Callback<LoginResultDTO> {
override fun onResponse(call: Call<LoginResultDTO>, response: Response<LoginResultDTO>) {
Log.d("LOGIN", "로그인 성공")
Log.d("LOGIN", "response : " + response.body().toString())
// FCM 토큰 발급
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.d("FCM_TOKEN", "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}

// 로컬에 아이디, 토큰 저장
val editor = shared.edit()
editor.putString("id", binding.editId.text.toString())
editor.putString("token", response.body()?.token)
// Get new FCM registration token
val token = task.result

// 기본 정보를 기억하는 경우
if (binding.checkAutoLogin.isChecked) {
editor.putBoolean("autoLogin", true)
editor.putString("loginID", binding.editId.text.toString())
editor.putString("loginPassword", binding.editPassword.text.toString())
}
// 기본 정보를 기억하지 않는 경우
else {
editor.putBoolean("autoLogin", false)
}
editor.apply()
// Log and toast
val msg = token.toString()
Log.d("FCM_TOKEN", msg)

var intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
Toast.makeText(this@LoginActivity, "로그인되었습니다.", Toast.LENGTH_SHORT).show()
finish()
}
// 관리자 로그인 API 연결
var loginInfo = LoginDTO(binding.editId.text.toString(), binding.editPassword.text.toString(), msg)
RetrofitBuilder.loginApi.login(loginInfo).enqueue(object : Callback<LoginResultDTO> {
override fun onResponse(call: Call<LoginResultDTO>, response: Response<LoginResultDTO>) {
Log.d("LOGIN", "로그인 성공")
Log.d("LOGIN", "response : " + response.body().toString())

override fun onFailure(call: Call<LoginResultDTO>, t: Throwable) {
Log.e("LOGIN", "로그인 실패")
Log.e("LOGIN", t.message.toString())
}
// 로컬에 아이디, 토큰 저장
val editor = shared.edit()
editor.putString("id", binding.editId.text.toString())
editor.putString("token", response.body()?.token)

// 기본 정보를 기억하는 경우
if (binding.checkAutoLogin.isChecked) {
editor.putBoolean("autoLogin", true)
editor.putString("loginID", binding.editId.text.toString())
editor.putString(
"loginPassword",
binding.editPassword.text.toString()
)
}
// 기본 정보를 기억하지 않는 경우
else {
editor.putBoolean("autoLogin", false)
}
editor.apply()

var intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
Toast.makeText(this@LoginActivity, "로그인되었습니다.", Toast.LENGTH_SHORT)
.show()
finish()
}

override fun onFailure(call: Call<LoginResultDTO>, t: Throwable) {
Log.e("LOGIN", "로그인 실패")
Log.e("LOGIN", t.message.toString())
}
})
})
}
}
Expand Down
54 changes: 54 additions & 0 deletions app/src/main/java/kr/co/sujungvillage_admin/RollCallActivity.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,72 @@
package kr.co.sujungvillage_admin

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.prolificinteractive.materialcalendarview.CalendarDay
import kr.co.sujungvillage_admin.adapter.RollcallAdapter
import kr.co.sujungvillage_admin.data.RollcallGetListResultDTO
import kr.co.sujungvillage_admin.databinding.ActivityCommWriteBinding
import kr.co.sujungvillage_admin.databinding.ActivityRollCallBinding
import kr.co.sujungvillage_admin.retrofit.RetrofitBuilder
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class RollCallActivity : AppCompatActivity() {
val binding by lazy { ActivityRollCallBinding.inflate(layoutInflater) }

companion object {
var selectedRollcall: MutableList<Long> = mutableListOf()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)

// 로컬에서 토큰 불러오기
val shared = this.getSharedPreferences("SujungVillage_Admin", Context.MODE_PRIVATE)
val token = shared?.getString("token", "error").toString()

// 대기 중인 점호 리스트 불러오기
loadRollcallData(token)

// 뒤로가기 버튼 연결
binding.btnBack.setOnClickListener{ finish() }
}

// 점호 신청 리스트 불러오기 함수
fun loadRollcallData(token: String) {
// 점호 신청 리스트 조회 API 연결 (★★★ 대기 중인 점호 리스트로 수정하기)
RetrofitBuilder.rollcallApi.rollcallGetList(token, CalendarDay.today().date.plusDays(-1).toString(), "대기").enqueue(object: Callback<List<RollcallGetListResultDTO>> {
override fun onResponse(call: Call<List<RollcallGetListResultDTO>>, response: Response<List<RollcallGetListResultDTO>>) {
Log.d("ROLLCALL_LIST_REQUEST", "점호 신청 리스트 조회 성공")
Log.d("ROLLCALL_LIST_REQUEST", response.body().toString())

if (response.body()?.size == 0) {
binding.textExist.visibility = View.VISIBLE
} else {
binding.textExist.visibility = View.GONE
}

var rollcallList: MutableList<RollcallGetListResultDTO> = mutableListOf()
for (info in response.body()!!) {
rollcallList.add(RollcallGetListResultDTO(info.id, info.userId, info.userName, info.dormitory, info.address, info.image, info.location, info.date, info.state))
}
val adapter = RollcallAdapter()
adapter.rollcallList = rollcallList
binding.recycleRollcall.adapter = adapter
binding.recycleRollcall.layoutManager = LinearLayoutManager(this@RollCallActivity)
}

override fun onFailure(call: Call<List<RollcallGetListResultDTO>>, t: Throwable) {
Log.e("ROLLCALL_LIST_REQUEST", "점호 신청 리스트 조회 실패")
Log.e("ROLLCALL_LIST_REQUEST", t.message.toString())
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kr.co.sujungvillage_admin.data.CommDTO
import kr.co.sujungvillage_admin.databinding.ListitemCommBinding
import kr.co.sujungvillage_admin.fragment.CommFragment

class commAdapter : RecyclerView.Adapter<CommHolder>() {
class CommAdapter : RecyclerView.Adapter<CommHolder>() {
var commList = mutableListOf<CommDTO>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommHolder {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package kr.co.sujungvillage_admin.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import kr.co.sujungvillage_admin.R
import kr.co.sujungvillage_admin.RollCallActivity.Companion.selectedRollcall
import kr.co.sujungvillage_admin.base.toBitmap
import kr.co.sujungvillage_admin.data.RollcallGetListResultDTO
import kr.co.sujungvillage_admin.databinding.ListitemRollcallBinding

class RollcallAdapter : RecyclerView.Adapter<RollcallHolder>() {
var rollcallList= mutableListOf<RollcallGetListResultDTO>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RollcallHolder {
val binding = ListitemRollcallBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return RollcallHolder(binding)
}

override fun onBindViewHolder(holder: RollcallHolder, position: Int) {
val rollcall = rollcallList.get(position)
holder.setRollcall(rollcall)
}

override fun getItemCount(): Int {
return rollcallList.size
}
}

class RollcallHolder(val binding: ListitemRollcallBinding): RecyclerView.ViewHolder(binding.root) {
fun setRollcall(rollcall: RollcallGetListResultDTO) {
binding.imgRollcall.setImageBitmap(rollcall.image.toBitmap())
binding.textName.text = "이름 : ${rollcall.userName}"
binding.textStudentNum.text = "학번 : ${rollcall.userId}"
binding.textDormitory.text = "기숙사 : ${rollcall.dormitory} ${rollcall.address}"
binding.textLocation.text = "위치 : ${rollcall.location}"

// 점호를 선택한 경우
binding.root.setOnClickListener {
// 이미 선택한 점호인 경우
if (selectedRollcall.contains(rollcall.id)) {
selectedRollcall.remove(rollcall.id)
binding.layout.setBackgroundColor(ContextCompat.getColor(itemView.context, R.color.green_200))
}
// 선택되지 않은 점호인 경우
else {
selectedRollcall.add(rollcall.id)
binding.layout.setBackgroundColor(ContextCompat.getColor(itemView.context, R.color.green_200))
}
}
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/kr/co/sujungvillage_admin/api/RollcallService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kr.co.sujungvillage_admin.api
import kr.co.sujungvillage_admin.data.RollcallCreateDTO
import kr.co.sujungvillage_admin.data.RollcallCreateResultDTO
import kr.co.sujungvillage_admin.data.RollcallGetDateResultDTO
import kr.co.sujungvillage_admin.data.RollcallGetListResultDTO
import retrofit2.Call
import retrofit2.http.*

Expand All @@ -20,4 +21,27 @@ interface RollcallService {
@Header("jwt_token") token: String,
@Body rollcallInfo: RollcallCreateDTO,
): Call<RollcallCreateResultDTO>

// 점호일 삭제
@DELETE("/api/admin/rollcall/deleteRollcallDate")
fun rollcallDelete(
@Header("jwt_token") token: String,
@Query("rollcallDateId") rollcallId: Long,
): Call<Void>

// 점호 신청 리스트 조회
@GET("/api/admin/rollcall/getRollcallList")
fun rollcallGetList(
@Header("jwt_token") token: String,
@Query("date") date: String,
@Query("state") state: String,
): Call<List<RollcallGetListResultDTO>>

// 점호 상태 변경
@PATCH("/api/admin/rollcall/changeRollcallState")
fun rollcallChange(
@Header("jwt_token") token: String,
@Query("rollcallId") rollcallId: Long,
@Query("state") state: String,
): Call<Void>
}
Loading

0 comments on commit ea6352c

Please sign in to comment.