Skip to content

Commit

Permalink
fix(menstrual): fixing force close in menstrual calendar.
Browse files Browse the repository at this point in the history
  • Loading branch information
anangkur committed Apr 19, 2020
1 parent 9c1b33e commit 6abce88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.anangkur.mediku"
minSdkVersion 21
targetSdkVersion 29
versionCode 5
versionName "2.0"
versionCode 21
versionName "2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.applandeo.materialcalendarview.EventDay
import kotlinx.android.synthetic.main.activity_menstrual.*
import kotlinx.android.synthetic.main.layout_toolbar.*
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.util.*
import kotlin.collections.ArrayList

Expand Down Expand Up @@ -157,34 +156,34 @@ class MenstrualActivity: BaseActivity<MenstrualViewModel>() {

private fun showMenstrualDataCalendar(data: MenstrualPeriodResume): ArrayList<EventDay> {
val listEvent = ArrayList<EventDay>()
var firstMenstrualDate: LocalDate = LocalDate.parse(data.firstDayPeriod)
val lastMenstrualDate: LocalDate = LocalDate.parse(data.lastDayPeriod)
while (firstMenstrualDate.isBefore(lastMenstrualDate)){
val calendar = Calendar.getInstance()
calendar.set(
firstMenstrualDate.year,
firstMenstrualDate.monthValue-1,
firstMenstrualDate.dayOfMonth
)
listEvent.add(EventDay(calendar, R.drawable.ic_blood_event))
firstMenstrualDate = firstMenstrualDate.plusDays(1L)
val firstMenstrualCalendar = Calendar.getInstance()
val lastMenstrualCalendar = Calendar.getInstance()
val firstMenstrualDate: Date = SimpleDateFormat(Const.DEFAULT_DATE_FORMAT_NO_TIME, Locale.US).parse(data.firstDayPeriod)!!
val lastMenstrualDate: Date = SimpleDateFormat(Const.DEFAULT_DATE_FORMAT_NO_TIME, Locale.US).parse(data.lastDayPeriod)!!
firstMenstrualCalendar.time = firstMenstrualDate
lastMenstrualCalendar.time = lastMenstrualDate
while (firstMenstrualCalendar.before(lastMenstrualCalendar)){
val eventCalendar = Calendar.getInstance()
eventCalendar.time = firstMenstrualCalendar.time
listEvent.add(EventDay(eventCalendar, R.drawable.ic_blood_event))
firstMenstrualCalendar.add(Calendar.DAY_OF_MONTH, 1)
}
return listEvent
}

private fun showFertileDataCalendar(data: MenstrualPeriodResume): ArrayList<EventDay> {
val listEvent = ArrayList<EventDay>()
var firstFertileDate: LocalDate = LocalDate.parse(data.firstDayFertile)
val lastDayFertileDate: LocalDate = LocalDate.parse(data.lastDayFertile)!!
while (firstFertileDate.isBefore(lastDayFertileDate)){
val calendar = Calendar.getInstance()
calendar.set(
firstFertileDate.year,
firstFertileDate.monthValue-1,
firstFertileDate.dayOfMonth
)
listEvent.add(EventDay(calendar, R.drawable.ic_baby_event))
firstFertileDate = firstFertileDate.plusDays(1L)
val firstFertileCalendar = Calendar.getInstance()
val lastFertileCalendar = Calendar.getInstance()
val firstFertileDate: Date = SimpleDateFormat(Const.DEFAULT_DATE_FORMAT_NO_TIME, Locale.US).parse(data.firstDayFertile)!!
val lastFertileDate: Date = SimpleDateFormat(Const.DEFAULT_DATE_FORMAT_NO_TIME, Locale.US).parse(data.lastDayFertile)!!
firstFertileCalendar.time = firstFertileDate
lastFertileCalendar.time = lastFertileDate
while (firstFertileCalendar.before(lastFertileCalendar)){
val eventCalendar = Calendar.getInstance()
eventCalendar.time = firstFertileCalendar.time
listEvent.add(EventDay(eventCalendar, R.drawable.ic_baby_event))
firstFertileCalendar.add(Calendar.DAY_OF_MONTH, 1)
}
return listEvent
}
Expand Down

0 comments on commit 6abce88

Please sign in to comment.