Skip to content

Commit

Permalink
[Parent][RC-2.0.5] Fixed IooB exception with student spinner (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorNeedham authored Sep 13, 2019
1 parent f791ccf commit bc803fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/parent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
applicationId "com.instructure.parentapp"
minSdkVersion Versions.MIN_SDK
targetSdkVersion Versions.TARGET_SDK
versionCode = 23
versionCode = 24
versionName = "2.0.5"

multiDexEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatSpinner
Expand Down Expand Up @@ -160,7 +159,7 @@ class NavigationActivity : BaseParentActivity(), MasqueradingDialog.OnMasqueradi
if (users.isNotEmpty()) {
configureUserSpinner()
} else {
setFragment(ParentPrefs.selectedStudentIdx)
setFragment(ParentPrefs.selectedStudentIndex)
}

setupNavDrawer()
Expand Down Expand Up @@ -296,7 +295,7 @@ class NavigationActivity : BaseParentActivity(), MasqueradingDialog.OnMasqueradi
updateBottomBarContentDescriptions(bottomBar.selectedItemId)
setFragment(page)
// Save the position so when the parent comes back to this page it will load the student they were on last
ParentPrefs.selectedStudentIdx = position
ParentPrefs.selectedStudentIndex = position
}
}
}
Expand All @@ -306,7 +305,7 @@ class NavigationActivity : BaseParentActivity(), MasqueradingDialog.OnMasqueradi

post {
adapter = UserSpinnerAdapter(this@NavigationActivity, users)
setSelection(ParentPrefs.selectedStudentIdx)
setSelection(ParentPrefs.selectedStudentIndex)
}

// Give the spinner a minimum height of 48dp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.instructure.canvasapi2.models.User
import com.instructure.pandautils.utils.ColorUtils
import com.instructure.pandautils.utils.GlideApp
import com.instructure.parentapp.R
import com.instructure.parentapp.util.ParentPrefs
import kotlinx.android.synthetic.main.spinner_user.view.*

class UserSpinnerAdapter(context: Context, users: Array<User>) : ArrayAdapter<User>(context, 0, users) {
Expand All @@ -38,7 +39,12 @@ class UserSpinnerAdapter(context: Context, users: Array<User>) : ArrayAdapter<Us

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View =
(convertView ?: inflater.inflate(R.layout.spinner_user, parent, false)).apply {
val user = getItem(position)
val user = if(position >= count) {
ParentPrefs.selectedStudentIndex = 0
getItem(0)
} else {
getItem(position)
}
GlideApp.with(avatar).load(user?.avatarUrl).placeholder(placeholder).error(placeholder).into(avatar)
userName.text = user?.shortName ?: ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object ParentPrefs : PrefManager(Const.CANVAS_PARENT_SP) {
@JvmStatic
var currentColor = ContextCompat.getColor(ContextKeeper.appContext, R.color.parent_colorPrimary)

var selectedStudentIdx by IntPref()
var selectedStudentIndex by IntPref()

var selectedTab by IntPref()

Expand Down

0 comments on commit bc803fb

Please sign in to comment.