Skip to content

Commit

Permalink
Initial Custom Scores Support
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed Jul 16, 2018
1 parent 7a4df38 commit 065b885
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 58 deletions.
14 changes: 3 additions & 11 deletions app/src/main/assets/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@
- Take a moment to give us your [feedback](https://poll.ly/#/PEA4x1Wg), thank you.

### Enhancements
- New polish translation
- Improved suggestions algorithm
- Consistent design for your media lists and airing anime
- Support for GIF images from keyboards such as Google Keyboard
- Lazy loading for series pages to just 3 tabs inclusive (because of too many requests)
- Amoled theme, find option in settings then use the toggle theme entry
- Changeable application language, find this option in settings

### Bug Fixes
- Incorrect review ratings
- Favourites for any new anime/manga
- A couple of random crashes have been fixed
- Actor roles now visible in character page
- Inverted title sort for your media lists
- Arabic translation related crashes
-

### Current Issues
- Clicking on @username shows mixed feed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void onViewRecycled() {
binding.unbind();
}

@Override @OnClick(R.id.series_image)
@Override @OnClick({R.id.series_image, R.id.container})
public void onClick(View v) {
performClick(clickListener, data, v);
}

@Override @OnLongClick(R.id.series_image)
@Override @OnLongClick({R.id.series_image, R.id.container})
public boolean onLongClick(View v) {
return performLongClick(clickListener, data, v);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mxt.anitrend.base.custom.view.text;

import android.content.Context;
import android.content.Intent;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.os.Build;
Expand All @@ -14,8 +15,11 @@
import com.mxt.anitrend.base.interfaces.view.CustomView;
import com.mxt.anitrend.databinding.CustomRatingWidgetBinding;
import com.mxt.anitrend.model.entity.anilist.MediaList;
import com.mxt.anitrend.model.entity.anilist.meta.MediaListOptions;
import com.mxt.anitrend.model.entity.base.MediaBase;
import com.mxt.anitrend.presenter.base.BasePresenter;
import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;

import java.util.Locale;

Expand All @@ -26,7 +30,7 @@

public class RatingTextView extends LinearLayout implements CustomView {

private static final int MAX = 5;
private @Nullable MediaListOptions mediaListOptions;
private CustomRatingWidgetBinding binding;

public RatingTextView(Context context) {
Expand Down Expand Up @@ -56,6 +60,9 @@ public RatingTextView(Context context, AttributeSet attrs, int defStyleAttr, int
@Override
public void onInit() {
binding = CustomRatingWidgetBinding.inflate(CompatUtil.getLayoutInflater(getContext()), this, true);
BasePresenter basePresenter = new BasePresenter(getContext());
if(basePresenter.getApplicationPref().isAuthenticated())
mediaListOptions = basePresenter.getDatabase().getCurrentUser().getMediaListOptions();
}

private void setFavourState(boolean isFavourite) {
Expand All @@ -64,21 +71,86 @@ private void setFavourState(boolean isFavourite) {
binding.ratingFavourState.setImageDrawable(drawable);
}

private void setRating(float value) {
binding.setRating(String.format(Locale.getDefault(),"%.2f", value));
private void setRating(MediaList mediaList) {
if(mediaListOptions != null)
switch (mediaListOptions.getScoreFormat()) {
case KeyUtil.POINT_10_DECIMAL:
binding.ratingValue.setText(String.format(Locale.getDefault(),"%.2f", mediaList.getScore()));
break;
case KeyUtil.POINT_100:
case KeyUtil.POINT_10:
case KeyUtil.POINT_5:
binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int)mediaList.getScore()));
break;
case KeyUtil.POINT_3:
binding.ratingValue.setText("");
int score = (int)mediaList.getScore();
switch (score) {
case 0:
case 1:
binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.getDrawable(getContext(),
R.drawable.ic_sentiment_dissatisfied_white_18dp), null, null, null);
break;
case 2:
binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.getDrawable(getContext(),
R.drawable.ic_sentiment_neutral_white_18dp), null, null, null);
break;
case 3:
binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.getDrawable(getContext(),
R.drawable.ic_sentiment_satisfied_white_18dp), null, null, null);
break;
}
break;
}
else
binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int)mediaList.getScore()));
}

