package com.rdc.bms.mvp.activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.rdc.bms.base.BaseActivity;
import com.rdc.bms.base.BasePresenter;
import com.rdc.bms.bookmanagementsystem.R;
import com.rdc.bms.config.Constants;
import com.rdc.bms.dto.SearchBookDTO;
import com.rdc.bms.dto.SimpleDTO;
import com.rdc.bms.entity.Book;
import com.rdc.bms.mvp.fragment.BookManageFragment;
import com.rdc.bms.util.GsonUtil;
import com.rdc.bms.util.ImageUtil;
import com.rdc.bms.util.OkHttpResultCallback;
import com.rdc.bms.util.OkHttpUtil;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import okhttp3.Call;
import static com.rdc.bms.config.Constants.SHOW_PICTURE;
public class BookManageActivity extends BaseActivity {
@BindView(R.id.tv_title_layout_top)
TextView mTvTitle;
@BindView(R.id.iv_back_layout_top)
ImageView mIvBack;
@BindView(R.id.iv_option2_layout_top)
ImageView mIvAddBook;
@BindView(R.id.tv_cancel_layout_search)
TextView mTvCancel;
@BindView(R.id.et_search_layout_search)
EditText mEtSearch;
@BindView(R.id.iv_delete_layout_search)
ImageView mIvDelete;
@BindView(R.id.iv_option1_layout_top)
ImageView mIvShowAll;
private BookManageFragment mBookManageFragment;
private int mAllBookPage = -1;//显示全部书籍的Page
private AlertDialog mBookDialog;
public static final int ADD_BOOK_OPTION = 0;
public static final int UPDATE_BOOK_OPTION = 1;
private ImageView mIvCover;
private String mImagePath;
private boolean mIsChooseImage = false;
private int mType = 0;
private int mPage = 0;
private boolean isShowALL = true;
private String mOldKey = "";
private int mOldType = mType;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected int setLayoutResID() {
return R.layout.activity_book_manage;
}
@Override
protected BasePresenter getInstance() {
return null;
}
@Override
protected void initData(Bundle savedInstanceState) {
mBookManageFragment = BookManageFragment.newInstance();
}
@Override
protected void initView() {
mTvCancel.setText("书籍名");
mTvTitle.setText("书籍管理");
mIvShowAll.setImageResource(R.drawable.iv_show_all);
mIvShowAll.setVisibility(View.VISIBLE);
mIvAddBook.setVisibility(View.VISIBLE);
mIvAddBook.setImageResource(R.drawable.iv_plus);
mIvBack.setVisibility(View.VISIBLE);
mEtSearch.setHint("按书籍名搜索");
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.container_act_book_manage, mBookManageFragment);
transaction.commitNow();
}
@Override
protected void initToolbar() {
}
@Override
protected void initListener() {
mTvCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSelectDialog();
}
});
mIvShowAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mEtSearch.setText("");
mPage = 0;
mAllBookPage = -1;
isShowALL = true;
mBookManageFragment.setCanShowLoadMore(true);
searchAllBook();
Toast.makeText(BookManageActivity.this, "显示全部书籍!", Toast.LENGTH_SHORT).show();
}
});
mIvAddBook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAddBookDialog(ADD_BOOK_OPTION,null);
}
});
mIvBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
mIvDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mEtSearch.setText("");
}
});
mEtSearch.addTextChangedListener(new TextWatcher() {
// boolean isHidedList = false;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty(s)){
mIvDelete.setVisibility(View.INVISIBLE);
}else {
mIvDelete.setVisibility(View.VISIBLE);
}
}
});
mEtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event){
if (actionId == EditorInfo.IME_ACTION_SEND
|| actionId == EditorInfo.IME_ACTION_DONE
|| (event != null
&& KeyEvent.KEYCODE_ENTER == event.getKeyCode()
&& KeyEvent.ACTION_DOWN == event.getAction())) {
isShowALL = false;
String key = getString(mEtSearch);
if (!TextUtils.isEmpty(key)){
if (mOldKey.equals(key) && mOldType == mType){
mPage++;
}else {
mPage = 0;
mBookManageFragment.setCanShowLoadMore(true);
}
searchBook(key,mType,mPage);
mOldKey = key;
mOldType = mType;
}else {
Toast.makeText(BookManageActivity.this, "关键字不能为空!", Toast.LENGTH_SHORT).show();
}
}
return true;
}
});
}
public void onLoadMore(){
if (isShowALL){
searchAllBook();
}else {
mPage++;
searchBook(mOldKey,mOldType,mPage);
}
}
/**
* 选择搜索关键字的类型的Dialog
*/
private void showSelectDialog(){
String[] items = {"书籍名","书籍ID","作者"};
AlertDialog.Builder builder =
new AlertDialog.Builder(this)
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case 0:
- 1
- 2
- 3
- 4
- 5
- 6
前往页