家庭切换

This commit is contained in:
BA7LZD 2020-06-07 03:35:52 +08:00
parent 13f572a16a
commit c355914d84
21 changed files with 560 additions and 127 deletions

View File

@ -12,6 +12,7 @@ import com.yuxihan.sdu.ui.account.HomeBean;
import com.yuxihan.sdu.ui.account.home.CodeParams;
import com.yuxihan.sdu.ui.baby.AddBabyParams;
import com.yuxihan.sdu.ui.baby.model.BabyInfoModel;
import com.yuxihan.sdu.ui.home.PostModel;
import com.yuxihan.sdu.ui.home.PostRequestParams;
import retrofit2.Call;
@ -54,6 +55,10 @@ public interface UpdateService {
Call<Result<HomeBean>> getFamilyList(
@Body BaseRequestParams params
);
@POST("/deleteFamily")
Call<Result> deleteFamily(
@Body BaseRequestParams params
);
@POST("/savePostDetail")
Call<Result> savePostDetail(
@ -64,8 +69,8 @@ public interface UpdateService {
Call<Result> addBaby(
@Body AddBabyParams params
);
@POST("/editBaby")
Call<Result> editBaby(
@POST("/updateBaby")
Call<Result> updateBaby(
@Body AddBabyParams params
);
@POST("/deleteBaby")
@ -81,5 +86,9 @@ public interface UpdateService {
Call<Result> addFamilyMembers(
@Body CodeParams params
);
@POST("/getPostDetailList")
Call<Result<PostModel>> getPostDetailList(
@Body BaseRequestParams params
);
}

View File

@ -11,6 +11,7 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
@ -89,6 +90,7 @@ public class AccountFragment extends BaseFragment implements View.OnClickListene
AccountUtils.setCurFamilyID(bean.getFamilyId() + "");
AccountUtils.setCurFamilyName(bean.getFamilyName());
ToastUtils.s(SDUApp.getAppContext(), "默认家庭切换到:" + bean.getFamilyName());
accountViewModel.getFamilyList();
}
});
}
@ -145,6 +147,8 @@ public class AccountFragment extends BaseFragment implements View.OnClickListene
super.onResume();
if (Const.NEED_RELOAD_PROFILE) {
setPersonalInfo();
accountViewModel.getFamilyList();
Const.NEED_RELOAD_PROFILE = false;
}
}
@ -165,6 +169,11 @@ public class AccountFragment extends BaseFragment implements View.OnClickListene
accountViewModel.getFamilyList();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(ExitHomeEvent event) {
accountViewModel.deleteFamily(event.getFamilyBean().getFamilyId()+"");
}
@Override
public void onStart() {
super.onStart();
@ -176,4 +185,5 @@ public class AccountFragment extends BaseFragment implements View.OnClickListene
super.onStop();
EventBus.getDefault().unregister(this);
}
}

View File

@ -12,6 +12,9 @@ import com.yuxihan.sdu.comm.SDUApp;
import com.yuxihan.sdu.comm.network.BaseRequestParams;
import com.yuxihan.sdu.data.Result;
import com.yuxihan.sdu.data.UpdateService;
import com.yuxihan.sdu.ui.account.home.RefreshHomeListEvent;
import org.greenrobot.eventbus.EventBus;
import retrofit2.Call;
import retrofit2.Callback;
@ -68,4 +71,40 @@ public class AccountViewModel extends ViewModel {
}
public void deleteFamily(String familyId) {
UpdateService updateService = SDUApp.getRetrofit().create(UpdateService.class);
BaseRequestParams baseRequestParams = new BaseRequestParams();
baseRequestParams.setFamilyId(familyId);
Call<Result> call = updateService.deleteFamily(baseRequestParams);
call.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call,
Response<Result> response) {
//请求成功返回是一个封装为DataBean的响应
if (null == response.body()) {
Toast.makeText(SDUApp.getAppContext(), "Internal Server Error",
Toast.LENGTH_LONG).show();
return;
}
if (Const.ERROR_CODE_NORMAL.equals(response.body().getErrCode())) {
Toast.makeText(SDUApp.getAppContext(), "退出成功~",
Toast.LENGTH_LONG).show();
EventBus.getDefault().post(new RefreshHomeListEvent());
} else {
Toast.makeText(SDUApp.getAppContext(), response.body().getErrMsg(),
Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Result> call, Throwable t) {
//请求失败
Log.e("TAG", "请求失败:" + t.getMessage());
Toast.makeText(SDUApp.getAppContext(), "服务器开小差了!", Toast.LENGTH_LONG).show();
}
});
}
}