private void setRating(MediaBase mediaBase) {
float mediaScoreDefault = (float) mediaBase.getMeanScore() * 5 / 100f;
if(mediaListOptions != null)
switch (mediaListOptions.getScoreFormat()) {
case KeyUtil.POINT_10_DECIMAL:
mediaScoreDefault = (mediaBase.getMeanScore() / 10);
binding.ratingValue.setText(String.format(Locale.getDefault(),"%.1f", mediaScoreDefault));
break;
case KeyUtil.POINT_100:
binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", mediaBase.getMeanScore()));
break;
case KeyUtil.POINT_10:
binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", mediaBase.getMeanScore() / 10));
break;
case KeyUtil.POINT_5:
binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", (int) mediaScoreDefault));
break;
case KeyUtil.POINT_3:
binding.ratingValue.setText("");
if(mediaBase.getMeanScore() >= 0 && mediaBase.getMeanScore() <= 33)
binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.getDrawable(getContext(),
R.drawable.ic_sentiment_dissatisfied_white_18dp), null, null, null);
else if (mediaBase.getMeanScore() >= 34 && mediaBase.getMeanScore() <= 66)
binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.getDrawable(getContext(),
R.drawable.ic_sentiment_neutral_white_18dp), null, null, null);
else if (mediaBase.getMeanScore() >= 67 && mediaBase.getMeanScore() <= 100)
binding.ratingValue.setCompoundDrawablesWithIntrinsicBounds(CompatUtil.getDrawable(getContext(),
R.drawable.ic_sentiment_satisfied_white_18dp), null, null, null);
break;
}
else
binding.ratingValue.setText(String.format(Locale.getDefault(),"%d", mediaBase.getMeanScore()));
}

@BindingAdapter("rating")
public static void setAverageRating(RatingTextView view, MediaBase mediaBase) {
float rating = (float) mediaBase.getAverageScore() * MAX / 100;
view.setRating(rating);
//float rating = (float) mediaBase.getAverageScore() * MAX / 100;
view.setRating(mediaBase);
view.setFavourState(mediaBase.isFavourite());
}

