Skip to content

Commit

Permalink
I146 app demo 3 (#155)
Browse files Browse the repository at this point in the history
* Removed legacy MainActivity

* Implemented image loading on warehouse items.

* Added cloud zeroconf bypass

* Added item images

* Added OrdersActivity

* Added qr code library to app

* Added bob logo to app

* Added ViewOrderDialog

* Added qr code generation

* Added quality of life improvements to shopping cart.
  • Loading branch information
oktay-sen committed Mar 12, 2019
1 parent 331fea9 commit 509c42a
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 32 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ dependencies {
implementation 'org.jetbrains.anko:anko-common:0.9'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.zxing:core:3.3.3'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.assis10t.bobandroid

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.CardView
import android.support.v7.widget.LinearLayoutManager
Expand Down Expand Up @@ -79,14 +80,20 @@ class OrdersActivity : ActivityWithLoginMenu() {
vh.title.text = order.warehouse!!.name
vh.timestamp.text = order.getTimeString()
vh.container.setOnClickListener {v ->
Toast.makeText(vh.container.context, "TODO: Open order details dialog", Toast.LENGTH_SHORT).show()
ViewOrderDialog(v.context, order).show()
}
vh.status.text = when(order.status) {
Order.Status.PENDING -> "Pending"
Order.Status.IN_TRANSIT -> "In transit"
Order.Status.COMPLETE -> "Ready to collect"
Order.Status.COMPLETE -> "Ready"
Order.Status.CANCELED -> "Canceled"
}
vh.status.setTextColor(when(order.status) {
Order.Status.PENDING -> R.color.statusPending
Order.Status.IN_TRANSIT -> R.color.statusInTransit
Order.Status.COMPLETE -> R.color.statusReady
Order.Status.CANCELED -> R.color.statusCanceled
})
vh.summary.text = "${order.items.size} items"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ import timber.log.Timber
class ViewCartDialog(context: Context, val warehouseId: String): Dialog(context) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dialog_view_cart)

val data = getCart(context)
if (data.isEmpty()) {
setContentView(R.layout.dialog_view_cart_empty)
return
} else {
setContentView(R.layout.dialog_view_cart)
}

cart.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
cart.adapter = CartAdapter(data)
Expand All @@ -38,6 +43,11 @@ class ViewCartDialog(context: Context, val warehouseId: String): Dialog(context)

total.text = "£${"%.2f".format(totalAmount)}"

clear.setOnClickListener {
clearCart(context)
dismiss()
}

complete_order.setOnClickListener {
val order = Order.Factory()
.items(data)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.github.assis10t.bobandroid

import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import io.github.assis10t.bobandroid.pojo.Item
import io.github.assis10t.bobandroid.pojo.Order
import kotlinx.android.synthetic.main.dialog_view_order.*
import org.w3c.dom.Text
import timber.log.Timber

class ViewOrderDialog(context: Context, val order: Order): Dialog(context) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dialog_view_order)

cart.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
cart.adapter = ViewCartDialog.CartAdapter(order.items)

warehouse_title.text = order.warehouse!!.name
status.text = when(order.status) {
Order.Status.PENDING -> "Pending"
Order.Status.IN_TRANSIT -> "In transit"
Order.Status.COMPLETE -> "Ready"
Order.Status.CANCELED -> "Canceled"
}
status.setTextColor(when(order.status) {
Order.Status.PENDING -> R.color.statusPending
Order.Status.IN_TRANSIT -> R.color.statusInTransit
Order.Status.COMPLETE -> R.color.statusReady
Order.Status.CANCELED -> R.color.statusCanceled
})

view_qr.visibility =
if (order.status == Order.Status.COMPLETE)
View.VISIBLE
else
View.VISIBLE //TODO: Change to View.GONE

val totalAmount =
if (order.items.isEmpty())
0.0
else
order.items
.map{ it.quantity!! * it.price }
.reduce { a, b -> a + b}

total.text = "£${"%.2f".format(totalAmount)}"


view_qr.setOnClickListener {
ViewQRDialog(context, order).show()
}

get_directions.setOnClickListener {
val location = order.warehouse!!.location!!
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/dir/?api=1&destination=${location.latitude},${location.longitude}")
)
context.startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.assis10t.bobandroid

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import com.bumptech.glide.Glide
import io.github.assis10t.bobandroid.pojo.Order
import kotlinx.android.synthetic.main.dialog_view_qr.*

class ViewQRDialog(context: Context, val order: Order): Dialog(context) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dialog_view_qr)

instructions.text = "Show this code to the cashier at ${order.warehouse!!.name}."

Glide.with(context)
.load(generateQRCode(order._id!!))
.into(qr)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Warehouse (
) {
companion object {
class Location(
latitude: Double = 0.0,
longitude: Double = 0.0
val latitude: Double = 0.0,
val longitude: Double = 0.0
)

fun fromString(str: String) = Gson().fromJson(str, Warehouse::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package io.github.assis10t.bobandroid

import android.content.Context
import android.content.SharedPreferences
import android.graphics.Bitmap
import android.util.TypedValue
import android.provider.SyncStateContract.Helpers.update
import android.util.Base64
import com.google.zxing.BarcodeFormat
import com.google.zxing.MultiFormatWriter
import com.journeyapps.barcodescanner.BarcodeEncoder
import io.github.assis10t.bobandroid.pojo.Item
import timber.log.Timber
import java.security.NoSuchAlgorithmException
Expand Down Expand Up @@ -77,4 +81,9 @@ fun base64ToByteArray(str: String): ByteArray? {
val pureStr = str.substring(str.indexOf(",")+1)
val bytes = Base64.decode(pureStr, Base64.DEFAULT)
return bytes
}

fun generateQRCode(str: String): Bitmap {
val bitMatrix = MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, 300, 300)
return BarcodeEncoder().createBitmap(bitMatrix)
}
9 changes: 9 additions & 0 deletions android/app/src/main/res/drawable/ic_delete_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http:https://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
15 changes: 14 additions & 1 deletion android/app/src/main/res/layout/dialog_view_cart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="300dp"
android:layout_width="350dp"
android:layout_height="wrap_content"
app:cardElevation="8dp">
<RelativeLayout
Expand All @@ -17,6 +17,19 @@
android:text="Shopping Cart"
android:layout_margin="8dp"
/>
<ImageButton
android:id="@+id/clear"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:layout_alignParentEnd="true"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_delete_black_24dp"
android:contentDescription="Clear"/>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
Expand Down
29 changes: 29 additions & 0 deletions android/app/src/main/res/layout/dialog_view_cart_empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.card.MaterialCardView
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="350dp"
android:layout_height="wrap_content"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/TextAppearance.MaterialComponents.Headline6"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shopping Cart"
android:layout_margin="8dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your cart is empty."
android:layout_margin="16dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/title"
/>
</RelativeLayout>
</android.support.design.card.MaterialCardView>
69 changes: 45 additions & 24 deletions android/app/src/main/res/layout/dialog_view_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,47 @@
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="300dp"
android:layout_width="350dp"
android:layout_height="wrap_content"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/TextAppearance.MaterialComponents.Headline6"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order Summary"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
/>
<RelativeLayout
android:id="@+id/warehouse_container"
android:layout_width="match_parent"
<TextView
style="@style/TextAppearance.MaterialComponents.Overline"
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_below="@id/title">
<TextView
style="@style/TextAppearance.MaterialComponents.Body1"
android:id="@+id/warehouse_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tesco Expresss"/>
</RelativeLayout>
android:text="Pending"
android:layout_alignParentEnd="true"
android:layout_margin="8dp"
android:layout_alignBaseline="@id/title"
android:textSize="16sp"
android:textColor="@color/statusPending"
/>
<TextView
style="@style/TextAppearance.MaterialComponents.Subtitle2"
android:id="@+id/warehouse_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appleton Tower Superstore"
android:layout_below="@id/title"
android:layout_marginStart="8dp"/>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="36dp"
android:padding="8dp"
android:layout_below="@id/warehouse_container">
android:layout_below="@id/warehouse_title">
<TextView
android:id="@+id/name_header"
style="@style/TextAppearance.MaterialComponents.Body2"
Expand Down Expand Up @@ -94,13 +101,27 @@
android:layout_alignParentEnd="true"
android:text="£23.96"/>
</RelativeLayout>
<android.support.design.button.MaterialButton
android:id="@+id/complete_order"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Complete order"
android:layout_below="@id/footer"
/>
android:orientation="horizontal"
android:layout_below="@id/footer">
<android.support.design.button.MaterialButton
android:id="@+id/view_qr"
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Collect"
android:layout_marginStart="8dp"
/>
<android.support.design.button.MaterialButton
android:id="@+id/get_directions"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Directions"
android:layout_marginStart="8dp"
/>
</LinearLayout>
</RelativeLayout>
</android.support.design.card.MaterialCardView>
27 changes: 27 additions & 0 deletions android/app/src/main/res/layout/dialog_view_qr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.card.MaterialCardView
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="300dp"
android:layout_height="wrap_content"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/instructions"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show this code to the cashier at Appleton Tower Superstore."
android:gravity="center"
android:layout_margin="8dp"/>
<ImageView
android:id="@+id/qr"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_below="@id/instructions"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</android.support.design.card.MaterialCardView>
Loading

0 comments on commit 509c42a

Please sign in to comment.