Compare commits
3 Commits
alpha-0.0.
...
alpha-0.0.
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a0d8cbf7f | |||
| 54693ff15d | |||
| 6ce23c2081 |
@@ -5,11 +5,11 @@ import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Matrix
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.graphics.scale
|
||||
import com.google.firebase.components.BuildConfig
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -33,8 +33,12 @@ fun generateThumbnailForImage(context: Context, imageHash: String) {
|
||||
val imageFile = File(picturesDir, "$imageHash.png")
|
||||
val imageContent = imageFile.inputStream().readBytes()
|
||||
var img = BitmapFactory.decodeByteArray(imageContent, 0, imageContent.size)
|
||||
img = img.scale(img.width/4,img.height/4)
|
||||
img.compress(Bitmap.CompressFormat.WEBP_LOSSY, 25, FileOutputStream(thumbnailFile))
|
||||
|
||||
val matrix = Matrix();
|
||||
matrix.postRotate(90f)
|
||||
val scaled = Bitmap.createScaledBitmap(img, img.width/4, img.height/4, true)
|
||||
val rotated = Bitmap.createBitmap(scaled, 0, 0, scaled.width, scaled.height, matrix, true)
|
||||
rotated.compress(Bitmap.CompressFormat.WEBP_LOSSY, 25, FileOutputStream(thumbnailFile))
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
@@ -45,6 +45,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||
private lateinit var pictureFile: File
|
||||
private lateinit var picturesPath: File
|
||||
private var barcode: String = ""
|
||||
private var action: String = "new"
|
||||
|
||||
private var scanningBarcode = false
|
||||
|
||||
@@ -53,11 +54,6 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||
|
||||
setContentView(R.layout.fragment_add_abstract_product)
|
||||
|
||||
val extras = intent.extras
|
||||
abstractProduct = extras!!.get("abstractProduct") as AbstractProduct?
|
||||
if (abstractProduct != null) {
|
||||
barcode = abstractProduct!!.barcode
|
||||
}
|
||||
|
||||
picturesPath = File(filesDir, "pictures")
|
||||
val thumbnailsDir = File(cacheDir, "thumbnails")
|
||||
@@ -83,15 +79,23 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||
this.barcode = barcodeText.text.toString()
|
||||
}
|
||||
|
||||
if (abstractProduct?.name == "" && abstractProduct?.barcode != "") {
|
||||
performRequest(abstractProduct?.barcode!!)
|
||||
val extras = intent.extras
|
||||
action = extras!!.get("action") as String
|
||||
when (action) {
|
||||
"update" -> {
|
||||
abstractProduct = extras.get("abstractProduct") as AbstractProduct?
|
||||
}
|
||||
"new_from_barcode" -> {
|
||||
abstractProduct = extras.get("abstractProduct") as AbstractProduct?
|
||||
barcode = abstractProduct!!.barcode
|
||||
performRequest(abstractProduct!!.barcode)
|
||||
}
|
||||
}
|
||||
|
||||
if (abstractProduct != null) {
|
||||
val imageThumbnailUri = getImageUri(this, File(thumbnailsDir, "${abstractProduct!!.imageHash}.webp"))
|
||||
pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]")
|
||||
imageView.setImageURI(imageThumbnailUri)
|
||||
imageView.rotation = 90f
|
||||
barcodeText.setText(abstractProduct!!.barcode)
|
||||
productNameText.text = abstractProduct!!.name
|
||||
netWeightText.text = abstractProduct!!.netWeight.toString()
|
||||
@@ -130,15 +134,15 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||
put(AbstractProductContract.AbstractProductEntry.UNIT, unitTypeSpinner.selectedItemPosition)
|
||||
}
|
||||
|
||||
if (abstractProduct == null) {
|
||||
db.insert(AbstractProductContract.AbstractProductEntry.TABLE_NAME, null, values)
|
||||
} else {
|
||||
if (action == "update") {
|
||||
db.update(
|
||||
AbstractProductContract.AbstractProductEntry.TABLE_NAME,
|
||||
values,
|
||||
"${BaseColumns._ID} = ?",
|
||||
arrayOf(abstractProduct!!.id.toString())
|
||||
)
|
||||
} else if (action == "new" || action == "new_from_barcode"){
|
||||
db.insert(AbstractProductContract.AbstractProductEntry.TABLE_NAME, null, values)
|
||||
}
|
||||
|
||||
finish()
|
||||
|
||||
@@ -6,10 +6,11 @@ import android.os.Bundle
|
||||
import android.provider.BaseColumns
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import org.foxarmy.barcodescannerforemployees.CategoriesContract
|
||||
import org.foxarmy.barcodescannerforemployees.dataclasses.Category
|
||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.R
|
||||
import org.foxarmy.barcodescannerforemployees.dataclasses.Category
|
||||
|
||||
class AddCategoryActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -27,6 +28,11 @@ class AddCategoryActivity : Activity() {
|
||||
findViewById<Button>(R.id.saveButton).setOnClickListener {
|
||||
val db = DBStorageController(this).writableDatabase
|
||||
|
||||
if (categoryNameTextEdit.text.toString() == "") {
|
||||
Toast.makeText(this, getString(R.string.category_name_required), Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (category.id == 0) { // Inserting new category
|
||||
val values = ContentValues().apply {
|
||||
put(CategoriesContract.CategoryEntry.CATEGORY_NAME, categoryNameTextEdit.text.toString())
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package org.foxarmy.barcodescannerforemployees.activities
|
||||
|
||||
import android.app.DatePickerDialog
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import com.journeyapps.barcodescanner.ScanContract
|
||||
import com.journeyapps.barcodescanner.ScanIntentResult
|
||||
@@ -60,6 +63,7 @@ class AddProductActivity : AppCompatActivity() {
|
||||
shelfLifeTextEdit = findViewById(R.id.shelfLifeTextEdit)
|
||||
|
||||
amountTextEdit = findViewById(R.id.amountTextEdit)
|
||||
amountTextEdit.setText("1")
|
||||
|
||||
dateOfProductionSelectButton = findViewById(R.id.selectDateOfProductionButton)
|
||||
saveProductButton = findViewById(R.id.saveProductButton)
|
||||
@@ -206,10 +210,26 @@ class AddProductActivity : AppCompatActivity() {
|
||||
product!!.dateOfExpiry = c.timeInMillis / 1000
|
||||
}
|
||||
|
||||
private fun displayAbstractProduct(abstractProduct: AbstractProduct) {
|
||||
private fun displayAbstractProduct(abstractProduct: AbstractProduct?, scannedBarcode: String) {
|
||||
if (abstractProduct == null) {
|
||||
AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.abstract_product_does_not_exist))
|
||||
.setPositiveButton(R.string.yes) { _, _ ->
|
||||
val addAbstractProductIntent = Intent(this, AddAbstractProductActivity::class.java)
|
||||
val extras = Bundle()
|
||||
extras.putParcelable("abstractProduct", AbstractProduct(0, scannedBarcode, "", 0.0, "", 0, 0))
|
||||
extras.putString("action", "new_from_barcode")
|
||||
addAbstractProductIntent.putExtras(extras)
|
||||
ContextCompat.startActivity(this, addAbstractProductIntent, extras)
|
||||
}
|
||||
.setNegativeButton(R.string.no) {_, _ ->
|
||||
|
||||
}.show()
|
||||
} else {
|
||||
abstractProductView.abstractProduct = abstractProduct
|
||||
abstractProductView.update()
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
val requestPermissionLauncher =
|
||||
@@ -230,11 +250,14 @@ class AddProductActivity : AppCompatActivity() {
|
||||
} else {
|
||||
val scannedBarcode = result.contents
|
||||
abstractProduct = DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, scannedBarcode)
|
||||
displayAbstractProduct(abstractProduct!!)
|
||||
|
||||
displayAbstractProduct(abstractProduct, scannedBarcode)
|
||||
if (abstractProduct != null) {
|
||||
product?.abstractProductId = abstractProduct!!.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepareBarcodeScanner() {
|
||||
val options = ScanOptions()
|
||||
|
||||
@@ -43,6 +43,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// I reuse the same stuff for editing and adding new product.
|
||||
// if abstractProduct == null, it means that we need to create new object
|
||||
extras.putParcelable("abstractProduct", null)
|
||||
extras.putString("action", "new")
|
||||
addAbstractProductIntent.putExtras(extras)
|
||||
ContextCompat.startActivity(this, addAbstractProductIntent, extras)
|
||||
}
|
||||
@@ -50,7 +51,7 @@ class MainActivity : AppCompatActivity() {
|
||||
"CategoriesFragment" -> {
|
||||
val addCategoryIntent = Intent(this, AddCategoryActivity::class.java)
|
||||
val extras = Bundle()
|
||||
extras.putParcelable("category", Category(0, "New category"))
|
||||
extras.putParcelable("category", Category(0, ""))
|
||||
addCategoryIntent.putExtras(extras)
|
||||
ContextCompat.startActivity(this, addCategoryIntent, extras)
|
||||
}
|
||||
@@ -69,13 +70,14 @@ class MainActivity : AppCompatActivity() {
|
||||
private fun setupViewPager(viewpager: ViewPager) {
|
||||
adapter = ViewPagerAdapter(supportFragmentManager)
|
||||
|
||||
adapter.addFragment(CategoriesFragment(), getString(R.string.categories_title))
|
||||
adapter.addFragment(StorageFragment(), getString(R.string.storage_title))
|
||||
adapter.addFragment(ShelfFragment(), getString(R.string.shelf_title))
|
||||
adapter.addFragment(CategoriesFragment(), getString(R.string.categories_title))
|
||||
|
||||
//TODO: settings fragments
|
||||
|
||||
// setting adapter to view pager.
|
||||
viewpager.setAdapter(adapter)
|
||||
viewpager.adapter = adapter
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@@ -151,4 +153,14 @@ class MainActivity : AppCompatActivity() {
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
fun filterAbstractProductsByCategory(id: Int) {
|
||||
binding.tabViewpager.setCurrentItem(0, true)
|
||||
|
||||
val currentPosition = binding.tabTablayout.selectedTabPosition
|
||||
val fragment = adapter.getItem(currentPosition)
|
||||
|
||||
val storageFragment = fragment as StorageFragment
|
||||
storageFragment.filterByCategory(id)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import kotlin.concurrent.thread
|
||||
class StorageFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentStorageBinding
|
||||
|
||||
private var filterByCategory = ""
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -45,6 +45,11 @@ class StorageFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
binding.dropFiltersButton.setOnClickListener {
|
||||
filterByCategory = ""
|
||||
updateContent()
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -94,6 +99,7 @@ class StorageFragment : Fragment() {
|
||||
val addProductIntent = Intent(requireContext(), AddAbstractProductActivity::class.java)
|
||||
val extras = Bundle()
|
||||
extras.putParcelable("abstractProduct", view.abstractProduct)
|
||||
extras.putString("action", "update")
|
||||
addProductIntent.putExtras(extras)
|
||||
ContextCompat.startActivity(requireContext(), addProductIntent, extras)
|
||||
}
|
||||
@@ -128,7 +134,15 @@ class StorageFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
val cursor = db.query(AbstractProductContract.AbstractProductEntry.TABLE_NAME, projection, null, null, null, null, orderBy)
|
||||
var selection = ""
|
||||
var selectionArgs: Array<String>? = null
|
||||
|
||||
if (filterByCategory != "") {
|
||||
selection = "${AbstractProductContract.AbstractProductEntry.CATEGORY} = ?"
|
||||
selectionArgs = arrayOf(filterByCategory)
|
||||
}
|
||||
|
||||
val cursor = db.query(AbstractProductContract.AbstractProductEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, orderBy)
|
||||
|
||||
with (cursor) {
|
||||
while(moveToNext()) {
|
||||
@@ -163,4 +177,10 @@ class StorageFragment : Fragment() {
|
||||
|
||||
updateContent()
|
||||
}
|
||||
|
||||
fun filterByCategory(id: Int) {
|
||||
// filterByCategory = DBStorageController(context!!).getCategoryNameById(DBStorageController(context!!).readableDatabase, id)
|
||||
filterByCategory = "$id"
|
||||
updateContent()
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class AbstractProductView: LinearLayout {
|
||||
thumbnailsDir.mkdirs()
|
||||
val imageUri = getImageUri(activity, File(thumbnailsDir, "${abstractProduct.imageHash}.webp"))
|
||||
productPicture!!.setImageURI(imageUri)
|
||||
productPicture!!.rotation = 90f
|
||||
// productPicture!!.rotation = 90f
|
||||
|
||||
productNameField!!.text = abstractProduct.name
|
||||
netWeightField!!.text = abstractProduct.netWeight.toString()
|
||||
|
||||
@@ -6,9 +6,10 @@ import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.foxarmy.barcodescannerforemployees.dataclasses.Category
|
||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.R
|
||||
import org.foxarmy.barcodescannerforemployees.activities.MainActivity
|
||||
import org.foxarmy.barcodescannerforemployees.dataclasses.Category
|
||||
|
||||
class CategoryView : LinearLayout {
|
||||
var category: Category
|
||||
@@ -35,5 +36,8 @@ class CategoryView : LinearLayout {
|
||||
this.background = ContextCompat.getDrawable(context, if (isCategorySelected) R.drawable.outline_selected else R.drawable.outline)
|
||||
true
|
||||
}
|
||||
setOnClickListener {
|
||||
(activity as MainActivity).filterAbstractProductsByCategory(category.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class ProductView: LinearLayout {
|
||||
val pictureFile = File(thumbnailsDir, "${linkedAbstractProduct.imageHash}.webp")
|
||||
val imageUri = getImageUri(activity, pictureFile)
|
||||
productImageView.setImageURI(imageUri)
|
||||
productImageView.rotation = 90f
|
||||
// productImageView.rotation = 90f
|
||||
|
||||
productNameTextView.text = linkedAbstractProduct.name
|
||||
productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString()
|
||||
|
||||
@@ -4,19 +4,18 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activities.AddCategoryActivity">
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:context=".activities.AddCategoryActivity" android:layout_gravity="center">
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:text="@string/sample_category"
|
||||
android:ems="10"
|
||||
android:id="@+id/newCategoryName" app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_marginTop="20dp"/>
|
||||
android:layout_marginTop="20dp" android:hint="@string/sample_category"/>
|
||||
<Button
|
||||
android:text="@string/saveButton"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
android:text="@string/scan_label"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/categoryTextView"
|
||||
android:layout_marginTop="15dp" android:layout_marginStart="5dp"/>
|
||||
android:layout_marginTop="40dp" android:layout_marginStart="5dp"/>
|
||||
<ImageView
|
||||
android:src="@android:drawable/ic_menu_camera"
|
||||
android:layout_width="0dp"
|
||||
@@ -69,27 +69,27 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/categoryTextView"
|
||||
app:layout_constraintTop_toBottomOf="@+id/netWeight"
|
||||
android:layout_marginTop="20dp" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginTop="30dp" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="8dp"/>
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/categorySpinner"
|
||||
android:layout_width="140dp"
|
||||
android:layout_height="50dp" android:id="@+id/categorySpinner"
|
||||
app:layout_constraintStart_toEndOf="@+id/categoryTextView"
|
||||
app:layout_constraintTop_toBottomOf="@+id/netWeight" android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="18dp"/>
|
||||
android:layout_marginTop="18dp" android:outlineProvider="bounds"/>
|
||||
<Button
|
||||
android:text="@string/saveButton"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="50dp" android:id="@+id/saveButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/categoryTextView"
|
||||
android:layout_marginTop="15dp" app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="40dp" app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginEnd="5dp"/>
|
||||
<Button
|
||||
android:text="@string/takePicture"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="55dp" android:id="@+id/takePictureButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/categoryTextView"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="40dp"
|
||||
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -22,12 +22,21 @@
|
||||
android:layout_height="32dp" android:id="@+id/spinner"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/sortByTextView"
|
||||
app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/dropFiltersButton" android:layout_marginEnd="10dp"
|
||||
/>
|
||||
<Button
|
||||
android:text="@string/drop_filters"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/dropFiltersButton"
|
||||
app:layout_constraintStart_toEndOf="@+id/spinner"
|
||||
app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp" app:layout_constraintTop_toTopOf="parent"/>
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@+id/spinner"
|
||||
android:id="@+id/scrollView2">
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/scrollView2"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dropFiltersButton">
|
||||
<androidx.gridlayout.widget.GridLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/contentGridLayout" app:columnCount="2"
|
||||
|
||||
@@ -77,4 +77,7 @@
|
||||
<item>Имя</item>
|
||||
<item>Категория</item>
|
||||
</string-array>
|
||||
<string name="abstract_product_does_not_exist">Абстрактный продукт с таким штрихкодом не существует. Хотите его добавить?. </string>
|
||||
<string name="drop_filters">Убрать фильтры</string>
|
||||
<string name="category_name_required">Требуется название категории</string>
|
||||
</resources>
|
||||
@@ -75,4 +75,7 @@
|
||||
<string name="expired">Expired</string>
|
||||
<string name="barcode">Barcode</string>
|
||||
<string name="scan_label">Scan</string>
|
||||
<string name="abstract_product_does_not_exist">Abstract product with such barcode does not exist. Do you want to add one?</string>
|
||||
<string name="drop_filters">Drop filters</string>
|
||||
<string name="category_name_required">Category name required</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user