diff --git a/app/build.gradle b/app/build.gradle index e48ff9f2a..eb52dbd0d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,7 +53,7 @@ dependencies { final DAGGER_VERSION = '2.0.1' final HAMCREST_VERSION = '1.3' final MOCKITO_VERSION = '1.10.19' - final STORIO_VERSION = '1.4.0' + final STORIO_VERSION = '1.5.0' final NUCLEUS_VERSION = '2.0.1' final ICEPICK_VERSION = '3.1.0' @@ -65,8 +65,8 @@ dependencies { compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION" - compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' - compile 'com.squareup.okhttp:okhttp:2.4.0' + compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0' + compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.squareup.okio:okio:1.6.0' compile 'com.google.code.gson:gson:2.4' compile 'com.jakewharton:disklrucache:2.0.2' @@ -80,7 +80,7 @@ dependencies { compile 'de.greenrobot:eventbus:2.4.0' compile 'com.github.bumptech.glide:glide:3.6.1' compile 'com.jakewharton:butterknife:7.0.1' - compile 'com.jakewharton.timber:timber:3.1.0' + compile 'com.jakewharton.timber:timber:4.1.0' compile 'uk.co.ribot:easyadapter:1.5.0@aar' compile 'ch.acra:acra:4.6.2' compile 'com.github.castorflex.verticalviewpager:library:19.0.1' diff --git a/app/src/main/java/eu/kanade/mangafeed/data/managers/MangaManagerImpl.java b/app/src/main/java/eu/kanade/mangafeed/data/managers/MangaManagerImpl.java index 5ced02879..5d546c304 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/managers/MangaManagerImpl.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/managers/MangaManagerImpl.java @@ -21,16 +21,17 @@ public class MangaManagerImpl extends BaseManager implements MangaManager { super(db); } - private final String mangasWithUnreadQuery = String.format( + private final String favoriteMangasWithUnreadQuery = String.format( "SELECT %1$s.*, COUNT(C.%4$s) AS %5$s FROM %1$s LEFT JOIN " + "(SELECT %4$s FROM %2$s WHERE %6$s = 0) AS C ON %3$s = C.%4$s " + - "GROUP BY %3$s", + "WHERE %7$s = 1 GROUP BY %3$s", MangasTable.TABLE, ChaptersTable.TABLE, MangasTable.TABLE + "." + MangasTable.COLUMN_ID, ChaptersTable.COLUMN_MANGA_ID, MangasTable.COLUMN_UNREAD, - ChaptersTable.COLUMN_READ + ChaptersTable.COLUMN_READ, + MangasTable.COLUMN_FAVORITE ); public Observable> getMangas() { @@ -47,7 +48,7 @@ public class MangaManagerImpl extends BaseManager implements MangaManager { return db.get() .listOfObjects(Manga.class) .withQuery(RawQuery.builder() - .query(mangasWithUnreadQuery) + .query(favoriteMangasWithUnreadQuery) .observesTables(MangasTable.TABLE, ChaptersTable.TABLE) .build()) .prepare() diff --git a/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java b/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java index 1054514b9..d886c3095 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java @@ -38,8 +38,8 @@ public class Manga { @StorIOSQLiteColumn(name = MangasTable.COLUMN_THUMBNAIL_URL) public String thumbnail_url; - @StorIOSQLiteColumn(name = MangasTable.COLUMN_RANK) - public int rank; + @StorIOSQLiteColumn(name = MangasTable.COLUMN_FAVORITE) + public boolean favorite; @StorIOSQLiteColumn(name = MangasTable.COLUMN_LAST_UPDATE) public long last_update; @@ -57,30 +57,6 @@ public class Manga { public Manga() {} - public Manga(String title) { - this.title = title; - } - - public Manga(String title, String author, String artist, String url, - String description, String genre, String status, int rank, - String thumbnail_url) { - this.title = title; - this.author = author; - this.artist = artist; - this.url = url; - this.description = description; - this.genre = genre; - this.status = status; - this.rank = rank; - this.thumbnail_url = thumbnail_url; - } - - public static Manga newManga(String title, String author, String artist, String url, - String description, String genre, String status, int rank, - String thumbnail_url) { - return new Manga(title, author, artist, url, description, genre, status, rank, thumbnail_url); - } - public static void copyFromNetwork(Manga local, Manga network) { if (network.title != null) local.title = network.title; @@ -107,6 +83,7 @@ public class Manga { local.thumbnail_url = network.thumbnail_url; local.initialized = true; + } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/data/tables/MangasTable.java b/app/src/main/java/eu/kanade/mangafeed/data/tables/MangasTable.java index d51d109a0..732343413 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/tables/MangasTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/tables/MangasTable.java @@ -2,9 +2,6 @@ package eu.kanade.mangafeed.data.tables; import android.support.annotation.NonNull; -/** - * Created by len on 23/09/2015. - */ public class MangasTable { @NonNull @@ -41,7 +38,7 @@ public class MangasTable { public static final String COLUMN_THUMBNAIL_URL = "thumbnail_url"; @NonNull - public static final String COLUMN_RANK = "rank"; + public static final String COLUMN_FAVORITE = "favorite"; @NonNull public static final String COLUMN_LAST_UPDATE = "last_update"; @@ -78,7 +75,7 @@ public class MangasTable { + COLUMN_TITLE + " TEXT NOT NULL, " + COLUMN_STATUS + " TEXT, " + COLUMN_THUMBNAIL_URL + " TEXT, " - + COLUMN_RANK + " INTEGER, " + + COLUMN_FAVORITE + " INTEGER NOT NULL, " + COLUMN_LAST_UPDATE + " LONG, " + COLUMN_INITIALIZED + " BOOLEAN NOT NULL, " + COLUMN_VIEWER + " INTEGER NOT NULL, " diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java index 20360a281..e78ba0c8b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java @@ -52,8 +52,12 @@ public class LibraryPresenter extends BasePresenter { .observeOn(Schedulers.io()) .map(checkedItems::keyAt) .map(adapter::getItem) + .map(manga -> { + manga.favorite = false; + return manga; + }) .toList() - .flatMap(db::deleteMangas) + .flatMap(db::insertMangas) .subscribe()); } diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java index 204d07029..cb96c2a31 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaDetailPresenter.java @@ -17,6 +17,8 @@ public class MangaDetailPresenter extends BasePresenter { @Inject DatabaseHelper db; private long mangaId; + private Manga manga; + private static final int DB_MANGA = 1; @Override @@ -24,9 +26,11 @@ public class MangaDetailPresenter extends BasePresenter { super.onCreate(savedState); restartableLatestCache(DB_MANGA, - this::getDbMangaObservable, + () -> getDbMangaObservable() + .doOnNext(manga -> this.manga = manga), (view, manga) -> { view.setManga(manga); + view.setFavoriteBtnVisible(!manga.favorite); EventBus.getDefault().postSticky(manga); }); } @@ -41,7 +45,6 @@ public class MangaDetailPresenter extends BasePresenter { private Observable getDbMangaObservable() { return db.getManga(mangaId) .subscribeOn(Schedulers.io()) - .take(1) .flatMap(Observable::from) .observeOn(AndroidSchedulers.mainThread()); } @@ -51,4 +54,14 @@ public class MangaDetailPresenter extends BasePresenter { start(DB_MANGA); } + public void setFavoriteVisibility() { + if (getView() != null) { + getView().setFavoriteBtnVisible(!manga.favorite); + } + } + + public boolean addToFavorites() { + manga.favorite = true; + return db.insertMangaBlock(manga).numberOfRowsUpdated() == 1; + } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java index 19f90cb8e..e5ff188e0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java @@ -10,7 +10,9 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; +import android.view.Menu; import android.view.MenuItem; +import android.widget.Toast; import butterknife.Bind; import butterknife.ButterKnife; @@ -32,6 +34,7 @@ public class MangaDetailActivity extends BaseRxActivity { private MangaDetailAdapter adapter; private long manga_id; private boolean is_online; + private MenuItem favoriteBtn; public final static String MANGA_ID = "manga_id"; public final static String MANGA_ONLINE = "manga_online"; @@ -62,12 +65,23 @@ public class MangaDetailActivity extends BaseRxActivity { getPresenter().queryManga(manga_id); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.manga, menu); + favoriteBtn = menu.findItem(R.id.action_favorite); + getPresenter().setFavoriteVisibility(); + return true; + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; + case R.id.action_favorite: + onFavoriteClick(); + return true; } return super.onOptionsItemSelected(item); } @@ -98,10 +112,22 @@ public class MangaDetailActivity extends BaseRxActivity { setToolbarTitle(manga.title); } + public void setFavoriteBtnVisible(boolean visible) { + if (favoriteBtn != null) + favoriteBtn.setVisible(visible); + } + public boolean isOnlineManga() { return is_online; } + private void onFavoriteClick() { + if (getPresenter().addToFavorites()) { + Toast.makeText(this, getString(R.string.toast_added_favorites), Toast.LENGTH_SHORT) + .show(); + } + } + class MangaDetailAdapter extends FragmentPagerAdapter { final int PAGE_COUNT = 2; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java b/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java index 507bd4d17..819a17c1c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java @@ -101,6 +101,9 @@ public class LoginDialogPreference extends DialogPreference { if (requestSubscription != null) requestSubscription.unsubscribe(); + if (username.getText().length() == 0 || password.getText().length() == 0) + return; + loginBtn.setProgress(1); requestSubscription = source.login(username.getText().toString(), diff --git a/app/src/main/res/drawable-hdpi/ic_action_favorite.png b/app/src/main/res/drawable-hdpi/ic_action_favorite.png new file mode 100644 index 000000000..3af6b7872 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_favorite.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_favorite.png b/app/src/main/res/drawable-mdpi/ic_action_favorite.png new file mode 100644 index 000000000..23f45f40a Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_favorite.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_favorite.png b/app/src/main/res/drawable-xhdpi/ic_action_favorite.png new file mode 100644 index 000000000..5afd1cfd9 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_favorite.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_favorite.png b/app/src/main/res/drawable-xxhdpi/ic_action_favorite.png new file mode 100644 index 000000000..a93d59c81 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_favorite.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_favorite.png b/app/src/main/res/drawable-xxxhdpi/ic_action_favorite.png new file mode 100644 index 000000000..f2b712612 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_favorite.png differ diff --git a/app/src/main/res/menu/manga.xml b/app/src/main/res/menu/manga.xml new file mode 100644 index 000000000..d3cc6ac6a --- /dev/null +++ b/app/src/main/res/menu/manga.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 48848ff9d..2dc2882e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,5 +71,7 @@ Success Login error Loading… + Added to favorites + Favorite diff --git a/build.gradle b/build.gradle index d591678ac..ade6a1190 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.github.ben-manes.versions' buildscript { repositories { @@ -13,6 +14,7 @@ buildscript { classpath 'com.zeroturnaround.jrebel.android:jr-android-gradle:0.9.+' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' classpath 'me.tatarka:gradle-retrolambda:3.2.3' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }