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

Preparation of selling by QRCode

Add new class with better jackson management
Introduce SellByQrCode
parent 1319d374
......@@ -43,6 +43,9 @@
<activity android:name="fr.utc.simde.jessy.SellActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.SellByQRCodeActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.EditActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
......
......@@ -248,6 +248,10 @@ public abstract class BaseActivity extends InternetActivity {
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
}
public void startSellByQRCodeActivity(final Activity activity) {
startActivity(new Intent(activity, SellByQRCodeActivity.class));
}
public void startEditActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
}
......
......@@ -102,6 +102,8 @@ public class MainActivity extends BaseActivity {
setConfig();
checkUpdate(false);
startSellByQRCodeActivity(MainActivity.this);
}
@Override
......
......@@ -17,11 +17,10 @@ import static android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK;
* Created by Samy on 18/11/2017.
*/
public class QRCodeReaderActivity extends BaseActivity {
public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerView.ResultHandler {
private static final String LOG_TAG = "_QRCodeReaderActivity";
protected ZXingScannerView scannerView;
protected ZXingScannerView.ResultHandler cameraHandler;
@Override
public void onCreate(final Bundle savedInstanceState) {
......@@ -35,21 +34,7 @@ public class QRCodeReaderActivity extends BaseActivity {
};
setContentView(this.scannerView);
this.cameraHandler = new ZXingScannerView.ResultHandler() {
@Override
public void handleResult(Result result) {
Log.d(LOG_TAG, result.getText());
Log.d(LOG_TAG, result.getBarcodeFormat().toString());
dialog.infoDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), result.getText(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
scannerView.resumeCameraPreview(cameraHandler);
}
});
}
};
this.scannerView.setResultHandler(this.cameraHandler);
scannerView.setResultHandler(QRCodeReaderActivity.this);
this.scannerView.startCamera(CAMERA_FACING_BACK);
}
......@@ -63,4 +48,20 @@ public class QRCodeReaderActivity extends BaseActivity {
}
});
}
@Override
public void handleResult(Result result) {
Log.d(LOG_TAG, result.getText());
Log.d(LOG_TAG, result.getBarcodeFormat().toString());
dialog.infoDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), result.getText(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
}
protected void resumeReading() {
scannerView.resumeCameraPreview(QRCodeReaderActivity.this);
}
}
......@@ -31,8 +31,15 @@ public class SellActivity extends ArticleGroupActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = findViewById(R.id.text_price);
this.panier = new Panier(textView);
TextView panierText = findViewById(R.id.text_price);
this.panier = new Panier(panierText);
panierText.setOnClickListener(new TextView.OnClickListener() {
@Override
public void onClick(View v) {
startSellByQRCodeActivity(SellActivity.this);
}
});
generate();
}
......
package fr.utc.simde.jessy;
import android.content.DialogInterface;
import android.util.Log;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.zxing.Result;
import fr.utc.simde.jessy.objects.GingerResponse;
import fr.utc.simde.jessy.objects.QRCodeResponse;
public class SellByQRCodeActivity extends QRCodeReaderActivity {
private static final String LOG_TAG = "_SellByQRCodeActivity";
@Override
public void handleResult(Result result) {
Log.d(LOG_TAG, result.getText());
Log.d(LOG_TAG, result.getBarcodeFormat().toString());
try {
final QRCodeResponse qrCodeResponse = new ObjectMapper().readValue(result.getText(), QRCodeResponse.class);
dialog.startLoading(SellByQRCodeActivity.this, getString(R.string.qrcode_reading), getString(R.string.user_ginger_info_collecting));
new Thread() {
@Override
public void run() {
try {
ginger.getInfo(qrCodeResponse.getUsername());
Thread.sleep(100);
}
catch (final Exception e) {
Log.e(LOG_TAG, e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.infoDialog(SellByQRCodeActivity.this, getString(R.string.qrcode_reading), e.getMessage(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
}
});
}
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
dialog.infoDialog(SellByQRCodeActivity.this, getString(R.string.qrcode_reading), (new ObjectMapper().readValue(ginger.getRequest().getResponse(), GingerResponse.class)).toString(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}.start();
}
catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
dialog.infoDialog(SellByQRCodeActivity.this, getString(R.string.qrcode_reading), e.getMessage(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
}
}
}
package fr.utc.simde.jessy.objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class GingerResponse {
protected String login;
protected String nom;
protected String prenom;
protected String mail;
protected String type;
protected boolean is_adulte;
protected boolean is_cotisant;
protected String badge_uid;
public String getUsername() { return login; }
public String getLastname() { return nom; }
public String getFirstname() { return prenom; }
public String getEmail() { return mail; }
public String getType() { return type; }
public boolean getIsAdult() { return is_adulte; }
public boolean getIsContributer() { return is_cotisant; }
public String getBadgeId() { return badge_uid; }
}
package fr.utc.simde.jessy.objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* Created by Samy on 21/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class QRCodeResponse {
private String username;
private String id;
public String getUsername() { return this.username; }
public void setUsername(String username) { this.username = username; }
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }
}
......@@ -10,10 +10,6 @@ import java.util.Map;
import fr.utc.simde.jessy.R;
/**
* Created by Samy on 10/11/2017.
*/
public class Ginger {
private static final String LOG_TAG = "_Ginger";
private static final String url = "https://assos.utc.fr/ginger/v1/";
......
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