完善个人资料,选择性别弹窗构建

This commit is contained in:
18401019693 2023-05-11 10:26:05 +08:00
parent 73b075b2a7
commit 8410439a90
13 changed files with 294 additions and 17 deletions

View File

@ -0,0 +1,88 @@
package com.yunbao.common.views;
import android.content.Context;
import android.graphics.Color;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.lxj.xpopup.core.BottomPopupView;
import com.yunbao.common.R;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
public class UpdateSexPopup extends BottomPopupView {
private int sex;
private LinearLayout linearMan, linearGirl;
private ImageView imageMan, imageGirl;
private TextView textMan, textGirl;
private UpdateSexCallBack callBack;
public UpdateSexPopup(@NonNull Context context, int sex, UpdateSexCallBack callBack) {
super(context);
this.sex = sex;
this.callBack = callBack;
}
// 返回自定义弹窗的布局
@Override
protected int getImplLayoutId() {
return R.layout.view_update_sex_popup;
}
// 执行初始化操作比如findView设置点击或者任何你弹窗内的业务逻辑
@Override
protected void onCreate() {
super.onCreate();
initView();
}
private void initView() {
linearMan = findViewById(R.id.linear_man);
imageMan = findViewById(R.id.image_man);
textMan = findViewById(R.id.text_man);
linearGirl = findViewById(R.id.linear_girl);
imageGirl = findViewById(R.id.image_girl);
textGirl = findViewById(R.id.text_girl);
if (sex == 0) {
ImgLoader.display(getContext(), R.mipmap.icon_male_default, imageMan);
ImgLoader.display(getContext(), R.mipmap.icon_female_default, imageGirl);
textMan.setTextColor(Color.parseColor("#999999"));
textGirl.setTextColor(Color.parseColor("#999999"));
} else if (sex == 1) {
ImgLoader.display(getContext(), R.mipmap.icon_male_highlighted, imageMan);
ImgLoader.display(getContext(), R.mipmap.icon_female_default, imageGirl);
textMan.setTextColor(Color.parseColor("#333333"));
textGirl.setTextColor(Color.parseColor("#999999"));
} else if (sex == 2) {
ImgLoader.display(getContext(), R.mipmap.icon_male_default, imageMan);
ImgLoader.display(getContext(), R.mipmap.icon_female_highlight, imageGirl);
textMan.setTextColor(Color.parseColor("#999999"));
textGirl.setTextColor(Color.parseColor("#333333"));
}
ViewClicksAntiShake.clicksAntiShake(linearMan, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.onSex(1);
}
}
});
ViewClicksAntiShake.clicksAntiShake(linearGirl, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.onSex(2);
}
}
});
}
public interface UpdateSexCallBack {
void onSex(int sex);
}
}

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="213.5dp"
android:background="@mipmap/bg_gift_completely"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/linear_man"
android:layout_width="0dp"
android:background="?android:attr/selectableItemBackground"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/image_man"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/icon_male_highlighted" />
<TextView
android:id="@+id/text_man"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9.5dp"
android:text="@string/man_student"
android:textColor="#333333"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear_girl"
android:layout_width="0dp"
android:background="?android:attr/selectableItemBackground"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/image_girl"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/icon_female_highlight" />
<TextView
android:id="@+id/text_girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9.5dp"
android:text="@string/girl_student"
android:textColor="#333333"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1155,4 +1155,6 @@ Limited ride And limited avatar frame</string>
<string name="love_powder">真愛粉\n頭像框(7天)</string>
<string name="golden_beans_128">128金豆</string>
<string name="love_powder_medal">真愛粉\n勛章(7天)</string>
<string name="man_student">男生</string>
<string name="girl_student">女生</string>
</resources>

View File

