1.宝宝列表

2.新增宝宝
This commit is contained in:
BA7LZD 2020-06-06 22:50:34 +08:00
parent 0c970fdccb
commit bcc4879db5
22 changed files with 1130 additions and 20 deletions

View File

@ -70,6 +70,8 @@ dependencies {
implementation('com.github.ihsanbal:LoggingInterceptor:3.1.0') {
exclude group: 'org.json', module: 'json'
}
//EventBus
implementation 'org.greenrobot:eventbus:3.2.0'
//
//implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.5.6'
//

View File

@ -22,7 +22,8 @@
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute"
tools:replace="android:allowBackup">
<activity android:name=".ui.home.NewPostActivity"></activity>
<activity android:name=".ui.baby.AddBabyActivity"></activity>
<activity android:name=".ui.home.NewPostActivity" />
<activity
android:name=".ui.account.home.InputCodeActivity"
android:windowSoftInputMode="stateVisible" />

View File

@ -86,7 +86,7 @@ public class SDUApp extends Application {
.build();
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
httpClientBuilder.addInterceptor(httpLoggingInterceptor);
httpClientBuilder.connectTimeout(60, TimeUnit.SECONDS);
httpClientBuilder.connectTimeout(10, TimeUnit.SECONDS);
mRetrofit = new Retrofit.Builder()
.client(httpClientBuilder.build())

View File

@ -9,6 +9,8 @@ import com.yuxihan.sdu.data.model.SMSParams;
import com.yuxihan.sdu.data.model.UpdateNicknameParams;
import com.yuxihan.sdu.data.model.UpdateUserHeadParams;
import com.yuxihan.sdu.ui.account.HomeBean;
import com.yuxihan.sdu.ui.baby.AddBabyParams;
import com.yuxihan.sdu.ui.baby.model.BabyInfoModel;
import com.yuxihan.sdu.ui.home.PostRequestParams;
import retrofit2.Call;
@ -57,4 +59,14 @@ public interface UpdateService {
@Body PostRequestParams params
);
@POST("/addBaby")
Call<Result> addBaby(
@Body AddBabyParams params
);
@POST("/getBabyList")
Call<Result<BabyInfoModel>> getBabyList(
@Body BaseRequestParams params
);
}

View File

@ -0,0 +1,371 @@
package com.yuxihan.sdu.ui.baby;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.lifecycle.ViewModelProvider;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.listener.OnResultCallbackListener;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.BaseActivity;
import com.yuxihan.sdu.comm.SDUApp;
import com.yuxihan.sdu.comm.util.AccountUtils;
import com.yuxihan.sdu.comm.util.DataUtil;
import com.yuxihan.sdu.comm.util.GlideEngine;
import com.yuxihan.sdu.comm.widget.ActionSheetDialog;
import com.yuxihan.sdu.comm.widget.CommonDialog;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.util.Calendar;
import java.util.List;
public class AddBabyActivity extends BaseActivity implements View.OnClickListener,
DatePickerDialog.OnDateSetListener {
private static final String TAG = "AddBabyActivity";
private TextView tv_birthday;
private TextView tv_baby_name;
private TextView tv_baby_gender;
private ImageView iv_baby_head;
private String selectedDate;
private AddBabyParams addBabyParams = new AddBabyParams();
AddBabyViewModel addBabyViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_baby);
addBabyViewModel = new ViewModelProvider(this).get(AddBabyViewModel.class);
initView();
}
private void initView() {
findViewById(R.id.iv_back).setOnClickListener(this);
findViewById(R.id.tv_save).setOnClickListener(this);
findViewById(R.id.rl_baby_head).setOnClickListener(this);
findViewById(R.id.rl_baby_birthday).setOnClickListener(this);
findViewById(R.id.rl_baby_gender).setOnClickListener(this);
findViewById(R.id.rl_baby_name).setOnClickListener(this);
tv_birthday = findViewById(R.id.tv_birthday);
tv_baby_name = findViewById(R.id.tv_baby_name);
tv_baby_gender = findViewById(R.id.tv_baby_gender);
iv_baby_head = findViewById(R.id.iv_baby_head);
// addBabyViewModel.getUpdateUserHead().observe(AddBabyActivity.this,
// new Observer<UpdateUserHeadState>() {
// @Override
// public void onChanged(UpdateUserHeadState updateUserHeadState) {
// Toast.makeText(SDUApp.getAppContext(),
// "加载头像:" + updateUserHeadState.getUpdatedUrl(),
// Toast.LENGTH_SHORT).show();
// if (!DataUtil.isEmpty(updateUserHeadState.getUpdatedUrl())) {
// Glide.with(AddBabyActivity.this).load(updateUserHeadState
// .getUpdatedUrl()).placeholder(R.drawable.ic_baby_head).into
// (iv_baby_head);
// }
// }
// });
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(UpdateBabyHeadEvent event) {
if (!DataUtil.isEmpty(event.getHeadUrl())) {
Glide.with(AddBabyActivity.this).load(event.getHeadUrl()).placeholder(R.drawable.ic_baby_head).into(iv_baby_head);
addBabyParams.setBabyHead(event.getHeadUrl());
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(AddBabySuccessEvent event) {
setResult(0);
finish();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_back:
finish();
break;
case R.id.tv_save:
checkParams();
break;
case R.id.rl_baby_head:
updateUserHead();
break;
case R.id.rl_baby_birthday:
Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
AddBabyActivity.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.show(getSupportFragmentManager(), "Datepickerdialog");
break;
case R.id.rl_baby_name:
updateNickname();
break;
case R.id.rl_baby_gender:
selectBabyGender();
break;
default:
break;
}
}
private void checkParams() {
addBabyParams.setBabyBirthday(tv_birthday.getText().toString().trim());
if ("".equals(tv_baby_gender.getText().toString())) {
addBabyParams.setBabyGender(0);
} else if ("".equals(tv_baby_gender.getText().toString())) {
addBabyParams.setBabyGender(1);
} else {
addBabyParams.setBabyGender(-1);
}
addBabyParams.setBabyName(tv_baby_name.getText().toString());
if (addBabyParams.isValid()) {
addBabyViewModel.addBaby(addBabyParams);
} else {
Toast.makeText(SDUApp.getAppContext(), "信息输入不全~", Toast.LENGTH_LONG).show();
}
}
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
String date = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;
long l = TimeUtils.string2Millis(date, "yyyy-MM-dd");
selectedDate = TimeUtils.millis2String(l, "yyyy-MM-dd");
tv_birthday.setText(selectedDate);
}
/**
* 修改昵称
*/
private void updateNickname() {
final CommonDialog dialog = new CommonDialog(AddBabyActivity.this);
dialog.setImageResId(R.mipmap.ic_launcher)
.setTitle("设置宝宝姓名")
.setEtHint("请输入宝宝姓名")
.setSingle(false).setOnClickBottomListener(new CommonDialog.OnClickBottomListener() {
@Override
public void onPositiveClick(String result) {
dialog.dismiss();
if (!TextUtils.isEmpty(result)) {
tv_baby_name.setText(result);
}
}
@Override
public void onNegativeClick() {
dialog.dismiss();
}
}).show();
}
/**
* 选择性别
*/
private void selectBabyGender() {
String[] fileFrom = new String[]{"", ""};
ActionSheetDialog actionSheetDialog = new ActionSheetDialog(
AddBabyActivity.this).builder().setCancelable(false)
.setCanceledOnTouchOutside(true);
for (String s : fileFrom) {
actionSheetDialog.addSheetItem(s,
ActionSheetDialog.SheetItemColor.Blue,
new ActionSheetDialog.OnSheetItemClickListener() {
@Override
public void onClick(int which) {
if (1 == which) {
tv_baby_gender.setText("");
} else if (2 == which) {
tv_baby_gender.setText("");
}
}
});
}
actionSheetDialog.show();
}
/**
* 获取裁减的文件
*/
private void getFile(int index) {
switch (index) {
case 1:
takePic();
break;
case 2:
gallery();
break;
}
}
/**
* 修改头像
*/
private void updateUserHead() {
String[] fileFrom = new String[]{"相机", "图库"};
ActionSheetDialog actionSheetDialog = new ActionSheetDialog(
AddBabyActivity.this).builder().setCancelable(false)
.setCanceledOnTouchOutside(true);
for (String s : fileFrom) {
actionSheetDialog.addSheetItem(s,
ActionSheetDialog.SheetItemColor.Blue,
new ActionSheetDialog.OnSheetItemClickListener() {
@Override
public void onClick(int which) {
getFile(which);
}
});
}
actionSheetDialog.show();
}
//去图库选择
private void gallery() {
PictureSelector.create(this)
.openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()图片.ofImage()
// 视频.ofVideo()音频.ofAudio()
.theme(R.style.picture_white_style)// 主题样式设置 具体参考 values/styles 用法R.style
// .picture_white_style
.maxSelectNum(1)// 最大图片选择数量
.minSelectNum(1)// 最小选择数量
.isCamera(false)// 是否显示拍照按钮
.imageSpanCount(4)// 每行显示个数
.isCompress(true)// 是否压缩 true or false
.compressQuality(60)
.maxSelectNum(1)// 最大图片选择数量
.isZoomAnim(true)// 图片列表点击 缩放效果 默认true
.synOrAsy(true)//同步true或异步false 压缩 默认同步
.glideOverride(120, 120)// glide 加载宽高越小图片列表越流畅但会影响列表图片浏览的清晰度
//.selectionMedia(picList)// 是否传入已选图片
//.minimumCompressSize(100)// 小于100kb的图片不压缩
.loadImageEngine(GlideEngine.createGlideEngine())
.isEnableCrop(true)//是否开启裁剪
.circleDimmedLayer(true)// 是否开启圆形裁剪
.showCropGrid(false)
.showCropFrame(false)
.withAspectRatio(1, 1)
.forResult(new AddBabyActivity.PicResultCallback());//结果回调
}
//拍照
private void takePic() {
//单独拍照
PictureSelector.create(this)
.openCamera(PictureMimeType.ofImage())
.theme(R.style.picture_white_style)// 主题样式设置 具体参考 values/styles
.minSelectNum(1)// 最小选择数量
.isCompress(true)
.compressQuality(60)
.selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选
.isCamera(false)// 是否显示拍照按钮
.glideOverride(120, 120)// glide 加载宽高越小图片列表越流畅但会影响列表图片浏览的清晰度
//.selectionMedia(picList)// 是否传入已选图片
.imageSpanCount(4)// 每行显示个数
.maxSelectNum(1)// 最大图片选择数量
.isZoomAnim(true)// 图片列表点击 缩放效果 默认true
.synOrAsy(true)//同步true或异步false 压缩 默认同步
//.minimumCompressSize(100)// 小于100kb的图片不压缩
.isEnableCrop(true)//是否开启裁剪
.circleDimmedLayer(true)// 是否开启圆形裁剪
.showCropGrid(false)
.showCropFrame(false)
.withAspectRatio(1, 1)
.forResult(new AddBabyActivity.CameraResultCallback());//结果回调
}
/**
* 图库返回结果回调
*/
private class PicResultCallback implements OnResultCallbackListener<LocalMedia> {
@Override
public void onResult(List<LocalMedia> result) {
for (LocalMedia media : result) {
Log.i(TAG, "PicResultCallback");
Log.i(TAG, "是否压缩:" + media.isCompressed());
Log.i(TAG, "压缩:" + media.getCompressPath());//取这个值
Log.i(TAG, "原图:" + media.getPath());
Log.i(TAG, "是否裁剪:" + media.isCut());
Log.i(TAG, "裁剪:" + media.getCutPath());
Log.i(TAG, "是否开启原图:" + media.isOriginal());
Log.i(TAG, "原图路径:" + media.getOriginalPath());
Log.i(TAG, "Android Q 特有Path:" + media.getAndroidQToPath());
Log.i(TAG, "宽高: " + media.getWidth() + "x" + media.getHeight());
Log.i(TAG, "Size: " + media.getSize());
//TODO:上传 media.getCompressPath()
addBabyViewModel.upload(File.separator + AccountUtils.getCurUserName() + File.separator + System.currentTimeMillis(), media.getCompressPath());
}
}
@Override
public void onCancel() {
Log.i(TAG, "PictureSelector Cancel");
}
}
/**
* 相机返回结果回调
*/
private class CameraResultCallback implements OnResultCallbackListener<LocalMedia> {
@Override
public void onResult(List<LocalMedia> result) {
for (LocalMedia media : result) {
Log.i(TAG, "CameraResultCallback");
Log.i(TAG, "是否压缩:" + media.isCompressed());
Log.i(TAG, "压缩:" + media.getCompressPath());
Log.i(TAG, "原图:" + media.getPath());
Log.i(TAG, "是否裁剪:" + media.isCut());
Log.i(TAG, "裁剪:" + media.getCutPath());
Log.i(TAG, "是否开启原图:" + media.isOriginal());
Log.i(TAG, "原图路径:" + media.getOriginalPath());
Log.i(TAG, "Android Q 特有Path:" + media.getAndroidQToPath());
Log.i(TAG, "宽高: " + media.getWidth() + "x" + media.getHeight());
Log.i(TAG, "Size: " + media.getSize());
//TODO:上传 media.getCompressPath()
addBabyViewModel.upload(File.separator + AccountUtils.getCurUserName() + File.separator + System.currentTimeMillis(), media.getCompressPath());
}
}
@Override
public void onCancel() {
Log.i(TAG, "PictureSelector Cancel");
}
}
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
}

