diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2014-12-30 10:41:02 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2014-12-30 10:41:02 +0100 |
| commit | 896f0bd7d1c6b4096fb37594e5d879f0f49ed3af (patch) | |
| tree | 66d889c9ba33ff569f700746b01b12caeceae840 /main/src/cgeo/geocaching/gcvote/GCVoteRatingBarUtil.java | |
| parent | 25b78896facadf9027130fb4180c394b464c7fe1 (diff) | |
| download | cgeo-896f0bd7d1c6b4096fb37594e5d879f0f49ed3af.zip cgeo-896f0bd7d1c6b4096fb37594e5d879f0f49ed3af.tar.gz cgeo-896f0bd7d1c6b4096fb37594e5d879f0f49ed3af.tar.bz2 | |
#4566 new voting dialog
The tap handler for the rating stars will be implemented later.
Diffstat (limited to 'main/src/cgeo/geocaching/gcvote/GCVoteRatingBarUtil.java')
| -rw-r--r-- | main/src/cgeo/geocaching/gcvote/GCVoteRatingBarUtil.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/gcvote/GCVoteRatingBarUtil.java b/main/src/cgeo/geocaching/gcvote/GCVoteRatingBarUtil.java new file mode 100644 index 0000000..2d485bd --- /dev/null +++ b/main/src/cgeo/geocaching/gcvote/GCVoteRatingBarUtil.java @@ -0,0 +1,58 @@ +package cgeo.geocaching.gcvote; + +import butterknife.ButterKnife; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; + +import org.eclipse.jdt.annotation.Nullable; + +import android.view.View; +import android.widget.RatingBar; +import android.widget.RatingBar.OnRatingBarChangeListener; +import android.widget.TextView; + +/** + * TODO: convert to fragment + * + */ +public final class GCVoteRatingBarUtil { + public interface OnRatingChangeListener { + public void onRatingChanged(final float stars); + } + + private GCVoteRatingBarUtil() { + // utility class + } + + public static void initializeRatingBar(final Geocache cache, final View parentView, @Nullable final OnRatingChangeListener changeListener) { + if (GCVote.isVotingPossible(cache)) { + final RatingBar ratingBar = ButterKnife.findById(parentView, R.id.gcvoteRating); + final TextView label = ButterKnife.findById(parentView, R.id.gcvoteLabel); + ratingBar.setVisibility(View.VISIBLE); + label.setVisibility(View.VISIBLE); + ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { + + @Override + public void onRatingChanged(final RatingBar ratingBar, final float stars, final boolean fromUser) { + // 0.5 is not a valid rating, therefore we must limit + final float rating = GCVote.isValidRating(stars) ? stars : 0; + if (rating < stars) { + ratingBar.setRating(rating); + } + label.setText(GCVote.getDescription(rating)); + if (changeListener != null) { + changeListener.onRatingChanged(rating); + } + } + }); + ratingBar.setRating(cache.getMyVote()); + } + } + + public static float getRating(final View parentView) { + final RatingBar ratingBar = ButterKnife.findById(parentView, R.id.gcvoteRating); + return ratingBar.getRating(); + } + +} |
