Commit 3ae098d1 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'release/v0.9.0'

parents 50942ba5 26ef2045
......@@ -4,7 +4,7 @@ android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "fr.utc.simde.payutc"
applicationId "fr.utc.simde.jessy"
minSdkVersion 21
targetSdkVersion 26
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
......
......@@ -10,6 +10,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
......@@ -19,6 +21,7 @@ import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -40,7 +43,7 @@ import fr.utc.simde.jessy.tools.NemopaySession;
* Created by Samy on 26/10/2017.
*/
public abstract class BaseActivity extends NFCActivity {
public abstract class BaseActivity extends InternetActivity {
private static final String LOG_TAG = "_BaseActivity";
private static final String gitUrl = "https://raw.githubusercontent.com/simde-utc/jessy/master/";
......@@ -50,8 +53,8 @@ public abstract class BaseActivity extends NFCActivity {
protected static NemopaySession nemopaySession;
protected static Ginger ginger;
protected static CASConnexion casConnexion;
protected static Config config;
protected static Config config;
protected static Dialog dialog;
protected static SharedPreferences sharedPreferences;
......@@ -60,7 +63,7 @@ public abstract class BaseActivity extends NFCActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dialog = new Dialog(this);
this.dialog = new Dialog(this);
}
@Override
......@@ -160,6 +163,7 @@ public abstract class BaseActivity extends NFCActivity {
Intent intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
activity.startActivity(intent);
}
......@@ -585,10 +589,12 @@ public abstract class BaseActivity extends NFCActivity {
try {
final Matcher matcher = Pattern.compile("android:versionCode=\"([0-9]*)\".*android:versionName=\"(\\S*)\"").matcher(httpRequest.getResponse());
if (matcher.find()) {
if (BuildConfig.VERSION_CODE > Integer.parseInt(matcher.group(1))) {
if (BuildConfig.VERSION_CODE < Integer.parseInt(matcher.group(1))) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BaseActivity.this);
alertDialogBuilder
.setTitle(R.string.update)
......@@ -610,6 +616,13 @@ public abstract class BaseActivity extends NFCActivity {
}
else if (popupIfNot)
throw new Exception(getString(R.string.no_update));
else
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
}
});
}
else
throw new Exception(getString(R.string.can_not_detect_update));
......
package fr.utc.simde.jessy;
import android.Manifest;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
......@@ -31,17 +20,12 @@ import android.widget.Toast;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.utc.simde.jessy.adapters.FoundationsAdapter;
import fr.utc.simde.jessy.adapters.OptionChoicesAdapter;
import fr.utc.simde.jessy.adapters.OptionsAdapter;
import fr.utc.simde.jessy.tools.HTTPRequest;
/**
* Created by Samy on 26/10/2017.
......@@ -160,7 +144,7 @@ public class FoundationsOptionsActivity extends BaseActivity {
hasRights(getString(R.string.nemopay), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_main, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
......@@ -185,7 +169,7 @@ public class FoundationsOptionsActivity extends BaseActivity {
hasRights(getString(R.string.ginger), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_main, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
......
package fr.utc.simde.jessy.tools;
/**
* Created by Samy on 24/10/2017.
*/
package fr.utc.simde.jessy;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import fr.utc.simde.jessy.R;
/**
* Created by Samy on 16/11/2017.
*/
public class InternetBroadcast extends BroadcastReceiver {
public abstract class InternetActivity extends NFCActivity {
private AlertDialog.Builder internetAlertDialog;
@Override
public void onReceive(final Context context, final Intent intent) {
if (!checkInternet(context))
enableInternetDialog(context);
}
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (!checkInternet(context) && internetAlertDialog == null)
enableInternetDialog(context);
}
};
public boolean checkInternet(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
......@@ -33,8 +34,8 @@ public class InternetBroadcast extends BroadcastReceiver {
protected void enableInternetDialog(final Context context) {
Toast.makeText(context, R.string.internet_not_available, Toast.LENGTH_SHORT).show();
AlertDialog.Builder internetAlertDialog = new AlertDialog.Builder(context);
internetAlertDialog
this.internetAlertDialog = new AlertDialog.Builder(context);
this.internetAlertDialog
.setTitle(R.string.connection)
.setMessage(R.string.internet_accessibility)
.setCancelable(true)
......@@ -42,6 +43,7 @@ public class InternetBroadcast extends BroadcastReceiver {
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
internetAlertDialog = null;
if (!checkInternet(context))
enableInternetDialog(context);
}
......@@ -50,4 +52,22 @@ public class InternetBroadcast extends BroadcastReceiver {
AlertDialog alertDialog = internetAlertDialog.create();
alertDialog.show();
}
}
\ No newline at end of file
@Override
public void onResume() {
super.onResume();
registerReceiver(broadcastReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
if (!checkInternet(InternetActivity.this) && internetAlertDialog == null)
enableInternetDialog(InternetActivity.this);
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(broadcastReceiver);
}
@Override
protected void onIdentification(String badgeId) {}
}
......@@ -5,6 +5,7 @@ import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
......@@ -26,7 +27,6 @@ import java.util.Locale;
import fr.utc.simde.jessy.tools.CASConnexion;
import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Ginger;
import fr.utc.simde.jessy.tools.InternetBroadcast;
import fr.utc.simde.jessy.tools.NemopaySession;
/**
......@@ -42,8 +42,6 @@ public class MainActivity extends BaseActivity {
private static TextView appRegisteredText;
private static Button usernameButton;
protected static InternetBroadcast internetBroadcast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -56,9 +54,6 @@ public class MainActivity extends BaseActivity {
casConnexion = new CASConnexion(nemopaySession);
config = new Config(sharedPreferences);
this.internetBroadcast = new InternetBroadcast();
registerReceiver(this.internetBroadcast, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
String key = sharedPreferences.getString("key", "");
if (!key.equals(""))
setNemopayKey(key);
......@@ -75,11 +70,7 @@ public class MainActivity extends BaseActivity {
appRegisteredText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!nemopaySession.isRegistered())
addKeyDialog();
else
unregister(MainActivity.this);
optionDialog();
return false;
}
});
......@@ -113,7 +104,6 @@ public class MainActivity extends BaseActivity {
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(this.internetBroadcast);
disconnect();
}
......@@ -474,17 +464,35 @@ public class MainActivity extends BaseActivity {
dialog.createDialog(alertDialogBuilder, nameInput);
}
protected void addKeyDialog() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
protected void optionDialog() {
final View view = getLayoutInflater().inflate(R.layout.dialog_main, null);
final EditText keyInput = view.findViewById(R.id.input_key);
final Button reloadButton = view.findViewById(R.id.button_reload);
final Button configButton = view.findViewById(R.id.button_config);
reloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startMainActivity(MainActivity.this);
}
});
configButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
config.reset();
startMainActivity(MainActivity.this);
}
});
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setTitle(R.string.key_registration)
.setView(keyView)
.setView(view)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
unregister(MainActivity.this);
setNemopayKey(keyInput.getText().toString());
}
})
......
......@@ -136,4 +136,18 @@ public class Config {
this.print18 = print18;
}
public void reset() {
setFoundation(-1, "");
setLocation(-1, "");
setOptionList(new ObjectMapper().createArrayNode());
setCanSell(true);
setCanCancel(true);
setInCategory(true);
setInGrid(true);
setPrintCotisant(false);
setPrint18(false);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_key_explication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/key_add_explication"
android:layout_marginBottom="10dp" />
<EditText
android:id="@+id/input_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:inputType="text|textEmailAddress"
android:hint="@string/key" />
<Button
android:id="@+id/button_reload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/reload" />
<Button
android:id="@+id/button_config"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/configurate_by_default" />
</LinearLayout>
\ No newline at end of file
Supports Markdown
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