Skip to content

Commit

Permalink
Merge pull request #92 from FOR-GRAD/14-커리어
Browse files Browse the repository at this point in the history
14 커리어
  • Loading branch information
kimyujin-com authored Feb 16, 2024
2 parents e2bb947 + d7232cf commit a8444f5
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CareerEditActivityFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_activity_to_fragment_career_activity)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -84,6 +85,7 @@ class CareerEditActivityFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_activity_to_fragment_career_activity)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -101,7 +103,7 @@ class CareerEditActivityFragment : Fragment() {
}
})
//버튼 활성화
viewModel.isFilledAllOptions.observe(viewLifecycleOwner) { isEnabled ->
viewModel.isFilledAnyOptions.observe(viewLifecycleOwner) { isEnabled ->
binding?.btnCareerEdit?.isEnabled = isEnabled
binding?.btnCareerEdit?.backgroundTintList =
ContextCompat.getColorStateList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.text.Editable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -64,6 +65,7 @@ class CareerEditCertificateFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_certificate_to_fragment_career_certificate)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -74,6 +76,7 @@ class CareerEditCertificateFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_certificate_to_fragment_career_certificate)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.text.Editable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -72,6 +73,7 @@ class CareerEditContestFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_contest_to_fragment_career_contest)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -81,6 +83,7 @@ class CareerEditContestFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_contest_to_fragment_career_contest)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.text.Editable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -63,6 +64,7 @@ class CareerEditVolunteerFragment : Fragment() {
if (isDeleted) {
//삭제 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_volunteer_to_fragment_career_volunteer)
Toast.makeText(mContext, "삭제되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand All @@ -72,6 +74,7 @@ class CareerEditVolunteerFragment : Fragment() {
if (isUpdated) {
//수정 작업이 완료되면 목록 업데이트
navigate(R.id.action_fragment_edit_volunteer_to_fragment_career_volunteer)
Toast.makeText(mContext, "수정되었습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class CareerAddCertificateViewModel : ViewModel() {
/* 버튼 활성화 기능 */
val isFilledAllOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
addSource(title) { value = areBothFieldsFilled() }
addSource(selectedCertificateType) { value = areBothFieldsFilled() }
addSource(startDate) { value = areBothFieldsFilled() }
addSource(endDate) { value = areBothFieldsFilled() }
}

private fun areBothFieldsFilled(): Boolean {
return !(title.value.isNullOrEmpty() || title.value!!.contains(" ") || title.value!!.length > 20) && isDateValid(
startDate.value
) && isDateValid(endDate.value)
return !(title.value.isNullOrEmpty() || title.value!!.contains(" ") || title.value!!.length > 20) && !selectedCertificateType.value.isNullOrEmpty()
&& isDateValid(startDate.value) && isDateValid(endDate.value)
}

private fun isDateValid(date: String?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class CareerAddContestViewModel : ViewModel() {
/* 버튼 활성화 기능 */
val isFilledAllOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
addSource(title) { value = areBothFieldsFilled() }
addSource(selectedAward) { value = areBothFieldsFilled() }
addSource(startDate) { value = areBothFieldsFilled() }
addSource(endDate) { value = areBothFieldsFilled() }
}

private fun areBothFieldsFilled(): Boolean {
return !(title.value.isNullOrEmpty() || title.value!!.contains(" ") || title.value!!.length > 20) && isDateValid(
startDate.value
) && isDateValid(endDate.value)
return !(title.value.isNullOrEmpty() || title.value!!.contains(" ") || title.value!!.length > 20) && !selectedAward.value.isNullOrEmpty()
&& isDateValid(startDate.value) && isDateValid(endDate.value)
}

private fun isDateValid(date: String?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class CareerEditActivityViewModel : ViewModel() {
val endDate: MutableLiveData<String> = MutableLiveData()
val fileAddedEvent: MutableLiveData<Boolean> = MutableLiveData()
val addFiles: MutableList<MultipartBody.Part> = mutableListOf()
val addFilesLive: MutableLiveData<Boolean> = MutableLiveData<Boolean>().apply {
value = addFiles.isNotEmpty()
}

init {
studentId.value = 0
Expand All @@ -49,18 +52,19 @@ class CareerEditActivityViewModel : ViewModel() {
startDate.value = ""
endDate.value = ""
addFiles.clear()
addFilesLive.value = addFiles.isNotEmpty()
}

val isFilledAllOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
value = areBothFieldsFilled()
addSource(startDate) { value = areBothFieldsFilled() }
addSource(endDate) { value = areBothFieldsFilled() }
val isFilledAnyOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
value = isAnyFieldFilled()
addSource(title) { value = isAnyFieldFilled() }
addSource(startDate) { value = isAnyFieldFilled() }
addSource(endDate) { value = isAnyFieldFilled() }
addSource(addFilesLive) { value = isAnyFieldFilled() }
}

private fun areBothFieldsFilled(): Boolean {
return (startDate.value.isNullOrBlank() && endDate.value.isNullOrBlank()) || (isDateValid(
startDate.value
) && isDateValid(endDate.value))
private fun isAnyFieldFilled(): Boolean {
return !title.value.isNullOrBlank() || !startDate.value.isNullOrBlank() || !endDate.value.isNullOrBlank() || (addFilesLive.value ?: false)
}

private fun isDateValid(date: String?): Boolean {
Expand All @@ -71,6 +75,7 @@ class CareerEditActivityViewModel : ViewModel() {
val requestFile = RequestBody.create("image/*".toMediaTypeOrNull(), file)
val body = MultipartBody.Part.createFormData("addFiles", file.name, requestFile)
addFiles.add(body)
addFilesLive.value = addFiles.isNotEmpty()
fileAddedEvent.value = true
}

Expand Down Expand Up @@ -99,6 +104,7 @@ class CareerEditActivityViewModel : ViewModel() {
val requestFile: RequestBody = RequestBody.create(mimeType?.toMediaTypeOrNull(), file)
val filePart = MultipartBody.Part.createFormData("addFiles", fileName, requestFile)
addFiles.add(filePart)
addFilesLive.value = addFiles.isNotEmpty()
fileAddedEvent.value = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ class CareerEditCertificateViewModel : ViewModel() {
startDate.value = ""
endDate.value = ""
}

val isFilledAllOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
value = areBothFieldsFilled()
addSource(startDate) { value = areBothFieldsFilled() }
addSource(endDate) { value = areBothFieldsFilled() }
value = isAnyFieldFilled()
addSource(title) { value = isAnyFieldFilled() }
addSource(type) { value = isAnyFieldFilled() }
addSource(startDate) { value = isAnyFieldFilled() }
addSource(endDate) { value = isAnyFieldFilled() }
}

private fun areBothFieldsFilled(): Boolean {
return (startDate.value.isNullOrBlank() && endDate.value.isNullOrBlank()) || (isDateValid(
startDate.value
) && isDateValid(endDate.value))
private fun isAnyFieldFilled(): Boolean {
return !title.value.isNullOrBlank() || !type.value.isNullOrBlank() || !startDate.value.isNullOrBlank() || !endDate.value.isNullOrBlank()
}

private fun isDateValid(date: String?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class CareerEditContestViewModel : ViewModel() {
}

val isFilledAllOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
value = areBothFieldsFilled()
addSource(startDate) { value = areBothFieldsFilled() }
addSource(endDate) { value = areBothFieldsFilled() }
value = isAnyFieldFilled()
addSource(title) { value = isAnyFieldFilled() }
addSource(award) { value = isAnyFieldFilled() }
addSource(startDate) { value = isAnyFieldFilled() }
addSource(endDate) { value = isAnyFieldFilled() }
}

private fun areBothFieldsFilled(): Boolean {
return (startDate.value.isNullOrBlank() && endDate.value.isNullOrBlank()) || (isDateValid(
startDate.value
) && isDateValid(endDate.value))
private fun isAnyFieldFilled(): Boolean {
return !title.value.isNullOrBlank() || !award.value.isNullOrBlank() || !startDate.value.isNullOrBlank() || !endDate.value.isNullOrBlank()
}

private fun isDateValid(date: String?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class CareerEditVolunteerViewModel : ViewModel() {
}

val isFilledAllOptions: LiveData<Boolean> = MediatorLiveData<Boolean>().apply {
value = areBothFieldsFilled()
addSource(startDate) { value = areBothFieldsFilled() }
addSource(endDate) { value = areBothFieldsFilled() }
value = isAnyFieldFilled()
addSource(title) { value = isAnyFieldFilled() }
addSource(hour) { value = isAnyFieldFilled() }
addSource(startDate) { value = isAnyFieldFilled() }
addSource(endDate) { value = isAnyFieldFilled() }
}

private fun areBothFieldsFilled(): Boolean {
return (startDate.value.isNullOrBlank() && endDate.value.isNullOrBlank()) || (isDateValid(
startDate.value
) && isDateValid(endDate.value))
private fun isAnyFieldFilled(): Boolean {
return !title.value.isNullOrBlank() || !hour.value.isNullOrBlank() || !startDate.value.isNullOrBlank() || !endDate.value.isNullOrBlank()
}

private fun isDateValid(date: String?): Boolean {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_career_add_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -137,6 +138,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_career_add_certificate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
android:focusable="false"
android:gravity="top"
android:hint="실기"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -103,6 +104,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -135,6 +137,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_career_add_contest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_choose"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -103,6 +104,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -135,6 +137,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_career_add_volunteer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -136,6 +137,7 @@
android:focusable="false"
android:gravity="top"
android:hint="@string/career_date_ex"
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_career_edit_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
android:focusable="false"
android:gravity="top"
android:hint=""
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -206,6 +207,7 @@
android:focusable="false"
android:gravity="top"
android:hint=""
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_career_edit_certificate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
android:focusable="false"
android:gravity="top"
android:hint=""
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -159,6 +160,7 @@
android:focusable="false"
android:gravity="top"
android:hint=""
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="11dp"
android:paddingBottom="10dp"
Expand Down Expand Up @@ -191,6 +193,7 @@
android:focusable="false"
android:gravity="top"
android:hint=""
android:inputType="none"
android:paddingStart="18dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
Expand Down
Loading

0 comments on commit a8444f5

Please sign in to comment.