219 lines
6.4 KiB
Plaintext
219 lines
6.4 KiB
Plaintext
package com.novelbook.android;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Typeface;
|
|
import android.support.design.widget.AppBarLayout;
|
|
import android.support.v4.view.ViewPager;
|
|
import android.support.v7.widget.Toolbar;
|
|
import android.util.DisplayMetrics;
|
|
import android.util.Log;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import com.flyco.tablayout.SlidingTabLayout;
|
|
import com.novelbook.android.adapter.MyPagerAdapter;
|
|
import com.novelbook.android.db.Chapter;
|
|
import com.novelbook.android.utils.Config;
|
|
import com.novelbook.android.utils.Constants;
|
|
import com.novelbook.android.utils.PageFactory;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.OnClick;
|
|
|
|
|
|
public class MarkActivity extends Activity_base {
|
|
|
|
|
|
private static final String TAG = MarkActivity.class.getSimpleName();
|
|
@BindView(R.id.toolbar)
|
|
Toolbar toolbar;
|
|
@BindView(R.id.appbar)
|
|
AppBarLayout appbar;
|
|
|
|
@BindView(R.id.pager)
|
|
ViewPager pager;
|
|
@BindView(R.id.tab_layout)
|
|
SlidingTabLayout tabLayout;
|
|
// @Bind(R.id.lv_catalogue)
|
|
// ListView lv_catalogue;
|
|
/*@BindView(R.id.btnSort)
|
|
ImageButton ibSort;
|
|
@BindView(R.id.btnRefresh)
|
|
ImageButton btnRefresh;*/
|
|
@BindView(R.id.tvSource)
|
|
TextView tvSource;
|
|
|
|
private PageFactory pageFactory;
|
|
/* private Config config;
|
|
private Typeface typeface;
|
|
private ArrayList<Chapter> catalogueList = new ArrayList<>();*/
|
|
private DisplayMetrics dm;
|
|
|
|
// private String EXTR_BOOK ="book";
|
|
@Override
|
|
public int getLayoutRes() {
|
|
return R.layout.zactivity_mark;
|
|
}
|
|
|
|
@Override
|
|
protected void initViews() {
|
|
/* if(getFactory().getNovle().isLocalBook()) {
|
|
// btnRefresh.setEnabled(false);
|
|
btnRefresh.setVisibility(View.GONE);
|
|
}*/
|
|
}
|
|
@Override
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
Log.e(TAG, "onPrepareOptionsMenu");
|
|
if(getFactory().getNovle().isLocalBook()) {
|
|
// btnRefresh.setEnabled(false);
|
|
menu.findItem(R.id.action_refresh).setVisible(false);
|
|
}
|
|
return super.onPrepareOptionsMenu(menu);
|
|
}
|
|
@Override
|
|
protected void setTitle() {
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void initData() {
|
|
pageFactory = getFactory();//PageFactory.getInstance(getApplicationContext());
|
|
Log.d(TAG, "prepareBook: pagefactory.mbook is ?" + (pageFactory.getNovle() .getName()) );
|
|
|
|
//config = Config.getInstance();
|
|
// dm = getResources().getDisplayMetrics();
|
|
// typeface = config.getTypeface();
|
|
|
|
setSupportActionBar(toolbar);
|
|
//设置导航图标
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
finish();
|
|
}
|
|
});
|
|
if (getSupportActionBar() != null) {
|
|
getSupportActionBar().setTitle(pageFactory.getBookName());
|
|
}
|
|
tvSource.setText(String.format("以下目录及内容来自%s%s",pageFactory.getSite().getName(), Constants.SHOW_NOVEL_CHAPTER_URL ? pageFactory.getSite().getMuluUrl():""));
|
|
|
|
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),pageFactory.getNovle().getId()));
|
|
tabLayout.setViewPager(pager);
|
|
}
|
|
|
|
@Override
|
|
public void fillData() {
|
|
|
|
}
|
|
|
|
|
|
protected void initListener() {
|
|
|
|
}
|
|
/*@OnClick({R.id.btnSort,R.id.btnRefresh})
|
|
void Onclick(View view){
|
|
if(view.getId() == R.id.btnSort){
|
|
Log.d(TAG, "Onclick: sorted");
|
|
|
|
if(sortcat!=null){
|
|
sortcat.sortList();
|
|
}
|
|
if(sortmark!=null){
|
|
sortmark.sortList();
|
|
}
|
|
}else{
|
|
if(view.getId() == R.id.btnRefresh){{
|
|
|
|
if(sortcat!=null){
|
|
sortcat.refresh();
|
|
}
|
|
if(sortmark!=null){
|
|
sortmark.refresh();
|
|
|
|
}
|
|
}}
|
|
}
|
|
|
|
}*/
|
|
private Sortcat sortcat=null;
|
|
private Sortmark sortmark=null;
|
|
|
|
public void setSortcat(Sortcat sort) {
|
|
this.sortcat = sort;
|
|
}
|
|
|
|
|
|
public void setSortmark(Sortmark sort) {
|
|
this.sortmark = sort;
|
|
}
|
|
public interface Sortmark {
|
|
public void sortList();
|
|
public void refresh();
|
|
}
|
|
public interface Sortcat {
|
|
public void sortList();
|
|
public void refresh();
|
|
}
|
|
@Override
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
getMenuInflater().inflate(R.menu.catalogemark, menu);
|
|
if(getFactory().getNovle().isLocalBook()) {
|
|
menu.findItem(R.id.action_change_source).setEnabled(false);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
// Handle action bar item clicks here. The action bar will
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
int id = item.getItemId();
|
|
|
|
if (id == R.id.action_change_source) {
|
|
Intent intent = new Intent(MarkActivity.this, Activity_ChgSource.class);
|
|
intent.putExtra(Activity_ChgSource.EXTR_ID, pageFactory.getChapter().getIndex());
|
|
intent.putExtra(Activity_ChgSource.EXTR_TITLE, pageFactory.getChapter().getChapterName());
|
|
intent.putExtra(Activity_ChgSource.EXTR_SITE, pageFactory.getChapter().getDomain());
|
|
intent.putExtra(Activity_ChgSource.EXTR_cate,true);
|
|
startActivity(intent);
|
|
finish();
|
|
}else
|
|
if (id == R.id.action_sort) {
|
|
Log.d(TAG, "Onclick: sorted");
|
|
|
|
if(sortcat!=null){
|
|
sortcat.sortList();
|
|
}
|
|
if(sortmark!=null){
|
|
sortmark.sortList();
|
|
}
|
|
}else
|
|
if (id == R.id.action_refresh) {
|
|
if(sortcat!=null){
|
|
sortcat.refresh();
|
|
}
|
|
if(sortmark!=null){
|
|
sortmark.refresh();
|
|
|
|
}
|
|
}
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
PageFactory getFactory(){
|
|
if(pageFactory==null) {
|
|
pageFactory = PageFactory.getInstance(getApplicationContext());
|
|
}
|
|
return pageFactory;
|
|
}
|
|
}
|