Administrator
2021-11-05 05d90004c120c5b597565bc99c7d3b85f15a4e73
短信验证码 倒计时
大厅顶部 UI
1 files added
4 files modified
199 ■■■■■ changed files
app/build.gradle 8 ●●●●● patch | view | raw | blame | history
app/src/main/java/com/duqing/missions/ui/login/view/LoginActivity.java 37 ●●●● patch | view | raw | blame | history
app/src/main/java/com/duqing/missions/ui/login/view/LoginViewModel.java 32 ●●●●● patch | view | raw | blame | history
app/src/main/res/layout/fragment_sub_hall.xml 65 ●●●●● patch | view | raw | blame | history
app/src/main/res/layout/hall_item_top.xml 57 ●●●●● patch | view | raw | blame | history
app/build.gradle
@@ -33,7 +33,7 @@
dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
@@ -52,7 +52,9 @@
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    //RXjava和retrofit结合
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    implementation 'com.permissionx.guolindev:permissionx:1.2.2'    //权限依赖
    implementation 'com.permissionx.guolindev:permissionx:1.2.2'    //权限依赖让你推广你就发群里?没有别的群了?
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
app/src/main/java/com/duqing/missions/ui/login/view/LoginActivity.java
@@ -16,6 +16,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.duqing.missions.R;
import com.duqing.missions.base.activities.BaseTitleBarActivity;
@@ -28,11 +29,9 @@
    @Override
    public void initViews() {
        final EditText phoneEdit = binding.editPhone;
        final EditText passwordEditText = binding.editPassword;
        final Button loginButton = binding.login;
        viewModel.getLoginFormState().observe(this, new Observer<LoginFormState>() {
            @Override
@@ -49,7 +48,6 @@
                }
            }
        });
        viewModel.getLoginResult().observe(this, new Observer<LoginResult>() {
            @Override
            public void onChanged(@Nullable LoginResult loginResult) {
@@ -68,7 +66,6 @@
                finish();
            }
        });
        binding.txtPasswordTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
@@ -78,7 +75,6 @@
                unCheckStyle(binding.txtVerifyTitle);
            }
        });
        binding.txtVerifyTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
@@ -88,7 +84,6 @@
                unCheckStyle(binding.txtPasswordTitle);
            }
        });
        TextWatcher afterTextChangedListener = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -109,7 +104,6 @@
        phoneEdit.addTextChangedListener(afterTextChangedListener);
        passwordEditText.addTextChangedListener(afterTextChangedListener);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
@@ -119,7 +113,6 @@
                return false;
            }
        });
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
@@ -127,6 +120,34 @@
                        passwordEditText.getText().toString());
            }
        });
        viewModel.getCountDown().observe(this, new Observer<Long>() {
            @Override
            public void onChanged(Long l) {
                if(l>0){
                    binding.textVerify.setTextColor(getResources().getColor(R.color.gray));
                    binding.textVerify.setEnabled(false);
                    binding.textVerify.setText("重新发送("+l+"s)");
                }else{
                    binding.textVerify.setEnabled(true);
                    binding.textVerify.setTextColor(getResources().getColor(R.color.sky));
                    binding.textVerify.setText("获取验证码");
                }
            }
        });
        binding.textVerify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewModel.startCountDown(0);
            }
        });
    }
    @Override
    public ViewModelProvider.Factory getViewModelFactory() {
        return new LoginViewModelFactory();
    }
    public void checkedStyle(TextView textView){
app/src/main/java/com/duqing/missions/ui/login/view/LoginViewModel.java
@@ -1,5 +1,6 @@
package com.duqing.missions.ui.login.view;
import android.os.CountDownTimer;
import android.util.Patterns;
import androidx.lifecycle.LiveData;
@@ -20,6 +21,8 @@
    private MutableLiveData<LoginFormState> loginFormState = new MutableLiveData<>();
    private MutableLiveData<LoginResult> loginResult = new MutableLiveData<>();
    private LoginRepository loginRepository;
    private MutableLiveData<Long> countDown = new MutableLiveData<>();
    private CountDownTimer timer;
    LoginViewModel(LoginRepository loginRepository) {
        this.loginRepository = loginRepository;
@@ -86,4 +89,31 @@
    private boolean isPasswordValid(String password) {
        return password != null && password.trim().length() > 5;
    }
}
    public MutableLiveData<Long> getCountDown() {
        return countDown;
    }
    /**
     * 启动倒计时
     * @param consumedTime
     */
    public void startCountDown(long consumedTime){
        //倒计时
        timer = new CountDownTimer(60 * 1000-consumedTime, 1000) {
            @Override
            public void onTick(long l) {
                countDown.postValue(l / 1000);
            }
            @Override
            public void onFinish() {
                countDown.setValue(0l);
            }
        };
        timer.start();
    }
}
app/src/main/res/layout/fragment_sub_hall.xml
@@ -63,18 +63,71 @@
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintHorizontal_chainStyle="spread" />
    <View
        android:id="@+id/view"
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@color/gray"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_white_corner"
        android:elevation="@dimen/small_radios"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:padding="@dimen/frame_margin_lr"
        app:layout_constraintTop_toBottomOf="@id/radio_group"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@id/include_refresh_recycler">
        <include layout="@layout/hall_item_top"
            android:id="@+id/layout_left"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@id/layout_between"/>
        <include layout="@layout/hall_item_top"
            android:id="@+id/layout_between"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@id/layout_left"
            app:layout_constraintRight_toLeftOf="@id/layout_right"
            />
        <include layout="@layout/hall_item_top"
            android:id="@+id/layout_right"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@id/layout_between"
            app:layout_constraintRight_toRightOf="parent"/>
        <View
            android:layout_width="0.5dp"
            android:layout_height="0dp"
            android:background="@color/gray"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@id/layout_left" />
        <View
            android:layout_width="0.5dp"
            android:layout_height="0dp"
            android:background="@color/gray"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@id/layout_between" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    <include layout="@layout/refresh_recycler"
        android:id="@+id/include_refresh_recycler"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/view"
        app:layout_constraintTop_toBottomOf="@id/layout"
        app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
app/src/main/res/layout/hall_item_top.xml
New file
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
    <ImageView
        android:id="@+id/image_avatar"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginTop="@dimen/frame_margin_lr"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@id/text_title"
        tools:srcCompat="@tools:sample/avatars" />
    <TextView
        android:id="@+id/text_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:ellipsize="end"
        android:singleLine="true"
        android:maxLines="1"
        android:textSize="16sp"
        android:textColor="@color/black"
        android:layout_marginTop="@dimen/frame_margin_lr"
        app:layout_constraintBottom_toTopOf="@id/text_label"
        app:layout_constraintTop_toBottomOf="@id/image_avatar"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />
    <TextView
        android:id="@+id/text_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_marginTop="@dimen/frame_margin_lr"
        app:layout_constraintBottom_toTopOf="@id/text_price"
        app:layout_constraintTop_toBottomOf="@id/text_title"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />
    <TextView
        android:id="@+id/text_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+0.00"
        android:textColor="@color/red"
        android:textSize="16sp"
        android:layout_marginTop="@dimen/frame_margin_lr"
        app:layout_constraintTop_toBottomOf="@id/text_label"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>