Skip to content

Commit

Permalink
Merge pull request #24 from nocap-stone-design/feature/#23-custom-toast
Browse files Browse the repository at this point in the history
[BUD-39] feat : customToast 구현(#23)
  • Loading branch information
KDW03 authored Apr 5, 2023
2 parents f861f26 + 2311bd9 commit b41bafe
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {

api project(path: ':foundation')

implementation 'com.github.Spikeysanju:MotionToast:1.4'
implementation 'de.hdodenhof:circleimageview:3.1.0'

api "androidx.navigation:navigation-fragment-ktx:$rootProject.nav_version"
Expand Down
38 changes: 38 additions & 0 deletions common-ui/src/main/java/com/nocapstone/common_ui/CustomToast.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.nocapstone.common_ui


import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import www.sanju.motiontoast.MotionToast
import www.sanju.motiontoast.MotionToastStyle


object CustomToast {
fun createToast(fragment: Fragment, message: String, toastType: ToastType) {
MotionToast.createColorToast(
fragment.requireActivity(),
toastType.title,
message,
toastType.style,
MotionToast.GRAVITY_BOTTOM,
MotionToast.SHORT_DURATION,
ResourcesCompat.getFont(
fragment.requireContext(),
www.sanju.motiontoast.R.font.helvetica_regular
)
)
}
}


enum class ToastType(val style: MotionToastStyle, val title: String) {
SUCCESS(MotionToastStyle.SUCCESS, "성공 \uD83D\uDE0D"),
ERROR(MotionToastStyle.ERROR, "에러 ☹ "),
INFO(MotionToastStyle.INFO, "알림")
}

data class ToastSet(
val message: String,
val type: ToastType
)

14 changes: 7 additions & 7 deletions diary/src/main/java/com/nocapstone/diary/data/DiaryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ interface DiaryService {
): CommonResponse<DiaryId>


@Multipart
@POST("diary/{diaryId}/image")
suspend fun createDiaryImage(
@Header("Authorization") token: String,
@Path("diaryId") diaryId: Long,
@Part image: List<MultipartBody.Part>
): CommonResponse<String?>
@Multipart
@POST("diary/{diaryId}/image")
suspend fun createDiaryImage(
@Header("Authorization") token: String,
@Path("diaryId") diaryId: Long,
@Part image: List<MultipartBody.Part>
): CommonResponse<String?>


@GET("diary/{diaryId}")
Expand Down
6 changes: 3 additions & 3 deletions diary/src/main/java/com/nocapstone/diary/ui/DiaryFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.navigation.fragment.findNavController
import com.example.diary.R
import com.example.diary.databinding.FragmentDiaryBinding
import com.nocapstone.common_ui.CalendarUtil
import com.nocapstone.common_ui.CustomToast
import com.nocapstone.common_ui.DialogForDateNoDay
import com.nocapstone.common_ui.MainActivityUtil
import com.nocapstone.diary.DiaryAdapter
Expand Down Expand Up @@ -67,14 +68,13 @@ class DiaryFragment : Fragment() {
}
diaryViewModel.readDiaryList(testYear, testMonth)
}
observeToast()
}

private fun observeToast() {
lifecycleScope.launch {
diaryViewModel.toastMessage.collectLatest {
if (it.isNotEmpty()) {
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
if (it != null) {
CustomToast.createToast(this@DiaryFragment, it.message, it.type)
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions diary/src/main/java/com/nocapstone/diary/ui/DiaryViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.lifecycle.viewModelScope
import com.nocapstone.common.domain.usecase.DataStoreUseCase
import com.nocapstone.common.util.ImageUtil
import com.nocapstone.common.util.printLog
import com.nocapstone.common_ui.ToastSet
import com.nocapstone.common_ui.ToastType
import com.nocapstone.diary.DiaryUtil
import com.nocapstone.diary.domain.CreateDiaryRequest
import com.nocapstone.diary.domain.DiaryUseCase
Expand Down Expand Up @@ -37,8 +39,8 @@ class DiaryViewModel @Inject constructor(
private val _diaryList = MutableStateFlow<MutableList<CalendarData>>(mutableListOf())
val diaryList: StateFlow<List<CalendarData>> = _diaryList

private val _toastMessage = MutableStateFlow("")
val toastMessage: StateFlow<String> = _toastMessage
private val _toastMessage = MutableStateFlow<ToastSet?>(null)
val toastMessage: StateFlow<ToastSet?> = _toastMessage

fun readDiaryList(year: Int, month: Int) {
viewModelScope.launch(Dispatchers.IO) {
Expand Down Expand Up @@ -97,9 +99,9 @@ class DiaryViewModel @Inject constructor(
_imageUriList.value = newUriList.toMutableList()
}

private fun setToastMessage(newMessage: String) {
_toastMessage.value = ""
_toastMessage.value = newMessage
fun setToastMessage(newMessage: String, toastType: ToastType) {
_toastMessage.value = null
_toastMessage.value = ToastSet(newMessage,toastType)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.example.diary.R
import com.example.diary.databinding.FragmentWriteDiaryBinding
import com.nocapstone.common_ui.*
import com.nocapstone.common_ui.CalendarUtil.Companion.getTodayDate
import com.nocapstone.common_ui.CalendarUtil.Companion.parseDateToFormatString
import com.nocapstone.common_ui.CalendarUtil.Companion.parseStringToDate
import com.nocapstone.common_ui.DialogForDatePicker
import com.nocapstone.common_ui.ImageAdapter
import com.nocapstone.common_ui.MainActivityUtil
import com.nocapstone.diary.domain.CreateDiaryRequest
import dagger.hilt.android.AndroidEntryPoint
import gun0912.tedimagepicker.builder.TedImagePicker
Expand All @@ -43,6 +41,8 @@ class WriteDiaryFragment : Fragment() {
setVisibilityBottomAppbar(View.GONE)
}

diaryViewModel.setToastMessage("안녕",ToastType.SUCCESS)

return binding.root
}

Expand Down Expand Up @@ -105,7 +105,7 @@ class WriteDiaryFragment : Fragment() {
titleTv.text.toString(),
contentTv.text.toString()
).let {
diaryViewModel.createDiary(it){
diaryViewModel.createDiary(it) {
findNavController().popBackStack()
}
}
Expand All @@ -120,8 +120,8 @@ class WriteDiaryFragment : Fragment() {
private fun observeToast() {
lifecycleScope.launch {
diaryViewModel.toastMessage.collectLatest {
if (it.isNotEmpty()) {
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
if (it != null) {
CustomToast.createToast(this@WriteDiaryFragment, it.message, it.type)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.nocapstone.onboarding.ui

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -46,6 +48,7 @@ class LoginFragment : Fragment() {
viewLifecycleOwner, callback
)


binding.kakaoLoginBtn.setOnClickListener {
LoginUtil.loginWithKaKao(requireContext()) { token ->
splashViewModel.signup(token!!, {
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencyResolutionManagement {
google()
mavenCentral()
maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' }
maven { url 'https://jitpack.io' }

}
}
rootProject.name = "buddyvet"
Expand Down

0 comments on commit b41bafe

Please sign in to comment.