Compare commits
No commits in common. "b3b4562f21fbf6ca497f027661bfe4c511ec904a" and "dc7e94b37ba2a5475c0ddfbda6f7dccb7600686d" have entirely different histories.
b3b4562f21
...
dc7e94b37b
@ -2,7 +2,9 @@ package tech.mercantec.easyeat.helpers
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import tech.mercantec.easyeat.models.ShoppingListItem
|
|
||||||
|
@Serializable
|
||||||
|
data class ShoppingListItem(val id: Int, val name: String, val amount: Double?, val unit: String?, val checked: Boolean)
|
||||||
|
|
||||||
fun getShoppingList(ctx: Context): Array<ShoppingListItem> {
|
fun getShoppingList(ctx: Context): Array<ShoppingListItem> {
|
||||||
return requestJson<Unit, Array<ShoppingListItem>>(ctx, "GET", "/api/ShoppingList/get", null)
|
return requestJson<Unit, Array<ShoppingListItem>>(ctx, "GET", "/api/ShoppingList/get", null)
|
||||||
@ -16,7 +18,3 @@ fun addShoppingItem(ctx: Context, name: String, amount: Double?, unit: String?)
|
|||||||
|
|
||||||
requestJson<AddShoppingItemRequest, Boolean>(ctx, "POST", "/api/ShoppingList/add", request)
|
requestJson<AddShoppingItemRequest, Boolean>(ctx, "POST", "/api/ShoppingList/add", request)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleShoppingItemChecked(ctx: Context, item: ShoppingListItem) {
|
|
||||||
requestJson<Unit, Boolean>(ctx, "PUT", "/api/ShoppingList/check?itemId=${item.id}", null)
|
|
||||||
}
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package tech.mercantec.easyeat.models
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ShoppingListItem(val id: Int, var name: String, var amount: Double?, var unit: String?, var checked: Boolean)
|
|
@ -1,60 +0,0 @@
|
|||||||
package tech.mercantec.easyeat.ui.shopping_list
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Paint
|
|
||||||
import android.icu.text.DecimalFormat
|
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.ArrayAdapter
|
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import tech.mercantec.easyeat.R
|
|
||||||
import tech.mercantec.easyeat.models.ShoppingListItem
|
|
||||||
|
|
||||||
class ShoppingItemAdapter(context: Context, items: ArrayList<ShoppingListItem>)
|
|
||||||
: ArrayAdapter<ShoppingListItem>(context, R.layout.shopping_list_item, items) {
|
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
|
||||||
val item = getItem(position)
|
|
||||||
val view = convertView ?: LayoutInflater.from(context).inflate(R.layout.shopping_list_item, parent, false)
|
|
||||||
|
|
||||||
item?.let { item ->
|
|
||||||
val checkmarkView = view.findViewById<ImageView>(R.id.checkmark)
|
|
||||||
val amountView = view.findViewById<TextView>(R.id.amount)
|
|
||||||
val unitView = view.findViewById<TextView>(R.id.unit)
|
|
||||||
val nameView = view.findViewById<TextView>(R.id.name)
|
|
||||||
val textViews = listOf(amountView, unitView, nameView)
|
|
||||||
|
|
||||||
amountView.text = DecimalFormat("#.##").format(item.amount)
|
|
||||||
unitView.text = item.unit
|
|
||||||
nameView.text = item.name
|
|
||||||
|
|
||||||
if (item.checked) {
|
|
||||||
textViews.forEach {
|
|
||||||
it.paintFlags = it.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
|
||||||
|
|
||||||
val color = TypedValue()
|
|
||||||
context.theme.resolveAttribute(R.attr.colorDisabled, color, true)
|
|
||||||
it.setTextColor(ContextCompat.getColor(context, color.resourceId))
|
|
||||||
|
|
||||||
checkmarkView.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
textViews.forEach {
|
|
||||||
it.paintFlags = it.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
||||||
|
|
||||||
val color = TypedValue()
|
|
||||||
context.theme.resolveAttribute(android.R.attr.textColorSecondary, color, true)
|
|
||||||
it.setTextColor(ContextCompat.getColor(context, color.resourceId))
|
|
||||||
|
|
||||||
checkmarkView.visibility = View.INVISIBLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,11 +15,6 @@ import tech.mercantec.easyeat.R
|
|||||||
import tech.mercantec.easyeat.databinding.FragmentShoppingListBinding
|
import tech.mercantec.easyeat.databinding.FragmentShoppingListBinding
|
||||||
import tech.mercantec.easyeat.helpers.ApiRequestException
|
import tech.mercantec.easyeat.helpers.ApiRequestException
|
||||||
import tech.mercantec.easyeat.helpers.addShoppingItem
|
import tech.mercantec.easyeat.helpers.addShoppingItem
|
||||||
import tech.mercantec.easyeat.helpers.getShoppingList
|
|
||||||
import tech.mercantec.easyeat.helpers.toggleShoppingItemChecked
|
|
||||||
import tech.mercantec.easyeat.models.Dish
|
|
||||||
import tech.mercantec.easyeat.models.ShoppingListItem
|
|
||||||
import java.util.ArrayList
|
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class ShoppingListFragment : Fragment() {
|
class ShoppingListFragment : Fragment() {
|
||||||
@ -38,41 +33,6 @@ class ShoppingListFragment : Fragment() {
|
|||||||
_binding = FragmentShoppingListBinding.inflate(inflater, container, false)
|
_binding = FragmentShoppingListBinding.inflate(inflater, container, false)
|
||||||
val root: View = binding.root
|
val root: View = binding.root
|
||||||
|
|
||||||
thread {
|
|
||||||
val items: Array<ShoppingListItem>
|
|
||||||
try {
|
|
||||||
items = getShoppingList(requireContext())
|
|
||||||
} catch (e: ApiRequestException) {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
Toast.makeText(context, e.message, Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
return@thread
|
|
||||||
}
|
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.shoppingList.adapter = ShoppingItemAdapter(requireContext(), ArrayList(items.toMutableList()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.shoppingList.setOnItemClickListener { parent, view, position, id ->
|
|
||||||
val item = parent.getItemAtPosition(position) as ShoppingListItem
|
|
||||||
item.checked = !item.checked
|
|
||||||
|
|
||||||
thread {
|
|
||||||
try {
|
|
||||||
toggleShoppingItemChecked(requireContext(), item)
|
|
||||||
} catch (e: ApiRequestException) {
|
|
||||||
Toast.makeText(requireContext(), e.message, Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val adapter = parent.adapter as ShoppingItemAdapter
|
|
||||||
|
|
||||||
adapter.remove(item)
|
|
||||||
adapter.insert(item, position)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.addToShoppingList.setOnClickListener {
|
binding.addToShoppingList.setOnClickListener {
|
||||||
val view = requireActivity().layoutInflater.inflate(R.layout.dialog_add_to_shopping_list, null)
|
val view = requireActivity().layoutInflater.inflate(R.layout.dialog_add_to_shopping_list, null)
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="960"
|
|
||||||
android:viewportHeight="960"
|
|
||||||
android:tint="?attr/colorControlNormal">
|
|
||||||
<path
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M382,720L154,492L211,435L382,606L749,239L806,296L382,720Z"/>
|
|
||||||
</vector>
|
|
@ -2,9 +2,11 @@
|
|||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:paddingTop="?attr/actionBarSize">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_host_fragment_activity_main"
|
android:id="@+id/nav_host_fragment_activity_main"
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
<?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"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/checkmark"
|
|
||||||
android:layout_width="32dp"
|
|
||||||
android:layout_height="32dp"
|
|
||||||
android:src="@drawable/ic_check_24px"
|
|
||||||
app:tint="@color/green"
|
|
||||||
android:contentDescription="@string/checked_desc"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/amount"
|
|
||||||
android:layout_width="70dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:textAlignment="textEnd"
|
|
||||||
android:textStyle="bold"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/unit"
|
|
||||||
android:layout_marginStart="3dp"
|
|
||||||
android:layout_width="70dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/name"
|
|
||||||
android:layout_marginStart="3dp"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@ -4,7 +4,6 @@
|
|||||||
<item name="colorPrimaryVariant">@color/dark_cyan</item>
|
<item name="colorPrimaryVariant">@color/dark_cyan</item>
|
||||||
<item name="colorOnPrimary">@color/white</item>
|
<item name="colorOnPrimary">@color/white</item>
|
||||||
<item name="colorSecondary">@color/dark_gray</item>
|
<item name="colorSecondary">@color/dark_gray</item>
|
||||||
<item name="colorDisabled">@color/dark_gray</item>
|
|
||||||
<item name="colorSurface">@color/dark_cyan</item>
|
<item name="colorSurface">@color/dark_cyan</item>
|
||||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
<item name="android:colorBackground">@color/black</item>
|
<item name="android:colorBackground">@color/black</item>
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<declare-styleable name="EasyEat">
|
|
||||||
<attr name="colorDisabled" format="color" />
|
|
||||||
</declare-styleable>
|
|
||||||
</resources>
|
|
@ -7,5 +7,4 @@
|
|||||||
<color name="black">#FF242424</color>
|
<color name="black">#FF242424</color>
|
||||||
<color name="white">#FFF9F9F9</color>
|
<color name="white">#FFF9F9F9</color>
|
||||||
<color name="red">#D62D2D </color>
|
<color name="red">#D62D2D </color>
|
||||||
<color name="green">#4CAF50</color>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
<string name="ingredient_name_hint">Beef</string>
|
<string name="ingredient_name_hint">Beef</string>
|
||||||
<string name="change_password_label">Change password</string>
|
<string name="change_password_label">Change password</string>
|
||||||
<string name="logout_label">Log out</string>
|
<string name="logout_label">Log out</string>
|
||||||
<string name="checked_desc">Checked</string>
|
|
||||||
<string-array name="units">
|
<string-array name="units">
|
||||||
<item></item>
|
<item></item>
|
||||||
<item>g</item>
|
<item>g</item>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<item name="colorPrimaryVariant">@color/dark_cyan</item>
|
<item name="colorPrimaryVariant">@color/dark_cyan</item>
|
||||||
<item name="colorOnPrimary">@color/white</item>
|
<item name="colorOnPrimary">@color/white</item>
|
||||||
<item name="colorSecondary">@color/dark_gray</item>
|
<item name="colorSecondary">@color/dark_gray</item>
|
||||||
<item name="colorDisabled">@color/gray</item>
|
|
||||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
<item name="android:colorBackground">@color/white</item>
|
<item name="android:colorBackground">@color/white</item>
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user