Commit 0ae4c650 authored by 张释方's avatar 张释方

提交绑定手机号

parent 8d8b7ed2
package com.mints.street.main.my
import android.Manifest
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.fry.base.base.BaseActivity
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.databinding.ActivityBindmobileBinding
import com.mints.street.utils.BackInputUtil
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.activity_bindmobile.*
import kotlinx.android.synthetic.main.activity_container.*
import kotlinx.android.synthetic.main.include_header.*
import me.goldze.mvvmhabit.utils.ToastUtils
class BindMobileActivity : BaseActivity<ActivityBindmobileBinding, BindMobileViewModel>(), View.OnClickListener {
private var mobile: String? = null
override fun initVariableId() = BR.viewModel
override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_bindmobile
override fun initData() {
super.initData()
initView()
initListener()
}
private fun initListener() {
iv_left_icon.setOnClickListener(this)
tvLoginSendcode.setOnClickListener(this)
tvLoginNext.setOnClickListener(this)
}
private fun initView() {
tv_title.text = "绑定手机号"
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
BackInputUtil.phoneNumAddSpace(etLoginMobile)
// mobile = UserManager.getInstance().mobile
if (!TextUtils.isEmpty(mobile)) {
etLoginMobile.setText(mobile)
etLoginMobile.setSelection(mobile!!.length + 2)
}
}
override fun onClick(v: View?) {
when(v?.id){
R.id.iv_left_icon -> {
finish()
}
R.id.tvLoginSendcode -> {
var mobile = etLoginMobile.text.toString().trim()
if (mobile.length < 13) {
ToastUtils.showShortSafe("请输入手机号")
return
}
sendCodeThread()
mobile = mobile.replace(" ".toRegex(), "")
// loginPresenter.sendMobileBindingCode(mobile)
}
R.id.tvLoginNext -> {
var mobile = etLoginMobile.text.toString().trim()
if (mobile.length < 13) {
ToastUtils.showShortSafe("请输入手机号")
return
}
val code = etLoginCode.text.toString().trim()
if (code.length < 4) {
ToastUtils.showShortSafe("请输入验证码")
return
}
RxPermissions(this@BindMobileActivity)
.request(Manifest.permission.READ_PHONE_STATE)
.subscribe { granted: Boolean ->
if (granted) {
mobile = mobile.replace(" ".toRegex(), "")
// loginPresenter.bindingMobile(mobile, code)
} else {
// showMissingPermissionDialog("设备")
}
}
}
}
}
var num = 0
var run: Runnable? = null
fun sendCodeThread() {
num = 60
tvLoginSendcode?.let {
it.isEnabled = false
it.text = "($num)重新获取"
run = object : Runnable {
override fun run() {
num--
if (num == 0) {
it.text = "重新获取"
it.isEnabled = true
} else {
it.text = "($num)重新获取"
it.postDelayed(this, 1000)
}
}
}
it.postDelayed(run, 1000)
}
}
}
package com.mints.street.main.my
import android.app.Application
import me.goldze.mvvmhabit.base.BaseViewModel
class BindMobileViewModel (application: Application): BaseViewModel(application) {
}
......@@ -3,26 +3,91 @@ package com.mints.street.main.my
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.fry.base.base.BaseActivity
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.databinding.ActivityMoresettingsBinding
import kotlinx.android.synthetic.main.activity_moresettings.*
import kotlinx.android.synthetic.main.include_header.*
class MoresettingsActivity: BaseActivity<ActivityMoresettingsBinding, MoresettingsViewModel>() {
class MoresettingsActivity : BaseActivity<ActivityMoresettingsBinding, MoresettingsViewModel>(), View.OnClickListener {
override fun initVariableId() = BR.viewModel
override fun initContentView(savedInstanceState: Bundle?)= R.layout.activity_moresettings
override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_moresettings
override fun initData() {
super.initData()
initView()
initListener()
}
private fun initListener() {
item_phone.setOnClickListener(this)
iv_left_icon.setOnClickListener(this)
item_userAgree.setOnClickListener(this)
item_privacyAgree.setOnClickListener(this)
}
private fun initView() {
tv_title.text="更多设置"
tv_title.text = "更多设置"
tv_title.setTextColor(Color.BLACK)
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
iv_left_icon.visibility= View.VISIBLE
iv_left_icon.visibility = View.VISIBLE
item_phone.findViewById<TextView>(R.id.tv_title).text = "手机号"
val phone = ContextCompat.getDrawable(this, R.mipmap.icon_settings_tel)
phone?.setBounds(0, 0, 56, 56)
item_phone.findViewById<TextView>(R.id.tv_title).setCompoundDrawables(phone, null, null, null)
item_phone.findViewById<TextView>(R.id.tv_right).visibility = View.VISIBLE
item_phone.findViewById<ImageView>(R.id.iv_right).visibility = View.GONE
item_phone.findViewById<TextView>(R.id.tv_right).text = "未绑定"
item_userAgree.findViewById<TextView>(R.id.tv_title).text = "用户协议"
val userAgree = ContextCompat.getDrawable(this, R.mipmap.icon_settings_user)
userAgree?.setBounds(0, 0, 56, 56)
item_userAgree.findViewById<TextView>(R.id.tv_title).setCompoundDrawables(userAgree, null, null, null)
item_userAgree.findViewById<TextView>(R.id.tv_right).visibility = View.GONE
item_userAgree.findViewById<ImageView>(R.id.iv_right).visibility = View.VISIBLE
item_privacyAgree.findViewById<TextView>(R.id.tv_title).text = "隐私协议"
val privacyAgree = ContextCompat.getDrawable(this, R.mipmap.icon_settings_privacy)
privacyAgree?.setBounds(0, 0, 56, 56)
item_privacyAgree.findViewById<TextView>(R.id.tv_title).setCompoundDrawables(privacyAgree, null, null, null)
item_privacyAgree.findViewById<TextView>(R.id.tv_right).visibility = View.GONE
item_privacyAgree.findViewById<ImageView>(R.id.iv_right).visibility = View.VISIBLE
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.iv_left_icon -> {
finish()
}
R.id.item_phone -> {
// if (!userManager.userIsLogin()) {
// readyGo(WxLoginActivity::class.java)
// return
// }
// if (userManager.mobile.isEmpty()) {
startActivity(BindMobileActivity::class.java)
// }
}
R.id.item_userAgree -> {
}
R.id.item_privacyAgree -> {
}
}
}
......
......@@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.fragment_my.*
* 个人中心页面
*/
class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), View.OnClickListener {
//弹窗
private var mBottomSheetDialog: BottomSheetDialog? = null
private var iv_weixin: ImageView? = null
......
package com.mints.street.utils;
import android.text.Editable;
import android.text.Selection;
import android.text.TextWatcher;
import android.widget.EditText;
/**
* 验卷,每四位自动跟横线
* Created by mengcuiguang on 2016/8/15.
*/
public class BackInputUtil {
public static void bankCardNumAddSpace(final EditText mEditText) {
mEditText.addTextChangedListener(new TextWatcher() {
private Editable etable;
int beforeTextLength = 0;
int onTextLength = 0;
boolean isChanged = false;
int location = 0;//记录光标的位置
private char[] tempChar;
private StringBuffer buffer = new StringBuffer();
int konggeNumberB = 0;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
beforeTextLength = s.length();
if (buffer.length() > 0) {
buffer.delete(0, buffer.length());
}
konggeNumberB = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') {
konggeNumberB++;
}
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
onTextLength = s.length();
buffer.append(s.toString());
if (onTextLength == beforeTextLength || onTextLength <= 3 || isChanged) {
isChanged = false;
return;
}
isChanged = true;
}
@Override
public void afterTextChanged(Editable s) {
if (isChanged) {
location = mEditText.getSelectionEnd();
int index = 0;
while (index < buffer.length()) {
if (buffer.charAt(index) == ' ') {
buffer.deleteCharAt(index);
} else {
index++;
}
}
index = 0;
int konggeNumberC = 0;
while (index < buffer.length()) {
//银行卡号的话需要改这里
if ((index == 4 || index == 9 || index == 14 || index == 19)) {
buffer.insert(index, ' ');
konggeNumberC++;
}
index++;
}
if (konggeNumberC > konggeNumberB) {
location += (konggeNumberC - konggeNumberB);
}
tempChar = new char[buffer.length()];
buffer.getChars(0, buffer.length(), tempChar, 0);
String str = buffer.toString();
if (location > str.length()) {
location = str.length();
} else if (location < 0) {
location = 0;
}
mEditText.setText(str);
etable = mEditText.getText();
Selection.setSelection(etable, location);
isChanged = false;
}
}
});
}
//手机号码的格式
public static void phoneNumAddSpace(final EditText mEditText) {
mEditText.addTextChangedListener(new TextWatcher() {
int beforeTextLength = 0;
int onTextLength = 0;
boolean isChanged = false;
int location = 0;// 记录光标的位置
private char[] tempChar;
private StringBuffer buffer = new StringBuffer();
int konggeNumberB = 0;
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
beforeTextLength = s.length();
if (buffer.length() > 0) {
buffer.delete(0, buffer.length());
}
konggeNumberB = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') {
konggeNumberB++;
}
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
onTextLength = s.length();
buffer.append(s.toString());
if (onTextLength == beforeTextLength || onTextLength <= 3
|| isChanged) {
isChanged = false;
return;
}
isChanged = true;
}
@Override
public void afterTextChanged(Editable s) {
if (isChanged) {
location = mEditText.getSelectionEnd();
int index = 0;
while (index < buffer.length()) {
if (buffer.charAt(index) == ' ') {
buffer.deleteCharAt(index);
} else {
index++;
}
}
index = 0;
int konggeNumberC = 0;
while (index < buffer.length()) {
if ((index == 3 || index == 8)) {
buffer.insert(index, ' ');
konggeNumberC++;
}
index++;
}
if (konggeNumberC > konggeNumberB) {
location += (konggeNumberC - konggeNumberB);
}
tempChar = new char[buffer.length()];
buffer.getChars(0, buffer.length(), tempChar, 0);
String str = buffer.toString();
if (location > str.length()) {
location = str.length();
} else if (location < 0) {
location = 0;
}
mEditText.setText(str);
Editable etable = mEditText.getText();
Selection.setSelection(etable, location);
isChanged = false;
}
}
});
}
}
package com.mints.street.widget;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.TranslateAnimation;
import androidx.core.widget.NestedScrollView;
/**
* 有弹性的ScrollView
* 实现下拉弹回和上拉弹回
*
* @author zhangjg
* @date Feb 13, 2014 6:11:33 PM
*/
public class ElasticScrollView extends NestedScrollView {
private static final String TAG = "ElasticScrollView";
//移动因子, 是一个百分比, 比如手指移动了100px, 那么View就只移动50px
//目的是达到一个延迟的效果
private static final float MOVE_FACTOR = 0.5f;
//松开手指后, 界面回到正常位置需要的动画时间
private static final int ANIM_TIME = 300;
//ScrollView的子View, 也是ScrollView的唯一一个子View
private View contentView;
//手指按下时的Y值, 用于在移动时计算移动距离
//如果按下时不能上拉和下拉, 会在手指移动时更新为当前手指的Y值
private float startY;
//用于记录正常的布局位置
private Rect originalRect = new Rect();
//手指按下时记录是否可以继续下拉
private boolean canPullDown = false;
//手指按下时记录是否可以继续上拉
private boolean canPullUp = false;
//在手指滑动的过程中记录是否移动了布局
private boolean isMoved = false;
public ElasticScrollView(Context context) {
super(context);
}
public ElasticScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (getChildCount() > 0) {
contentView = getChildAt(0);
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (contentView == null) return;
//ScrollView中的唯一子控件的位置信息, 这个位置信息在整个控件的生命周期中保持不变
originalRect.set(contentView.getLeft(), contentView.getTop(), contentView
.getRight(), contentView.getBottom());
}
/**
* 在触摸事件中, 处理上拉和下拉的逻辑
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (contentView == null) {
return super.dispatchTouchEvent(ev);
}
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
//判断是否可以上拉和下拉
canPullDown = isCanPullDown();
canPullUp = isCanPullUp();
//记录按下时的Y值
startY = ev.getY();
break;
case MotionEvent.ACTION_UP:
if (!isMoved) break; //如果没有移动布局, 则跳过执行
// 开启动画
TranslateAnimation anim = new TranslateAnimation(0, 0, contentView.getTop(),
originalRect.top);
anim.setDuration(ANIM_TIME);
anim.setInterpolator(new AccelerateInterpolator());
contentView.startAnimation(anim);
// 设置回到正常的布局位置
contentView.layout(originalRect.left, originalRect.top,
originalRect.right, originalRect.bottom);
//将标志位设回false
canPullDown = false;
canPullUp = false;
isMoved = false;
break;
case MotionEvent.ACTION_MOVE:
//在移动的过程中, 既没有滚动到可以上拉的程度, 也没有滚动到可以下拉的程度
if (!canPullDown && !canPullUp) {
startY = ev.getY();
canPullDown = isCanPullDown();
canPullUp = isCanPullUp();
break;
}
//计算手指移动的距离
float nowY = ev.getY();
int deltaY = (int) (nowY - startY);
//是否应该移动布局
boolean shouldMove =
(canPullDown && deltaY > 0) //可以下拉, 并且手指向下移动
|| (canPullUp && deltaY < 0) //可以上拉, 并且手指向上移动
|| (canPullUp && canPullDown); //既可以上拉也可以下拉(这种情况出现在ScrollView包裹的控件比ScrollView还小)
if (shouldMove) {
//计算偏移量
int offset = (int) (deltaY * MOVE_FACTOR);
//随着手指的移动而移动布局
contentView.layout(originalRect.left, originalRect.top + offset,
originalRect.right, originalRect.bottom + offset);
isMoved = true; //记录移动了布局
}
break;
default:
break;
}
return super.dispatchTouchEvent(ev);
}
/**
* 判断是否滚动到顶部
*/
private boolean isCanPullDown() {
return getScrollY() == 0 ||
contentView.getHeight() < getHeight() + getScrollY();
}
/**
* 判断是否滚动到底部
*/
private boolean isCanPullUp() {
return contentView.getHeight() <= getHeight() + getScrollY();
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="viewModel"
type="com.mints.street.main.my.BindMobileViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include layout="@layout/include_header" />
<com.mints.street.widget.ElasticScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:src="@mipmap/ic_launcher_main" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手机号:" />
<com.mints.street.widget.ClearEditText
android:id="@+id/etLoginMobile"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="30dp"
android:background="@null"
android:gravity="center_vertical"
android:hint="请输入手机号"
android:inputType="number"
android:maxLength="13"
android:maxLines="1"
android:textColor="@color/color_172B54"
android:textColorHint="@color/color_BEC2CC"
android:textSize="12sp" />
</LinearLayout>
<View
style="@style/line_3"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="验证码:" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="30dp">
<com.mints.street.widget.ClearEditText
android:id="@+id/etLoginCode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginRight="120dp"
android:background="@null"
android:hint="请输入验证码"
android:inputType="number"
android:maxLength="4"
android:maxLines="1"
android:textColor="@color/color_172B54"
android:textColorHint="@color/color_BEC2CC"
android:textSize="12sp" />
<TextView
android:id="@+id/tvLoginSendcode"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="发送验证码"
android:textColor="@color/color_FF9837"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
<View
style="@style/line_3"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp" />
<TextView
android:id="@+id/tvLoginNext"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:layout_marginRight="40dp"
android:background="@drawable/shape_main"
android:gravity="center"
android:text="绑定手机号"
android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout>
</com.mints.street.widget.ElasticScrollView>
</LinearLayout>
</layout>
\ No newline at end of file
......@@ -2,6 +2,7 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="viewModel"
type="com.mints.street.main.my.MoresettingsViewModel" />
......@@ -9,70 +10,69 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_gold_card"
android:elevation="5dp"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/include_header" />
<LinearLayout
android:id="@+id/ly_aboutus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="用户协议"
android:textColor="@color/black"
android:textSize="18sp" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:src="@mipmap/bg_right" />
</LinearLayout>
<include layout="@layout/include_header" />
<View
<com.mints.street.widget.ElasticScrollView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#979797" />
android:layout_height="match_parent"
android:overScrollMode="never">
<LinearLayout
android:id="@+id/ly_moresettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:padding="10dp">
android:layout_height="match_parent"
android:elevation="5dp"
android:orientation="vertical">
<include
android:id="@+id/item_phone"
layout="@layout/item_settings" />
<include
android:id="@+id/item_wechat"
layout="@layout/item_settings" />
<include
android:id="@+id/item_invitedCode"
layout="@layout/item_settings" />
<include
android:id="@+id/item_cleanCache"
layout="@layout/item_settings" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="隐私政策"
android:textColor="@color/black"
android:textSize="18sp" />
<include
android:id="@+id/item_userAgree"
layout="@layout/item_settings" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:src="@mipmap/bg_right" />
<include
android:id="@+id/item_privacyAgree"
layout="@layout/item_settings" />
<include
android:id="@+id/item_aboutUs"
layout="@layout/item_settings" />
<include
android:id="@+id/item_feedBack"
layout="@layout/item_settings" />
<Button
android:id="@+id/btn_switch"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="@drawable/shape_btn_switch"
android:text="退出登录"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</com.mints.street.widget.ElasticScrollView>
</LinearLayout>
</layout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:textColor="@color/color_121B32"
android:textSize="16sp" />
<ImageView
android:id="@+id/iv_right"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@mipmap/ic_arrow_more"
android:visibility="gone" />
<TextView
android:id="@+id/tv_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:visibility="gone" />
<View
style="@style/view_line_E6E6E6"
android:layout_alignParentBottom="true" />
</RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment