Skip to content

Commit

Permalink
[FIX/#2]: 갤러리 프래그먼트에서 데이터의 초기화 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeha committed Apr 20, 2023
1 parent a2333b0 commit 532d3e1
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 25 deletions.
16 changes: 9 additions & 7 deletions app/src/main/java/org/android/go/sopt/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
private fun initBnvItemReselectedListener() {
binding.bnvMain.setOnItemReselectedListener {
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_main)
if(currentFragment is HomeFragment){
val recyclerView = findViewById<RecyclerView>(R.id.rv_repo)
recyclerView.scrollToPosition(0)
when(currentFragment){
is HomeFragment -> {
val recyclerView = findViewById<RecyclerView>(R.id.rv_home)
recyclerView.scrollToPosition(0)
}
is GalleryFragment -> {
val recyclerView = findViewById<RecyclerView>(R.id.rv_gallery)
recyclerView.scrollToPosition(0)
}
}
}
}
Expand Down Expand Up @@ -65,8 +71,4 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
.replace(R.id.fcv_main, fragment)
.commit()
}

companion object {
private const val UP_DIRECTION = -1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import org.android.go.sopt.R
import org.android.go.sopt.binding.BindingFragment
import org.android.go.sopt.databinding.FragmentGalleryBinding
import org.android.go.sopt.ui.main.gallery.adapter.MyListAdapter
import org.android.go.sopt.ui.main.gallery.adapter.model.Repo
import org.android.go.sopt.ui.main.home.adapter.MyItemTouchHelperCallback

class GalleryFragment : BindingFragment<FragmentGalleryBinding>(R.layout.fragment_gallery) {
private val myListAdapter: MyListAdapter by lazy {
MyListAdapter()
}

private val dataSet = arrayListOf<Repo>().apply {
for (i in 1..20) {
add(Repo(R.drawable.ic_launcher_background, "name $i", "author $i"))
}
}

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

Expand All @@ -31,24 +26,33 @@ class GalleryFragment : BindingFragment<FragmentGalleryBinding>(R.layout.fragmen
}

private fun initRecyclerView() {
binding.rvRepo.apply {
binding.rvGallery.apply {
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
adapter = myListAdapter
}

val dataSet = arrayListOf<Repo>().apply {
for (i in 1..20) {
add(Repo(R.drawable.ic_launcher_background, "name $i", "author $i"))
}
}

myListAdapter.submitList(dataSet)
Log.d("ListAdapter", "submitList called...")
}

private fun initFABClickListener() {
binding.fabShuffle.setOnClickListener {
myListAdapter.submitList(dataSet.shuffled())
val currentList = myListAdapter.currentList
myListAdapter.submitList(currentList.shuffled())
Log.d("ListAdapter", "submitList called...")
}
}

private fun applyItemTouchHelper() {
val itemTouchHelper = ItemTouchHelper(MyItemTouchHelperCallback(binding.rvRepo))
itemTouchHelper.attachToRecyclerView(binding.rvRepo)
val recyclerView = binding.rvGallery
val itemTouchHelper = ItemTouchHelper(MyItemTouchHelperCallback(recyclerView))
itemTouchHelper.attachToRecyclerView(recyclerView)
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.android.go.sopt.ui.main.gallery.adapter

import androidx.recyclerview.widget.DiffUtil
import org.android.go.sopt.ui.main.gallery.Repo
import org.android.go.sopt.ui.main.gallery.adapter.model.Repo

class MyDiffCallback : DiffUtil.ItemCallback<Repo>() {
override fun areItemsTheSame(oldItem: Repo, newItem: Repo): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import org.android.go.sopt.databinding.ItemImageBinding
import org.android.go.sopt.ui.main.gallery.Repo
import org.android.go.sopt.ui.main.gallery.adapter.model.Repo
import java.util.*

class MyListAdapter : ListAdapter<Repo, MyViewHolder>(MyDiffCallback()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.android.go.sopt.ui.main.gallery.adapter

import androidx.recyclerview.widget.RecyclerView
import org.android.go.sopt.databinding.ItemImageBinding
import org.android.go.sopt.ui.main.gallery.Repo
import org.android.go.sopt.ui.main.gallery.adapter.model.Repo

class MyViewHolder(private val binding: ItemImageBinding) :
RecyclerView.ViewHolder(binding.root) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.android.go.sopt.ui.main.gallery
package org.android.go.sopt.ui.main.gallery.adapter.model

import androidx.annotation.DrawableRes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.android.go.sopt.ui.main.home

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import org.android.go.sopt.R
import org.android.go.sopt.binding.BindingFragment
Expand All @@ -20,7 +19,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
}

private fun initRecyclerView(dataSet: ArrayList<MultiViewItem>) {
binding.rvRepo.apply {
binding.rvHome.apply {
adapter = MultiViewAdapter(dataSet)
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
setHasFixedSize(true)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_gallery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_repo"
android:id="@+id/rv_gallery"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_repo"
android:id="@+id/rv_home"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
Expand Down

0 comments on commit 532d3e1

Please sign in to comment.