+ * Created by Samset on 23,October,2020 at 6:34 PM for sendotp-android. + *
+ * New Delhi,India + */ + + +public class AppController extends Application { + @Override + public void onCreate() { + super.onCreate(); + SendOTP.initializeApp(this,"authKey"); + + } +} diff --git a/app/src/main/java/com/msg91/sendotp/sample/ApplicationClass.java b/app/src/main/java/com/msg91/sendotp/sample/ApplicationClass.java deleted file mode 100644 index 273526e..0000000 --- a/app/src/main/java/com/msg91/sendotp/sample/ApplicationClass.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.msg91.sendotp.sample; - -import android.app.Application; - -import com.msg91.sendotpandroid.library.internal.SendOTP; - -public class ApplicationClass extends Application { - @Override - public void onCreate() { - super.onCreate(); - SendOTP.initializeApp(this,"authKey"); - } -} diff --git a/app/src/main/java/com/msg91/sendotp/sample/DataManager.java b/app/src/main/java/com/msg91/sendotp/sample/core/DataManager.java similarity index 85% rename from app/src/main/java/com/msg91/sendotp/sample/DataManager.java rename to app/src/main/java/com/msg91/sendotp/sample/core/DataManager.java index 77d189a..832c2c6 100644 --- a/app/src/main/java/com/msg91/sendotp/sample/DataManager.java +++ b/app/src/main/java/com/msg91/sendotp/sample/core/DataManager.java @@ -1,4 +1,4 @@ -package com.msg91.sendotp.sample; +package com.msg91.sendotp.sample.core; import android.app.Dialog; import android.content.Context; @@ -8,6 +8,18 @@ import android.view.WindowManager; import android.widget.TextView; +import com.msg91.sendotp.sample.R; + +/** + * Copyright (C) sendotp-android - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + *
+ * Created by Samset on 23,October,2020 at 6:34 PM for sendotp-android. + *
+ * New Delhi,India + */ + public class DataManager { private static final DataManager ourInstance = new DataManager(); private boolean isProgressDialogRunning; diff --git a/app/src/main/java/com/msg91/sendotp/sample/MainActivity.java b/app/src/main/java/com/msg91/sendotp/sample/ui/MainActivity.java similarity index 87% rename from app/src/main/java/com/msg91/sendotp/sample/MainActivity.java rename to app/src/main/java/com/msg91/sendotp/sample/ui/MainActivity.java index f7d87d3..013a191 100644 --- a/app/src/main/java/com/msg91/sendotp/sample/MainActivity.java +++ b/app/src/main/java/com/msg91/sendotp/sample/ui/MainActivity.java @@ -1,28 +1,37 @@ -package com.msg91.sendotp.sample; +package com.msg91.sendotp.sample.ui; import android.Manifest; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.os.Bundle; import android.telephony.TelephonyManager; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.View; import android.widget.EditText; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; +import com.msg91.sendotp.sample.R; +import com.msg91.sendotp.sample.utils.CountrySpinner; +import com.msg91.sendotp.sample.utils.NetworkUtils; import com.msg91.sendotpandroid.library.internal.Iso2Phone; import com.msg91.sendotpandroid.library.utils.PhoneNumberFormattingTextWatcher; import com.msg91.sendotpandroid.library.utils.PhoneNumberUtils; +import java.lang.reflect.Method; import java.util.Locale; + public class MainActivity extends AppCompatActivity { public static final String INTENT_PHONENUMBER = "phonenumber"; @@ -32,15 +41,15 @@ public class MainActivity extends AppCompatActivity { private TextView mSmsButton; private String mCountryIso; private TextWatcher mNumberTextWatcher; + private NetworkUtils networkConnectivity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main_new); mPhoneNumber = findViewById(R.id.phoneNumber); mSmsButton = findViewById(R.id.smsVerificationButton); - + networkConnectivity = NetworkUtils.getInstance(); mCountryIso = PhoneNumberUtils.getDefaultCountryIso(this); final String defaultCountryName = new Locale("", mCountryIso).getDisplayName(); final CountrySpinner spinner = (CountrySpinner) findViewById(R.id.spinner); @@ -59,6 +68,7 @@ public void onCountryIsoSelected(String selectedIso) { resetNumberTextWatcher(mCountryIso); tryAndPrefillPhoneNumber(); + } private void tryAndPrefillPhoneNumber() { @@ -75,8 +85,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in tryAndPrefillPhoneNumber(); } else { if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) { - Toast.makeText(this, "This application needs permission to read your phone number to automatically " - + "pre-fill it", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "This application needs permission to read your phone number to automatically pre-fill it", Toast.LENGTH_LONG).show(); } } } @@ -93,7 +102,12 @@ private void setButtonsEnabled(boolean enabled) { } public void onButtonClicked(View view) { - openActivity(getE164Number()); + if (networkConnectivity.isNetworkAvailable(this)) { + openActivity(getE164Number()); + } else { + Toast.makeText(this, "Internet not availble ", Toast.LENGTH_SHORT).show(); + } + } private void resetNumberTextWatcher(String countryIso) { @@ -137,4 +151,6 @@ private String getE164Number() { return mPhoneNumber.getText().toString().replaceAll("\\D", "").trim(); // return PhoneNumberUtils.formatNumberToE164(mPhoneNumber.getText().toString(), mCountryIso); } + + } diff --git a/app/src/main/java/com/msg91/sendotp/sample/VerificationActivity.java b/app/src/main/java/com/msg91/sendotp/sample/ui/VerificationActivity.java similarity index 86% rename from app/src/main/java/com/msg91/sendotp/sample/VerificationActivity.java rename to app/src/main/java/com/msg91/sendotp/sample/ui/VerificationActivity.java index 79e111f..436744a 100644 --- a/app/src/main/java/com/msg91/sendotp/sample/VerificationActivity.java +++ b/app/src/main/java/com/msg91/sendotp/sample/ui/VerificationActivity.java @@ -1,39 +1,43 @@ -package com.msg91.sendotp.sample; +package com.msg91.sendotp.sample.ui; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer; -import android.util.Log; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import com.msg91.sendotp.sample.R; +import com.msg91.sendotp.sample.core.DataManager; +import com.msg91.sendotp.sample.utils.NetworkUtils; +import com.msg91.sendotp.sample.utils.OtpEditText; import com.msg91.sendotpandroid.library.internal.SendOTP; import com.msg91.sendotpandroid.library.listners.VerificationListener; import com.msg91.sendotpandroid.library.roots.RetryType; import com.msg91.sendotpandroid.library.roots.SendOTPConfigBuilder; import com.msg91.sendotpandroid.library.roots.SendOTPResponseCode; - public class VerificationActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, VerificationListener { private static final String TAG = "VerificationActivity"; private static final int OTP_LNGTH = 4; TextView resend_timer; private OtpEditText mOtpEditText; + private NetworkUtils networkConnectivity; + @Override protected void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); setContentView(R.layout.activity_verification); resend_timer = (TextView) findViewById(R.id.resend_timer); @@ -46,8 +50,15 @@ public void onClick(View v) { startTimer(); mOtpEditText = findViewById(R.id.inputCode); mOtpEditText.setMaxLength(OTP_LNGTH); - enableInputField(true); - initiateVerification(); + networkConnectivity = NetworkUtils.getInstance(); + if (networkConnectivity.isNetworkAvailable(this)) { + enableInputField(true); + initiateVerification(); + } else { + Toast.makeText(this, "Internet not availble ", Toast.LENGTH_SHORT).show(); + } + + } void createVerification(String phoneNumber, int countryCode) { @@ -65,7 +76,6 @@ void createVerification(String phoneNumber, int countryCode) { .setMessage("##OTP## is Your verification digits.") .setOtpLength(OTP_LNGTH) .setVerificationCallBack(this).build(); - SendOTP.getInstance().getTrigger().initiate(); @@ -91,14 +101,18 @@ public void ResendCode() { public void onSubmitClicked(View view) { String code = mOtpEditText.getText().toString(); - if (!code.isEmpty()) { - hideKeypad(); - verifyOtp(code); - DataManager.getInstance().showProgressMessage(this, ""); - TextView messageText = (TextView) findViewById(R.id.textView); - messageText.setText("Verification in progress"); - enableInputField(false); + if (networkConnectivity.isNetworkAvailable(this)) { + if (!code.isEmpty()) { + hideKeypad(); + verifyOtp(code); + DataManager.getInstance().showProgressMessage(this, ""); + TextView messageText = (TextView) findViewById(R.id.textView); + messageText.setText("Verification in progress"); + enableInputField(false); + } + }else { + Toast.makeText(this, "Internet not availble ", Toast.LENGTH_SHORT).show(); } } @@ -160,7 +174,7 @@ public void onSendOtpResponse(final SendOTPResponseCode responseCode, final Stri runOnUiThread(new Runnable() { @Override public void run() { - Log.e(TAG, "onSendOtpResponse: " + responseCode.getCode() + "=======" + message); + //Log.e(TAG, "onSendOtpResponse: " + responseCode.getCode() + "=======" + message); if (responseCode == SendOTPResponseCode.DIRECT_VERIFICATION_SUCCESSFUL_FOR_NUMBER || responseCode == SendOTPResponseCode.OTP_VERIFIED) { DataManager.getInstance().hideProgressMessage(); enableInputField(false); @@ -194,12 +208,14 @@ public void run() { DataManager.getInstance().hideProgressMessage(); } else if (responseCode == SendOTPResponseCode.NO_INTERNET_CONNECTED) { DataManager.getInstance().hideProgressMessage(); + Toast.makeText(VerificationActivity.this, "Internet not availble ", Toast.LENGTH_SHORT).show(); } else { DataManager.getInstance().hideProgressMessage(); hideKeypad(); hideProgressBarAndShowMessage(R.string.failed); enableInputField(true); } + SendOTP.getInstance().getTrigger().stop(); } }); } @@ -233,9 +249,5 @@ private void hideKeypad() { } } - @Override - protected void onDestroy() { - super.onDestroy(); - SendOTP.getInstance().getTrigger().stop(); - } + } diff --git a/app/src/main/java/com/msg91/sendotp/sample/CountrySpinner.java b/app/src/main/java/com/msg91/sendotp/sample/utils/CountrySpinner.java similarity index 87% rename from app/src/main/java/com/msg91/sendotp/sample/CountrySpinner.java rename to app/src/main/java/com/msg91/sendotp/sample/utils/CountrySpinner.java index a5916f4..bc97a5f 100644 --- a/app/src/main/java/com/msg91/sendotp/sample/CountrySpinner.java +++ b/app/src/main/java/com/msg91/sendotp/sample/utils/CountrySpinner.java @@ -1,4 +1,4 @@ -package com.msg91.sendotp.sample; +package com.msg91.sendotp.sample.utils; import android.content.Context; import android.util.AttributeSet; @@ -10,12 +10,24 @@ import androidx.appcompat.widget.AppCompatSpinner; import androidx.core.content.ContextCompat; +import com.msg91.sendotp.sample.R; + import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TreeMap; +/** + * Copyright (C) sendotp-android - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + *
+ * Created by Samset on 23,October,2020 at 6:34 PM for sendotp-android. + *
+ * New Delhi,India
+ */
+
public class CountrySpinner extends AppCompatSpinner {
private Map
+ * Created by Samset on 23,October,2020 at 6:34 PM for sendotp-android.
+ *
+ * New Delhi,India
+ */
+
public class OtpEditText extends AppCompatEditText {
private float mSpace = 10; //24 dp by default, space between the lines
private float mNumChars = 4;
diff --git a/app/src/main/res/layout/activity_main_new.xml b/app/src/main/res/layout/activity_main_new.xml
index f06e4e3..f7e88e8 100644
--- a/app/src/main/res/layout/activity_main_new.xml
+++ b/app/src/main/res/layout/activity_main_new.xml
@@ -4,7 +4,7 @@
android:layout_height="match_parent"
android:background="@drawable/gradient_bg"
android:padding="0dip"
- tools:context=".MainActivity">
+ tools:context=".ui.MainActivity">