View File

@ -4,6 +4,7 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.opengl.Visibility;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@ -15,10 +16,13 @@ import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.util.AccountUtils;
import com.yuxihan.sdu.comm.widget.selector.Selector;
import org.greenrobot.eventbus.EventBus;
public class AgeSelector extends Selector {
private TextView tvTitle;
private TextView tv_record_member_count;
private TextView tv_creator;
private TextView tv_home_exit;
private TextView tv_code;
private ImageView ivIcon;
private ImageView ivSelector;
@ -74,6 +78,7 @@ public class AgeSelector extends Selector {
ivIcon = view.findViewById(R.id.iv_home_head);
tv_record_member_count = view.findViewById(R.id.tv_record_member_count);
tv_creator = view.findViewById(R.id.tv_creator);
tv_home_exit = view.findViewById(R.id.tv_home_exit);
tv_code = view.findViewById(R.id.tv_code);
ivSelector = view.findViewById(R.id.iv_select_status);
onBindView(text, iconResId, indicatorResId, textColor, textSize);
@ -89,9 +94,11 @@ public class AgeSelector extends Selector {
tv_code.setVisibility(VISIBLE);
tv_code.setText(getResources().getString(R.string.code_show,
familyBean.getInvitedCode()));
tv_home_exit.setVisibility(GONE);
} else {
tv_creator.setVisibility(GONE);
tv_code.setVisibility(GONE);
tv_home_exit.setVisibility(VISIBLE);
}
if (AccountUtils.getCurFamilyID().equals(familyBean.getFamilyId() + "")) {
setSelected(true);
@ -100,6 +107,12 @@ public class AgeSelector extends Selector {
setSelected(false);
ivSelector.setVisibility(GONE);
}
tv_home_exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new ExitHomeEvent(familyBean));
}
});
}
@Override

View File

@ -0,0 +1,17 @@
package com.yuxihan.sdu.ui.account;
public class ExitHomeEvent {
HomeBean.FamilyBean familyBean;
public ExitHomeEvent(HomeBean.FamilyBean familyBean) {
this.familyBean = familyBean;
}
public HomeBean.FamilyBean getFamilyBean() {
return familyBean;
}
public void setFamilyBean(HomeBean.FamilyBean familyBean) {
this.familyBean = familyBean;
}
}

View File