View File

@ -0,0 +1,61 @@
package com.yuxihan.sdu.ui.baby;
import android.text.TextUtils;
import com.yuxihan.sdu.comm.network.BaseRequestParams;
public class AddBabyParams extends BaseRequestParams {
/**
* userName : 15919474525
* babyName : 猪胖
* familyId : 1
* babyHead : 45612121545
* babyGender : 1
* token : f5a43874-d56b-48dd-a5cf-7311598b857b
* babyBirthday : 2019-09-14
*/
private String babyName;
private String babyHead;
private int babyGender;
private String babyBirthday;
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 getBabyGender() {
return babyGender;
}
public void setBabyGender(int babyGender) {
this.babyGender = babyGender;
}
public String getBabyBirthday() {
return babyBirthday;
}
public void setBabyBirthday(String babyBirthday) {
this.babyBirthday = babyBirthday;
}
public boolean isValid() {
return !TextUtils.isEmpty(babyName)
&& !TextUtils.isEmpty(babyBirthday)
&& babyGender != -1;
}
}

View File

@ -0,0 +1,5 @@
package com.yuxihan.sdu.ui.baby;
public class AddBabySuccessEvent {
}

View File

@ -0,0 +1,113 @@
package com.yuxihan.sdu.ui.baby;
import android.util.Log;
import android.widget.Toast;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.tencent.cos.xml.exception.CosXmlClientException;
import com.tencent.cos.xml.exception.CosXmlServiceException;
import com.tencent.cos.xml.listener.CosXmlProgressListener;
import com.tencent.cos.xml.listener.CosXmlResultListener;
import com.tencent.cos.xml.model.CosXmlRequest;
import com.tencent.cos.xml.model.CosXmlResult;
import com.tencent.cos.xml.transfer.COSXMLUploadTask;
import com.tencent.cos.xml.transfer.TransferState;
import com.tencent.cos.xml.transfer.TransferStateListener;
import com.yuxihan.sdu.comm.Const;
import com.yuxihan.sdu.comm.SDUApp;
import com.yuxihan.sdu.comm.util.UploadTencentSDK;
import com.yuxihan.sdu.data.Result;
import com.yuxihan.sdu.data.UpdateService;
import com.yuxihan.sdu.ui.info.UpdateUserHeadState;
import org.greenrobot.eventbus.EventBus;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class AddBabyViewModel extends ViewModel {
private MutableLiveData<UpdateUserHeadState> updateUserHead = new MutableLiveData<>();
public MutableLiveData<UpdateUserHeadState> getUpdateUserHead() {
return updateUserHead;
}
public void addBaby(AddBabyParams params) {
UpdateService updateService = SDUApp.getRetrofit().create(UpdateService.class);
Call<Result> call = updateService.addBaby(params);
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_SHORT).show();
EventBus.getDefault().post(new AddBabySuccessEvent());
} 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();
}
});
}
/**
* 上传
*
* @params cosPath 上传到 COS 的路径
* @params localPath 本地文件路径
*/
public void upload(String cosPath, String localPath) {
// 开始上传并返回生成的 COSXMLUploadTask
COSXMLUploadTask cosxmlUploadTask =
UploadTencentSDK.getTransferManager().upload(Const.BUCKET_NAME, cosPath,
localPath, null);
// 设置上传状态监听
cosxmlUploadTask.setTransferStateListener(new TransferStateListener() {
@Override
public void onStateChanged(final TransferState state) {
}
});
// 设置上传进度监听
cosxmlUploadTask.setCosXmlProgressListener(new CosXmlProgressListener() {
@Override
public void onProgress(final long complete, final long target) {
}
});
// 设置结果监听
cosxmlUploadTask.setCosXmlResultListener(new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
// updateUserHead.setValue(new UpdateUserHeadState(result.accessUrl));
EventBus.getDefault().post(new UpdateBabyHeadEvent(result.accessUrl));
}
@Override
public void onFail(CosXmlRequest request, CosXmlClientException exception,
CosXmlServiceException serviceException) {
Toast.makeText(SDUApp.getAppContext(), "头像上传失败,请重试!", Toast.LENGTH_LONG).show();
}
});
}
}

