From 89f179b578da861ff2ee134afb48c0fb8255f755 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Thu, 12 Jan 2023 20:44:16 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B2=80=EC=83=89=EC=95=84=EC=9D=B4?= =?UTF-8?q?=EC=BD=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/inu/events/ui/home/HomeViewModel.kt | 6 +++ .../events/ui/util/toolbar/ToolbarListener.kt | 1 + app/src/main/res/drawable/ic_search.xml | 5 +++ app/src/main/res/layout/toolbar_layout.xml | 37 +++++++++++++------ 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/ic_search.xml diff --git a/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt b/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt index eb1749e..3076c34 100644 --- a/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt +++ b/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt @@ -1,6 +1,7 @@ package org.inu.events.ui.home import android.content.Intent +import android.util.Log import android.view.View import android.view.ViewParent import androidx.lifecycle.ViewModel @@ -40,6 +41,11 @@ class HomeViewModel : ViewModel(), KoinComponent { val likeClickEvent = SingleLiveEvent() val shouldRefresh = SingleLiveEvent() val toolbarListener = object : ToolbarListener { + override fun onClickSearch(view: View) { + val intent = Intent(view.context, SearchActivity::class.java) + view.context.startActivity(intent) + } + override fun onClickMyPage(view: View) { if (loginService.isLoggedIn) { val intent = Intent(view.context, MyPageActivity::class.java) diff --git a/app/src/main/java/org/inu/events/ui/util/toolbar/ToolbarListener.kt b/app/src/main/java/org/inu/events/ui/util/toolbar/ToolbarListener.kt index b160ef1..a44b2d4 100644 --- a/app/src/main/java/org/inu/events/ui/util/toolbar/ToolbarListener.kt +++ b/app/src/main/java/org/inu/events/ui/util/toolbar/ToolbarListener.kt @@ -3,5 +3,6 @@ package org.inu.events.ui.util.toolbar import android.view.View interface ToolbarListener { + fun onClickSearch(view: View) fun onClickMyPage(view: View) } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_search.xml b/app/src/main/res/drawable/ic_search.xml new file mode 100644 index 0000000..a5687c6 --- /dev/null +++ b/app/src/main/res/drawable/ic_search.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/toolbar_layout.xml b/app/src/main/res/layout/toolbar_layout.xml index b92f311..2f869e4 100644 --- a/app/src/main/res/layout/toolbar_layout.xml +++ b/app/src/main/res/layout/toolbar_layout.xml @@ -1,18 +1,21 @@ + - + + + + - + app:contentInsetStart="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:layout_marginStart="@dimen/horizontal_margin" + android:src="@drawable/ic_toolbar_logo" /> + android:src="@drawable/ic_person" + android:visibility="@{listener != null ? View.VISIBLE : View.GONE }" /> + + + From ee96e7d0b9b23b2f753617b8be8e87f12f33754f Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:37:09 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20UniSpinner=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/inu/events/lib/spinner/UniSpinner.kt | 86 +++++++++++++++++++ .../events/ui/binding/UniSpinnerBinding.kt | 11 +++ .../org/inu/events/ui/home/SpinnerAdapter.kt | 70 +++++++-------- app/src/main/res/drawable/ic_arrow_down.xml | 4 +- app/src/main/res/layout/uni_spinner.xml | 27 +++--- ...spinner_popup.xml => uni_spinner_item.xml} | 13 +-- app/src/main/res/values/attrs.xml | 5 ++ 7 files changed, 157 insertions(+), 59 deletions(-) create mode 100644 app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt create mode 100644 app/src/main/java/org/inu/events/ui/binding/UniSpinnerBinding.kt rename app/src/main/res/layout/{uni_spinner_popup.xml => uni_spinner_item.xml} (51%) diff --git a/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt b/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt new file mode 100644 index 0000000..f9037b8 --- /dev/null +++ b/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt @@ -0,0 +1,86 @@ +package org.inu.events.lib.spinner + +import android.content.Context +import android.util.AttributeSet +import android.widget.ArrayAdapter +import android.widget.FrameLayout +import android.widget.ListPopupWindow +import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout +import org.inu.events.R + +class UniSpinner @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + private lateinit var items: Array + private lateinit var selectedText: TextView + private val popUp = ListPopupWindow(context) + private lateinit var adapter: ArrayAdapter + + init { + inflate(context, R.layout.uni_spinner, this) + + setAttrs(attrs) + setAdapter() + setPopup() + setSelectedText() + } + + private fun setAttrs(attrs: AttributeSet?) { + context.obtainStyledAttributes(attrs, R.styleable.UniSpinner).run { + items = getTextArray(R.styleable.UniSpinner_items) ?: arrayOf("전체", "간식나눔", "공고") + recycle() + } + } + + + private fun setAdapter() { + adapter = ArrayAdapter(context, R.layout.uni_spinner_item, items) + popUp.setAdapter(adapter) + } + + private fun measureWidth(): Int { + var width = 0 + for (i in items.indices) { + val view = adapter.getView(i, null, FrameLayout(context)) + view.measure(0, 0) + width = width.coerceAtLeast(view.measuredWidth) + } + return width + } + + private fun setSelectedText() { + selectedText = findViewById(R.id.selected_item).apply { + text = items.first() + width = popUp.width + setOnClickListener { + if (popUp.isShowing) { + popUp.dismiss() + } else { + popUp.show() + } + } + } + } + + private fun setPopup() { + popUp.apply { + isModal = true + anchorView = this@UniSpinner + verticalOffset = this.height + 8 + setContentWidth(measureWidth() + 100) + } + + } + + fun setOnItemClick(onClick: (pos:Int) -> Unit) { + popUp.setOnItemClickListener { _, _, position, _ -> + selectedText.text = items[position] + popUp.dismiss() + onClick(position) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/inu/events/ui/binding/UniSpinnerBinding.kt b/app/src/main/java/org/inu/events/ui/binding/UniSpinnerBinding.kt new file mode 100644 index 0000000..ff53c13 --- /dev/null +++ b/app/src/main/java/org/inu/events/ui/binding/UniSpinnerBinding.kt @@ -0,0 +1,11 @@ +package org.inu.events.ui.binding + +import androidx.databinding.BindingAdapter +import org.inu.events.lib.spinner.UniSpinner + +@BindingAdapter("setOnItemClick") +fun bindSetOnItemClick(view: UniSpinner, onClick: (position: Int) -> Unit) { + view.setOnItemClick { position -> + onClick(position) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/inu/events/ui/home/SpinnerAdapter.kt b/app/src/main/java/org/inu/events/ui/home/SpinnerAdapter.kt index 5ff05be..8ab0ae9 100644 --- a/app/src/main/java/org/inu/events/ui/home/SpinnerAdapter.kt +++ b/app/src/main/java/org/inu/events/ui/home/SpinnerAdapter.kt @@ -1,35 +1,35 @@ -package org.inu.events.ui.home - -import android.content.Context -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ArrayAdapter -import androidx.annotation.LayoutRes -import org.inu.events.databinding.UniSpinnerBinding -import org.inu.events.databinding.UniSpinnerPopupBinding - -class SpinnerAdapter( - context: Context, - @LayoutRes private val resId: Int, - private val list: MutableList, - private val spinnerTitle: String -) : ArrayAdapter(context, resId, list) { - override fun getCount(): Int = list.size - override fun getItem(position: Int): String = list[position] - - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val binding = UniSpinnerBinding.inflate(LayoutInflater.from(parent.context), parent, false) - binding.selectedItem.text = if (position == 0) spinnerTitle else list[position] - - return binding.root - } - - override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View { - val binding = UniSpinnerPopupBinding.inflate(LayoutInflater.from(parent.context), parent, false) - val model = list[position] - binding.item.text = model - - return binding.root - } -} \ No newline at end of file +//package org.inu.events.ui.home +// +//import android.content.Context +//import android.view.LayoutInflater +//import android.view.View +//import android.view.ViewGroup +//import android.widget.ArrayAdapter +//import androidx.annotation.LayoutRes +//import org.inu.events.databinding.UniSpinnerBinding +//import org.inu.events.databinding.UniSpinnerPopupBinding +// +//class SpinnerAdapter( +// context: Context, +// @LayoutRes private val resId: Int, +// private val list: MutableList, +// private val spinnerTitle: String +//) : ArrayAdapter(context, resId, list) { +// override fun getCount(): Int = list.size +// override fun getItem(position: Int): String = list[position] +// +// override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { +// val binding = UniSpinnerBinding.inflate(LayoutInflater.from(parent.context), parent, false) +// binding.selectedItem.text = if (position == 0) spinnerTitle else list[position] +// +// return binding.root +// } +// +// override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View { +// val binding = UniSpinnerPopupBinding.inflate(LayoutInflater.from(parent.context), parent, false) +// val model = list[position] +// binding.item.text = model +// +// return binding.root +// } +//} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_arrow_down.xml b/app/src/main/res/drawable/ic_arrow_down.xml index 983a153..ac804f1 100644 --- a/app/src/main/res/drawable/ic_arrow_down.xml +++ b/app/src/main/res/drawable/ic_arrow_down.xml @@ -1,5 +1,5 @@ - + - - - + tools:text="카테고리" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/uni_spinner_popup.xml b/app/src/main/res/layout/uni_spinner_item.xml similarity index 51% rename from app/src/main/res/layout/uni_spinner_popup.xml rename to app/src/main/res/layout/uni_spinner_item.xml index 577010d..a87fef8 100644 --- a/app/src/main/res/layout/uni_spinner_popup.xml +++ b/app/src/main/res/layout/uni_spinner_item.xml @@ -1,12 +1,13 @@ \ No newline at end of file + app:layout_constraintTop_toTopOf="parent" + tools:text="학생회" /> \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index f5e7e4a..f91b4b9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -4,4 +4,9 @@ + + + + + \ No newline at end of file From 61365550745c3c19833096decef4b4d87671d5ba Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:37:46 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20UniSpinner=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/inu/events/ui/home/HomeViewModel.kt | 6 +-- .../org/inu/events/ui/home/MainActivity.kt | 21 +++++---- app/src/main/res/layout/activity_main.xml | 43 ++++++------------- 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt b/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt index 3076c34..e151371 100644 --- a/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt +++ b/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt @@ -1,9 +1,7 @@ package org.inu.events.ui.home import android.content.Intent -import android.util.Log import android.view.View -import android.view.ViewParent import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData @@ -106,12 +104,12 @@ class HomeViewModel : ViewModel(), KoinComponent { } } - fun onCategoryItemClick(parent: ViewParent, view: View, position: Int, id: Long) { + val onCategoryItemClick = fun(position: Int) { categoryId = position getHomeData(categoryId, eventStatus) } - fun onFilterItemClick(parent: ViewParent, view: View, position: Int, id: Long) { + val onFilterItemClick = fun(position: Int) { eventStatus = position == 1 getHomeData(categoryId, eventStatus) } diff --git a/app/src/main/java/org/inu/events/ui/home/MainActivity.kt b/app/src/main/java/org/inu/events/ui/home/MainActivity.kt index c11c376..9af7ecd 100644 --- a/app/src/main/java/org/inu/events/ui/home/MainActivity.kt +++ b/app/src/main/java/org/inu/events/ui/home/MainActivity.kt @@ -36,7 +36,6 @@ class MainActivity : AppCompatActivity(), LoginDialog.LoginDialog { setupRecyclerView() setUpSwipeRefresh() setupRefreshEvent() - setupSpinner() } override fun onResume() { @@ -102,16 +101,16 @@ class MainActivity : AppCompatActivity(), LoginDialog.LoginDialog { } } - private fun setupSpinner() { - val categoryItems = resources.getStringArray(R.array.classification) - val filterItems = resources.getStringArray(R.array.filter) - - val categoryAdapter = SpinnerAdapter(this, R.layout.uni_spinner_popup, categoryItems.toMutableList(), "카테고리") - val filterAdapter = SpinnerAdapter(this, R.layout.uni_spinner_popup, filterItems.toMutableList(), "전체") - - binding.spinnerClassification.adapter = categoryAdapter - binding.spinnerFilter.adapter = filterAdapter - } +// private fun setupSpinner() { +// val categoryItems = resources.getStringArray(R.array.classification) +// val filterItems = resources.getStringArray(R.array.filter) +// +// val categoryAdapter = SpinnerAdapter(this, R.layout.uni_spinner_popup, categoryItems.toMutableList(), "카테고리") +// val filterAdapter = SpinnerAdapter(this, R.layout.uni_spinner_popup, filterItems.toMutableList(), "전체") +// +// binding.spinnerClassification.adapter = categoryAdapter +// binding.spinnerFilter.adapter = filterAdapter +// } private fun askUserForLogin() { LoginDialog().show(this, ::onOk, ::onCancel) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e508c2b..94c07b0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,42 +22,27 @@ app:layout_constraintTop_toTopOf="parent" app:listener="@{mainViewModel.toolbarListener}" /> - + app:layout_constraintTop_toBottomOf="@id/include" + app:setOnItemClick="@{mainViewModel.onCategoryItemClick}" /> - + app:items="@array/filter" + app:layout_constraintEnd_toStartOf="@id/us_category" + app:layout_constraintTop_toBottomOf="@id/include" + app:setOnItemClick="@{mainViewModel.onFilterItemClick}" /> Date: Fri, 13 Jan 2023 20:59:34 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=EC=95=B1=20=EC=8B=9C=EC=9E=91=20?= =?UTF-8?q?=EC=8B=9C,=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4,=20=ED=95=84=ED=84=B0=20=EC=A0=84=EC=B2=B4=EB=A1=9C?= =?UTF-8?q?=20=EB=B6=80=EB=A5=B4=EA=B2=8C=EB=81=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt b/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt index e151371..962b3b4 100644 --- a/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt +++ b/app/src/main/java/org/inu/events/ui/home/HomeViewModel.kt @@ -58,6 +58,10 @@ class HomeViewModel : ViewModel(), KoinComponent { } } + init { + getHomeData(categoryId, eventStatus) + } + fun refresh() { shouldRefresh.call() } From 83dc509cf836ba526d7fc70c8ebfb7e3eb05ee13 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Fri, 13 Jan 2023 21:09:14 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20UniSpinner=20=EC=88=98=EC=A0=95=20(?= =?UTF-8?q?=EB=94=94=EC=9E=90=EC=9D=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/inu/events/lib/spinner/UniSpinner.kt | 10 ++++++++-- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/activity_register_events.xml | 2 +- app/src/main/res/layout/fragment_register2.xml | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt b/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt index f9037b8..22e621f 100644 --- a/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt +++ b/app/src/main/java/org/inu/events/lib/spinner/UniSpinner.kt @@ -70,8 +70,9 @@ class UniSpinner @JvmOverloads constructor( popUp.apply { isModal = true anchorView = this@UniSpinner - verticalOffset = this.height + 8 - setContentWidth(measureWidth() + 100) + verticalOffset = this.height + DISTANCE_POPUP_TITLE + width = measureWidth() + MARGIN_END_POPUP_ITEM + setBackgroundDrawable(context.getDrawable(R.drawable.popup_background)) } } @@ -83,4 +84,9 @@ class UniSpinner @JvmOverloads constructor( onClick(position) } } + + companion object { + const val DISTANCE_POPUP_TITLE = 8 * 3 + const val MARGIN_END_POPUP_ITEM = 16 * 3 + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 94c07b0..89e3e66 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -38,7 +38,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:layout_marginEnd="20dp" + android:layout_marginEnd="4dp" app:items="@array/filter" app:layout_constraintEnd_toStartOf="@id/us_category" app:layout_constraintTop_toBottomOf="@id/include" diff --git a/app/src/main/res/layout/activity_register_events.xml b/app/src/main/res/layout/activity_register_events.xml index 202e256..f9450a3 100644 --- a/app/src/main/res/layout/activity_register_events.xml +++ b/app/src/main/res/layout/activity_register_events.xml @@ -315,7 +315,7 @@ android:layout_height="@dimen/exitText_height" android:layout_marginHorizontal="20dp" android:layout_marginTop="4dp" - android:background="@drawable/spinner_background" + android:background="@drawable/drawable_edit_text_background" android:entries="@array/classification" android:paddingHorizontal="16dp" android:selectedItemPosition="@={registerViewModel.selectedItemPosition}" diff --git a/app/src/main/res/layout/fragment_register2.xml b/app/src/main/res/layout/fragment_register2.xml index 71f1a3f..21f4d93 100644 --- a/app/src/main/res/layout/fragment_register2.xml +++ b/app/src/main/res/layout/fragment_register2.xml @@ -150,7 +150,7 @@ android:layout_height="@dimen/exitText_height" android:layout_marginHorizontal="20dp" android:layout_marginTop="4dp" - android:background="@drawable/spinner_background" + android:background="@drawable/drawable_edit_text_background" android:entries="@array/classification" android:paddingHorizontal="8dp" android:paddingVertical="10dp" From 750a72bef99ddf231cf4a719cacf41c375784a8d Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Fri, 13 Jan 2023 21:16:39 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20back=20=EB=B2=84=ED=8A=BC=20=ED=99=9C=EC=84=B1?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/inu/events/ui/home/SearchActivity.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/org/inu/events/ui/home/SearchActivity.kt b/app/src/main/java/org/inu/events/ui/home/SearchActivity.kt index 89f3f26..182fc26 100644 --- a/app/src/main/java/org/inu/events/ui/home/SearchActivity.kt +++ b/app/src/main/java/org/inu/events/ui/home/SearchActivity.kt @@ -25,6 +25,7 @@ class SearchActivity : AppCompatActivity() { } initRecyclerView() + initBackButton() observeSearch() setContentView(binding.root) @@ -44,4 +45,10 @@ class SearchActivity : AppCompatActivity() { } } } + + private fun initBackButton() { + binding.tvBack.setOnClickListener { + finish() + } + } } \ No newline at end of file