Search in sources :

Example 1 with Rating

use of tr.bcxip.hummingbird.api.objects.Rating in project Hummingbird-for-Android by xiprox.

the class AnimeDetailsActivity method displayLibraryElements.

/* If Anime exist in user library, show library related elements... */
public void displayLibraryElements() {
    if (libraryEntry != null) {
        if (mRemove != null)
            mRemove.setVisible(true);
        final String animeEpisodeCount = anime.getEpisodeCount() != 0 ? anime.getEpisodeCount() + "" : "?";
        mEpisodes.setText(libraryEntry.getEpisodesWatched() + "/" + animeEpisodeCount);
        mRewatching.setChecked(libraryEntry.isRewatching());
        mRewatchedTimes.setText(libraryEntry.getNumberOfRewatches() + "");
        mPrivate.setChecked(libraryEntry.isPrivate());
        Rating rating = libraryEntry.getRating();
        if (rating.isAdvanced()) {
            if (rating.getAdvancedRating() != null)
                mRatingBar.setRating(Float.parseFloat(rating.getAdvancedRating()));
            else
                mRatingBar.setRating(0);
            mRatingBar.setVisibility(View.VISIBLE);
            mSimpleRatingView.setVisibility(View.GONE);
        } else {
            if (rating.getSimpleRating() != null)
                mSimpleRatingView.setSelectedRating(Utils.getRatingFromString(rating.getSimpleRating()));
            else
                mSimpleRatingView.setSelectedRating(SimpleRatingView.Rating.NEUTRAL);
            mRatingBar.setVisibility(View.GONE);
            mSimpleRatingView.setVisibility(View.VISIBLE);
        }
        newWatchStatus = libraryEntry.getStatus();
        newEpisodesWatched = libraryEntry.getEpisodesWatched();
        newIsRewatching = libraryEntry.isRewatching();
        newRewatchedTimes = libraryEntry.getNumberOfRewatches();
        newPrivate = libraryEntry.isPrivate();
        newRating = libraryEntry.getRating().getAdvancedRating() != null ? libraryEntry.getRating().getAdvancedRating() : "0";
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(AnimeDetailsActivity.this, R.array.library_watch_status_items, R.layout.item_spinner_library_status);
        adapter.setDropDownViewResource(R.layout.item_spinner_item_library_status);
        mStatusSpinner.setAdapter(adapter);
        String watchStatus = libraryEntry.getStatus();
        if (watchStatus.equals("currently-watching"))
            mStatusSpinner.setSelection(0);
        if (watchStatus.equals("plan-to-watch"))
            mStatusSpinner.setSelection(1);
        if (watchStatus.equals("completed"))
            mStatusSpinner.setSelection(2);
        if (watchStatus.equals("on-hold"))
            mStatusSpinner.setSelection(3);
        if (watchStatus.equals("dropped"))
            mStatusSpinner.setSelection(4);
        mEpisodesHolder.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                View dialogView = getLayoutInflater().inflate(R.layout.number_picker, null);
                final NumberPicker mNumberPicker = (NumberPicker) dialogView.findViewById(R.id.number_picker);
                mNumberPicker.setMaxValue(anime.getEpisodeCount() != 0 ? anime.getEpisodeCount() : 1000);
                mNumberPicker.setValue(newEpisodesWatched);
                mNumberPicker.setWrapSelectorWheel(false);
                new MaterialDialog.Builder(AnimeDetailsActivity.this).title(R.string.content_episodes).positiveText(R.string.ok).negativeText(R.string.cancel).positiveColor(vibrantColor).negativeColorRes(R.color.text_dialog_action).customView(dialogView, true).callback(new MaterialDialog.ButtonCallback() {

                    @Override
                    public void onPositive(MaterialDialog materialDialog) {
                        newEpisodesWatched = mNumberPicker.getValue();
                        mEpisodes.setText(newEpisodesWatched + "/" + animeEpisodeCount);
                        if ((newEpisodesWatched + "").equals(animeEpisodeCount))
                            // (completed)
                            mStatusSpinner.setSelection(2);
                        updateUpdateButtonStatus(libraryEntry);
                    }
                }).show();
            }
        });
        mRewatching.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                newIsRewatching = isChecked;
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mRewatchedTimesHolder.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                View dialogView = getLayoutInflater().inflate(R.layout.number_picker, null);
                final NumberPicker mNumberPicker = (NumberPicker) dialogView.findViewById(R.id.number_picker);
                mNumberPicker.setMaxValue(200);
                mNumberPicker.setValue(newRewatchedTimes);
                mNumberPicker.setWrapSelectorWheel(false);
                new MaterialDialog.Builder(AnimeDetailsActivity.this).title(R.string.content_rewatched).positiveText(R.string.ok).negativeText(R.string.cancel).positiveColor(vibrantColor).negativeColorRes(R.color.text_dialog_action).customView(dialogView, true).callback(new MaterialDialog.ButtonCallback() {

                    @Override
                    public void onPositive(MaterialDialog materialDialog) {
                        newRewatchedTimes = mNumberPicker.getValue();
                        mRewatchedTimes.setText(newRewatchedTimes + "");
                        updateUpdateButtonStatus(libraryEntry);
                    }
                }).show();
            }
        });
        mPrivate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                newPrivate = isChecked;
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mStatusSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
                switch(position) {
                    case 0:
                        newWatchStatus = "currently-watching";
                        break;
                    case 1:
                        newWatchStatus = "plan-to-watch";
                        break;
                    case 2:
                        newWatchStatus = "completed";
                        break;
                    case 3:
                        newWatchStatus = "on-hold";
                        break;
                    case 4:
                        newWatchStatus = "dropped";
                        break;
                }
                updateUpdateButtonStatus(libraryEntry);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }
        });
        mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                newRating = rating + "";
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mSimpleRatingView.setOnRatingChangedListener(new SimpleRatingView.OnRatingChangeListener() {

            @Override
            public void onRatingChanged(SimpleRatingView.Rating rating) {
                switch(rating) {
                    case POSITIVE:
                        newRating = "1";
                        break;
                    case NEUTRAL:
                        newRating = "3";
                        break;
                    case NEGATIVE:
                        newRating = "5";
                        break;
                }
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mActionButton.setImageResource(R.drawable.ic_upload_white_24dp);
        mActionButton.setOnClickListener(new OnLibraryUpdateClickListener());
        mLibraryProgressBar.setVisibility(View.GONE);
        mLibraryInfoHolder.setVisibility(View.VISIBLE);
    } else {
        enableFAB();
        mRemove.setVisible(false);
        mLibraryProgressBar.setVisibility(View.GONE);
        mLibraryInfoHolder.setVisibility(View.GONE);
    }
}
Also used : Rating(tr.bcxip.hummingbird.api.objects.Rating) NumberPicker(android.widget.NumberPicker) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ImageView(android.widget.ImageView) ObservableScrollView(tr.bcxip.hummingbird.widget.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) SimpleRatingView(tr.xip.widget.simpleratingview.SimpleRatingView) TextView(android.widget.TextView) RatingBar(android.widget.RatingBar) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SimpleRatingView(tr.xip.widget.simpleratingview.SimpleRatingView)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 NumberPicker (android.widget.NumberPicker)1 RatingBar (android.widget.RatingBar)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 Rating (tr.bcxip.hummingbird.api.objects.Rating)1 ObservableScrollView (tr.bcxip.hummingbird.widget.ObservableScrollView)1 SimpleRatingView (tr.xip.widget.simpleratingview.SimpleRatingView)1