Skip to content

Commit

Permalink
[FEAT] #4 - 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jinsilWoo committed May 21, 2022
2 parents 157f112 + fc00902 commit e031337
Show file tree
Hide file tree
Showing 51 changed files with 921 additions and 41 deletions.
39 changes: 32 additions & 7 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.sopt.sopkathon5.andorid.data.model
package org.sopt.sopkathon5.andorid.data

import org.sopt.sopkathon5.andorid.data.service.MyPageService
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ServiceCreator {
private const val BASE_URL = "https://asia-northeast3-we-sopt-29.cloudfunctions.net/api/"
private const val BASE_URL = "54.180.144.204:5001/"

private val retrofit: Retrofit = Retrofit
.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()

val myPageService = retrofit.create(MyPageService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.sopkathon5.andorid.data.model.request

data class RequestMissionCheck(
val _id: String,
val userId: Int,
val dailyId: String,
val completeMissions: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.sopt.sopkathon5.andorid.data.model.response

data class ResponseStoreDaily(
val status: Int,
val success: Boolean,
val message: String,
val data: List<Data>
) {
data class Data(
val _id: String,
val userId: Int,
val userName: String,
val dailyId: String,
val completeMissions: List<List<String>>,
val __v: Int
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.sopkathon5.andorid.data.service

interface ApiService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.sopkathon5.andorid.data.service

import org.sopt.sopkathon5.andorid.data.model.response.ResponseStoreDaily
import retrofit2.Call
import retrofit2.http.GET

interface MyPageService {
@GET("daily/1")
fun getStoredDaily(): Call<ResponseStoreDaily>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@ import androidx.recyclerview.widget.RecyclerView
import org.sopt.sopkathon5.andorid.R
import org.sopt.sopkathon5.andorid.data.model.DailyData
import org.sopt.sopkathon5.andorid.databinding.ItemDailyListBinding
import kotlin.math.log

class DailyAdapter : RecyclerView.Adapter<DailyAdapter.DailyViewHolder>() {
class DailyAdapter(private val itemClick: (() -> (Unit))? = null, private val logoutClickListener: (() -> Unit)? = null) : RecyclerView.Adapter<DailyAdapter.DailyViewHolder>() {
val itemList = mutableListOf<DailyData>()

class DailyViewHolder(private val binding: ItemDailyListBinding) :
class DailyViewHolder(
private val binding: ItemDailyListBinding,
private val itemClick: (() -> Unit)?
) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: DailyData) {
fun onBind(data: DailyData, logoutClickListener: (() -> Unit)?) {
binding.data = data
binding.tvLogout.setOnClickListener {
logoutClickListener?.invoke()
}
val todoAdapter = TodoAdapter()
binding.rvTodo.adapter = todoAdapter

binding.btnPoint.setOnClickListener { //호출시 itemclick 람다함수실행함
itemClick?.invoke()
}
}
}

Expand All @@ -27,11 +38,11 @@ class DailyAdapter : RecyclerView.Adapter<DailyAdapter.DailyViewHolder>() {
parent,
false
)
return DailyViewHolder(binding)
return DailyViewHolder(binding, itemClick)
}

override fun onBindViewHolder(holder: DailyViewHolder, position: Int) {
holder.onBind(itemList[position])
holder.onBind(itemList[position], logoutClickListener)
}

override fun getItemCount(): Int = itemList.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initAdapter()
initNetwork()
}

private fun initAdapter(){
detailAdapter = DailyAdapter()
binding.rvDaily.adapter = detailAdapter

detailAdapter.itemList.addAll(
listOf(
DailyData("sdfs"),
DailyData("ddfsdfs"),
DailyData("sfs")
)
)
detailAdapter.notifyDataSetChanged()

}
private fun initNetwork(){

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.sopt.sopkathon5.andorid.ui.mypage

import android.os.Bundle
import android.view.View
import org.sopt.sopkathon5.andorid.R
import org.sopt.sopkathon5.andorid.databinding.FragmentMyDailyBinding
import org.sopt.sopkathon5.andorid.ui.home.DailyAdapter
import org.sopt.sopkathon5.andorid.ui.mypage.adapter.MyPageTodoCheckAdapter
import org.sopt.sopkathon5.andorid.util.base.BaseFragment

class MyDailyFragment : BaseFragment<FragmentMyDailyBinding>(R.layout.fragment_my_daily) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initAdapter()
}

private fun initAdapter() {
binding.rvMyDaily.adapter = DailyAdapter().apply {

}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,72 @@
package org.sopt.sopkathon5.andorid.ui.mypage

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.databinding.DataBindingUtil
import org.sopt.sopkathon5.andorid.R
import org.sopt.sopkathon5.andorid.databinding.FragmentMyPageBinding
import org.sopt.sopkathon5.andorid.databinding.LayoutCompleteDialogBinding
import org.sopt.sopkathon5.andorid.ui.mypage.adapter.MyPageViewPagerAdapter
import org.sopt.sopkathon5.andorid.util.DialogUtil
import org.sopt.sopkathon5.andorid.util.base.BaseFragment

class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_page) {
private lateinit var completeDialog: Dialog
private lateinit var layoutCompleteDialogBinding: LayoutCompleteDialogBinding

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.tvMyDaily.isSelected = true
initDialogBinding()
initDialog()
initViewPager()
}

private fun initViewPager() {
with(binding) {
vpMypage.adapter = MyPageViewPagerAdapter(requireActivity()).apply {
fragmentList = listOf(
MyDailyFragment(),
YourDailyFragment()
)
}

vpMypage.isUserInputEnabled = false

tvMyDaily.setOnClickListener {
it.isSelected = true
tvYourDaily.isSelected = false
binding.vpMypage.currentItem = 0
}

tvYourDaily.setOnClickListener {
it.isSelected = true
tvMyDaily.isSelected = false
binding.vpMypage.currentItem = 1
}
}
}

private fun initDialogBinding() {
layoutCompleteDialogBinding = DataBindingUtil.inflate(
LayoutInflater.from(requireContext()),
R.layout.layout_complete_dialog,
null,
false
)
}

private fun initDialog() {
requireContext().apply {
completeDialog = DialogUtil.makeDialog(this)
}

layoutCompleteDialogBinding.btnComplete.setOnClickListener {
completeDialog.dismiss()
}

DialogUtil.setDialog(completeDialog, layoutCompleteDialogBinding.root)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.sopt.sopkathon5.andorid.ui.mypage

import android.os.Bundle
import android.view.View
import org.sopt.sopkathon5.andorid.R
import org.sopt.sopkathon5.andorid.databinding.FragmentYourDailyBinding
import org.sopt.sopkathon5.andorid.util.base.BaseFragment

class YourDailyFragment : BaseFragment<FragmentYourDailyBinding>(R.layout.fragment_your_daily) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
with(binding) {
layoutDaily.isBookmarkNotVisible = true
layoutDaily.isLogoutVisible = true
}
}

private fun initAdapter() {
binding.rvDone.adapter
binding.layoutDaily.rvTodo.adapter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.sopt.sopkathon5.andorid.ui.mypage.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import org.sopt.sopkathon5.andorid.R
import org.sopt.sopkathon5.andorid.databinding.ItemTodoCheckBinding

class MyPageTodoCheckAdapter :
RecyclerView.Adapter<MyPageTodoCheckAdapter.MyPageTodoCheckViewHolder>() {
private val _data = mutableListOf<String>()
var data: List<String> = _data
set(value) {
_data.clear()
_data.addAll(value)
notifyDataSetChanged()
}

class MyPageTodoCheckViewHolder(
private val binding: ItemTodoCheckBinding
) : RecyclerView.ViewHolder(
binding.root
) {
fun onBind(data: String) {
with(binding) {
tvTodo.text = data
ibCheck.isSelected = !ibCheck.isSelected
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyPageTodoCheckViewHolder {
val binding: ItemTodoCheckBinding = DataBindingUtil.inflate(
LayoutInflater.from(parent.context),
R.layout.item_todo_check, parent, false
)
return MyPageTodoCheckViewHolder(binding)
}

override fun onBindViewHolder(holder: MyPageTodoCheckViewHolder, position: Int) {
holder.onBind(_data[position])
}

override fun getItemCount(): Int = _data.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.sopkathon5.andorid.ui.mypage.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter

class MyPageViewPagerAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {
private val _fragmentList = mutableListOf<Fragment>()
var fragmentList: List<Fragment> = _fragmentList
set(value) {
_fragmentList.addAll(value)
}

override fun getItemCount(): Int = _fragmentList.size
override fun createFragment(position: Int): Fragment = _fragmentList[position]
}
26 changes: 26 additions & 0 deletions app/src/main/java/org/sopt/sopkathon5/andorid/util/DialogUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.sopt.sopkathon5.andorid.util

import android.app.Dialog
import android.content.Context
import android.view.View
import android.view.Window
import android.view.WindowManager
import org.sopt.sopkathon5.andorid.R

object DialogUtil {
fun makeDialog(context: Context) = Dialog(context, R.style.CompleteDialogStyle)

fun setDialog(dialog: Dialog, view: View) {
dialog.apply {
requestWindowFeature(Window.FEATURE_NO_TITLE)
setCancelable(false)
setContentView(view)

with(window?.attributes) {
this?.width = WindowManager.LayoutParams.MATCH_PARENT
this?.height = WindowManager.LayoutParams.WRAP_CONTENT
this?.verticalWeight = 1F
}
}
}
}
Loading

0 comments on commit e031337

Please sign in to comment.