Allow to set status, score and last chapter read in MAL. Other minor changes

This commit is contained in:
inorichi 2015-12-20 20:10:04 +01:00
parent 5f44e5d492
commit 50d6632d0e
15 changed files with 370 additions and 153 deletions

View file

@ -14,8 +14,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ui.main.MainActivity"
android:theme="@style/AppTheme" >
android:name=".ui.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View file

@ -20,6 +20,7 @@ import java.util.List;
import javax.inject.Inject;
import eu.kanade.mangafeed.App;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.models.MangaSync;
import eu.kanade.mangafeed.data.mangasync.MangaSyncManager;
import eu.kanade.mangafeed.data.mangasync.base.MangaSyncService;
@ -52,7 +53,10 @@ public class MyAnimeList extends MangaSyncService {
public static final int DEFAULT_STATUS = READING;
public static final int DEFAULT_SCORE = 0;
private Context context;
public MyAnimeList(Context context) {
this.context = context;
App.get(context).getComponent().inject(this);
String username = preferences.getMangaSyncUsername(this);
@ -228,15 +232,15 @@ public class MyAnimeList extends MangaSyncService {
public String getStatus(int status) {
switch (status) {
case READING:
return "Reading";
return context.getString(R.string.reading);
case COMPLETED:
return "Completed";
return context.getString(R.string.completed);
case ON_HOLD:
return "On hold";
return context.getString(R.string.on_hold);
case DROPPED:
return "Dropped";
return context.getString(R.string.dropped);
case PLAN_TO_READ:
return "Plan to read";
return context.getString(R.string.plan_to_read);
}
return "";
}

View file

@ -29,7 +29,6 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
restartableLatestCache(GET_MANGAS,
() -> db.getFavoriteMangasWithUnread().createObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()),
LibraryFragment::onNextMangas);

View file

@ -1,21 +1,21 @@
package eu.kanade.mangafeed.ui.manga.myanimelist;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.TextView;
import com.afollestad.materialdialogs.MaterialDialog;
import java.text.DecimalFormat;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.models.MangaSync;
import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment;
@ -25,10 +25,9 @@ import nucleus.factory.RequiresPresenter;
public class MyAnimeListFragment extends BaseRxFragment<MyAnimeListPresenter> {
@Bind(R.id.myanimelist_title) TextView title;
@Bind(R.id.last_chapter_read) EditText lastChapterRead;
@Bind(R.id.score) TextView score;
@Bind(R.id.status) TextView status;
@Bind(R.id.update_button) Button updateButton;
@Bind(R.id.myanimelist_chapters) TextView chapters;
@Bind(R.id.myanimelist_score) TextView score;
@Bind(R.id.myanimelist_status) TextView status;
private MyAnimeListDialogFragment dialog;
@ -38,43 +37,17 @@ public class MyAnimeListFragment extends BaseRxFragment<MyAnimeListPresenter> {
return new MyAnimeListFragment();
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_myanimelist, container, false);
ButterKnife.bind(this, view);
updateButton.setOnClickListener(v -> getPresenter().updateLastChapter(
Integer.parseInt(lastChapterRead.getText().toString())));
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.myanimelist, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.myanimelist_edit:
showSearchDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
public void setMangaSync(MangaSync mangaSync) {
title.setText(mangaSync.title);
lastChapterRead.setText(mangaSync.last_chapter_read + "");
score.setText(decimalFormat.format(mangaSync.score));
chapters.setText(mangaSync.last_chapter_read + "");
score.setText(mangaSync.score == 0 ? "-" : decimalFormat.format(mangaSync.score));
status.setText(getPresenter().myAnimeList.getStatus(mangaSync.status));
}
@ -89,4 +62,86 @@ public class MyAnimeListFragment extends BaseRxFragment<MyAnimeListPresenter> {
if (dialog != null)
dialog.setResults(results);
}
@OnClick(R.id.myanimelist_title_layout)
void onTitleClick() {
showSearchDialog();
}
@OnClick(R.id.myanimelist_status_layout)
void onStatusClick() {
if (getPresenter().mangaSync == null)
return;
Context ctx = getActivity();
new MaterialDialog.Builder(ctx)
.title(R.string.status)
.items(getPresenter().getAllStatus(ctx))
.itemsCallbackSingleChoice(getPresenter().getIndexFromStatus(),
(materialDialog, view, i, charSequence) -> {
getPresenter().setStatus(i);
status.setText("...");
return true;
})
.show();
}
@OnClick(R.id.myanimelist_chapters_layout)
void onChaptersClick() {
if (getPresenter().mangaSync == null)
return;
MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
.title(R.string.chapters)
.customView(R.layout.dialog_myanimelist_chapters, false)
.positiveText(R.string.button_ok)
.negativeText(R.string.button_cancel)
.onPositive((materialDialog, dialogAction) -> {
View view = materialDialog.getCustomView();
if (view != null) {
NumberPicker np = (NumberPicker) view.findViewById(R.id.chapters_picker);
getPresenter().setLastChapterRead(np.getValue());
chapters.setText("...");
}
})
.show();
View view = dialog.getCustomView();
if (view != null) {
NumberPicker np = (NumberPicker) view.findViewById(R.id.chapters_picker);
// Set initial value
np.setValue(getPresenter().mangaSync.last_chapter_read);
// Don't allow to go from 0 to 9999
np.setWrapSelectorWheel(false);
}
}
@OnClick(R.id.myanimelist_score_layout)
void onScoreClick() {
if (getPresenter().mangaSync == null)
return;
MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
.title(R.string.score)
.customView(R.layout.dialog_myanimelist_score, false)
.positiveText(R.string.button_ok)
.negativeText(R.string.button_cancel)
.onPositive((materialDialog, dialogAction) -> {
View view = materialDialog.getCustomView();
if (view != null) {
NumberPicker np = (NumberPicker) view.findViewById(R.id.score_picker);
getPresenter().setScore(np.getValue());
score.setText("...");
}
})
.show();
View view = dialog.getCustomView();
if (view != null) {
NumberPicker np = (NumberPicker) view.findViewById(R.id.score_picker);
// Set initial value
np.setValue((int) getPresenter().mangaSync.score);
}
}
}

View file

@ -1,19 +1,20 @@
package eu.kanade.mangafeed.ui.manga.myanimelist;
import android.content.Context;
import android.os.Bundle;
import javax.inject.Inject;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.DatabaseHelper;
import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.database.models.MangaSync;
import eu.kanade.mangafeed.data.mangasync.MangaSyncManager;
import eu.kanade.mangafeed.data.mangasync.services.MyAnimeList;
import eu.kanade.mangafeed.data.database.DatabaseHelper;
import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
import eu.kanade.mangafeed.util.EventBusHook;
import eu.kanade.mangafeed.util.ToastUtil;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber;
@ -25,13 +26,11 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
protected MyAnimeList myAnimeList;
protected Manga manga;
private MangaSync mangaSync;
protected MangaSync mangaSync;
private String query;
private Subscription updateSubscription;
private static final int GET_CHAPTER_SYNC = 1;
private static final int GET_MANGA_SYNC = 1;
private static final int GET_SEARCH_RESULTS = 2;
@Override
@ -44,7 +43,7 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
myAnimeList = syncManager.getMyAnimeList();
restartableLatestCache(GET_CHAPTER_SYNC,
restartableLatestCache(GET_MANGA_SYNC,
() -> db.getMangaSync(manga, myAnimeList).createObservable()
.flatMap(Observable::from)
.doOnNext(mangaSync -> this.mangaSync = mangaSync)
@ -65,7 +64,7 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
}
private void onProcessRestart() {
stop(GET_CHAPTER_SYNC);
stop(GET_MANGA_SYNC);
stop(GET_SEARCH_RESULTS);
}
@ -84,22 +83,19 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
@EventBusHook
public void onEventMainThread(Manga manga) {
this.manga = manga;
start(GET_CHAPTER_SYNC);
start(GET_MANGA_SYNC);
}
public void updateLastChapter(int chapterNumber) {
if (updateSubscription != null)
remove(updateSubscription);
mangaSync.last_chapter_read = chapterNumber;
add(updateSubscription = myAnimeList.update(mangaSync)
private void updateRemote() {
add(myAnimeList.update(mangaSync)
.flatMap(response -> db.insertMangaSync(mangaSync).createObservable())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> {},
.subscribe(next -> {},
error -> {
Timber.e(error.getMessage());
// Restart on error to set old values
start(GET_MANGA_SYNC);
}
));
}
@ -114,15 +110,42 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
add(myAnimeList.bind(manga)
.flatMap(response -> {
if (response.isSuccessful()) {
return Observable.just(manga);
return db.insertMangaSync(manga).createObservable();
}
return Observable.error(new Exception("Could not add manga"));
return Observable.error(new Exception("Could not bind manga"));
})
.flatMap(manga2 -> db.insertMangaSync(manga2).createObservable())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(manga2 -> {},
error -> ToastUtil.showShort(getContext(), error.getMessage())));
}
public String[] getAllStatus(Context context) {
return new String[] {
context.getString(R.string.reading),
context.getString(R.string.completed),
context.getString(R.string.on_hold),
context.getString(R.string.dropped),
context.getString(R.string.plan_to_read)
};
}
public int getIndexFromStatus() {
return mangaSync.status == 6 ? 4 : mangaSync.status - 1;
}
public void setStatus(int index) {
mangaSync.status = index == 4 ? 6 : index + 1;
updateRemote();
}
public void setScore(int score) {
mangaSync.score = score;
updateRemote();
}
public void setLastChapterRead(int chapterNumber) {
mangaSync.last_chapter_read = chapterNumber;
updateRemote();
}
}

View file

@ -0,0 +1,36 @@
package eu.kanade.mangafeed.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.NumberPicker;
import eu.kanade.mangafeed.R;
public class MinMaxNumberPicker extends NumberPicker{
public MinMaxNumberPicker(Context context) {
super(context);
}
public MinMaxNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
processAttributeSet(context, attrs);
}
public MinMaxNumberPicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
processAttributeSet(context, attrs);
}
private void processAttributeSet(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MinMaxNumberPicker, 0, 0);
try {
setMinValue(ta.getInt(R.styleable.MinMaxNumberPicker_min, 0));
setMaxValue(ta.getInt(R.styleable.MinMaxNumberPicker_max, 0));
} finally {
ta.recycle();
}
}
}

