Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sumdays/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ dependencies {
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation("com.google.android.material:material:1.9.0")
implementation(libs.androidx.compose.ui.text)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
101 changes: 69 additions & 32 deletions Sumdays/app/src/main/java/com/example/sumdays/CalendarActivity.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// CalendarActivity.kt
package com.example.sumdays

import android.app.Activity
Expand All @@ -9,8 +8,10 @@ import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.NumberPicker // [변경] 기본 위젯 import
import android.widget.TextView
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
Expand All @@ -22,15 +23,18 @@ import com.example.sumdays.calendar.CalendarLanguage
import com.example.sumdays.calendar.MonthAdapter
import com.example.sumdays.data.viewModel.CalendarViewModel
import com.example.sumdays.utils.setupEdgeToEdge
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.jakewharton.threetenabp.AndroidThreeTen
// import com.shawnlin.numberpicker.NumberPicker [삭제]
import org.threeten.bp.LocalDate
import org.threeten.bp.YearMonth
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.temporal.ChronoUnit
import java.util.Locale


class CalendarActivity : AppCompatActivity() {

// ... (기존 변수 선언 동일) ...
private lateinit var calendarViewPager: ViewPager2
private lateinit var tvMonthYear: TextView
private lateinit var monthAdapter: MonthAdapter
Expand All @@ -40,12 +44,9 @@ class CalendarActivity : AppCompatActivity() {
private val viewModel: CalendarViewModel by viewModels()
var currentStatusMap: Map<String, Pair<Boolean, String?>> = emptyMap()
private var currentMonthLiveData: LiveData<Map<String, Pair<Boolean, String?>>>? = null


// 캘린더 언어 설정
private var currentLanguage: CalendarLanguage = CalendarLanguage.KOREAN
private val today: LocalDate by lazy { LocalDate.now() }
private val currentYearMonth: YearMonth by lazy { YearMonth.from(today) }
private val CENTER_POSITION = Int.MAX_VALUE / 2

@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -62,31 +63,29 @@ class CalendarActivity : AppCompatActivity() {
setStatisticBtnListener()
setNavigationBar()

// 상태바, 네비게이션바 같은 색으로
tvMonthYear.setOnClickListener {
showYearMonthPicker()
}

val rootView = findViewById<View>(R.id.root_layout)
setupEdgeToEdge(rootView)

// 최초 실행 여부를 판단
val pref: SharedPreferences = getSharedPreferences("checkFirst", Activity.MODE_PRIVATE);
val checkFirst = pref.getBoolean("checkFirst", false);
// val checkFirst = false

val pref: SharedPreferences = getSharedPreferences("checkFirst", Activity.MODE_PRIVATE)
val checkFirst = pref.getBoolean("checkFirst", false)

// false일 경우 튜토리얼 최초 실행
if (!checkFirst) {
// 앱 최초 실행시 하고 싶은 작업
val editor = pref.edit()
editor.putBoolean("checkFirst", true)
editor.apply()

val intent: Intent = Intent(this, TutorialActivity::class.java)
finish()
val intent = Intent(this, TutorialActivity::class.java)
startActivity(intent)
}
}

// ... (setStatisticBtnListener, setNavigationBar, setCustomCalendar 등 기존 함수 동일) ...
private fun setStatisticBtnListener() {
val btnStats = findViewById<ImageButton>(R.id.statistic_btn)

btnStats.setOnClickListener {
val intent = Intent(this, StatisticsActivity::class.java)
startActivity(intent)
Expand Down Expand Up @@ -115,13 +114,11 @@ class CalendarActivity : AppCompatActivity() {
}
}

/** setCustomCalendar: 달력의 스크롤, 버튼에 의한 달 전환과 현재 월을 표시 */
@RequiresApi(Build.VERSION_CODES.O)
private fun setCustomCalendar() {
monthAdapter = MonthAdapter(activity = this)
calendarViewPager.adapter = monthAdapter

// 0. 언어에 따른 헤더 설정
val headerLayout = findViewById<LinearLayout>(R.id.day_of_week_header)
headerLayout.removeAllViews()

Expand All @@ -145,19 +142,15 @@ class CalendarActivity : AppCompatActivity() {
headerLayout.addView(tv)
}

// 1. Scroll로 달 전환: 중앙에서 시작
val startPosition = Int.MAX_VALUE / 2
calendarViewPager.setCurrentItem(startPosition, false)

calendarViewPager.setCurrentItem(CENTER_POSITION, false)
calendarViewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
updateMonthYearTitle(position)
observeMonthlyData(position) // 월 변경 시 데이터 구독 갱신
observeMonthlyData(position)
}
})

// 2. 이전/다음 달 버튼으로 달 전환 (미래 달 진입 방지)
btnPrevMonth.setOnClickListener {
val currentItem = calendarViewPager.currentItem
calendarViewPager.setCurrentItem(currentItem - 1, true)
Expand All @@ -168,12 +161,10 @@ class CalendarActivity : AppCompatActivity() {
calendarViewPager.setCurrentItem(nextPos, true)
}

// 현재 월 표시 & 데이터 구독
updateMonthYearTitle(startPosition)
observeMonthlyData(startPosition)
updateMonthYearTitle(CENTER_POSITION)
observeMonthlyData(CENTER_POSITION)
}

/** 특정 position(월)에 해당하는 데이터를 구독 */
@RequiresApi(Build.VERSION_CODES.O)
private fun observeMonthlyData(position: Int) {
val targetMonth = getTargetMonthForPosition(position)
Expand All @@ -188,7 +179,6 @@ class CalendarActivity : AppCompatActivity() {
}
}

/** 입력 받은 position 위치의 달/년도 계산하여 반환함 */
@RequiresApi(Build.VERSION_CODES.O)
private fun updateMonthYearTitle(position: Int) {
val targetMonth = getTargetMonthForPosition(position)
Expand All @@ -200,10 +190,57 @@ class CalendarActivity : AppCompatActivity() {
tvMonthYear.text = targetMonth.format(formatter)
}

@RequiresApi(Build.VERSION_CODES.O)
private fun getTargetMonthForPosition(position: Int): YearMonth {
val baseYearMonth = YearMonth.now()
val startPosition = Int.MAX_VALUE / 2
val monthDiff = position - startPosition
val monthDiff = position - CENTER_POSITION
return baseYearMonth.plusMonths(monthDiff.toLong())
}

// -------------------------------------------------------------
// [수정된 함수] 기본 NumberPicker를 사용하도록 변경
// -------------------------------------------------------------
@RequiresApi(Build.VERSION_CODES.O)
private fun showYearMonthPicker() {
val dialog = BottomSheetDialog(this)
val view = layoutInflater.inflate(R.layout.dialog_year_month_picker, null)
dialog.setContentView(view)

// XML에서 기본 위젯(<NumberPicker>)을 사용했으므로 타입도 맞춰줍니다.
val npYear = view.findViewById<NumberPicker>(R.id.np_year)
val npMonth = view.findViewById<NumberPicker>(R.id.np_month)
val btnConfirm = view.findViewById<Button>(R.id.btn_confirm)

// 초기값 계산
val currentPosition = calendarViewPager.currentItem
val currentTarget = getTargetMonthForPosition(currentPosition)

// 연도 설정 (2000 ~ 2099)
npYear.minValue = 2000
npYear.maxValue = 2099
npYear.value = currentTarget.year
npYear.wrapSelectorWheel = false // 연도는 뺑뺑이 안 돌게

// 월 설정 (1 ~ 12)
npMonth.minValue = 1
npMonth.maxValue = 12
npMonth.value = currentTarget.monthValue
npMonth.wrapSelectorWheel = true // 월은 12에서 1로 돌아가게

btnConfirm.setOnClickListener {
val selectedYear = npYear.value
val selectedMonth = npMonth.value

val targetYearMonth = YearMonth.of(selectedYear, selectedMonth)
val baseYearMonth = YearMonth.now()

val monthDiff = ChronoUnit.MONTHS.between(baseYearMonth, targetYearMonth)
val newPosition = CENTER_POSITION + monthDiff.toInt()

calendarViewPager.setCurrentItem(newPosition, false)
dialog.dismiss()
}

dialog.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ class DailyWriteActivity : AppCompatActivity() {
editText.setText(memo.content)

builder.setView(dialogView)
.setPositiveButton("삭제") { dialog, id ->
memoViewModel.delete(memo)
dialog.dismiss()
}
.setNegativeButton("수정") { dialog, id ->
.setPositiveButton("수정") { dialog, id ->
val newContent = editText.text.toString().trim()
if (newContent.isNotEmpty()) {
val updatedMemo = memo.copy(content = newContent)
Expand All @@ -358,6 +354,10 @@ class DailyWriteActivity : AppCompatActivity() {
Toast.makeText(this, "내용을 입력해 주세요.", Toast.LENGTH_SHORT).show()
}
}
.setNegativeButton("삭제") { dialog, id ->
memoViewModel.delete(memo)
dialog.dismiss()
}
.setNeutralButton("취소") { dialog, id ->
dialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ class DayAdapter(
}
if (isToday) {
val density = itemView.context.resources.displayMetrics.density
val size = (20 * density).toInt() // 32dp 크기로 고정 (원하는 크기로 조절 가능)
val width = (20 * density).toInt() // 가로 20dp
val height = (17 * density).toInt() // 세로 14dp (원하는 만큼 줄이세요)

val params = tvDayNumber.layoutParams
params.width = size
params.height = size
params.width = width
params.height = height
tvDayNumber.layoutParams = params

val drawable = GradientDrawable()
Expand Down
58 changes: 58 additions & 0 deletions Sumdays/app/src/main/res/layout/dialog_year_month_picker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#282d35"
android:padding="24dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="날짜 이동"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginBottom="24dp"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<!-- 연도 선택 (Year) : 기본 NumberPicker에 테마 적용 -->
<NumberPicker
android:id="@+id/np_year"
android:layout_width="wrap_content"
android:layout_height="180dp"
android:layout_marginEnd="16dp"
android:theme="@style/Theme.WhiteNumberPicker"
android:descendantFocusability="blocksDescendants" />

<!-- 월 선택 (Month) : 기본 NumberPicker에 테마 적용 -->
<NumberPicker
android:id="@+id/np_month"
android:layout_width="wrap_content"
android:layout_height="180dp"
android:layout_marginStart="16dp"
android:theme="@style/Theme.WhiteNumberPicker"
android:descendantFocusability="blocksDescendants" />

</LinearLayout>

<Button
android:id="@+id/btn_confirm"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginTop="32dp"
android:text="이동하기"
android:textSize="16sp"
android:textStyle="bold"
android:backgroundTint="#4A90E2"
android:textColor="#FFFFFF"
app:cornerRadius="12dp"/>

</LinearLayout>
7 changes: 6 additions & 1 deletion Sumdays/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@
<!-- 배경 흰색 + 둥근 모서리 drawable 쓰면 더 예쁨 (있으면) -->
<item name="android:windowBackground">@drawable/bg_tutorial_popup</item>
</style>

<style name="Theme.WhiteNumberPicker" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorControlNormal">#FFFFFF</item> <!-- 구분선 색상 -->
<item name="android:textColorPrimary">#FFFFFF</item> <!-- 선택된 텍스트 색상 -->
<item name="android:textColorSecondary">#80FFFFFF</item> <!-- 선택되지 않은 텍스트 색상 -->
<item name="android:textSize">20sp</item>
</style>
</resources>
Loading
Loading