View File

@ -4,13 +4,20 @@ import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.BaseActivity;
import com.yuxihan.sdu.ui.baby.adapter.BabyListAdapter;
import com.yuxihan.sdu.ui.baby.model.BabyInfoModel;
public class BabyListActivity extends BaseActivity implements View.OnClickListener {
BabyListViewModel babyListViewModel;
RecyclerView rv_baby_list;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -18,6 +25,23 @@ public class BabyListActivity extends BaseActivity implements View.OnClickListen
setContentView(R.layout.activity_baby_list);
babyListViewModel = new ViewModelProvider(this, new BabyListViewModelFactory())
.get(BabyListViewModel.class);
initView();
}
private void initView() {
findViewById(R.id.tv_add_baby).setOnClickListener(this);
findViewById(R.id.iv_back).setOnClickListener(this);
rv_baby_list = findViewById(R.id.rv_baby_list);
BabyListAdapter babyListAdapter = new BabyListAdapter(null);
rv_baby_list.setAdapter(babyListAdapter);
rv_baby_list.setLayoutManager(new LinearLayoutManager(this));
babyListViewModel.getBabyInfoModel().observe(this, new Observer<BabyInfoModel>() {
@Override
public void onChanged(BabyInfoModel babyInfoModel) {
babyListAdapter.setData(babyInfoModel);
}
});
babyListViewModel.getBabyList();
}
@Override
@ -27,10 +51,18 @@ public class BabyListActivity extends BaseActivity implements View.OnClickListen
finish();
break;
case R.id.tv_add_baby:
startActivity(new Intent(BabyListActivity.this, BabyListActivity.class));
startActivityForResult(new Intent(BabyListActivity.this, AddBabyActivity.class), 0);
break;
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 0) {
babyListViewModel.getBabyList();
}
}
}

