2019-04-02 17:41:53 +08:00
|
|
|
package com.novelbook.android;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Intent;
|
2019-04-21 10:57:20 +08:00
|
|
|
import android.content.pm.ActivityInfo;
|
2019-04-02 17:41:53 +08:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Bundle;
|
2019-04-21 10:57:20 +08:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Message;
|
2019-04-02 17:41:53 +08:00
|
|
|
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;
|
2019-05-13 00:18:07 +08:00
|
|
|
import com.novelbook.android.netutils.NetUtil;
|
2019-04-02 17:41:53 +08:00
|
|
|
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
|
|
|
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
2019-05-11 23:21:57 +08:00
|
|
|
import com.novelbook.android.upgrade.UpdateManager;
|
2019-05-25 23:57:12 +08:00
|
|
|
import com.novelbook.android.utils.CommonUtil;
|
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;
|
2019-05-11 23:21:57 +08:00
|
|
|
import com.umeng.analytics.MobclickAgent;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
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);
|
2019-04-21 10:57:20 +08:00
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
2019-04-02 17:41:53 +08:00
|
|
|
setContentView(getLayoutRes());
|
|
|
|
ButterKnife.bind(this);
|
|
|
|
setupToolbar();
|
|
|
|
// 初始化View注入
|
|
|
|
setTitle();
|
|
|
|
initData();
|
|
|
|
initViews();
|
2019-05-11 23:21:57 +08:00
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
}
|
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-20 00:26:49 +08:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2019-05-11 23:21:57 +08:00
|
|
|
// MobclickAgent.onResume(this);
|
2019-04-20 00:26:49 +08:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected void onPause(){
|
|
|
|
super.onPause();
|
|
|
|
hideProgress();
|
2019-05-11 23:21:57 +08:00
|
|
|
// MobclickAgent.onPause(this);
|
2019-04-20 00:26:49 +08:00
|
|
|
}
|
2019-05-18 23:02:33 +08:00
|
|
|
protected void closeCurrentActitivty(){
|
|
|
|
if( this instanceof BookActivity ) {
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
finish();
|
|
|
|
}
|
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-18 17:19:42 +08:00
|
|
|
|
2019-04-12 23:02:31 +08:00
|
|
|
// showBook("射雕" +position);
|
|
|
|
showBookDetail(mDatas.get(position));
|
2019-05-18 23:02:33 +08:00
|
|
|
closeCurrentActitivty();
|
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;
|
|
|
|
}
|
|
|
|
|
2019-04-21 10:57:20 +08:00
|
|
|
public abstract void fillData();
|
|
|
|
|
|
|
|
Handler handler = new Handler() {
|
|
|
|
@Override
|
|
|
|
public void handleMessage(Message msg) {
|
|
|
|
|
|
|
|
int wt = msg.what;
|
|
|
|
|
|
|
|
if (msg.what == 1) {
|
|
|
|
fillData();
|
|
|
|
} else if (msg.what == 2) //
|
|
|
|
{
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
2019-04-21 10:57:20 +08:00
|
|
|
Toast.makeText(Activity_base.this, " 请求失败", Toast.LENGTH_LONG).show();
|
|
|
|
} else if (msg.what == 3) {
|
|
|
|
|
|
|
|
Toast.makeText(Activity_base.this, " ", Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hideProgress();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2019-04-02 17:41:53 +08:00
|
|
|
|
2019-04-20 00:26:49 +08:00
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
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);
|
2019-05-24 00:33:30 +08:00
|
|
|
mProgressDialog.setCancelable(true);
|
2019-04-02 17:41:53 +08:00
|
|
|
mProgressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
mProgressDialog.setMessage(message);
|
|
|
|
}
|
2019-05-13 00:18:07 +08:00
|
|
|
if(NetUtil.isNetworkConnected())
|
2019-04-02 17:41:53 +08:00
|
|
|
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) {
|
2019-05-25 23:57:12 +08:00
|
|
|
CommonUtil.checkPermission(thisActivity,permission,requestCode,errorText);
|
2019-04-02 17:41:53 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-05-11 23:21:57 +08:00
|
|
|
public void checkUpdate(boolean isSilence){
|
|
|
|
UpdateManager manager = new UpdateManager(this);
|
|
|
|
if(isSilence)
|
|
|
|
manager.checkUpdateSilence();
|
|
|
|
else
|
|
|
|
manager.checkUpdate();
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|