修改密码:新密码不能与原密码相同

0515
panqihua 5 years ago
parent fd31332b20
commit c9db460d93
  1. 50
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java
  2. 2
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java
  3. 7
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java
  4. 11
      app/src/main/java/com/community/pocket/util/HttpUtil.java
  5. 3
      app/src/main/java/com/community/pocket/util/Param.java
  6. 17
      app/src/main/res/layout/main/layout/info/layout/info_fragment.xml
  7. 24
      app/src/main/res/layout/main/layout/info/layout/modify_password.xml
  8. 1
      app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml
  9. 1
      app/src/main/res/values-en-rUS/strings.xml
  10. 1
      app/src/main/res/values-zh-rCN/strings.xml
  11. 1
      app/src/main/res/values/strings.xml

@ -1,5 +1,6 @@
package com.community.pocket.ui.main.ui.info; package com.community.pocket.ui.main.ui.info;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -29,6 +30,7 @@ import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.login.LoginActivity; import com.community.pocket.ui.login.LoginActivity;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.util.AppDatabase; import com.community.pocket.util.AppDatabase;
import com.community.pocket.util.Param;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
@ -91,9 +93,6 @@ public class InfoFragment extends BaseFragment {
//确认新密码 //确认新密码
private EditText confirmNewPwd; private EditText confirmNewPwd;
//修改密码按钮
private Button modifyPwdBtn;
//打开修改密码弹窗 //打开修改密码弹窗
@ViewInject(R.id.open_modify_password) @ViewInject(R.id.open_modify_password)
private Button openModify; private Button openModify;
@ -127,7 +126,11 @@ public class InfoFragment extends BaseFragment {
} }
if (infoFormState.getNewPwdError() != null) { if (infoFormState.getNewPwdError() != null) {
if (infoFormState.getNewPwdError() == R.string.invalid_password) {
newPwd.setError(getString(infoFormState.getNewPwdError(), PropertiesUtil.getIntValue("password.length"))); newPwd.setError(getString(infoFormState.getNewPwdError(), PropertiesUtil.getIntValue("password.length")));
} else {
newPwd.setError(getString(infoFormState.getNewPwdError()));
}
} }
if (infoFormState.getConfirmNewPwdError() != null) { if (infoFormState.getConfirmNewPwdError() != null) {
@ -138,7 +141,12 @@ public class InfoFragment extends BaseFragment {
} }
} }
modifyPwdBtn.setEnabled(infoFormState.isDataValid()); Message message = new Message();
Bundle bundle = new Bundle();
bundle.putBoolean(Param.enable.name(), infoFormState.isDataValid());
message.setData(bundle);
handler.sendMessage(message);
} }
}); });
@ -153,7 +161,6 @@ public class InfoFragment extends BaseFragment {
infoResponse.toast(getContext()); infoResponse.toast(getContext());
if (infoResponse.getResult() == Response.Result.OK) { if (infoResponse.getResult() == Response.Result.OK) {
handler.sendEmptyMessage(0);
logout(logout); logout(logout);
} }
@ -227,34 +234,31 @@ public class InfoFragment extends BaseFragment {
newPwd.addTextChangedListener(textWatcher); newPwd.addTextChangedListener(textWatcher);
confirmNewPwd.addTextChangedListener(textWatcher); confirmNewPwd.addTextChangedListener(textWatcher);
//修改密码按钮 AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
modifyPwdBtn = view.findViewById(R.id.modify_password); final AlertDialog alertDialog = alert.setTitle(R.string.modify_password).setView(view)
modifyPwdBtn.setOnClickListener(new View.OnClickListener() { .setNegativeButton(R.string.modify_password, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(DialogInterface dialog, int which) {
viewModel.modifyPwd(oldPwd.getText().toString(), newPwd.getText().toString()); viewModel.modifyPwd(oldPwd.getText().toString(), newPwd.getText().toString());
dialog.dismiss();
} }
}); })
.setNeutralButton(R.string.action_close, new DialogInterface.OnClickListener() {
AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); @Override
final AlertDialog alertDialog = alert.setTitle(R.string.modify_password).setView(view).create(); public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create();
handler = new Handler(Looper.getMainLooper()) { handler = new Handler(Looper.getMainLooper()) {
@Override @Override
public void handleMessage(@NonNull Message msg) { public void handleMessage(@NonNull Message msg) {
alertDialog.dismiss(); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(msg.getData().getBoolean(Param.enable.name()));
} }
}; };
Button close = view.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handler.sendEmptyMessage(0);
}
});
alertDialog.show(); alertDialog.show();
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(false);
} }
/** /**

@ -37,6 +37,8 @@ public class InfoViewModel extends BaseViewModel<InfoRequest> {
modifyFormState.setValue(new InfoFormState(R.string.invalid_password, null, null)); modifyFormState.setValue(new InfoFormState(R.string.invalid_password, null, null));
} else if (!ValidUtil.passwordvalid(newpwd)) { } else if (!ValidUtil.passwordvalid(newpwd)) {
modifyFormState.setValue(new InfoFormState(null, R.string.invalid_password, null)); modifyFormState.setValue(new InfoFormState(null, R.string.invalid_password, null));
} else if (oldpwd.equals(newpwd)) {
modifyFormState.setValue(new InfoFormState(null, R.string.password_diff, null));
} else if (!ValidUtil.passwordvalid(confirmNewPwd)) { } else if (!ValidUtil.passwordvalid(confirmNewPwd)) {
modifyFormState.setValue(new InfoFormState(null, null, R.string.invalid_password)); modifyFormState.setValue(new InfoFormState(null, null, R.string.invalid_password));
} else if (!newpwd.equals(confirmNewPwd)) { } else if (!newpwd.equals(confirmNewPwd)) {

@ -11,6 +11,7 @@ import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -70,6 +71,10 @@ public class VisitorAppointmentFragment extends BaseFragment {
@ViewInject(R.id.submit) @ViewInject(R.id.submit)
private Button submit; private Button submit;
//预约时间layout
@ViewInject(R.id.choose_time_layout)
private LinearLayout chooseTimeLayout;
private VisitorViewModel appointmentViewModel; private VisitorViewModel appointmentViewModel;
//动态更新搜索框数据源 //动态更新搜索框数据源
@ -160,6 +165,7 @@ public class VisitorAppointmentFragment extends BaseFragment {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
chooseTimeLayout.setVisibility(View.GONE);
if (timeAdpter != null) { if (timeAdpter != null) {
timeAdpter.clear(); timeAdpter.clear();
} }
@ -169,6 +175,7 @@ public class VisitorAppointmentFragment extends BaseFragment {
if (visitorAdpter != null && visitorAdpter.containsKey(s.toString())) { if (visitorAdpter != null && visitorAdpter.containsKey(s.toString())) {
appointmentViewModel.appointmentDataChanged(appointment.getText(), chooseDate.getText(), today, notes.getText()); appointmentViewModel.appointmentDataChanged(appointment.getText(), chooseDate.getText(), today, notes.getText());
initTime(s); initTime(s);
chooseTimeLayout.setVisibility(View.VISIBLE);
return; return;
} }
appointment.setTag(R.string.visitor_tag, s.toString()); appointment.setTag(R.string.visitor_tag, s.toString());

@ -152,17 +152,6 @@ public class HttpUtil {
} }
}); });
// int[] buttonId=new int[]{R.id.button,R.id.button2};
// View.OnClickListener onClickListener=new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// System.exit(0);
// }
// };
// for(int id:buttonId){
// view.findViewById(id).setOnClickListener(onClickListener);
// }
builder.setView(constraintLayout); builder.setView(constraintLayout);
} else { } else {

@ -7,5 +7,6 @@ public enum Param {
username, username,
email, email,
forumId, forumId,
isOutPeople isOutPeople,
enable
} }

@ -37,6 +37,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginTop="@dimen/size_50" android:layout_marginTop="@dimen/size_50"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="@id/headimg" app:layout_constraintStart_toEndOf="@id/headimg"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -46,6 +47,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginTop="@dimen/size_50" android:layout_marginTop="@dimen/size_50"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="@id/headimg" app:layout_constraintStart_toEndOf="@id/headimg"
app:layout_constraintTop_toBottomOf="@id/nickname" /> app:layout_constraintTop_toBottomOf="@id/nickname" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
@ -73,17 +75,9 @@
android:gravity="center" /> android:gravity="center" />
</LinearLayout> </LinearLayout>
<Button
android:id="@+id/open_modify_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/size_8"
android:text="@string/modify_password" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/size_8"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
@ -148,6 +142,13 @@
</LinearLayout> </LinearLayout>
</HorizontalScrollView> </HorizontalScrollView>
<Button
android:id="@+id/open_modify_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/size_8"
android:text="@string/modify_password" />
<Button <Button
android:id="@+id/logout" android:id="@+id/logout"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -39,28 +39,4 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/new_password" /> app:layout_constraintTop_toBottomOf="@id/new_password" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/new_confirm_password">
<Button
android:id="@+id/modify_password"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="false"
android:text="@string/modify_password" />
<Button
android:id="@+id/close"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/action_close" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -62,6 +62,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/chooseDate"> app:layout_constraintTop_toBottomOf="@id/chooseDate">

@ -215,4 +215,5 @@
<string name="post_type_score">score</string> <string name="post_type_score">score</string>
<string name="not_match_people">not match people</string> <string name="not_match_people">not match people</string>
<string name="forum_show_complain">complain:%1s</string> <string name="forum_show_complain">complain:%1s</string>
<string name="password_diff">新密码不能与原密码相同</string>
</resources> </resources>

@ -215,4 +215,5 @@
<string name="post_type_score">结算</string> <string name="post_type_score">结算</string>
<string name="not_match_people">无法匹配任何用户</string> <string name="not_match_people">无法匹配任何用户</string>
<string name="forum_show_complain">投诉人:%1s</string> <string name="forum_show_complain">投诉人:%1s</string>
<string name="password_diff">新密码不能与原密码相同</string>
</resources> </resources>

@ -216,6 +216,7 @@
<string name="post_type_score">score</string> <string name="post_type_score">score</string>
<string name="not_match_people">not match people</string> <string name="not_match_people">not match people</string>
<string name="forum_show_complain">complain:%1s</string> <string name="forum_show_complain">complain:%1s</string>
<string name="password_diff">新密码不能与原密码相同</string>
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save