@ -34,10 +34,11 @@ import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.UserBean;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.main.R;
import com.yunbao.main.event.EditProfileEvent;
import com.yunbao.main.event.RegSuccessEvent;
import com.yunbao.main.http.MainHttpConsts;
import com.yunbao.main.http.MainHttpUtil;
@ -73,7 +74,7 @@ public class BindUserActivity extends AbsActivity {
private int mCountryCode = 852;//国家代码
private ImageView mIvCountryCode;
private LinearLayout lt_now_bind, lt_give, lt_password, lt_password2;
private TextView tv_now_phone,tv_title;
private TextView tv_now_phone, tv_title;
private Button btn_goto_updata;
private String isBind = "0", mobile = "";
private WebView webview;
@ -107,8 +108,8 @@ public class BindUserActivity extends AbsActivity {
btn_goto_updata = findViewById(R.id.btn_goto_updata);
tv_title = findViewById(R.id.tv_title);
mGetCode =mContext.getString(R.string.reg_get_code);
mGetCodeAgain =mContext.getString(R.string.reg_get_code_again);
mGetCode = mContext.getString(R.string.reg_get_code);
mGetCodeAgain = mContext.getString(R.string.reg_get_code_again);
mTvCountryCodeClick();
mEditPhone.addTextChangedListener(new TextWatcher() {
@Override
@ -372,6 +373,7 @@ public class BindUserActivity extends AbsActivity {
public void onSuccess(int code, String msg, String[] info) {
ToastUtil.show(msg);
if (code == 0) {
Bus.get().post(new EditProfileEvent());
finish();
}
if (mDialog != null) {
@ -392,6 +394,7 @@ public class BindUserActivity extends AbsActivity {
public void onSuccess(int code, String msg, String[] info) {
ToastUtil.show(msg);
if (code == 0) {
Bus.get().post(new EditProfileEvent());
finish();
}
if (mDialog != null) {

View File

@ -12,6 +12,7 @@ import android.widget.TextView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lxj.xpopup.XPopup;
import com.sahooz.library.Country;
import com.sahooz.library.CountryPicker;
import com.sahooz.library.OnPick;
@ -29,17 +30,22 @@ import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.interfaces.ActivityResultCallback;
import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.interfaces.ImageResultCallback;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.CityUtil;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.ProcessImageUtil;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.UpdateSexPopup;
import com.yunbao.main.R;
import com.yunbao.main.event.EditProfileEvent;
import com.yunbao.main.http.MainHttpConsts;
import com.yunbao.main.http.MainHttpUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.util.ArrayList;
@ -72,8 +78,8 @@ public class EditProfileActivity extends AbsActivity {
private String isBind = "0", mobile = "";
private boolean isName = false;
private View viewProgress1, viewProgress2, viewProgress3;
private FrameLayout completeInformation1, completeInformation2, completeInformation3;
private TextView information1, information2, information3;
private FrameLayout completeInformation, completeInformation1, completeInformation2, completeInformation3;
private TextView information, information1, information2, information3, submit;
@Override
protected int getLayoutId() {
@ -82,6 +88,7 @@ public class EditProfileActivity extends AbsActivity {
@Override
protected void main() {
Bus.getOn(this);
setTitle(mContext.getString(R.string.edit_profile));
mAvatar = (ImageView) findViewById(R.id.avatar);
mName = (TextView) findViewById(R.id.name);
@ -93,12 +100,15 @@ public class EditProfileActivity extends AbsActivity {
viewProgress1 = findViewById(R.id.view_progress1);
viewProgress2 = findViewById(R.id.view_progress2);
viewProgress3 = findViewById(R.id.view_progress3);
completeInformation = findViewById(R.id.complete_information);
completeInformation1 = findViewById(R.id.complete_information1);
completeInformation2 = findViewById(R.id.complete_information2);
completeInformation3 = findViewById(R.id.complete_information3);
information = findViewById(R.id.information);
information1 = findViewById(R.id.information1);
information2 = findViewById(R.id.information2);
information3 = findViewById(R.id.information3);
submit = findViewById(R.id.submit);
mImageUtil = new ProcessImageUtil(this);
mImageUtil.setImageResultCallback(new ImageResultCallback() {
@Override
@ -204,8 +214,25 @@ public class EditProfileActivity extends AbsActivity {
editBirthday();
} else if (i == R.id.btn_sex) {
forwardSex();
// forwardSex();
new XPopup.Builder(mContext)
.asCustom(new UpdateSexPopup(mContext, userModel.getSex(), new UpdateSexPopup.UpdateSexCallBack() {
@Override
public void onSex(int sex) {
MainHttpUtil.updateFields("{\"sex\":\"" + sex + "\"}", new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
JSONObject obj = JSON.parseObject(info[0]);
ToastUtil.show(obj.getString("msg"));
userModel.setSex(sex);
showData(userModel);
}
}
});
}
}))
.show();
} else if (i == R.id.btn_city) {
CountryPicker.newInstance(null, new OnPick() {
@Override
@ -221,6 +248,11 @@ public class EditProfileActivity extends AbsActivity {
if (u != null) {
u.setLocation(country.name);
}
if (userModel != null) {
userModel.setLocation(country.name);
}
showData(userModel);
EventBus.getDefault().post(new UpdateFieldEvent());
}
ToastUtil.show(obj.getString("msg"));
@ -333,6 +365,12 @@ public class EditProfileActivity extends AbsActivity {
ToastUtil.show(JSON.parseObject(info[0]).getString("msg"));
mUserBean.setBirthday(date);
mBirthday.setText(date);
if (userModel != null) {
userModel.setBirthday(date);
}
showData(userModel);
EventBus.getDefault().post(new UpdateFieldEvent());
}
} else {
@ -371,6 +409,7 @@ public class EditProfileActivity extends AbsActivity {
@Override
protected void onDestroy() {
Bus.getOff(this);
if (mImageUtil != null) {
mImageUtil.release();
}
@ -379,11 +418,30 @@ public class EditProfileActivity extends AbsActivity {
super.onDestroy();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEditProfileEvent(EditProfileEvent event) {
MainHttpUtil.getBaseInfo(new CommonCallback<UserBean>() {
@Override
public void callback(UserBean u) {
showData(u);
}
});
}
private UserBean userModel;
private void showData(UserBean u) {
userModel = u;
int index = 0;
String birthday = u.getBirthday();
String location = u.getLocation();
String bindPhone = u.getMobile();
String sex = "";
if (u.getSex() == 1) {
sex = mContext.getString(R.string.sex_male);
} else if (u.getSex() == 2) {
sex = mContext.getString(R.string.sex_female);
}
if (!TextUtils.isEmpty(bindPhone)) {
index = index + 1;
}
@ -393,59 +451,99 @@ public class EditProfileActivity extends AbsActivity {
if (!TextUtils.isEmpty(birthday)) {
index = index + 1;
}
if (!TextUtils.isEmpty(sex)) {
index = index + 1;
}
if (index == 0) {
completeInformation.setBackgroundResource(R.mipmap.bg_complete_information_progress);
completeInformation1.setBackgroundResource(R.mipmap.bg_complete_information_progress);
completeInformation2.setBackgroundResource(R.mipmap.bg_complete_information_progress);
completeInformation3.setBackgroundResource(R.mipmap.bg_complete_information_progress);
information1.setVisibility(View.INVISIBLE);
information2.setVisibility(View.INVISIBLE);
information3.setVisibility(View.INVISIBLE);
information.setVisibility(View.VISIBLE);
information1.setVisibility(View.VISIBLE);
information2.setVisibility(View.VISIBLE);
information3.setVisibility(View.VISIBLE);
viewProgress1.setBackgroundColor(Color.parseColor("#DEE4F1"));
viewProgress2.setBackgroundColor(Color.parseColor("#DEE4F1"));
viewProgress3.setBackgroundColor(Color.parseColor("#DEE4F1"));
submit.setText(R.string.to_complete);
submit.setTextColor(Color.parseColor("#ffffff"));
} else if (index == 1) {
completeInformation.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation1.setBackgroundResource(R.mipmap.bg_complete_information_progress);
completeInformation2.setBackgroundResource(R.mipmap.bg_complete_information_progress);
completeInformation3.setBackgroundResource(R.mipmap.bg_complete_information_progress);
information.setVisibility(View.INVISIBLE);
information1.setVisibility(View.VISIBLE);
information2.setVisibility(View.VISIBLE);
information3.setVisibility(View.VISIBLE);
viewProgress1.setBackgroundColor(Color.parseColor("#DEE4F1"));
viewProgress2.setBackgroundColor(Color.parseColor("#DEE4F1"));
viewProgress3.setBackgroundColor(Color.parseColor("#DEE4F1"));
submit.setText(R.string.to_complete);
submit.setTextColor(Color.parseColor("#ffffff"));
} else if (index == 2) {
information.setVisibility(View.INVISIBLE);
information1.setVisibility(View.INVISIBLE);
information2.setVisibility(View.VISIBLE);
information3.setVisibility(View.VISIBLE);
completeInformation1.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation2.setBackgroundResource(R.mipmap.bg_complete_information_progress);
completeInformation3.setBackgroundResource(R.mipmap.bg_complete_information_progress);
viewProgress1.setBackgroundColor(Color.parseColor("#FFE5D0"));
viewProgress2.setBackgroundColor(Color.parseColor("#DEE4F1"));
viewProgress3.setBackgroundColor(Color.parseColor("#DEE4F1"));
} else if (index == 2) {
submit.setText(R.string.to_complete);
submit.setTextColor(Color.parseColor("#ffffff"));
} else if (index == 3) {
information.setVisibility(View.INVISIBLE);
information1.setVisibility(View.INVISIBLE);
information2.setVisibility(View.INVISIBLE);
information3.setVisibility(View.VISIBLE);
completeInformation.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation1.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation2.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation3.setBackgroundResource(R.mipmap.bg_complete_information_progress);
viewProgress1.setBackgroundColor(Color.parseColor("#FFE5D0"));
viewProgress2.setBackgroundColor(Color.parseColor("#FFE5D0"));
viewProgress3.setBackgroundColor(Color.parseColor("#DEE4F1"));
} else if (index == 3) {
submit.setText(R.string.to_complete);
submit.setTextColor(Color.parseColor("#ffffff"));
} else if (index == 4) {
information.setVisibility(View.INVISIBLE);
information1.setVisibility(View.INVISIBLE);
information2.setVisibility(View.INVISIBLE);
information3.setVisibility(View.INVISIBLE);
completeInformation.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation1.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation2.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
completeInformation3.setBackgroundResource(R.mipmap.bg_complete_information_progress2);
viewProgress1.setBackgroundColor(Color.parseColor("#FFE5D0"));
viewProgress2.setBackgroundColor(Color.parseColor("#FFE5D0"));
viewProgress3.setBackgroundColor(Color.parseColor("#FFE5D0"));
submit.setText(R.string.to_receive);
submit.setTextColor(Color.parseColor("#935902"));
}
ImgLoader.displayAvatar(mContext, u.getAvatar(), mAvatar);
mName.setText(u.getUserNiceName());
mSign.setText(u.getSignature());
mBirthday.setText(u.getBirthday());
mSex.setText(u.getSex() == 1 ? R.string.sex_male : R.string.sex_female);
if (u.getSex() == 0) {
mSex.setText("");
} else if (u.getSex() == 1) {
mSex.setText(R.string.sex_male);
} else if (u.getSex() == 2) {
mSex.setText(R.string.sex_female);
}
mCity.setText(u.getLocation());
if ("1".equals(u.getIs_bind())) {
mobile = u.getMobile();
tv_bind_phone.setText(mobile);
isBind = "1";
} else {
tv_bind_phone.setText(getResources().getString(R.string.bind_phone_text));
tv_bind_phone.setHint(getResources().getString(R.string.bind_phone_text));
isBind = "0";
}
}
@ -537,7 +635,7 @@ public class EditProfileActivity extends AbsActivity {
tv_bind_phone.setText(mobile);
isBind = "1";
} else {
tv_bind_phone.setText(getResources().getString(R.string.bind_phone_text));
tv_bind_phone.setHint(getResources().getString(R.string.bind_phone_text));
isBind = "0";
}
}

View File

@ -0,0 +1,6 @@
package com.yunbao.main.event;
import com.yunbao.common.bean.BaseModel;
public class EditProfileEvent extends BaseModel {
}

View File

@ -314,7 +314,7 @@
android:ellipsize="end"
android:gravity="right"
android:singleLine="true"
android:text="@string/bind_phone_text"
android:hint="@string/bind_phone_text"
android:textColor="#353535"
android:textSize="14sp"
android:textStyle="bold" />
@ -413,10 +413,19 @@
</LinearLayout>
<FrameLayout
android:id="@+id/complete_information"
android:layout_width="15.5dp"
android:layout_height="15.5dp"
android:background="@mipmap/bg_complete_information_progress2">
<TextView
android:id="@+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1"
android:textColor="@color/white"
android:textSize="7.99sp" />
</FrameLayout>
<FrameLayout
@ -561,6 +570,18 @@
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/submit"
android:layout_width="64dp"
android:layout_height="25.5dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="32dp"
android:layout_marginEnd="8.5dp"
android:background="@mipmap/bg_submit"
android:gravity="center"
android:text="@string/to_complete"
android:textColor="@color/white"
android:textSize="12.44sp" />
</RelativeLayout>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB