From 4630a5ed1aae0887facb93c06eda56131053f035 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 14 Dec 2015 16:51:12 +0100 Subject: [PATCH] Catalogue now has a dropdown menu to select or change the source --- .../data/preference/PreferencesHelper.java | 8 +- .../mangafeed/data/source/SourceManager.java | 20 +-- .../data/source/base/BaseSource.java | 6 +- .../mangafeed/data/source/base/Source.java | 4 +- .../data/source/online/english/Batoto.java | 4 +- .../data/source/online/english/Kissmanga.java | 4 +- .../data/source/online/english/Mangafox.java | 6 +- .../data/source/online/english/Mangahere.java | 6 +- .../injection/component/AppComponent.java | 6 +- .../ui/catalogue/CatalogueFragment.java | 66 ++++++++-- .../ui/catalogue/CataloguePresenter.java | 21 ++- .../ui/catalogue/CatalogueSpinnerAdapter.java | 120 ++++++++++++++++++ .../ui/catalogue/SourceFragment.java | 69 ---------- .../mangafeed/ui/catalogue/SourceHolder.java | 28 ---- .../ui/catalogue/SourcePresenter.java | 30 ----- .../mangafeed/ui/main/MainActivity.java | 8 +- .../mangafeed/ui/reader/ReaderPresenter.java | 2 +- app/src/main/res/layout/fragment_source.xml | 13 -- app/src/main/res/layout/item_source.xml | 16 --- app/src/main/res/values/strings.xml | 1 + 20 files changed, 233 insertions(+), 205 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueSpinnerAdapter.java delete mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceFragment.java delete mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceHolder.java delete mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourcePresenter.java delete mode 100644 app/src/main/res/layout/fragment_source.xml delete mode 100644 app/src/main/res/layout/item_source.xml diff --git a/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java index 8f37e0c517..a1f560f151 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java @@ -88,17 +88,17 @@ public class PreferencesHelper { } public String getSourceUsername(Source source) { - return prefs.getString(SOURCE_ACCOUNT_USERNAME + source.getSourceId(), ""); + return prefs.getString(SOURCE_ACCOUNT_USERNAME + source.getId(), ""); } public String getSourcePassword(Source source) { - return prefs.getString(SOURCE_ACCOUNT_PASSWORD + source.getSourceId(), ""); + return prefs.getString(SOURCE_ACCOUNT_PASSWORD + source.getId(), ""); } public void setSourceCredentials(Source source, String username, String password) { prefs.edit() - .putString(SOURCE_ACCOUNT_USERNAME + source.getSourceId(), username) - .putString(SOURCE_ACCOUNT_PASSWORD + source.getSourceId(), password) + .putString(SOURCE_ACCOUNT_USERNAME + source.getId(), username) + .putString(SOURCE_ACCOUNT_PASSWORD + source.getId(), password) .apply(); } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/SourceManager.java b/app/src/main/java/eu/kanade/mangafeed/data/source/SourceManager.java index 36cde5e297..58cba352f1 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/SourceManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/SourceManager.java @@ -19,21 +19,21 @@ public class SourceManager { public static final int MANGAFOX = 3; public static final int KISSMANGA = 4; - private HashMap mSourcesMap; + private HashMap sourcesMap; private Context context; public SourceManager(Context context) { - mSourcesMap = new HashMap<>(); + sourcesMap = new HashMap<>(); this.context = context; initializeSources(); } public Source get(int sourceKey) { - if (!mSourcesMap.containsKey(sourceKey)) { - mSourcesMap.put(sourceKey, createSource(sourceKey)); + if (!sourcesMap.containsKey(sourceKey)) { + sourcesMap.put(sourceKey, createSource(sourceKey)); } - return mSourcesMap.get(sourceKey); + return sourcesMap.get(sourceKey); } private Source createSource(int sourceKey) { @@ -52,14 +52,14 @@ public class SourceManager { } private void initializeSources() { - mSourcesMap.put(BATOTO, createSource(BATOTO)); - mSourcesMap.put(MANGAHERE, createSource(MANGAHERE)); - mSourcesMap.put(MANGAFOX, createSource(MANGAFOX)); - mSourcesMap.put(KISSMANGA, createSource(KISSMANGA)); + sourcesMap.put(BATOTO, createSource(BATOTO)); + sourcesMap.put(MANGAHERE, createSource(MANGAHERE)); + sourcesMap.put(MANGAFOX, createSource(MANGAFOX)); + sourcesMap.put(KISSMANGA, createSource(KISSMANGA)); } public List getSources() { - return new ArrayList<>(mSourcesMap.values()); + return new ArrayList<>(sourcesMap.values()); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java index 4d65b037f1..ddd55b4a6b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java @@ -18,7 +18,7 @@ public abstract class BaseSource { public abstract String getName(); // Id of the source (must be declared and obtained from SourceManager to avoid conflicts) - public abstract int getSourceId(); + public abstract int getId(); // Base url of the source, like: http://example.com public abstract String getBaseUrl(); @@ -95,4 +95,8 @@ public abstract class BaseSource { return builder; } + @Override + public String toString() { + return getName(); + } } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java index 6466daa885..31792685bd 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java @@ -34,6 +34,8 @@ public abstract class Source extends BaseSource { protected Headers requestHeaders; protected LazyHeaders glideHeaders; + public Source() {} + public Source(Context context) { App.get(context).getComponent().inject(this); requestHeaders = headersBuilder().build(); @@ -188,7 +190,7 @@ public abstract class Source extends BaseSource { } protected String getChapterCacheKey(String chapterUrl) { - return getSourceId() + chapterUrl; + return getId() + chapterUrl; } protected LazyHeaders.Builder glideHeadersBuilder() { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java index 02ee94dd03..02a9e619d5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java @@ -70,7 +70,7 @@ public class Batoto extends Source { } @Override - public int getSourceId() { + public int getId() { return SourceManager.BATOTO; } @@ -218,7 +218,7 @@ public class Batoto extends Source { Element urlElement = htmlBlock.select("a[href^=http://bato.to]").first(); Element updateElement = htmlBlock.select("td").get(5); - mangaFromHtmlBlock.source = getSourceId(); + mangaFromHtmlBlock.source = getId(); if (urlElement != null) { mangaFromHtmlBlock.setUrl(urlElement.attr("href")); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java index a18ce77905..c69ca68296 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java @@ -55,7 +55,7 @@ public class Kissmanga extends Source { } @Override - public int getSourceId() { + public int getId() { return SourceManager.KISSMANGA; } @@ -94,7 +94,7 @@ public class Kissmanga extends Source { private Manga constructPopularMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); - mangaFromHtmlBlock.source = getSourceId(); + mangaFromHtmlBlock.source = getId(); Element urlElement = htmlBlock.select("td a:eq(0)").first(); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java index 59b8ec6a75..8e6e39dfba 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangafox.java @@ -40,7 +40,7 @@ public class Mangafox extends Source { } @Override - public int getSourceId() { + public int getId() { return SourceManager.MANGAFOX; } @@ -79,7 +79,7 @@ public class Mangafox extends Source { private Manga constructPopularMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); - mangaFromHtmlBlock.source = getSourceId(); + mangaFromHtmlBlock.source = getId(); Element urlElement = htmlBlock.select("a.title").first(); @@ -115,7 +115,7 @@ public class Mangafox extends Source { private Manga constructSearchMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); - mangaFromHtmlBlock.source = getSourceId(); + mangaFromHtmlBlock.source = getId(); Element urlElement = htmlBlock.select("a.series_preview").first(); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java index 788e8f3b15..f58455be90 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java @@ -40,7 +40,7 @@ public class Mangahere extends Source { } @Override - public int getSourceId() { + public int getId() { return SourceManager.MANGAHERE; } @@ -117,7 +117,7 @@ public class Mangahere extends Source { private Manga constructPopularMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); - mangaFromHtmlBlock.source = getSourceId(); + mangaFromHtmlBlock.source = getId(); Element urlElement = htmlBlock.select("div.title > a").first(); @@ -153,7 +153,7 @@ public class Mangahere extends Source { private Manga constructSearchMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); - mangaFromHtmlBlock.source = getSourceId(); + mangaFromHtmlBlock.source = getId(); Element urlElement = htmlBlock.select("a.manga_info").first(); diff --git a/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java b/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java index 1bef652e57..5e5b39b44e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java +++ b/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java @@ -5,15 +5,14 @@ import android.app.Application; import javax.inject.Singleton; import dagger.Component; -import eu.kanade.mangafeed.data.mangasync.services.MyAnimeList; -import eu.kanade.mangafeed.data.sync.UpdateMangaSyncService; import eu.kanade.mangafeed.data.download.DownloadService; +import eu.kanade.mangafeed.data.mangasync.services.MyAnimeList; import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.sync.LibraryUpdateService; +import eu.kanade.mangafeed.data.sync.UpdateMangaSyncService; import eu.kanade.mangafeed.injection.module.AppModule; import eu.kanade.mangafeed.injection.module.DataModule; import eu.kanade.mangafeed.ui.catalogue.CataloguePresenter; -import eu.kanade.mangafeed.ui.catalogue.SourcePresenter; import eu.kanade.mangafeed.ui.download.DownloadPresenter; import eu.kanade.mangafeed.ui.library.LibraryPresenter; import eu.kanade.mangafeed.ui.manga.MangaActivity; @@ -37,7 +36,6 @@ public interface AppComponent { void inject(LibraryPresenter libraryPresenter); void inject(MangaPresenter mangaPresenter); - void inject(SourcePresenter sourcePresenter); void inject(CataloguePresenter cataloguePresenter); void inject(MangaInfoPresenter mangaInfoPresenter); void inject(ChaptersPresenter chaptersPresenter); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java index dac2244569..5e423ac220 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java @@ -1,8 +1,10 @@ package eu.kanade.mangafeed.ui.catalogue; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.widget.SearchView; +import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; @@ -10,9 +12,11 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.GridView; import android.widget.ImageView; import android.widget.ProgressBar; +import android.widget.Spinner; import java.util.List; import java.util.concurrent.TimeUnit; @@ -22,9 +26,12 @@ import butterknife.ButterKnife; import butterknife.OnItemClick; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment; +import eu.kanade.mangafeed.ui.main.MainActivity; import eu.kanade.mangafeed.ui.manga.MangaActivity; import eu.kanade.mangafeed.util.PageBundle; +import eu.kanade.mangafeed.util.ToastUtil; import eu.kanade.mangafeed.widget.EndlessScrollListener; import icepick.Icepick; import icepick.State; @@ -40,23 +47,20 @@ public class CatalogueFragment extends BaseRxFragment { @Bind(R.id.progress) ProgressBar progress; @Bind(R.id.progress_grid) ProgressBar progressGrid; + private Toolbar toolbar; + private Spinner spinner; private CatalogueAdapter adapter; private EndlessScrollListener scrollListener; @State String query = ""; + @State int selectedIndex = -1; private final int SEARCH_TIMEOUT = 1000; private PublishSubject queryDebouncerSubject; private Subscription queryDebouncerSubscription; - public final static String SOURCE_ID = "source_id"; - - public static CatalogueFragment newInstance(int sourceId) { - CatalogueFragment fragment = new CatalogueFragment(); - Bundle args = new Bundle(); - args.putInt(SOURCE_ID, sourceId); - fragment.setArguments(args); - return fragment; + public static CatalogueFragment newInstance() { + return new CatalogueFragment(); } @Override @@ -78,13 +82,43 @@ public class CatalogueFragment extends BaseRxFragment { gridView.setAdapter(adapter); gridView.setOnScrollListener(scrollListener); - int sourceId = getArguments().getInt(SOURCE_ID, -1); + // Create toolbar spinner + Context themedContext = getBaseActivity().getSupportActionBar() != null ? + getBaseActivity().getSupportActionBar().getThemedContext() : getActivity(); + spinner = new Spinner(themedContext); + CatalogueSpinnerAdapter spinnerAdapter = new CatalogueSpinnerAdapter(themedContext, + android.R.layout.simple_spinner_item, getPresenter().getEnabledSources()); + spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(spinnerAdapter); + spinner.setSelection(savedState == null ? spinnerAdapter.getEmptyIndex() : selectedIndex); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + Source source = spinnerAdapter.getItem(position); + // We add an empty source with id -1 that acts as a placeholder to show a hint + // that asks to select a source + if (source.getId() != -1 && selectedIndex != position) { + // Set previous selection if it's not a valid source and notify the user + if (!getPresenter().isValidSource(source)) { + spinner.setSelection(selectedIndex != -1 ? selectedIndex : + spinnerAdapter.getEmptyIndex()); + ToastUtil.showShort(getActivity(), R.string.source_requires_login); + } else { + selectedIndex = position; + showProgressBar(); + getPresenter().startRequesting(source); + } + } + } - showProgressBar(); - if (savedState == null) - getPresenter().startRequesting(sourceId); + @Override + public void onNothingSelected(AdapterView parent) {} + }); + + setToolbarTitle(""); + toolbar = ((MainActivity)getActivity()).getToolbar(); + toolbar.addView(spinner); - setToolbarTitle(getPresenter().getSource().getName()); return view; } @@ -128,6 +162,12 @@ public class CatalogueFragment extends BaseRxFragment { super.onStop(); } + @Override + public void onDestroyView() { + toolbar.removeView(spinner); + super.onDestroyView(); + } + @Override public void onSaveInstanceState(Bundle outState) { Icepick.saveInstanceState(this, outState); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java index 54819bb2b2..03a88bdde3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java @@ -13,6 +13,7 @@ import javax.inject.Inject; import eu.kanade.mangafeed.data.cache.CoverCache; import eu.kanade.mangafeed.data.database.DatabaseHelper; import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.preference.PreferencesHelper; import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.source.model.MangasPage; @@ -30,6 +31,7 @@ public class CataloguePresenter extends BasePresenter { @Inject SourceManager sourceManager; @Inject DatabaseHelper db; @Inject CoverCache coverCache; + @Inject PreferencesHelper prefs; private Source source; @@ -85,8 +87,8 @@ public class CataloguePresenter extends BasePresenter { super.onDestroy(); } - public void startRequesting(int sourceId) { - source = sourceManager.get(sourceId); + public void startRequesting(Source source) { + this.source = source; restartRequest(null); } @@ -123,7 +125,7 @@ public class CataloguePresenter extends BasePresenter { } private Manga networkToLocalManga(Manga networkManga) { - List dbResult = db.getManga(networkManga.url, source.getSourceId()).executeAsBlocking(); + List dbResult = db.getManga(networkManga.url, source.getId()).executeAsBlocking(); Manga localManga = !dbResult.isEmpty() ? dbResult.get(0) : null; if (localManga == null) { PutResult result = db.insertManga(networkManga).executeAsBlocking(); @@ -152,4 +154,17 @@ public class CataloguePresenter extends BasePresenter { return lastMangasPage != null && lastMangasPage.nextPageUrl != null; } + public boolean isValidSource(Source source) { + if (!source.isLoginRequired() || source.isLogged()) + return true; + + return !(prefs.getSourceUsername(source).equals("") + || prefs.getSourcePassword(source).equals("")); + } + + public List getEnabledSources() { + // TODO filter by enabled source + return sourceManager.getSources(); + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueSpinnerAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueSpinnerAdapter.java new file mode 100644 index 0000000000..08e5001f96 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueSpinnerAdapter.java @@ -0,0 +1,120 @@ +package eu.kanade.mangafeed.ui.catalogue; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import org.jsoup.nodes.Document; + +import java.util.List; + +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.database.models.Chapter; +import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.source.base.Source; +import eu.kanade.mangafeed.data.source.model.MangasPage; + +public class CatalogueSpinnerAdapter extends ArrayAdapter { + + public CatalogueSpinnerAdapter(Context context, int resource, List sources) { + super(context, resource, sources); + sources.add(new SimpleSource()); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + View v = super.getView(position, convertView, parent); + if (position == getCount()) { + ((TextView)v.findViewById(android.R.id.text1)).setText(""); + ((TextView)v.findViewById(android.R.id.text1)).setHint(getItem(getCount()).getName()); + } + + return v; + } + + @Override + public int getCount() { + return super.getCount()-1; // you dont display last item. It is used as hint. + } + + public int getEmptyIndex() { + return getCount(); + } + + private class SimpleSource extends Source { + + @Override + public String getName() { + return getContext().getString(R.string.select_source); + } + + @Override + public int getId() { + return -1; + } + + @Override + public String getBaseUrl() { + return null; + } + + @Override + public boolean isLoginRequired() { + return false; + } + + @Override + protected String getInitialPopularMangasUrl() { + return null; + } + + @Override + protected String getInitialSearchUrl(String query) { + return null; + } + + @Override + protected List parsePopularMangasFromHtml(Document parsedHtml) { + return null; + } + + @Override + protected String parseNextPopularMangasUrl(Document parsedHtml, MangasPage page) { + return null; + } + + @Override + protected List parseSearchFromHtml(Document parsedHtml) { + return null; + } + + @Override + protected String parseNextSearchUrl(Document parsedHtml, MangasPage page, String query) { + return null; + } + + @Override + protected Manga parseHtmlToManga(String mangaUrl, String unparsedHtml) { + return null; + } + + @Override + protected List parseHtmlToChapters(String unparsedHtml) { + return null; + } + + @Override + protected List parseHtmlToPageUrls(String unparsedHtml) { + return null; + } + + @Override + protected String parseHtmlToImageUrl(String unparsedHtml) { + return null; + } + } + +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceFragment.java deleted file mode 100644 index 671a421c7e..0000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceFragment.java +++ /dev/null @@ -1,69 +0,0 @@ -package eu.kanade.mangafeed.ui.catalogue; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ListView; -import android.widget.Toast; - -import java.util.List; - -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnItemClick; -import eu.kanade.mangafeed.R; -import eu.kanade.mangafeed.data.source.base.Source; -import eu.kanade.mangafeed.ui.main.MainActivity; -import eu.kanade.mangafeed.ui.base.fragment.BaseRxFragment; -import nucleus.factory.RequiresPresenter; -import uk.co.ribot.easyadapter.EasyAdapter; - -@RequiresPresenter(SourcePresenter.class) -public class SourceFragment extends BaseRxFragment { - - @Bind(R.id.catalogue_list) ListView source_list; - - private EasyAdapter adapter; - - public static SourceFragment newInstance() { - return new SourceFragment(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_source, container, false); - ButterKnife.bind(this, view); - - setToolbarTitle(R.string.label_catalogues); - - createAdapter(); - - return view; - } - - @OnItemClick(R.id.catalogue_list) - public void onSourceClick(int position) { - Source source = adapter.getItem(position); - MainActivity activity = (MainActivity) getActivity(); - - if (getPresenter().isValidSource(source)) { - CatalogueFragment fragment = CatalogueFragment.newInstance(source.getSourceId()); - activity.setFragment(fragment); - } else { - Toast.makeText(getActivity(), R.string.source_requires_login, Toast.LENGTH_SHORT).show(); - } - } - - private void createAdapter() { - adapter = new EasyAdapter<>(getActivity(), SourceHolder.class); - source_list.setAdapter(adapter); - } - - public void setItems(List items) { - adapter.setItems(items); - } - -} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceHolder.java deleted file mode 100644 index 7db940156f..0000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourceHolder.java +++ /dev/null @@ -1,28 +0,0 @@ -package eu.kanade.mangafeed.ui.catalogue; - -import android.view.View; -import android.widget.TextView; - -import eu.kanade.mangafeed.R; -import eu.kanade.mangafeed.data.source.base.Source; -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_source) -public class SourceHolder extends ItemViewHolder { - - @ViewId(R.id.source_name) - TextView source_name; - - public SourceHolder(View view) { - super(view); - } - - @Override - public void onSetValues(Source item, PositionInfo positionInfo) { - source_name.setText(item.getName()); - } -} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourcePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourcePresenter.java deleted file mode 100644 index 8a32a5a6e2..0000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/SourcePresenter.java +++ /dev/null @@ -1,30 +0,0 @@ -package eu.kanade.mangafeed.ui.catalogue; - -import javax.inject.Inject; - -import eu.kanade.mangafeed.data.preference.PreferencesHelper; -import eu.kanade.mangafeed.data.source.SourceManager; -import eu.kanade.mangafeed.data.source.base.Source; -import eu.kanade.mangafeed.ui.base.presenter.BasePresenter; - - -public class SourcePresenter extends BasePresenter { - - @Inject SourceManager sourceManager; - @Inject PreferencesHelper prefs; - - @Override - protected void onTakeView(SourceFragment view) { - super.onTakeView(view); - - view.setItems(sourceManager.getSources()); - } - - public boolean isValidSource(Source source) { - if (!source.isLoginRequired() || source.isLogged()) - return true; - - return !(prefs.getSourceUsername(source).equals("") - || prefs.getSourcePassword(source).equals("")); - } -} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/main/MainActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/main/MainActivity.java index 1f52a2c1a6..195608ff90 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/main/MainActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/main/MainActivity.java @@ -14,7 +14,7 @@ import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.ui.base.activity.BaseActivity; -import eu.kanade.mangafeed.ui.catalogue.SourceFragment; +import eu.kanade.mangafeed.ui.catalogue.CatalogueFragment; import eu.kanade.mangafeed.ui.download.DownloadFragment; import eu.kanade.mangafeed.ui.library.LibraryFragment; import eu.kanade.mangafeed.ui.setting.SettingsActivity; @@ -80,7 +80,7 @@ public class MainActivity extends BaseActivity { case R.id.nav_drawer_recent_updates: break; case R.id.nav_drawer_catalogues: - setFragment(SourceFragment.newInstance()); + setFragment(CatalogueFragment.newInstance()); break; case R.id.nav_drawer_downloads: setFragment(DownloadFragment.newInstance()); @@ -111,4 +111,8 @@ public class MainActivity extends BaseActivity { fragmentStack.replace(fragment); } + public Toolbar getToolbar() { + return toolbar; + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java index 5c747b6b89..3ffc02c02a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java @@ -128,7 +128,7 @@ public class ReaderPresenter extends BasePresenter { EventBus.getDefault().removeStickyEvent(event); manga = event.getManga(); source = event.getSource(); - sourceId = source.getSourceId(); + sourceId = source.getId(); loadChapter(event.getChapter()); } diff --git a/app/src/main/res/layout/fragment_source.xml b/app/src/main/res/layout/fragment_source.xml deleted file mode 100644 index bf001c4089..0000000000 --- a/app/src/main/res/layout/fragment_source.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/item_source.xml b/app/src/main/res/layout/item_source.xml deleted file mode 100644 index d51e8cc5f3..0000000000 --- a/app/src/main/res/layout/item_source.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ 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 28a4ffc16f..285d226267 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,6 +90,7 @@ This source requires login + Select a source Info