Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • infrastruktur/warppay-app
  • HoelShare/warppay-app
2 results
Show changes
package ms.warpzone.warppay.manager;
import android.content.Context;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import ms.warpzone.warppay.R;
import ms.warpzone.warppay.data.RestService;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
public class RestManager {
private static RestManager ourInstance = new RestManager();
RestService restService;
private RestManager() {}
public static RestManager getInstance() {
return ourInstance;
}
public void initRestService() {
this.restService = this.createRestService();
}
public RestService getRestService() {
return restService;
}
private RestService createRestService() {
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://infra-test.warpzone/api/")
.addConverterFactory(GsonConverterFactory.create());
OkHttpClient okHttp = new OkHttpClient();
try {
okHttp.setSslSocketFactory(getSSLConfig(MainManager.getInstance().getMainActivity().getBaseContext()).getSocketFactory());
okHttp.networkInterceptors().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder()
.addHeader("Authorization", "Token cdcca01b29316e993477b32f1a86274804318fa0")
.build();
return chain.proceed(newRequest);
}
});
} catch (CertificateException | NoSuchAlgorithmException | KeyManagementException | IOException | KeyStoreException e) {
e.printStackTrace();
}
Retrofit retrofit = builder.client(okHttp).build();
return retrofit.create(RestService.class);
}
private static SSLContext getSSLConfig(Context context) throws CertificateException, IOException,
KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
String password = "e44r4dv9z1d0vwr9erotafxe66114v31jwhjlvttc8qkoa3nrskcj4ml0pwrh8aw";
KeyStore keyStore = KeyStore.getInstance("BKS");
keyStore.load(context.getResources().openRawResource(R.raw.keystore_old), password.toCharArray());
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
return sslContext;
}
}
package ms.warpzone.warppay.manager;
import android.util.Log;
import java.util.ArrayList;
import ms.warpzone.warppay.data.models.local.User;
import ms.warpzone.warppay.data.models.rest.RestTransaction;
import ms.warpzone.warppay.data.models.rest.RestUser;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;
public class TransactionManager {
private static TransactionManager ourInstance = new TransactionManager();
private TransactionManager() {}
public static TransactionManager getInstance() {
return ourInstance;
}
/***
* Perform a Transaction and update the User.
* @param transactions
* @return
*/
public void perform_transactions(ArrayList<RestTransaction> transactions, final boolean show_credit_dialog, final boolean logout) {
User currentUser = DataManager.getInstance().getCurrentUser();
RestManager.getInstance().getRestService().saveTransaction(currentUser.getUserid(), transactions).enqueue(new Callback<Void>() {
@Override
public void onResponse(Response<Void> response, Retrofit retrofit) {
if(response.code() != 200) {
Log.d("REST_1", String.valueOf(response.code()));
UiManager.getInstance().showWarning("Transaction Error. Please try Again", 4000);
}
}
@Override
public void onFailure(Throwable t) {
Log.d("REST", t.getMessage());
UiManager.getInstance().showWarning("Transaction Error. Please try Again", 4000);
}
});
if(currentUser.getUserid() == "Guest") {
if (logout)
MainManager.getInstance().clearCurrentUser();
return;
}
RestManager.getInstance().getRestService().getSingleUser(currentUser.getUserid()).enqueue(new Callback<RestUser>() {
@Override
public void onResponse(Response<RestUser> response, Retrofit retrofit) {
if(response.code() == 200) {
DataManager.getInstance().getCurrentUser().setCredit(response.body().getCredit());
UiManager.getInstance().refreshCreditTextView(DataManager.getInstance().getCurrentUser().getCredit());
DataManager.getInstance().getCurrentUser().save();
if (show_credit_dialog) {
UiManager.getInstance().showMessage("Neues Guthaben: " + DataManager.getInstance().getCurrentUser().getCredit() + " Euro", 2500);
}
if (logout)
MainManager.getInstance().clearCurrentUser();
} else {
Log.d("REST_2", String.valueOf(response.code()));
UiManager.getInstance().showWarning("Transaction Error. Please try again", 4000);
}
}
@Override
public void onFailure(Throwable t) {
UiManager.getInstance().showWarning("Transaction Error. Please try again", 4000);
Log.d("REST", t.getMessage());
}
});
}
}
package ms.warpzone.warppay.manager;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Build;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
......@@ -17,6 +18,7 @@ import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
......@@ -51,7 +53,7 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
private ArrayAdapter atxvAdapter;
private ArrayList<Double> order;
private List<User> users;
private ProgressDialog processDialog = null;
private PayChoiceDialog payChoiceDialog;
private ProductDialog productDialog;
......@@ -71,8 +73,8 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
protected void initUi(MainActivity mainActivity) {
this.txtSum = (TextView) mainActivity.findViewById(R.id.txtSum);
this.txtCredit = (TextView)mainActivity.findViewById(R.id.txtCredit);
this.txtCredit.setText(mainActivity.getResources().getString(R.string.credit,0.0));
this.txtSum.setText(mainActivity.getResources().getString(R.string.total,0.0));
this.txtCredit.setText(mainActivity.getResources().getString(R.string.credit,"0.0"));
this.txtSum.setText(mainActivity.getResources().getString(R.string.total,"0.0"));
this.btnLogout = (Button) mainActivity.findViewById(R.id.btnLogout);
this.btnRefresh = (ImageButton) mainActivity.findViewById(R.id.btnRefresh);
......@@ -81,10 +83,6 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
this.btnGuest = (Button) mainActivity.findViewById(R.id.btnGuest);
this.btnSettings = (Button) mainActivity.findViewById(R.id.btnSettings);
/* this.txtBarcode = (EditText) mainActivity.findViewById(R.id.txtBarcode);
this.txtBarcode.setShowSoftInputOnFocus(false);
this.txtBarcode.setOnKeyListener(this);
*/
this.lstOrderedAdapter = new ListViewAdapter(mainActivity, R.layout.order_list_item, new ArrayList<Order>());
this.lstProductAdapter = new ListViewAdapterProducts(mainActivity, R.layout.product_list_item, Product.getAll());
......@@ -116,11 +114,11 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
}
protected void refreshTotalTextView(double totalAmount) {
this.txtSum.setText(this.mainActivity.getResources().getString(R.string.total,totalAmount));
protected void refreshTotalTextView(BigDecimal totalAmount) {
this.txtSum.setText(this.mainActivity.getResources().getString(R.string.total,totalAmount.toString()));
}
protected void refreshCreditTextView(double credit) {
this.txtCredit.setText(this.mainActivity.getResources().getString(R.string.credit, credit));
protected void refreshCreditTextView(BigDecimal credit) {
this.txtCredit.setText(this.mainActivity.getResources().getString(R.string.credit, credit.toString()));
}
protected void setCurrentUser(User user) {
......@@ -137,8 +135,8 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
this.lstOrderedAdapter.clear();
this.enableControls(false);
this.btnLogout.setVisibility(View.INVISIBLE);
this.refreshCreditTextView(0.0);
this.refreshTotalTextView(0.0);
this.refreshCreditTextView(new BigDecimal(0.0));
this.refreshTotalTextView(new BigDecimal(0.0));
if(this.atxvName.requestFocus()) {
this.showSoftKeyboard(this.mainActivity.getCurrentFocus());
}
......@@ -227,12 +225,12 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
break;
case R.id.btnRefresh:
MainManager.getInstance().refreshData();
RefreshManager.getInstance().refreshData();
break;
case R.id.btnGuest:
if(MainManager.getInstance().getCurrentUser() == null) {
DataManager.getInstance().setIs_guest(true);
MainManager.getInstance().setCurrentUser(new User("Guest", "", 0, ""));
MainManager.getInstance().setCurrentUser(new User("Guest", "", new BigDecimal(0), ""));
this.atxvName.setText("Gast");
this.atxvName.dismissDropDown();
}
......@@ -303,5 +301,20 @@ public class UiManager implements View.OnKeyListener, View.OnClickListener, Adap
this.chargeCustomDialog = chargeCustomDialog;
}
public void showWarning(String message, int time) {
this.showMessageBox(message, true, time);
}
public void showMessage(String message, int time) {
this.showMessageBox(message, false, time);
}
private void showMessageBox(String message, boolean warning, int time) {
NotificationDialog ndTransfer = new NotificationDialog(MainManager.getInstance().getMainActivity());
if(warning)
ndTransfer.setWarning();
ndTransfer.setMessage(message);
ndTransfer.show(time);
}
}
......@@ -5,24 +5,30 @@
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_width="384dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25">
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:id="@+id/txtOrderName"
android:layout_width="213dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal"
android:text="Large Text"
android:id="@+id/txtOrderName" />
android:maxLines="1"
android:textSize="22sp" />
<Space
android:layout_width="15dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtOrderValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txtOrderValue" />
android:text="1.00 Euro"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="22sp" />
</LinearLayout>
......
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="386dp"
android:id="@+id/txtProductName"
android:layout_width="247dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal"
android:text="Large Text"
android:id="@+id/txtProductName"
android:layout_gravity="center_horizontal" />
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textSize="30sp" />
<TextView
android:layout_width="229dp"
android:id="@+id/txtProductPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="1.0"
android:id="@+id/txtProductPrice" />
android:text="1.00 Euro"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30sp" />
</LinearLayout>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_width="234dp"
android:layout_height="63dp"
android:onClick="removeOrderOnClickHandler"
/>
......
File added
File deleted
......@@ -23,8 +23,8 @@
<string name="confirm_payment_title">Bezahlung bestaetigen</string>
<string name="confirm_learn_card">Karte anlernen</string>
<string name="confirm_payment">Willst du wirklich %1$,.2f Euro bezahlen?</string>
<string name="credit">Guthaben: %1$,.2f Euro</string>
<string name="total">Gesamt: %1$,.2f Euro</string>
<string name="credit">Guthaben: %1s Euro</string>
<string name="total">Gesamt: %1s Euro</string>
<string name="addNewUser">Benutzer hinzufügen</string>
<string name="rest_service">RESTAPI-URL</string>
<string name="rest_config_header">REST-API Konfiguration</string>
......
......@@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......