Skip to content

Commit

Permalink
fixed UninitializedPropertyException when no date is selected.
Browse files Browse the repository at this point in the history
  • Loading branch information
xyznaveen committed Jun 21, 2019
1 parent b7517f3 commit 7548e80
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 38 deletions.
28 changes: 3 additions & 25 deletions .idea/codeStyles/Project.xml

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

4 changes: 4 additions & 0 deletions .idea/encodings.xml

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

86 changes: 86 additions & 0 deletions .idea/markdown-navigator.xml

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

3 changes: 3 additions & 0 deletions .idea/markdown-navigator/profiles_settings.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

### How do I use this ?

##### Include In Project

you must be using jitpack to be able to use this project.

see jitpack.io for more details on jitpack

```
implementation 'com.github.xyznaveen:pal:$latest-version'
// see releases for $latest-version
```

```
// Kotlin
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
24 changes: 24 additions & 0 deletions ghadi/src/main/java/np/com/naveenniraula/ghadi/data/DateItem.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package np.com.naveenniraula.ghadi.data

import np.com.naveenniraula.ghadi.miti.Date
import java.util.*

data class DateItem(
val date: String,
var month: String = "",
Expand All @@ -13,4 +16,25 @@ data class DateItem(

return "$year-$month-$date"
}

companion object {
fun getTodayNepali(): DateItem {
val cal = Calendar.getInstance()
val today = Date(
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH) + 1,
cal.get(Calendar.DAY_OF_MONTH)
).convertToNepali()
return DateItem(
date = "${today.day}",
month = "${today.month}",
year = "${today.year}",
isClickable = false,
isSelected = true,
isHoliday = false,
isToday = true
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class GhadiPickerFragment : DialogFragment() {
if (!::datePickCompleteListener.isInitialized) throw listenerException

val date = adapter.getSelectedDate()

Log.d("jqiu7", "$date")

val engDate = Date(date.year.toInt(), date.month.toInt(), date.date.toInt()).convertToEnglish()
val weekDayNumber = engDate.weekDayNum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,9 @@ class NepaliDateAdapter<T> : RecyclerView.Adapter<NepaliDateAdapter.Vh>() {

fun getSelectedDate(): DateItem {

if (!::selectedDate.isInitialized) {
dataList.forEach {
val item = it as DateItem
if (item.isToday) {
selectedDate = item
}
}
}

// if the variable is not initialized no date was select
// so, return today's date
if (!::selectedDate.isInitialized) selectedDate = DateItem.getTodayNepali()
return selectedDate
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Feb 25 19:27:20 NPT 2019
#Fri Jun 21 12:32:49 NPT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit 7548e80

Please sign in to comment.