Skip to content

Commit

Permalink
Feat : Add sign up UI, custom calendarview, and autoLogin tukcomCD202…
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-g001 committed Jan 27, 2024
1 parent 662778c commit 9bd9538
Show file tree
Hide file tree
Showing 40 changed files with 1,025 additions and 19 deletions.
3 changes: 3 additions & 0 deletions android/HowAboutTrip/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ dependencies {
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-auth:22.3.0")
implementation("com.google.android.gms:play-services-auth:20.7.0")
implementation("com.squareup.retrofit:retrofit:2.0.0-beta2")
implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.12")
implementation("com.github.bumptech.glide:glide:5.0.0-rc01")


testImplementation("junit:junit:4.13.2")
Expand Down
20 changes: 14 additions & 6 deletions android/HowAboutTrip/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -14,11 +15,21 @@
android:theme="@style/Base.Theme.HowAboutTrip"
tools:targetApi="31">
<activity
android:name=".view.activity.LoginActivity"
android:name=".view.activity.SignUpActivity"
android:theme="@style/Theme.HowAboutTrip.BlackStatusBar"
android:exported="false" />
android:exported="false">
</activity>
<activity
android:name=".view.activity.LoginActivity"
android:exported="false"
android:theme="@style/Theme.HowAboutTrip.BlackStatusBar" />
<activity
android:name=".view.activity.SplashActivity"
android:exported="true"
android:theme="@style/Theme.HowAboutTrip.BlackStatusBar">
</activity>
<activity
android:name=".view.activity.MainActivity"
android:theme="@style/Theme.HowAboutTrip.BlackStatusBar"
android:exported="true">
<intent-filter>
Expand All @@ -27,9 +38,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.activity.MainActivity"
android:exported="false"/>
</application>

</manifest>
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
}
}
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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import com.google.firebase.auth.GoogleAuthProvider

class LoginRepository {
private val firebaseAuth = FirebaseAuth.getInstance()
private val _currentUserLiveData = MutableLiveData<FirebaseUser>()
private val _userLiveData = MutableLiveData<FirebaseUser>()
val currentUserLiveData : LiveData<FirebaseUser>
get() = _currentUserLiveData
val userLiveData: LiveData<FirebaseUser>
get() = _userLiveData

Expand All @@ -23,4 +26,15 @@ class LoginRepository {
}
}
}
fun checkCurrentUser() {
val currentUser = firebaseAuth.currentUser
if(currentUser != null){
Log.d("checkCurrentUser", "firebaseAuth.current != null\nemail : ${currentUser.email}\ndisplayName : ${currentUser.displayName}")
_currentUserLiveData.postValue(currentUser!!)
Log.d("checkCurrentUser", "_currentUserLiveData.value : ${_currentUserLiveData.value}")
Log.d("checkCurrentUser", "currentUserLiveData.value : ${currentUserLiveData.value}")
}else{
Log.d("checkCurrentUser", "firebaseAuth.current == null")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.project.how.model

class SignUpRepository {
}
Loading

0 comments on commit 9bd9538

Please sign in to comment.