-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
468 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
buddy/src/main/java/com/nocapstone/buddyvet/buddy/BuddyProfileListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.nocapstone.buddyvet.buddy | ||
|
||
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.nocapstone.buddyvet.buddy.databinding.ItemBuddyProfileBinding | ||
import com.nocapstone.buddyvet.buddy.domain.entity.BuddyData | ||
|
||
class BuddyProfileListAdapter( | ||
private val ColorChange: Boolean, | ||
private val onClickBuddyListener: (Int) -> Unit | ||
) : | ||
ListAdapter<BuddyData, RecyclerView.ViewHolder>(BuddyProfileListDiffCallback()) { | ||
|
||
var prePosition = -1 | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return BuddyListViewHolder( | ||
ItemBuddyProfileBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
if (holder is BuddyListViewHolder) { | ||
val buddyData = getItem(position) | ||
holder.bind(buddyData, position) | ||
} | ||
} | ||
|
||
inner class BuddyListViewHolder(private val binding: ItemBuddyProfileBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun bind(data: BuddyData, position: Int) { | ||
|
||
binding.apply { | ||
buddyData = data | ||
} | ||
|
||
itemView.setOnClickListener { | ||
onClickBuddyListener(position) | ||
if (ColorChange) { | ||
if (prePosition >= 0) { | ||
getItem(prePosition).isSelect = false | ||
} | ||
getItem(position).isSelect = true | ||
prePosition = position | ||
notifyDataSetChanged() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private class BuddyProfileListDiffCallback : DiffUtil.ItemCallback<BuddyData>() { | ||
override fun areItemsTheSame(oldItem: BuddyData, newItem: BuddyData): Boolean { | ||
return oldItem === newItem | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: BuddyData, newItem: BuddyData): Boolean { | ||
return oldItem == newItem | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
buddy/src/main/java/com/nocapstone/buddyvet/buddy/domain/entity/MasterInfoResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.nocapstone.buddyvet.buddy.domain.entity | ||
|
||
data class MasterInfoResponse( | ||
val userId : Int, | ||
val nickname : String, | ||
val profile : String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
buddy/src/main/java/com/nocapstone/buddyvet/buddy/ui/MyBuddyFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.nocapstone.buddyvet.buddy.ui | ||
|
||
import android.os.Bundle | ||
import android.view.* | ||
import androidx.fragment.app.Fragment | ||
import android.widget.ListAdapter | ||
import androidx.core.view.MenuHost | ||
import androidx.core.view.MenuProvider | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.navigation.fragment.findNavController | ||
import com.nocapstone.buddyvet.buddy.BuddyListAdapter | ||
import com.nocapstone.buddyvet.buddy.R | ||
import com.nocapstone.buddyvet.buddy.databinding.FragmentMyBuddyBinding | ||
import com.nocapstone.common_ui.MainActivityUtil | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class MyBuddyFragment : Fragment() { | ||
|
||
private var _binding: FragmentMyBuddyBinding? = null | ||
private val binding get() = _binding!! | ||
private val buddyViewModel: BuddyViewModel by viewModels({ requireActivity() }) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
_binding = FragmentMyBuddyBinding.inflate(inflater, container, false) | ||
|
||
(activity as MainActivityUtil).run { | ||
setToolbarTitle("My Buddy") | ||
} | ||
|
||
return binding.root | ||
} | ||
|
||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
buddyViewModel.readMasterProfile() | ||
buddyViewModel.readBuddyList() | ||
initMenu() | ||
binding.apply { | ||
lifecycleOwner = viewLifecycleOwner | ||
viewModel = buddyViewModel | ||
adapter = BuddyListAdapter() | ||
} | ||
|
||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
private fun initMenu() { | ||
val menuHost: MenuHost = requireActivity() | ||
|
||
menuHost.addMenuProvider(object : MenuProvider { | ||
|
||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { | ||
menuInflater.inflate(R.menu.my_buddy_menu, menu) | ||
} | ||
|
||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean { | ||
when (menuItem.itemId) { | ||
android.R.id.home -> { | ||
findNavController().popBackStack() | ||
} | ||
R.id.add_buddy -> { | ||
findNavController().navigate(R.id.next) | ||
} | ||
} | ||
return true | ||
} | ||
}, viewLifecycleOwner, Lifecycle.State.RESUMED) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#DCAE89" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="14dp" | ||
android:height="15dp" | ||
android:viewportWidth="14" | ||
android:viewportHeight="15"> | ||
<group> | ||
<clip-path | ||
android:pathData="M0,0.5h14v14h-14z"/> | ||
<path | ||
android:pathData="M3.786,12.243L4.818,13.275L10.593,7.5L4.818,1.725L3.786,2.757L8.528,7.5L3.786,12.243Z" | ||
android:fillColor="#000000"/> | ||
</group> | ||
</vector> |
Oops, something went wrong.