1
This commit is contained in:
@@ -126,6 +126,7 @@ public abstract class BaseActivity<VDB extends ViewDataBinding> extends RxAppCom
|
||||
View mActionBarView;
|
||||
mActionBarView = mactionBarBinding.getRoot();
|
||||
ActionBar actionBar = this.getSupportActionBar();
|
||||
if (actionBar==null)return mactionBarBinding.getRoot();
|
||||
if (MyPhoneValue.getSDKVersion()[0] > 4) {
|
||||
actionBar.setElevation(0);
|
||||
}
|
||||
@@ -173,9 +174,9 @@ public abstract class BaseActivity<VDB extends ViewDataBinding> extends RxAppCom
|
||||
|
||||
public void fullScreen(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Window window = activity.getWindow();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
//5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色
|
||||
Window window = activity.getWindow();
|
||||
View decorView = window.getDecorView();
|
||||
//两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
|
||||
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
@@ -186,7 +187,6 @@ public abstract class BaseActivity<VDB extends ViewDataBinding> extends RxAppCom
|
||||
//导航栏颜色也可以正常设置
|
||||
// window.setNavigationBarColor(Color.TRANSPARENT);
|
||||
} else {
|
||||
Window window = activity.getWindow();
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
|
||||
int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
|
||||
|
||||
@@ -8,14 +8,14 @@ import android.support.v4.app.Fragment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.cutil.SizeUtils;
|
||||
import com.cutil.StringUtils;
|
||||
import com.cutil.Utils;
|
||||
import com.sl.house_property.cart.AddressListActivity;
|
||||
import com.sl.house_property.databinding.FragmentMain4Binding;
|
||||
import com.sl.house_property.f1.UserdlistActivity;
|
||||
import com.sl.house_property.user.MyAuthorizedFamilyHistory;
|
||||
import com.sl.house_property.user.MyBillHistory;
|
||||
@@ -26,8 +26,6 @@ import com.sl.house_property.user.MyPropertyActivity;
|
||||
import com.sl.house_property.user.MyServiceHistory;
|
||||
import com.sl.house_property.user.MyUserMessage;
|
||||
import com.sl.house_property.user.MyWalletActivity;
|
||||
import com.sl.house_property.databinding.FragmentMain4Binding;
|
||||
import com.sl.house_property.databinding.UserFragmentItemBinding;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.io.File;
|
||||
@@ -36,7 +34,6 @@ import java.util.ArrayList;
|
||||
import adapter.BaseRecycleViewAdapter;
|
||||
import entity.MyUserFEntity;
|
||||
import entity.RegisterUser;
|
||||
import my_view.tao_bao_refresh.FullyGridLayoutManager;
|
||||
import tools.Config;
|
||||
import utils.BitmapTools;
|
||||
|
||||
@@ -49,7 +46,7 @@ import utils.BitmapTools;
|
||||
* Use the {@link Main1Fragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
@@ -59,7 +56,7 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
private int userImgeREQUST=10000;
|
||||
private int userImgeREQUST = 10000;
|
||||
private OnFragmentInteractionListener mListener;
|
||||
private boolean istakepic;
|
||||
private ArrayList<MyUserFEntity> myUserFEntities;
|
||||
@@ -69,14 +66,15 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
public Main4Fragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreateVew(LayoutInflater inflater, Bundle savedInstanceState) {
|
||||
super.onCreateVew(inflater, savedInstanceState);
|
||||
mDataBinding.setting.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent=new Intent(getActivity(),SettingActivity.class);
|
||||
startActivity(intent);
|
||||
Intent intent = new Intent(getActivity(), SettingActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
//mDataBinding.myRecyView;
|
||||
@@ -87,9 +85,9 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
}
|
||||
});
|
||||
initTopView();
|
||||
initMyReycyView();
|
||||
// initMyReycyView();
|
||||
initData();
|
||||
// mDataBinding.usermale;
|
||||
// mDataBinding.usermale;
|
||||
|
||||
|
||||
/* toolbar.set*/
|
||||
@@ -105,7 +103,7 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
}
|
||||
}, 0, null, R.mipmap.head);
|
||||
*/
|
||||
// int height= MyPhoneValue.getStatusBarHeight(getActivity());
|
||||
// int height= MyPhoneValue.getStatusBarHeight(getActivity());
|
||||
|
||||
|
||||
/* mDataBinding.myhistory.setOnClickListener(this);
|
||||
@@ -116,15 +114,15 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* 初始化顶部view
|
||||
* */
|
||||
private void initTopView(){
|
||||
*
|
||||
* 初始化顶部view
|
||||
* */
|
||||
private void initTopView() {
|
||||
DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
View topView = mDataBinding.topView;
|
||||
LinearLayout.LayoutParams topViewLp = (LinearLayout.LayoutParams) topView.getLayoutParams();
|
||||
topViewLp.width = dm.widthPixels;
|
||||
topViewLp.height = topViewLp.width*152/375;
|
||||
topViewLp.height = topViewLp.width * 152 / 375;
|
||||
topView.setLayoutParams(topViewLp);
|
||||
|
||||
View userView = mDataBinding.userLayout;
|
||||
@@ -136,82 +134,131 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
|
||||
userImageView = mDataBinding.userImage;
|
||||
RelativeLayout.LayoutParams userImageLP = (RelativeLayout.LayoutParams) userImageView.getLayoutParams();
|
||||
int userImageHeight = (int) ( userViewLp.height*0.7);
|
||||
int userImageHeight = (int) (userViewLp.height * 0.7);
|
||||
userImageLP.height = userImageHeight;
|
||||
userImageLP.width = userImageHeight;
|
||||
userImageView.setLayoutParams(userImageLP);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initMyReycyView() {
|
||||
myUserFEntities=getMyActivityList();
|
||||
|
||||
FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(),1);
|
||||
mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
||||
mgr.setSmoothScrollbarEnabled(true);
|
||||
mDataBinding.myRecyView.setLayoutManager(mgr);
|
||||
|
||||
baseRecycleViewAdapter=new BaseRecycleViewAdapter(getActivity(),R.layout.user_fragment_item);
|
||||
|
||||
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||||
mDataBinding.llQianbao.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onBindViewHolder(Object b, final int position) {
|
||||
if(!(position>=myUserFEntities.size())) {
|
||||
UserFragmentItemBinding homeGridAdapterItemBinding = (UserFragmentItemBinding) b;
|
||||
homeGridAdapterItemBinding.setMyentity(myUserFEntities.get(position));
|
||||
homeGridAdapterItemBinding.imageViewlogo.setImageResource(myUserFEntities.get(position).getImagetResource());homeGridAdapterItemBinding.userFragmentItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getActivity(), myUserFEntities.get(position).getMyclazz());
|
||||
intent.putExtra("usertitile", myUserFEntities.get(position).getTitile());
|
||||
startActivityForResult(intent,0);
|
||||
}
|
||||
});
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), MyWalletActivity.class);
|
||||
intent.putExtra("usertitile", "我的钱包");
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
});
|
||||
mDataBinding.llShouquan.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(),MyAuthorizedFamilyHistory.class);
|
||||
intent.putExtra("usertitile", "授权家庭");
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
});
|
||||
mDataBinding.llFangchan.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), MyPropertyActivity.class);
|
||||
intent.putExtra("usertitile", "我的房产");
|
||||
startActivityForResult(intent, 0);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
mDataBinding.llYaoshi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), MyKeyManagement.class);
|
||||
intent.putExtra("usertitile", "钥匙管理");
|
||||
startActivityForResult(intent, 0);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mDataBinding.myRecyView.setAdapter(baseRecycleViewAdapter);
|
||||
baseRecycleViewAdapter.setData(myUserFEntities);
|
||||
mDataBinding.llGeren.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), MyUserMessage.class);
|
||||
intent.putExtra("usertitile", "个人信息");
|
||||
startActivityForResult(intent, 0);
|
||||
|
||||
}
|
||||
});
|
||||
mDataBinding.llShouhuo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), AddressListActivity.class);
|
||||
intent.putExtra("usertitile", "收货地址");
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void refreshData(){
|
||||
// private void initMyReycyView() {
|
||||
// myUserFEntities=getMyActivityList();
|
||||
//
|
||||
// FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(),1);
|
||||
// mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
||||
// mgr.setSmoothScrollbarEnabled(true);
|
||||
// mDataBinding.myRecyView.setLayoutManager(mgr);
|
||||
//
|
||||
// baseRecycleViewAdapter=new BaseRecycleViewAdapter(getActivity(),R.layout.user_fragment_item);
|
||||
//
|
||||
// baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||||
// @Override
|
||||
// public void onBindViewHolder(Object b, final int position) {
|
||||
// if(!(position>=myUserFEntities.size())) {
|
||||
// UserFragmentItemBinding homeGridAdapterItemBinding = (UserFragmentItemBinding) b;
|
||||
// homeGridAdapterItemBinding.setMyentity(myUserFEntities.get(position));
|
||||
// homeGridAdapterItemBinding.imageViewlogo.setImageResource(myUserFEntities.get(position).getImagetResource());homeGridAdapterItemBinding.userFragmentItem.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// Intent intent = new Intent(getActivity(), myUserFEntities.get(position).getMyclazz());
|
||||
// intent.putExtra("usertitile", myUserFEntities.get(position).getTitile());
|
||||
// startActivityForResult(intent,0);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// mDataBinding.myRecyView.setAdapter(baseRecycleViewAdapter);
|
||||
// baseRecycleViewAdapter.setData(myUserFEntities);
|
||||
//
|
||||
// }
|
||||
|
||||
public void refreshData() {
|
||||
initTopView();
|
||||
initMyReycyView();
|
||||
// initMyReycyView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/*
|
||||
* 初始化数据
|
||||
* */
|
||||
private void initData(){
|
||||
RegisterUser user = Config.getInstance(getActivity()).getUser();
|
||||
* 初始化数据
|
||||
* */
|
||||
private void initData() {
|
||||
RegisterUser user = Config.getInstance(getActivity()).getUser();
|
||||
mDataBinding.username.setText(user.getNickname());
|
||||
if(StringUtils.isEmpty(user.getAvatar())){
|
||||
if (StringUtils.isEmpty(user.getAvatar())) {
|
||||
Picasso.with(getActivity()).load(R.mipmap.head).error(R.mipmap.head).placeholder(R.mipmap.head).into(mDataBinding.userImage);
|
||||
}else {
|
||||
} else {
|
||||
Picasso.with(getActivity()).load(user.getAvatar()).error(R.mipmap.head).placeholder(R.mipmap.head).into(mDataBinding.userImage);
|
||||
|
||||
}
|
||||
String gender = user.getGender();
|
||||
if(gender.equals("0")){
|
||||
if (gender.equals("0")) {
|
||||
Picasso.with(getActivity()).load(R.mipmap.icon_secret).into(mDataBinding.usermale);
|
||||
}else if(gender.equals("1")){
|
||||
} else if (gender.equals("1")) {
|
||||
Picasso.with(getActivity()).load(R.mipmap.boy).into(mDataBinding.usermale);
|
||||
}else if(gender.equals("2")){
|
||||
} else if (gender.equals("2")) {
|
||||
Picasso.with(getActivity()).load(R.mipmap.lady).into(mDataBinding.usermale);
|
||||
}else {
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
@@ -230,11 +277,12 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private boolean onclik=false;
|
||||
private boolean onclik = false;
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
onclik=false;
|
||||
onclik = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -248,7 +296,7 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
BaseActivity baseActivity= (BaseActivity) getActivity();
|
||||
baseActivity.setSupportActionBar(toolbar);*/
|
||||
|
||||
/* toolbar.set*/
|
||||
/* toolbar.set*/
|
||||
/* baseActivity.setAbr(getString(R.string.news4), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -302,7 +350,7 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
|
||||
@Override
|
||||
protected void loadData() {
|
||||
initData();
|
||||
initData();
|
||||
}
|
||||
|
||||
|
||||
@@ -310,16 +358,15 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
onclik=true;
|
||||
|
||||
onclik = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<MyUserFEntity> getMyActivityList() {
|
||||
ArrayList<MyUserFEntity> myUserFEntities=new ArrayList<>();
|
||||
String myActivityListString[]=getActivity().getResources().getStringArray(R.array.useraction);
|
||||
int imageres[]={R.mipmap.genren,
|
||||
ArrayList<MyUserFEntity> myUserFEntities = new ArrayList<>();
|
||||
String myActivityListString[] = getActivity().getResources().getStringArray(R.array.useraction);
|
||||
int imageres[] = {R.mipmap.genren,
|
||||
R.mipmap.qianbao,
|
||||
R.mipmap.shangcheng,
|
||||
R.mipmap.zhangdan,
|
||||
@@ -329,7 +376,7 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
R.mipmap.shouquan,
|
||||
R.mipmap.fangchan,
|
||||
R.mipmap.yaoshi};
|
||||
Class tClass[]={MyUserMessage.class,
|
||||
Class tClass[] = {MyUserMessage.class,
|
||||
MyWalletActivity.class,
|
||||
MyMarketShopActivity.class,
|
||||
MyBillHistory.class,
|
||||
@@ -339,8 +386,8 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
MyAuthorizedFamilyHistory.class,
|
||||
MyPropertyActivity.class,
|
||||
MyKeyManagement.class};
|
||||
for (int i = 0; i <9 ; i++) {
|
||||
MyUserFEntity myUserFEntity=new MyUserFEntity();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
MyUserFEntity myUserFEntity = new MyUserFEntity();
|
||||
myUserFEntity.setImagetResource(imageres[i]);
|
||||
myUserFEntity.setMyclazz(tClass[i]);
|
||||
myUserFEntity.setTitile(myActivityListString[i]);
|
||||
@@ -370,8 +417,8 @@ public class Main4Fragment extends BaseFragment<FragmentMain4Binding> {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(deletePath.size()>0){
|
||||
for (int i = 0; i <deletePath.size(); i++) {
|
||||
if (deletePath.size() > 0) {
|
||||
for (int i = 0; i < deletePath.size(); i++) {
|
||||
BitmapTools.deleteFile(new File(deletePath.get(i)));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.sl.house_property.cart.CartFragment;
|
||||
import com.sl.house_property.databinding.ActivityMainTabBinding;
|
||||
import com.sl.house_property.discovery.DiscoveryFragment;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class MainTabActivity extends BaseActivity<ActivityMainTabBinding>
|
||||
private MainFragment fragment0;
|
||||
private DiscoveryFragment fragment1;
|
||||
private Main3Fragment fragment2;
|
||||
private Main2Fragment fragment3;
|
||||
private CartFragment fragment3;
|
||||
private Main4Fragment fragment4;
|
||||
private Fragment currentFragment;
|
||||
|
||||
@@ -174,7 +175,7 @@ public class MainTabActivity extends BaseActivity<ActivityMainTabBinding>
|
||||
case R.id.button3:
|
||||
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
||||
if (fragment3 == null) {
|
||||
fragment3 = Main2Fragment.newInstance("", "");
|
||||
fragment3 = CartFragment.newInstance();
|
||||
fragmentTransaction.add(R.id.mycontent, fragment3, "fragment3");
|
||||
} else {
|
||||
fragmentTransaction.show(fragment3);
|
||||
|
||||
@@ -59,9 +59,9 @@ public class MyApplication extends Application{
|
||||
Log.d(TAG, "[ExampleApplication] onCreate");
|
||||
super.onCreate();
|
||||
instance = this;
|
||||
|
||||
CrashHandler crashHandler = CrashHandler.getInstance();
|
||||
crashHandler.init(this);
|
||||
//
|
||||
// CrashHandler crashHandler = CrashHandler.getInstance();
|
||||
// crashHandler.init(this);
|
||||
System.setProperty("http.proxyHost", "haotian.hoheng.cn");
|
||||
System.setProperty("http.proxyPort", "8080");
|
||||
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
package com.sl.house_property.cart;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.lxj.xpopup.interfaces.OnConfirmListener;
|
||||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
|
||||
import com.sl.house_property.BaseActivity;
|
||||
import com.sl.house_property.R;
|
||||
import com.sl.house_property.databinding.ActivityAddressListBinding;
|
||||
import com.sl.house_property.databinding.ItemAddressBinding;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import adapter.BaseRecycleViewAdapter;
|
||||
import entity.AddressEntity;
|
||||
import entity.RegisterUser;
|
||||
import http.ApiConfig;
|
||||
import my_loader.Loader;
|
||||
import my_loader.Resultcode;
|
||||
import rx.functions.Action1;
|
||||
import tools.Config;
|
||||
import utils.Md5;
|
||||
|
||||
public class AddressListActivity extends BaseActivity<ActivityAddressListBinding> {
|
||||
private int page = 1;
|
||||
private Context context;
|
||||
private ArrayList<AddressEntity> list = new ArrayList<>();
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_address_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
context = this;
|
||||
ImmersionBar.with(this)
|
||||
.keyboardEnable(true) //解决软键盘与底部输入框冲突问题
|
||||
// .keyboardEnable(true, WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
|
||||
// | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) //软键盘自动弹出
|
||||
.init();
|
||||
progressDialog = new ProgressDialog(this);
|
||||
initRec();
|
||||
mDataBinding.dw.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
|
||||
@Override
|
||||
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
||||
getList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||||
page = 1;
|
||||
getList();
|
||||
}
|
||||
});
|
||||
mDataBinding.dw.autoRefresh();
|
||||
|
||||
}
|
||||
|
||||
private void initRec() {
|
||||
BaseRecycleViewAdapter<AddressEntity, ItemAddressBinding> adapter = new BaseRecycleViewAdapter<>(context, R.layout.item_address);
|
||||
adapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView<ItemAddressBinding>() {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ItemAddressBinding b, int position) {
|
||||
final AddressEntity addressEntity = list.get(position);
|
||||
b.tvName.setText(addressEntity.getName());
|
||||
b.tvPhone.setText(addressEntity.getMobile());
|
||||
b.tvDetail.setText(addressEntity.getRegion() + addressEntity.getAddress());
|
||||
if (addressEntity.getIs_default().equals("1")) {
|
||||
b.tvState.setVisibility(View.VISIBLE);
|
||||
b.ivEdit.setVisibility(View.GONE);
|
||||
} else {
|
||||
b.tvState.setVisibility(View.GONE);
|
||||
b.ivEdit.setVisibility(View.VISIBLE);
|
||||
}
|
||||
b.ivEdit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new XPopup.Builder(context).asConfirm("", "真的要设置为默认吗?", new OnConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
|
||||
opera(addressEntity.getConsignee_id(), "1");
|
||||
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
b.ivDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new XPopup.Builder(context).asConfirm("", "真的要删除吗?", new OnConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
|
||||
opera(addressEntity.getConsignee_id(), "2");
|
||||
|
||||
}
|
||||
}).show();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
mDataBinding.rec.setAdapter(adapter);
|
||||
mDataBinding.rec.setLayoutManager(new LinearLayoutManager(context));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
Loader loader = new Loader();
|
||||
|
||||
private void opera(String consignee_id, String action) {
|
||||
progressDialog.setMessage("提交中");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
RegisterUser user =
|
||||
Config.getInstance(context).getUser();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (user != null) {
|
||||
map.put("userid", user.getUserid());
|
||||
} else {
|
||||
map.put("userid", 0 + "");
|
||||
}
|
||||
map.put("app", "Order");
|
||||
map.put("class", "UserAddressAction");
|
||||
map.put("action", action);
|
||||
map.put("consignee_id", consignee_id);
|
||||
map.put("sign", Md5.md5("Order" + "UserAddressAction" + Md5.secret));
|
||||
|
||||
loader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
progressDialog.dismiss();
|
||||
if (!(resultcode.status == 0)) {
|
||||
Toast.makeText(context, resultcode.msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
Toast.makeText(context, resultcode.msg, Toast.LENGTH_SHORT).show();
|
||||
page = 1;
|
||||
getList();
|
||||
}
|
||||
}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
throwable.fillInStackTrace();
|
||||
Toast.makeText(context, "提交失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getList() {
|
||||
RegisterUser user =
|
||||
Config.getInstance(context).getUser();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (user != null) {
|
||||
map.put("userid", user.getUserid());
|
||||
} else {
|
||||
map.put("userid", 0 + "");
|
||||
}
|
||||
map.put("app", "Order");
|
||||
map.put("class", "UserAddressInfo");
|
||||
map.put("page", page + "");
|
||||
map.put("sign", Md5.md5("Order" + "UserAddressInfo" + Md5.secret));
|
||||
|
||||
loader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
mDataBinding.dw.finishRefresh();
|
||||
mDataBinding.dw.finishLoadMore();
|
||||
if (!(resultcode.status == 0)) {
|
||||
Toast.makeText(context, resultcode.msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
Gson gs = new Gson();
|
||||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
org.json.JSONArray array = jsonObject.getJSONArray("info");
|
||||
Type type = new TypeToken<ArrayList<AddressEntity>>() {
|
||||
}.getType();
|
||||
ArrayList<AddressEntity> newList = gs.fromJson(array.toString(), type);
|
||||
int count = jsonObject.getInt("count");
|
||||
|
||||
if (page == 1) {
|
||||
list.clear();
|
||||
}
|
||||
list.addAll(newList);
|
||||
if (list.size() == count || newList.isEmpty()) {
|
||||
mDataBinding.dw.finishLoadMoreWithNoMoreData();
|
||||
} else {
|
||||
page++;
|
||||
}
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.rec.getAdapter();
|
||||
baseRecycleViewAdapter.setData(list);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
mDataBinding.dw.finishRefresh();
|
||||
mDataBinding.dw.finishLoadMore();
|
||||
Toast.makeText(context, getString(R.string.getdatafailure), Toast.LENGTH_SHORT).show();
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
136
app/src/main/java/com/sl/house_property/cart/AmountView.java
Normal file
136
app/src/main/java/com/sl/house_property/cart/AmountView.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package com.sl.house_property.cart;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sl.house_property.R;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义组件:购买数量,带减少增加按钮
|
||||
* Created by hiwhitley on 2016/7/4.
|
||||
*/
|
||||
public class AmountView extends LinearLayout implements View.OnClickListener, TextWatcher {
|
||||
|
||||
private static final String TAG = "AmountView";
|
||||
private int amount = 1; //购买数量
|
||||
private int goods_storage = 100; //商品库存
|
||||
|
||||
private OnAmountChangeListener mListener;
|
||||
|
||||
private TextView etAmount;
|
||||
private ImageView btnDecrease;
|
||||
private ImageView btnIncrease;
|
||||
|
||||
public AmountView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
|
||||
public AmountView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.view_amount, this);
|
||||
etAmount = findViewById(R.id.etAmount);
|
||||
btnDecrease = findViewById(R.id.btnDecrease);
|
||||
btnIncrease = findViewById(R.id.btnIncrease);
|
||||
btnDecrease.setOnClickListener(this);
|
||||
btnIncrease.setOnClickListener(this);
|
||||
etAmount.addTextChangedListener(this);
|
||||
|
||||
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.AmountView);
|
||||
int btnWidth = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_btnWidth, LayoutParams.WRAP_CONTENT);
|
||||
int tvWidth = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_tvWidth, 80);
|
||||
int tvTextSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_tvTextSize, 0);
|
||||
// int btnTextSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_btnTextSize, 0);
|
||||
obtainStyledAttributes.recycle();
|
||||
|
||||
LayoutParams btnParams = new LayoutParams(btnWidth, LayoutParams.MATCH_PARENT);
|
||||
btnDecrease.setLayoutParams(btnParams);
|
||||
btnIncrease.setLayoutParams(btnParams);
|
||||
// if (btnTextSize != 0) {
|
||||
//// 0
|
||||
//// btnIncrease.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnTextSize);
|
||||
// }
|
||||
|
||||
LayoutParams textParams = new LayoutParams(tvWidth, LayoutParams.MATCH_PARENT);
|
||||
etAmount.setLayoutParams(textParams);
|
||||
if (tvTextSize != 0) {
|
||||
etAmount.setTextSize(tvTextSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnAmountChangeListener(OnAmountChangeListener onAmountChangeListener) {
|
||||
this.mListener = onAmountChangeListener;
|
||||
}
|
||||
|
||||
public void setGoods_storage(int goods_storage) {
|
||||
this.goods_storage = goods_storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int i = v.getId();
|
||||
if (i == R.id.btnDecrease) {
|
||||
if (amount > 1) {
|
||||
amount--;
|
||||
etAmount.setText(amount + "");
|
||||
}
|
||||
} else if (i == R.id.btnIncrease) {
|
||||
if (amount < goods_storage) {
|
||||
amount++;
|
||||
etAmount.setText(amount + "");
|
||||
}
|
||||
}
|
||||
|
||||
etAmount.clearFocus();
|
||||
|
||||
if (mListener != null) {
|
||||
mListener.onAmountChange(this, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
public void changeAmount(int num){
|
||||
amount=num;
|
||||
etAmount.setText(num+"");
|
||||
}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (s.toString().isEmpty())
|
||||
return;
|
||||
amount = Integer.valueOf(s.toString());
|
||||
if (amount > goods_storage) {
|
||||
etAmount.setText(goods_storage + "");
|
||||
return;
|
||||
}
|
||||
|
||||
// if (mListener != null) {
|
||||
//// mListener.onAmountChange(this, amount);
|
||||
//// }
|
||||
}
|
||||
|
||||
|
||||
public interface OnAmountChangeListener {
|
||||
void onAmountChange(View view, int amount);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,366 @@
|
||||
package com.sl.house_property.cart;
|
||||
|
||||
public class CartFragment {
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
|
||||
import com.sl.house_property.BaseActivity;
|
||||
import com.sl.house_property.BaseFragment;
|
||||
import com.sl.house_property.R;
|
||||
import com.sl.house_property.databinding.FragmentCartBinding;
|
||||
import com.sl.house_property.databinding.ItemCartBinding;
|
||||
import com.sl.house_property.databinding.ItemCartCartBinding;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import adapter.BaseRecycleViewAdapter;
|
||||
import entity.CartEntity;
|
||||
import entity.RegisterUser;
|
||||
import http.ApiConfig;
|
||||
import my_loader.Loader;
|
||||
import my_loader.Resultcode;
|
||||
import rx.functions.Action1;
|
||||
import tools.Config;
|
||||
import utils.Md5;
|
||||
|
||||
public class CartFragment extends BaseFragment<FragmentCartBinding> {
|
||||
BaseActivity baseActivity;
|
||||
private ProgressDialog progressDialog;
|
||||
//private int page = 1;
|
||||
private Loader loader;
|
||||
private ArrayList<CartEntity> cartEntities;
|
||||
private double amount = 0.00;
|
||||
|
||||
public static CartFragment newInstance() {
|
||||
CartFragment fragment = new CartFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_cart;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadData() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreateVew(LayoutInflater inflater, Bundle savedInstanceState) {
|
||||
super.onCreateVew(inflater, savedInstanceState);
|
||||
baseActivity = (BaseActivity) getActivity();
|
||||
progressDialog = new ProgressDialog(baseActivity);
|
||||
intRecycleView();
|
||||
mDataBinding.dw.setOnRefreshListener(new OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||||
getData();
|
||||
}
|
||||
});
|
||||
mDataBinding.dw.autoRefresh();
|
||||
mDataBinding.tvManager.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!cartEntities.isEmpty()) {
|
||||
for (int i = 0; i < cartEntities.size(); i++) {
|
||||
cartEntities.get(i).setCheck(false);
|
||||
for (int j = 0; j < cartEntities.get(i).getList().size(); j++) {
|
||||
cartEntities.get(i).getList().get(j).setCheck(false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
amount = 0.00;
|
||||
mDataBinding.cbAll.setChecked(false);
|
||||
mDataBinding.rec.getAdapter().notifyDataSetChanged();
|
||||
if (mDataBinding.tvManager.getText().equals("管理")) {
|
||||
mDataBinding.tvManager.setText("完成");
|
||||
mDataBinding.tvAmount.setVisibility(View.GONE);
|
||||
mDataBinding.btnDelete.setVisibility(View.VISIBLE);
|
||||
mDataBinding.btnSettle.setVisibility(View.GONE);
|
||||
mDataBinding.tvT.setVisibility(View.GONE);
|
||||
} else {
|
||||
mDataBinding.tvManager.setText("管理");
|
||||
mDataBinding.tvAmount.setVisibility(View.VISIBLE);
|
||||
mDataBinding.btnDelete.setVisibility(View.GONE);
|
||||
mDataBinding.btnSettle.setVisibility(View.VISIBLE);
|
||||
mDataBinding.tvT.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
mDataBinding.btnDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!cartEntities.isEmpty()) {
|
||||
StringBuilder id = new StringBuilder();
|
||||
for (int i = 0; i < cartEntities.size(); i++) {
|
||||
for (int j = 0; j < cartEntities.get(i).getList().size(); j++) {
|
||||
if (cartEntities.get(i).getList().get(j).isCheck()) {
|
||||
if (id.toString().equals("")) {
|
||||
id = new StringBuilder(cartEntities.get(i).getList().get(j).getCart_id());
|
||||
} else {
|
||||
id.append(",").append(cartEntities.get(i).getList().get(j).getCart_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!id.toString().equals("")) {
|
||||
editGoods(1, id.toString(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getData() {
|
||||
RegisterUser user =
|
||||
Config.getInstance(getContext()).getUser();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (user != null) {
|
||||
map.put("userid", user.getUserid());
|
||||
} else {
|
||||
map.put("userid", 0 + "");
|
||||
}
|
||||
map.put("app", "Goods");
|
||||
map.put("class", "GetCart");
|
||||
// map.put("page", page + "");
|
||||
map.put("sign", Md5.md5("Goods" + "GetCart" + Md5.secret));
|
||||
// progressDialog.setMessage("正在请求数据");
|
||||
//progressDialog.setCancelable(false);
|
||||
loader = new Loader();
|
||||
loader.getMovie(ApiConfig.BASE_URL, map)
|
||||
.subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
mDataBinding.dw.finishRefresh();
|
||||
mDataBinding.dw.finishLoadMore();
|
||||
// progressDialog.dismiss();
|
||||
if (!(resultcode.status == 0)) {
|
||||
baseActivity.setToast(1, resultcode.msg);
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
Gson gs = new Gson();
|
||||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
org.json.JSONArray array = jsonObject.getJSONArray("cart");
|
||||
Type type = new TypeToken<ArrayList<CartEntity>>() {
|
||||
}.getType();
|
||||
|
||||
cartEntities = new Gson().fromJson(array.toString(), type);
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.rec.getAdapter();
|
||||
baseRecycleViewAdapter.setData(cartEntities);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
// progressDialog.dismiss();
|
||||
mDataBinding.dw.finishRefresh();
|
||||
mDataBinding.dw.finishLoadMore();
|
||||
baseActivity.setToast(2, getString(R.string.getdatafailure));
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void intRecycleView() {
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(baseActivity);
|
||||
mDataBinding.rec.setLayoutManager(linearLayoutManager);
|
||||
final BaseRecycleViewAdapter<CartEntity, ItemCartBinding> adapter = new BaseRecycleViewAdapter<>(baseActivity, R.layout.item_cart);
|
||||
|
||||
mDataBinding.rec.setAdapter(adapter);
|
||||
cartEntities = new ArrayList<>();
|
||||
adapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView<ItemCartBinding>() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ItemCartBinding b, final int position) {
|
||||
if (!(position >= cartEntities.size())) {
|
||||
final CartEntity cartEntity = cartEntities.get(position);
|
||||
b.cbCheck.setChecked(cartEntity.isCheck());
|
||||
b.tvUsername.setText(cartEntity.getNickname());
|
||||
RequestOptions requestOptions = new RequestOptions();
|
||||
requestOptions.placeholder(R.mipmap.head);
|
||||
requestOptions.error(R.mipmap.head);
|
||||
Glide.with(getContext()).load(cartEntity.getAvatar())
|
||||
.apply(requestOptions)
|
||||
.into(b.ivHead);
|
||||
b.itemRec.setLayoutManager(new LinearLayoutManager(baseActivity));
|
||||
final BaseRecycleViewAdapter<CartEntity.CartList, ItemCartCartBinding> itemAdapter = new BaseRecycleViewAdapter<>(baseActivity, R.layout.item_cart_cart);
|
||||
itemAdapter.setData(cartEntity.getList());
|
||||
b.itemRec.setAdapter(itemAdapter);
|
||||
b.ll.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
cartEntities.get(position).setCheck(!cartEntities.get(position).isCheck());
|
||||
for (int i = 0; i < cartEntities.get(position).getList().size(); i++) {
|
||||
cartEntities.get(position).getList().get(i).setCheck(cartEntities.get(position).isCheck());
|
||||
|
||||
}
|
||||
boolean isAllCheck = true;
|
||||
for (int i = 0; i < cartEntities.size(); i++) {
|
||||
if (!cartEntities.get(position).isCheck()) {
|
||||
isAllCheck = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
mDataBinding.cbAll.setChecked(isAllCheck);
|
||||
}
|
||||
});
|
||||
itemAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView<ItemCartCartBinding>() {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ItemCartCartBinding b, final int position) {
|
||||
if (!(position >= cartEntity.getList().size())) {
|
||||
b.cb.setChecked(cartEntity.getList().get(position).isCheck());
|
||||
b.tvGoodsName.setText(cartEntity.getList().get(position).getGoods_detail());
|
||||
b.tvInfo2.setText(cartEntity.getList().get(position).getProperty());
|
||||
RequestOptions requestOptions = new RequestOptions();
|
||||
requestOptions.placeholder(R.mipmap.icon_default_rectangle);
|
||||
requestOptions.error(R.mipmap.icon_default_rectangle);
|
||||
|
||||
Glide.with(getContext()).load(cartEntity.getList().get(position).getThumb())
|
||||
.apply(requestOptions)
|
||||
.into(b.ivGoods);
|
||||
b.tvPrice.setText("¥" + cartEntity.getList().get(position).getSale_price());
|
||||
if (!cartEntity.getList().get(position).getSale_num().isEmpty()) {
|
||||
b.amountView.changeAmount(Integer.parseInt(cartEntity.getList().get(position).getSale_num()));
|
||||
|
||||
}
|
||||
b.amountView.setOnAmountChangeListener(new AmountView.OnAmountChangeListener() {
|
||||
@Override
|
||||
public void onAmountChange(View view, int amount) {
|
||||
editGoods(2, cartEntity.getList().get(position).getCart_id(), amount);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
itemAdapter.setOnItemClickListener(new BaseRecycleViewAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(View itemView, int x) {
|
||||
// if (mDataBinding.tvAmount.getVisibility()==View.VISIBLE){
|
||||
// if (!cartEntities.get(position).getList().get(x).isCheck()) {
|
||||
// BigDecimal bigDecimal = new BigDecimal(0.00);
|
||||
// BigDecimal bigDecimal1 = new BigDecimal(amount);
|
||||
// BigDecimal add = bigDecimal.add(bigDecimal1);
|
||||
// amount = add.doubleValue();
|
||||
// mDataBinding.tvAmount.setText(amount+"");
|
||||
// } else {
|
||||
// BigDecimal bigDecimal = new BigDecimal(0.00);
|
||||
// BigDecimal bigDecimal1 = new BigDecimal(amount);
|
||||
// BigDecimal subtract = bigDecimal1.subtract(bigDecimal);
|
||||
// amount = subtract.doubleValue();
|
||||
// mDataBinding.tvAmount.setText(amount+"");
|
||||
// }
|
||||
// }
|
||||
|
||||
cartEntities.get(position).getList().get(x).setCheck(!cartEntities.get(position).getList().get(x).isCheck());
|
||||
|
||||
itemAdapter.notifyDataSetChanged();
|
||||
boolean isItemAllCheck = true;
|
||||
boolean isAllCheck = true;
|
||||
for (int i = 0; i < cartEntities.get(position).getList().size(); i++) {
|
||||
if (!cartEntities.get(position).getList().get(i).isCheck()) {
|
||||
isItemAllCheck = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cartEntities.get(position).setCheck(isItemAllCheck);
|
||||
adapter.notifyDataSetChanged();
|
||||
if (isItemAllCheck) {
|
||||
for (int i = 0; i < cartEntities.size(); i++) {
|
||||
if (!cartEntities.get(i).isCheck()) {
|
||||
isAllCheck = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isAllCheck = false;
|
||||
}
|
||||
mDataBinding.cbAll.setChecked(isAllCheck);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void editGoods(final int action, String cart_id, int num) {
|
||||
progressDialog.setMessage("提交中...");
|
||||
progressDialog.show();
|
||||
RegisterUser user =
|
||||
Config.getInstance(getContext()).getUser();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (user != null) {
|
||||
map.put("userid", user.getUserid());
|
||||
} else {
|
||||
map.put("userid", 0 + "");
|
||||
}
|
||||
map.put("app", "Goods");
|
||||
map.put("class", "CartAction");
|
||||
map.put("action", action + "");
|
||||
map.put("cart_id", cart_id);
|
||||
if (action == 2) {
|
||||
map.put("num", num + "");
|
||||
}
|
||||
// map.put("page", page + "");
|
||||
map.put("sign", Md5.md5("Goods" + "CartAction" + Md5.secret));
|
||||
// progressDialog.setMessage("正在请求数据");
|
||||
//progressDialog.setCancelable(false);
|
||||
loader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
progressDialog.dismiss();
|
||||
if (resultcode.status == 0) {
|
||||
Toast.makeText(baseActivity, resultcode.msg, Toast.LENGTH_SHORT).show();
|
||||
if (action == 1) {
|
||||
getData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.sl.house_property.discovery;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.sl.house_property.BaseActivity;
|
||||
import com.sl.house_property.R;
|
||||
import com.sl.house_property.databinding.ActivityAddDiscoveryBinding;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import imageselector.utils.ImageSelector;
|
||||
|
||||
public class AddDiscoveryActivity extends BaseActivity<ActivityAddDiscoveryBinding> {
|
||||
|
||||
private static final int REQUEST_CODE_SELECT_PICTURE = 300;
|
||||
private int type;
|
||||
private AdditionImageWrapper additionImageWrapper;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_add_discovery;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ImmersionBar.with(this)
|
||||
.keyboardEnable(true) //解决软键盘与底部输入框冲突问题
|
||||
// .keyboardEnable(true, WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
|
||||
// | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) //软键盘自动弹出
|
||||
.barColor(R.color.backcolorAccent)
|
||||
.init();
|
||||
mDataBinding.rec2.setNestedScrollingEnabled(false);
|
||||
mDataBinding.rvDynamicImage.setNestedScrollingEnabled(false);
|
||||
type = getIntent().getIntExtra("type", 0);
|
||||
if (type == 0) {
|
||||
mDataBinding.tvCover.setVisibility(View.GONE);
|
||||
mDataBinding.vi.setVisibility(View.GONE);
|
||||
mDataBinding.rec2.setVisibility(View.GONE);
|
||||
mDataBinding.tvGoods.setVisibility(View.GONE);
|
||||
} else if (type == 1) {
|
||||
|
||||
mDataBinding.tvCover.setVisibility(View.VISIBLE);
|
||||
mDataBinding.vi.setVisibility(View.VISIBLE);
|
||||
mDataBinding.rec2.setVisibility(View.VISIBLE);
|
||||
mDataBinding.tvGoods.setVisibility(View.VISIBLE);
|
||||
}
|
||||
additionImageWrapper = new AdditionImageWrapper(this, mDataBinding.rvDynamicImage);
|
||||
additionImageWrapper.wrap(new AdditionImageWrapper.OnAdditionLayoutItemClick() {
|
||||
@Override
|
||||
public void onAdditionItemClick() {
|
||||
//
|
||||
checkAlbumPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImageItemClick(int position) {
|
||||
//普通图片被点击
|
||||
List<File> imageList = additionImageWrapper.getImageList();
|
||||
ArrayList<String> arrayListOf = new ArrayList<>();
|
||||
for (int i = 0; i < imageList.size(); i++) {
|
||||
arrayListOf.add(imageList.get(i).getAbsolutePath());
|
||||
}
|
||||
Intent intent = new Intent(AddDiscoveryActivity.this, ImageViewerAndDeleteActivity.class);
|
||||
intent.putExtra("index", position);
|
||||
intent.putStringArrayListExtra("images", arrayListOf);
|
||||
startActivityForResult(intent, 111);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 111 && resultCode == 111) {
|
||||
ArrayList<String> images = data.getStringArrayListExtra("images");
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
for (int i = 0; i < images.size(); i++) {
|
||||
files.add(new File(images.get(i)));
|
||||
}
|
||||
additionImageWrapper.setData(files);
|
||||
|
||||
} else if (requestCode == REQUEST_CODE_SELECT_PICTURE && data != null) {
|
||||
ArrayList<String> images = data.getStringArrayListExtra(ImageSelector.SELECT_RESULT);
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.addAll(additionImageWrapper.getImageList());
|
||||
for (int i = 0; i < images.size(); i++) {
|
||||
files.add(new File(images.get(i)));
|
||||
}
|
||||
additionImageWrapper.setData(files);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void selectImage() {
|
||||
ImageSelector.builder()
|
||||
.useCamera(false) // 设置是否使用拍照
|
||||
.setSingle(false) //设置是否单选
|
||||
.setViewImage(true) //是否点击放大图片查看,,默认为true
|
||||
.setMaxSelectCount(additionImageWrapper.getRemainCount()) // 图片的最大选择数量,小于等于0时,不限数量。
|
||||
.start(AddDiscoveryActivity.this, REQUEST_CODE_SELECT_PICTURE); // 打开相册
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 检查访问相册权限
|
||||
* */
|
||||
private void checkAlbumPermission() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
selectImage();
|
||||
return;
|
||||
}
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
//权限还没有授予,需要在这里写申请权限的代码
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
|
||||
}
|
||||
|
||||
} else {
|
||||
selectImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package com.sl.house_property.discovery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.sl.house_property.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by: xudiwei
|
||||
* <p>
|
||||
* on: 2017/4/13.
|
||||
* <p>
|
||||
* 描述:用于处理带有可添加item的列表布局,可用于动态创建时的图片内容的显示操作布局
|
||||
* <p>
|
||||
* ------
|
||||
* | |
|
||||
* | + |
|
||||
* | |
|
||||
* ------
|
||||
* <p>
|
||||
* 用例 :
|
||||
* <p>
|
||||
* AdditionImageWrapper additionImageWrapper = new AdditionImageWrapper(Context, RecyclerView);
|
||||
* additionImageWrapper.wrap(new AdditionImageWrapper.OnAdditionLayoutItemClick() {
|
||||
*
|
||||
* @Override public void onAdditionItemClick() {
|
||||
* //添加item被点击
|
||||
* }
|
||||
* @Override public void onImageItemClick(int position) {
|
||||
* //普通图片被点击
|
||||
* }
|
||||
* });
|
||||
* <p>
|
||||
* //设置图片的数据
|
||||
* additionImageWrapper.setData(List<String>);
|
||||
* <p>
|
||||
* //设置最多显示的图片数量(默认为9张)
|
||||
* additionImageWrapper.setLimit(int);
|
||||
* <p>
|
||||
* //设置RecyclerView的列(默认为4列)
|
||||
* addition.setRow(int);
|
||||
*/
|
||||
|
||||
public class AdditionImageWrapper {
|
||||
private static final String TAG = "AdditionImageWrapper";
|
||||
/*默认图片数量为4张*/
|
||||
public static final int DEFAULT_COUNT = 9;
|
||||
/*默认图片的列数为4格*/
|
||||
public static final int DEFAULT_ROW = 4;
|
||||
/*图片数据有存在包含添加item的数据的,(当图片的数量小于mImageCountLimit时)*/
|
||||
private List<File> mList = new ArrayList<>();
|
||||
/*直实通过setData设置进来的图片*/
|
||||
private List<File> mRealList = new ArrayList<>();
|
||||
//剩下几张 mImageCountLimit - list
|
||||
private int mRemainCount = DEFAULT_COUNT;
|
||||
|
||||
private Context mContext;
|
||||
private RecyclerView mRecyclerView;
|
||||
private int mImageCountLimit = DEFAULT_COUNT;
|
||||
private int mRecyclerViewRow = DEFAULT_ROW;
|
||||
private OnAdditionLayoutItemClick mItemClick;
|
||||
private CreateDynamicRVAdapter mAdapter;
|
||||
|
||||
|
||||
public AdditionImageWrapper(Context context, RecyclerView recyclerView) {
|
||||
this.mContext = context;
|
||||
this.mRecyclerView = recyclerView;
|
||||
}
|
||||
|
||||
public void setLimit(int imageCountLimit) {
|
||||
this.mImageCountLimit = imageCountLimit;
|
||||
this.mRemainCount = imageCountLimit;
|
||||
}
|
||||
|
||||
public void setRow(int recyclerViewRow) {
|
||||
this.mRecyclerViewRow = recyclerViewRow;
|
||||
}
|
||||
|
||||
public int getRemainCount() {
|
||||
return mRemainCount;
|
||||
}
|
||||
|
||||
public List<File> getImageList() {
|
||||
return mRealList;
|
||||
}
|
||||
|
||||
|
||||
public void setData(List<File> list) {
|
||||
if (list.size() > mImageCountLimit) {
|
||||
throw new IllegalArgumentException(" list size is 大于limit, limit是:" + mImageCountLimit + " 你给的是: " + list.size());
|
||||
}
|
||||
mRealList.clear();
|
||||
|
||||
mRealList.addAll(list);
|
||||
mRemainCount = mImageCountLimit - list.size();
|
||||
|
||||
this.mList.clear();
|
||||
this.mList.addAll(list);
|
||||
if (this.mList.size() < mImageCountLimit) {
|
||||
addDefaultItem();
|
||||
}
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 包裹
|
||||
*
|
||||
* @param itemClick
|
||||
*/
|
||||
public void wrap(OnAdditionLayoutItemClick itemClick) {
|
||||
this.mItemClick = itemClick;
|
||||
initRecyclerView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加珍上空的Item数据
|
||||
*/
|
||||
private void addDefaultItem() {
|
||||
mList.add(null);
|
||||
}
|
||||
|
||||
private void initRecyclerView() {
|
||||
addDefaultItem();
|
||||
GridLayoutManager manager = new GridLayoutManager(mContext, mRecyclerViewRow);
|
||||
mAdapter = new CreateDynamicRVAdapter(mContext, mList);
|
||||
mRecyclerView.setLayoutManager(manager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public interface OnAdditionLayoutItemClick {
|
||||
/**
|
||||
* 添加图片的item被点击
|
||||
*/
|
||||
void onAdditionItemClick();
|
||||
|
||||
/**
|
||||
* 图片item被点击
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
void onImageItemClick(int position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* RecyclerView适配器
|
||||
*/
|
||||
private class CreateDynamicRVAdapter extends RecyclerView.Adapter<CreateDynamicRVAdapter.ViewHolder> {
|
||||
private Context mContext;
|
||||
private List<File> mList;
|
||||
|
||||
CreateDynamicRVAdapter(Context context, List<File> list) {
|
||||
this.mContext = context;
|
||||
this.mList = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateDynamicRVAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_rv_create_dynamic, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CreateDynamicRVAdapter.ViewHolder holder, int position) {
|
||||
File path = mList.get(position);
|
||||
if (position == mList.size() - 1 && null == path) {
|
||||
holder.ivImage.setImageResource(R.mipmap.icon_add);
|
||||
} else {
|
||||
// holder.ivImage.setImageResource(R.mipmap.ic_avatar_default);
|
||||
// mContext.(mContext, holder.ivImage, path);
|
||||
// ImageLoaderKt.loadToFile(mContext,holder.ivImage,path);
|
||||
RequestOptions requestOptions = new RequestOptions();
|
||||
requestOptions.placeholder(R.mipmap.icon_default_rectangle);
|
||||
requestOptions.error(R.mipmap.icon_default_rectangle);
|
||||
requestOptions.skipMemoryCache(false);
|
||||
Glide.with(mContext).load(path).apply(requestOptions).into(holder.ivImage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewHolder
|
||||
*/
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView ivImage;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ivImage = (ImageView) itemView.findViewById(R.id.riv_img);
|
||||
if (null == mItemClick) {
|
||||
return;
|
||||
}
|
||||
|
||||
//设置点击事件
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = ViewHolder.this.getLayoutPosition();
|
||||
File path = mList.get(position);
|
||||
if (null == path && position == mList.size() - 1) {
|
||||
mItemClick.onAdditionItemClick();
|
||||
} else {
|
||||
mItemClick.onImageItemClick(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sl.house_property.discovery;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
@@ -100,6 +101,14 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
intRecycleView();
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
activity.registerMyOnTouchListener(this);
|
||||
mDataBinding.ivAdd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getContext(), AddDiscoveryActivity.class);
|
||||
intent.putExtra("type",0);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.sl.house_property.discovery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.github.chrisbanes.photoview.PhotoView;
|
||||
import com.sl.house_property.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 日期:2017.01.06
|
||||
* <p>
|
||||
* 作者:xudiwei
|
||||
* <p>
|
||||
* 描述::图片预览/删除页面的适配器
|
||||
*/
|
||||
public class ImageViewerAdapter extends PagerAdapter {
|
||||
|
||||
private static final String TAG = "ImageViewerAdapter";
|
||||
|
||||
private Context mContext;
|
||||
private List<String> mList;
|
||||
private OnImageLongClickListener mImageLongClickListener;
|
||||
|
||||
public ImageViewerAdapter(Context context, List<String> list) {
|
||||
mContext = context;
|
||||
mList = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, final int position) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_preview, container, false);
|
||||
PhotoView photoView = (PhotoView) view.findViewById(R.id.photoView);
|
||||
photoView.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
|
||||
//点击事件
|
||||
if (null != mImageLongClickListener) {
|
||||
photoView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
mImageLongClickListener.onImageLongClick(position, v);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String url = mList.get(position);
|
||||
Log.d(TAG,"url: "+url);
|
||||
// ImageLoader.loadToUrl(mContext, photoView, url);
|
||||
// ImageLoaderKt.loadToUrl(mContext,photoView,url);
|
||||
RequestOptions requestOptions = new RequestOptions();
|
||||
requestOptions.placeholder(R.mipmap.icon_default_rectangle);
|
||||
requestOptions.error(R.mipmap.icon_default_rectangle);
|
||||
requestOptions.skipMemoryCache(false);
|
||||
Glide.with(mContext).load(url).apply(requestOptions).into(photoView);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
container.removeView((View) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
return POSITION_NONE;
|
||||
// return super.getItemPosition(object);
|
||||
}
|
||||
|
||||
public void setOnImageLongClickListener(OnImageLongClickListener listener) {
|
||||
this.mImageLongClickListener = listener;
|
||||
}
|
||||
|
||||
public interface OnImageLongClickListener {
|
||||
void onImageLongClick(int position, View view);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.sl.house_property.discovery;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
|
||||
import com.sl.house_property.BaseActivity;
|
||||
import com.sl.house_property.R;
|
||||
import com.sl.house_property.databinding.ActivityImagePreviewAndDeleteBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImageViewerAndDeleteActivity extends BaseActivity<ActivityImagePreviewAndDeleteBinding> {
|
||||
|
||||
private ArrayList<String> mList;
|
||||
private ImageViewerAdapter adapter;
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_image_preview_and_delete;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mList = getIntent().getStringArrayListExtra("images");
|
||||
index = getIntent().getIntExtra("index", 0);
|
||||
adapter = new ImageViewerAdapter(this, mList);
|
||||
mDataBinding.tvTitle.setText(getString(R.string.text_preview_index, index + 1, mList.size()));
|
||||
|
||||
mDataBinding.tvDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mList.size() == 1) {
|
||||
mList.remove(index);
|
||||
|
||||
} else {
|
||||
mList.remove(index);
|
||||
adapter.notifyDataSetChanged();
|
||||
mDataBinding.tvTitle.setText(getString(R.string.text_preview_index, index + 1, mList.size()));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
mDataBinding.vpPreview.setAdapter(adapter);
|
||||
mDataBinding.vpPreview.setCurrentItem(index);
|
||||
mDataBinding.vpPreview.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int i, float v, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int i) {
|
||||
mDataBinding.tvTitle.setText(getString(R.string.text_preview_index, i + 1, mList.size()));
|
||||
index = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
//返回操作后的数据
|
||||
Intent intent = new Intent();
|
||||
intent.putStringArrayListExtra("images", mList);
|
||||
setResult(200, intent);
|
||||
super.onBackPressed();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sl.house_property.discovery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
|
||||
/***
|
||||
* 自定义viewPager操作类
|
||||
*/
|
||||
public class PhotoViewPager extends ViewPager {
|
||||
|
||||
public PhotoViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public PhotoViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
return super.onTouchEvent(ev);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user