Skip to content

Commit

Permalink
[MIN-49] feat: story 리사이클러 뷰 구현(#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDW03 committed Feb 12, 2023
1 parent 13fdb60 commit 111df0e
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 30 deletions.
2 changes: 2 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<!-- Customize your theme here. -->
<item name="android:statusBarColor">@color/black</item>

</style>


Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
kakao_version = '2.12.1'
dataStorePreferences_version = '1.0.0'
retrofit2Version = '2.9.0'

recyclerViewVersion = '1.2.1'
}

dependencies {
Expand Down
4 changes: 4 additions & 0 deletions common-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ android {

dependencies {

api project(path: ':common')


api "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion"

// Fragment
api "androidx.fragment:fragment:$rootProject.fragment_version"
Expand Down
5 changes: 1 addition & 4 deletions common-ui/src/main/res/layout/item_story.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

</data>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
Expand Down Expand Up @@ -74,5 +72,4 @@

</FrameLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.common.data.dto

import com.example.common.data.entity.StoryWithDate

data class StoryListResponse(
val success: Boolean,
val data: List<StoryWithDate>
)
22 changes: 7 additions & 15 deletions common/src/main/java/com/example/common/data/entity/HomeData.kt
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
package com.example.common.data.entity

import com.kakao.sdk.user.model.User

data class HomeData(
val couple: Couple,
val newStory: NewStory,
val newStory: Story,
val widgets: List<Widget>
)


data class Couple(
val me: Me,
val mine: Mine,
val me: UserInfo,
val mine: UserInfo,
val name: String,
val startDate: String
)


data class NewStory(
data class Story(
val date: String,
val postId: Int,
val region: String,
val thumbnailImage: String
)


data class Mine(
val birthday: String,
val description: String,
val gender: String,
val instaId: String,
val nickname: String,
val profileImage: String
)


data class Me(
data class UserInfo(
val birthday: String,
val description: String,
val gender: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.common.data.entity

data class StoryWithDate(
val year : String,
val month : String,
val posts : List<Story>
)
58 changes: 58 additions & 0 deletions story/src/main/java/com/najudoryeong/mineme/story/StoryAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.najudoryeong.mineme.story

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.common.data.entity.Story
import com.najudoryeong.mineme.common_ui.databinding.ItemStoryBinding
import com.najudoryeong.mineme.story.databinding.TestStoryBinding


class StoryAdapter : ListAdapter<StoryModel, RecyclerView.ViewHolder>(StoryDiffCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return StoryViewHolder(
TestStoryBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is StoryViewHolder){
val story = getItem(position)
holder.bind(story)
}
}

class StoryViewHolder(private val binding: TestStoryBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(storyModel: StoryModel) {
with(binding) {
story = storyModel
executePendingBindings()
itemView.setOnClickListener {
// story 상세보기
Log.d("testStory","상세보기 클릭")
}
}
}
}


}


private class StoryDiffCallback : DiffUtil.ItemCallback<StoryModel>() {
override fun areItemsTheSame(oldItem: StoryModel, newItem: StoryModel): Boolean {
return oldItem === newItem
}

override fun areContentsTheSame(oldItem: StoryModel, newItem: StoryModel): Boolean {
return oldItem == newItem
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ package com.najudoryeong.mineme.story

import com.najudoryeong.mineme.common_ui.BaseFragment
import com.najudoryeong.mineme.story.databinding.FragmentStoryBinding
import com.example.common.data.entity.Story

class StoryFragment : BaseFragment<FragmentStoryBinding>(Story) {

private val myListAdapter: StoryAdapter by lazy {
StoryAdapter()
}

private val dataSet = arrayListOf<StoryModel>().apply {
add(StoryModel("2022-01-03",1, "마산","https://images.unsplash.com/photo-1511739001486-6bfe10ce785f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80"))
add(StoryModel("2022-01-04",1, "마산1","https://images.unsplash.com/photo-1511739001486-6bfe10ce785f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80"))
add(StoryModel("2022-01-05",1, "마산2","https://images.unsplash.com/photo-1511739001486-6bfe10ce785f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80"))
add(StoryModel("2022-01-06",1, "마산3","https://images.unsplash.com/photo-1511739001486-6bfe10ce785f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80"))
add(StoryModel("2022-01-07",1, "마산4","https://images.unsplash.com/photo-1511739001486-6bfe10ce785f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80"))

}

override fun initView() {
binding.apply {

//todo callback
recyclerView.adapter = myListAdapter
}
myListAdapter.submitList(dataSet)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.najudoryeong.mineme.story

data class StoryModel(
val date: String,
val postId: Int,
val region: String,
val thumbnailImage: String
)
36 changes: 27 additions & 9 deletions story/src/main/res/layout/fragment_story.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<FrameLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StoryFragment">
android:layout_height="match_parent">

<!-- TODO: Update blank fragment layout -->
<TextView
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="50dp"
android:text="스토리부분" />
</FrameLayout>
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:clipToPadding="false"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="@layout/test_story" />

</androidx.constraintlayout.widget.ConstraintLayout>


</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
67 changes: 67 additions & 0 deletions story/src/main/res/layout/test_story.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="story"
type="com.najudoryeong.mineme.story.StoryModel" />

</data>


<androidx.cardview.widget.CardView
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="165dp"
app:cardCornerRadius="8dp">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<ImageView
photoUrl="@{story.thumbnailImage}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/img_profile" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#99C9C9C9">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/cafe24_ssurround"
android:padding="16dp"
android:text="@{story.region}"
android:textColor="#FFFFFF"
android:textSize="14sp" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/cafe24_ssurround"
android:gravity="end"
android:padding="16dp"
android:text="@{story.date}"
android:textColor="#FFFFFF"
android:textSize="14sp" />


</LinearLayout>

</FrameLayout>
</androidx.cardview.widget.CardView>
</layout>

0 comments on commit 111df0e

Please sign in to comment.