Create catalogue fragment

This commit is contained in:
inorichi 2015-10-10 14:28:57 +02:00
parent a6a05fbb7f
commit 13124ee02f
12 changed files with 207 additions and 13 deletions

View File

@ -6,6 +6,7 @@ import javax.inject.Singleton;
import dagger.Component; import dagger.Component;
import eu.kanade.mangafeed.data.DataModule; import eu.kanade.mangafeed.data.DataModule;
import eu.kanade.mangafeed.presenter.CataloguePresenter;
import eu.kanade.mangafeed.presenter.LibraryPresenter; import eu.kanade.mangafeed.presenter.LibraryPresenter;
import eu.kanade.mangafeed.presenter.MangaDetailPresenter; import eu.kanade.mangafeed.presenter.MangaDetailPresenter;
import eu.kanade.mangafeed.ui.activity.MainActivity; import eu.kanade.mangafeed.ui.activity.MainActivity;
@ -23,6 +24,7 @@ public interface AppComponent {
void inject(LibraryPresenter libraryPresenter); void inject(LibraryPresenter libraryPresenter);
void inject(MangaDetailPresenter mangaDetailPresenter); void inject(MangaDetailPresenter mangaDetailPresenter);
void inject(CataloguePresenter cataloguePresenter);
Application application(); Application application();
} }

View File

@ -1,6 +1,8 @@
package eu.kanade.mangafeed.data.helpers; package eu.kanade.mangafeed.data.helpers;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import eu.kanade.mangafeed.data.caches.CacheManager; import eu.kanade.mangafeed.data.caches.CacheManager;
import eu.kanade.mangafeed.sources.Batoto; import eu.kanade.mangafeed.sources.Batoto;
@ -18,6 +20,8 @@ public class SourceManager {
mSourcesMap = new HashMap<>(); mSourcesMap = new HashMap<>();
mNetworkHelper = networkHelper; mNetworkHelper = networkHelper;
mCacheManager = cacheManager; mCacheManager = cacheManager;
initializeSources();
} }
public Source get(int sourceKey) { public Source get(int sourceKey) {
@ -35,4 +39,12 @@ public class SourceManager {
return null; return null;
} }
private void initializeSources() {
mSourcesMap.put(BATOTO, createSource(BATOTO));
}
public List<Source> getSources() {
return new ArrayList<Source>(mSourcesMap.values());
}
} }

View File

@ -0,0 +1,39 @@
package eu.kanade.mangafeed.presenter;
import javax.inject.Inject;
import eu.kanade.mangafeed.App;
import eu.kanade.mangafeed.data.helpers.SourceManager;
import eu.kanade.mangafeed.sources.Source;
import eu.kanade.mangafeed.ui.adapter.SourceHolder;
import eu.kanade.mangafeed.view.CatalogueView;
import uk.co.ribot.easyadapter.EasyAdapter;
public class CataloguePresenter {
private CatalogueView view;
@Inject SourceManager sourceManager;
EasyAdapter<Source> adapter;
public CataloguePresenter(CatalogueView view) {
this.view = view;
App.getComponent(view.getActivity()).inject(this);
}
public void initializeSources() {
adapter = new EasyAdapter<Source>(
view.getActivity(),
SourceHolder.class,
sourceManager.getSources());
view.setAdapter(adapter);
view.setSourceClickListener();
}
public void onSourceClick(int position) {
}
}

View File

@ -32,6 +32,11 @@ public class Batoto extends Source {
super(networkService, cacheManager); super(networkService, cacheManager);
} }
@Override
public String getName() {
return NAME;
}
@Override @Override
protected Headers.Builder headersBuilder() { protected Headers.Builder headersBuilder() {
Headers.Builder builder = super.headersBuilder(); Headers.Builder builder = super.headersBuilder();
@ -85,7 +90,7 @@ public class Batoto extends Source {
} }
@Override @Override
protected int getSource() { public int getSource() {
return SourceManager.BATOTO; return SourceManager.BATOTO;
} }

View File

@ -94,12 +94,15 @@ public abstract class Source {
return defaultMangaUrl; return defaultMangaUrl;
} }
abstract protected int getSource(); public abstract String getName();
abstract protected String getUrlFromPageNumber(int page); public abstract int getSource();
abstract protected List<Manga> parsePopularMangasFromHtml(String unparsedHtml);
abstract protected Manga parseHtmlToManga(String mangaUrl, String unparsedHtml); protected abstract String getUrlFromPageNumber(int page);
abstract protected List<Chapter> parseHtmlToChapters(String unparsedHtml); protected abstract List<Manga> parsePopularMangasFromHtml(String unparsedHtml);
abstract protected List<String> parseHtmlToPageUrls(String unparsedHtml); protected abstract Manga parseHtmlToManga(String mangaUrl, String unparsedHtml);
abstract protected String parseHtmlToImageUrl(String unparsedHtml); protected abstract List<Chapter> parseHtmlToChapters(String unparsedHtml);
protected abstract List<String> parseHtmlToPageUrls(String unparsedHtml);
protected abstract String parseHtmlToImageUrl(String unparsedHtml);
} }