View file

@ -29,7 +29,6 @@
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@color/white" />
android:layout_weight="1"/>
</LinearLayout>

View file

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/myanimelist_title_layout"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:paddingRight="?android:listPreferredItemPaddingRight"
android:background="?attr/selectableItemBackground"
android:clickable="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Title"/>
<TextView
android:id="@+id/myanimelist_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text="Edit..."/>
</RelativeLayout>
<View
android:id="@+id/divider1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/myanimelist_title_layout"
android:background="@color/list_choice_pressed_bg_light" />
<RelativeLayout
android:id="@+id/myanimelist_status_layout"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:layout_below="@id/divider1"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:paddingRight="?android:listPreferredItemPaddingRight"
android:background="?attr/selectableItemBackground"
android:clickable="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/status"/>
<TextView
android:id="@+id/myanimelist_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
tools:text="Reading"/>
</RelativeLayout>
<View
android:id="@+id/divider2"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/myanimelist_status_layout"
android:background="@color/list_choice_pressed_bg_light" />
<RelativeLayout
android:id="@+id/myanimelist_chapters_layout"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:layout_below="@id/divider2"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:paddingRight="?android:listPreferredItemPaddingRight"
android:background="?attr/selectableItemBackground"
android:clickable="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Chapters"/>
<TextView
android:id="@+id/myanimelist_chapters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
tools:text="12/24"/>
</RelativeLayout>
<View
android:id="@+id/divider3"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/myanimelist_chapters_layout"
android:background="@color/list_choice_pressed_bg_light" />
<RelativeLayout
android:id="@+id/myanimelist_score_layout"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:layout_below="@id/divider3"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:paddingRight="?android:listPreferredItemPaddingRight"
android:background="?attr/selectableItemBackground"
android:clickable="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/score"/>
<TextView
android:id="@+id/myanimelist_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
tools:text="10"/>
</RelativeLayout>
</RelativeLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<eu.kanade.mangafeed.widget.MinMaxNumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/chapters_picker"
app:min="0"
app:max="9999"/>
</LinearLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<eu.kanade.mangafeed.widget.MinMaxNumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/score_picker"
app:min="0"
app:max="10"/>
</LinearLayout>

