-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create custom spinner implementation
- Loading branch information
1 parent
9ce2430
commit a9b6fbb
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.viscouspot.gitsync.ui | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.widget.Spinner | ||
|
||
|
||
/** Spinner extension that calls onItemSelected even when the selection is the same as its previous value */ | ||
class NDSpinner : androidx.appcompat.widget.AppCompatSpinner { | ||
constructor(context: Context) : super(context) | ||
|
||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) | ||
|
||
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super( | ||
context, | ||
attrs, | ||
defStyle | ||
) | ||
|
||
override fun setSelection(position: Int, animate: Boolean) { | ||
val sameSelected = position == selectedItemPosition | ||
super.setSelection(position, animate) | ||
if (sameSelected) { | ||
// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now | ||
onItemSelectedListener!!.onItemSelected( | ||
this, | ||
selectedView, position, selectedItemId | ||
) | ||
} | ||
} | ||
|
||
override fun setSelection(position: Int) { | ||
val sameSelected = position == selectedItemPosition | ||
super.setSelection(position) | ||
if (sameSelected) { | ||
// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now | ||
onItemSelectedListener!!.onItemSelected( | ||
this, | ||
selectedView, position, selectedItemId | ||
) | ||
} | ||
} | ||
} |