Commit 0d531246 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Bug fixed

App connection fix
Duplicate applications fix
Securize activites by checking nemopay session
parent e009905c
......@@ -178,34 +178,26 @@ public abstract class BaseActivity extends InternetActivity {
}
protected void restartApp(final Activity activity) {
try {
PackageManager pm = getPackageManager();
Intent mStartActivity = pm.getLaunchIntentForPackage(
getPackageName()
);
mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int mPendingIntentId = 223344;
PendingIntent mPendingIntent = PendingIntent.getActivity(activity, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
}
startMainActivity(activity);
}
protected void startMainActivity(final Activity activity) {
disconnect();
if (activity instanceof MainActivity)
((MainActivity) activity).launch();
else {
disconnect();
Intent intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
activity.startActivity(intent);
Intent intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
activity.startActivity(intent);
}
}
protected void startFoundationListActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
if (config.getFoundationId() != -1) {
startSellActivity(activity);
return;
......@@ -260,15 +252,24 @@ public abstract class BaseActivity extends InternetActivity {
}
public void startSellActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
}
public void startEditActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
config.setInCategory(true); // Do not allow keyboard modification (not supported yet)
startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
}
public void startArticleGroupActivity(final Activity activity, final Intent intent) {
if (!nemopaySession.isConnected())
restartApp(activity);
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), getString(R.string.location_list_collecting));
new Thread() {
......@@ -484,6 +485,9 @@ public abstract class BaseActivity extends InternetActivity {
}
protected void startBuyerInfoActivity(final Activity activity, final String badgeId) {
if (!nemopaySession.isConnected())
restartApp(activity);
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.buyer_info_collecting));
final Intent intent = new Intent(activity, BuyerInfoActivity.class);
......@@ -546,6 +550,9 @@ public abstract class BaseActivity extends InternetActivity {
}
protected void startCardManagementActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"GESUSERS"}, true, new Runnable() {
@Override
public void run() {
......@@ -555,20 +562,15 @@ public abstract class BaseActivity extends InternetActivity {
}
protected void startQRCodeReaderActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
if (haveCameraPermission())
startActivity(new Intent(activity, QRCodeReaderActivity.class));
else
dialog.errorDialog(BaseActivity.this, getString(R.string.qrcode), getString(R.string.need_camera_permission));
}
protected void delKey() {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.remove("key");
edit.apply();
unregister(BaseActivity.this);
}
protected void setNemopayKey(final String key) {
if (key.equals(""))
return;
......
......@@ -50,50 +50,7 @@ public class MainActivity extends BaseActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sharedPreferences = getSharedPreferences("payutc", Activity.MODE_PRIVATE);
nemopaySession = new NemopaySession(MainActivity.this);
ginger = new Ginger(MainActivity.this);
casConnexion = new CASConnexion(nemopaySession);
config = new Config(sharedPreferences);
setNemopayKey(sharedPreferences.getString("key", ""));
ginger.setKey(sharedPreferences.getString("key_ginger", ""));
appImg = findViewById(R.id.img_payutc);
appNameText = findViewById(R.id.text_app_name);
appConfigText = findViewById(R.id.text_app_config);
appRegisteredText = findViewById(R.id.text_app_registered);
usernameButton = findViewById(R.id.button_username);
casConnexionDialog = false;
appImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
config.reset();
restartApp(MainActivity.this);
return false;
}
});
appRegisteredText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
optionDialog();
return false;
}
});
usernameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
casDialog();
}
});
setConfig();
checkUpdate(false);
launch();
}
@Override
......@@ -108,6 +65,8 @@ public class MainActivity extends BaseActivity {
if (!key.equals(""))
setNemopayKey(key);
}
checkUpdate(false);
}
@Override
......@@ -128,6 +87,8 @@ public class MainActivity extends BaseActivity {
@Override
protected void enableInternetDialog(final Context context) {
Toast.makeText(context, R.string.internet_not_available, Toast.LENGTH_SHORT).show();
appRegisteredText.setText(R.string.app_not_connected);
appRegisteredText.setOnLongClickListener(null);
dialog.infoDialog(MainActivity.this, getString(R.string.connection), getString(R.string.internet_accessibility), new DialogInterface.OnClickListener() {
@Override
......@@ -166,6 +127,53 @@ public class MainActivity extends BaseActivity {
((TextView) findViewById(R.id.text_app_registered)).setText(R.string.app_not_registred);
}
protected void launch() {
sharedPreferences = getSharedPreferences("payutc", Activity.MODE_PRIVATE);
nemopaySession = new NemopaySession(MainActivity.this);
ginger = new Ginger(MainActivity.this);
casConnexion = new CASConnexion(nemopaySession);
config = new Config(sharedPreferences);
setNemopayKey(sharedPreferences.getString("key", ""));
ginger.setKey(sharedPreferences.getString("key_ginger", ""));
appImg = findViewById(R.id.img_payutc);
appNameText = findViewById(R.id.text_app_name);
appConfigText = findViewById(R.id.text_app_config);
appRegisteredText = findViewById(R.id.text_app_registered);
usernameButton = findViewById(R.id.button_username);
casConnexionDialog = false;
appImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
config.reset();
restartApp(MainActivity.this);
return false;
}
});
appRegisteredText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
optionDialog();
return false;
}
});
usernameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
casDialog();
}
});
setConfig();
checkUpdate(false);
}
protected void setConfig() {
if (config.getFoundationId() != -1) {
appNameText.setText(config.getFoundationName());
......
......@@ -65,9 +65,9 @@
android:id="@+id/text_app_registered"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:gravity="center"
android:textStyle="italic"
android:text="@string/app_not_connected" />
android:paddingBottom="10dp"
android:text="@string/app_not_registred"
android:textStyle="italic" />
</LinearLayout>
</RelativeLayout>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment