working on first page

This commit is contained in:
mwang 2019-04-11 18:05:41 +08:00
parent d57aab3251
commit 56427a7621
36 changed files with 1101 additions and 378 deletions

View File

@ -92,7 +92,7 @@
</activity>
<activity
android:name=".Main2Activity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/ToolBarTheme.NoActionBar">
<intent-filter>

View File

@ -14,13 +14,17 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.MovieSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.MyImageLoader;
import com.novelbook.android.utils.OnItemClickListener;
import com.novelbook.android.adapter.BookListAdapter;
@ -33,6 +37,7 @@ import butterknife.ButterKnife;
public abstract class Activity_base extends AppCompatActivity {
private ProgressDialog mProgressDialog;
protected Gson gson = new Gson();
@Nullable
@BindView(R.id.recycleViewBookList)
RecyclerView rvshudan;
@ -41,7 +46,7 @@ public abstract class Activity_base extends AppCompatActivity {
intent.putExtra("BOOKNAME",bookName);
startActivity(intent);
}
// protected MyImageLoader imgloader = new MyImageLoader();
/**
* 初始化布局
*/
@ -151,7 +156,7 @@ public abstract class Activity_base extends AppCompatActivity {
}
}
public void showProgress(boolean flag, String message) {
public void showProgressDialog(boolean flag, String message) {
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
@ -199,6 +204,9 @@ public abstract class Activity_base extends AppCompatActivity {
}
}
protected void loadImageView(String url, ImageView imageView){
ImageUtil.loadImage( this, url , imageView);
}
/*
class BookListAdapter extends RecyclerView.Adapter<MyViewHolder> {

View File

@ -16,11 +16,12 @@ import butterknife.BindView;
public class Activity_cate_books extends Activity_base {
public static String EXTRNAME="catename";
@BindView(R.id.viewpager)
ViewPager mViewpager;
@BindView(R.id.tab_layout)
SlidingTabLayout tabLayout;
String cate="";
private ArrayList<Fragment> mFragments;
ArrayList<View> mList;
String[] mTitle;
@ -39,8 +40,8 @@ public class Activity_cate_books extends Activity_base {
@Override
protected void setTitle() {
String title = getIntent().getStringExtra("CATENAME");
this.setTitle(title);
cate = getIntent().getStringExtra(EXTRNAME);
this.setTitle(cate);
}
@Override
@ -52,12 +53,13 @@ public class Activity_cate_books extends Activity_base {
void initTabs() {
if(mFragments ==null || mFragments.size() ==0){
mTitle = new String[]{"最热", "最新", "评分","完结"};
mTitle = new String[]{"新书", "连载", "完本"};
mFragments = new ArrayList<>();
mFragments.add(new Fragment_booklist());
mFragments.add(new Fragment_booklist());
mFragments.add(new Fragment_booklist());
mFragments.add(new Fragment_booklist());
mFragments.add( Fragment_booklist.newInstance(cate,1));
mFragments.add( Fragment_booklist.newInstance(cate,2));
mFragments.add( Fragment_booklist.newInstance(cate,3));
Log.d(TAG,"initial fragments in tabs ");
}
Log.d(TAG,"set viewPager adapter ");

View File

@ -42,6 +42,7 @@ import com.novelbook.android.service.MyIntentService;
import com.novelbook.android.service.ServiceDownload;
import com.novelbook.android.utils.BookUtil;
import com.novelbook.android.utils.GsonUtil;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.MyImageLoader;
import com.novelbook.android.utils.NovelParseUtil;
import com.novelbook.android.utils.PageFactory;
@ -174,7 +175,7 @@ public class BookActivity extends Activity_base {
}
private MyImageLoader loader = new MyImageLoader();
/**
* 设置服务器传来的详细信息
@ -191,9 +192,7 @@ public class BookActivity extends Activity_base {
if (mNovel.getLastUpateTime() > 0) {
this.txtLatestCate.setText(new Date(mNovel.getLastUpateTime()).toString() + "\n" + txtLatestCate.getText());
}
loader.displayImage(BookActivity.this, NetUtil.getCoverUrl(mNovel.getCover()), imageView);
loadImageView(mNovel.getCover(),imageView);
}
@ -373,7 +372,7 @@ public class BookActivity extends Activity_base {
}.start();
showProgress(false, "正在加入到队列,请等待");
showProgressDialog(false, "正在加入到队列,请等待");
}

View File

@ -232,7 +232,7 @@ public class FileActivity extends Activity_base {
private class SearchTextFileTask extends AsyncTask<Void,Void,Boolean>{
@Override
protected void onPreExecute() {
showProgress(true,"正在扫描txt文件");
showProgressDialog(true,"正在扫描txt文件");
}
@Override

View File

@ -9,6 +9,8 @@ import android.content.res.Resources;
import android.graphics.pdf.PdfDocument;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
@ -27,6 +29,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.novelbook.android.Activity_base;
import com.novelbook.android.Activity_paihangbang;
@ -39,8 +42,11 @@ import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.MyImageLoader;
import com.novelbook.android.utils.OnItemClickListener;
import com.novelbook.android.utils.PageFactory;
import com.youth.banner.loader.ImageLoader;
import org.litepal.LitePal;
import org.w3c.dom.Text;
@ -63,9 +69,11 @@ public abstract class BasicFragment extends Fragment {
private View rootView;
protected abstract int getLayoutRes();
protected abstract void initData();
protected abstract void fillData();
protected void initListener(){}
protected abstract void initViews();
protected Gson gson = new Gson();
// protected MyImageLoader imgloader = new MyImageLoader();
// Main2Activity activity;
FragmentActivity activity;
@ -79,12 +87,15 @@ public abstract class BasicFragment extends Fragment {
// Log.d(TAG,"fragment onCreate ");
// activity =(Main2Activity)getActivity();
activity = getActivity();
initData();
processArguments();
// QLog.getLogger().e(dTAG,TAG+" "+ "onCreate");
// mediumFontSize = activity.getMiddleSizeFont();
}
protected abstract void processArguments();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -95,7 +106,7 @@ public abstract class BasicFragment extends Fragment {
ButterKnife.bind(this,view);
initListener();
initData();
initViews();
return view;
// Inflate the layout for this fragment
@ -110,6 +121,29 @@ public abstract class BasicFragment extends Fragment {
public abstract void setFTag();
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int wt = msg.what;
if (msg.what == 1) {
fillData();
} else if (msg.what == 2) //
{
Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
} else if (msg.what == 3) {
Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
}
hideProgress();
}
};
//--------------------------------------------------------------book list adapter------------------------------------------------
@ -138,6 +172,7 @@ public abstract class BasicFragment extends Fragment {
}
void showBookDetail(Novel book) {
Intent intent = new Intent(activity, BookActivity.class);
intent.putExtra(BookActivity.EXTRA_BOOK,book);
startActivity(intent);
@ -155,10 +190,12 @@ public abstract class BasicFragment extends Fragment {
Novel nv ;
nv = gson.fromJson(result,Novel.class);
nv.update(id);
nv= LitePal.find(Novel.class,id);
if(id>0) {
nv.update(id);
nv= LitePal.find(Novel.class,id);
}else {
nv.save();
}
PageFactory.getInstance().prepareBook(nv ); //打开本地小说内容
try {
@ -181,7 +218,7 @@ public abstract class BasicFragment extends Fragment {
}
void showProgressDialog(boolean flag,String msg){
((Activity_base) getActivity()).showProgress(flag,msg);
((Activity_base) getActivity()).showProgressDialog(flag,msg);
}
void hideProgress(){
((Activity_base) getActivity()).hideProgress();
@ -261,5 +298,7 @@ public abstract class BasicFragment extends Fragment {
startActivity(intent);
}
protected void loadImageView(String url, ImageView imageView){
ImageUtil.loadImage( getActivity(), url , imageView);
}
}

View File

@ -0,0 +1,109 @@
package com.novelbook.android.Fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.novelbook.android.R;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link BlankFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link BlankFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BlankFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public BlankFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment BlankFragment.
*/
// TODO: Rename and change types and number of parameters
public static BlankFragment newInstance(String param1, String param2) {
BlankFragment fragment = new BlankFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_blank2, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}

View File

@ -50,9 +50,19 @@ public class BookMarkFragment extends BasicFragment {
bookMarksList = LitePal.where("novelId = ?", novelId+"").find(BookMarks.class);
}
@Override
protected void fillData() {
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected void initListener() {
lv_bookmark.setOnItemClickListener(new AdapterView.OnItemClickListener() {

View File

@ -40,8 +40,18 @@ public class CatalogFragment extends BasicFragment {
}
progressDialog.show();
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected void fillData() {
}
private void dismissProgressDialog() {
if ( null != progressDialog) {
progressDialog.dismiss();

View File

@ -124,8 +124,18 @@ public class Fragment_Shelf extends BasicFragment {
initReceyleView();
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected void fillData() {
}
public void initReceyleView() {
initData();
// mRecyclerView.setLayoutManager(new LinearLayoutManager(this.activity));

View File

@ -33,7 +33,16 @@ public class Fragment_bangdan extends BasicFragment {
fragment.setArguments(args);
return fragment;
}
@Override
protected void fillData() {
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected int getLayoutRes() {
return R.layout.fragment_fragment_bangdan;

View File

@ -30,8 +30,18 @@ public class Fragment_bookStore extends BasicFragment {
ArrayList<View> mList;
String[] mTitle;
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected void fillData() {
}
public static Fragment_bookStore newInstance(String param1, String param2) {
Fragment_bookStore fragment = new Fragment_bookStore();
Bundle args = new Bundle();

View File

@ -3,24 +3,45 @@ package com.novelbook.android.Fragments;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.novelbook.android.R;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
import com.novelbook.android.utils.Constants;
import com.novelbook.android.utils.OnItemClickListener;
import com.novelbook.android.adapter.BookListAdapter;
import org.json.JSONObject;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import butterknife.BindView;
public class Fragment_booklist extends BasicFragment {
private static final String EXTR_CATE ="cate" ;
private static final String EXTR_PROGRESS ="progress" ;
private BookListAdapter mAdapter;
// private BookListAdapter mAdapter;
private List<Novel> mData;;
private String cate;
private int progress;
private int pageNo=1;
private int totalCount;
private int pageCount;
@BindView(R.id.rvBooklist)
RecyclerView rvBooklist;
@ -28,30 +49,63 @@ public class Fragment_booklist extends BasicFragment {
// Required empty public constructor
}
public static Fragment_booklist newInstance(String param1, String param2) {
public static Fragment_booklist newInstance(String noveType,int progress) {
Fragment_booklist fragment = new Fragment_booklist();
Bundle args = new Bundle();
args.putString(EXTR_CATE,noveType);
args.putInt(EXTR_PROGRESS, progress);
fragment.setArguments(args);
return fragment;
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
cate = bundle.getString(EXTR_CATE);
progress = bundle.getInt(EXTR_PROGRESS);
@Override
protected int getLayoutRes() {
return R.layout.fragment_fragment_booklist;
}
}
public List<Novel> parserJsonArray(String strJson) {
List<Novel> list = new ArrayList<Novel>();
//创建一个Gson对象
// Gson gson = new Gson();
//创建一个JsonParser
JsonParser parser = new JsonParser();
//通过JsonParser对象可以把json格式的字符串解析成一个JsonElement对象
JsonElement el = parser.parse(strJson);
//把JsonElement对象转换成JsonObject
JsonObject jsonObj = null;
if (el.isJsonObject()) {
jsonObj = el.getAsJsonObject();
}
//把JsonElement对象转换成JsonArray
JsonArray jsonArray = null;
if (el.isJsonArray()) {
jsonArray = el.getAsJsonArray();
}
//遍历JsonArray对象
Iterator it = jsonArray.iterator();
while (it.hasNext()) {
JsonElement e = (JsonElement) it.next();
//JsonElement转换为JavaBean对象
list.add((Novel) gson.fromJson(e, Novel.class));
}
return list;
}
@Override
public void initData() {
protected void fillData() {
mData =initData(mData,'Z');
mAdapter = new BookListAdapter(activity, mData, R.layout.recycle_list_item_shudan, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
showBookDetail(mData.get(position) );
showBookDetail(mData.get(position) );
// openBook(mData.get(position),mAdapter);
}
@ -67,11 +121,47 @@ public class Fragment_booklist extends BasicFragment {
Toast.LENGTH_SHORT).show();
}
});
initialBookList();
}
@Override
protected int getLayoutRes() {
return R.layout.fragment_fragment_booklist;
}
@Override
public void initData() {
showProgressDialog(true, "正在加载");
BookSubscribe.getCateNovelList(cate,pageNo,Constants.SEX,progress,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
@Override
public void onSuccess(String result) {
// mFirstPage= gson.fromJson(result, FirstPage.class);
try {
JSONObject jsonObject = new JSONObject(result);
String resultstr = jsonObject.getString("ns");
mData = parserJsonArray(resultstr);
} catch (Exception e) {
e.printStackTrace();
}
handler.sendEmptyMessage(1);
}
@Override
public void onFault(String errorMsg) {
//失败
Log.d(TAG, "error on get firstpage: " + errorMsg);
handler.sendEmptyMessage(1);
}
}, getActivity()));
}
@Override
public void initViews(){
initialBookList();
}
//----------------绑定列表

View File

@ -11,20 +11,29 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.novelbook.android.BookActivity;
import com.novelbook.android.R;
import com.novelbook.android.bean.FirstPage;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.db.SiteRule;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
import com.novelbook.android.utils.CyclePageIndicator;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.MyViewPager;
import com.novelbook.android.utils.OnItemClickListener;
import com.novelbook.android.adapter.BookListAdapter;
@ -34,9 +43,11 @@ import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;
import org.json.JSONObject;
import org.litepal.LitePal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import butterknife.BindView;
@ -50,7 +61,7 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
private String mParam1;
private String mParam2;
//@BindView(R.id.llTuijian)
// LinearLayout llTuijian;
// LinearLayout llTuijian;
@BindView(R.id.banner)
Banner banner;
@BindView(R.id.dot_horizontal)
@ -59,21 +70,43 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
MyViewPager mViewpagerTuijian;
//@BindView(R.id.titleIndictator)
// TitlePageIndicator titleIndicator;
@BindView(R.id.imageBlock1)
ImageView imageViewBlock1;
@BindView(R.id.imageBlock2)
ImageView imageViewBlock2;
@BindView(R.id.imageBlock3)
ImageView imageViewBlock3;
@BindView(R.id.tvBlock1)
TextView tvBlock1;
@BindView(R.id.tvBlock2)
TextView tvBlock2;
@BindView(R.id.tvBlock3)
TextView tvBlock3;
@BindView(R.id.buttonMore1)
Button btnMore1;
@BindView(R.id.buttonMore2)
Button btnMore2;
@BindView(R.id.buttonMore3)
Button btnMore3;
private List<Fragment> mFragments;
private ArrayList<View> mList;
// String[] mTitle;
private ArrayList<String> list_path;
private ArrayList<String> list_title;
private List<NovelBlock> mBlocks;
private List<String> list_path;
private List<String> list_title;
private FirstPage mFirstPage;
public Fragment_jingxuan() {
// Required empty public constructor
}
public static Fragment_jingxuan newInstance(String param1, String param2) {
Fragment_jingxuan fragment = new Fragment_jingxuan();
Bundle args = new Bundle();
@ -83,27 +116,7 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int wt = msg.what;
if (msg.what == 1) {
} else if (msg.what == 2) //
{
Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
} else if (msg.what == 3) {
Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
}
}
};
@Override
@ -111,14 +124,55 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
return R.layout.fragment_jingxuan;
}
public List<NovelBlock> parserJsonArray(String strJson) {
List<NovelBlock> list = new ArrayList<NovelBlock>();
//创建一个Gson对象
// Gson gson = new Gson();
//创建一个JsonParser
JsonParser parser = new JsonParser();
//通过JsonParser对象可以把json格式的字符串解析成一个JsonElement对象
JsonElement el = parser.parse(strJson);
//把JsonElement对象转换成JsonObject
JsonObject jsonObj = null;
if (el.isJsonObject()) {
jsonObj = el.getAsJsonObject();
}
//把JsonElement对象转换成JsonArray
JsonArray jsonArray = null;
if (el.isJsonArray()) {
jsonArray = el.getAsJsonArray();
}
//遍历JsonArray对象
Iterator it = jsonArray.iterator();
while (it.hasNext()) {
JsonElement e = (JsonElement) it.next();
//JsonElement转换为JavaBean对象
list.add((NovelBlock) gson.fromJson(e, NovelBlock.class));
}
return list;
}
@Override
public void initData() {
BookSubscribe.getFirstPage( new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
showProgressDialog(true, "正在加载");
BookSubscribe.getFirstPage(new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
@Override
public void onSuccess(String result) {
mFirstPage= gson.fromJson(result, FirstPage.class);
// mFirstPage= gson.fromJson(result, FirstPage.class);
try {
JSONObject jsonObject = new JSONObject(result);
String resultstr = jsonObject.getString("blocks");
mBlocks = parserJsonArray(resultstr);
} catch (Exception e) {
e.printStackTrace();
}
handler.sendEmptyMessage(1);
}
@ -126,49 +180,92 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
@Override
public void onFault(String errorMsg) {
//失败
Log.d(TAG,"error on get firstpage: "+errorMsg);
Log.d(TAG, "error on get firstpage: " + errorMsg);
handler.sendEmptyMessage(1);
}
},getActivity()));
}, getActivity()));
mHotNewData_l = initData(mHotNewData_l,'B');
mHotNewData_g= initData(mHotNewData_g,'D');
mHotLianZaiData_l= initData(mHotLianZaiData_l,'C');
mHotLianZaiData_g=initData(mHotLianZaiData_g,'D');
mFinishedData_l=initData(mFinishedData_l,'A');
mFinishedData_g=initData(mFinishedData_g,'G');
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
public void initViews(){
protected void fillData() {
/*
mHotNewData_l = initData(mHotNewData_l, 'B');
mHotNewData_g = initData(mHotNewData_g, 'D');
mHotLianZaiData_l = initData(mHotLianZaiData_l, 'C');
mHotLianZaiData_g = initData(mHotLianZaiData_g, 'D');
mFinishedData_l = initData(mFinishedData_l, 'A');
mFinishedData_g = initData(mFinishedData_g, 'G');
*/
if(mBlocks ==null || mBlocks.size() ==0){
return;
}
if(mBlocks.size()>0) {
mHotNewData_l = mBlocks.get(0).getNs();
tvBlock1.setText(mBlocks.get(0).getName());
loadImageView(mBlocks.get(0).getIcon(),imageViewBlock1);
btnMore1.setTag(mBlocks.get(0).getName());
}
// mHotNewData_g = initData(mHotNewData_g, 'D');
if(mBlocks.size()>1) {
mHotLianZaiData_l = mBlocks.get(1).getNs();//initData(mHotLianZaiData_l, 'C');
tvBlock2.setText(mBlocks.get(1).getName());
loadImageView(mBlocks.get(1).getIcon(),imageViewBlock2);
btnMore2.setTag(mBlocks.get(1).getName());
}
// mHotLianZaiData_g = initData(mHotLianZaiData_g, 'D');
// mFinishedData_l = mBlocks.get(2).getNs(); //initData(mFinishedData_l, 'A');
if(mBlocks.size()>2) {
mFinishedData_g = mBlocks.get(2).getNs();// initData(mFinishedData_g, 'G');
tvBlock3.setText(mBlocks.get(2).getName());
loadImageView(mBlocks.get(2).getIcon(),imageViewBlock3);
btnMore3.setTag(mBlocks.get(2).getName());
}
testBanner(banner, this);
initTuijianPagers();
initialBookList();
initTuijianPagers();
}
@Override
public void initViews() {
}
@Override
public void setFTag() {
TAG ="com.novelbook.android.Fragments.Fragment_jingxuan";
TAG = "com.novelbook.android.Fragments.Fragment_jingxuan";
}
@OnClick({R.id.buttonMoreHot,R.id.buttonMoreLianzai,R.id.buttonMoreTuijian,R.id.buttonMoreWanben
,R.id.buttonCatePingfen,R.id.buttonCateRegeng ,R.id.buttonCateTuijian,R.id.buttonCateShoucang,R.id.buttonCateWanjie
@OnClick({R.id.buttonMore1, R.id.buttonMore2, R.id.buttonMoreTuijian, R.id.buttonMore3
, R.id.buttonCatePingfen, R.id.buttonCateRegeng, R.id.buttonCateTuijian, R.id.buttonCateShoucang, R.id.buttonCateWanjie
})
void bubmitButton(View view) {
switch (view.getId()) {
case R.id.buttonMoreLianzai:
showPaihangbang("最热");
case R.id.buttonMore1:
showPaihangbang(btnMore1.getTag().toString());
break;
case R.id.buttonMoreTuijian:
showPaihangbang("推荐");
break;
case R.id.buttonMoreWanben:
showPaihangbang("完结");
case R.id.buttonMore2:
showPaihangbang(btnMore2.getTag().toString());
break;
case R.id.buttonMoreHot:
showPaihangbang("新书");
case R.id.buttonMore3:
showPaihangbang(btnMore3.getTag().toString());
break;
case R.id.buttonCatePingfen:
showPaihangbang("评分");
@ -187,13 +284,21 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
break;
}
}
void testBanner(Banner banner,OnBannerListener listioner) {
void testBanner(Banner banner, OnBannerListener listioner) {
//放图片地址的集合
list_path = new ArrayList<>();
list_path = mBlocks.get(0).getPictures();//new ArrayList<String>();// mBlocks.get(0).getPictures() ;
//放标题的集合
list_title = new ArrayList<>();
for (Novel nv : mBlocks.get(0).getNs()) {
list_title.add(nv.getName());
}
/*
list_path.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic21363tj30ci08ct96.jpg");
list_path.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic259ohaj30ci08c74r.jpg");
list_path.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2b16zuj30ci08cwf4.jpg");
@ -202,10 +307,11 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
list_title.add("天天向上");
list_title.add("热爱劳动");
list_title.add("不搞对象");
*/
//设置内置样式共有六种可以点入方法内逐一体验使用
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
//设置图片加载器图片加载器在下方
banner.setImageLoader(new MyLoader());
banner.setImageLoader(ImageUtil.loader);
//设置图片网址或地址的集合
banner.setImages(list_path);
//设置轮播的动画效果内含多种特效可点入方法内查找后内逐一体验
@ -229,14 +335,10 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
@Override
public void OnBannerClick(int position) {
showShudanDetail(position);
}
//自定义的图片加载器
private class MyLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context).load((String) path).into(imageView);
}
Novel nv = mBlocks.get(0).getNs().get(position);
showBookDetail(nv);
// showShudanDetail(position);
}
@ -249,13 +351,12 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
void initTuijianPagers() {
if (mFragments == null || mFragments.size() == 0) {
// mTitle = new String[]{"精选", "榜单", "书单"};
// mTitle = new String[]{"精选", "榜单", "书单"};
mFragments = new ArrayList<>();
mFragments.add(new Fragment_jingxuan_tuijian());
mFragments.add(new Fragment_jingxuan_tuijian());
mFragments.add(new Fragment_jingxuan_tuijian());
mFragments.add(new Fragment_jingxuan_tuijian());
mFragments.add(new Fragment_jingxuan_tuijian());
for(NovelBlock block : mBlocks ){
mFragments.add(Fragment_jingxuan_tuijian.newInstance(block.getNs()));
}
Log.d(TAG, "initial fragments in tabs ");
}
@ -273,10 +374,10 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}
//ViewPager与TabLayout绑定后这里获取到PageTitle就是Tab的Text
// @Override
// public CharSequence getPageTitle(int position) {
// return mTitle[position];
// }
// @Override
// public CharSequence getPageTitle(int position) {
// return mTitle[position];
// }
};
mViewpagerTuijian.setAdapter(mAdapter);
mViewpagerTuijian.addOnPageChangeListener(new CyclePageIndicator(getContext(), cyclell, mFragments.size()));
@ -284,199 +385,179 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}
//---------------------------------------------------book cate list-------------------------------begin
// private BookListAdapter mAdapter;
private List<Novel> mHotNewData_l,mHotNewData_g,mHotLianZaiData_l, mHotLianZaiData_g,mFinishedData_l, mFinishedData_g;
// private BookListAdapter mAdapter;
private List<Novel> mHotNewData_l, mHotNewData_g, mHotLianZaiData_l, mHotLianZaiData_g, mFinishedData_l, mFinishedData_g;
@BindView(R.id.rvHotNewL) RecyclerView rvHotNewL;
@BindView(R.id.rvHotNewG) RecyclerView rvHotNewG;
@BindView(R.id.rvLianZaiG) RecyclerView rvLianZaiG;
@BindView(R.id.rvLianZaiL) RecyclerView rvLianZaiL;
@BindView(R.id.rvFinishL) RecyclerView rvFinishL;
@BindView(R.id.rvFinishG) RecyclerView rvFinishG;
@BindView(R.id.rvHotNewL)
RecyclerView rvHotNewL;
@BindView(R.id.rvHotNewG)
RecyclerView rvHotNewG;
@BindView(R.id.rvLianZaiG)
RecyclerView rvLianZaiG;
@BindView(R.id.rvLianZaiL)
RecyclerView rvLianZaiL;
@BindView(R.id.rvFinishL)
RecyclerView rvFinishL;
@BindView(R.id.rvFinishG)
RecyclerView rvFinishG;
void initialBookList() {
OnItemClickListener onItemClickListener =new OnItemClickListener()
{
OnItemClickListener onItemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(View view, int position)
{
public void onItemClick(View view, int position) {
showBookDetail(mHotNewData_l.get(position));
// openBook(mHotNewData_l.get(position),null);
// openBook(mHotNewData_l.get(position),null);
}
@Override
public void onItemLongClick(View view, int position)
{
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position ,int llId) {
public void onLinearOutClick(View view, int position, int llId) {
}
} ;
rvHotNewL.setLayoutManager(new LinearLayoutManager(activity));
rvHotNewL.setAdapter(new BookListAdapter(activity,mHotNewData_l,R.layout.recycle_list_item_horizon ,onItemClickListener));
};
if(mHotNewData_l!=null) {
rvHotNewL.setLayoutManager(new LinearLayoutManager(activity));
rvHotNewL.setAdapter(new BookListAdapter(activity, mHotNewData_l, R.layout.recycle_list_item_horizon, onItemClickListener));
}
if(mHotNewData_g!=null) {
rvHotNewG.setLayoutManager(new GridLayoutManager(activity, 3));
rvHotNewG.setLayoutManager(new GridLayoutManager(activity,3));
rvHotNewG.setAdapter(new BookListAdapter(activity, mHotNewData_g, R.layout.recycle_list_item, new OnItemClickListener() {
rvHotNewG.setAdapter(new BookListAdapter(activity,mHotNewData_g,R.layout.recycle_list_item,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position) {
showBookDetail(mHotNewData_g.get(position));
@Override
public void onItemClick(View view, int position)
{
showBookDetail(mHotNewData_g.get(position));
// openBook( mHotNewData_g.get(position) ,null);
}
// openBook( mHotNewData_g.get(position) ,null);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onItemLongClick(View view, int position)
{
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position ,int llId) {
@Override
public void onLinearOutClick(View view, int position, int llId) {
}
}));
}
}));
}
if(rvLianZaiL!=null) {
rvLianZaiL.setLayoutManager(new LinearLayoutManager(this.activity));
rvLianZaiL.setLayoutManager(new LinearLayoutManager(this.activity));
rvLianZaiL.setAdapter(new BookListAdapter(activity, mHotLianZaiData_l, R.layout.recycle_list_item_horizon, new OnItemClickListener() {
rvLianZaiL.setAdapter(new BookListAdapter(activity,mHotLianZaiData_l,R.layout.recycle_list_item_horizon,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position)
{
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
@Override
public void onItemClick(View view, int position) {
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
showBookDetail(mHotLianZaiData_l.get(position));
// openBook( mHotLianZaiData_l.get(position) ,null);
}
showBookDetail(mHotLianZaiData_l.get(position));
// openBook( mHotLianZaiData_l.get(position) ,null);
}
@Override
public void onItemLongClick(View view, int position)
{
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position ,int llId) {
@Override
public void onLinearOutClick(View view, int position, int llId) {
}
}));
}
}));
}
if(mHotLianZaiData_g!=null) {
rvLianZaiG.setLayoutManager(new GridLayoutManager(activity, 3));
rvLianZaiG.setLayoutManager(new GridLayoutManager(activity,3));
rvLianZaiG.setAdapter(new BookListAdapter(activity, mHotLianZaiData_g, R.layout.recycle_list_item, new OnItemClickListener() {
rvLianZaiG.setAdapter(new BookListAdapter(activity,mHotLianZaiData_g,R.layout.recycle_list_item,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position) {
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
@Override
public void onItemClick(View view, int position)
{
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
showBookDetail(mHotLianZaiData_g.get(position));
showBookDetail(mHotLianZaiData_g.get(position));
// openBook( mHotLianZaiData_g.get(position) ,null);
}
// openBook( mHotLianZaiData_g.get(position) ,null);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onItemLongClick(View view, int position)
{
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position ,int llId) {
@Override
public void onLinearOutClick(View view, int position, int llId) {
}
}));
}
}));
}
if(mFinishedData_l!=null) {
rvFinishL.setLayoutManager(new LinearLayoutManager(this.activity));
rvFinishL.setAdapter(new BookListAdapter(activity, mFinishedData_l, R.layout.recycle_list_item_horizon, new OnItemClickListener() {
rvFinishL.setLayoutManager(new LinearLayoutManager(this.activity));
rvFinishL.setAdapter(new BookListAdapter(activity,mFinishedData_l,R.layout.recycle_list_item_horizon,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position) {
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
@Override
public void onItemClick(View view, int position)
{
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
showBookDetail(mFinishedData_l.get(position));
showBookDetail(mFinishedData_l.get(position));
// openBook( mFinishedData_l.get(position) ,null);
}
// openBook( mFinishedData_l.get(position) ,null);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onItemLongClick(View view, int position)
{
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position ,int llId) {
@Override
public void onLinearOutClick(View view, int position, int llId) {
}
}));
}
}));
}
if(mFinishedData_g!=null) {
rvFinishG.setLayoutManager(new GridLayoutManager(activity, 3));
rvFinishG.setLayoutManager(new GridLayoutManager(activity,3));
rvFinishG.setAdapter(new BookListAdapter(activity, mFinishedData_g, R.layout.recycle_list_item, new OnItemClickListener() {
rvFinishG.setAdapter(new BookListAdapter(activity,mFinishedData_g,R.layout.recycle_list_item ,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position) {
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
@Override
public void onItemClick(View view, int position)
{
// Toast.makeText(activity, position + "grid click", Toast.LENGTH_SHORT).show();
showBookDetail(mFinishedData_g.get(position));
showBookDetail(mFinishedData_g.get(position));
// openBook( mFinishedData_g.get(position) ,null);
}
// openBook( mFinishedData_g.get(position) ,null);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onItemLongClick(View view, int position)
{
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position ,int llId) {
}
}));
@Override
public void onLinearOutClick(View view, int position, int llId) {
}
}));
}
}
}
class BannerListioner1 implements OnBannerListener {
@Override
public void OnBannerClick(int position) {
Log.i("第一个banner", "你点了第一个banner 第" + position + "张轮播图");
}
}
class BannerListioner2 implements OnBannerListener {
@Override
public void OnBannerClick(int position) {
Log.i("第二个banner", "你点了第二个banner 第"+position+"张轮播图");
}
}
}

