Created
December 28, 2025 21:43
-
-
Save sajjadyousefnia/debe12d0063a801a264153f8daf0fac0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.asantech.asanpay.setting; | |
| import android.app.ProgressDialog; | |
| import android.os.Bundle; | |
| import android.widget.EditText; | |
| import android.widget.Toast; | |
| import androidx.appcompat.app.AppCompatActivity; | |
| import com.android.volley.DefaultRetryPolicy; | |
| import com.android.volley.Request; | |
| import com.android.volley.RequestQueue; | |
| import com.android.volley.toolbox.StringRequest; | |
| import com.android.volley.toolbox.Volley; | |
| import com.asantech.asanpay.R; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.Objects; | |
| public class ChangePincodeActivity extends AppCompatActivity { | |
| private EditText lastpin_edittext; | |
| private EditText newpin1_edittext; | |
| private EditText newpin2_edittext; | |
| private ProgressDialog progressDialog; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_change_pincode); | |
| Objects.requireNonNull(getSupportActionBar()).hide(); | |
| progressDialog = new ProgressDialog(ChangePincodeActivity.this); | |
| progressDialog.setMessage(getString(R.string.Pleasewait)); | |
| lastpin_edittext = findViewById(R.id.lastpin_edittext); | |
| newpin1_edittext = findViewById(R.id.newpin1_edittext); | |
| newpin2_edittext = findViewById(R.id.newpin2_edittext); | |
| findViewById(R.id.confirm_btn).setOnClickListener(v -> { | |
| String lastPin = lastpin_edittext.getText().toString().trim(); | |
| String newPin1 = newpin1_edittext.getText().toString().trim(); | |
| String newPin2 = newpin2_edittext.getText().toString().trim(); | |
| if (ISValidInputs(lastPin, newPin1, newPin2)) { | |
| ChangePassword(lastPin, newPin2); | |
| } | |
| }); | |
| findViewById(R.id.dismiss_btn).setOnClickListener(v -> { | |
| finish(); | |
| }); | |
| findViewById(R.id.back_ibtn).setOnClickListener(v -> { | |
| finish(); | |
| }); | |
| } | |
| private void ChangePassword(String oldpin, String newpin) { | |
| progressDialog.show(); | |
| RequestQueue requestQueue = Volley.newRequestQueue(ChangePincodeActivity.this); | |
| String req_url = Globals.global_link + "user_changepin.php"; | |
| StringRequest stringRequest = new StringRequest(Request.Method.POST, req_url, response -> { | |
| progressDialog.dismiss(); | |
| try { | |
| JSONObject jresponse = new JSONObject(response); | |
| Boolean status = jresponse.getBoolean("status"); | |
| String message = jresponse.getString("message"); | |
| if (status) { | |
| Toast.makeText(ChangePincodeActivity.this, message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| finish(); | |
| } else { | |
| Toast.makeText(ChangePincodeActivity.this, message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| } | |
| } catch (JSONException e) { | |
| Toast.makeText(ChangePincodeActivity.this, getString(R.string.severError), Toast.LENGTH_LONG).show(); | |
| } | |
| }, error -> { | |
| progressDialog.dismiss(); | |
| Toast.makeText(ChangePincodeActivity.this, getString(R.string.severError), Toast.LENGTH_LONG).show(); | |
| }) { | |
| @Override | |
| protected Map<String, String> getParams() { | |
| Map<String, String> params = new HashMap<>(); | |
| params.put("private_key", Globals.getUser(ChangePincodeActivity.this)); | |
| params.put("old_pin", oldpin); | |
| params.put("new_pin", newpin); | |
| return params; | |
| } | |
| }; | |
| stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); | |
| requestQueue.add(stringRequest); | |
| } | |
| private boolean ISValidInputs(String lastPin, String newPin1, String newPin2) { | |
| if (lastPin.length() == 4) { | |
| if (newPin1.length() == 4) { | |
| if (newPin1.equals(newPin2)) { | |
| return true; | |
| } else { | |
| Toast.makeText(ChangePincodeActivity.this, getString(R.string.change_pin_err3), Toast.LENGTH_SHORT).show(); | |
| return false; | |
| } | |
| } else { | |
| Toast.makeText(ChangePincodeActivity.this, getString(R.string.change_pin_err2), Toast.LENGTH_SHORT).show(); | |
| return false; | |
| } | |
| } else { | |
| Toast.makeText(ChangePincodeActivity.this, getString(R.string.change_pin_err1), Toast.LENGTH_SHORT).show(); | |
| return false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment