forked from tukcomCD2024/ISP
-
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.
Feat : Add sign up UI, custom calendarview, and autoLogin tukcomCD202…
- Loading branch information
Showing
40 changed files
with
1,025 additions
and
19 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
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
154 changes: 154 additions & 0 deletions
154
android/HowAboutTrip/app/src/main/java/com/project/how/adapter/CalendarAdapter.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,154 @@ | ||
package com.project.how.adapter | ||
|
||
import android.graphics.Color | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.project.how.R | ||
import com.project.how.databinding.CalendarDayItemBinding | ||
import java.time.LocalDate | ||
|
||
class CalendarAdapter( | ||
repositoryDays : List<Int>, | ||
selectedDate : LocalDate, | ||
private val onItemClickListener : OnItemClickListener) | ||
: RecyclerView.Adapter<CalendarAdapter.ViewHolder>() { | ||
private var sd = selectedDate | ||
private var selected : MutableList<Boolean> = mutableListOf() | ||
private val selectedMonthDays : MutableMap<Int, MutableList<Boolean>> = mutableMapOf() | ||
private val selectedTwoDay : MutableMap<Int, LocalDate> = mutableMapOf() | ||
private var days = repositoryDays | ||
private var emptyCount = 0 | ||
private var dayCount = 1 | ||
private var selectedCount = 0 | ||
|
||
init { | ||
Log.d("CalendarAdapter", "init repositoryDays.size : ${repositoryDays.size}\n${days.size}") | ||
initSelected() | ||
} | ||
|
||
inner class ViewHolder(val binding : CalendarDayItemBinding) : RecyclerView.ViewHolder(binding.root){ | ||
fun bind(data: Int, position: Int){ | ||
if(data != EMPTY){ | ||
binding.day.text = dayCount++.toString() | ||
val firstSelected = selectedTwoDay[FIRST] | ||
val secondSelected = selectedTwoDay[SECOND] | ||
if(firstSelected != null && secondSelected != null){ | ||
if(firstSelected.month.value < secondSelected.month.value){ | ||
if((position - emptyCount) < secondSelected.dayOfMonth){ | ||
binding.day.setTextColor(Color.parseColor("#00000000")) | ||
binding.background.setBackgroundResource(R.color.black) | ||
} | ||
}else if(firstSelected.month.value > secondSelected.month.value){ | ||
if((position - emptyCount) < firstSelected.dayOfMonth){ | ||
binding.day.setTextColor(Color.parseColor("#00000000")) | ||
binding.background.setBackgroundResource(R.color.black) | ||
} | ||
}else{ | ||
if(firstSelected.dayOfMonth < secondSelected.dayOfMonth){ | ||
if((firstSelected.dayOfMonth < (position - emptyCount)) && (secondSelected.dayOfMonth > (position - emptyCount))) { | ||
binding.day.setTextColor(Color.parseColor("#00000000")) | ||
binding.background.setBackgroundResource(R.color.black) | ||
} | ||
}else if(firstSelected.dayOfMonth > secondSelected.dayOfMonth){ | ||
if((firstSelected.dayOfMonth > (position - emptyCount)) && (secondSelected.dayOfMonth < (position - emptyCount))) { | ||
binding.day.setTextColor(Color.parseColor("#00000000")) | ||
binding.background.setBackgroundResource(R.color.black) | ||
} | ||
} | ||
} | ||
} | ||
binding.day.setOnClickListener { | ||
// selected[position] = !selected[position] | ||
selectedTwoDay[selectedCount++%2] = sd.withDayOfMonth(position-emptyCount) | ||
val sd = sd.withDayOfMonth(position-emptyCount) | ||
onItemClickListener.onItemClickListener(data, selected, position, sd) | ||
} | ||
|
||
changeColor(binding, position) | ||
}else{ | ||
binding.day.text = " " | ||
emptyCount++ | ||
} | ||
|
||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = ViewHolder( | ||
CalendarDayItemBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
) | ||
|
||
override fun getItemCount(): Int = days.size | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val data = days[position] | ||
holder.bind(data, position) | ||
} | ||
|
||
fun update(newDays : List<Int>, sd: LocalDate){ | ||
days = newDays | ||
dayCount = 1 | ||
emptyCount = 0 | ||
observeMonthChange(sd) | ||
notifyDataSetChanged() | ||
} | ||
|
||
fun observeMonthChange(sd : LocalDate){ | ||
selectedMonthDays[this.sd.month.value] = selected | ||
this.sd = sd | ||
initSelected() | ||
} | ||
|
||
private fun initSelected(){ | ||
Log.d("CalendarAdapter", "Before ${selected.size}\n${days.size}") | ||
selected = mutableListOf() | ||
for(i in days.indices){ | ||
selected.add(false) | ||
} | ||
Log.d("CalendarAdapter", "After ${selected.size}\n${days.size}") | ||
} | ||
|
||
fun resetSelected(){ | ||
for(i in days.indices) | ||
selected[i] = false | ||
dayCount = 1 | ||
emptyCount = 0 | ||
notifyDataSetChanged() | ||
} | ||
|
||
private fun changeColor(binding: CalendarDayItemBinding, position: Int){ | ||
if(selected[position]){ | ||
binding.day.setTextColor(Color.parseColor("#FFFFFFFF")) | ||
binding.background.setBackgroundResource(R.drawable.black_oval_day_background) | ||
}else{ | ||
binding.day.setTextColor(Color.parseColor("#FF000000")) | ||
binding.background.setBackgroundResource(R.drawable.white_oval_day_background) | ||
} | ||
} | ||
|
||
fun getSelectedDays() : MutableMap<Int, LocalDate>?{ | ||
if (selectedTwoDay[FIRST] != null || selectedTwoDay[SECOND] != null) | ||
return selectedTwoDay | ||
return null | ||
} | ||
|
||
fun getSelectedDay() : LocalDate?{ | ||
if (selectedTwoDay[FIRST] != null) | ||
return selectedTwoDay[FIRST] | ||
return null | ||
} | ||
|
||
interface OnItemClickListener{ | ||
fun onItemClickListener(data : Int, selected : MutableList<Boolean>, position: Int, sd: LocalDate){} | ||
} | ||
companion object{ | ||
private val EMPTY = 99 | ||
private val FIRST = 0 | ||
private val SECOND = 1 | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
android/HowAboutTrip/app/src/main/java/com/project/how/model/CalendarRepository.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,73 @@ | ||
package com.project.how.model | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import java.time.LocalDate | ||
|
||
class CalendarRepository { | ||
private val nowDate = LocalDate.now() | ||
private val EMPTY = 99 | ||
private val _selectedDate = MutableLiveData<LocalDate>() | ||
val selectedDate : LiveData<LocalDate> | ||
get() = _selectedDate | ||
private lateinit var monthOfFirstDate : LocalDate | ||
private lateinit var sd : LocalDate | ||
private var monthOfFirstDayOfWeek = EMPTY | ||
private var lastDay = 0 | ||
|
||
private fun getMonthInform(fdw : Int) : Flow<List<Int>> = flow { | ||
val monthInfo = mutableListOf<Int>() | ||
lastDay = sd.lengthOfMonth() | ||
var week = fdw | ||
for (i in 0 until fdw) | ||
monthInfo.add(EMPTY) | ||
for(i in 1..lastDay){ | ||
monthInfo.add(week) | ||
week = (week+1) % 7 | ||
} | ||
this.emit(monthInfo) | ||
} | ||
|
||
private fun getMonthOfFirstDayOfWeekChangeInt() : Int { | ||
when(monthOfFirstDate.dayOfWeek.toString()){ | ||
"MONDAY" -> return 1 | ||
"TUESDAY" -> return 2 | ||
"WEDNESDAY" -> return 3 | ||
"THURSDAY" -> return 4 | ||
"FRIDAY" -> return 5 | ||
"SATURDAY" -> return 6 | ||
"SUNDAY" -> return 0 | ||
else -> { | ||
Log.e("getMonthOfFirstDayOfWeek", "monthOfFirstDate.dayOfWeek.toString() go to else case\n${monthOfFirstDate.dayOfWeek}") | ||
return 99} | ||
} | ||
} | ||
|
||
private fun getFirstDate(): Flow<List<Int>> { | ||
monthOfFirstDate = sd.withDayOfMonth(1)!! | ||
monthOfFirstDayOfWeek = getMonthOfFirstDayOfWeekChangeInt() | ||
return getMonthInform(monthOfFirstDayOfWeek) | ||
} | ||
|
||
fun plusSelectedDate(): Flow<List<Int>> { | ||
sd = sd.plusMonths(1) | ||
_selectedDate.postValue(sd) | ||
return getFirstDate() | ||
} | ||
|
||
fun minusSelectedDate(): Flow<List<Int>> { | ||
sd = sd.minusMonths(1) | ||
_selectedDate.postValue(sd) | ||
return getFirstDate() | ||
} | ||
|
||
fun init() : Flow<List<Int>>{ | ||
sd = nowDate | ||
_selectedDate.postValue(nowDate) | ||
return getFirstDate() | ||
} | ||
|
||
} |
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
4 changes: 4 additions & 0 deletions
4
android/HowAboutTrip/app/src/main/java/com/project/how/model/SignUpRepository.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,4 @@ | ||
package com.project.how.model | ||
|
||
class SignUpRepository { | ||
} |
Oops, something went wrong.