@ -32,8 +32,8 @@ public class InputCodeViewModel extends ViewModel {
}
if (Const.ERROR_CODE_NORMAL.equals(response.body().getErrCode())) {
Toast.makeText(SDUApp.getAppContext(), "加入家庭成功~", Toast.LENGTH_LONG).show();
Const.NEED_RELOAD_PROFILE = true;
EventBus.getDefault().post(new CloseInputCodeActivityEvent());
EventBus.getDefault().post(new RefreshHomeListEvent());
} else {
Toast.makeText(SDUApp.getAppContext(), response.body().getErrMsg(),
Toast.LENGTH_LONG).show();

View File

@ -161,7 +161,7 @@ public class AddBabyActivity extends BaseActivity implements View.OnClickListene
private void editBaby() {
if (addBabyParams.isValid()) {
addBabyParams.setBabyId(curBaby.getBabyId());
addBabyViewModel.addBaby(addBabyParams);
addBabyViewModel.updateBaby(addBabyParams);
} else {
Toast.makeText(SDUApp.getAppContext(), "信息输入不全~", Toast.LENGTH_LONG).show();
}

View File

@ -68,9 +68,9 @@ public class AddBabyViewModel extends ViewModel {
}
public void editBaby(AddBabyParams params) {
public void updateBaby(AddBabyParams params) {
UpdateService updateService = SDUApp.getRetrofit().create(UpdateService.class);
Call<Result> call = updateService.editBaby(params);
Call<Result> call = updateService.updateBaby(params);
call.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {

View File

@ -4,15 +4,17 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.BaseFragment;
import com.yuxihan.sdu.ui.account.home.RefreshHomeListEvent;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class GrowFragment extends BaseFragment {
@ -23,13 +25,25 @@ public class GrowFragment extends BaseFragment {
growViewModel =
new ViewModelProvider(this).get(GrowViewModel.class);
View root = inflater.inflate(R.layout.fragment_grow, container, false);
final TextView textView = root.findViewById(R.id.text_dashboard);
growViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(@Nullable String s) {
textView.setText(s);
}
});
return root;
}
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void onMessageEvent( event) {
//
// }
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
}

View File

@ -19,10 +19,11 @@ import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.BaseFragment;
import com.yuxihan.sdu.comm.util.AccountUtils;
import com.yuxihan.sdu.data.model.PostDetailBean;
import com.yuxihan.sdu.ui.home.adapter.HomeListAdapter;
import java.util.ArrayList;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class HomeFragment extends BaseFragment implements View.OnClickListener {
@ -30,6 +31,7 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
private View add_new_post;
private View add_new_post_pic;
private TextView tv_home_title;
private TextView tv_no_data;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
@ -44,6 +46,7 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
add_new_post = root.findViewById(R.id.add_new_post);
tv_home_title = root.findViewById(R.id.tv_home_title);
tv_no_data = root.findViewById(R.id.tv_no_data);
tv_home_title.setText(AccountUtils.getCurFamilyName());
add_new_post.setOnClickListener(this);
add_new_post_pic = root.findViewById(R.id.add_new_post_pic);
@ -77,14 +80,20 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
growListRV.setHasFixedSize(true);
HomeListAdapter homeListAdapter = new HomeListAdapter(null);
growListRV.setAdapter(homeListAdapter);
homeViewModel.getPostListLD().observe(getViewLifecycleOwner(),
new Observer<ArrayList<PostDetailBean>>() {
@Override
public void onChanged(ArrayList<PostDetailBean> postDetailBeans) {
homeListAdapter.updateData(postDetailBeans);
}
});
homeViewModel.getPostListLD().observe(getViewLifecycleOwner(), new Observer<PostModel>() {
@Override
public void onChanged(PostModel postModel) {
if (postModel == null
|| postModel.getPostDetailList() == null
|| postModel.getPostDetailList().size() == 0) {
tv_no_data.setVisibility(View.VISIBLE);
} else {
tv_no_data.setVisibility(View.GONE);
}
homeListAdapter.updateData(postModel);
}
});
homeViewModel.getPostDetailList();
}
@Override
@ -94,10 +103,28 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
startActivity(new Intent(getContext(), NewPostActivity.class));
break;
case R.id.add_new_post_pic:
startActivity(new Intent(getContext(), NewPostActivity.class));
//startActivity(new Intent(getContext(), NewPostActivity.class));
break;
default:
break;
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(RefreshHomeFragment event) {
homeViewModel.getPostDetailList();
}
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
}

View File

@ -1,59 +1,61 @@
package com.yuxihan.sdu.ui.home;
import android.util.Log;
import android.widget.Toast;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.yuxihan.sdu.data.model.PostDetailBean;
import com.yuxihan.sdu.comm.Const;
import com.yuxihan.sdu.comm.SDUApp;
import com.yuxihan.sdu.comm.network.BaseRequestParams;
import com.yuxihan.sdu.data.Result;
import com.yuxihan.sdu.data.UpdateService;
import java.util.ArrayList;
import org.greenrobot.eventbus.EventBus;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class HomeViewModel extends ViewModel {
private MutableLiveData<String> mText;
private MutableLiveData<ArrayList<PostDetailBean>> postListLD;
private MutableLiveData<PostModel> postListLD = new MutableLiveData<>();
public HomeViewModel() {
postListLD = new MutableLiveData<>();
ArrayList<String> picUrlList = new ArrayList<>();
picUrlList.add("http://t9.baidu.com/it/u=188672807," +
"2175104643&fm=79&app=86&f=JPEG?w=1280&h=853");
picUrlList.add("http://t9.baidu.com/it/u=3989902316," +
"3793481456&fm=79&app=86&f=JPEG?w=1280&h=853");
picUrlList.add("http://t9.baidu.com/it/u=1038289730," +
"4068396403&fm=79&app=86&f=JPEG?w=1280&h=853");
picUrlList.add("http://t8.baidu.com/it/u=3346148719," +
"3315269675&fm=79&app=86&f=JPEG?w=666&h=1000");
picUrlList.add("http://t7.baidu.com/it/u=1263664584," +
"1982855955&fm=79&app=86&f=JPEG?w=534&h=800");
picUrlList.add("http://t7.baidu.com/it/u=2832630561," +
"1836266954&fm=79&app=86&f=JPEG?w=667&h=1000");
picUrlList.add("http://t8.baidu.com/it/u=3647266255," +
"2679682355&fm=79&app=86&f=JPEG?w=667&h=1000");
picUrlList.add("http://t7.baidu.com/it/u=558764796," +
"419343714&fm=79&app=86&f=JPEG?w=667&h=1000");
picUrlList.add("http://t7.baidu.com/it/u=4047929277," +
"3427505730&fm=79&app=86&f=JPEG?w=667&h=1000");
ArrayList<PostDetailBean> postList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
postList.add(new PostDetailBean("0000" + i, "雨曦大魔王" + i, "http://jzvd-pic.nathen" +
".cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png", "1" + i,
1590460786L,
i + ":图片大图预览效果是一个库工程,方便导入使用。\n" +
"对不同张数图片进行的适配。\n" +
"根据NineGridView的属性来控制不同的显示模式\n" +
"向QQ空间那样大于9张图片的时候以+号显示\n" +
"图片加载非常的灵活。\n" +
"大图加载的时候有预览动画,大图的尺寸根据原图的尺度", null,
new ArrayList<String>(picUrlList.subList(0, i % 10)), 1 + i, i % 2 == 0, i
));
}
postListLD.setValue(postList);
}
public MutableLiveData<ArrayList<PostDetailBean>> getPostListLD() {
public MutableLiveData<PostModel> getPostListLD() {
return postListLD;
}
public void getPostDetailList() {
UpdateService updateService = SDUApp.getRetrofit().create(UpdateService.class);
Call<Result<PostModel>> call = updateService.getPostDetailList(new BaseRequestParams());
call.enqueue(new Callback<Result<PostModel>>() {
@Override
public void onResponse(Call<Result<PostModel>> call,
Response<Result<PostModel>> response) {
//请求成功返回是一个封装为DataBean的响应
if (null == response.body()) {
Toast.makeText(SDUApp.getAppContext(), "Internal Server Error",
Toast.LENGTH_LONG).show();
return;
}
if (Const.ERROR_CODE_NORMAL.equals(response.body().getErrCode())) {
postListLD.setValue(response.body().getResult());
EventBus.getDefault().post(new RefreshHomeFragment());
} else {
Toast.makeText(SDUApp.getAppContext(), response.body().getErrMsg(),
Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Result<PostModel>> call, Throwable t) {
//请求失败
Log.e("TAG", "请求失败:" + t.getMessage());
Toast.makeText(SDUApp.getAppContext(), "服务器开小差了!",
Toast.LENGTH_LONG).show();
}
});
}
}

View File

@ -109,6 +109,10 @@ public class NewPostActivity extends BaseActivity implements View.OnClickListene
postRequestParams.setBabyId(babyList.get(0).getBabyId() + "");
tv_baby_selected.setText(babyList.get(0).getBabyName());
tv_baby_selected.setTag(babyList.get(0));
} else {
postRequestParams.setBabyId("");
tv_baby_selected.setText("请添加宝宝信息");
tv_baby_selected.setTag(null);
}
}

View File

@ -10,6 +10,8 @@ import com.yuxihan.sdu.comm.SDUApp;
import com.yuxihan.sdu.data.Result;
import com.yuxihan.sdu.data.UpdateService;
import org.greenrobot.eventbus.EventBus;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -32,6 +34,7 @@ public class NewPostViewModel extends ViewModel {
if (Const.ERROR_CODE_NORMAL.equals(response.body().getErrCode())) {
Toast.makeText(SDUApp.getAppContext(), "发送成功",
Toast.LENGTH_LONG).show();
EventBus.getDefault().post(new RefreshHomeFragment());
} else {
Toast.makeText(SDUApp.getAppContext(), response.body().getErrMsg(),
Toast.LENGTH_LONG).show();

View File

@ -0,0 +1,193 @@
package com.yuxihan.sdu.ui.home;
import java.io.Serializable;
import java.util.List;
public class PostModel {
private List<PostDetailBean> postDetailList;
public List<PostDetailBean> getPostDetailList() {
return postDetailList;
}
public void setPostDetailList(List<PostDetailBean> postDetailList) {
this.postDetailList = postDetailList;
}
public static class PostDetailBean implements Serializable {
/**
* familyId : 8
* userId : 20
* postLikeCount : 0
* commentCount : 0
* postId : 8
* familyName : 13262911437的家庭
* userName : 13262911437
* userHead : null
* nickname : 用户1591430254813
* babyName : null
* babyHead : null
* babyId : 2
* postTextContent : 投票
* postVideoUrl : null
* postPicUrls : null
* postTime : 2020-06-07
* isLikedByCurAccount : 0
*/
private int familyId;
private int userId;
private int postLikeCount;
private int commentCount;
private int postId;
private String familyName;
private String userName;
private String userHead;
private String nickname;
private String babyName;
private String babyHead;
private int babyId;
private String postTextContent;
private Object postVideoUrl;
private String postPicUrls;
private String postTime;
private int isLikedByCurAccount;
public int getFamilyId() {
return familyId;
}
public void setFamilyId(int familyId) {
this.familyId = familyId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getPostLikeCount() {
return postLikeCount;
}
public void setPostLikeCount(int postLikeCount) {
this.postLikeCount = postLikeCount;
}
public int getCommentCount() {
return commentCount;
}
public void setCommentCount(int commentCount) {
this.commentCount = commentCount;
}
public int getPostId() {
return postId;
}
public void setPostId(int postId) {
this.postId = postId;
}
public String getFamilyName() {
return familyName;
}
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserHead() {
return userHead;
}
public void setUserHead(String userHead) {
this.userHead = userHead;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getBabyName() {
return babyName;
}
public void setBabyName(String babyName) {
this.babyName = babyName;
}
public String getBabyHead() {
return babyHead;
}
public void setBabyHead(String babyHead) {
this.babyHead = babyHead;
}
public int getBabyId() {
return babyId;
}
public void setBabyId(int babyId) {
this.babyId = babyId;
}
public String getPostTextContent() {
return postTextContent;
}
public void setPostTextContent(String postTextContent) {
this.postTextContent = postTextContent;
}
public Object getPostVideoUrl() {
return postVideoUrl;
}
public void setPostVideoUrl(Object postVideoUrl) {
this.postVideoUrl = postVideoUrl;
}
public String getPostPicUrls() {
return postPicUrls;
}
public void setPostPicUrls(String postPicUrls) {
this.postPicUrls = postPicUrls;
}
public String getPostTime() {
return postTime;
}
public void setPostTime(String postTime) {
this.postTime = postTime;
}
public int getIsLikedByCurAccount() {
return isLikedByCurAccount;
}
public void setIsLikedByCurAccount(int isLikedByCurAccount) {
this.isLikedByCurAccount = isLikedByCurAccount;
}
}
}

View File

@ -0,0 +1,4 @@
package com.yuxihan.sdu.ui.home;
public class RefreshHomeFragment {
}

View File

@ -18,19 +18,22 @@ import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.sackcentury.shinebuttonlib.ShineButton;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.Const;
import com.yuxihan.sdu.comm.util.CommViewHolder;
import com.yuxihan.sdu.comm.util.TimeConvert;
import com.yuxihan.sdu.data.model.PostDetailBean;
import com.yuxihan.sdu.post.PostDetailActivity;
import com.yuxihan.sdu.ui.home.PostModel;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class HomeListAdapter extends RecyclerView.Adapter {
private ArrayList<PostDetailBean> mDataSet;
private PostModel mDataSet;
private Context mContext;
public HomeListAdapter(ArrayList<PostDetailBean> myDataSet) {
public HomeListAdapter(PostModel myDataSet) {
mDataSet = myDataSet;
}
@ -55,16 +58,17 @@ public class HomeListAdapter extends RecyclerView.Adapter {
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
PostDetailBean curPost = mDataSet.get(position);
List<PostModel.PostDetailBean> postDetailList = mDataSet.getPostDetailList();
PostModel.PostDetailBean curPost = postDetailList.get(position);
//findView & setData
ImageView posterHead = CommViewHolder.get(holder.itemView, R.id.poster_head);
Glide.with(mContext).load(curPost.getUserHead()).into(posterHead);
Glide.with(mContext).load(curPost.getUserHead()).placeholder(R.drawable.ic_head_default).into(posterHead);
TextView posterName = CommViewHolder.get(holder.itemView, R.id.tv_poster_name);
posterName.setText(curPost.getUserName());
posterName.setText(curPost.getNickname());
TextView postTime = CommViewHolder.get(holder.itemView, R.id.tv_post_time);
postTime.setText(TimeConvert.getTimeElapse(curPost.getPostTime()));
postTime.setText(TimeConvert.getTimeElapse(new Date().getTime()));
TextView postContentText = CommViewHolder.get(holder.itemView, R.id.tv_post_content_text);
postContentText.setText(curPost.getPostTextContent());
@ -79,16 +83,16 @@ public class HomeListAdapter extends RecyclerView.Adapter {
tvLikeCount.setText(curPost.getPostLikeCount() + "");
ShineButton shineButton = CommViewHolder.get(holder.itemView, R.id.bt_like);
shineButton.setChecked(curPost.isLikedByCurAccount());
shineButton.setChecked(curPost.getIsLikedByCurAccount() == 1);
shineButton.setOnCheckStateChangeListener(new ShineButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(View view, boolean checked) {
if (checked) {
curPost.setLikedByCurAccount(true);
curPost.setIsLikedByCurAccount(1);
curPost.setPostLikeCount(curPost.getPostLikeCount() + 1);
tvLikeCount.setText(curPost.getPostLikeCount() + "");
} else {
curPost.setLikedByCurAccount(false);
curPost.setIsLikedByCurAccount(0);
curPost.setPostLikeCount(curPost.getPostLikeCount() - 1);
tvLikeCount.setText(curPost.getPostLikeCount() + "");
}
@ -98,22 +102,26 @@ public class HomeListAdapter extends RecyclerView.Adapter {
NineGridView ngvPicContainer = CommViewHolder.get(holder.itemView, R.id.ngv_pic_container);
ArrayList<ImageInfo> imageInfoList = new ArrayList<>();
ArrayList<String> postPicUrls = curPost.getPostPicUrls();
if (postPicUrls != null) {
for (String picUrl : postPicUrls) {
ImageInfo info = new ImageInfo();
info.setThumbnailUrl(picUrl);
info.setBigImageUrl(picUrl);
imageInfoList.add(info);
String postPicUrls1 = curPost.getPostPicUrls();
if (null != postPicUrls1) {
String[] split = postPicUrls1.split(Const.URL_Separator);
if (split.length > 0) {
for (String picUrl : split) {
ImageInfo info = new ImageInfo();
info.setThumbnailUrl(picUrl);
info.setBigImageUrl(picUrl);
imageInfoList.add(info);
}
}
ngvPicContainer.setAdapter(new NineGridViewClickAdapter(mContext, imageInfoList));
}
ngvPicContainer.setAdapter(new NineGridViewClickAdapter(mContext, imageInfoList));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(mContext,PostDetailActivity.class);
Intent intent = new Intent(mContext, PostDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("key",curPost);
bundle.putSerializable("key", curPost);
intent.putExtras(bundle);
mContext.startActivity(intent);
}
@ -123,10 +131,14 @@ public class HomeListAdapter extends RecyclerView.Adapter {
@Override
public int getItemCount() {
return mDataSet == null ? 0 : mDataSet.size();
if (mDataSet == null) {
return 0;
}
List<PostModel.PostDetailBean> postDetailList = mDataSet.getPostDetailList();
return postDetailList == null ? 0 : postDetailList.size();
}
public void updateData(ArrayList<PostDetailBean> myDataSet) {
public void updateData(PostModel myDataSet) {
mDataSet = myDataSet;
notifyDataSetChanged();
}

View File

@ -1,22 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.grow.GrowFragment">
<TextView
android:id="@+id/text_dashboard"
<RelativeLayout
android:id="@+id/rl_grow_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="75dp"
android:background="@color/white_bg"
android:gravity="center_vertical"
android:paddingTop="25dp"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/add_new_post_pic"
android:visibility="gone"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_cam" />
<TextView
android:layout_width="wrap_content"
android:id="@+id/tv_home_title"
android:layout_marginStart="12dp"
android:layout_height="wrap_content"
android:text="@string/grow_record"
android:textColor="@color/text_black"
android:textSize="20sp" />
<ImageView
android:id="@+id/add_new_post"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="12dp"
android:padding="2dp"
android:src="@drawable/ic_add" />
</RelativeLayout>
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintTop_toBottomOf="@+id/rl_grow_title">
<!-- app:tr_head_height="100dp"
app:tr_wave_height="180dp"-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_grow_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
</LinearLayout>

View File

@ -18,17 +18,17 @@
<ImageView
android:id="@+id/add_new_post_pic"
android:visibility="gone"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_cam" />
android:src="@drawable/ic_cam"
android:visibility="gone" />
<TextView
android:layout_width="wrap_content"
android:id="@+id/tv_home_title"
android:layout_marginStart="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="@string/nav_home"
android:textColor="@color/text_black"
android:textSize="20sp" />
@ -43,21 +43,34 @@
android:src="@drawable/ic_add" />
</RelativeLayout>
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
android:id="@+id/refreshLayout"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintTop_toBottomOf="@+id/rl_grow_title">
<!-- app:tr_head_height="100dp"
app:tr_wave_height="180dp"-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_grow_list"
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
app:layout_constraintHeight_percent="0.5">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_grow_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
<TextView
android:id="@+id/tv_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="@string/no_data"
android:textSize="20sp"
android:visibility="gone"
tools:visibility="visible" />
</RelativeLayout>
</LinearLayout>

View File

@ -85,5 +85,15 @@
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/tv_home_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/exit"
android:textSize="15sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View File

@ -1,8 +1,8 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="63dp"
xmlns:tools="http://schemas.android.com/tools"
android:padding="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
@ -19,10 +19,9 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/poster_head"
tools:text="四脚吞金兽"
android:textColor="@color/black"
android:textSize="15sp"
/>
tools:text="四脚吞金兽" />
<TextView
android:id="@+id/tv_post_time"
@ -33,4 +32,24 @@
android:textColor="@color/text_hint"
android:textSize="12sp"
tools:text="二小时前" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/baby_head"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/tv_baby_name"
android:src="@drawable/wel_icon" />
<TextView
android:id="@+id/tv_baby_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textColor="@color/text_red"
android:textSize="15sp"
tools:text="四脚吞金兽" />
</RelativeLayout>

View File

@ -54,4 +54,7 @@
<string name="baby_birthday_show">宝宝生日:%1$s</string>
<string name="code_show">邀请码:%1$s</string>
<string name="loading">宝宝加载中。。。</string>
<string name="grow_record">成长记录</string>
<string name="exit">退出</string>
<string name="no_data">暂时没有数据\n点击右上角去记录吧~</string>
</resources>