@BindingAdapter("rating")
public static void setAverageRating(RatingTextView view, MediaList mediaList) {
float rating = (float) mediaList.getScore() * MAX / 100;
view.setRating(rating);
//float rating = (float) mediaList.getScore() * MAX / 100;
view.setRating(mediaList);
view.setFavourState(mediaList.getMedia().isFavourite());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void bindFields() {
binding.diaCurrentProgress.setProgressMaximum(model.getMedia().getEpisodes());

binding.diaCurrentScore.setProgressMaximum(100);
binding.diaCurrentScore.setProgressCurrent(model.getScore());
binding.diaCurrentScore.setProgressCurrent((int)model.getScore());
binding.diaCurrentProgress.setProgressCurrent(model.getProgress());
binding.diaCurrentRewatch.setProgressCurrent(model.getRepeat());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected void bindFields() {
binding.diaCurrentChapters.setProgressMaximum(model.getMedia().getChapters());

binding.diaCurrentScore.setProgressMaximum(100);
binding.diaCurrentScore.setProgressCurrent(model.getScore());
binding.diaCurrentScore.setProgressCurrent((int)model.getScore());
binding.diaCurrentChapters.setProgressCurrent(model.getProgress());
binding.diaCurrentVolumes.setProgressCurrent(model.getProgressVolumes());
binding.diaCurrentReread.setProgressCurrent(model.getRepeat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MediaList extends RecyclerItem implements Parcelable, Cloneable {
private long id;
private long mediaId;
private @KeyUtil.MediaListStatus String status;
private int score;
private float score;
private int progress;
private int progressVolumes;
private int repeat;
Expand All @@ -46,7 +46,7 @@ protected MediaList(Parcel in) {
id = in.readLong();
mediaId = in.readLong();
status = in.readString();
score = in.readInt();
score = in.readFloat();
progress = in.readInt();
progressVolumes = in.readInt();
repeat = in.readInt();
Expand All @@ -67,7 +67,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeLong(mediaId);
dest.writeString(status);
dest.writeInt(score);
dest.writeFloat(score);
dest.writeInt(progress);
dest.writeInt(progressVolumes);
dest.writeInt(repeat);
Expand Down Expand Up @@ -112,7 +112,7 @@ public long getMediaId() {
return status;
}

public int getScore() {
public float getScore() {
return score;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.mxt.anitrend.util.CompatUtil;
import com.mxt.anitrend.util.KeyUtil;

import java.util.Locale;
Expand Down Expand Up @@ -66,23 +67,31 @@ public MediaRank[] newArray(int size) {
public String getTypeHtml() {
if(year == 0)
if(season != null)
return String.format(Locale.getDefault(), "<b>#%d %s <small>%s<small/></b> <small>(%s)</small>", rank, context.toUpperCase(), season.toUpperCase(), format);
return String.format(Locale.getDefault(), "<b>#%d %s <small>%s<small/></b> <small>(%s)</small>",
rank, context.toUpperCase(), season.toUpperCase(), CompatUtil.capitalizeWords(format));
else
return String.format(Locale.getDefault(), "<b>#%d %s</b> <small>(%s)</small>", rank, context.toUpperCase(), format);
return String.format(Locale.getDefault(), "<b>#%d %s</b> <small>(%s)</small>",
rank, context.toUpperCase(), CompatUtil.capitalizeWords(format));
if(season != null)
return String.format(Locale.getDefault(), "<b>#%d %s <small>%s %d</small></b> <small>(%s)</small>", rank, context.toUpperCase(), season.toUpperCase(), year, format);
return String.format(Locale.getDefault(), "<b>#%d %s <small>%d</small></b> <small>(%s)</small>", rank, context.toUpperCase(), year, format);
return String.format(Locale.getDefault(), "<b>#%d %s <small>%s %d</small></b> <small>(%s)</small>",
rank, context.toUpperCase(), season.toUpperCase(), year, CompatUtil.capitalizeWords(format));
return String.format(Locale.getDefault(), "<b>#%d %s <small>%d</small></b> <small>(%s)</small>",
rank, context.toUpperCase(), year, CompatUtil.capitalizeWords(format));
}

public String getTypeHtmlPlainTitle() {
if(year == 0)
if(season != null)
return String.format(Locale.getDefault(), "%s <small>%s<small/> <small>(%s)</small>", context.toUpperCase(), season, format);
return String.format(Locale.getDefault(), "%s <small>%s<small/> <small>(%s)</small>",
context.toUpperCase(), season, CompatUtil.capitalizeWords(format));
else
return String.format(Locale.getDefault(), "%s <small>(%s)</small>", context.toUpperCase(), format);
return String.format(Locale.getDefault(), "%s <small>(%s)</small>",
context.toUpperCase(), CompatUtil.capitalizeWords(format));
if(season != null)
return String.format(Locale.getDefault(), "%s <small>%s %d</small> <small>(%s)</small>", context.toUpperCase(), season, year, format);
return String.format(Locale.getDefault(), "%s <small>%d</small> <small>(%s)</small>", context.toUpperCase(), year, format);
return String.format(Locale.getDefault(), "%s <small>%s %d</small> <small>(%s)</small>",
context.toUpperCase(), season, year, CompatUtil.capitalizeWords(format));
return String.format(Locale.getDefault(), "%s <small>%d</small> <small>(%s)</small>",
context.toUpperCase(), year, CompatUtil.capitalizeWords(format));
}

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Created by max on 2018/03/22.
* https://anilist.github.io/ApiV2-GraphQL-Docs/medialistoptions.doc.html
*/

public class MediaListOptions implements Parcelable {
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/com/mxt/anitrend/util/ApplicationPref.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public class ApplicationPref {
public static final String _isAmoledTheme = "_isAmoledTheme";

/** Api Keys */
private final String _sortOrder = "_sortOrder";
private final String _mediaStatus = "_mediaStatus";
private final String _mediaFormat = "_mediaFormat";
private final String _mediaSource = "_mediaSource";
private final String _airingSort = "_airingSort";
private final String _characterSort = "_characterSort";
private final String _mediaListSort = "_mediaListSort";
private final String _mediaSort = "_mediaSort";
private final String _mediaTrendSort = "_mediaTrendSort";
private final String _reviewSort = "_reviewSort";
private final String _staffSort = "_staffSort";
private static final String _sortOrder = "_sortOrder";
private static final String _mediaStatus = "_mediaStatus";
private static final String _mediaFormat = "_mediaFormat";
private static final String _mediaSource = "_mediaSource";
private static final String _airingSort = "_airingSort";
private static final String _characterSort = "_characterSort";
public static final String _mediaListSort = "_mediaListSort";
private static final String _mediaSort = "_mediaSort";
private static final String _mediaTrendSort = "_mediaTrendSort";
private static final String _reviewSort = "_reviewSort";
private static final String _staffSort = "_staffSort";

private SharedPreferences sharedPreferences;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.mxt.anitrend.base.custom.fragment.FragmentBaseList;
import com.mxt.anitrend.model.entity.anilist.MediaList;
import com.mxt.anitrend.model.entity.anilist.MediaListCollection;
import com.mxt.anitrend.model.entity.anilist.meta.MediaListOptions;
import com.mxt.anitrend.model.entity.base.MediaBase;
import com.mxt.anitrend.model.entity.base.MediaListCollectionBase;
import com.mxt.anitrend.model.entity.container.body.PageContainer;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class MediaListFragment extends FragmentBaseList<MediaList, PageContainer
protected long userId;
protected String userName;
protected @KeyUtil.MediaType String mediaType;
protected MediaListOptions mediaListOptions;

protected MediaListCollectionBase mediaListCollectionBase;
protected QueryContainerBuilder queryContainer;
Expand Down Expand Up @@ -136,22 +138,22 @@ protected void updateUI() {
*/
@Override
public void makeRequest() {
ApplicationPref pref = getPresenter().getApplicationPref();

mediaListOptions = getPresenter().getDatabase().getCurrentUser().getMediaListOptions();
if (userId != 0)
queryContainer.putVariable(KeyUtil.arg_userId, userId);
else
queryContainer.putVariable(KeyUtil.arg_userName, userName);

queryContainer.putVariable(KeyUtil.arg_mediaType, mediaType)
.putVariable(KeyUtil.arg_scoreFormat, KeyUtil.POINT_100)
.putVariable(KeyUtil.arg_forceSingleCompletedList, true);
.putVariable(KeyUtil.arg_forceSingleCompletedList, true)
.putVariable(KeyUtil.arg_scoreFormat, mediaListOptions.getScoreFormat());

// since anilist doesn't support sorting by title we set a temporary sorting key
if(!MediaListUtil.isTitleSort(pref.getMediaListSort()))
queryContainer.putVariable(KeyUtil.arg_sort, pref.getMediaListSort() + pref.getSortOrder());
if(!MediaListUtil.isTitleSort(getPresenter().getApplicationPref().getMediaListSort()))
queryContainer.putVariable(KeyUtil.arg_sort, getPresenter().getApplicationPref().getMediaListSort() +
getPresenter().getApplicationPref().getSortOrder());
else
queryContainer.putVariable(KeyUtil.arg_sort, KeyUtil.MEDIA_ID + pref.getSortOrder());
queryContainer.putVariable(KeyUtil.arg_sort, KeyUtil.MEDIA_ID + getPresenter().getApplicationPref().getSortOrder());

getViewModel().getParams().putParcelable(KeyUtil.arg_graph_params, queryContainer);
getViewModel().requestData(KeyUtil.MEDIA_LIST_COLLECTION_REQ, getContext());
Expand All @@ -161,7 +163,7 @@ public void makeRequest() {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(getPresenter() != null && isFilterable && GraphUtil.isKeyFilter(key)) {
@KeyUtil.MediaListSort String mediaListSort = getPresenter().getApplicationPref().getMediaListSort();
if(CompatUtil.equals(key, "_mediaListSort") && MediaListUtil.isTitleSort(mediaListSort)) {
if(CompatUtil.equals(key, ApplicationPref._mediaListSort) && MediaListUtil.isTitleSort(mediaListSort)) {
swipeRefreshLayout.setRefreshing(true);
sortMediaListByTitle(mAdapter.getData());
}
Expand Down Expand Up @@ -232,6 +234,7 @@ public void onChanged(@Nullable PageContainer<MediaListCollection> content) {
@Override
public void onItemClick(View target, IntPair<MediaList> data) {
switch (target.getId()) {
case R.id.container:
case R.id.series_image:
MediaBase mediaBase = data.getSecond().getMedia();
Intent intent = new Intent(getActivity(), MediaActivity.class);
Expand All @@ -252,6 +255,7 @@ public void onItemClick(View target, IntPair<MediaList> data) {
@Override
public void onItemLongClick(View target, IntPair<MediaList> data) {
switch (target.getId()) {
case R.id.container:
case R.id.series_image:
if(getPresenter().getApplicationPref().isAuthenticated()) {
mediaActionUtil = new MediaActionUtil.Builder()
Expand Down
Loading

0 comments on commit 065b885

Please sign in to comment.