From 35b8be6c75e263236a83886aa5263d67adc07da2 Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 27 Oct 2015 00:00:09 +0100 Subject: [PATCH] Library now showing favorite mangas --- app/build.gradle | 8 ++--- .../data/managers/MangaManagerImpl.java | 9 +++--- .../kanade/mangafeed/data/models/Manga.java | 29 ++---------------- .../mangafeed/data/tables/MangasTable.java | 7 ++--- .../mangafeed/presenter/LibraryPresenter.java | 6 +++- .../presenter/MangaDetailPresenter.java | 17 ++++++++-- .../ui/activity/MangaDetailActivity.java | 26 ++++++++++++++++ .../ui/dialog/LoginDialogPreference.java | 3 ++ .../res/drawable-hdpi/ic_action_favorite.png | Bin 0 -> 387 bytes .../res/drawable-mdpi/ic_action_favorite.png | Bin 0 -> 262 bytes .../res/drawable-xhdpi/ic_action_favorite.png | Bin 0 -> 479 bytes .../drawable-xxhdpi/ic_action_favorite.png | Bin 0 -> 707 bytes .../drawable-xxxhdpi/ic_action_favorite.png | Bin 0 -> 901 bytes app/src/main/res/menu/manga.xml | 11 +++++++ app/src/main/res/values/strings.xml | 2 ++ build.gradle | 2 ++ 16 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_action_favorite.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_favorite.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_favorite.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_favorite.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_action_favorite.png create mode 100644 app/src/main/res/menu/manga.xml diff --git a/app/build.gradle b/app/build.gradle index e48ff9f2a0..eb52dbd0d5 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 5ced02879a..5d546c3042 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 1054514b90..d886c30959 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 d51d109a07..7323434134 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 20360a2812..e78ba0c8b4 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 204d070294..cb96c2a310 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 19f90cb8eb..e5ff188e08 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 507bd4d17b..819a17c1c7 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 0000000000000000000000000000000000000000..3af6b78729d71e6b204002a868de7af6d3da6b85 GIT binary patch literal 387 zcmV-}0et?6P)Nkl9rmzfod2@^_I#D?xPQHsBTm9kajAFz_8g%!$HRQ%WWqR@00mH8myq zb+Z|YjIU`FUiaL&_nf=r**^8zo%cDh*nhM`k{Om+VF3qAG&UKQSgp6yB%33>?DEQY zE}6$}G%YMr{?WX!LysRbg^M=_bdcgm(L6AzVjP}Or$EW4sWSSTiF1ZYinK~-4%5s^ zXx|vxlhBPZbSQ^RA?idIY4IW|NK2 hy^Ts)@(=Lm@&PB3pia=|pE>{l002ovPDHLkV1i{=sm%ZY literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..23f45f40a626c09d0060d1b43d7312b9b621d953 GIT binary patch literal 262 zcmV+h0r~!kP)mNsC+GI z#EJiZhFAI1|6=HIZTkN!PUT#ZaCum`+sL#3D6Um05Fxi;Y+hl|39NB|AZ1Y zShbk`e+^gu8mrqew5b1o09O9szZ$WbN$US)Ae15{{|WvV9H_hx0D%b*x6t9BYybcN M07*qoM6N<$f+i(;761SM literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..5afd1cfd9fa626ab7154c95035c31a6c2e1d547e GIT binary patch literal 479 zcmV<50U-W~P)psBGS2%Mt5A%cjMq-bmi0*3~} z=)*RXCa;vgUK)ga@0Z@==5v?J%@4czz-Sqwn3j(6K0b* zAF86DDlb{1$DMhA0}RUb%@M&;O)tmlOS$sw)9z$HP8us^nfa@kC1+Xl#F)MPCw3~b z#4`5ES|U_)(m1K89w((N8l`$Kr9JbLV~7FrCMQZAOi8WkfS4%YLI=Ey0$z1MK@?!< z07Ddz*8v$(z?%+8hyvm|U|SThr2|Gq0V8Jr@~xQtwfS8%Ee4pdx=+tV>`$%d!4O}b z?Q?|fM$V#Vz=G4zjC!&^bRPQ6+*ECUMU$Ic(Mhr@`v*GQ=Au3q(^;Ry!Ahc6gx8Af zpBbn$-3{~N+CELBngAJb*{BqQ)n?Rw9v$tIguKMyZtiXE@96THv;#J`Y=Sn4FyG3V zsr?BpQu{)q3h(8L(jd8#_}Tquzk^?X?^!J+?3G%rR`V*J8O+skdz)gizQfj4re9MX V5TxYLCoup3002ovPDHLkV1gKO;B_oX7Ats;dv=3DJdy>kYyMB zj8I{QI`d3W<}$m<1xBr44+A`UP2)hUF(NTRCr z(h*H2!%3zHW|ltuhN!$ahq;ib?;Izie>TIY@s`a?QCoPY7*(WQN2il<)cM8!e^Cd; ziK+9t`Gq$>oj2(5heI3|-+GL(M(x=dMxS|V5u%0^o+VCTlVjo6HDy)kTgbJEyknbl z!C86Iy3j;G_7*P*7j(&m`ke?}kPD4C5qcsQsyGq)AQzf(A~Y=*T5uw?AQzf;BJ@Kp zRCOX$kqecb2$keQSDXk9%7qR%5!xpgS}p1t+sx4x^m@H*UFcSD`Cs33mvsQ%8sCTX{j3%!0SgXIMz^8;u`?b2` zh8_G)OsB^7C-YgZKbxDZFY&g=>fXW!^k=hj9pfPQY&{O>D-|;sWn56 zo7y@zV*k-Y>HxjoZ7^0ERLtJ$bI9Jrbrz*gQxBD?bIRt@swZSnUZcnM9<7_7@)49$ zH(^|9t7I$om2IxJjT?FYpUy`%xmn$Hd{?2$QDJdyY_zQFa1Et-5?|lFO002ovPDHLkV1iePLMi|N literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f2b7126124abebbbcfdbe32f51614d08cfdab56e GIT binary patch literal 901 zcmV;01A6?4P)B7xc=J9IDb(y2sK z3@;T?ARz^5Vu)oVZkAT=vd?crh@`eV^JeC~_j@p(z3l0?-w!))X5P%tvJ3`;!C){L z41ypXC1^z_J|K)JY)rFn-DpNB(jC>=fFo!@4~AIRdMb{ii~U$U zY&=B;R&(pD!D;j*s1su%LzXe@TBwtU&(d`sAXPqo zCsg=}!oPJ6;FnUJ4k-mTc-o;#1O+H$lcXy5B?b~3`#P9mA01qBKJ(b1L=3x~&HDqO zM!$n~fh}7UIVV2*jFJ=>5!_&~Jr7mN#00v?3Op9uFxzAWVpzu)C;?>-@&#H+3pDcu zI!O!gp91!ZNSQ&tK$x_^Bwrv(S|G|7h>#YD@dYMG3;YQBLp;nE=q4@D%NMv!TA+#$v|O;%us=v#4bK&Q|Jfnt&Z#o_`Xyd)R@ z_3|V8L<&XZ1PYuUE@PEDcgLFe^p|u>jq4{Gg6HoJ){@4#jp0O4fc$N)!9acpPjsA zihHC84*T7VT%^#_H-r5Y`lE6>>4|IQ}QC`+a4FEQhz7@3DniV}2(3 zh2y`%MvERuL!VImp7{Okek-iPLvH+bthDHY6}Xo${vD-mbdNTA*W<>&>e+r%QKITU zTMQd#t>A#tC2c#iD6xVC^8Yyuo5DUTcwp!J`aF(YE10nLc?g5pW(5~yXgi=a7z_r3 b!9b8dS + + + + \ 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 48848ff9db..2dc2882e2e 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 d591678ac0..ade6a11901 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 }