Skip to content

Commit

Permalink
[FEAT] #8 - 홈 > 실천 사항 리스트
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Aug 4, 2023
1 parent 395d141 commit 0785f6e
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager

import com.ssjm.sw_hackathon.databinding.FragmentEduBookmarkBinding
import com.ssjm.sw_hackathon.education.recycler.EducationAdapter
import com.ssjm.sw_hackathon.education.recycler.EducationItem
import com.ssjm.sw_hackathon.education.recycler.EducationItemInterface

// 교육 > 찜
Expand Down Expand Up @@ -40,6 +41,8 @@ class EduBookmarkFragment : Fragment() {

// recyclerview 세팅
initRecycler()


}

// 교육 아이템 recyclerview 세팅
Expand All @@ -54,6 +57,11 @@ class EduBookmarkFragment : Fragment() {
educationAdapter.items = bookmarkEducationItems!!
}

private fun addEdu(edu: EducationItem) {
bookmarkEducationItems!!.add(edu)
educationAdapter.notifyDataSetChanged()
}

override fun onDestroy() {
super.onDestroy()
_binding = null
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/ssjm/sw_hackathon/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.ssjm.sw_hackathon.databinding.FragmentHomeBinding
import com.ssjm.sw_hackathon.home.recycler.HomeTodoAdapter
import com.ssjm.sw_hackathon.home.recycler.HomeTodoItem

// 메인 탭
class HomeFragment : Fragment() {
// ViewBinding Setting
private var _binding: FragmentHomeBinding? = null
private val binding get() = _binding!!

// 실천 리스트 recyclerview adapter
private var homeTodoItems: MutableList<HomeTodoItem>? = null
private lateinit var homeTodoAdapter: HomeTodoAdapter

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -24,6 +31,30 @@ class HomeFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initRecycler()

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

// recyclerview 세팅
private fun initRecycler() {
homeTodoItems = mutableListOf<HomeTodoItem>()

// 링크 리스트 recyclerview 세팅
homeTodoAdapter = HomeTodoAdapter(
requireContext()
)
binding.recyclerviewHomeTodo.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
binding.recyclerviewHomeTodo.adapter = homeTodoAdapter
binding.recyclerviewHomeTodo.isNestedScrollingEnabled = true
homeTodoAdapter.items = homeTodoItems!!
}

private fun addTodo(todo: HomeTodoItem) {
homeTodoItems!!.add(todo)
homeTodoAdapter.notifyDataSetChanged()
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.ssjm.sw_hackathon.home.recycler

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ssjm.sw_hackathon.R
import com.ssjm.sw_hackathon.databinding.ItemTodoOfHomeBinding

class HomeTodoAdapter (private val context: Context,
) : RecyclerView.Adapter<HomeTodoAdapter.HomeTodoViewHolder>() {

var items = mutableListOf<HomeTodoItem>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) :
HomeTodoViewHolder {

val view = LayoutInflater.from(context).inflate(R.layout.item_todo_of_home, parent, false)

return HomeTodoViewHolder(ItemTodoOfHomeBinding.bind(view))
}

override fun getItemCount(): Int = items.size

override fun onBindViewHolder(holder: HomeTodoViewHolder, position: Int) {
holder.bind(items[position])

// 링크 아이템 클릭 시
/*holder.itemView.setOnClickListener {
onClickLinkItem(items[position].memoNum)
}*/
}

inner class HomeTodoViewHolder(private val binding: ItemTodoOfHomeBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bind(item: HomeTodoItem) {

// 이미지
val imgResourceName = "img_todo_" + item.coverImage
val iconResourceId = context.resources.getIdentifier(imgResourceName, "drawable", context.packageName)
binding.imgTodoCover.setImageResource(iconResourceId)

// 내용
binding.textTodoContent.text = item.content

// 기간
binding.textTodoPeriod.text = item.period

// 요일 리스트 보여줄 recyclerview 세팅
binding.recyclerviewHomeTodoDay.apply {
adapter = HomeTodoDayAdapter(context).build(item.day)
layoutManager =
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ssjm.sw_hackathon.home.recycler

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ssjm.sw_hackathon.R
import com.ssjm.sw_hackathon.databinding.ItemTodoDayBinding
import com.ssjm.sw_hackathon.databinding.ItemTodoOfHomeBinding

class HomeTodoDayAdapter (private val context: Context,
) : RecyclerView.Adapter<HomeTodoDayAdapter.HomeTodoDayViewHolder>() {

var items = mutableListOf<String>()

fun build(days: MutableList<String>?): HomeTodoDayAdapter {
if(days != null)
items = days

return this
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) :
HomeTodoDayViewHolder {

val view = LayoutInflater.from(context).inflate(R.layout.item_todo_day, parent, false)

return HomeTodoDayViewHolder(ItemTodoDayBinding.bind(view))
}

override fun getItemCount(): Int = items.size

override fun onBindViewHolder(holder: HomeTodoDayViewHolder, position: Int) {
holder.bind(items[position])

}

inner class HomeTodoDayViewHolder(private val binding: ItemTodoDayBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bind(item: String) {
binding.textTodoDay.text = item
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ssjm.sw_hackathon.home.recycler

import android.graphics.drawable.Drawable

data class HomeTodoItem(
val coverImage: String,
val content: String,
val period: String,
val day: MutableList<String>
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/layouts/home/drawable/shape_todo_cover_radius.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">

<solid android:color="@color/white"/>
<corners
android:radius="12dp"/>

</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/layouts/home/drawable/shape_todo_day.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">

<solid android:color="@color/main_color_2"/>
<corners
android:radius="6dp" />

</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/layouts/home/drawable/shape_todo_title.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">

<solid android:color="#CC000000"/>
<corners
android:radius="7dp" />

</shape>
15 changes: 14 additions & 1 deletion app/src/main/res/layouts/home/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
android:id="@+id/text_job"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="개발자"
android:text="바리스타"
android:textSize="26sp"
android:textStyle="bold"
android:textColor="@color/black01"
Expand Down Expand Up @@ -118,5 +118,18 @@

</RelativeLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_home_todo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="48dp"
android:layout_below="@id/relative_home_title"
android:layout_alignParentStart="true"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_todo_of_home"/>


</RelativeLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/layouts/home/layout/item_todo_day.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_todo_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:paddingVertical="4dp"
android:paddingHorizontal="8dp"
android:text=""
android:textSize="18sp"
android:textColor="@color/black03"
android:textStyle="bold"
android:background="@drawable/shape_todo_day"/>
61 changes: 61 additions & 0 deletions app/src/main/res/layouts/home/layout/item_todo_of_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="191dp"
android:layout_height="233dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginRight="16dp">

<ImageView
android:id="@+id/img_todo_cover"
android:layout_width="191dp"
android:layout_height="233dp"
android:scaleType="centerCrop"
android:clipToOutline="true"
android:src="@drawable/img_todo_note1"
android:background="@drawable/shape_todo_cover_radius"/>

<!-- 실천사항 내용 -->
<TextView
android:id="@+id/text_todo_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="14dp"
android:paddingVertical="6dp"
android:paddingHorizontal="10dp"
android:text="노트에 필사하기"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="@color/white"
android:background="@drawable/shape_todo_title"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"/>

<!-- 실천 기간 -->
<TextView
android:id="@+id/text_todo_period"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="14dp"
android:text="66일째 실천중"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="@color/main_color_2"
android:layout_below="@id/text_todo_content"
android:layout_alignParentStart="true"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_home_todo_day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginBottom="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_todo_day"/>

</RelativeLayout>

0 comments on commit 0785f6e

Please sign in to comment.