mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Create catalogue fragment
This commit is contained in:
parent
a6a05fbb7f
commit
13124ee02f
12 changed files with 207 additions and 13 deletions
|
@ -6,6 +6,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import dagger.Component;
|
||||
import eu.kanade.mangafeed.data.DataModule;
|
||||
import eu.kanade.mangafeed.presenter.CataloguePresenter;
|
||||
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
||||
import eu.kanade.mangafeed.presenter.MangaDetailPresenter;
|
||||
import eu.kanade.mangafeed.ui.activity.MainActivity;
|
||||
|
@ -23,6 +24,7 @@ public interface AppComponent {
|
|||
|
||||
void inject(LibraryPresenter libraryPresenter);
|
||||
void inject(MangaDetailPresenter mangaDetailPresenter);
|
||||
void inject(CataloguePresenter cataloguePresenter);
|
||||
|
||||
Application application();
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package eu.kanade.mangafeed.data.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import eu.kanade.mangafeed.data.caches.CacheManager;
|
||||
import eu.kanade.mangafeed.sources.Batoto;
|
||||
|
@ -18,6 +20,8 @@ public class SourceManager {
|
|||
mSourcesMap = new HashMap<>();
|
||||
mNetworkHelper = networkHelper;
|
||||
mCacheManager = cacheManager;
|
||||
|
||||
initializeSources();
|
||||
}
|
||||
|
||||
public Source get(int sourceKey) {
|
||||
|
@ -35,4 +39,12 @@ public class SourceManager {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initializeSources() {
|
||||
mSourcesMap.put(BATOTO, createSource(BATOTO));
|
||||
}
|
||||
|
||||
public List<Source> getSources() {
|
||||
return new ArrayList<Source>(mSourcesMap.values());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -32,6 +32,11 @@ public class Batoto extends Source {
|
|||
super(networkService, cacheManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Headers.Builder headersBuilder() {
|
||||
Headers.Builder builder = super.headersBuilder();
|
||||
|
@ -85,7 +90,7 @@ public class Batoto extends Source {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int getSource() {
|
||||
public int getSource() {
|
||||
return SourceManager.BATOTO;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,12 +94,15 @@ public abstract class Source {
|
|||
return defaultMangaUrl;
|
||||
}
|
||||
|
||||
abstract protected int getSource();
|
||||
abstract protected String getUrlFromPageNumber(int page);
|
||||
abstract protected List<Manga> parsePopularMangasFromHtml(String unparsedHtml);
|
||||
abstract protected Manga parseHtmlToManga(String mangaUrl, String unparsedHtml);
|
||||
abstract protected List<Chapter> parseHtmlToChapters(String unparsedHtml);
|
||||
abstract protected List<String> parseHtmlToPageUrls(String unparsedHtml);
|
||||
abstract protected String parseHtmlToImageUrl(String unparsedHtml);
|
||||
public abstract String getName();
|
||||
public abstract int getSource();
|
||||
|
||||
protected abstract String getUrlFromPageNumber(int page);
|
||||
protected abstract List<Manga> parsePopularMangasFromHtml(String unparsedHtml);
|
||||
protected abstract Manga parseHtmlToManga(String mangaUrl, String unparsedHtml);
|
||||
protected abstract List<Chapter> parseHtmlToChapters(String unparsedHtml);
|
||||
protected abstract List<String> parseHtmlToPageUrls(String unparsedHtml);
|
||||
protected abstract String parseHtmlToImageUrl(String unparsedHtml);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
|||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.ui.fragment.CatalogueFragment;
|
||||
import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
|
||||
|
@ -64,8 +65,11 @@ public class MainActivity extends BaseActivity {
|
|||
case R.id.nav_drawer_library:
|
||||
setFragment(LibraryFragment.newInstance());
|
||||
break;
|
||||
case R.id.nav_drawer_catalogues:
|
||||
case R.id.nav_drawer_recent_updates:
|
||||
break;
|
||||
case R.id.nav_drawer_catalogues:
|
||||
setFragment(CatalogueFragment.newInstance());
|
||||
break;
|
||||
case R.id.nav_drawer_settings:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -23,8 +23,8 @@ import uk.co.ribot.easyadapter.EasyAdapter;
|
|||
public class LibraryFragment extends BaseFragment implements LibraryView {
|
||||
|
||||
@Bind(R.id.gridView) GridView grid;
|
||||
LibraryPresenter presenter;
|
||||
MainActivity activity;
|
||||
private LibraryPresenter presenter;
|
||||
private MainActivity activity;
|
||||
|
||||
public static LibraryFragment newInstance() {
|
||||
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) {
|
||||
mode.setTitle(getResources().getString(R.string.library_selection_title)
|
||||
+ ": " + grid.getCheckedItemCount());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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();
|
||||
}
|
13
app/src/main/res/layout/fragment_catalogue.xml
Normal file
13
app/src/main/res/layout/fragment_catalogue.xml
Normal 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>
|
11
app/src/main/res/layout/item_source.xml
Normal file
11
app/src/main/res/layout/item_source.xml
Normal 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>
|
Loading…
Reference in a new issue