View file

@ -19,6 +19,7 @@
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:descendantFocusability="blocksDescendants"
android:background="@color/white"
tools:listitem="@layout/item_chapter">
</android.support.v7.widget.RecyclerView>

View file

@ -5,80 +5,13 @@
android:layout_height="match_parent"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyAnimeList title:" />
<include layout="@layout/card_myanimelist_personal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myanimelist_title" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last chapter read" />
<EditText
android:layout_width="56dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/last_chapter_read"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_update"
android:id="@+id/update_button"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/score"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/status"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/action_edit"
android:id="@+id/myanimelist_edit"
android:icon="@drawable/ic_create"
app:showAsAction="ifRoom" />
</menu>

View file

@ -11,4 +11,9 @@
<declare-styleable name="PTSansTextView">
<attr name="typeface"/>
</declare-styleable>
<declare-styleable name="MinMaxNumberPicker">
<attr name="min" format="integer"/>
<attr name="max" format="integer"/>
</declare-styleable>
</resources>

View file

@ -119,6 +119,14 @@
<string name="chapter_error">Error</string>
<string name="fetch_chapters_error">Error while fetching chapters</string>
<!-- MyAnimeList fragment -->
<string name="reading">Reading</string>
<string name="completed">Completed</string>
<string name="dropped">Dropped</string>
<string name="on_hold">On hold</string>
<string name="plan_to_read">Plan to read</string>
<string name="score">Score</string>
<!-- Reader activity -->
<string name="downloading">Downloading…</string>
<string name="download_progress">Downloaded %1$d%%</string>