Tasker: scroll to selected profile
This commit is contained in:
@@ -76,12 +76,11 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
handler.post(() => text.setText(builder))
|
||||
}
|
||||
|
||||
def bind(item: Profile, i: Int) {
|
||||
def bind(item: Profile) {
|
||||
this.item = item
|
||||
updateText()
|
||||
if (item.id == ShadowsocksApplication.profileId) {
|
||||
text.setChecked(true)
|
||||
selectedIndex = i
|
||||
selectedItem = this
|
||||
} else {
|
||||
text.setChecked(false)
|
||||
@@ -102,7 +101,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
|
||||
def getItemCount = profiles.length
|
||||
|
||||
def onBindViewHolder(vh: ProfileViewHolder, i: Int) = vh.bind(profiles(i), i)
|
||||
def onBindViewHolder(vh: ProfileViewHolder, i: Int) = vh.bind(profiles(i))
|
||||
|
||||
def onCreateViewHolder(vg: ViewGroup, i: Int) =
|
||||
new ProfileViewHolder(LayoutInflater.from(vg.getContext).inflate(R.layout.layout_profiles_item, vg, false))
|
||||
@@ -154,7 +153,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
}
|
||||
}
|
||||
|
||||
private var selectedIndex = -1
|
||||
private var selectedItem: ProfileViewHolder = _
|
||||
private val handler = new Handler
|
||||
|
||||
@@ -181,10 +179,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
profilesList.setLayoutManager(layoutManager)
|
||||
profilesList.setItemAnimator(new DefaultItemAnimator)
|
||||
profilesList.setAdapter(profilesAdapter)
|
||||
if (selectedIndex < 0) selectedIndex = profilesAdapter.profiles.zipWithIndex.collectFirst {
|
||||
layoutManager.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst {
|
||||
case (profile, i) if profile.id == ShadowsocksApplication.profileId => i
|
||||
}.getOrElse(-1)
|
||||
layoutManager.scrollToPosition(selectedIndex)
|
||||
}.getOrElse(-1))
|
||||
removedSnackbar = Snackbar.make(profilesList, R.string.removed, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.undo, ((v: View) => profilesAdapter.undoRemoves): OnClickListener)
|
||||
removedSnackbar.getView.addOnAttachStateChangeListener(new OnAttachStateChangeListener {
|
||||
|
||||
Reference in New Issue
Block a user