Skip to content

Commit

Permalink
Prevent IndexOutOfBoundIndex in ProgressListRemoteFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
kevalpatel2106 committed Sep 8, 2019
1 parent 0a48576 commit 1a5ffa9
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@ internal class ProgressListRemoteFactory @Inject constructor(
private val progresses: ArrayList<Progress> = arrayListOf()

override fun getViewAt(position: Int): RemoteViews? {
if (progresses.size - 1 < position) return null
val rowView = RemoteViews(application.packageName, R.layout.row_widget_progress_list)
with(progresses[position]) {
val progress = progresses.getOrNull(position) ?: return null

rowView.setTextViewText(R.id.widget_battery_list_name_tv, this.title)
val rowView = RemoteViews(application.packageName, R.layout.row_widget_progress_list)
with(progress) {
rowView.setTextViewText(R.id.widget_battery_list_name_tv, title)

@Suppress("DEPRECATION")
rowView.setTextViewText(
R.id.widget_battery_list_level_tv,
application.getString(R.string.progress_percentage, this.percent)
application.getString(R.string.progress_percentage, percent)
)

rowView.setTextColor(
R.id.widget_battery_list_level_tv,
this.color.colorInt
)
rowView.setTextColor(R.id.widget_battery_list_level_tv, color.colorInt)

rowView.setOnClickFillInIntent(
R.id.battery_list_row,
AppLaunchHelper.launchWithProgressDetail(application, this.id)
AppLaunchHelper.launchWithProgressDetail(application, id)
)
}
return rowView
Expand Down

0 comments on commit 1a5ffa9

Please sign in to comment.