-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to wrap around rating selection 0->5->0 (#300)
Closes #283 Pressing left on a zero rating will wrap around to 5 stars (or 10.0 decimal). And pressing right on a five star or 10.0 decimal rating to wrap around to zero. This makes it easier/faster to pick a higher value.
- Loading branch information
1 parent
85ee660
commit 11b4059
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/github/damontecres/stashapp/views/DecimalRatingBar.kt
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,24 @@ | ||
package com.github.damontecres.stashapp.views | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.KeyEvent | ||
import androidx.appcompat.widget.AppCompatSeekBar | ||
|
||
class DecimalRatingBar(context: Context, attrs: AttributeSet?) : AppCompatSeekBar(context, attrs) { | ||
override fun onKeyDown( | ||
keyCode: Int, | ||
event: KeyEvent?, | ||
): Boolean { | ||
if (super.isEnabled()) { | ||
if ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_MINUS) && progress <= 0) { | ||
progress = 100 | ||
return true | ||
} else if ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_PLUS) && progress >= 100) { | ||
progress = 0 | ||
return true | ||
} | ||
} | ||
return super.onKeyDown(keyCode, event) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/github/damontecres/stashapp/views/StarRatingBar.kt
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,24 @@ | ||
package com.github.damontecres.stashapp.views | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.KeyEvent | ||
import androidx.appcompat.widget.AppCompatRatingBar | ||
|
||
class StarRatingBar(context: Context, attrs: AttributeSet?) : AppCompatRatingBar(context, attrs) { | ||
override fun onKeyDown( | ||
keyCode: Int, | ||
event: KeyEvent?, | ||
): Boolean { | ||
if (super.isEnabled()) { | ||
if ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_MINUS) && rating < .05f) { | ||
rating = 5f | ||
return true | ||
} else if ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_PLUS) && rating > 4.95f) { | ||
rating = 0f | ||
return true | ||
} | ||
} | ||
return super.onKeyDown(keyCode, event) | ||
} | ||
} |
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