From bc803fb5056db929ae5ec089c0da8a7cac7c581c Mon Sep 17 00:00:00 2001 From: Blackchai Date: Fri, 13 Sep 2019 13:50:36 -0600 Subject: [PATCH] [Parent][RC-2.0.5] Fixed IooB exception with student spinner (#315) --- apps/parent/build.gradle | 2 +- .../instructure/parentapp/activity/NavigationActivity.kt | 7 +++---- .../instructure/parentapp/adapter/UserSpinnerAdapter.kt | 8 +++++++- .../java/com/instructure/parentapp/util/ParentPrefs.kt | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/parent/build.gradle b/apps/parent/build.gradle index 9fc4e6d9ee..37bf163f09 100644 --- a/apps/parent/build.gradle +++ b/apps/parent/build.gradle @@ -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 diff --git a/apps/parent/src/main/java/com/instructure/parentapp/activity/NavigationActivity.kt b/apps/parent/src/main/java/com/instructure/parentapp/activity/NavigationActivity.kt index 3f9acb86c9..a5193c18d1 100644 --- a/apps/parent/src/main/java/com/instructure/parentapp/activity/NavigationActivity.kt +++ b/apps/parent/src/main/java/com/instructure/parentapp/activity/NavigationActivity.kt @@ -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 @@ -160,7 +159,7 @@ class NavigationActivity : BaseParentActivity(), MasqueradingDialog.OnMasqueradi if (users.isNotEmpty()) { configureUserSpinner() } else { - setFragment(ParentPrefs.selectedStudentIdx) + setFragment(ParentPrefs.selectedStudentIndex) } setupNavDrawer() @@ -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 } } } @@ -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. diff --git a/apps/parent/src/main/java/com/instructure/parentapp/adapter/UserSpinnerAdapter.kt b/apps/parent/src/main/java/com/instructure/parentapp/adapter/UserSpinnerAdapter.kt index 4d924b72cb..e1e145b62c 100644 --- a/apps/parent/src/main/java/com/instructure/parentapp/adapter/UserSpinnerAdapter.kt +++ b/apps/parent/src/main/java/com/instructure/parentapp/adapter/UserSpinnerAdapter.kt @@ -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) : ArrayAdapter(context, 0, users) { @@ -38,7 +39,12 @@ class UserSpinnerAdapter(context: Context, users: Array) : ArrayAdapter= 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 ?: "" } diff --git a/apps/parent/src/main/java/com/instructure/parentapp/util/ParentPrefs.kt b/apps/parent/src/main/java/com/instructure/parentapp/util/ParentPrefs.kt index 31dc4ab4a2..dcb8c4e12d 100644 --- a/apps/parent/src/main/java/com/instructure/parentapp/util/ParentPrefs.kt +++ b/apps/parent/src/main/java/com/instructure/parentapp/util/ParentPrefs.kt @@ -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()