View File

@ -13,6 +13,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.ui.fragment.CatalogueFragment;
import eu.kanade.mangafeed.ui.fragment.LibraryFragment; import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
import rx.subscriptions.CompositeSubscription; import rx.subscriptions.CompositeSubscription;
@ -64,8 +65,11 @@ public class MainActivity extends BaseActivity {
case R.id.nav_drawer_library: case R.id.nav_drawer_library:
setFragment(LibraryFragment.newInstance()); setFragment(LibraryFragment.newInstance());
break; break;
case R.id.nav_drawer_catalogues:
case R.id.nav_drawer_recent_updates: case R.id.nav_drawer_recent_updates:
break;
case R.id.nav_drawer_catalogues:
setFragment(CatalogueFragment.newInstance());
break;
case R.id.nav_drawer_settings: case R.id.nav_drawer_settings:
break; break;
} }

View File

@ -0,0 +1,28 @@
package eu.kanade.mangafeed.ui.adapter;
import android.view.View;
import android.widget.TextView;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.sources.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<Source> {
@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());
}
}

View File

@ -0,0 +1,68 @@
package eu.kanade.mangafeed.ui.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.presenter.CataloguePresenter;
import eu.kanade.mangafeed.ui.activity.MainActivity;
import eu.kanade.mangafeed.view.CatalogueView;
import uk.co.ribot.easyadapter.EasyAdapter;
public class CatalogueFragment extends BaseFragment implements CatalogueView {
private CataloguePresenter presenter;
private MainActivity activity;
@Bind(R.id.catalogue_list)
ListView source_list;
public static CatalogueFragment newInstance() {
CatalogueFragment fragment = new CatalogueFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
presenter = new CataloguePresenter(this);
activity = (MainActivity)getActivity();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
activity.setToolbarTitle(R.string.catalogues_title);
ButterKnife.bind(this, view);
presenter.initializeSources();
return view;
}
// CatalogueView
@Override
public void setAdapter(EasyAdapter adapter) {
source_list.setAdapter(adapter);
}
@Override
public void setSourceClickListener() {
source_list.setOnItemClickListener(
(parent, view, position, id) ->
presenter.onSourceClick(position)
);
}
}

View File

@ -23,8 +23,8 @@ import uk.co.ribot.easyadapter.EasyAdapter;
public class LibraryFragment extends BaseFragment implements LibraryView { public class LibraryFragment extends BaseFragment implements LibraryView {
@Bind(R.id.gridView) GridView grid; @Bind(R.id.gridView) GridView grid;
LibraryPresenter presenter; private LibraryPresenter presenter;
MainActivity activity; private MainActivity activity;
public static LibraryFragment newInstance() { public static LibraryFragment newInstance() {
LibraryFragment fragment = new LibraryFragment(); LibraryFragment fragment = new LibraryFragment();
@ -99,8 +99,6 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
mode.setTitle(getResources().getString(R.string.library_selection_title) mode.setTitle(getResources().getString(R.string.library_selection_title)
+ ": " + grid.getCheckedItemCount()); + ": " + grid.getCheckedItemCount());
} }
@Override @Override

View File

@ -0,0 +1,11 @@
package eu.kanade.mangafeed.view;
import uk.co.ribot.easyadapter.EasyAdapter;
/**
* Created by len on 10/10/2015.
*/
public interface CatalogueView extends BaseView {
void setAdapter(EasyAdapter adapter);
void setSourceClickListener();
}

View File

@ -0,0 +1,13 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="eu.kanade.mangafeed.ui.fragment.CatalogueFragment">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/catalogue_list" />
</LinearLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/source_name" />
</LinearLayout>