1
This commit is contained in:
@@ -77,7 +77,7 @@ public abstract class BaseActivity<VDB extends ViewDataBinding> extends RxAppCom
|
||||
}
|
||||
mDataBinding = DataBindingUtil.setContentView(this, getLayoutResId());
|
||||
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
||||
fullScreen(this);
|
||||
// fullScreen(this);
|
||||
progressDialog = new ProgressDialog(this);
|
||||
|
||||
if (mDataBinding != null) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sl.house_property;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.databinding.ViewDataBinding;
|
||||
import android.os.Bundle;
|
||||
@@ -10,6 +11,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
/**
|
||||
* Created by ximsfei on 17-1-7.
|
||||
@@ -41,6 +43,7 @@ public ProgressDialog progressDialog;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected abstract void loadData();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,21 +6,26 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.sl.house_property.databinding.ActivityMainTabBinding;
|
||||
import com.sl.house_property.discovery.DiscoveryFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import tools.Config;
|
||||
import utils.UtilHelpers;
|
||||
|
||||
public class MainTabActivity extends BaseActivity<ActivityMainTabBinding>
|
||||
implements View.OnClickListener,MainFragment.OnFragmentInteractionListener,
|
||||
implements View.OnClickListener, MainFragment.OnFragmentInteractionListener,
|
||||
Main1Fragment.OnFragmentInteractionListener,
|
||||
Main2Fragment.OnFragmentInteractionListener,
|
||||
Main3Fragment.OnFragmentInteractionListener,
|
||||
Main4Fragment.OnFragmentInteractionListener{
|
||||
Main4Fragment.OnFragmentInteractionListener {
|
||||
|
||||
/*定义的全局返回码,例如在主界面的某个Fragment点击某一项后进入下一个界面后
|
||||
如果在下一个界面有数据更改,需要Fragment刷新时,通过setResult方法通知主界面,主界面的
|
||||
@@ -30,58 +35,96 @@ implements View.OnClickListener,MainFragment.OnFragmentInteractionListener,
|
||||
public static final int RESUlT_CODE_0 = 201;//首页
|
||||
public static final int RESUlT_CODE_1 = 202;//发现
|
||||
public static final int RESUlT_CODE_2 = 203;//购物车
|
||||
// public static final int RESUlT_CODE_3 = 204;//
|
||||
// public static final int RESUlT_CODE_3 = 204;//
|
||||
public static final int RESUlT_CODE_4 = 205;//我的
|
||||
private RadioGroup radioGroup;
|
||||
private MainFragment fragment0;
|
||||
private DiscoveryFragment fragment1;
|
||||
private Main3Fragment fragment2;
|
||||
private Main2Fragment fragment3;
|
||||
private Main4Fragment fragment4;
|
||||
private RadioGroup radioGroup;
|
||||
private MainFragment fragment0;
|
||||
private DiscoveryFragment fragment1;
|
||||
private Main3Fragment fragment2;
|
||||
private Main2Fragment fragment3;
|
||||
private Main4Fragment fragment4;
|
||||
private Fragment currentFragment;
|
||||
|
||||
private int myeditcode=1000;
|
||||
private int myeditcode = 1000;
|
||||
|
||||
|
||||
private int nowradioId;
|
||||
|
||||
private int nowradioId;
|
||||
|
||||
// @Override
|
||||
// public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
// switch (ev.getAction()) {
|
||||
// case MotionEvent.ACTION_DOWN:
|
||||
//
|
||||
// UtilHelpers.hideKeyboard(ev, getCurrentFocus(), this);
|
||||
// break;
|
||||
// }
|
||||
// return super.dispatchTouchEvent(ev);
|
||||
//
|
||||
// }
|
||||
public void visibilyBottom(int isVisibily){
|
||||
findViewById(R.id.rl_bottom).setVisibility(isVisibily);
|
||||
}
|
||||
//2. 保存MyOnTouchListener接口的列表
|
||||
private ArrayList<MyOnTouchListener> onTouchListeners = new ArrayList<MyOnTouchListener>();
|
||||
//1.触摸事件接口
|
||||
public interface MyOnTouchListener {
|
||||
public boolean onTouch(MotionEvent ev);
|
||||
}
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
for (MyOnTouchListener listener : onTouchListeners) {
|
||||
// listener.onTouch(ev);
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
//4.提供给Fragment通过getActivity()方法来注册自己的触摸事件的方法
|
||||
public void registerMyOnTouchListener(MyOnTouchListener myOnTouchListener) {
|
||||
onTouchListeners.add(myOnTouchListener);
|
||||
}
|
||||
//5.提供给Fragment通过getActivity()方法来注销自己的触摸事件的方法
|
||||
public void unregisterMyOnTouchListener(MyOnTouchListener myOnTouchListener) {
|
||||
onTouchListeners.remove(myOnTouchListener);
|
||||
}
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
|
||||
|
||||
return R.layout.activity_main_tab;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Config.getInstance(MainTabActivity.this).put("MainTabActivity",true);
|
||||
Config.getInstance(MainTabActivity.this).put("MainTabActivity", true);
|
||||
//setPhotoSysyrmbar();
|
||||
//setSytemBar(R.color.colorPrimary);//设置主题样式
|
||||
//setFramentMarginTop();
|
||||
|
||||
//setSytemBar(R.color.colorPrimary);//设置主题样式
|
||||
//setFramentMarginTop();
|
||||
ImmersionBar.with(this)
|
||||
.keyboardEnable(true) //解决软键盘与底部输入框冲突问题
|
||||
// .keyboardEnable(true, WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
|
||||
// | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) //软键盘自动弹出
|
||||
.init();
|
||||
initView();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressLint("MissingSuperCall")
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
radioGroup= mDataBinding.radioGroup;
|
||||
for (int i = 0; i <radioGroup.getChildCount() ; i++) {
|
||||
RadioButton myRadioButton= (RadioButton) radioGroup.getChildAt(i);
|
||||
radioGroup = mDataBinding.radioGroup;
|
||||
for (int i = 0; i < radioGroup.getChildCount(); i++) {
|
||||
RadioButton myRadioButton = (RadioButton) radioGroup.getChildAt(i);
|
||||
myRadioButton.setOnClickListener(this);
|
||||
|
||||
}
|
||||
mDataBinding.button.setChecked(true);
|
||||
nowradioId= mDataBinding.button.getId();
|
||||
nowradioId = mDataBinding.button.getId();
|
||||
mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
||||
changeFragment( mDataBinding.button.getId());
|
||||
changeFragment(mDataBinding.button.getId());
|
||||
|
||||
}
|
||||
|
||||
@@ -159,26 +202,27 @@ implements View.OnClickListener,MainFragment.OnFragmentInteractionListener,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(view.getId()==nowradioId)return;
|
||||
RadioButton myRadioButton=(RadioButton)findViewById(nowradioId);
|
||||
if(view.getId()==R.id.button4){
|
||||
if( (Config.getInstance(MainTabActivity.this).getUser()==null)){
|
||||
Intent intent =new Intent(MainTabActivity.this,LoginActivity.class);
|
||||
if (view.getId() == nowradioId) return;
|
||||
RadioButton myRadioButton = (RadioButton) findViewById(nowradioId);
|
||||
if (view.getId() == R.id.button4) {
|
||||
if ((Config.getInstance(MainTabActivity.this).getUser() == null)) {
|
||||
Intent intent = new Intent(MainTabActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
myRadioButton=(RadioButton)view;
|
||||
myRadioButton = (RadioButton) view;
|
||||
myRadioButton.setChecked(false);
|
||||
myRadioButton=(RadioButton)findViewById(nowradioId);
|
||||
myRadioButton = (RadioButton) findViewById(nowradioId);
|
||||
myRadioButton.setChecked(true);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
myRadioButton.setChecked(false);
|
||||
myRadioButton=(RadioButton)view;
|
||||
myRadioButton = (RadioButton) view;
|
||||
myRadioButton.setChecked(true);
|
||||
nowradioId=view.getId();
|
||||
nowradioId = view.getId();
|
||||
changeFragment(view.getId());
|
||||
}
|
||||
|
||||
@@ -190,8 +234,8 @@ implements View.OnClickListener,MainFragment.OnFragmentInteractionListener,
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
if(resultCode==RESUlT_CODE_4){
|
||||
if(currentFragment==fragment4){
|
||||
if (resultCode == RESUlT_CODE_4) {
|
||||
if (currentFragment == fragment4) {
|
||||
// if(fragment0!=null){
|
||||
// fragmentTransaction.remove(fragment0);
|
||||
// fragment0 = null;
|
||||
@@ -219,16 +263,16 @@ implements View.OnClickListener,MainFragment.OnFragmentInteractionListener,
|
||||
// }
|
||||
// fragmentTransaction.show(fragment4);
|
||||
// currentFragment = fragment4;
|
||||
fragment4.refreshData();
|
||||
}
|
||||
fragment4.refreshData();
|
||||
}
|
||||
try {
|
||||
// fragmentTransaction.commit();
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
fragmentTransaction.commitAllowingStateLoss();
|
||||
}
|
||||
}else if(resultCode==myeditcode){
|
||||
if(currentFragment==fragment1){
|
||||
} else if (resultCode == myeditcode) {
|
||||
if (currentFragment == fragment1) {
|
||||
fragment1.loadData();
|
||||
}
|
||||
}
|
||||
@@ -237,7 +281,7 @@ implements View.OnClickListener,MainFragment.OnFragmentInteractionListener,
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Config.getInstance(MainTabActivity.this).put("MainTabActivity",false);
|
||||
Config.getInstance(MainTabActivity.this).put("MainTabActivity", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,48 +2,63 @@ package com.sl.house_property.discovery;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.dalong.refreshlayout.OnRefreshListener;
|
||||
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.lzy.ninegrid.ImageInfo;
|
||||
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
|
||||
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.BaseFragment;
|
||||
import com.sl.house_property.MainTabActivity;
|
||||
import com.sl.house_property.R;
|
||||
import com.sl.house_property.databinding.FragmentDiscoveryBinding;
|
||||
import com.sl.house_property.databinding.ItemCommentBinding;
|
||||
import com.sl.house_property.databinding.ItemDiscoveryBinding;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.squareup.picasso.Target;
|
||||
|
||||
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.DiscoveryListEntity;
|
||||
import entity.RegisterUser;
|
||||
import http.ApiConfig;
|
||||
import my_loader.Loader;
|
||||
import my_loader.Resultcode;
|
||||
import my_view.CommentDialog;
|
||||
import my_view.tao_bao_refresh.FullyGridLayoutManager;
|
||||
import rx.Subscription;
|
||||
import rx.functions.Action1;
|
||||
import tools.Config;
|
||||
import tools.PicassoRoundTransform;
|
||||
import utils.CommonUtils;
|
||||
import utils.DateUtils;
|
||||
import utils.KeyboardUtil;
|
||||
import utils.Md5;
|
||||
import utils.UtilHelpers;
|
||||
|
||||
public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> implements MainTabActivity.MyOnTouchListener {
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
private String mParam1;
|
||||
@@ -69,21 +84,75 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
super.onCreateVew(inflater, savedInstanceState);
|
||||
baseActivity = (BaseActivity) getActivity();
|
||||
progressDialog = new ProgressDialog(baseActivity);
|
||||
mDataBinding.rl.setOnRefreshListener(new OnRefreshListener() {
|
||||
mDataBinding.dw.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
||||
getlist(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||||
page = 1;
|
||||
getlist(page);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMore() {
|
||||
|
||||
}
|
||||
});
|
||||
mDataBinding.rl.setAutoRefresh(true);
|
||||
mDataBinding.dw.autoRefresh();
|
||||
intRecycleView();
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
activity.registerMyOnTouchListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
activity.unregisterMyOnTouchListener(this);
|
||||
}
|
||||
|
||||
public void updateEditTextBodyVisible(int visibility) {
|
||||
mDataBinding.llComment.setVisibility(visibility);
|
||||
if (View.VISIBLE == visibility) {
|
||||
mDataBinding.llComment.requestFocus();
|
||||
//弹出键盘
|
||||
CommonUtils.showSoftInput(mDataBinding.etComment.getContext(), mDataBinding.etComment);
|
||||
|
||||
} else if (View.GONE == visibility) {
|
||||
//隐藏键盘
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
activity.visibilyBottom(View.VISIBLE);
|
||||
CommonUtils.hideSoftInput(mDataBinding.etComment.getContext(), mDataBinding.etComment);
|
||||
}
|
||||
}
|
||||
|
||||
private int currentKeyboardH;
|
||||
private int editTextBodyHeight;
|
||||
|
||||
private void setViewTreeObserver() {
|
||||
final ViewTreeObserver swipeRefreshLayoutVTO = mDataBinding.rl.getViewTreeObserver();
|
||||
swipeRefreshLayoutVTO.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
Rect r = new Rect();
|
||||
mDataBinding.rl.getWindowVisibleDisplayFrame(r);
|
||||
int statusBarH = ImmersionBar.getStatusBarHeight(DiscoveryFragment.this);//状态栏高度
|
||||
int screenH = mDataBinding.rl.getRootView().getHeight();
|
||||
if (r.top != statusBarH) {
|
||||
//r.top代表的是状态栏高度,在沉浸式状态栏时r.top=0,通过getStatusBarHeight获取状态栏高度
|
||||
r.top = statusBarH;
|
||||
}
|
||||
int keyboardH = screenH - (r.bottom - r.top);
|
||||
|
||||
if (keyboardH == currentKeyboardH) {//有变化时才处理,否则会陷入死循环
|
||||
return;
|
||||
}
|
||||
currentKeyboardH = keyboardH;
|
||||
editTextBodyHeight = mDataBinding.llComment.getHeight();
|
||||
if (keyboardH < 150) {//说明是隐藏键盘的情况
|
||||
updateEditTextBodyVisible(View.GONE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Loader mGankLoader;
|
||||
@@ -104,24 +173,234 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), mypage);
|
||||
}
|
||||
|
||||
private void like(String goodsId, final int position) {
|
||||
final 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", "AddUp");
|
||||
map.put("goods_id", goodsId);
|
||||
map.put("sign", Md5.md5("Goods" + "AddUp" + Md5.secret));
|
||||
progressDialog.setMessage("提交中");
|
||||
progressDialog.setCancelable(false);
|
||||
// progressDialog.show();
|
||||
|
||||
mGankLoader = new Loader();
|
||||
Subscription subscription = mGankLoader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||||
|
||||
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
|
||||
progressDialog.dismiss();
|
||||
if (!(resultcode.status == 0)) {
|
||||
baseActivity.setToast(1, resultcode.msg);
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
BaseRecycleViewAdapter adapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
if (discoveryListEntities.get(position).getIs_like() == 1) {
|
||||
discoveryListEntities.get(position).setIs_like(0);
|
||||
ArrayList<DiscoveryListEntity.Like> like = discoveryListEntities.get(position).getLike();
|
||||
for (int i = 0; i < like.size(); i++) {
|
||||
if (user.getUserid().equals(like.get(i).getUserid())) {
|
||||
like.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
discoveryListEntities.get(position).setLike(like);
|
||||
} else {
|
||||
discoveryListEntities.get(position).setIs_like(1);
|
||||
DiscoveryListEntity.Like like = new DiscoveryListEntity.Like();
|
||||
like.setNickname(user.getNickname());
|
||||
like.setUserid(user.getUserid());
|
||||
discoveryListEntities.get(position).getLike().add(like);
|
||||
}
|
||||
|
||||
adapter.upDateOne(position, discoveryListEntities.get(position));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
baseActivity.setToast(2, "提交失败");
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
baseActivity.addSubscription(subscription);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取控件左上顶点Y坐标
|
||||
*
|
||||
* @param view
|
||||
* @return
|
||||
*/
|
||||
private int getCoordinateY(View view) {
|
||||
int[] coordinate = new int[2];
|
||||
view.getLocationOnScreen(coordinate);
|
||||
return coordinate[1];
|
||||
}
|
||||
|
||||
|
||||
private void intRecycleView() {
|
||||
FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(), 1);
|
||||
mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
||||
mgr.setSmoothScrollbarEnabled(true);
|
||||
mDataBinding.recyView.setLayoutManager(mgr);
|
||||
mDataBinding.tvSendComment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setViewTreeObserver();
|
||||
}
|
||||
});
|
||||
mDataBinding.sv.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (mDataBinding.llComment.getVisibility() == View.VISIBLE) {
|
||||
updateEditTextBodyVisible(View.GONE);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(baseActivity);
|
||||
mDataBinding.recyView.setNestedScrollingEnabled(false);//禁止rcyc嵌套滑动
|
||||
mDataBinding.recyView.setLayoutManager(linearLayoutManager);
|
||||
BaseRecycleViewAdapter<DiscoveryListEntity, ItemDiscoveryBinding> baseRecycleViewAdapter = new BaseRecycleViewAdapter(getActivity(), R.layout.item_discovery);
|
||||
baseRecycleViewAdapter.setHasStableIds(true);
|
||||
|
||||
discoveryListEntities = new ArrayList<>();
|
||||
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||||
@Override
|
||||
public void onBindViewHolder(Object b, int position) {
|
||||
public void onBindViewHolder(Object b, final int position) {
|
||||
if (!(position >= discoveryListEntities.size())) {
|
||||
ItemDiscoveryBinding homeGridAdapterItemBinding = (ItemDiscoveryBinding) b;
|
||||
final ItemDiscoveryBinding homeGridAdapterItemBinding = (ItemDiscoveryBinding) b;
|
||||
// homeGridAdapterItemBinding.setMyentity(discoveryListEntities.get(position));
|
||||
DiscoveryListEntity discoveryListEntity = discoveryListEntities.get(position);
|
||||
final DiscoveryListEntity discoveryListEntity = discoveryListEntities.get(position);
|
||||
homeGridAdapterItemBinding.tvNikeName.setText(discoveryListEntity.getNickname());
|
||||
homeGridAdapterItemBinding.tvContent.setText(discoveryListEntity.getGoods_detail());
|
||||
|
||||
// Picasso.with(getActivity()).load(discoveryListEntity.getAvatar())
|
||||
// .placeholder(R.mipmap.icon_default_rectangle)
|
||||
// .transform(new PicassoRoundTransform())
|
||||
// .into(homeGridAdapterItemBinding.imageHead);
|
||||
mDataBinding.tvSendComment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.e("click", "comment");
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
CommonUtils.hideSoftInput(getContext(),mDataBinding.etComment);
|
||||
mDataBinding.llComment.setVisibility(View.GONE);
|
||||
activity.visibilyBottom(View.VISIBLE);
|
||||
comment(discoveryListEntity.getGoods_id(), position, "", mDataBinding.etComment.getText().toString());
|
||||
}
|
||||
});
|
||||
homeGridAdapterItemBinding.ivComment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
final CommentDialog commentDialog = new CommentDialog(baseActivity);
|
||||
commentDialog.setShowBug(discoveryListEntity.getType() == 2);
|
||||
commentDialog.setPraise(discoveryListEntity.getIs_like() == 1);
|
||||
final int mBottomY = getCoordinateY(homeGridAdapterItemBinding.ivComment) + homeGridAdapterItemBinding.ivComment.getHeight();
|
||||
commentDialog.setOnCommentOperateListener(new CommentDialog.OnCommentOperateListener() {
|
||||
@Override
|
||||
public void click(int type) {
|
||||
|
||||
if (type == 1 || type == 2) {
|
||||
//点赞/取消
|
||||
commentDialog.dismiss();
|
||||
like(discoveryListEntity.getGoods_id(), position);
|
||||
} else if (type == 3) {
|
||||
mDataBinding.llComment.setVisibility(View.VISIBLE);
|
||||
mDataBinding.etComment.requestFocus();
|
||||
mDataBinding.etComment.setHint("评论");
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
KeyboardUtil.showSoftInput(getContext());
|
||||
activity.visibilyBottom(View.GONE);
|
||||
|
||||
commentDialog.dismiss();
|
||||
mDataBinding.etComment.setText("");
|
||||
homeGridAdapterItemBinding.ivComment.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int y = getCoordinateY(mDataBinding.llComment) - 20;
|
||||
//评论时滑动到对应item底部和输入框顶部对齐
|
||||
mDataBinding.sv.smoothScrollBy(0, mBottomY - y);
|
||||
}
|
||||
}, 300);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
new XPopup.Builder(baseActivity).hasShadowBg(false).atView(homeGridAdapterItemBinding.ivComment).asCustom(commentDialog)
|
||||
.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (discoveryListEntity.getLike().isEmpty()) {
|
||||
homeGridAdapterItemBinding.tvLike.setVisibility(View.GONE);
|
||||
} else {
|
||||
homeGridAdapterItemBinding.tvLike.setVisibility(View.VISIBLE);
|
||||
StringBuilder likeString = new StringBuilder();
|
||||
for (int i = 0; i < discoveryListEntity.getLike().size(); i++) {
|
||||
if (i == 0) {
|
||||
likeString.append("❤");
|
||||
|
||||
} else {
|
||||
likeString.append(",");
|
||||
}
|
||||
likeString.append(discoveryListEntity.getLike().get(i).getNickname());
|
||||
}
|
||||
homeGridAdapterItemBinding.tvLike.setText(likeString.toString());
|
||||
|
||||
homeGridAdapterItemBinding.tvTime.setText(DateUtils.getDate(discoveryListEntity.getCtime()));
|
||||
|
||||
}
|
||||
if (discoveryListEntity.getDis_content().isEmpty()) {
|
||||
homeGridAdapterItemBinding.rvComment.setVisibility(View.GONE);
|
||||
} else {
|
||||
homeGridAdapterItemBinding.rvComment.setVisibility(View.VISIBLE);
|
||||
FullyGridLayoutManager mgr = new FullyGridLayoutManager(getActivity(), 1);
|
||||
mgr.setOrientation(FullyGridLayoutManager.VERTICAL);
|
||||
mgr.setSmoothScrollbarEnabled(true);
|
||||
homeGridAdapterItemBinding.rvComment.setLayoutManager(mgr);
|
||||
BaseRecycleViewAdapter<DiscoveryListEntity.Dis_content, ItemCommentBinding> baseRecycleViewAdapter = new BaseRecycleViewAdapter(getActivity(), R.layout.item_comment);
|
||||
homeGridAdapterItemBinding.rvComment.setAdapter(baseRecycleViewAdapter);
|
||||
final ArrayList<DiscoveryListEntity.Dis_content> dis_content = discoveryListEntity.getDis_content();
|
||||
baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() {
|
||||
@Override
|
||||
public void onBindViewHolder(Object b, int position) {
|
||||
ItemCommentBinding itemCommentBinding = (ItemCommentBinding) b;
|
||||
itemCommentBinding.tvName.setText(dis_content.get(position).getNickname() + ": ");
|
||||
itemCommentBinding.tvInfo.setText(dis_content.get(position).getContents());
|
||||
if (dis_content.get(position).getReply().isEmpty()) {
|
||||
itemCommentBinding.llHf.setVisibility(View.GONE);
|
||||
|
||||
} else {
|
||||
itemCommentBinding.llHf.setVisibility(View.VISIBLE);
|
||||
itemCommentBinding.tvName2.setText(discoveryListEntity.getNickname());
|
||||
itemCommentBinding.tvInfo2.setText("回复");
|
||||
itemCommentBinding.tvName3.setText(dis_content.get(position).getNickname() + ":");
|
||||
itemCommentBinding.tvInfo3.setText(dis_content.get(position).getReply());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
baseRecycleViewAdapter.setData(dis_content);
|
||||
|
||||
}
|
||||
|
||||
|
||||
RequestOptions requestOptions = new RequestOptions();
|
||||
requestOptions.placeholder(R.mipmap.icon_default_rectangle);
|
||||
requestOptions.error(R.mipmap.icon_default_rectangle);
|
||||
@@ -160,14 +439,6 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||||
}
|
||||
|
||||
private void addRecycleVerization(ArrayList<DiscoveryListEntity> lsit) {
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
|
||||
discoveryListEntities = lsit;
|
||||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||||
|
||||
}
|
||||
|
||||
private void getGankList(String myurl, Map<String, String> map, String msg, final int requstecode) {
|
||||
progressDialog.setMessage(msg);
|
||||
progressDialog.setCancelable(false);
|
||||
@@ -180,8 +451,8 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
|
||||
mDataBinding.rl.stopRefresh(true);
|
||||
mDataBinding.rl.stopLoadMore(true);
|
||||
mDataBinding.dw.finishRefresh();
|
||||
mDataBinding.dw.finishLoadMore();
|
||||
progressDialog.dismiss();
|
||||
if (!(resultcode.status == 0)) {
|
||||
baseActivity.setToast(1, resultcode.msg);
|
||||
@@ -191,22 +462,37 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
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<DiscoveryListEntity>>() {
|
||||
}.getType();
|
||||
String fengmian = jsonObject.getString("fengmian");
|
||||
String avatar = jsonObject.getString("avatar");
|
||||
Picasso.with(getActivity()).load(fengmian)
|
||||
.placeholder(R.mipmap.icon_default_rectangle)
|
||||
.into(target);
|
||||
Picasso.with(getActivity()).load(avatar)
|
||||
.placeholder(R.mipmap.icon_default_rectangle)
|
||||
.transform(new PicassoRoundTransform())
|
||||
.into(mDataBinding.head);
|
||||
discoveryListEntities = new Gson().fromJson(array.toString(), type);
|
||||
addRecycleVerization(discoveryListEntities);
|
||||
if (page == 1) {
|
||||
String fengmian = jsonObject.getString("fengmian");
|
||||
String avatar = jsonObject.getString("avatar");
|
||||
Picasso.with(getActivity()).load(fengmian)
|
||||
.placeholder(R.mipmap.icon_default_rectangle)
|
||||
.into(target);
|
||||
Picasso.with(getActivity()).load(avatar)
|
||||
.placeholder(R.mipmap.icon_default_rectangle)
|
||||
.transform(new PicassoRoundTransform())
|
||||
.into(mDataBinding.head);
|
||||
discoveryListEntities = new Gson().fromJson(array.toString(), type);
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||||
page++;
|
||||
} else {
|
||||
ArrayList<DiscoveryListEntity> o = new Gson().fromJson(array.toString(), type);
|
||||
discoveryListEntities.addAll(o);
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||||
int count = jsonObject.getInt("count");
|
||||
if (discoveryListEntities.size() == count || o.isEmpty()) {
|
||||
mDataBinding.dw.finishLoadMoreWithNoMoreData();
|
||||
} else {
|
||||
page++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -214,36 +500,6 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
}
|
||||
}
|
||||
|
||||
// if (resultcode.status == 0) {
|
||||
//// baseActivity.setToast(0, resultcode.msg);
|
||||
// if (requstecode == 0) {
|
||||
// Gson gs = new Gson();
|
||||
// LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||||
// String s = gs.toJson(adta);
|
||||
//
|
||||
// ArrayList<Advertorial_listEntity> list = null;
|
||||
// try {
|
||||
// JSONObject jsonObject = new JSONObject(s);
|
||||
// org.json.JSONArray array1 = jsonObject.getJSONArray("advert_info");
|
||||
// if (array1.length() > 0) {
|
||||
// String img = array1.getJSONObject(0).optString("advert_img");
|
||||
// configTopImage(img);
|
||||
// imgme = img;
|
||||
//
|
||||
// }
|
||||
// org.json.JSONArray array = jsonObject.getJSONArray("advertorial_list");
|
||||
// Type type = new TypeToken<ArrayList<Advertorial_listEntity>>() {
|
||||
// }.getType();
|
||||
// list = new Gson().fromJson(array.toString(), type);
|
||||
// //addRecycleVerization(list);
|
||||
//
|
||||
//
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -251,8 +507,8 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
mDataBinding.rl.stopRefresh(true);
|
||||
mDataBinding.rl.stopLoadMore(true);
|
||||
mDataBinding.dw.finishRefresh();
|
||||
mDataBinding.dw.finishLoadMore();
|
||||
baseActivity.setToast(2, getString(R.string.getdatafailure));
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
@@ -298,4 +554,86 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(MotionEvent ev) {
|
||||
switch (ev.getAction()) {
|
||||
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
//点击空白处隐藏键盘,隐藏输入框相关
|
||||
if (getActivity().getCurrentFocus()!=null&&getActivity().getCurrentFocus().getId() == R.id.tv_send_comment) {
|
||||
return false;
|
||||
}
|
||||
boolean b = UtilHelpers.hideKeyboard(ev, getActivity().getCurrentFocus(), getActivity());
|
||||
if (b) {
|
||||
CommonUtils.hideSoftInput( mDataBinding.etComment.getContext(), mDataBinding.etComment);
|
||||
MainTabActivity activity = (MainTabActivity) getActivity();
|
||||
activity.visibilyBottom(View.VISIBLE);
|
||||
mDataBinding.llComment.setVisibility(View.GONE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void comment(String goodsId, final int position, String reply_id, final String content) {
|
||||
final 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", "DisGoods");
|
||||
map.put("goods_id", goodsId);
|
||||
if (!TextUtils.isEmpty(reply_id)) {
|
||||
map.put("reply_id", reply_id);
|
||||
}
|
||||
|
||||
map.put("contents", content);
|
||||
map.put("sign", Md5.md5("Goods" + "DisGoods" + Md5.secret));
|
||||
progressDialog.setMessage("提交中");
|
||||
progressDialog.setCancelable(false);
|
||||
// progressDialog.show();
|
||||
|
||||
mGankLoader = new Loader();
|
||||
Subscription subscription = mGankLoader.getMovie(ApiConfig.BASE_URL, map).subscribe(new Action1<Resultcode>() {
|
||||
|
||||
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
|
||||
progressDialog.dismiss();
|
||||
if (!(resultcode.status == 0)) {
|
||||
baseActivity.setToast(1, resultcode.msg);
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
|
||||
// BaseRecycleViewAdapter adapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
// if (discoveryListEntities.get(position).getDis_content().isEmpty()) {
|
||||
// DiscoveryListEntity.Dis_content dis_content = new DiscoveryListEntity.Dis_content();
|
||||
// dis_content.setContents(content);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// adapter.upDateOne(position, discoveryListEntities.get(position));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
baseActivity.setToast(2, "提交失败");
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
baseActivity.addSubscription(subscription);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user