From 18eb7a02e6ca5b5655b268789bfa1997d6e90887 Mon Sep 17 00:00:00 2001 From: Samwel Date: Thu, 4 Jul 2024 22:14:37 +0300 Subject: [PATCH] code optimization --- app/build.gradle | 1 + .../mpesaintegrationandroid/MainActivity.java | 19 +++++++++++++++++-- gradle/libs.versions.toml | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 07fcd04..1b2dc00 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,7 @@ dependencies { implementation libs.butterknife implementation libs.firebase.messaging annotationProcessor libs.butterknife.compiler + implementation libs.core //Networking implementation libs.retrofit implementation libs.converter.gson diff --git a/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java b/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java index d049fd7..a235fce 100644 --- a/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java +++ b/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java @@ -2,7 +2,22 @@ import androidx.appcompat.app.AppCompatActivity; +import android.app.ProgressDialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.mpesaandroidintegration.mpesa.Mpesa; +import com.mpesaandroidintegration.mpesa.interfaces.AuthListener; +import com.mpesaandroidintegration.mpesa.interfaces.MpesaListener; +import com.mpesaandroidintegration.mpesa.models.STKPush; +import com.mpesaandroidintegration.mpesa.utils.Pair; public class MainActivity extends AppCompatActivity implements AuthListener, MpesaListener { //TODO: Replace these values from @@ -35,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) { dialog.setMessage("Processing"); dialog.setIndeterminate(true); - pay.setOnClickListener(new OnClickListener() { + pay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String p = phone.getText().toString(); @@ -75,7 +90,7 @@ public void onAuthSuccess() { } private void pay(String phone, int amount){ dialog.show(); - STKPush.Builder builder = new Builder(BUSINESS_SHORT_CODE, PASSKEY, amount,BUSINESS_SHORT_CODE, phone); + STKPush.Builder builder = new STKPush.Builder(BUSINESS_SHORT_CODE, PASSKEY, amount,BUSINESS_SHORT_CODE, phone); SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); String token = sharedPreferences.getString("InstanceID", ""); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d3b0215..ff9dc06 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,7 @@ appcompat = "1.7.0" butterknife = "10.2.3" constraintlayout = "2.1.4" +core = "0.9.5.0" espressoCore = "3.6.1" gson = "2.10.1" junit = "4.13.2" @@ -18,6 +19,7 @@ butterknife = { module = "com.jakewharton:butterknife", version.ref = "butterkni butterknife-compiler = { module = "com.jakewharton:butterknife-compiler", version.ref = "butterknife" } constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" } converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" } +core = { module = "com.afollestad.material-dialogs:core", version.ref = "core" } espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" } ext-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" } gson = { module = "com.google.code.gson:gson", version.ref = "gson" }