added things my wife asked
This commit is contained in:
		@@ -45,7 +45,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
 | 
			
		||||
    private lateinit var pictureFile: File
 | 
			
		||||
    private lateinit var picturesPath: File
 | 
			
		||||
    private var barcode: String = ""
 | 
			
		||||
    private var updatingExisting = false
 | 
			
		||||
    private var action: String = "new"
 | 
			
		||||
 | 
			
		||||
    private var scanningBarcode = false
 | 
			
		||||
 | 
			
		||||
@@ -54,8 +54,6 @@ class AddAbstractProductActivity : AppCompatActivity() {
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.fragment_add_abstract_product)
 | 
			
		||||
 | 
			
		||||
        val extras = intent.extras
 | 
			
		||||
        abstractProduct = extras!!.get("abstractProduct") as AbstractProduct?
 | 
			
		||||
 | 
			
		||||
        picturesPath = File(filesDir, "pictures")
 | 
			
		||||
        val thumbnailsDir = File(cacheDir, "thumbnails")
 | 
			
		||||
@@ -81,21 +79,23 @@ class AddAbstractProductActivity : AppCompatActivity() {
 | 
			
		||||
            this.barcode = barcodeText.text.toString()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (abstractProduct != null && abstractProduct!!.barcode != "" && abstractProduct!!.name == "") {
 | 
			
		||||
            barcode = abstractProduct!!.barcode
 | 
			
		||||
            updatingExisting = false
 | 
			
		||||
            performRequest(abstractProduct!!.barcode)
 | 
			
		||||
        } else if (abstractProduct != null && abstractProduct!!.barcode == ""){
 | 
			
		||||
            updatingExisting = true
 | 
			
		||||
        } else if (abstractProduct == null) {
 | 
			
		||||
            updatingExisting = false
 | 
			
		||||
        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()
 | 
			
		||||
@@ -134,14 +134,14 @@ class AddAbstractProductActivity : AppCompatActivity() {
 | 
			
		||||
                put(AbstractProductContract.AbstractProductEntry.UNIT, unitTypeSpinner.selectedItemPosition)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (updatingExisting) {
 | 
			
		||||
            if (action == "update") {
 | 
			
		||||
                db.update(
 | 
			
		||||
                    AbstractProductContract.AbstractProductEntry.TABLE_NAME,
 | 
			
		||||
                    values,
 | 
			
		||||
                    "${BaseColumns._ID} = ?",
 | 
			
		||||
                    arrayOf(abstractProduct!!.id.toString())
 | 
			
		||||
                )
 | 
			
		||||
            } else {
 | 
			
		||||
            } else if (action == "new" || action == "new_from_barcode"){
 | 
			
		||||
                db.insert(AbstractProductContract.AbstractProductEntry.TABLE_NAME, null, values)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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())
 | 
			
		||||
 
 | 
			
		||||
@@ -63,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)
 | 
			
		||||
@@ -217,6 +218,7 @@ class AddProductActivity : AppCompatActivity() {
 | 
			
		||||
                    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)
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
@@ -78,4 +78,6 @@
 | 
			
		||||
        <item>Категория</item>
 | 
			
		||||
    </string-array>
 | 
			
		||||
    <string name="abstract_product_does_not_exist">Абстрактный продукт с таким штрихкодом не существует. Хотите его добавить?. </string>
 | 
			
		||||
    <string name="drop_filters">Убрать фильтры</string>
 | 
			
		||||
    <string name="category_name_required">Требуется название категории</string>
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -76,4 +76,6 @@
 | 
			
		||||
    <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