Skip to content

Commit

Permalink
fix: null pointer exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankbasant committed Feb 3, 2024
1 parent ee612c5 commit 5ad1322
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "com.dscvit.vitty"
minSdkVersion 24
targetSdkVersion 33
versionCode 35
versionName "2.0.0"
versionCode 37
versionName "2.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class AddInfoActivity : AppCompatActivity() {
startActivity(intent)
finish()
}
}else{
Toast.makeText(this, R.string.something_went_wrong, Toast.LENGTH_LONG).show()
binding.loadingView.visibility = View.GONE
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/dscvit/vitty/ui/schedule/DayFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class DayFragment : Fragment() {

}

private fun processTimetableData(userResponse: UserResponse) {
val timetableDays = userResponse.timetable?.data
private fun processTimetableData(userResponse: UserResponse?) {
val timetableDays = userResponse?.timetable?.data
when (day) {
"monday" -> {
val monday = timetableDays?.Monday
Expand Down
84 changes: 41 additions & 43 deletions app/src/main/java/com/dscvit/vitty/widget/NextClassWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,6 @@ suspend fun fetchData(
}
}
today = today?.sortedBy { it.start_time }
// if(today.isNullOrEmpty()){
// pd.courseName = ""
// updateNextClassWidget(context, appWidgetManager, appWidgetId, pd)
// return@coroutineScope
// }
if (today != null) {
for (period in today) {

Expand Down Expand Up @@ -362,49 +357,52 @@ suspend fun fetchData(
}
}
today = today?.sortedBy { it.start_time }
for (period in today!!) {

try {
val start = Calendar.getInstance()
val s = Calendar.getInstance()
s.time = parseTimeToTimestamp(period.start_time).toDate()
start[Calendar.HOUR_OF_DAY] = s[Calendar.HOUR_OF_DAY]
start[Calendar.MINUTE] = s[Calendar.MINUTE]
Timber.d("$calendar")
Timber.d("$start")
if (start.time > calendar.time) {
val end = Calendar.getInstance()
val e = Calendar.getInstance()
e.time = parseTimeToTimestamp(period.end_time).toDate()
end[Calendar.HOUR_OF_DAY] = e[Calendar.HOUR_OF_DAY]
end[Calendar.MINUTE] = e[Calendar.MINUTE]
Timber.d("$end")
if (end.time > calendar.time) {
pd = PeriodDetails(
period.code,
period.name,
parseTimeToTimestamp(period.start_time),
parseTimeToTimestamp(period.end_time),
period.slot,
period.venue
)
break

val todayTimetable = today
if(todayTimetable != null){
for (period in todayTimetable) {
try {
val start = Calendar.getInstance()
val s = Calendar.getInstance()
s.time = parseTimeToTimestamp(period.start_time).toDate()
start[Calendar.HOUR_OF_DAY] = s[Calendar.HOUR_OF_DAY]
start[Calendar.MINUTE] = s[Calendar.MINUTE]
Timber.d("$calendar")
Timber.d("$start")
if (start.time > calendar.time) {
val end = Calendar.getInstance()
val e = Calendar.getInstance()
e.time = parseTimeToTimestamp(period.end_time).toDate()
end[Calendar.HOUR_OF_DAY] = e[Calendar.HOUR_OF_DAY]
end[Calendar.MINUTE] = e[Calendar.MINUTE]
Timber.d("$end")
if (end.time > calendar.time) {
pd = PeriodDetails(
period.code,
period.name,
parseTimeToTimestamp(period.start_time),
parseTimeToTimestamp(period.end_time),
period.slot,
period.venue
)
break
}
} else {
pd.courseName = ""
val simpleDateFormat =
SimpleDateFormat("h:mm a", Locale.getDefault())
val sTime: String =
simpleDateFormat.format(calendar.time)
.uppercase(Locale.ROOT)
Timber.d("LOL: $sTime")
}
} else {
} catch (e: Exception) {
pd.courseName = ""
val simpleDateFormat =
SimpleDateFormat("h:mm a", Locale.getDefault())
val sTime: String =
simpleDateFormat.format(calendar.time)
.uppercase(Locale.ROOT)
Timber.d("LOL: $sTime")
Timber.d("F: $e")
}
} catch (e: Exception) {
pd.courseName = ""
Timber.d("F: $e")
}


}
}
updateNextClassWidget(context, appWidgetManager, appWidgetId, pd)

Expand Down
29 changes: 17 additions & 12 deletions app/src/main/java/com/dscvit/vitty/widget/TodayWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,23 @@ suspend fun fetchTodayData(
}
}
today = today?.sortedBy { it.start_time }
for (period in today!!) {
var startTime = parseTimeToTimestamp(period.start_time).toDate()
var endTime = parseTimeToTimestamp(period.end_time).toDate()

val simpleDateFormat = SimpleDateFormat("h:mm a", Locale.getDefault())
val sTime: String =
simpleDateFormat.format(startTime).uppercase(Locale.ROOT)
val eTime: String =
simpleDateFormat.format(endTime).uppercase(Locale.ROOT)
courseList.add(period.name)
timeList.add("$sTime - $eTime")
roomList.add(period.venue)
val todayTimeTable = today
if(todayTimeTable != null) {

for (period in todayTimeTable) {
var startTime = parseTimeToTimestamp(period.start_time).toDate()
var endTime = parseTimeToTimestamp(period.end_time).toDate()

val simpleDateFormat =
SimpleDateFormat("h:mm a", Locale.getDefault())
val sTime: String =
simpleDateFormat.format(startTime).uppercase(Locale.ROOT)
val eTime: String =
simpleDateFormat.format(endTime).uppercase(Locale.ROOT)
courseList.add(period.name)
timeList.add("$sTime - $eTime")
roomList.add(period.venue)
}
}

updateTodayWidget(
Expand Down

0 comments on commit 5ad1322

Please sign in to comment.