View File

@ -1,30 +1,78 @@
package com.novelbook.android.Fragments;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.novelbook.android.R;
import com.novelbook.android.db.Novel;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class Fragment_jingxuan_tuijian extends BasicFragment {
@BindView(R.id.imageGallary1)
ImageView imageView1;
@BindView(R.id.imageGallary2)
ImageView imageView2;
@BindView(R.id.imageGallary3)
ImageView imageView3;
@BindView(R.id.tvGallaryName1)
TextView tvName1;
@BindView(R.id.tvGallaryName2)
TextView tvName2;
@BindView(R.id.tvGallaryName3)
TextView tvName3;
private Novel novel1,novel2,novel3;
private static String EXTR_NV1="nv1";
private static String EXTR_NV2="nv2";
private static String EXTR_NV3="nv3";
public static Fragment_jingxuan_tuijian newInstance(String param1, String param2) {
public static Fragment_jingxuan_tuijian newInstance(List<Novel> novels) {
Fragment_jingxuan_tuijian fragment = new Fragment_jingxuan_tuijian();
Bundle args = new Bundle();
args.putSerializable(EXTR_NV1,novels.get(0));
args.putSerializable(EXTR_NV2,novels.get(1));
args.putSerializable(EXTR_NV3,novels.get(2));
fragment.setArguments(args);
return fragment;
}
@Override
protected void fillData() {
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
novel1 = (Novel) bundle.getSerializable(EXTR_NV1);
novel2= (Novel) bundle.getSerializable(EXTR_NV2);
novel3 = (Novel) bundle.getSerializable(EXTR_NV3);
}
}
/*
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -34,19 +82,20 @@ public class Fragment_jingxuan_tuijian extends BasicFragment {
ButterKnife.bind(this, view);
return view;
}
*/
@OnClick({R.id.llGallary1,R.id.llGallary2,R.id.llGallary3})
void onGallaryClick(View view){
switch (view.getId()){
case R.id.llGallary1:
// showBookDetail("ABC");
if(novel1!=null)
showBookDetail(novel1);
break;
case R.id.llGallary2:
// showBookDetail("123");
if(novel2!=null) showBookDetail(novel2);
break;
case R.id.llGallary3:
// showBookDetail("ZXF");
if(novel3!=null)
showBookDetail(novel3);
break;
}
}
@ -63,6 +112,20 @@ public class Fragment_jingxuan_tuijian extends BasicFragment {
@Override
public void initViews(){
if(novel1!=null) {
tvName1.setText(novel1.getName());
loadImageView(novel1.getCover(),imageView1);
}
if(novel2!=null) {
tvName2.setText(novel2.getName());
loadImageView(novel2.getCover(),imageView2);
}
if(novel3!=null) {
tvName3.setText(novel3.getName());
loadImageView(novel3.getCover(),imageView3);
}
}
@Override

View File

@ -47,8 +47,18 @@ public class Fragment_paihang extends BasicFragment {
public Fragment_paihang() {
// Required empty public constructor
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected void fillData() {
}
public static Fragment_paihang newInstance(String param1, String param2) {
Fragment_paihang fragment = new Fragment_paihang();
Bundle args = new Bundle();

View File

@ -43,7 +43,17 @@ public class Fragment_shudan extends BasicFragment {
protected int getLayoutRes() {
return R.layout.fragment_shudan;
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected void fillData() {
}
@Override
public void initData() {

View File

@ -45,6 +45,9 @@ public class Fragment_shudan_list extends BasicFragment {
return fragment;
}
@Override
protected void fillData() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -54,8 +57,15 @@ public class Fragment_shudan_list extends BasicFragment {
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
}
}
@Override
protected int getLayoutRes() {
return R.layout.fragment_fragment_shudan_list;

View File

@ -72,7 +72,7 @@ public class Main2Activity extends Activity_base
@Override
protected void setTitle() {
setTitle("");
}
@Override
@ -120,13 +120,13 @@ public class Main2Activity extends Activity_base
private void creatToolbar() {
// toolbar= (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// toolbar.setNavigationIcon(R.mipmap.ic_launcher_round);//设置导航栏图标
// toolbar.setLogo(R.mipmap.ic_launcher);//设置app logo
// toolbar.setTitle("Title");//设置主标题
// setTitle("titleaa");
// toolbar.setSubtitle("Subtitle");//设置子标题
toolbar.inflateMenu(R.menu.main);//设置右上角的填充菜单
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
@ -287,7 +287,7 @@ private int bottomSelectedIndex;
toggle.setDrawerIndicatorEnabled(showToggle);
toggle.syncState();
spinner.setVisibility( showSpinner?View.VISIBLE:View.INVISIBLE);
spinner.setVisibility( showSpinner?View.VISIBLE:View.GONE);
supportInvalidateOptionsMenu();
//invalidateOptionsMenu();
@ -295,7 +295,7 @@ private int bottomSelectedIndex;
if(bottomSelectedIndex==1) {
title ="";
}
txtTitle.setText(title);
this.setTitle(title);
}
@ -365,49 +365,6 @@ private int bottomSelectedIndex;
}
private void getDataFromServer() {
//url
String url1 = "http://api.kkmh.com/v1/topic_new/discovery_list?gender=0&sa_event=eyJwcm9qZWN0Ijoia%203VhaWthbl9hcHAiLCJ0aW1lIjoxNDg3ODM5MDM5MzE1LCJwcm9wZXJ0aWVzIjp7IkhvbWVwYWdlVGFiTmFtZSI6IueDremXqCIsIlZDb21t%20dW5pdHlUYWJOYW1lIjoi54Ot6ZeoIiwiJG9zX3ZlcnNpb24iOiI0LjIuMiIsIkdlbmRlclR5cGUiOiLlpbPniYgiLCJGcm9tRmluZENhdGVnb%203J5VGFiTmFtZSI6IuWFqOmDqCIsIklzQXV0b0xvYWQiOmZhbHNlLCIkbGliX3ZlcnNpb24iOiIxLjYuMzQiLCIkbmV0d29ya190eXBlIjoiV0l%20GSSIsIiR3aWZpIjp0cnVlLCIkbWFudWZhY3R1cmVyIjoic2Ftc3VuZyIsIkZyb21GaW5kVGFiTmFtZSI6IuaOqOiNkCIsIiRzY3JlZW%205faGVpZ2h0Ijo1NzYsIkNhdGVnb3J5Ijoi5peg5rOV6I635Y-WIiwiSG9tZXBhZ2VVcGRhdGVEYXRlIjowLCJQcm9wZXJ0eUV2ZW5%200IjoiUmVhZEZpbmRQYWdlIiwiRmluZFRhYk5hbWUiOiLmjqjojZAiLCJhYnRlc3RfZ3JvdXAiOjQ2LCIkc2NyZWVuX3dpZHRoIjo%20xMDI0LCJGaW5kQ2F0ZWdvcnlUYWJOYW1lIjoi5YWo6YOoIiwiJG9zIjoiQW5kcm9pZCIsIlRyaWdnZXJQYWdlIjoiSG9tZVBhZ2%20UiLCIkY2FycmllciI6IkNNQ0MiLCIkbW9kZWwiOiJHVC1QNTIxMCIsIiRhcHBfdmVyc2lvbiI6IjMuOC4xIn0sInR5cGUiOiJ0cmFja%20yIsImRpc3RpbmN0X2lkIjoiQTo5MDUxMDQyNzYzNzU1MTA5Iiwib3JpZ2luYWxfaWQiOiJBOjkwNTEwNDI3NjM3NTUxMDkiLCJldmV%20udCI6IlJlYWRGaW5kUGFnZSJ9";
RequestParams params1 = new RequestParams();
params1.setUri(url1);
//用xutils3网络请求数据需要导入xutils3的依赖和帮助类自己导入
x.http().get(params1, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(final String result) {
if (result != null) {
Log.i("xutils-http-result", result);
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
Log.i("xutils-http-error", "onError: ");
}
@Override
public void onCancelled(CancelledException cex) {
Log.i("xutils-http-cancel", "onCancelled: ");
}
@Override
public void onFinished() {
Log.i("xutils-http-finished", "onFinished: ");
}
});
}
long firstTime =0;

View File

@ -3,22 +3,40 @@ package com.novelbook.android;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.novelbook.android.bean.Cataloge;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
import com.novelbook.android.utils.Constants;
import com.novelbook.android.utils.ImageUtil;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import butterknife.BindView;
@ -30,18 +48,59 @@ public class activity_cates extends Activity_base {
RecyclerView mRecyclerView;
private List<String> mDatas;
private BookListAdapter mAdapter;
private String TAG = activity_cates.class.getSimpleName();
@Override
public int getLayoutRes() {
return R.layout.activity_cates;
}
private List<Cataloge> mCataloges;
@Override
protected void initViews() {
initReceyleView();
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int wt = msg.what;
if (msg.what == 1) {
fillData();
} else if (msg.what == 2) //
{
Toast.makeText(activity_cates.this, " ", Toast.LENGTH_LONG).show();
} else if (msg.what == 3) {
Toast.makeText(activity_cates.this, " ", Toast.LENGTH_LONG).show();
}
hideProgress();
}
};
private void fillData() {
List<Cataloge> cates = new ArrayList<>();
for(Cataloge cate:mCataloges){
if(cate.getNovelCount()>0){
cates.add(cate);
}
}
mAdapter = new BookListAdapter(this, cates, R.layout.recycle_list_item_cates, new OnItemClickLitener() {
@Override
public void onItemClick(View view, int position) {
showCateList(mCataloges.get(position).getName());
}
});
initReceyleView();
}
@Override
protected void setTitle() {
@ -56,26 +115,75 @@ public class activity_cates extends Activity_base {
private void showCateList(String s) {
Intent intent = new Intent(activity_cates.this, Activity_cate_books.class);
intent.putExtra("CATENAME",s);
intent.putExtra(Activity_cate_books.EXTRNAME,s);
startActivity(intent);
}
public List<Cataloge> parserJsonArray(String strJson) {
List<Cataloge> list = new ArrayList<Cataloge>();
//创建一个Gson对象
// Gson gson = new Gson();
//创建一个JsonParser
JsonParser parser = new JsonParser();
//通过JsonParser对象可以把json格式的字符串解析成一个JsonElement对象
JsonElement el = parser.parse(strJson);
//把JsonElement对象转换成JsonObject
JsonObject jsonObj = null;
if (el.isJsonObject()) {
jsonObj = el.getAsJsonObject();
}
//把JsonElement对象转换成JsonArray
JsonArray jsonArray = null;
if (el.isJsonArray()) {
jsonArray = el.getAsJsonArray();
}
//遍历JsonArray对象
Iterator it = jsonArray.iterator();
while (it.hasNext()) {
JsonElement e = (JsonElement) it.next();
//JsonElement转换为JavaBean对象
list.add((Cataloge) gson.fromJson(e, Cataloge.class));
}
return list;
}
@Override
protected void initData() {
mDatas = new ArrayList<String>();
for (int i = 0; i <5; i++)
{
mDatas.add("cate"+i);
}
mAdapter = new BookListAdapter(this, mDatas, R.layout.recycle_list_item_cates, new OnItemClickLitener() {
showProgressDialog(true, "正在加载");
BookSubscribe.getCates(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
@Override
public void onItemClick(View view, int position) {
showCateList(mDatas.get(position));
public void onSuccess(String result) {
// mFirstPage= gson.fromJson(result, FirstPage.class);
try {
JSONObject jsonObject = new JSONObject(result);
String resultstr = jsonObject.getString("nts");
mCataloges = parserJsonArray(resultstr);
handler.sendEmptyMessage(1);
} catch (Exception e) {
e.printStackTrace();
}
handler.sendEmptyMessage(1);
}
});
@Override
public void onFault(String errorMsg) {
//失败
Log.d(TAG, "error on get firstpage: " + errorMsg);
handler.sendEmptyMessage(1);
}
}, this));
}
@ -83,7 +191,7 @@ public class activity_cates extends Activity_base {
void initReceyleView() {
// mRecyclerView.setLayoutManager(new LinearLayoutManager(this.activity));
mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));
mRecyclerView.setLayoutManager(new GridLayoutManager(this,3));
mRecyclerView.setAdapter(mAdapter );
}
@ -94,10 +202,10 @@ public class activity_cates extends Activity_base {
private final int IMAGE_VIEW = 3;
private Context context;
private List<String> mDatas = new ArrayList<String>();
private List<Cataloge> mDatas = new ArrayList<Cataloge>();
private OnItemClickLitener mOnItemClickLitener;
private int listItemID;
public BookListAdapter(Context context, List<String> mDatas, int listItemID, OnItemClickLitener clickLitener) {
public BookListAdapter(Context context, List<Cataloge> mDatas, int listItemID, OnItemClickLitener clickLitener) {
this.context = context;
this.mDatas = mDatas;
this.mOnItemClickLitener = clickLitener;
@ -131,7 +239,7 @@ public class activity_cates extends Activity_base {
public void setParameters(List<String> mDatas,int listItemID ) {
public void setParameters(List<Cataloge> mDatas,int listItemID ) {
this.mDatas = mDatas;
this.listItemID = listItemID;
}
@ -144,8 +252,13 @@ public class activity_cates extends Activity_base {
@Override
public void onBindViewHolder(BookListAdapter.MyViewHolder holder, int position)
{
holder.tvTitle.setText(mDatas.get(position));
holder.tvNum.setText("9999");
holder.tvTitle.setText(mDatas.get(position).getName());
holder.tvNum.setText(mDatas.get(position).getNovelCount()+"");
if( mDatas.get(position).getNovel()!=null) {
ImageUtil.loadImage(context, mDatas.get(position).getNovel().getCover(), holder.imageView);
}
// 如果设置了回调则设置点击事件
if (mOnItemClickLitener != null)
{
@ -167,8 +280,8 @@ public class activity_cates extends Activity_base {
return mDatas.size();
}
public void addData(int position) {
mDatas.add(position, "Insert One");
notifyItemInserted(position);
// mDatas.add(position, "Insert One");
// notifyItemInserted(position);
}
public void removeData(int position) {
@ -181,6 +294,8 @@ public class activity_cates extends Activity_base {
TextView tvTitle;
@BindView(R.id.tvCateNums)
TextView tvNum;
@BindView(R.id.imageViewCate)
ImageView imageView;
public MyViewHolder(View view)
{

View File

@ -11,6 +11,7 @@ import com.novelbook.android.BookActivity;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netutils.NetUtil;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.MyImageLoader;
import com.novelbook.android.utils.OnItemClickListener;
@ -21,7 +22,7 @@ public class BookListAdapter extends RecyclerView.Adapter< MyViewHolder> {
private final int EMPTY_VIEW = 1;
private final int PROGRESS_VIEW = 2;
private final int IMAGE_VIEW = 3;
private MyImageLoader loader = new MyImageLoader();
// private MyImageLoader loader = new MyImageLoader();
private Context context;
private List<Novel> mDatas ;
private OnItemClickListener mOnItemClickListener;
@ -89,8 +90,7 @@ public class BookListAdapter extends RecyclerView.Adapter< MyViewHolder> {
if (holder.tvCate != null) holder.tvCate.setText(mDatas.get(position).getNovelType());
if (holder.tvDesc != null) holder.tvDesc.setText(mDatas.get(position).getDesc());
if (holder.imageView != null && !TextUtils.isEmpty(mDatas.get(position).getCover())) {
loader.displayImage(context,NetUtil.getCoverUrl(mDatas.get(position).getCover()) ,holder.imageView);
ImageUtil.loadImage( context, mDatas.get(position).getCover() ,holder. imageView);
}
if(holder.tvNum!=null)holder.tvNum.setText("999");
// 如果设置了回调则设置点击事件

View File

@ -0,0 +1,34 @@
package com.novelbook.android.bean;
import com.novelbook.android.db.Novel;
public class Cataloge
{
private String name;
private int novelCount;
private Novel novel;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNovelCount() {
return novelCount;
}
public void setNovelCount(int novelCount) {
this.novelCount = novelCount;
}
public Novel getNovel() {
return novel;
}
public void setNovel(Novel novel) {
this.novel = novel;
}
}

View File

@ -0,0 +1,48 @@
package com.novelbook.android.bean;
import com.novelbook.android.db.Novel;
import java.util.List;
public class NovelBlock{
private String name;
private String icon;
private List<String> pictures;
private List<Novel> ns;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public List<String> getPictures() {
return pictures;
}
public void setPictures(List<String> pictures) {
this.pictures = pictures;
}
public List<Novel> getNs() {
return ns;
}
public void setNs(List<Novel> ns) {
this.ns = ns;
}
}

View File

@ -10,6 +10,7 @@ import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;
@ -49,8 +50,20 @@ public interface HttpApi {
@GET("s/{siteDomain}.json")
Observable<ResponseBody> getNovelRule(@Path("siteDomain") String siteDomain);
@GET("/page/index")
@GET("page/index")
Observable<ResponseBody> getFirstPage();
//分类的总榜显示每个小说分类有多少本书
@GET("page/noveltype")
Observable<ResponseBody> getCates(@Query("sex") int sex);
// sex1 2 progress:1, 连载中2已完本3. 新书 http://xiaoshuofenxiang.com/api/search/nt/言情/2?sex=2&progress=1
//@GET("search/nt/{cate}/{pageno}?sex={sex}&progress={progress} ")
// Observable<ResponseBody> search(@Query("cate") String cate, @Query("pageno") int pageno, @Query("sex") int sex, @Query("progress") int progress);
@GET("search/nt/{cate}/{pageno}")
Observable<ResponseBody> getCateNovels(@Path("cate") String cate, @Path("pageno") int pageno, @Query("sex") int sex, @Query("progress") int progress);
}

View File

@ -35,6 +35,12 @@ public class BookSubscribe {
Observable<ResponseBody> observable = HttpMethods.getInstance().getHttpApi().getFirstPage();
HttpMethods.getInstance().toSubscribe(observable, subscriber);
}
public static void getCates(int sex,DisposableObserver<ResponseBody> subscriber){
Observable<ResponseBody> observable = HttpMethods.getInstance().getHttpApi().getCates(sex);
HttpMethods.getInstance().toSubscribe(observable, subscriber);
}
public static void getCateNovelList(String cate,int pageno,int sex,int progress,DisposableObserver<ResponseBody> subscriber){
Observable<ResponseBody> observable = HttpMethods.getInstance().getHttpApi().getCateNovels(cate,pageno,sex,progress);
HttpMethods.getInstance().toSubscribe(observable, subscriber);
}
}

View File

@ -252,7 +252,11 @@ public class HttpMethods {
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
} else {
return originalResponse;
return originalResponse.newBuilder()
.removeHeader("Pragma")
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
// return originalResponse;
}
}
};

View File

@ -0,0 +1,6 @@
package com.novelbook.android.utils;
public class Constants {
public static int SEX=1;
}

View File

@ -0,0 +1,16 @@
package com.novelbook.android.utils;
import android.content.Context;
import android.util.Log;
import android.widget.ImageView;
import com.novelbook.android.netutils.NetUtil;
public class ImageUtil {
public static String TAG= ImageUtil.class.getSimpleName();
public static MyImageLoader loader = new MyImageLoader();
public static void loadImage(Context context, String url, ImageView imageView){
loader.displayImage(context, NetUtil.getCoverUrl(url), imageView);
Log.d(TAG,"loading image url: " + NetUtil.getCoverUrl(url));
}
}

View File

@ -58,7 +58,7 @@
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="20dp"
android:orientation="horizontal">

View File

@ -25,7 +25,20 @@
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolBarTheme.PopupOverlay" >
<TextView
android:id="@+id/toolbarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:text="我是标题"
android:textSize="20sp"
android:layout_weight="1"
android:visibility="visible"
android:textColor="@color/white"
android:background="@color/colorAccent"
/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/sexSelect"
android:layout_width="wrap_content"
@ -39,17 +52,7 @@
android:layout_weight="0"
android:visibility="gone"
/>
<TextView
android:id="@+id/toolbarTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="我是标题"
android:textSize="20sp"
android:layout_weight="1"
android:visibility="gone"
/>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".Fragments.BlankFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

View File

@ -64,6 +64,7 @@
<Button
android:id="@+id/buttonMoreTuijian"
style="@style/buttonRightMore"
android:visibility="gone"
android:text="更多>"
/>
@ -109,12 +110,14 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/imageBlock1"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/googleg_standard_color_18"
android:layout_gravity="left"
/>
<TextView
android:id="@+id/tvBlock1"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="left"
@ -124,7 +127,7 @@
android:textColor="#212121" />
<Button
android:id="@+id/buttonMoreHot"
android:id="@+id/buttonMore1"
style="@style/buttonRightMore"
android:text="更多>"
@ -165,12 +168,14 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/imageBlock2"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/googleg_standard_color_18"
android:layout_gravity="left"
/>
<TextView
android:id="@+id/tvBlock2"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="left"
@ -180,7 +185,7 @@
android:textColor="#212121" />
<Button
android:id="@+id/buttonMoreLianzai"
android:id="@+id/buttonMore2"
style="@style/buttonRightMore"
android:text="更多>"
@ -221,12 +226,14 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/imageBlock3"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/googleg_standard_color_18"
android:layout_gravity="left"
/>
<TextView
android:id="@+id/tvBlock3"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="left"
@ -236,7 +243,7 @@
android:textColor="#212121" />
<Button
android:id="@+id/buttonMoreWanben"
android:id="@+id/buttonMore3"
style="@style/buttonRightMore"
android:text="更多>"

View File

@ -6,20 +6,34 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cardView"
android:layout_marginRight="10dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="2dp"
android:layout_marginLeft="2dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
app:cardCornerRadius="6dp"
app:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:orientation="vertical"
android:background="@drawable/item_selector"
>
<ImageView
android:layout_weight="0"
android:padding="2dp"
android:id="@+id/imageViewCate"
android:layout_width="100dp"
android:layout_height="120dp"
android:scaleType="fitCenter"
android:src="@drawable/googleg_standard_color_18"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -43,15 +57,6 @@
</LinearLayout>
<ImageView
android:layout_weight="0"
android:padding="2dp"
android:id="@+id/iv_goods"
android:layout_width="70dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/googleg_standard_color_18"
tools:ignore="ContentDescription" />

View File

@ -24,14 +24,33 @@
<TextView
android:id="@+id/title"
style="@style/TextViewNovelTitle"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="left"
android:text="射雕英雄传"
android:textColor="#212121" />
/>
<LinearLayout
android:layout_marginTop="2dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/author"
style="@style/TextViewNovelAuthor"
android:text="金庸"
/>
<TextView
style="@style/TextViewNovelType"
android:id="@+id/category"
android:text="武侠小说"
/>
</LinearLayout>
<TextView
android:id="@+id/desc"
android:layout_marginTop="5dp"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
@ -39,28 +58,7 @@
android:maxLines="2"
android:text=" "
android:textColor="@color/common_google_signin_btn_text_light" />
<LinearLayout
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="金庸"
android:textColor="#212121" />
<TextView
android:id="@+id/category"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="武侠小说"
android:textColor="@color/colorAccent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -1,5 +1,5 @@
<resources>
<string name="app_name">zhuike</string>
<string name="app_name">未知</string>
<string name="title_home">书架</string>
<string name="title_dashboard">书城</string>
<string name="title_notifications">排行榜</string>

View File

@ -150,6 +150,7 @@
<item name="android:layout_height">30dp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">#212121</item>
<item name="android:maxLines">1</item>
</style>
@ -252,4 +253,30 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="TextViewNovelTitle">
<item name="android:textColor">#212121</item>
<item name="android:layout_height">25dp</item>
<item name="android:layout_gravity">left</item>
<item name="android:layout_width">wrap_content</item>
</style>
<style name="TextViewNovelAuthor">
<item name="android:textColor">#212121</item>
<item name="android:textSize">12sp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">left</item>
</style>
<style name="TextViewNovelType">
<item name="android:layout_marginLeft">5dp</item>
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textSize">12sp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>