Skip to content

Commit

Permalink
Merge branch 'develop' into feature/alarm-box-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
m6z1 committed Feb 21, 2024
2 parents e6c60f1 + 014b37a commit 781d71f
Show file tree
Hide file tree
Showing 37 changed files with 795 additions and 438 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
android:exported="false" />
<activity
android:name=".ui.view.main.MainActivity"
android:exported="false" />
android:exported="false"
android:windowSoftInputMode="adjustPan" />
<!-- Firebase Cloud Messaging -->
<service
android:name=".service.FCMService"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dongyang.android.youdongknowme.function

import android.content.Context
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.widget.TextView
import androidx.core.content.ContextCompat.getColor
import com.dongyang.android.youdongknowme.R

fun setSpanText(mContext: Context, spanTextView: TextView, startIdx: Int, endIdx: Int) {
SpannableStringBuilder(spanTextView.text).apply {
setSpan(
ForegroundColorSpan(getColor(mContext, R.color.blue300)),
startIdx,
endIdx,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
spanTextView.text = this
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.dongyang.android.youdongknowme.standard.base

import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
Expand Down Expand Up @@ -28,6 +32,18 @@ abstract class BaseActivity<T : ViewDataBinding, R : BaseViewModel> : AppCompatA
initAfterBinding()
}

protected fun setSpanText(spanTextView: TextView, startIdx: Int, endIdx: Int){
SpannableStringBuilder(spanTextView.text).apply {
setSpan(
ForegroundColorSpan(getColor(com.dongyang.android.youdongknowme.R.color.main)),
startIdx,
endIdx,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
spanTextView.text = this
}
}

protected fun showToast(message: String) {
applicationContext.toast(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,20 @@ private val defaultKeywordList = arrayListOf(
KeywordEntity("수강", "course", false),
KeywordEntity("특강", "lecture", false),
KeywordEntity("계절학기", "season", false),
KeywordEntity("장학", "scholarship", false),
KeywordEntity("등록", "tuition", false),
KeywordEntity("휴학", "leave", false),
KeywordEntity("복학", "return", false),
KeywordEntity("졸업", "graduation", false),
KeywordEntity("전과", "transfer", false),
KeywordEntity("학기포기", "drop", false),
KeywordEntity("장학", "scholarship", false),
KeywordEntity("국가장학", "nationalScholarship", false),
KeywordEntity("등록", "tuition", false),
KeywordEntity("채용", "recruitment", false),
KeywordEntity("공모전", "contest", false),
KeywordEntity("현장실습", "field", false),
KeywordEntity("대회", "competition", false),
KeywordEntity("현장실습", "field", false),
KeywordEntity("봉사", "service", false),
KeywordEntity("기숙사", "dormitory", false),
KeywordEntity("코로나19", "corona", false),
KeywordEntity("동아리", "club", false),
KeywordEntity("학생회", "studentCouncil", false),
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@ class CafeteriaContainer(
bind.itemCalendarDay.text = dayFormatter.format(day.date)
bind.itemCalendarMonth.text = monthFormatter.format(day.date)

bind.itemCalendarDate.setTextColor(
ContextCompat.getColor(
view.context,
if (day.date == viewModel.selectedDate.value) {
R.color.main
} else {
R.color.black
}
if (day.date == viewModel.selectedDate.value) {
bind.mvItemCalendarDate.setCardBackgroundColor(
ContextCompat.getColor(
view.context,
R.color.blue300
)
)
)
bind.itemCalendarDate.setTextColor(ContextCompat.getColor(view.context, R.color.white))
} else {
bind.mvItemCalendarDate.setCardBackgroundColor(
ContextCompat.getColor(
view.context,
R.color.white
)
)
bind.itemCalendarDate.setTextColor(ContextCompat.getColor(view.context, R.color.black))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.dongyang.android.youdongknowme.ui.view.cafeteria

import android.view.MenuItem
import android.view.View
import androidx.appcompat.view.menu.MenuAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.window.layout.WindowMetricsCalculator
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.FragmentCafeteriaBinding
Expand All @@ -26,62 +29,42 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo

private lateinit var stuKoreanMenuAdapter: CafeteriaAdapter
private lateinit var stuAnotherMenuAdapter: CafeteriaAdapter
private lateinit var eduKoreanMenuAdapter: CafeteriaAdapter
private lateinit var eduAnotherMenuAdapter: CafeteriaAdapter

override fun initStartView() {
binding.vm = viewModel

stuKoreanMenuAdapter = CafeteriaAdapter()
stuAnotherMenuAdapter = CafeteriaAdapter()
eduKoreanMenuAdapter = CafeteriaAdapter()
eduAnotherMenuAdapter = CafeteriaAdapter()

binding.cafeteriaStuKoreanMenuList.apply {
binding.rvCafeteriaMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
this.adapter = this@CafeteriaFragment.stuKoreanMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}

binding.cafeteriaStuAnotherMenuList.apply {
binding.rvCafeteriaAnotherMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
this.adapter = this@CafeteriaFragment.stuAnotherMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}

binding.cafeteriaEduKoreanMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
this.adapter = this@CafeteriaFragment.eduKoreanMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}

binding.cafeteriaEduAnotherMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
this.adapter = this@CafeteriaFragment.eduAnotherMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}

val wmc =
WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity())

binding.cafeteriaCalendar.apply {
binding.cvCafeteriaCalendar.apply {
val dayWidth = wmc.bounds.width() / 5
val dayHeight: Int = (dayWidth * 1.25).toInt()

daySize = Size(dayWidth, dayHeight)
}

binding.cafeteriaCalendar.dayBinder = object : DayBinder<CafeteriaContainer> {
binding.cvCafeteriaCalendar.dayBinder = object : DayBinder<CafeteriaContainer> {
override fun create(view: View): CafeteriaContainer =
CafeteriaContainer(view, binding.cafeteriaCalendar, viewModel)
CafeteriaContainer(view, binding.cvCafeteriaCalendar, viewModel)

override fun bind(container: CafeteriaContainer, day: CalendarDay) = container.bind(day)
}
Expand All @@ -103,20 +86,16 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
stuAnotherMenuAdapter.submitList(it.second)
}

viewModel.eduMenus.observe(viewLifecycleOwner) {
eduKoreanMenuAdapter.submitList(it.first)
eduAnotherMenuAdapter.submitList(it.second)
}
}

override fun initAfterBinding() {
binding.cafeteriaCalendar.setup(
binding.cvCafeteriaCalendar.setup(
YearMonth.now().minusMonths(2),
YearMonth.now().plusMonths(1),
DayOfWeek.values().random()
)

binding.cafeteriaCalendar.scrollToDate(LocalDate.now().minusDays(2))
binding.cvCafeteriaCalendar.scrollToDate(LocalDate.now().minusDays(2))

binding.cafeteriaErrorContainer.refresh.setOnClickListener {
viewModel.fetchCafeteria()
Expand All @@ -127,7 +106,7 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
super.onPause()
notifyDateChanged(
viewModel,
binding.cafeteriaCalendar,
binding.cvCafeteriaCalendar,
viewModel.selectedDate.value,
LocalDate.now()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class CafeteriaViewModel(
private val _stuMenus: MutableLiveData<Pair<List<String>, List<String>>> = MutableLiveData()
val stuMenus: LiveData<Pair<List<String>, List<String>>> = _stuMenus

private val _eduMenus: MutableLiveData<Pair<List<String>, List<String>>> = MutableLiveData()
val eduMenus: LiveData<Pair<List<String>, List<String>>> = _eduMenus

init {
fetchCafeteria()
}
Expand Down Expand Up @@ -77,12 +74,7 @@ class CafeteriaViewModel(
it.date == selectedDate && it.restaurant == resourceProvider.getString(R.string.cafeteria_student) && it.menuContent != "-"
}?.menuContent ?: ""

val eduMenu = cafeteriaList.find {
it.date == selectedDate && it.restaurant == resourceProvider.getString(R.string.cafeteria_employee) && it.menuContent != "-"
}?.menuContent ?: ""

_stuMenus.value = parsingMenu(stuMenu)
_eduMenus.value = parsingMenu(eduMenu)
}

private fun parsingMenu(menu: String): Pair<List<String>, List<String>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.LinearLayoutManager
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ActivityDepartBinding
import com.dongyang.android.youdongknowme.function.setSpanText
import com.dongyang.android.youdongknowme.ui.adapter.DepartAdapter
import com.dongyang.android.youdongknowme.ui.view.keyword.KeywordActivity
import com.dongyang.android.youdongknowme.ui.view.main.MainActivity
Expand All @@ -33,6 +34,9 @@ class DepartActivity : AppCompatActivity(), DepartClickListener {

viewModel.checkFirstLaunch()

// 부분 색상 지정
setSpanText(baseContext, binding.tvDepartTitleMain, startIdx = 0, endIdx = 5)

// 학과 리스트
val items =
resources.getStringArray(R.array.dmu_department_list).toCollection(ArrayList<String>())
Expand All @@ -43,16 +47,12 @@ class DepartActivity : AppCompatActivity(), DepartClickListener {
setItemClickListener(this@DepartActivity)
}

binding.departRcv.apply {
binding.rvDepart.apply {
this.adapter = this@DepartActivity.adapter
this.layoutManager = LinearLayoutManager(this@DepartActivity)
this.setHasFixedSize(true)
}

binding.departToolbar.tvToolbarExitButton.setOnClickListener {
finish()
}

// 선택 포지션을 실시간 옵저빙
viewModel.selectDepartPosition.observe(this) {
adapter.submitPosition(it)
Expand All @@ -70,10 +70,14 @@ class DepartActivity : AppCompatActivity(), DepartClickListener {
// 확인 버튼을 누르면 내부 DB에 학과를 담고 메인 액티비티로 이동
private fun getSnackBar(items: ArrayList<String>): Snackbar {
val snackbar =
Snackbar.make(binding.departContainer, getString(R.string.department_snackbar_title), LENGTH_LONG)
Snackbar.make(
binding.coordinatorDepart,
getString(R.string.department_snackbar_title),
LENGTH_LONG
)
.setAction(getString(R.string.department_snackbar_positive_button)) {
viewModel.setDepartment(items[viewModel.selectDepartPosition.value ?: 0])
if(viewModel.isFirstLaunch.value == true) {
if (viewModel.isFirstLaunch.value == true) {
val intent = Intent(this, KeywordActivity::class.java)
startActivity(intent)
finish()
Expand All @@ -87,23 +91,24 @@ class DepartActivity : AppCompatActivity(), DepartClickListener {
override fun onShown(transientBottomBar: Snackbar?) {
super.onShown(transientBottomBar)

binding.departRcv.updateLayoutParams<ViewGroup.MarginLayoutParams> {
binding.rvDepart.updateLayoutParams<ViewGroup.MarginLayoutParams> {
setMargins(0, 0, 0, transientBottomBar?.view?.height ?: 0)
}
}

override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)

binding.departRcv.updateLayoutParams<ViewGroup.MarginLayoutParams> {
binding.rvDepart.updateLayoutParams<ViewGroup.MarginLayoutParams> {
setMargins(0, 0, 0, 0)
}
}
})


val snackBarView = snackbar.view
val snackBarText = snackBarView.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)
val snackBarText =
snackBarView.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)
snackBarText.typeface = Typeface.createFromAsset(this.assets, "pretendard_regular.otf")

snackbar.animationMode = BaseTransientBottomBar.ANIMATION_MODE_SLIDE
Expand Down
Loading

0 comments on commit 781d71f

Please sign in to comment.