Skip to content

Commit

Permalink
Fix links redirecting to incorrect sections and improve schedule widget
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Oct 8, 2018
1 parent 1fdcdd0 commit 26fae74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/me/proxer/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class MainActivity : DrawerActivity() {
companion object {
private const val TITLE_STATE = "title"
private const val SECTION_EXTRA = "section"
private const val SECTION_ACTION_PREFIX = "me.proxer.app.intent.action."

fun navigateToSection(context: Context, section: DrawerItem) = context
.startActivity(getSectionIntent(context, section))

fun getSectionIntent(context: Context, section: DrawerItem) = context
fun getSectionIntent(context: Context, section: DrawerItem): Intent = context
.intentFor<MainActivity>(SECTION_EXTRA to section)
.setAction(SECTION_ACTION_PREFIX + section.name)
}

override val contentView = R.layout.activity_main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,17 @@ class ScheduleWidgetUpdateWorker(
val detailIntent = applicationContext.intentFor<MediaActivity>()
val detailPendingIntent = PendingIntent.getActivity(applicationContext, 0, detailIntent, FLAG_UPDATE_CURRENT)

val position = calendarEntries.indexOfFirst { it.date.convertToDateTime().isAfter(LocalDateTime.now()) }
val position = calendarEntries
.indexOfFirst { it.date.convertToDateTime().isAfter(LocalDateTime.now()) }
.let {
when (it < 0) {
true -> when (LocalDateTime.now().isAfter(calendarEntries.last().date.convertToDateTime())) {
true -> calendarEntries.lastIndex
false -> 0
}
false -> it
}
}

bindBaseLayout(id, views)

Expand Down

0 comments on commit 26fae74

Please sign in to comment.