From 1d9a56c17633ca2d8d91da08a3572eb6a0b1b676 Mon Sep 17 00:00:00 2001 From: Stefan Hagemann Date: Wed, 24 Oct 2018 10:49:14 +0200 Subject: [PATCH 1/2] Add avg price to scan If you press "+1" it will add with the avg price of the textview --- app/build.gradle | 16 +- .../ContinuousCaptureActivity.java | 8 +- .../PartkeeprScannrApplication.java | 1 + .../partkeeprscannrapp/SendLogActivity.java | 2 - .../partkeeprscannrapp/SettingsActivity.java | 4 + app/src/main/res/layout/activity_scan.xml | 227 +++++++++++------- build.gradle | 3 +- 7 files changed, 163 insertions(+), 98 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 698fb8d..b5cfe0f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.3" + buildToolsVersion "27.0.3" defaultConfig { applicationId "com.drobisch.partkeeprscannrapp" @@ -20,13 +20,13 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.+' - compile 'com.android.support:design:23.+' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:23.4.0' + implementation 'com.android.support:design:23.4.0' - compile 'com.journeyapps:zxing-android-embedded:3.4.0' - debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' - releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' + implementation 'com.journeyapps:zxing-android-embedded:3.6.0' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.3.1' + releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' } diff --git a/app/src/main/java/com/drobisch/partkeeprscannrapp/ContinuousCaptureActivity.java b/app/src/main/java/com/drobisch/partkeeprscannrapp/ContinuousCaptureActivity.java index 3c4c7bd..69946fe 100644 --- a/app/src/main/java/com/drobisch/partkeeprscannrapp/ContinuousCaptureActivity.java +++ b/app/src/main/java/com/drobisch/partkeeprscannrapp/ContinuousCaptureActivity.java @@ -43,6 +43,7 @@ public class ContinuousCaptureActivity extends Activity { private TextView mPartNameView; private TextView mPartStockView; private TextView mPartLocationView; + private EditText mAVGPriceField; @@ -95,6 +96,7 @@ protected void onCreate(Bundle savedInstanceState) { mPartNameView = (TextView) findViewById(R.id.partName); mPartLocationView = (TextView) findViewById(R.id.partLocation); mPartStockView = (TextView) findViewById(R.id.partStock); + mAVGPriceField = (EditText) findViewById(R.id.avgPrice) ; mPartNameView.setText(""); mPartLocationView.setText(""); @@ -120,6 +122,7 @@ public void onClick(View view) { barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner); barcodeView.setStatusText(""); barcodeView.decodeContinuous(callback); + } private void updatePartInfo(int partID) { @@ -130,7 +133,7 @@ private void updatePartInfo(int partID) { private void addStock() { Log.d("CaptureActivity", "addStock"); if(mPartPartID != -1) { - ApiPartTask task = new ApiPartTask(mUser, mPassword, mServer, mPartPartID,"addStock", "quantity=1&price=0&comment="); + ApiPartTask task = new ApiPartTask(mUser, mPassword, mServer, mPartPartID,"addStock", "quantity=1&price=" + mAVGPriceField.getText().toString() + "&comment="); task.execute((Void) null); } } @@ -270,6 +273,7 @@ public class ApiPartTask extends AsyncTask { private Integer mPartStock = 0; private String mPartLocation = ""; private Integer mPartID; + private double mPartAvgPrice = 0; private Boolean error = false; private String errorString; @@ -337,6 +341,7 @@ protected Boolean doInBackground(Void... params) { JSONObject jsonStorage = json.getJSONObject("storageLocation"); mPartLocation = (String) jsonStorage.get("name"); mPartStock = json.getInt("stockLevel"); + mPartAvgPrice = json.getDouble("averagePrice"); } catch (JSONException e) { e.printStackTrace(); error = true; @@ -351,6 +356,7 @@ protected void onPostExecute(final Boolean success) { mPartLocationView.setText(mPartLocation); mPartStockView.setText(mPartStock.toString()); mPartPartID = mPartID; + mAVGPriceField.setText(String.valueOf(Math.round(mPartAvgPrice *100.0) /100.0)); if(error == true) { mPartPartID = -1; Toast infoToast = Toast.makeText(getApplicationContext(),errorString,Toast.LENGTH_SHORT); diff --git a/app/src/main/java/com/drobisch/partkeeprscannrapp/PartkeeprScannrApplication.java b/app/src/main/java/com/drobisch/partkeeprscannrapp/PartkeeprScannrApplication.java index 448bab2..739f4f6 100644 --- a/app/src/main/java/com/drobisch/partkeeprscannrapp/PartkeeprScannrApplication.java +++ b/app/src/main/java/com/drobisch/partkeeprscannrapp/PartkeeprScannrApplication.java @@ -12,6 +12,7 @@ */ public class PartkeeprScannrApplication extends Application { public void onCreate () { + super.onCreate(); // Setup handler for uncaught exceptions. Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override diff --git a/app/src/main/java/com/drobisch/partkeeprscannrapp/SendLogActivity.java b/app/src/main/java/com/drobisch/partkeeprscannrapp/SendLogActivity.java index 004442e..a155338 100644 --- a/app/src/main/java/com/drobisch/partkeeprscannrapp/SendLogActivity.java +++ b/app/src/main/java/com/drobisch/partkeeprscannrapp/SendLogActivity.java @@ -1,9 +1,7 @@ package com.drobisch.partkeeprscannrapp; import android.app.Activity; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import android.view.View; import android.view.Window; import android.widget.TextView; diff --git a/app/src/main/java/com/drobisch/partkeeprscannrapp/SettingsActivity.java b/app/src/main/java/com/drobisch/partkeeprscannrapp/SettingsActivity.java index 662b3f6..2420cd9 100644 --- a/app/src/main/java/com/drobisch/partkeeprscannrapp/SettingsActivity.java +++ b/app/src/main/java/com/drobisch/partkeeprscannrapp/SettingsActivity.java @@ -3,12 +3,16 @@ import android.content.SharedPreferences; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; + + import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.widget.AutoCompleteTextView; import android.widget.Button; +import static android.content.Context.MODE_PRIVATE; + public class SettingsActivity extends AppCompatActivity { private AutoCompleteTextView mServerView; diff --git a/app/src/main/res/layout/activity_scan.xml b/app/src/main/res/layout/activity_scan.xml index 6107236..ac3151a 100644 --- a/app/src/main/res/layout/activity_scan.xml +++ b/app/src/main/res/layout/activity_scan.xml @@ -1,137 +1,192 @@ + android:layout_width="fill_parent" + android:layout_height="13dp" + android:layout_weight="0.4"> + + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true"> + - + android:layout_width="fill_parent" + android:layout_height="0dp" + android:layout_weight="0.30"> + + + + + - + android:orientation="vertical" + android:shrinkColumns="1" + android:stretchColumns="2"> + + + + android:layout_weight="1" + android:padding="5dip"> + + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="5dp" + android:text="Part:" + android:textColor="#000" /> + + android:id="@+id/partName" + android:layout_width="wrap_content" + android:layout_height="76dp" + android:layout_margin="5dp" + android:text="Part" + android:textColor="#000" /> + android:id="@+id/tableRow2" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:padding="5dip"> + + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="5dp" + android:text="Location:" + android:textColor="#000" /> + + android:id="@+id/partLocation" + android:layout_width="wrap_content" + android:layout_height="58dp" + android:layout_margin="5dp" + android:text="Location" + android:textColor="#000" /> + + + + android:layout_margin="5dp" + android:text="Stock:" + android:textColor="#000" /> + + android:id="@+id/partStock" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="5dp" + android:text="Stock" + android:textColor="#000" /> + + + + > + + android:id="@+id/textView2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Avg Price:" + android:textColor="#000" /> + + + - + + + + + - + android:orientation="vertical" + android:stretchColumns="0"> + + android:id="@+id/tableRowButton1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_weight="1"> + + /> + + android:id="@+id/tableRowButton2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1"> + + android:id="@+id/removeStock_button" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:src="@drawable/ic_exposure_minus_1_24dp" /> - \ No newline at end of file + diff --git a/build.gradle b/build.gradle index 77ce66e..63db7bf 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 0c9e23f78de8c6d85e343ea55906fda58a447fea Mon Sep 17 00:00:00 2001 From: Christopher Teutsch Date: Wed, 24 Oct 2018 12:13:09 +0200 Subject: [PATCH 2/2] Layout adjustments --- app/src/main/res/layout/activity_scan.xml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/layout/activity_scan.xml b/app/src/main/res/layout/activity_scan.xml index ac3151a..0cbabc3 100644 --- a/app/src/main/res/layout/activity_scan.xml +++ b/app/src/main/res/layout/activity_scan.xml @@ -122,24 +122,29 @@ android:id="@+id/tableRow4" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="5dip">> + android:padding="5dip" + > + android:textColor="#000" + android:layout_gravity="center_vertical" + /> + android:textAlignment="center" />