Skip to content

Commit

Permalink
Feat : Add a shedule order change feature tukcomCD2024#85
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-g001 committed Jun 15, 2024
1 parent 1aa9e5c commit 94def5f
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ class DaysScheduleEditAdapter (
notifyItemChanged(dailySchedule.lastIndex)
}

fun remove(position: Int){
fun remove(position: Int, notify: Boolean){
dailySchedule.removeAt(position)
notifyDataSetChanged()
if (notify)
notifyDataSetChanged()
}

fun edit(data : DaysSchedule, position: Int){
Expand All @@ -157,6 +158,16 @@ class DaysScheduleEditAdapter (

fun getData() = dailySchedule

fun getData(position: Int) = dailySchedule[position]

fun add(position: Int, data: DaysSchedule, notify : Boolean){
dailySchedule.add(position, data)
if (notify)
notifyDataSetChanged()
}



override fun onItemMove(fromPosition: Int, toPosition: Int): Boolean {
Log.d("addOnItemTouchListener", "onItemMove start\nfrom : $fromPosition\tto : $toPosition")
if (fromPosition < toPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RadioButtonAdapter(data: List<String>, private val multiple : Boolean, pri
binding.radioBtn.setOnClickListener {
if (!multiple){
reset()
onItemClickListener.onItemClickListener(data, type)
onItemClickListener.onItemClickListener(data, type, position)
}
check[position] = !check[position]
notifyDataSetChanged()
Expand Down Expand Up @@ -64,12 +64,16 @@ class RadioButtonAdapter(data: List<String>, private val multiple : Boolean, pri
return datas
}

fun setCheck(position: Int){
check[position] = true
}

private fun changeColor(binding: SimpleRadiobuttonItemBinding, position: Int){
binding.radioBtn.isChecked = check[position]
}

interface OnItemClickListener{
fun onItemClickListener(data: String, type : Int)
fun onItemClickListener(data: String, type: Int, position: Int)
}companion object{
const val KOREA = 0
const val JAPAN = 1
Expand All @@ -85,5 +89,6 @@ class RadioButtonAdapter(data: List<String>, private val multiple : Boolean, pri
const val CITY = 203
const val MEDIA = 204
const val ATMOSPHERE = 205
const val ORDER = 301
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.project.how.interface_af

interface OnOrderChangeListener {
fun onOrderChangeListener(changedPosition : Int, previousPosition : Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import com.project.how.data_class.recyclerview.Schedule
import com.project.how.databinding.ActivityCalendarEditBinding
import com.project.how.interface_af.OnDateTimeListener
import com.project.how.interface_af.OnDesListener
import com.project.how.interface_af.OnOrderChangeListener
import com.project.how.interface_af.OnScheduleListener
import com.project.how.interface_af.interface_ada.ItemStartDragListener
import com.project.how.view.activity.MainActivity
import com.project.how.view.dialog.AiScheduleDialog
import com.project.how.view.dialog.DatePickerDialog
import com.project.how.view.dialog.OrderChangeDialog
import com.project.how.view.dialog.bottom_sheet_dialog.DesBottomSheetDialog
import com.project.how.view.dialog.bottom_sheet_dialog.EditScheduleBottomSheetDialog
import com.project.how.view.dp.DpPxChanger
Expand All @@ -53,14 +55,13 @@ import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.TimeZone
import kotlin.math.abs


class CalendarEditActivity
: AppCompatActivity(), OnMapReadyCallback, DaysScheduleEditAdapter.OnDaysButtonClickListener, OnScheduleListener, OnDesListener, OnDateTimeListener {
: AppCompatActivity(), OnMapReadyCallback, DaysScheduleEditAdapter.OnDaysButtonClickListener, OnScheduleListener, OnDesListener, OnDateTimeListener, OnOrderChangeListener {
private lateinit var binding : ActivityCalendarEditBinding
private val viewModel : ScheduleViewModel by viewModels()
private val calendarViewModel : CalendarViewModel by viewModels()
Expand Down Expand Up @@ -344,6 +345,11 @@ class CalendarEditActivity
}
}

private fun showOrderChange(position: Int){
val order = OrderChangeDialog(data.dailySchedule[selectedDays], position, this)
order.show(supportFragmentManager, "OrderChangeDialog")
}

private suspend fun saveNewSchedule(){

viewModel.saveSchedule(this, MemberViewModel.tokensLiveData.value!!.accessToken, data).collect{check ->
Expand Down Expand Up @@ -416,11 +422,11 @@ class CalendarEditActivity
}

override fun onMoreMenuOrderChangeClickListener(position: Int) {

showOrderChange(position)
}

override fun onMoreMenuDeleteClickListener(position: Int) {
adapter.remove(position)
adapter.remove(position, true)
data.dailySchedule[selectedDays]= adapter.getData()
lifecycleScope.launch {
viewModel.getTotalCost(data).collect{
Expand Down Expand Up @@ -470,11 +476,18 @@ class CalendarEditActivity
val diffMillies = abs(sd.time - ssd.time)
val diff = (diffMillies / (24 * 60 * 60 * 1000)).toInt()
data.dailySchedule[selectedDays+diff].add(d)
adapter.remove(position)
adapter.remove(position, true)
supportMapFragment.getMapAsync(this)

}

override fun onOrderChangeListener(changedPosition: Int, previousPosition: Int) {
val temp = adapter.getData(previousPosition)
adapter.remove(previousPosition, false)
adapter.add(changedPosition, temp, true)
supportMapFragment.getMapAsync(this)
}

companion object{
const val FAILURE = -1
const val AI_SCHEDULE = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.project.how.view.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import com.project.how.R
import com.project.how.adapter.recyclerview.RadioButtonAdapter
import com.project.how.data_class.recyclerview.DaysSchedule
import com.project.how.databinding.DialogOrderChangeBinding
import com.project.how.interface_af.OnOrderChangeListener

class OrderChangeDialog(private val data : MutableList<DaysSchedule>, private val currentPosition : Int, private val onOrderChangeListener: OnOrderChangeListener) : DialogFragment(), RadioButtonAdapter.OnItemClickListener {
private var _binding : DialogOrderChangeBinding? = null
private val binding : DialogOrderChangeBinding
get() = _binding!!
private lateinit var adapter : RadioButtonAdapter
private lateinit var days : MutableList<String>
private var position = currentPosition

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
days = mutableListOf()
for (i in 1..data.size){
days.add("${i}번째 : ${data[i-1].todo}")
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = DataBindingUtil.inflate(inflater, R.layout.dialog_order_change, container, false)
binding.order = this
binding.lifecycleOwner = viewLifecycleOwner
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
adapter = RadioButtonAdapter(days, false, this, RadioButtonAdapter.ORDER)
adapter.setCheck(currentPosition)
binding.scheduleOrder.adapter = adapter
return binding.root
}

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

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

fun cancel(){
dismiss()
}

fun save(){
onOrderChangeListener.onOrderChangeListener(position, currentPosition)
dismiss()
}

override fun onItemClickListener(data: String, type: Int, position: Int) {
this.position = position
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.project.how.view.dialog.bottom_sheet_dialog

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.util.DisplayMetrics
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.project.how.R
Expand Down Expand Up @@ -186,7 +182,7 @@ class ActivityBottomSheetDialog(private val onActivityListener: OnActivityListen
_binding = null
}

override fun onItemClickListener(data: String, type: Int) {
override fun onItemClickListener(data: String, type: Int, position: Int) {
}

companion object{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AirportBottomSheetDialog(private val type: Int, private val onAirportListe
}
}

override fun onItemClickListener(data: String, type: Int) {
override fun onItemClickListener(data: String, type: Int, position: Int) {
lifecycleScope.launch {
when(type){
RadioButtonAdapter.KOREA->{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class DesBottomSheetDialog(private val onDesListener: OnDesListener) : BottomShe
}
}

override fun onItemClickListener(data: String, type: Int) {
override fun onItemClickListener(data: String, type: Int, position: Int) {
when(type){
RadioButtonAdapter.JAPAN->{
lifecycleScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class PurposeBottomSheetDialog(private val onPurposeListener : OnPurposeListener
_binding = null
}

override fun onItemClickListener(data: String, type: Int) {
override fun onItemClickListener(data: String, type: Int, position: Int) {
if (type == RadioButtonAdapter.WHO){
who = data
}else if(type == RadioButtonAdapter.ACTIVITY_LEVEL){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="order"
type="com.project.how.view.dialog.OrderChangeDialog" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/white_round_rectangle">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/info_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginHorizontal="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/schedule_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="300dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
tools:listitem="@layout/simple_radiobutton_item"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/cancel"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
android:background="@drawable/gray_dialog_no"
android:onClick="@{()-> order.cancel()}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/save"
app:layout_constraintTop_toBottomOf="@+id/info_box" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/save"
android:layout_width="0dp"
android:text="@string/edit"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/black_dialog_yes"
android:onClick="@{()->order.save()}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/cancel"
app:layout_constraintTop_toBottomOf="@+id/info_box" />

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
android:background="@drawable/radio_btn_round_rectangle"
android:paddingHorizontal="13dp"
android:textSize="13sp"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginEnd="7dp"
android:layout_marginBottom="7dp"
android:button="@null"
Expand Down

0 comments on commit 94def5f

Please sign in to comment.