|
|
|
@ -1,24 +1,33 @@
|
|
|
|
|
package com.cst.im30.activity; |
|
|
|
|
|
|
|
|
|
import static android.Manifest.permission.READ_EXTERNAL_STORAGE; |
|
|
|
|
import static android.Manifest.permission.READ_PHONE_STATE; |
|
|
|
|
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; |
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.app.AlertDialog; |
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.content.pm.PackageManager; |
|
|
|
|
import android.graphics.Color; |
|
|
|
|
import android.graphics.drawable.AnimationDrawable; |
|
|
|
|
import android.graphics.drawable.ColorDrawable; |
|
|
|
|
import android.os.Build; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.os.Handler; |
|
|
|
|
import android.view.LayoutInflater; |
|
|
|
|
import android.view.View; |
|
|
|
|
import android.widget.ImageView; |
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
import android.widget.TextView; |
|
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
import androidx.activity.result.ActivityResultLauncher; |
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts; |
|
|
|
|
import androidx.annotation.RequiresApi; |
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
import androidx.core.content.ContextCompat; |
|
|
|
|
|
|
|
|
|
import com.cst.im30.BuildConfig; |
|
|
|
|
import com.cst.im30.EchoClient; |
|
|
|
@ -39,22 +48,28 @@ import com.cst.im30.utility.PaymentUtils;
|
|
|
|
|
import com.daimajia.slider.library.SliderLayout; |
|
|
|
|
import com.daimajia.slider.library.SliderTypes.BaseSliderView; |
|
|
|
|
import com.daimajia.slider.library.SliderTypes.TextSliderView; |
|
|
|
|
import com.jakewharton.processphoenix.ProcessPhoenix; |
|
|
|
|
|
|
|
|
|
import net.mrbin99.laravelechoandroid.EchoCallback; |
|
|
|
|
|
|
|
|
|
import org.json.JSONException; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements CallableInterface { |
|
|
|
|
public static final String TAG = "MainActivity."; |
|
|
|
|
|
|
|
|
|
ImageView load; |
|
|
|
|
AnimationDrawable animationDrawable; |
|
|
|
|
private ImageView load; |
|
|
|
|
private AnimationDrawable animationDrawable; |
|
|
|
|
|
|
|
|
|
private String status; |
|
|
|
|
// Echo Server Connection
|
|
|
|
|
private LinearLayout echoStatusLayout; |
|
|
|
|
private ImageView paymentEchoStatusImageView, icEchoStatusImageView; |
|
|
|
|
private TextView paymentEchoStatusTextView, icEchoStatusTextView; |
|
|
|
|
|
|
|
|
|
private TextView testTitle; //todo until new screen
|
|
|
|
|
|
|
|
|
@ -74,9 +89,11 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
if (verifyIC(name, cardNo)) { |
|
|
|
|
showStatusDialog(true, "NRIC Match"); |
|
|
|
|
service.verifySuccess(MainApplication.currentCode); |
|
|
|
|
Logger.recordICScan("[MATCH] " + name + ":" + cardNo); |
|
|
|
|
} else { |
|
|
|
|
showStatusDialog(false, "NRIC Not Match"); |
|
|
|
|
service.verifyFail(MainApplication.currentCode); |
|
|
|
|
Logger.recordICScan("[NOT MATCH] " + name + ":" + cardNo); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (result.getResultCode() == Activity.RESULT_CANCELED) { |
|
|
|
@ -89,14 +106,23 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.M) |
|
|
|
|
@Override |
|
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
|
|
|
|
|
|
checkPermissions(); |
|
|
|
|
|
|
|
|
|
sliderLayout = findViewById(R.id.slider_layout_ma); |
|
|
|
|
sliderLayout.setVisibility(View.INVISIBLE); //todo until get good image
|
|
|
|
|
|
|
|
|
|
echoStatusLayout = findViewById(R.id.echoStatusLayout); |
|
|
|
|
paymentEchoStatusImageView = findViewById(R.id.paymentEchoStatusImageView); |
|
|
|
|
icEchoStatusImageView = findViewById(R.id.icEchoStatusImageView); |
|
|
|
|
paymentEchoStatusTextView = findViewById(R.id.paymentEchoStatusTextView); |
|
|
|
|
icEchoStatusTextView = findViewById(R.id.icEchoStatusTextView); |
|
|
|
|
|
|
|
|
|
testTitle = findViewById(R.id.testText); |
|
|
|
|
|
|
|
|
|
load = findViewById(R.id.loading_image_mt); |
|
|
|
@ -212,9 +238,13 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
sliderLayout.setVisibility(View.INVISIBLE); |
|
|
|
|
testTitle.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
|
|
animationDrawable = (AnimationDrawable) load.getDrawable(); |
|
|
|
|
animationDrawable.start(); |
|
|
|
|
load.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
|
|
echoStatusLayout.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -224,7 +254,10 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
//sliderLayout.setVisibility(View.VISIBLE);
|
|
|
|
|
testTitle.setVisibility(View.VISIBLE); |
|
|
|
|
animationDrawable.stop(); |
|
|
|
|
load.setVisibility(View.GONE); |
|
|
|
|
|
|
|
|
|
echoStatusLayout.setVisibility(View.VISIBLE); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -581,18 +614,19 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
@Override |
|
|
|
|
public void onDestroy() { |
|
|
|
|
super.onDestroy(); |
|
|
|
|
|
|
|
|
|
disconnectEchoClientIC(); |
|
|
|
|
disconnectEchoClientPayment(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initEchoClientIC() { |
|
|
|
|
Logger.logD("echoClient IC: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); |
|
|
|
|
MainApplication.icClient = new EchoClient(this, BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); |
|
|
|
|
//Logger.logD("echoClient IC: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
|
|
|
|
|
MainApplication.icClient = new EchoClient(BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initEchoClientPayment() { |
|
|
|
|
Logger.logD("echoClient Payment: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); |
|
|
|
|
MainApplication.paymentClient = new EchoClient(this, BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); |
|
|
|
|
//Logger.logD("echoClient Payment: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
|
|
|
|
|
MainApplication.paymentClient = new EchoClient(BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void connectEchoClientIC() { |
|
|
|
@ -616,13 +650,17 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onConnectSuccessPayment(Object[] args) { |
|
|
|
|
MainApplication.paymentIsConnected = true; |
|
|
|
|
try { |
|
|
|
|
String channelID = BuildConfig.SOCKET_PREFIX + BuildConfig.PAYMENT_CHANNEL_ID + BuildConfig.KIOSK_CODE; |
|
|
|
|
String eventType = BuildConfig.PAYMENT_EVENT_TYPE; |
|
|
|
|
EchoCallback echoCallback = this::receiveMessagePayment; |
|
|
|
|
MainApplication.paymentClient.channel(channelID).listen(eventType, echoCallback); |
|
|
|
|
Logger.logD("Listening to: " + eventType + " on " + channelID); |
|
|
|
|
|
|
|
|
|
MainApplication.paymentIsConnected = true; |
|
|
|
|
MainApplication.failCountPayment = 0; |
|
|
|
|
|
|
|
|
|
updatePaymentOnline(); |
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
Logger.logE("Error on contact: " + ex.getMessage()); |
|
|
|
|
} |
|
|
|
@ -630,17 +668,31 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
|
|
|
|
|
private void onConnectFailurePayment(Object[] args) { |
|
|
|
|
MainApplication.paymentIsConnected = false; |
|
|
|
|
Logger.logW("Failed To Connect Payment"); |
|
|
|
|
if (MainApplication.failCountIC == 0) { |
|
|
|
|
Logger.logW("Failed To Connect to Payment Socket. Retrying up to " + MainApplication.MAX_RETRY + " times"); |
|
|
|
|
} |
|
|
|
|
MainApplication.failCountPayment++; |
|
|
|
|
|
|
|
|
|
if (MainApplication.failCountPayment >= MainApplication.MAX_RETRY) { |
|
|
|
|
Logger.logE("Payment Echo Connection Failed More than " + MainApplication.MAX_RETRY + " times! Restarting app..."); |
|
|
|
|
ProcessPhoenix.triggerRebirth(MainActivity.this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updatePaymentOffline(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onConnectSuccessIC(Object[] args) { |
|
|
|
|
MainApplication.icIsConnected = true; |
|
|
|
|
try { |
|
|
|
|
String channelID = BuildConfig.SOCKET_PREFIX + BuildConfig.IC_CHANNEL_ID + BuildConfig.KIOSK_CODE; |
|
|
|
|
String eventType = BuildConfig.IC_EVENT_TYPE; |
|
|
|
|
EchoCallback echoCallback = this::receiveMessageIC; |
|
|
|
|
MainApplication.icClient.channel(channelID).listen(eventType, echoCallback); |
|
|
|
|
Logger.logD("Listening to: " + eventType + " on " + channelID); |
|
|
|
|
|
|
|
|
|
MainApplication.icIsConnected = true; |
|
|
|
|
MainApplication.failCountIC = 0; |
|
|
|
|
|
|
|
|
|
updateICOnline(); |
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
Logger.logE("Error on contact: " + ex.getMessage()); |
|
|
|
|
} |
|
|
|
@ -648,10 +700,53 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
|
|
|
|
|
private void onConnectFailureIC(Object[] args) { |
|
|
|
|
MainApplication.icIsConnected = false; |
|
|
|
|
Logger.logW("Failed To Connect IC"); |
|
|
|
|
if (MainApplication.failCountIC == 0) { |
|
|
|
|
Logger.logW("Failed To Connect toIC Socket. Retrying up to " + MainApplication.MAX_RETRY + " times"); |
|
|
|
|
} |
|
|
|
|
MainApplication.failCountIC++; |
|
|
|
|
|
|
|
|
|
if (MainApplication.failCountIC >= MainApplication.MAX_RETRY) { |
|
|
|
|
Logger.logE("IC Echo Connection Failed More than " + MainApplication.MAX_RETRY + " times! Restarting app..."); |
|
|
|
|
ProcessPhoenix.triggerRebirth(MainActivity.this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateICOffline(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updatePaymentOnline() { |
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
paymentEchoStatusImageView.setImageResource(R.drawable.echo_payment_online); |
|
|
|
|
paymentEchoStatusTextView.setText(R.string.online_caps); |
|
|
|
|
paymentEchoStatusTextView.setTextColor(getResources().getColor(R.color.online)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updatePaymentOffline() { |
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
paymentEchoStatusImageView.setImageResource(R.drawable.echo_payment_offline); |
|
|
|
|
paymentEchoStatusTextView.setText(R.string.offline_caps); |
|
|
|
|
paymentEchoStatusTextView.setTextColor(getResources().getColor(R.color.offline)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updateICOnline() { |
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
icEchoStatusImageView.setImageResource(R.drawable.echo_ic_online); |
|
|
|
|
icEchoStatusTextView.setText(R.string.online_caps); |
|
|
|
|
icEchoStatusTextView.setTextColor(getResources().getColor(R.color.online)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updateICOffline() { |
|
|
|
|
runOnUiThread(() -> { |
|
|
|
|
icEchoStatusImageView.setImageResource(R.drawable.echo_ic_offline); |
|
|
|
|
icEchoStatusTextView.setText(R.string.offline_caps); |
|
|
|
|
icEchoStatusTextView.setTextColor(getResources().getColor(R.color.offline)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void startWork() { |
|
|
|
|
Logger.logD("START WORK"); |
|
|
|
|
MainApplication.working = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -659,4 +754,41 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
|
|
|
|
|
public void onBackPressed() { |
|
|
|
|
Logger.logI("Back Button Disabled!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.M) |
|
|
|
|
private void checkPermissions() { |
|
|
|
|
List<String> permsArray = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
Logger.logD("Requesting Write External Storage Permission"); |
|
|
|
|
permsArray.add(WRITE_EXTERNAL_STORAGE); |
|
|
|
|
} |
|
|
|
|
if (ContextCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
Logger.logD("Requesting Read External Storage Permission"); |
|
|
|
|
permsArray.add(READ_EXTERNAL_STORAGE); |
|
|
|
|
} |
|
|
|
|
if (ContextCompat.checkSelfPermission(this, READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
Logger.logD("Requesting Read Phone State Permission"); |
|
|
|
|
permsArray.add(READ_PHONE_STATE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (permsArray.size() > 0) { |
|
|
|
|
String[] perms = permsArray.toArray(new String[0]); |
|
|
|
|
requestPermissions(perms, 200); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*private void setupCloudWatch() { |
|
|
|
|
String accessKey = ""; |
|
|
|
|
String secretKey = ""; |
|
|
|
|
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey); |
|
|
|
|
AmazonCloudWatchLogsClient client = new AmazonCloudWatchLogsClient(basicAWSCredentials); |
|
|
|
|
Regions regions = Regions.AP_SOUTHEAST_1; // Singapore
|
|
|
|
|
client.setRegion(Region.getRegion(regions)); |
|
|
|
|
|
|
|
|
|
String logGroupName = "TEST123"; |
|
|
|
|
CreateLogGroupRequest createLogGroupRequest = new CreateLogGroupRequest(logGroupName); |
|
|
|
|
|
|
|
|
|
client.createLogGroup(new CreateLogGroupRequest("")); |
|
|
|
|
}*/ |
|
|
|
|
} |