-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from FPT-NMTung/nguyen-fix-bug-2
Nguyen fix bug 2
- Loading branch information
Showing
14 changed files
with
591 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...c/main/java/fu/prm391/sampl/project/model/user/change_password/ChangePasswordRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fu.prm391.sampl.project.model.user.change_password; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class ChangePasswordRequest { | ||
|
||
@SerializedName("oldPassword") | ||
@Expose | ||
private String oldPassword; | ||
|
||
@SerializedName("password") | ||
@Expose | ||
private String password; | ||
|
||
public ChangePasswordRequest(String oldPassword, String password) { | ||
this.oldPassword = oldPassword; | ||
this.password = password; | ||
} | ||
|
||
public ChangePasswordRequest() { | ||
} | ||
|
||
public String getOldPassword() { | ||
return oldPassword; | ||
} | ||
|
||
public void setOldPassword(String oldPassword) { | ||
this.oldPassword = oldPassword; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../main/java/fu/prm391/sampl/project/model/user/change_password/ChangePasswordResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package fu.prm391.sampl.project.model.user.change_password; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class ChangePasswordResponse { | ||
@SerializedName("message") | ||
@Expose | ||
private String message; | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
app/src/main/java/fu/prm391/sampl/project/view/account/ChangePassword.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package fu.prm391.sampl.project.view.account; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.text.method.HideReturnsTransformationMethod; | ||
import android.text.method.PasswordTransformationMethod; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
|
||
import fu.prm391.sampl.project.R; | ||
import fu.prm391.sampl.project.helper.PreferencesHelpers; | ||
import fu.prm391.sampl.project.model.user.change_password.ChangePasswordRequest; | ||
import fu.prm391.sampl.project.model.user.change_password.ChangePasswordResponse; | ||
import fu.prm391.sampl.project.remote.ApiClient; | ||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class ChangePassword extends AppCompatActivity { | ||
|
||
private TextView txtBack; | ||
private EditText oldPass, newPass, rePass; | ||
private Button btnSave; | ||
private String token; | ||
private ImageView btnShowOldPass, btnShowNewPass, btnShowRepass; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_change_password); | ||
|
||
token = PreferencesHelpers.loadStringData(ChangePassword.this, "token"); | ||
|
||
changePasswordAction(); | ||
showHidePass(); | ||
backAction(); | ||
} | ||
|
||
private void changePasswordAction() { | ||
oldPass = findViewById(R.id.et_old_pass); | ||
newPass = findViewById(R.id.et_new_pass); | ||
rePass = findViewById(R.id.et_re_pass); | ||
btnSave = findViewById(R.id.btnSaveChangePass); | ||
btnSave.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
btnSave.setEnabled(false); | ||
if (TextUtils.isEmpty(oldPass.getText().toString().trim()) | ||
|| TextUtils.isEmpty(newPass.getText().toString().trim()) | ||
|| TextUtils.isEmpty(rePass.getText().toString().trim())) { | ||
Toast.makeText(ChangePassword.this, "All fields are required!", Toast.LENGTH_SHORT).show(); | ||
btnSave.setEnabled(true); | ||
} else if (!newPass.getText().toString().equals(rePass.getText().toString())) { | ||
Toast.makeText(ChangePassword.this, "New Password & Re-Password must be the same!", Toast.LENGTH_SHORT).show(); | ||
btnSave.setEnabled(true); | ||
} else { | ||
// proceed change password | ||
changePassword(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void changePassword() { | ||
ChangePasswordRequest changePasswordRequest = new ChangePasswordRequest(); | ||
changePasswordRequest.setOldPassword(oldPass.getText().toString()); | ||
changePasswordRequest.setPassword(newPass.getText().toString()); | ||
|
||
Call<ChangePasswordResponse> changePasswordResponseCall = ApiClient | ||
.getUserService() | ||
.changePassword("Bearer " + token, changePasswordRequest); | ||
changePasswordResponseCall.enqueue(new Callback<ChangePasswordResponse>() { | ||
@Override | ||
public void onResponse(Call<ChangePasswordResponse> call, Response<ChangePasswordResponse> response) { | ||
if (response.isSuccessful()) { | ||
Toast.makeText(ChangePassword.this, response.body().getMessage(), Toast.LENGTH_SHORT).show(); | ||
finish(); | ||
} else { | ||
try { | ||
JSONObject jsonObject = new JSONObject(response.errorBody().string()); | ||
Toast.makeText(ChangePassword.this, jsonObject.getString("message"), Toast.LENGTH_SHORT).show(); | ||
} catch (JSONException | IOException e) { | ||
Toast.makeText(ChangePassword.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); | ||
} | ||
btnSave.setEnabled(true); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<ChangePasswordResponse> call, Throwable t) { | ||
btnSave.setEnabled(true); | ||
} | ||
}); | ||
} | ||
|
||
private void backAction() { | ||
txtBack = findViewById(R.id.txtBackChangePass); | ||
txtBack.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
finish(); | ||
} | ||
}); | ||
} | ||
|
||
public void showHidePass() { | ||
btnShowOldPass = findViewById(R.id.btnShowOldPassChangePass); | ||
btnShowOldPass.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (oldPass.getTransformationMethod().equals(PasswordTransformationMethod.getInstance())) { | ||
((ImageView) (view)).setImageResource(R.drawable.ic_visibility_off); | ||
oldPass.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); | ||
} else { | ||
((ImageView) (view)).setImageResource(R.drawable.ic_visibility); | ||
oldPass.setTransformationMethod(PasswordTransformationMethod.getInstance()); | ||
} | ||
oldPass.setSelection(oldPass.length()); | ||
} | ||
}); | ||
|
||
btnShowNewPass = findViewById(R.id.btnShowNewPassChangePass); | ||
btnShowNewPass.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (newPass.getTransformationMethod().equals(PasswordTransformationMethod.getInstance())) { | ||
((ImageView) (view)).setImageResource(R.drawable.ic_visibility_off); | ||
newPass.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); | ||
} else { | ||
((ImageView) (view)).setImageResource(R.drawable.ic_visibility); | ||
newPass.setTransformationMethod(PasswordTransformationMethod.getInstance()); | ||
} | ||
newPass.setSelection(newPass.length()); | ||
} | ||
}); | ||
|
||
btnShowRepass = findViewById(R.id.btnShowRePassChangePass); | ||
btnShowRepass.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (rePass.getTransformationMethod().equals(PasswordTransformationMethod.getInstance())) { | ||
((ImageView) (view)).setImageResource(R.drawable.ic_visibility_off); | ||
rePass.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); | ||
} else { | ||
((ImageView) (view)).setImageResource(R.drawable.ic_visibility); | ||
rePass.setTransformationMethod(PasswordTransformationMethod.getInstance()); | ||
} | ||
rePass.setSelection(rePass.length()); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.