mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Show mangas from catalogue
This commit is contained in:
parent
381bedf68d
commit
2aaaad7a24
11 changed files with 137 additions and 16 deletions
|
@ -92,6 +92,16 @@ public class DatabaseHelper implements MangaManager, ChapterManager {
|
|||
return mMangaManager.getMangasWithUnread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Manga>> getManga(String url) {
|
||||
return mMangaManager.getManga(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Manga>> getManga(int id) {
|
||||
return mMangaManager.getManga(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<PutResult> insertManga(Manga manga) {
|
||||
return mMangaManager.insertManga(manga);
|
||||
|
|
|
@ -16,6 +16,10 @@ public interface MangaManager {
|
|||
|
||||
Observable<List<Manga>> getMangasWithUnread();
|
||||
|
||||
Observable<List<Manga>> getManga(String url);
|
||||
|
||||
Observable<List<Manga>> getManga(int id);
|
||||
|
||||
Observable<PutResult> insertManga(Manga manga);
|
||||
|
||||
Observable<PutResults<Manga>> insertMangas(List<Manga> mangas);
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.pushtorefresh.storio.sqlite.operations.put.PutResults;
|
|||
import com.pushtorefresh.storio.sqlite.queries.Query;
|
||||
import com.pushtorefresh.storio.sqlite.queries.RawQuery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
|
@ -55,6 +54,22 @@ public class MangaManagerImpl extends BaseManager implements MangaManager {
|
|||
.createObservable();
|
||||
}
|
||||
|
||||
public Observable<List<Manga>> getManga(String url) {
|
||||
return db.get()
|
||||
.listOfObjects(Manga.class)
|
||||
.withQuery(Query.builder()
|
||||
.table(MangasTable.TABLE)
|
||||
.where(MangasTable.COLUMN_URL + "=?")
|
||||
.whereArgs(url)
|
||||
.build())
|
||||
.prepare()
|
||||
.createObservable();
|
||||
}
|
||||
|
||||
public Observable<List<Manga>> getManga(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Observable<PutResult> insertManga(Manga manga) {
|
||||
return db.put()
|
||||
.object(manga)
|
||||
|
|
|
@ -71,15 +71,15 @@ public class MangasTable {
|
|||
+ COLUMN_ID + " INTEGER NOT NULL PRIMARY KEY, "
|
||||
+ COLUMN_SOURCE + " INTEGER NOT NULL, "
|
||||
+ COLUMN_URL + " TEXT NOT NULL, "
|
||||
+ COLUMN_ARTIST + " TEXT NOT NULL, "
|
||||
+ COLUMN_AUTHOR + " TEXT NOT NULL, "
|
||||
+ COLUMN_DESCRIPTION + " TEXT NOT NULL, "
|
||||
+ COLUMN_GENRE + " TEXT NOT NULL, "
|
||||
+ COLUMN_ARTIST + " TEXT, "
|
||||
+ COLUMN_AUTHOR + " TEXT, "
|
||||
+ COLUMN_DESCRIPTION + " TEXT, "
|
||||
+ COLUMN_GENRE + " TEXT, "
|
||||
+ COLUMN_TITLE + " TEXT NOT NULL, "
|
||||
+ COLUMN_STATUS + " TEXT NOT NULL, "
|
||||
+ COLUMN_THUMBNAIL_URL + " TEXT NOT NULL, "
|
||||
+ COLUMN_RANK + " INTEGER NOT NULL, "
|
||||
+ COLUMN_LAST_UPDATE + " LONG NOT NULL, "
|
||||
+ COLUMN_STATUS + " TEXT, "
|
||||
+ COLUMN_THUMBNAIL_URL + " TEXT, "
|
||||
+ COLUMN_RANK + " INTEGER, "
|
||||
+ COLUMN_LAST_UPDATE + " LONG, "
|
||||
+ COLUMN_INITIALIZED + " BOOLEAN NOT NULL, "
|
||||
+ COLUMN_VIEWER + " INTEGER NOT NULL, "
|
||||
+ COLUMN_CHAPTER_ORDER + " INTEGER NOT NULL"
|
||||
|
|
|
@ -5,14 +5,26 @@ import android.content.Intent;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import eu.kanade.mangafeed.App;
|
||||
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
||||
import eu.kanade.mangafeed.data.helpers.SourceManager;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.sources.Source;
|
||||
import eu.kanade.mangafeed.ui.adapter.CatalogueListHolder;
|
||||
import eu.kanade.mangafeed.view.CatalogueListView;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||
|
||||
public class CatalogueListPresenter {
|
||||
|
||||
CatalogueListView view;
|
||||
EasyAdapter<Manga> adapter;
|
||||
Source selectedSource;
|
||||
|
||||
@Inject SourceManager sourceManager;
|
||||
@Inject DatabaseHelper db;
|
||||
|
||||
|
||||
public CatalogueListPresenter(CatalogueListView view) {
|
||||
this.view = view;
|
||||
|
@ -20,8 +32,30 @@ public class CatalogueListPresenter {
|
|||
}
|
||||
|
||||
public void initializeSource() {
|
||||
Intent intent = view.getIntent();
|
||||
int sourceId = intent.getIntExtra(Intent.EXTRA_UID, -1);
|
||||
view.setSource(sourceManager.get(sourceId));
|
||||
int sourceId = view.getIntent().getIntExtra(Intent.EXTRA_UID, -1);
|
||||
selectedSource = sourceManager.get(sourceId);
|
||||
view.setSource(selectedSource);
|
||||
|
||||
adapter = new EasyAdapter<>(view.getActivity(), CatalogueListHolder.class);
|
||||
view.setAdapter(adapter);
|
||||
|
||||
getMangasFromSource();
|
||||
}
|
||||
|
||||
private void getMangasFromSource() {
|
||||
selectedSource.pullPopularMangasFromNetwork(1)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.flatMap(Observable::from)
|
||||
.flatMap(networkManga -> db.getManga(networkManga.url)
|
||||
.flatMap(result -> {
|
||||
if (result.size() == 0) {
|
||||
return db.insertManga(networkManga)
|
||||
.flatMap(i -> Observable.just(networkManga));
|
||||
}
|
||||
return Observable.just(networkManga);
|
||||
}))
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(adapter::addItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ import eu.kanade.mangafeed.view.LibraryView;
|
|||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static rx.android.schedulers.AndroidSchedulers.mainThread;
|
||||
|
||||
public class LibraryPresenter extends BasePresenter {
|
||||
|
||||
private LibraryView view;
|
||||
|
@ -54,7 +52,6 @@ public class LibraryPresenter extends BasePresenter {
|
|||
view.setMangaClickListener();
|
||||
|
||||
subscriptions.add(db.getMangasWithUnread()
|
||||
.observeOn(mainThread())
|
||||
.subscribe(adapter::setNewItems)
|
||||
);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.activity;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.widget.ListView;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -9,12 +10,16 @@ import eu.kanade.mangafeed.R;
|
|||
import eu.kanade.mangafeed.presenter.CatalogueListPresenter;
|
||||
import eu.kanade.mangafeed.sources.Source;
|
||||
import eu.kanade.mangafeed.view.CatalogueListView;
|
||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||
|
||||
public class CatalogueListActivity extends BaseActivity implements CatalogueListView {
|
||||
|
||||
@Bind(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@Bind(R.id.catalogue_manga_list)
|
||||
ListView manga_list;
|
||||
|
||||
private CatalogueListPresenter presenter;
|
||||
private Source source;
|
||||
|
||||
|
@ -35,4 +40,8 @@ public class CatalogueListActivity extends BaseActivity implements CatalogueList
|
|||
setToolbarTitle(source.getName());
|
||||
}
|
||||
|
||||
public void setAdapter(EasyAdapter adapter) {
|
||||
manga_list.setAdapter(adapter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package eu.kanade.mangafeed.ui.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import uk.co.ribot.easyadapter.ItemViewHolder;
|
||||
import uk.co.ribot.easyadapter.PositionInfo;
|
||||
import uk.co.ribot.easyadapter.annotations.LayoutId;
|
||||
import uk.co.ribot.easyadapter.annotations.ViewId;
|
||||
|
||||
@LayoutId(R.layout.item_catalogue)
|
||||
public class CatalogueListHolder extends ItemViewHolder<Manga> {
|
||||
|
||||
@ViewId(R.id.catalogue_title)
|
||||
TextView title;
|
||||
|
||||
public CatalogueListHolder(View view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetValues(Manga manga, PositionInfo positionInfo) {
|
||||
title.setText(manga.title);
|
||||
}
|
||||
}
|
|
@ -3,8 +3,10 @@ package eu.kanade.mangafeed.view;
|
|||
import android.content.Intent;
|
||||
|
||||
import eu.kanade.mangafeed.sources.Source;
|
||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||
|
||||
public interface CatalogueListView extends BaseView {
|
||||
Intent getIntent();
|
||||
void setSource(Source source);
|
||||
void setAdapter(EasyAdapter adapter);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:fitsSystemWindows="true"
|
||||
tools:context="eu.kanade.mangafeed.ui.activity.CatalogueListActivity">
|
||||
|
||||
|
@ -9,4 +11,11 @@
|
|||
android:id="@+id/toolbar"
|
||||
layout="@layout/toolbar"/>
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/catalogue_manga_list"
|
||||
tools:listitem="@layout/item_catalogue"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
14
app/src/main/res/layout/item_catalogue.xml
Normal file
14
app/src/main/res/layout/item_catalogue.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
tools:text="New Text"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/catalogue_title" />
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue