2019-04-02 17:41:53 +08:00
|
|
|
|
package com.novelbook.android;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
2019-04-11 18:05:41 +08:00
|
|
|
|
import android.widget.ImageView;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
2019-04-11 18:05:41 +08:00
|
|
|
|
import com.google.gson.Gson;
|
2019-04-03 16:21:00 +08:00
|
|
|
|
import com.novelbook.android.db.Novel;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import com.novelbook.android.netsubscribe.MovieSubscribe;
|
|
|
|
|
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
|
|
|
|
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
2019-04-11 18:05:41 +08:00
|
|
|
|
import com.novelbook.android.utils.ImageUtil;
|
|
|
|
|
import com.novelbook.android.utils.MyImageLoader;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import com.novelbook.android.utils.OnItemClickListener;
|
|
|
|
|
import com.novelbook.android.adapter.BookListAdapter;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
|
|
|
|
|
public abstract class Activity_base extends AppCompatActivity {
|
|
|
|
|
private ProgressDialog mProgressDialog;
|
|
|
|
|
|
2019-04-11 18:05:41 +08:00
|
|
|
|
protected Gson gson = new Gson();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
@Nullable
|
2019-04-16 23:11:00 +08:00
|
|
|
|
@BindView(R.id.toolbar)
|
|
|
|
|
Toolbar toolbar;
|
|
|
|
|
@Nullable
|
2019-04-02 17:41:53 +08:00
|
|
|
|
@BindView(R.id.recycleViewBookList)
|
|
|
|
|
RecyclerView rvshudan;
|
|
|
|
|
void showBook(String bookName) { //show paihangbang activity
|
|
|
|
|
Intent intent = new Intent(this, BookActivity.class);
|
|
|
|
|
intent.putExtra("BOOKNAME",bookName);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
2019-04-11 18:05:41 +08:00
|
|
|
|
// protected MyImageLoader imgloader = new MyImageLoader();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 初始化布局
|
|
|
|
|
*/
|
|
|
|
|
public abstract int getLayoutRes();
|
|
|
|
|
|
|
|
|
|
protected abstract void initViews();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
setContentView(getLayoutRes());
|
|
|
|
|
ButterKnife.bind(this);
|
|
|
|
|
setupToolbar();
|
|
|
|
|
// 初始化View注入
|
|
|
|
|
setTitle();
|
|
|
|
|
initData();
|
|
|
|
|
initViews();
|
|
|
|
|
}
|
2019-04-16 23:11:00 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
protected void setupToolbar(){
|
|
|
|
|
// Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
|
// setSupportActionBar(toolbar);
|
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
protected abstract void setTitle();
|
|
|
|
|
|
|
|
|
|
protected abstract void initData() ;
|
|
|
|
|
|
2019-04-12 23:02:31 +08:00
|
|
|
|
protected BookListAdapter getBookListAdapter(List<Novel> mDatas,int itemResourceId){
|
|
|
|
|
BookListAdapter mAdapter = new BookListAdapter(this ,mDatas,itemResourceId,new OnItemClickListener()
|
2019-04-02 17:41:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(View view, int position)
|
|
|
|
|
{
|
2019-04-12 23:02:31 +08:00
|
|
|
|
// showBook("射雕" +position);
|
|
|
|
|
showBookDetail(mDatas.get(position));
|
2019-04-02 17:41:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemLongClick(View view, int position)
|
|
|
|
|
{
|
|
|
|
|
// initDialog(position);
|
|
|
|
|
// mAdapter.removeData(position);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void onLinearOutClick(View view, int bookId,int llId) {
|
|
|
|
|
// Toast.makeText(activity, "book "+ bookId + " clicked", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
// showBookDetail( mData.get(bookId));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return mAdapter;
|
|
|
|
|
}
|
2019-04-12 23:02:31 +08:00
|
|
|
|
void showBookDetail(Novel book) {
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-12 23:02:31 +08:00
|
|
|
|
Intent intent = new Intent(this, BookActivity.class);
|
|
|
|
|
intent.putExtra(BookActivity.EXTRA_BOOK,book);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
if(item.getItemId()==android.R.id.home){ //拦截toolbar 返回事件
|
|
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 16:21:00 +08:00
|
|
|
|
protected List<Novel> getFakeData(int max ){
|
|
|
|
|
List<Novel> mDatas = new ArrayList<Novel>();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
for (int i = 0; i <max; i++)
|
|
|
|
|
{
|
2019-04-03 16:21:00 +08:00
|
|
|
|
Novel bk = new Novel();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
bk.setAuthor("金庸");
|
2019-04-05 23:59:31 +08:00
|
|
|
|
bk.setName("射雕英雄传" +(char)i);
|
2019-04-03 16:21:00 +08:00
|
|
|
|
bk.setNovelType("武侠");
|
2019-04-09 22:32:02 +08:00
|
|
|
|
bk.setDesc("南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
2019-04-02 17:41:53 +08:00
|
|
|
|
mDatas.add(bk);
|
|
|
|
|
}
|
|
|
|
|
return mDatas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
@BindView(R.id.title)
|
|
|
|
|
TextView tvTitle;
|
|
|
|
|
@BindView(R.id.author)
|
|
|
|
|
TextView tvAuthor;
|
|
|
|
|
@BindView(R.id.category)
|
|
|
|
|
TextView tvCate;
|
|
|
|
|
@BindView(R.id.desc)
|
|
|
|
|
TextView tvDesc;
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
@BindView(R.id.btnItemDelete)
|
|
|
|
|
Button btnDelete;
|
|
|
|
|
|
|
|
|
|
public MyViewHolder(View view) {
|
|
|
|
|
super(view);
|
|
|
|
|
ButterKnife.bind(this, view);
|
|
|
|
|
//tvTitle = (TextView) view.findViewById(R.id.title);
|
|
|
|
|
// tvAuthor = (TextView) view.findViewById(R.id.author);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-11 18:05:41 +08:00
|
|
|
|
public void showProgressDialog(boolean flag, String message) {
|
2019-04-02 17:41:53 +08:00
|
|
|
|
if (mProgressDialog == null) {
|
|
|
|
|
mProgressDialog = new ProgressDialog(this);
|
|
|
|
|
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
|
|
mProgressDialog.setCancelable(flag);
|
|
|
|
|
mProgressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
|
mProgressDialog.setMessage(message);
|
|
|
|
|
}
|
|
|
|
|
mProgressDialog.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void hideProgress() {
|
|
|
|
|
if (mProgressDialog == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (mProgressDialog.isShowing()) {
|
|
|
|
|
mProgressDialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否拥有权限
|
|
|
|
|
* @param thisActivity
|
|
|
|
|
* @param permission
|
|
|
|
|
* @param requestCode
|
|
|
|
|
* @param errorText
|
|
|
|
|
*/
|
|
|
|
|
protected void checkPermission (Activity thisActivity, String permission, int requestCode, String errorText) {
|
|
|
|
|
//判断当前Activity是否已经获得了该权限
|
|
|
|
|
if(ContextCompat.checkSelfPermission(thisActivity,permission) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
//如果App的权限申请曾经被用户拒绝过,就需要在这里跟用户做出解释
|
|
|
|
|
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
|
|
|
|
|
permission)) {
|
|
|
|
|
Toast.makeText(this,errorText,Toast.LENGTH_SHORT).show();
|
|
|
|
|
//进行权限请求
|
|
|
|
|
ActivityCompat.requestPermissions(thisActivity,
|
|
|
|
|
new String[]{permission},
|
|
|
|
|
requestCode);
|
|
|
|
|
} else {
|
|
|
|
|
//进行权限请求
|
|
|
|
|
ActivityCompat.requestPermissions(thisActivity,
|
|
|
|
|
new String[]{permission},
|
|
|
|
|
requestCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 18:05:41 +08:00
|
|
|
|
protected void loadImageView(String url, ImageView imageView){
|
|
|
|
|
ImageUtil.loadImage( this, url , imageView);
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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 Context context;
|
|
|
|
|
private List<String> mDatas = new ArrayList<String>();
|
|
|
|
|
private OnItemClickListener mOnItemClickListener;
|
|
|
|
|
private int listItemID;
|
|
|
|
|
|
|
|
|
|
public BookListAdapter(Context context, List<String> mDatas, int listItemID, OnItemClickListener clicklistener) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.mDatas = mDatas;
|
|
|
|
|
this.mOnItemClickListener = clicklistener;
|
|
|
|
|
this.listItemID = listItemID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BookListAdapter(Context context, OnItemClickListener clickLitener) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.mOnItemClickListener = clickLitener;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
|
if (mDatas.size() == 0) {
|
|
|
|
|
return EMPTY_VIEW;
|
|
|
|
|
} else if (mDatas.get(position) == null) {
|
|
|
|
|
return PROGRESS_VIEW;
|
|
|
|
|
} else {
|
|
|
|
|
return super.getItemViewType(position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
|
|
|
|
|
context).inflate(listItemID, parent,
|
|
|
|
|
false));
|
|
|
|
|
return holder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setParameters(List<String> mDatas, int listItemID) {
|
|
|
|
|
this.mDatas = mDatas;
|
|
|
|
|
this.listItemID = listItemID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setOnItemClickLitener(OnItemClickListener mOnItemClickListener) {
|
|
|
|
|
this.mOnItemClickListener = mOnItemClickListener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(MyViewHolder holder, int position) {
|
|
|
|
|
|
|
|
|
|
holder.tvTitle.setText(mDatas.get(position));
|
|
|
|
|
holder.tvAuthor.setText("金庸" + position);
|
|
|
|
|
holder.tvCate.setText("cate" + position);
|
|
|
|
|
holder.tvDesc.setText("this is desc " + position);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果设置了回调,则设置点击事件
|
|
|
|
|
if (mOnItemClickListener != null) {
|
|
|
|
|
holder.itemView.setOnClickListener(new View.OnClickListener() //show more cate paihang
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
int pos = holder.getLayoutPosition();
|
|
|
|
|
mOnItemClickListener.onItemClick(holder.itemView, pos);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
int pos = holder.getLayoutPosition();
|
|
|
|
|
mOnItemClickListener.onItemLongClick(holder.itemView, pos);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return mDatas.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addData(int position) {
|
|
|
|
|
mDatas.add(position, "Insert One");
|
|
|
|
|
notifyItemInserted(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeData(int position) {
|
|
|
|
|
mDatas.remove(position);
|
|
|
|
|
notifyItemRemoved(position);
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}
|