Commit 68ef471f authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'release/v0.11.9'

parents cc1b1898 a87144ef
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/PayUTC.iml" filepath="$PROJECT_DIR$/PayUTC.iml" /> <module fileurl="file://$PROJECT_DIR$/PayUTC.iml" filepath="$PROJECT_DIR$/PayUTC.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/jessy.iml" filepath="$PROJECT_DIR$/jessy.iml" />
</modules> </modules>
</component> </component>
</project> </project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.utc.simde.jessy" package="fr.utc.simde.jessy"
android:versionCode="33" android:versionCode="42"
android:versionName="0.11.0"> android:versionName="0.11.9">
<uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
......
...@@ -177,14 +177,14 @@ public abstract class ArticleGroupActivity extends BaseActivity { ...@@ -177,14 +177,14 @@ public abstract class ArticleGroupActivity extends BaseActivity {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleGroupActivity.this); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleGroupActivity.this);
alertDialogBuilder alertDialogBuilder
.setTitle(R.string.configuration) .setTitle(R.string.configuration)
.setView(popupView) .setView(popupView)
.setCancelable(false) .setCancelable(false)
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) { public void onClick(DialogInterface dialogInterface, int id) {
config.setCanCancel(true); config.setCanCancel(true);
} }
}); });
dialog.createDialog(alertDialogBuilder); dialog.createDialog(alertDialogBuilder);
} }
......
...@@ -6,6 +6,7 @@ import android.app.AlarmManager; ...@@ -6,6 +6,7 @@ import android.app.AlarmManager;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
...@@ -102,8 +103,17 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -102,8 +103,17 @@ public abstract class BaseActivity extends InternetActivity {
}); });
} }
protected void hasRights(final String title, final String[] rightList, final Runnable runnable) { hasRights(title, rightList, false, runnable);} protected void hasRights(final String title, final String[] rightList, final Runnable runnablePos) { hasRights(title, rightList, false, runnablePos);}
protected void hasRights(final String title, final String[] rightList, final boolean needToBeSuper, final Runnable runnable) { protected void hasRights(final String title, final String[] rightList, final boolean needToBeSuper, final Runnable runnablePos) {
hasRights(title, rightList, false, runnablePos, new Runnable() {
@Override
public void run() {
dialog.errorDialog(BaseActivity.this, title, nemopaySession.forbidden(rightList, needToBeSuper));
}
});
}
protected void hasRights(final String title, final String[] rightList, final Runnable runnablePos, final Runnable runnableNeg) { hasRights(title, rightList, false, runnablePos, runnableNeg);}
protected void hasRights(final String title, final String[] rightList, final boolean needToBeSuper, final Runnable runnablePos, final Runnable runnableNeg) {
dialog.startLoading(BaseActivity.this, getString(R.string.information_collection), getString(R.string.user_rights_list_collecting)); dialog.startLoading(BaseActivity.this, getString(R.string.information_collection), getString(R.string.user_rights_list_collecting));
new Thread() { new Thread() {
@Override @Override
...@@ -125,6 +135,18 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -125,6 +135,18 @@ public abstract class BaseActivity extends InternetActivity {
if (!needToBeSuper) { if (!needToBeSuper) {
for (JsonNode foundation : myRightList) { for (JsonNode foundation : myRightList) {
if (rightList.length == 0 && foundation.size() > 75) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
runnablePos.run();
}
});
return;
}
for (JsonNode myRight : foundation) { for (JsonNode myRight : foundation) {
if (rights.contains(myRight.textValue()) && !sameRights.contains(myRight.textValue())) if (rights.contains(myRight.textValue()) && !sameRights.contains(myRight.textValue()))
sameRights.add(myRight.textValue()); sameRights.add(myRight.textValue());
...@@ -137,7 +159,7 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -137,7 +159,7 @@ public abstract class BaseActivity extends InternetActivity {
@Override @Override
public void run() { public void run() {
dialog.stopLoading(); dialog.stopLoading();
runnable.run(); runnablePos.run();
} }
}); });
else { else {
...@@ -145,7 +167,7 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -145,7 +167,7 @@ public abstract class BaseActivity extends InternetActivity {
@Override @Override
public void run() { public void run() {
dialog.stopLoading(); dialog.stopLoading();
dialog.errorDialog(BaseActivity.this, title, nemopaySession.forbidden(rightList, needToBeSuper)); runnableNeg.run();
} }
}); });
} }
...@@ -166,34 +188,26 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -166,34 +188,26 @@ public abstract class BaseActivity extends InternetActivity {
} }
protected void restartApp(final Activity activity) { protected void restartApp(final Activity activity) {
try { startMainActivity(activity);
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());
}
} }
protected void startMainActivity(final Activity 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 intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish(); finish();
activity.startActivity(intent); activity.startActivity(intent);
}
} }
protected void startFoundationListActivity(final Activity activity) { protected void startFoundationListActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
if (config.getFoundationId() != -1) { if (config.getFoundationId() != -1) {
startSellActivity(activity); startSellActivity(activity);
return; return;
...@@ -248,14 +262,24 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -248,14 +262,24 @@ public abstract class BaseActivity extends InternetActivity {
} }
public void startSellActivity(final Activity activity) { public void startSellActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class)); startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
} }
public void startEditActivity(final Activity activity) { 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)); startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
} }
public void startArticleGroupActivity(final Activity activity, final Intent intent) { 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)); dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), getString(R.string.location_list_collecting));
new Thread() { new Thread() {
...@@ -471,6 +495,9 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -471,6 +495,9 @@ public abstract class BaseActivity extends InternetActivity {
} }
protected void startBuyerInfoActivity(final Activity activity, final String badgeId) { 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)); 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); final Intent intent = new Intent(activity, BuyerInfoActivity.class);
...@@ -533,6 +560,9 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -533,6 +560,9 @@ public abstract class BaseActivity extends InternetActivity {
} }
protected void startCardManagementActivity(final Activity activity) { 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() { hasRights(getString(R.string.user_rights_list_collecting), new String[]{"GESUSERS"}, true, new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -542,20 +572,15 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -542,20 +572,15 @@ public abstract class BaseActivity extends InternetActivity {
} }
protected void startQRCodeReaderActivity(final Activity activity) { protected void startQRCodeReaderActivity(final Activity activity) {
if (!nemopaySession.isConnected())
restartApp(activity);
if (haveCameraPermission()) if (haveCameraPermission())
startActivity(new Intent(activity, QRCodeReaderActivity.class)); startActivity(new Intent(activity, QRCodeReaderActivity.class));
else else
dialog.errorDialog(BaseActivity.this, getString(R.string.qrcode), getString(R.string.need_camera_permission)); 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) { protected void setNemopayKey(final String key) {
if (key.equals("")) if (key.equals(""))
return; return;
......
...@@ -135,70 +135,110 @@ public class BuyerInfoActivity extends BaseActivity { ...@@ -135,70 +135,110 @@ public class BuyerInfoActivity extends BaseActivity {
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) { public void onClick(DialogInterface dialogInterface, int id) {
new Thread() { hasRights(getString(R.string.cancel_transaction), new String[]{
"GESSALES"
}, new Runnable() {
@Override @Override
public void run() { public void run() {
try { new Thread() {
nemopaySession.cancelTransaction(article.get("fundation_id").intValue(), article.get("purchase_id").intValue()); @Override
Thread.sleep(100); public void run() {
try {
runOnUiThread(new Runnable() { nemopaySession.cancelTransaction(article.get("fundation_id").intValue(), article.get("purchase_id").intValue(), true);
@Override Thread.sleep(100);
public void run() { } catch (final Exception e) {
dialog.stopLoading(); Log.e(LOG_TAG, "error: " + e.getMessage());
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BuyerInfoActivity.this); try {
alertDialogBuilder final JsonNode response = nemopaySession.getRequest().getJSONResponse();
.setTitle(R.string.cancel_transaction)
.setMessage(getString(R.string.transaction_canceled)) if (response.has("error") && response.get("error").has("message")) {
.setCancelable(true) runOnUiThread(new Runnable() {
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialogInterface, int id) { public void run() {
try { dialog.stopLoading();
startBuyerInfoActivity(BuyerInfoActivity.this, badgeId); dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), response.get("error").get("message").textValue());
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(BuyerInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
}
} }
}); });
} else
dialog.createDialog(alertDialogBuilder); throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), e.getMessage());
}
});
}
} }
}); }
} catch (final Exception e) { }.start();
Log.e(LOG_TAG, "error: " + e.getMessage()); }
}, new Runnable() {
try { @Override
final JsonNode response = nemopaySession.getRequest().getJSONResponse(); public void run() {
new Thread() {
if (response.has("error") && response.get("error").has("message")) { @Override
runOnUiThread(new Runnable() { public void run() {
try {
nemopaySession.cancelTransaction(article.get("fundation_id").intValue(), article.get("purchase_id").intValue(), false);
Thread.sleep(100);
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
final JsonNode response = nemopaySession.getRequest().getJSONResponse();
if (response.has("error") && response.get("error").has("message")) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), response.get("error").get("message").textValue());
}
});
} else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), e.getMessage());
}
});
}
}
}
}.start();
}
});
dialog.stopLoading();
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BuyerInfoActivity.this);
alertDialogBuilder
.setTitle(R.string.cancel_transaction)
.setMessage(getString(R.string.transaction_canceled))
.setCancelable(true)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
try {
startBuyerInfoActivity(BuyerInfoActivity.this, badgeId);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(BuyerInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override @Override
public void run() { public void onClick(DialogInterface dialogInterface, int id) {
dialog.stopLoading(); finish();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), response.get("error").get("message").textValue());
} }
}); });
} else }
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), e.getMessage());
}
});
} }
} });
}
}.start(); dialog.createDialog(alertDialogBuilder);
} }
}) })
.setNegativeButton(R.string.do_nothing, null); .setNegativeButton(R.string.do_nothing, null);
......
...@@ -145,7 +145,20 @@ public class EditActivity extends ArticleGroupActivity { ...@@ -145,7 +145,20 @@ public class EditActivity extends ArticleGroupActivity {
switchCotisant.setChecked(config.getPrintCotisant()); switchCotisant.setChecked(config.getPrintCotisant());
swtich18.setChecked(config.getPrint18()); swtich18.setChecked(config.getPrint18());
configButton.setVisibility(View.GONE); configButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
hasRights(getString(R.string.configurate), new String[]{
"STAFF",
"GESAPPLICATIONS"
}, new Runnable() {
@Override
public void run() {
configDialog();
}
});
}
});
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(EditActivity.this); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(EditActivity.this);
alertDialogBuilder alertDialogBuilder
...@@ -311,7 +324,7 @@ public class EditActivity extends ArticleGroupActivity { ...@@ -311,7 +324,7 @@ public class EditActivity extends ArticleGroupActivity {
StringBuilder builder = new StringBuilder(dest); StringBuilder builder = new StringBuilder(dest);
builder.replace(dstart, dend, source builder.replace(dstart, dend, source
.subSequence(start, end).toString()); .subSequence(start, end).toString());
if (!builder.toString().matches("(([1-9]{1})([0-9]{0,"+(maxDigitsBeforeDecimalPoint-1)+"})?)?(\\.[0-9]{0,"+maxDigitsAfterDecimalPoint+"})?")) { if (!builder.toString().matches("((([1-9]{1})([0-9]{0,"+(maxDigitsBeforeDecimalPoint-1)+"})?)|0)?(\\.[0-9]{0,"+maxDigitsAfterDecimalPoint+"})?")) {
if (source.length() == 0) if (source.length() == 0)
return dest.subSequence(dstart, dend); return dest.subSequence(dstart, dend);
return ""; return "";
...@@ -444,7 +457,7 @@ public class EditActivity extends ArticleGroupActivity { ...@@ -444,7 +457,7 @@ public class EditActivity extends ArticleGroupActivity {
.setTitle(R.string.configuration) .setTitle(R.string.configuration)
.setView(popupView) .setView(popupView)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.reload, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) { public void onClick(DialogInterface dialogInterface, int id) {
if (!nameInput.getText().toString().equals("") && (radioVariablePrice.isChecked() || !priceInput.getText().toString().equals(""))) { if (!nameInput.getText().toString().equals("") && (radioVariablePrice.isChecked() || !priceInput.getText().toString().equals(""))) {
dialog.startLoading(EditActivity.this, getString(R.string.article_edit), getString(R.string.article_editing)); dialog.startLoading(EditActivity.this, getString(R.string.article_edit), getString(R.string.article_editing));
......
...@@ -50,50 +50,7 @@ public class MainActivity extends BaseActivity { ...@@ -50,50 +50,7 @@ public class MainActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
sharedPreferences = getSharedPreferences("payutc", Activity.MODE_PRIVATE); launch();
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