From 2e74fe4dd377021749479152142401fb0cb62117 Mon Sep 17 00:00:00 2001 From: kimdowoo Date: Sun, 26 Mar 2023 15:34:38 +0900 Subject: [PATCH] =?UTF-8?q?[MIN-52]=20refactor=20:=20=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=83=81=EC=84=B8=20=EB=B3=B4=EA=B8=B0=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EC=88=98=EC=A0=95=20(#25)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetDropDown.xml | 17 ---- .../com/najudoryeong/mineme/MainActivity.kt | 10 +- .../com/najudoryeong/mineme/MainViewModel.kt | 3 + .../mineme/common_ui/CalendarUtil.kt | 2 +- ...tePickerNoDay.kt => DialogForDateNoDay.kt} | 42 ++++---- .../mineme/common_ui/DialogForDatePicker.kt | 3 +- .../layout/dialog_for_datepicker_no_day.xml | 83 ++++++++++++++++ .../mineme/home/ui/HomeViewModel.kt | 16 ++- .../story/domain/entity/DetailStoryData.kt | 24 +++++ .../mineme/story/ui/StoryDetailFragment.kt | 2 + .../mineme/story/ui/StoryFragment.kt | 26 ++--- .../mineme/story/ui/StoryViewModel.kt | 36 ++----- .../mineme/story/util/FragmentObject.kt | 2 +- .../main/res/layout/fragment_story_detail.xml | 99 ++++++++++++++++--- story/src/main/res/values/strings.xml | 1 + 15 files changed, 258 insertions(+), 108 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml rename common-ui/src/main/java/com/najudoryeong/mineme/common_ui/{DialogForDatePickerNoDay.kt => DialogForDateNoDay.kt} (56%) create mode 100644 common-ui/src/main/res/layout/dialog_for_datepicker_no_day.xml create mode 100644 story/src/main/java/com/najudoryeong/mineme/story/domain/entity/DetailStoryData.kt diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 75e2e61..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/najudoryeong/mineme/MainActivity.kt b/app/src/main/java/com/najudoryeong/mineme/MainActivity.kt index 942b5cb..fd87d01 100644 --- a/app/src/main/java/com/najudoryeong/mineme/MainActivity.kt +++ b/app/src/main/java/com/najudoryeong/mineme/MainActivity.kt @@ -2,6 +2,7 @@ package com.najudoryeong.mineme import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.util.Log import android.view.View import androidx.activity.viewModels import androidx.databinding.DataBindingUtil @@ -32,12 +33,11 @@ class MainActivity : AppCompatActivity(), MainActivityUtil { binding = DataBindingUtil.setContentView(this, R.layout.activity_main) binding.viewModel = model - initAppBar() initBottomNav() - } + private fun initBottomNav() { val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_containerView) as NavHostFragment @@ -55,8 +55,11 @@ class MainActivity : AppCompatActivity(), MainActivityUtil { setupWithNavController(navController) itemIconTintList = null } + } + + private fun initAppBar() { setSupportActionBar(binding.toolbar) supportActionBar?.run { @@ -73,8 +76,6 @@ class MainActivity : AppCompatActivity(), MainActivityUtil { } - - /** [MainActivityUtil] */ override fun setToolbarTitle(newTitle: String) { binding.toolbar.title = newTitle @@ -90,4 +91,5 @@ class MainActivity : AppCompatActivity(), MainActivityUtil { binding.topAppBar.visibility = visibilityMode } + } \ No newline at end of file diff --git a/app/src/main/java/com/najudoryeong/mineme/MainViewModel.kt b/app/src/main/java/com/najudoryeong/mineme/MainViewModel.kt index a4827d0..1a91862 100644 --- a/app/src/main/java/com/najudoryeong/mineme/MainViewModel.kt +++ b/app/src/main/java/com/najudoryeong/mineme/MainViewModel.kt @@ -1,9 +1,12 @@ package com.najudoryeong.mineme import androidx.lifecycle.ViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow class MainViewModel : ViewModel() { + /* private val _toolbarTitle = MutableLiveData() val toolbarTitle: LiveData diff --git a/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/CalendarUtil.kt b/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/CalendarUtil.kt index 8050629..122a414 100644 --- a/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/CalendarUtil.kt +++ b/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/CalendarUtil.kt @@ -34,7 +34,7 @@ class CalendarUtil { dateFormat.parse(textView.text.toString()) fun parseStringToDateNoDay(textView: TextView):Date? = - dateFormatNoDay.parse(textView.text.toString()+"-01") + dateFormatNoDay.parse(textView.text.toString()) fun getMonthFormat(month: String): String { return when (month.toInt()) { diff --git a/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePickerNoDay.kt b/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDateNoDay.kt similarity index 56% rename from common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePickerNoDay.kt rename to common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDateNoDay.kt index f769a5a..c6b2a4c 100644 --- a/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePickerNoDay.kt +++ b/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDateNoDay.kt @@ -1,24 +1,20 @@ package com.najudoryeong.mineme.common_ui -import android.annotation.SuppressLint + import android.app.Dialog import android.content.Context -import android.content.res.Resources import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle -import android.view.View -import android.widget.NumberPicker -import com.najudoryeong.mineme.common_ui.CalendarUtil.Companion.getDateNoDay -import com.najudoryeong.mineme.common_ui.databinding.DialogForDatepickerBinding +import android.util.Log +import com.najudoryeong.mineme.common_ui.databinding.DialogForDatepickerNoDayBinding import java.util.* -class DialogForDatePickerNoDay( - context: Context, - private val initDate: Date, - private val onClickPositiveButton: (String) -> Unit +class DialogForDateNoDay(context: Context, + private val initDate: Date, + private val onClickPositiveButton: (String) -> Unit ) : Dialog(context) { - private lateinit var binding: DialogForDatepickerBinding + private lateinit var binding: DialogForDatepickerNoDayBinding private var calendar: Calendar = Calendar.getInstance() init { @@ -27,15 +23,22 @@ class DialogForDatePickerNoDay( override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + Log.d("postTest","click Dalogtest") + + binding = DialogForDatepickerNoDayBinding.inflate(layoutInflater).apply { + + pickerYear.maxValue = 2099 + pickerYear.minValue = 1980 - binding = DialogForDatepickerBinding.inflate(layoutInflater).apply { - datePicker.init(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),1,null) + pickerYear.value = calendar.get(Calendar.YEAR) + + pickerMonth.maxValue = 12 + pickerMonth.minValue = 1 + + pickerMonth.value = calendar.get(Calendar.MONTH)+1 - val daySpinnerId = Resources.getSystem().getIdentifier("day", "id", "android") - val daySpinner = datePicker.findViewById(daySpinnerId) - daySpinner.visibility = View.GONE positiveButton.setOnClickListener { - onClickPositiveButton.invoke(datePicker.getDateNoDay()) + onClickPositiveButton.invoke("${pickerYear.value}-${pickerMonth.value}") dismiss() } negativeButton.setOnClickListener { @@ -49,7 +52,7 @@ class DialogForDatePickerNoDay( class Builder(private val context: Context) { private lateinit var initDate: Date - private var onClickPositiveButton : (String) -> Unit = {} + private var onClickPositiveButton: (String) -> Unit = {} fun setInitDate(initDate: Date) = apply { @@ -61,10 +64,11 @@ class DialogForDatePickerNoDay( } - fun build() = DialogForDatePicker( + fun build() = DialogForDateNoDay( context, initDate, onClickPositiveButton ) } + } \ No newline at end of file diff --git a/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePicker.kt b/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePicker.kt index 35f415f..748e011 100644 --- a/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePicker.kt +++ b/common-ui/src/main/java/com/najudoryeong/mineme/common_ui/DialogForDatePicker.kt @@ -6,6 +6,7 @@ import android.content.res.Resources import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle +import android.util.Log import android.view.View import com.najudoryeong.mineme.common_ui.CalendarUtil.Companion.getDate import com.najudoryeong.mineme.common_ui.databinding.DialogForDatepickerBinding @@ -25,7 +26,7 @@ class DialogForDatePicker( override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - + Log.d("postTest","click Dalog") binding = DialogForDatepickerBinding.inflate(layoutInflater).apply { datePicker.init(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH),null) positiveButton.setOnClickListener { diff --git a/common-ui/src/main/res/layout/dialog_for_datepicker_no_day.xml b/common-ui/src/main/res/layout/dialog_for_datepicker_no_day.xml new file mode 100644 index 0000000..3caa6ec --- /dev/null +++ b/common-ui/src/main/res/layout/dialog_for_datepicker_no_day.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/home/src/main/java/com/najudoryeong/mineme/home/ui/HomeViewModel.kt b/home/src/main/java/com/najudoryeong/mineme/home/ui/HomeViewModel.kt index 272f854..d3f48dc 100644 --- a/home/src/main/java/com/najudoryeong/mineme/home/ui/HomeViewModel.kt +++ b/home/src/main/java/com/najudoryeong/mineme/home/ui/HomeViewModel.kt @@ -20,7 +20,7 @@ class HomeViewModel @Inject constructor( ) : ViewModel() { private val _isNewStory = MutableStateFlow(true) - val isNewStory : StateFlow = _isNewStory + val isNewStory: StateFlow = _isNewStory private val _homeData = MutableStateFlow(null) val homeData: StateFlow = _homeData @@ -31,27 +31,25 @@ class HomeViewModel @Inject constructor( fun settingHomeData() { viewModelScope.launch { - var jwt = dataStoreUseCase.bearerJsonWebToken.first() - //todo 삭제 - if (jwt == null) jwt = "bearer test" + val jwt = dataStoreUseCase.bearerJsonWebToken.first()!! try { homeUseCase.readHomeInfo(jwt).let { - if (it != null){ - if (it.newStory.postId == -1){ + if (it != null) { + if (it.newStory.postId == -1) { _isNewStory.value = true } _homeData.value = it } else { - Log.d("TESTAPI","API실패") + Log.d("TESTAPI", "API실패") } } - }catch (e : Exception) { + } catch (e: Exception) { setToastMessage("메인 가져오는 거 실패") } } } - private fun setToastMessage(newMessage : String){ + private fun setToastMessage(newMessage: String) { _toastMessage.value = "" _toastMessage.value = newMessage } diff --git a/story/src/main/java/com/najudoryeong/mineme/story/domain/entity/DetailStoryData.kt b/story/src/main/java/com/najudoryeong/mineme/story/domain/entity/DetailStoryData.kt new file mode 100644 index 0000000..849c7d9 --- /dev/null +++ b/story/src/main/java/com/najudoryeong/mineme/story/domain/entity/DetailStoryData.kt @@ -0,0 +1,24 @@ +package com.najudoryeong.mineme.story.domain.entity + +data class DetailStoryData( + val List: +) + + + +data class DetailStory( + + val region : String, + val isAnniversary : String, + val anniversary : Anniversary, + val date : String, + val images : List, + val postId : Int, + val content : String, + val author : String +) + +data class Anniversary( + val type : String, + val day : Int +) \ No newline at end of file diff --git a/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryDetailFragment.kt b/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryDetailFragment.kt index 3f8d4cb..57fd81a 100644 --- a/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryDetailFragment.kt +++ b/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryDetailFragment.kt @@ -1,6 +1,7 @@ package com.najudoryeong.mineme.story.ui +import androidx.fragment.app.viewModels import androidx.navigation.fragment.navArgs import com.najudoryeong.mineme.common_ui.BaseFragment import com.najudoryeong.mineme.story.databinding.FragmentStoryDetailBinding @@ -11,6 +12,7 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class StoryDetailFragment : BaseFragment(DetailStoryFoundationInfo) { + private val storyViewModel: StoryViewModel by viewModels() private val args: StoryDetailFragmentArgs by navArgs() override fun initView() { diff --git a/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryFragment.kt b/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryFragment.kt index b81fdd5..d477a56 100644 --- a/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryFragment.kt +++ b/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryFragment.kt @@ -1,6 +1,7 @@ package com.najudoryeong.mineme.story.ui import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -8,15 +9,12 @@ import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.viewModels -import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.GridLayoutManager import com.najudoryeong.mineme.common_ui.BaseFragment import com.najudoryeong.mineme.common_ui.CalendarUtil -import com.najudoryeong.mineme.common_ui.DialogForDatePicker -import com.najudoryeong.mineme.common_ui.DialogForDatePickerNoDay +import com.najudoryeong.mineme.common_ui.DialogForDateNoDay import com.najudoryeong.mineme.story.CalendarAdapter import com.najudoryeong.mineme.story.R import com.najudoryeong.mineme.story.databinding.FragmentStoryBinding @@ -36,21 +34,13 @@ class StoryFragment : BaseFragment(StoryFoundationInfo) { private val storyOutAdapter: StoryOutAdapter by lazy { StoryOutAdapter(this) } private var nowView: Int = 0 - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { + override fun initView() { (activity as AppCompatActivity).run { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setHomeAsUpIndicator(R.drawable.img_story_menu) } - return super.onCreateView(inflater, container, savedInstanceState) - } - - override fun initView() { binding.apply { this.lifecycleOwner = viewLifecycleOwner this.adapter = storyOutAdapter @@ -62,14 +52,14 @@ class StoryFragment : BaseFragment(StoryFoundationInfo) { } this.calendarDate.text = CalendarUtil.getTodayDateNoDay() this.calendarDate.setOnClickListener { - DialogForDatePickerNoDay.Builder(requireContext()) + DialogForDateNoDay.Builder(requireContext()) .setInitDate(CalendarUtil.parseStringToDateNoDay(it as TextView)!!) - .setOnClickPositiveButton { newDate -> + .setOnClickPositiveButton { + newDate-> binding.calendarDate.text = newDate - dateList = getDatesInMonth(newDate.substring(0,4).toInt(), newDate.substring(5,6).toInt()) + dateList = getDatesInMonth(newDate.substring(0,4).toInt(), newDate.substring(5).toInt()) initCalendarView() - } - .build().show() + }.build().show() } } diff --git a/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryViewModel.kt b/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryViewModel.kt index dc5d4b9..d27ffce 100644 --- a/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryViewModel.kt +++ b/story/src/main/java/com/najudoryeong/mineme/story/ui/StoryViewModel.kt @@ -48,31 +48,14 @@ var dummy: MutableList = mutableListOf( ), StoryListWithDate( - "2020", "04", listOf( + "2023", "03", listOf( Story( - "2020-04-01", + "2023-03-14", 5, "마산", - "https://upload3.inven.co.kr/upload/2022/03/15/bbs/i16343629296.jpg?MW=800" - ), - Story( - "2020-04-02", - 6, - "마산11", - "https://upload3.inven.co.kr/upload/2022/03/15/bbs/i16343629296.jpg?MW=800" - ), - Story( - "2020-04-03", - 7, - "마산21", - "https://upload3.inven.co.kr/upload/2022/03/15/bbs/i16343629296.jpg?MW=800" - ), - Story( - "2020-04-04", - 8, - "마산31", - "https://upload3.inven.co.kr/upload/2022/03/15/bbs/i16343629296.jpg?MW=800" - ), + "https://mineme-bucket.s3.ap-northeast-2.amazonaws.com/buddyvet/prod/2/0811f026-4fda-4d28-a416-5b9f1f74b28d.jpg" + ) + ) ) ) @@ -112,27 +95,26 @@ class StoryViewModel @Inject constructor( } } - fun postNewStory(){ + fun postNewStory() { viewModelScope.launch { _isApiLoading.value = true try { storyUseCase.readStoryList(dataStoreUseCase.bearerJsonWebToken.first()!!).let { } - } catch (e : Exception){ + } catch (e: Exception) { } } } - - fun setToastMessage(newMessage : String){ + fun setToastMessage(newMessage: String) { _toastMessage.value = "" _toastMessage.value = newMessage } - fun setImage(newUriList: List){ + fun setImage(newUriList: List) { _imageUri.value = newUriList.toMutableList() } diff --git a/story/src/main/java/com/najudoryeong/mineme/story/util/FragmentObject.kt b/story/src/main/java/com/najudoryeong/mineme/story/util/FragmentObject.kt index 646f21c..c480451 100644 --- a/story/src/main/java/com/najudoryeong/mineme/story/util/FragmentObject.kt +++ b/story/src/main/java/com/najudoryeong/mineme/story/util/FragmentObject.kt @@ -10,7 +10,7 @@ object StoryFoundationInfo : FragmentInfoUtil { override val layoutID: Int get() = R.layout.fragment_story override val toolbarText: Int - get() = R.string.story + get() = R.string.diary override val menu: Int get() = R.menu.story_menu override val bottomNavi_visibility: Int diff --git a/story/src/main/res/layout/fragment_story_detail.xml b/story/src/main/res/layout/fragment_story_detail.xml index e04a61e..79e97e4 100644 --- a/story/src/main/res/layout/fragment_story_detail.xml +++ b/story/src/main/res/layout/fragment_story_detail.xml @@ -1,23 +1,100 @@ - - + + + + + + + - + + + + + + + + + + + + + + android:layout_height="wrap_content" + android:layout_marginVertical="16dp" + android:fontFamily="@font/cafe24_ssurround_air" + android:gravity="start" + android:paddingHorizontal="21dp" + android:text="sagasgsagasgsagasga\ngasgasg\nasdasd\nsadsad" + android:textColor="@color/black" + android:textSize="13sp" + app:layout_constraintTop_toBottomOf="@id/picture_layout" /> - + diff --git a/story/src/main/res/values/strings.xml b/story/src/main/res/values/strings.xml index 607cffa..36e0627 100644 --- a/story/src/main/res/values/strings.xml +++ b/story/src/main/res/values/strings.xml @@ -2,5 +2,6 @@ Hello blank fragment 스토리 + 일기 스토리 작성 \ No newline at end of file