View File

@ -1,6 +1,5 @@
package com.yuxihan.sdu.ui.baby;
import android.util.Log;
import android.widget.Toast;
import androidx.lifecycle.MutableLiveData;
@ -8,25 +7,30 @@ import androidx.lifecycle.ViewModel;
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 com.yuxihan.sdu.data.model.DataBean;
import com.yuxihan.sdu.data.model.LoggedInUser;
import com.yuxihan.sdu.data.model.LoginParams;
import com.yuxihan.sdu.ui.baby.model.BabyInfoModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class BabyListViewModel extends ViewModel {
private MutableLiveData<LoggedInUser> loggedInUser = new MutableLiveData<>();
private MutableLiveData<BabyInfoModel> babyInfoModel = new MutableLiveData<>();
public void login1(final String username, String password) {
public MutableLiveData<BabyInfoModel> getBabyInfoModel() {
return babyInfoModel;
}
public void getBabyList() {
UpdateService updateService = SDUApp.getRetrofit().create(UpdateService.class);
Call<DataBean> call = updateService.login(new LoginParams(username, password));
call.enqueue(new Callback<DataBean>() {
Call<Result<BabyInfoModel>> call = updateService.getBabyList(new BaseRequestParams());
call.enqueue(new Callback<Result<BabyInfoModel>>() {
@Override
public void onResponse(Call<DataBean> call, Response<DataBean> response) {
public void onResponse(Call<Result<BabyInfoModel>> call,
Response<Result<BabyInfoModel>> response) {
//请求成功返回是一个封装为DataBean的响应
if (null == response.body()) {
Toast.makeText(SDUApp.getAppContext(), "Internal Server Error",
@ -34,18 +38,18 @@ public class BabyListViewModel extends ViewModel {
return;
}
if (Const.ERROR_CODE_NORMAL.equals(response.body().getErrCode())) {
babyInfoModel.setValue(response.body().getResult());
} else {
loggedInUser.setValue(new LoggedInUser(username, response.body().getErrMsg(),
false));
Toast.makeText(SDUApp.getAppContext(), response.body().getErrMsg(),
Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<DataBean> call, Throwable t) {
public void onFailure(Call<Result<BabyInfoModel>> call, Throwable t) {
//请求失败
Log.e("TAG", "请求失败:" + t.getMessage());
loggedInUser.setValue(new LoggedInUser(username, "服务器开小差了!", false));
Toast.makeText(SDUApp.getAppContext(), "服务器开小差了!",
Toast.LENGTH_LONG).show();
}
});
}

View File

@ -0,0 +1,17 @@
package com.yuxihan.sdu.ui.baby;
public class UpdateBabyHeadEvent {
private String headUrl;
public UpdateBabyHeadEvent(String headUrl) {
this.headUrl = headUrl;
}
public String getHeadUrl() {
return headUrl;
}
public void setHeadUrl(String headUrl) {
this.headUrl = headUrl;
}
}

View File

@ -0,0 +1,72 @@
package com.yuxihan.sdu.ui.baby.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.yuxihan.sdu.R;
import com.yuxihan.sdu.comm.util.CommViewHolder;
import com.yuxihan.sdu.ui.baby.model.BabyInfoModel;
import com.yuxihan.sdu.ui.home.adapter.HomeListAdapter;
public class BabyListAdapter extends RecyclerView.Adapter {
private BabyInfoModel babyInfoModel;
private Context mContext;
public BabyListAdapter(BabyInfoModel babyInfoModel) {
this.babyInfoModel = babyInfoModel;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
mContext = parent.getContext();
ViewGroup v = (ViewGroup) LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_baby_list, parent, false);
return new HomeListAdapter.MyViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
BabyInfoModel.BabyBean curBaby = babyInfoModel.getBabyList().get(position);
ImageView posterHead = CommViewHolder.get(holder.itemView, R.id.civ_baby_head);
Glide.with(mContext).load(curBaby.getBabyHead()).placeholder(R.drawable.ic_baby_head).into(posterHead);
TextView posterName = CommViewHolder.get(holder.itemView, R.id.tv_baby_name);
posterName.setText(curBaby.getBabyName());
TextView tv_birthday = CommViewHolder.get(holder.itemView, R.id.tv_birthday);
tv_birthday.setText(mContext.getString(R.string.baby_birthday_show,
curBaby.getBabyBirthday()));
CommViewHolder.get(holder.itemView, R.id.ll_delete_baby).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
CommViewHolder.get(holder.itemView, R.id.rl_edit_baby).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
@Override
public int getItemCount() {
if (null == babyInfoModel) {
return 0;
}
return null == babyInfoModel.getBabyList() ? 0 : babyInfoModel.getBabyList().size();
}
public void setData(BabyInfoModel babyInfoModel) {
this.babyInfoModel = babyInfoModel;
notifyDataSetChanged();
}
}

View File

@ -0,0 +1,102 @@
package com.yuxihan.sdu.ui.baby.model;
import java.util.List;
public class BabyInfoModel {
private List<BabyBean> babyList;
public List<BabyBean> getBabyList() {
return babyList;
}
public void setBabyList(List<BabyBean> babyList) {
this.babyList = babyList;
}
public static class BabyBean {
/**
* familyId : 8
* babyId : 2
* babyName : 毫无意义
* babyBirthday : 2020-06-06
* isSelectBaby : 0
* babyGender : 1
* familyName : null
* babyHead : https://a-1300518338.cos.ap-guangzhou.myqcloud.com/13262911437/1591450382931
*/
private int familyId;
private int babyId;
private String babyName;
private String babyBirthday;
private int isSelectBaby;
private int babyGender;
private Object familyName;
private String babyHead;
public int getFamilyId() {
return familyId;
}
public void setFamilyId(int familyId) {
this.familyId = familyId;
}
public int getBabyId() {
return babyId;
}
public void setBabyId(int babyId) {
this.babyId = babyId;
}
public String getBabyName() {
return babyName;
}
public void setBabyName(String babyName) {
this.babyName = babyName;
}
public String getBabyBirthday() {
return babyBirthday;
}
public void setBabyBirthday(String babyBirthday) {
this.babyBirthday = babyBirthday;
}
public int getIsSelectBaby() {
return isSelectBaby;
}
public void setIsSelectBaby(int isSelectBaby) {
this.isSelectBaby = isSelectBaby;
}
public int getBabyGender() {
return babyGender;
}
public void setBabyGender(int babyGender) {
this.babyGender = babyGender;
}
public Object getFamilyName() {
return familyName;
}
public void setFamilyName(Object familyName) {
this.familyName = familyName;
}
public String getBabyHead() {
return babyHead;
}
public void setBabyHead(String babyHead) {
this.babyHead = babyHead;
}
}
}

View File

@ -6,6 +6,7 @@ import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;
@ -17,6 +18,7 @@ import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
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;
@ -27,6 +29,7 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
private HomeViewModel homeViewModel;
private View add_new_post;
private View add_new_post_pic;
private TextView tv_home_title;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
@ -39,8 +42,9 @@ public class HomeFragment extends BaseFragment implements View.OnClickListener {
private void initView(View root) {
add_new_post = root.findViewById(R.id.add_new_post);
tv_home_title = root.findViewById(R.id.tv_home_title);
tv_home_title.setText(AccountUtils.getCurFamilyName());
add_new_post.setOnClickListener(this);
add_new_post_pic = root.findViewById(R.id.add_new_post_pic);
add_new_post_pic.setOnClickListener(this);

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M799.2,874.4c0,34.4 -28,62.4 -62.4,62.4L287.2,936.8c-34.4,0 -62.4,-28 -62.4,-62.4L224.8,212h574.4v662.4zM349.6,100c0,-7.2 5.6,-12.8 12.8,-12.8h300c7.2,0 12.8,5.6 12.8,12.8v37.6L349.6,137.6L349.6,100zM986.4,137.6L749.6,137.6L749.6,100c0,-48 -39.2,-87.2 -87.2,-87.2h-300c-48,0 -87.2,39.2 -87.2,87.2v37.6L37.6,137.6C16.8,137.6 0,154.4 0,175.2s16.8,37.6 37.6,37.6h112v661.6c0,76 61.6,137.6 137.6,137.6h449.6c76,0 137.6,-61.6 137.6,-137.6L874.4,212h112c20.8,0 37.6,-16.8 37.6,-37.6s-16.8,-36.8 -37.6,-36.8zM512,824c20.8,0 37.6,-16.8 37.6,-37.6v-400c0,-20.8 -16.8,-37.6 -37.6,-37.6s-37.6,16.8 -37.6,37.6v400c0,20.8 16.8,37.6 37.6,37.6m-175.2,0c20.8,0 37.6,-16.8 37.6,-37.6v-400c0,-20.8 -16.8,-37.6 -37.6,-37.6s-37.6,16.8 -37.6,37.6v400c0.8,20.8 17.6,37.6 37.6,37.6m350.4,0c20.8,0 37.6,-16.8 37.6,-37.6v-400c0,-20.8 -16.8,-37.6 -37.6,-37.6s-37.6,16.8 -37.6,37.6v400c0,20.8 16.8,37.6 37.6,37.6"
android:fillColor="#C6C7CB"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M309.18,563.78a8.42,8.42 0,0 0,-1.57 2.75l-49.92,183.07a31.42,31.42 0,0 0,7.97 30.27,31.3 31.3,0 0,0 30.11,7.87l181.7,-49.57c0.29,0 0.42,0.26 0.64,0.26a7.9,7.9 0,0 0,5.7 -2.37l485.82,-486.08A77.6,77.6 0,0 0,992 194.43c0,-24.26 -10.3,-48.54 -28.32,-66.56l-45.86,-45.98a95.14,95.14 0,0 0,-66.53 -28.35c-21.44,0 -41.09,7.94 -55.58,22.34L309.92,562.11c-0.51,0.48 -0.35,1.15 -0.74,1.7M922.11,202.43l-48.26,48.22 -78.24,-79.52 47.58,-47.58c7.49,-7.55 22.11,-6.46 30.72,2.18l45.89,45.98c4.8,4.83 7.55,11.17 7.55,17.44a18.62,18.62 0,0 1,-5.25 13.28M395.58,571.42L746.14,220.61l78.27,79.62 -349.89,350.11 -78.94,-78.91zM331.71,713.66l25.34,-93.06 67.55,67.62 -92.9,25.44zM952.9,395.04c-18.4,0 -33.5,14.98 -33.57,33.6v453.18c0,23.78 -19.26,43.04 -43.04,43.04L110.11,924.86a43.14,43.14 0,0 1,-43.1 -43.04L67.01,142.14c0,-23.78 19.36,-43.1 43.1,-43.1h493.47a33.5,33.5 0,0 0,0 -67.04L105.02,32A105.15,105.15 0,0 0,0 137.09v749.86A105.12,105.12 0,0 0,105.02 992h776.32a105.12,105.12 0,0 0,105.06 -105.06L986.4,428.45a33.6,33.6 0,0 0,-33.5 -33.41z"
android:fillColor="#C6C7CB"/>
</vector>

View File

@ -0,0 +1,176 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@color/divider_gray"
android:orientation="vertical"
tools:context=".ui.baby.AddBabyActivity">
<RelativeLayout
android:id="@+id/rl_account_title"
android:layout_width="match_parent"
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/iv_back"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="14dp"
android:src="@drawable/ic_arrow_left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="12dp"
android:text="@string/add_baby"
android:textColor="@color/text_black"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="12dp"
android:paddingTop="12dp"
android:text="@string/save"
android:textColor="@color/black"
android:textSize="20sp" />
</RelativeLayout>
<include layout="@layout/view_divider" />
<LinearLayout
android:id="@+id/rl_baby_head"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/iv_baby_head"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="@drawable/ic_baby_head" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:text="@string/click_set_baby_head" />
</LinearLayout>
<include layout="@layout/view_divider" />
<RelativeLayout
android:id="@+id/rl_baby_name"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/white"
android:gravity="center_vertical"
android:paddingStart="12dp"
android:paddingEnd="12dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/baby_name"
android:textColor="@color/black"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_baby_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/ic_next_name"
android:textSize="16sp"
tools:text="韩雨曦" />
<ImageView
android:id="@+id/ic_next_name"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_arrow_right" />
</RelativeLayout>
<include layout="@layout/view_divider" />
<RelativeLayout
android:id="@+id/rl_baby_birthday"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/white"
android:gravity="center_vertical"
android:paddingStart="12dp"
android:paddingEnd="12dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/baby_birthday"
android:textColor="@color/black"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/ic_next_birthday"
android:textSize="16sp"
tools:text="2020-06-06" />
<ImageView
android:id="@+id/ic_next_birthday"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_arrow_right" />
</RelativeLayout>
<include layout="@layout/view_divider" />
<RelativeLayout
android:id="@+id/rl_baby_gender"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/white"
android:gravity="center_vertical"
android:paddingStart="12dp"
android:paddingEnd="12dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/baby_gender"
android:textColor="@color/black"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_baby_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@+id/ic_next_gender"
android:textSize="16sp"
tools:text="女" />
<ImageView
android:id="@+id/ic_next_gender"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_arrow_right" />
</RelativeLayout>
</LinearLayout>

View File

@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/divider_gray"
android:orientation="vertical"
tools:context=".ui.baby.BabyListActivity">
<RelativeLayout
@ -38,6 +39,7 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="12dp"
android:paddingStart="15dp"
android:paddingTop="12dp"
android:text="@string/info_baby_add"
android:textColor="@color/text_red"
@ -45,4 +47,11 @@
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_baby_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
</LinearLayout>

View File

@ -18,6 +18,7 @@
<ImageView
android:id="@+id/add_new_post_pic"
android:visibility="gone"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
@ -25,8 +26,9 @@
<TextView
android:layout_width="wrap_content"
android:id="@+id/tv_home_title"
android:layout_marginStart="12dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/nav_home"
android:textColor="@color/text_black"
android:textSize="20sp" />

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="115dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@color/white"
android:paddingStart="12dp"
android:paddingEnd="12dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_baby_head"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
tools:src="@color/black" />
<TextView
android:id="@+id/tv_baby_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/civ_baby_head"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/civ_baby_head"
android:textColor="@color/black"
android:textSize="15sp"
tools:text="哈哈哈" />
<TextView
android:id="@+id/tv_birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/civ_baby_head"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/civ_baby_head"
android:textColor="@color/text_hint"
android:textSize="12sp"
tools:text="2020-06-06" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="@color/divider_gray" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ll_delete_baby"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp">
<ImageView
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_marginEnd="10dp"
android:src="@drawable/ic_delete" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/delete" />
</LinearLayout>
<LinearLayout
android:id="@+id/rl_edit_baby"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toStartOf="@+id/ll_delete_baby"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp">
<ImageView
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_marginEnd="10dp"
android:src="@drawable/ic_edit" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@ -44,4 +44,12 @@
<string name="select_relate_baby">选择相关宝宝</string>
<string name="record_time">记录时间</string>
<string name="time">时间</string>
<string name="save">保存</string>
<string name="baby_name">宝宝姓名</string>
<string name="baby_birthday">宝宝生日</string>
<string name="baby_gender">宝宝性别</string>
<string name="click_set_baby_head">点击设置宝宝头像</string>
<string name="edit">修改</string>
<string name="delete">删除</string>
<string name="baby_birthday_show">宝宝生日:%1$s</string>
</resources>