Commit bca0190f authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Option management

Add cotization option
Optimization
Prepare option config
parent 9794eeb3
......@@ -101,7 +101,13 @@ public abstract class BaseActivity extends NFCActivity {
}
if ((rights.size() == sameRights.size()) || (myRightList.has("0") && rights.size() == 0))
runOnUiThread(runnable);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
runnable.run();
}
});
else {
runOnUiThread(new Runnable() {
@Override
......@@ -390,8 +396,8 @@ public abstract class BaseActivity extends NFCActivity {
protected void startCardManagementActivity(final Activity activity) {
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"STAFF", "POSS3", "GESUSERS"}, new Runnable() {
@Override
public void run() {dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.buyer_info_collecting));
activity.startActivity(new Intent(activity, CardManagementActivity.class));
public void run() {
activity.startActivity(new Intent(activity, CardManagementActivity.class));
}
});
}
......@@ -412,26 +418,35 @@ public abstract class BaseActivity extends NFCActivity {
try {
nemopaySession.loginApp(key, casConnexion);
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
if (nemopaySession.isRegistered()) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key", key);
editor.apply();
if (nemopaySession.isRegistered()) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key", key);
editor.apply();
((TextView) findViewById(R.id.text_app_registered)).setText(nemopaySession.getName().substring(0, nemopaySession.getName().length() - (nemopaySession.getName().matches("^.* - ([0-9]{4})([/-])([0-9]{2})\\2([0-9]{2})$") ? 13 : 0)));
TextView textView = findViewById(R.id.text_app_registered);
if (textView != null)
textView.setText(nemopaySession.getName().substring(0, nemopaySession.getName().length() - (nemopaySession.getName().matches("^.* - ([0-9]{4})([/-])([0-9]{2})\\2([0-9]{2})$") ? 13 : 0)));
}
else
dialog.errorDialog(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_error_registering));
}
else
});
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_error_registering));
}
});
}
});
}
}
}.start();
}
......
......@@ -3,13 +3,21 @@ package fr.utc.simde.payutc;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by Samy on 29/10/2017.
*/
......@@ -39,9 +47,9 @@ public class CardManagementActivity extends BaseActivity {
TextView textTagGinger;
String username;
String badgeId;
Runnable toRun;
Integer solde;
Integer toRun;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -78,12 +86,7 @@ public class CardManagementActivity extends BaseActivity {
}
});
toRun = new Thread(){
@Override
public void run() {
readCard();
}
};
toRun = 1;
}
});
......@@ -96,13 +99,7 @@ public class CardManagementActivity extends BaseActivity {
}
});
toRun = new Thread(){
@Override
public void run() {
contributeCard();
readCard();
}
};
toRun = 2;
}
});
}
......@@ -111,7 +108,59 @@ public class CardManagementActivity extends BaseActivity {
protected void onIdentification(final String badgeId) {
if (this.toRun != null) {
this.badgeId = badgeId;
this.toRun.run();
if (toRun == 1) {
dialog.startLoading(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.buyer_info_collecting));
new Thread(){
@Override
public void run() {
readCard();
}
}.start();
}
else if (toRun == 2) {
dialog.dismiss();
final View view = getLayoutInflater().inflate(R.layout.dialog_contribute, null);
final RadioGroup radioGroup = view.findViewById(R.id.radio_type);
final RadioButton radioButton = view.findViewById(R.id.radio_student);
final EditText editText = view.findViewById(R.id.nbr_days);
radioButton.setChecked(true);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CardManagementActivity.this);
alertDialogBuilder
.setTitle(R.string.contribute)
.setView(view)
.setCancelable(false)
.setPositiveButton(R.string.contribute, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
dialog.startLoading(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.buyer_info_collecting));
new Thread(){
@Override
public void run() {
int id = radioGroup.indexOfChild(radioGroup.findViewById(radioGroup.getCheckedRadioButtonId()));
if (contributeCard(id == 3 ? new SimpleDateFormat("yyyy-MM-dd").format(new Date(new Date().getTime() + (Long.parseLong(String.valueOf(editText.getText())) * 86400000L))) : (Integer.parseInt(new SimpleDateFormat("MM").format(new Date())) > 8 ? Integer.toString(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) + 1) : new SimpleDateFormat("yyyy").format(new Date())) + "-08-31", id < 2 ? 20 : 1))
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(CardManagementActivity.this, R.string.contribute_now, Toast.LENGTH_LONG).show();
}
});
readCard();
}
}.start();
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, editText);
}
this.toRun = null;
}
}
......@@ -131,6 +180,8 @@ public class CardManagementActivity extends BaseActivity {
this.textTagId.setText(Integer.toString(tagInfo.get("id").intValue()));
this.textTag.setText(tagInfo.get("tag").textValue());
this.textShortTag.setText(tagInfo.get("short_tag").textValue() == null ? getString(R.string.none) : tagInfo.get("short_tag").textValue());
this.textSolde.setText(String.format("%.2f", new Float(this.solde) / 100.00f) + "€");
this.textCotisantGinger.setTextColor(this.solde == 0 ? Color.RED : Color.BLUE);
this.textUsernameGinger.setText(gingerInfo.get("login").textValue());
this.textFirstnameGinger.setText(gingerInfo.get("prenom").textValue());
......@@ -153,7 +204,7 @@ public class CardManagementActivity extends BaseActivity {
}
}
protected void contributeCard() {
protected Boolean contributeCard(final String fin, final Integer paid) {
try {
nemopaySession.getBuyerInfo(badgeId);
Thread.sleep(100);
......@@ -187,7 +238,7 @@ public class CardManagementActivity extends BaseActivity {
});
}
return;
return false;
}
runOnUiThread(new Runnable() {
......@@ -198,7 +249,7 @@ public class CardManagementActivity extends BaseActivity {
});
try {
ginger.addCotisation(username, "20");
ginger.addCotisation(username, fin, paid);
Thread.sleep(100);
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
......@@ -229,8 +280,10 @@ public class CardManagementActivity extends BaseActivity {
});
}
return;
return false;
}
return true;
}
protected void readCard() {
......@@ -245,7 +298,7 @@ public class CardManagementActivity extends BaseActivity {
throw new Exception("Unexpected JSON");
username = nemopaySession.getRequest().getJSONResponse().get("username").textValue();
textSolde.setText(String.format("%.2f", new Float(buyerInfo.get("solde").intValue()) / 100.00f) + "€");
solde = buyerInfo.get("solde").intValue();
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
......
package fr.utc.simde.payutc;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.Arrays;
import java.util.List;
import fr.utc.simde.payutc.adapters.FoundationsAdapter;
import fr.utc.simde.payutc.adapters.ListAdapater;
import fr.utc.simde.payutc.adapters.OptionsAdapter;
/**
* Created by Samy on 26/10/2017.
......@@ -39,6 +31,9 @@ public class FoundationsOptionsActivity extends BaseActivity {
ListView optionList;
FoundationsAdapter foundationsAdapter;
OptionsAdapter optionsAdapter;
List<String> allOptionList;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -53,9 +48,11 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.foundations)).setIndicator(getString(R.string.foundations)).setContent(R.id.list_foundations));
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.options)).setIndicator(getString(R.string.options)).setContent(R.id.list_options));
this.allOptionList = Arrays.asList(getResources().getStringArray(R.array.options));
try {
setFoundationList((ArrayNode) new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList")));
setOptionList();
setOptionList((ArrayNode) new ObjectMapper().valueToTree(this.allOptionList));
} catch (Exception e) {
Log.wtf(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_unexpected), new DialogInterface.OnClickListener() {
......@@ -92,20 +89,26 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.foundationList.setAdapter(this.foundationsAdapter);
}
protected void setOptionList() {
protected void setOptionList(ArrayNode optionList) throws Exception {
this.optionsAdapter = new OptionsAdapter(FoundationsOptionsActivity.this, optionList);
this.optionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (position == 2)
final String text = optionsAdapter.getOptionName(position);
if (text.equals(allOptionList.get(3)))
startCardManagementActivity(FoundationsOptionsActivity.this);
else if (position == 6)
else if (text.equals(allOptionList.get(4)))
keyNemopayDialog();
else if (position == 7)
else if (text.equals(allOptionList.get(5)))
keyGingerDialog();
else
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
}
});
this.optionList.setAdapter(this.optionsAdapter);
}
protected void keyNemopayDialog() {
......
......@@ -102,8 +102,8 @@ public class MainActivity extends BaseActivity {
}
@Override
public void onResume() {
super.onResume();
public void onRestart() {
super.onRestart();
disconnect();
setConfig();
......
package fr.utc.simde.payutc.adapters;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.fasterxml.jackson.databind.node.ArrayNode;
import fr.utc.simde.payutc.R;
/**
* Created by Samy on 28/10/2017.
*/
public class OptionsAdapter extends BaseAdapter {
private static final String LOG_TAG = "_OptionsAdapter";
protected Activity activity;
protected ArrayNode optionList;
public OptionsAdapter(final Activity activity, final ArrayNode optionList) throws Exception {
this.activity = activity;
this.optionList = optionList;
}
@Override
public int getCount() {
return this.optionList.size();
}
@Override
public Object getItem(int position) {
return this.optionList.get(position).textValue();
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
view = layoutInflater.inflate(R.layout.fragment_list, null);
TextView textView = view.findViewById(R.id.text_element);
textView.setText(this.optionList.get(position).textValue());
return view;
}
public String getOptionName(int position) {
return this.optionList.get(position).textValue();
}
}
\ No newline at end of file
......@@ -4,12 +4,10 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import fr.utc.simde.payutc.MainActivity;
import fr.utc.simde.payutc.R;
/**
......@@ -79,6 +77,7 @@ public class Dialog {
public void infoDialog(final Activity activity, final String title, final String message) { errorDialog(activity, title, message, null); }
public void infoDialog(final Activity activity, final String title, final String message, final DialogInterface.OnClickListener onClickListener) {
this.activity = activity;
dismiss();
this.alertDialogBuilder = new AlertDialog.Builder(activity);
this.alertDialogBuilder
.setTitle(title)
......
......@@ -3,7 +3,6 @@ package fr.utc.simde.payutc.tools;
import android.app.Activity;
import android.util.Log;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
......@@ -46,13 +45,13 @@ public class Ginger {
public HTTPRequest getRequest() { return this.request; }
public int addCotisation(final String login, final String paid) throws Exception {
public int addCotisation(final String login, final String fin, final Integer paid) throws Exception {
return request(
login + "/cotisations",
new HashMap<String, String>() {{
put("debut", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
put("fin", (Integer.parseInt(new SimpleDateFormat("MM").format(new Date())) > 8 ? Integer.toString(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) + 1) : new SimpleDateFormat("yyyy").format(new Date())) + "-08-31");
put("montant", paid);
put("fin", fin);
put("montant", Integer.toString(paid));
}}
);
}
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="fr.utc.simde.payutc.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/contribute_choice" />
<RadioGroup
android:id="@+id/radio_type"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="vertical">
<RadioButton
android:id="@+id/radio_student"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="@string/contribute_student" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/contribute_ext" />
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/contribute_admin" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:text="@string/contribute_temp" />
</RadioGroup>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/contribute_temp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<EditText
android:id="@+id/nbr_days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:inputType="numberSigned" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/day_s_" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -3,9 +3,10 @@
<string-array name="options">
<item>Mode annulation</item>
<item>Modifier les articles</item>
<item>Gestion des cartes/cotisations</item>
<item>Lire un QR Code</item>
<item>Gestion des cartes/cotisations</item>
<item>Modifier la clé Nemopay</item>
<item>Modifier la clé Ginger</item>
<item>Configurer l\'appareil</item>
</string-array>
</resources>
\ No newline at end of file
......@@ -55,6 +55,7 @@
<string name="tag">Numéro de badge</string>
<string name="short_tag">Numéro raccourci</string>
<string name="type">Type</string>
<string name="day_s_">jour(s)</string>
<string name="author">&lt;/&gt; avec ♥ par Samy NASTUZZI</string>
<string name="error_unexpected">Une erreur improbable a eu lieu</string>
......@@ -138,6 +139,12 @@
<string name="ginger_information">Informations de la part de Ginger</string>
<string name="ginger_no_key">Aucune clé n\'a été donnée</string>
<string name="contribute_already">La personne est déjà cotisante</string>
<string name="contribute_now">Cotisation réalisée !</string>
<string name="contribute_choice">Type de cotisation</string>
<string name="contribute_student">Etudiant (20€)</string>
<string name="contribute_ext">Extérieur (20€)</string>
<string name="contribute_admin">Membre d\'honneur (0€)</string>
<string name="contribute_temp">Temporaire</string>
<string name="print_mode">Mode d\'affichage</string>
<string name="filters">Filtres d\'affichage</string>
......
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