-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from hwicode/feature/custom-calendar
[Android][히데_라이너스] 달력 화면 기능 구현 진행
- Loading branch information
Showing
19 changed files
with
440 additions
and
51 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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/example/airbnb/data/RepositoryImpl.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,18 @@ | ||
package com.example.airbnb.data | ||
|
||
import com.example.airbnb.domain.Repository | ||
import com.example.airbnb.domain.model.CalendarDay | ||
import com.example.airbnb.ui.common.CalendarUtil | ||
import org.joda.time.LocalDateTime | ||
|
||
class RepositoryImpl : Repository { | ||
override fun getCalendarMap():Map<LocalDateTime, List<CalendarDay>> { | ||
var calendarMap: MutableMap<LocalDateTime, List<CalendarDay>> = mutableMapOf() | ||
val monthList = Array(12) { index -> LocalDateTime.now().plusMonths(index)} | ||
monthList.map { | ||
calendarMap.put(it, CalendarUtil.getDayList(it)) | ||
} | ||
|
||
return calendarMap | ||
} | ||
} |
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,9 @@ | ||
package com.example.airbnb.domain | ||
|
||
import com.example.airbnb.domain.model.CalendarDay | ||
|
||
|
||
interface Repository { | ||
|
||
fun getCalendarMap():Map<org.joda.time.LocalDateTime, List<CalendarDay>> | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/example/airbnb/domain/model/CalendarDay.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,10 @@ | ||
package com.example.airbnb.domain.model | ||
|
||
data class CalendarDay ( | ||
val month:Int, | ||
val day:String, | ||
var isStartDay:Boolean= false, | ||
var isSelectable:Boolean=true, | ||
var isSelected:Boolean=false, | ||
var isInRange:Boolean=false | ||
) |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/example/airbnb/ui/calendar/CalendarFragment.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,32 @@ | ||
package com.example.airbnb.ui.calendar | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import com.example.airbnb.R | ||
import com.example.airbnb.databinding.FragmentCalendarBinding | ||
|
||
class CalendarFragment : Fragment() { | ||
|
||
private val viewModel: CalendarViewModel by viewModels() | ||
private lateinit var binding: FragmentCalendarBinding | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_calendar, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val monthAdapter = MonthAdapter() | ||
binding.rvCalendar.adapter = monthAdapter | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/example/airbnb/ui/calendar/CalendarViewModel.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,15 @@ | ||
package com.example.airbnb.ui.calendar | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.example.airbnb.data.RepositoryImpl | ||
import com.example.airbnb.domain.Repository | ||
import com.example.airbnb.domain.model.CalendarDay | ||
import org.joda.time.LocalDateTime | ||
|
||
class CalendarViewModel :ViewModel(){ | ||
|
||
private val repository: Repository= RepositoryImpl() | ||
fun getCalendarMap(): Map<LocalDateTime, List<CalendarDay>> { | ||
return repository.getCalendarMap() | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/example/airbnb/ui/calendar/DayAdapter.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,51 @@ | ||
package com.example.airbnb.ui.calendar | ||
|
||
import android.graphics.Color | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.view.isVisible | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.airbnb.R | ||
import com.example.airbnb.databinding.ItemCalendarDayBinding | ||
import com.example.airbnb.domain.model.CalendarDay | ||
|
||
class DayAdapter : RecyclerView.Adapter<DayAdapter.ViewHolder>() { | ||
|
||
private val dayList = mutableListOf<CalendarDay>() | ||
|
||
class ViewHolder(private val binding: ItemCalendarDayBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun bind(day:CalendarDay) { | ||
binding.day = day.day | ||
if(day.isSelectable){ | ||
if(day.isStartDay){ | ||
binding.tvCalendarDay.setBackgroundColor(Color.GREEN) | ||
} | ||
binding.tvCalendarDay.setTextColor(Color.BLACK) | ||
} | ||
else{ | ||
binding.tvCalendarDay.setTextColor(Color.GRAY) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return DayAdapter.ViewHolder(ItemCalendarDayBinding.inflate(inflater, parent, false)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.bind(dayList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return dayList.size | ||
} | ||
|
||
fun submitList(list:List<CalendarDay>){ | ||
this.dayList.addAll(list) | ||
} | ||
|
||
|
||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/example/airbnb/ui/calendar/MonthAdapter.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,41 @@ | ||
package com.example.airbnb.ui.calendar | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.airbnb.databinding.ItemCalendarMonthBinding | ||
import com.example.airbnb.ui.common.CalendarUtil | ||
import org.joda.time.LocalDateTime | ||
|
||
class MonthAdapter : RecyclerView.Adapter<MonthAdapter.ViewHolder>() { | ||
|
||
private val _monthList = Array(12) { index -> | ||
LocalDateTime.now().plusMonths(index) | ||
} | ||
|
||
|
||
class ViewHolder(private val binding: ItemCalendarMonthBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun bind(dateTime: LocalDateTime) { | ||
binding.tvCalendarMonth.text = dateTime.toDateTime().toString("YYYY년 MM월") | ||
val dayAdapter= DayAdapter() | ||
binding.rvCalendarMonth.adapter= dayAdapter | ||
dayAdapter.submitList(CalendarUtil.getDayList(dateTime)) | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return MonthAdapter.ViewHolder(ItemCalendarMonthBinding.inflate(inflater, parent, false)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.bind(_monthList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return _monthList.size | ||
} | ||
|
||
|
||
} |
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/example/airbnb/ui/common/CalendarUtil.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,87 @@ | ||
package com.example.airbnb.ui.common | ||
|
||
import com.example.airbnb.domain.model.CalendarDay | ||
import kotlin.math.absoluteValue | ||
|
||
object CalendarUtil { | ||
|
||
fun getDayList(date: org.joda.time.LocalDateTime): ArrayList<CalendarDay> { | ||
val yearMonth = date.monthOfYear().localDateTime | ||
val lastDay = yearMonth.dayOfMonth().withMaximumValue().values[2] | ||
val firstDay = date.withDayOfMonth(1) | ||
val dayOfWeek = firstDay.dayOfWeek.absoluteValue | ||
return if (dayOfWeek != 7) { | ||
getDayListNotStartWithSunday(date.monthOfYear, dayOfWeek, lastDay) | ||
} else { | ||
getDayListStartWithSunday(date.monthOfYear, dayOfWeek, lastDay) | ||
} | ||
} | ||
|
||
private fun getDayListStartWithSunday(month:Int, dayOfWeek: Int, lastDay: Int): ArrayList<CalendarDay> { | ||
val dayList = arrayListOf<CalendarDay>() | ||
val isInStartMonth = (org.joda.time.LocalDateTime.now().monthOfYear == month) | ||
val nowDay = org.joda.time.LocalDateTime.now().dayOfMonth | ||
for (i in 8..49) { | ||
if (i <= dayOfWeek || i > lastDay + dayOfWeek) { | ||
dayList.add(CalendarDay(month, "")) | ||
} else { | ||
val day = ((i - dayOfWeek).toString()) | ||
if (isInStartMonth) { | ||
dayList.add(CalendarDay(month, day, day.toInt()==nowDay, day.toInt() >= nowDay)) | ||
} else { | ||
dayList.add(CalendarDay(month, day)) | ||
} | ||
} | ||
} | ||
return dayList | ||
} | ||
|
||
private fun getDayListNotStartWithSunday(month: Int, dayOfWeek: Int, lastDay: Int): ArrayList<CalendarDay> { | ||
val dayList = arrayListOf<CalendarDay>() | ||
val isInStartMonth = (org.joda.time.LocalDateTime.now().monthOfYear == month) | ||
val nowDay = org.joda.time.LocalDateTime.now().dayOfMonth | ||
for (i in 1..42) { | ||
if (i <= dayOfWeek || i > lastDay + dayOfWeek) { | ||
dayList.add(CalendarDay(month, "")) | ||
} else { | ||
val day = ((i - dayOfWeek).toString()) | ||
|
||
if (isInStartMonth) { | ||
dayList.add(CalendarDay(month, day, day.toInt()==nowDay,day.toInt() > nowDay)) | ||
} else { | ||
dayList.add(CalendarDay(month, day)) | ||
} | ||
} | ||
|
||
} | ||
return dayList | ||
} | ||
} | ||
|
||
// | ||
//private fun getDayList(date: LocalDate):ArrayList<String> { | ||
// val dayLit = arrayListOf<String>() | ||
// val yearMonth = YearMonth.from(date) | ||
// val lastDay = yearMonth.lengthOfMonth() | ||
// val firstDay = date.withDayOfMonth(1) | ||
// val dayOfWeek = firstDay.dayOfWeek.value | ||
// | ||
// if (dayOfWeek != 7) { | ||
// for (i in 1..42) { | ||
// if (i <= dayOfWeek || i > lastDay + dayOfWeek) { | ||
// dayLit.add("") | ||
// } else { | ||
// dayLit.add((i - dayOfWeek).toString()) | ||
// } | ||
// } | ||
// } else { | ||
// for (i in 8..49) { | ||
// if (i <= dayOfWeek || i > lastDay + dayOfWeek) { | ||
// dayLit.add("") | ||
// } else { | ||
// dayLit.add((i - dayOfWeek).toString()) | ||
// } | ||
// } | ||
// } | ||
// return dayLit | ||
//} |
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
16 changes: 3 additions & 13 deletions
16
app/src/main/java/com/example/airbnb/ui/information/InformationInputFragment.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 |
---|---|---|
@@ -1,43 +1,33 @@ | ||
package com.example.airbnb.ui.information | ||
|
||
import android.content.res.ColorStateList | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.RequiresApi | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.graphics.drawable.DrawableCompat | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.NavController | ||
import com.example.airbnb.R | ||
import com.example.airbnb.databinding.FragmentInformationInputBinding | ||
|
||
|
||
class InformationInputFragment : Fragment() { | ||
|
||
private lateinit var binding: FragmentInformationInputBinding | ||
private lateinit var navigator: NavController | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
): View { | ||
|
||
binding = | ||
DataBindingUtil.inflate(inflater, R.layout.fragment_information_input, container, false) | ||
return binding.root | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val menu = binding.tbarInformationInput.menu | ||
binding.tbarInformationInput.setNavigationOnClickListener { | ||
|
||
} | ||
val icon= menu.getItem(0).icon | ||
DrawableCompat.setTint(icon,(ContextCompat.getColor(requireContext(), R.color.pink))) | ||
} | ||
|
||
} |
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
Oops, something went wrong.