Commit 1319d374 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Add edit articles management

Reorganisation of multiple files
parent 2605ea09
...@@ -40,7 +40,10 @@ ...@@ -40,7 +40,10 @@
<activity android:name="fr.utc.simde.jessy.CardManagementActivity" <activity android:name="fr.utc.simde.jessy.CardManagementActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.ArticleGroupActivity" <activity android:name="fr.utc.simde.jessy.SellActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.EditActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.QRCodeReaderActivity" <activity android:name="fr.utc.simde.jessy.QRCodeReaderActivity"
......
...@@ -2,7 +2,6 @@ package fr.utc.simde.jessy; ...@@ -2,7 +2,6 @@ package fr.utc.simde.jessy;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -14,8 +13,6 @@ import android.widget.ListView; ...@@ -14,8 +13,6 @@ import android.widget.ListView;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -27,24 +24,21 @@ import java.util.HashMap; ...@@ -27,24 +24,21 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import fr.utc.simde.jessy.adapters.LocationsAdapter; import fr.utc.simde.jessy.adapters.LocationsAdapter;
import fr.utc.simde.jessy.fragments.GroupFragment; import fr.utc.simde.jessy.fragments.ArticleGroupFragment;
import fr.utc.simde.jessy.tools.HTTPRequest; import fr.utc.simde.jessy.tools.HTTPRequest;
import fr.utc.simde.jessy.tools.Panier;
/** /**
* Created by Samy on 27/10/2017. * Created by Samy on 27/10/2017.
*/ */
public class ArticleGroupActivity extends BaseActivity { public abstract class ArticleGroupActivity extends BaseActivity {
private static final String LOG_TAG = "_ArticleGroupActivity"; private static final String LOG_TAG = "_ArticleGroupActivity";
protected ImageButton paramButton; protected ImageButton paramButton;
protected ImageButton deleteButton; protected ImageButton optionButton;
protected TabHost tabHost; protected TabHost tabHost;
protected Panier panier; protected List<ArticleGroupFragment> groupFragmentList;
protected List<GroupFragment> groupFragmentList;
protected int nbrGroups; protected int nbrGroups;
@Override @Override
...@@ -52,15 +46,16 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -52,15 +46,16 @@ public class ArticleGroupActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_group); setContentView(R.layout.activity_article_group);
TextView textView = findViewById(R.id.text_price);
this.panier = new Panier(textView);
this.paramButton = findViewById(R.id.image_param); this.paramButton = findViewById(R.id.image_param);
this.deleteButton = findViewById(R.id.image_delete); this.optionButton = findViewById(R.id.image_delete);
this.tabHost = findViewById(R.id.tab_categories); this.tabHost = findViewById(R.id.tab_categories);
this.tabHost.setup(); this.tabHost.setup();
this.groupFragmentList = new ArrayList<GroupFragment>(); this.groupFragmentList = new ArrayList<ArticleGroupFragment>();
this.nbrGroups = 0; this.nbrGroups = 0;
}
protected void generate() {
try { try {
if (getIntent().getExtras().getString("categoryList") != null) if (getIntent().getExtras().getString("categoryList") != null)
...@@ -145,7 +140,7 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -145,7 +140,7 @@ public class ArticleGroupActivity extends BaseActivity {
config.setPrintCotisant(switchCotisant.isChecked()); config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked()); config.setPrint18(swtich18.isChecked());
startArticleGroupActivity(ArticleGroupActivity.this); startSellActivity(ArticleGroupActivity.this);
} }
}) })
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null);
...@@ -165,8 +160,8 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -165,8 +160,8 @@ public class ArticleGroupActivity extends BaseActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
hasRights(getString(R.string.configurate_by_default), new String[]{ hasRights(getString(R.string.configurate_by_default), new String[]{
"STAFF", "STAFF",
"GESAPPLICATIONS" "GESAPPLICATIONS"
}, new Runnable() { }, new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -190,7 +185,7 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -190,7 +185,7 @@ public class ArticleGroupActivity extends BaseActivity {
config.setPrintCotisant(switchCotisant.isChecked()); config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked()); config.setPrint18(swtich18.isChecked());
startArticleGroupActivity(ArticleGroupActivity.this); startSellActivity(ArticleGroupActivity.this);
} }
}) })
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null);
...@@ -200,24 +195,10 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -200,24 +195,10 @@ public class ArticleGroupActivity extends BaseActivity {
} }
}); });
this.deleteButton.setOnClickListener(new View.OnClickListener() { setOptionButton();
@Override
public void onClick(View view) {
clearPanier();
}
});
} }
@Override protected abstract void setOptionButton();
protected void onIdentification(final String badgeId) {
if (dialog.isShowing())
return;
if (this.panier.isEmpty())
startBuyerInfoActivity(ArticleGroupActivity.this, badgeId);
else
pay(badgeId);
}
protected void configDialog() { protected void configDialog() {
dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getString(config.getInCategory() ? R.string.category_list_collecting : R.string.keyboard_list_collecting)); dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getString(config.getInCategory() ? R.string.category_list_collecting : R.string.keyboard_list_collecting));
...@@ -319,94 +300,6 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -319,94 +300,6 @@ public class ArticleGroupActivity extends BaseActivity {
}.start(); }.start();
} }
public void clearPanier() {
for (GroupFragment groupFragment : groupFragmentList)
groupFragment.clear();
panier.clear();
}
public void setBackgroundColor(int color) {
this.tabHost.setBackgroundColor(color);
new Thread(){
@Override
public void run() {
try {
Thread.sleep(2500);
runOnUiThread(new Runnable() {
@Override
public void run() {
tabHost.setBackgroundColor(getResources().getColor(R.color.white));
}
});
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
}.start();
}
protected void pay(final String badgeId) {
dialog.startLoading(this, getResources().getString(R.string.paiement), getResources().getString(R.string.transaction_in_progress));
final List<Integer> articleList = new ArrayList<Integer>(panier.getArticleList());
clearPanier();
new Thread() {
@Override
public void run() {
try {
nemopaySession.setTransaction(badgeId, articleList);
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(ArticleGroupActivity.this, "Paiement effectué", Toast.LENGTH_LONG).show();
setBackgroundColor(getResources().getColor(R.color.success));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(250);
}
});
} 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(ArticleGroupActivity.this, getString(R.string.paiement), response.get("error").get("message").textValue());
setBackgroundColor(getResources().getColor(R.color.error));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(500);
}
});
}
else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(ArticleGroupActivity.this, getString(R.string.paiement), e.getMessage());
setBackgroundColor(getResources().getColor(R.color.error));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(500);
}
});
}
}
}
}.start();
}
protected void createCategories(final JsonNode categoryList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception { protected void createCategories(final JsonNode categoryList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>(); HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
final int foundationId = nemopaySession.getFoundationId(); final int foundationId = nemopaySession.getFoundationId();
...@@ -488,17 +381,6 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -488,17 +381,6 @@ public class ArticleGroupActivity extends BaseActivity {
} }
} }
protected void createNewGroup(final String name, final ArrayNode articleList) throws Exception { createNewGroup(name, articleList, 3); } protected abstract void createNewGroup(final String name, final ArrayNode articleList) throws Exception;
protected void createNewGroup(final String name, final ArrayNode articleList, int gridColumns) throws Exception { protected abstract void createNewGroup(final String name, final ArrayNode articleList, int gridColumns) throws Exception;
GroupFragment articleGroupFragment = new GroupFragment(ArticleGroupActivity.this, articleList, this.panier, this.config, gridColumns);
TabHost.TabSpec newTabSpec = this.tabHost.newTabSpec(name);
newTabSpec.setIndicator(name);
newTabSpec.setContent(articleGroupFragment);
this.groupFragmentList.add(articleGroupFragment);
this.tabHost.addTab(newTabSpec);
nbrGroups++;
}
} }
...@@ -12,8 +12,6 @@ import android.content.Intent; ...@@ -12,8 +12,6 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -22,9 +20,7 @@ import android.os.StrictMode; ...@@ -22,9 +20,7 @@ import android.os.StrictMode;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.widget.BaseAdapter;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
...@@ -196,7 +192,7 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -196,7 +192,7 @@ public abstract class BaseActivity extends InternetActivity {
protected void startFoundationListActivity(final Activity activity) { protected void startFoundationListActivity(final Activity activity) {
if (config.getFoundationId() != -1) { if (config.getFoundationId() != -1) {
startArticleGroupActivity(activity); startSellActivity(activity);
return; return;
} }
...@@ -248,9 +244,16 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -248,9 +244,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start(); }.start();
} }
protected void startArticleGroupActivity(final Activity activity) { public void startSellActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
}
public void startEditActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
}
public void startArticleGroupActivity(final Activity activity, final Intent intent) {
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));
final Intent intent = new Intent(activity, ArticleGroupActivity.class);
new Thread() { new Thread() {
@Override @Override
......
package fr.utc.simde.jessy;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
import java.util.List;
import fr.utc.simde.jessy.fragments.ArticleGroupFragment;
import fr.utc.simde.jessy.fragments.EditFragment;
import fr.utc.simde.jessy.fragments.SellFragment;
import fr.utc.simde.jessy.tools.Panier;
/**
* Created by Samy on 20/11/2017.
*/
public class EditActivity extends ArticleGroupActivity {
private static final String LOG_TAG = "_EditActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
generate();
}
@Override
protected void setOptionButton() {
this.optionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
@Override
protected void createNewGroup(final String name, final ArrayNode articleList) throws Exception { createNewGroup(name, articleList, 3); }
protected void createNewGroup(final String name, final ArrayNode articleList, int gridColumns) throws Exception {
ArticleGroupFragment articleGroupFragment = new EditFragment(EditActivity.this, articleList, this.dialog, this.config, gridColumns);
TabHost.TabSpec newTabSpec = this.tabHost.newTabSpec(name);
newTabSpec.setIndicator(name);
newTabSpec.setContent(articleGroupFragment);
this.groupFragmentList.add(articleGroupFragment);
this.tabHost.addTab(newTabSpec);
nbrGroups++;
}
}
...@@ -18,6 +18,7 @@ import android.widget.TabHost; ...@@ -18,6 +18,7 @@ import android.widget.TabHost;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
...@@ -25,6 +26,7 @@ import java.util.Arrays; ...@@ -25,6 +26,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import fr.utc.simde.jessy.adapters.FoundationsAdapter; import fr.utc.simde.jessy.adapters.FoundationsAdapter;
import fr.utc.simde.jessy.adapters.LocationsAdapter;
import fr.utc.simde.jessy.adapters.OptionChoicesAdapter; import fr.utc.simde.jessy.adapters.OptionChoicesAdapter;
import fr.utc.simde.jessy.adapters.OptionsAdapter; import fr.utc.simde.jessy.adapters.OptionsAdapter;
...@@ -87,7 +89,7 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -87,7 +89,7 @@ public class FoundationsOptionsActivity extends BaseActivity {
@Override @Override
public void onItemClick(AdapterView parent, View view, int position, long id) { public void onItemClick(AdapterView parent, View view, int position, long id) {
nemopaySession.setFoundation(foundationsAdapter.getFoundationId(position), foundationsAdapter.getFoundationName(position), -1); nemopaySession.setFoundation(foundationsAdapter.getFoundationId(position), foundationsAdapter.getFoundationName(position), -1);
startArticleGroupActivity(FoundationsOptionsActivity.this); startSellActivity(FoundationsOptionsActivity.this);
} }
}); });
...@@ -120,7 +122,7 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -120,7 +122,7 @@ public class FoundationsOptionsActivity extends BaseActivity {
startActivity(new Intent(FoundationsOptionsActivity.this, BuyerInfoActivity.class)); startActivity(new Intent(FoundationsOptionsActivity.this, BuyerInfoActivity.class));
} }
else if (isOption(position,1)) else if (isOption(position,1))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.11"); editDialog();
else if (isOption(position,2)) else if (isOption(position,2))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.12"); dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.12");
else if (isOption(position,3)) else if (isOption(position,3))
...@@ -337,7 +339,7 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -337,7 +339,7 @@ public class FoundationsOptionsActivity extends BaseActivity {
config.setPrintCotisant(switchCotisant.isChecked()); config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked()); config.setPrint18(swtich18.isChecked());
startArticleGroupActivity(FoundationsOptionsActivity.this); startSellActivity(FoundationsOptionsActivity.this);
} }
}) })
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null);
...@@ -345,4 +347,121 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -345,4 +347,121 @@ public class FoundationsOptionsActivity extends BaseActivity {
dialog.createDialog(alertDialogBuilder); dialog.createDialog(alertDialogBuilder);
} }
} }
protected void editDialog() {
dialog.startLoading(FoundationsOptionsActivity.this, getString(R.string.information_collection), getString(R.string.user_rights_list_collecting));
new Thread() {
@Override
public void run() {
try {
nemopaySession.getAllMyRights();
Thread.sleep(100);
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(FoundationsOptionsActivity.this, getString(R.string.foundation_list_collecting), e.getMessage());
}
});
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getString(R.string.foundation_list_collecting));
}
});
try {
final JsonNode rightList = nemopaySession.getRequest().getJSONResponse();
nemopaySession.getFoundations();
Thread.sleep(100);
final JsonNode foundationList = nemopaySession.getRequest().getJSONResponse();
ArrayNode foundationListWithRights = new ObjectMapper().createArrayNode();
if (rightList.has("0")) {
for (JsonNode element : rightList.get("0")) {
if (element.textValue().equals("GESARTICLE")) {
foundationListWithRights = (ArrayNode) foundationList;
break;
}
}
}
if (foundationListWithRights.size() == 0) {
for (final JsonNode foundation : foundationList) {
if (!foundation.has("name") || !foundation.has("fun_id"))
throw new Exception("Unexpected JSON");
if (rightList.has(Integer.toString(foundation.get("fun_id").intValue()))) {
for (JsonNode element : rightList.get(Integer.toString(foundation.get("fun_id").intValue()))) {
if (element.textValue().equals("GESARTICLE")) {
foundationListWithRights.add(foundation);
break;
}
}
}
}
}
final ArrayNode finalFoundationListWithRights = foundationListWithRights;
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
if (finalFoundationListWithRights.size() == 0)
dialog.infoDialog(FoundationsOptionsActivity.this, getString(R.string.user_rights_list_collecting), nemopaySession.forbidden(new String[]{"GESARTICLE"}, false));
else {
final LayoutInflater layoutInflater = LayoutInflater.from(FoundationsOptionsActivity.this);
final View popupView = layoutInflater.inflate(R.layout.dialog_list, null);