attempt to make gridview
This commit is contained in:
		@@ -15,7 +15,7 @@ class AbstractProductView: LinearLayout {
 | 
			
		||||
    private var categoryField: TextView
 | 
			
		||||
    private var unitField: TextView
 | 
			
		||||
 | 
			
		||||
        constructor(activity: Activity, context: Context, productImageFile: String, productName: String, netWeight: Double, category: Int) : super(context) {
 | 
			
		||||
    constructor(activity: Activity, context: Context, productImageFile: String, productName: String, netWeight: Double, category: Int) : super(context) {
 | 
			
		||||
 | 
			
		||||
        val inflater:LayoutInflater = activity.layoutInflater
 | 
			
		||||
        inflater.inflate(R.layout.abstract_product_view, this)
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ import android.widget.Toast
 | 
			
		||||
import androidx.activity.result.contract.ActivityResultContracts
 | 
			
		||||
import androidx.annotation.RequiresApi
 | 
			
		||||
import androidx.fragment.app.Fragment
 | 
			
		||||
import androidx.navigation.fragment.findNavController
 | 
			
		||||
import com.google.mlkit.vision.barcode.common.Barcode
 | 
			
		||||
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
 | 
			
		||||
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
 | 
			
		||||
@@ -72,7 +73,6 @@ class AddProductFragment : Fragment() {
 | 
			
		||||
            ActivityResultContracts.RequestPermission()
 | 
			
		||||
        ) { isGranted: Boolean ->
 | 
			
		||||
            if (isGranted) {
 | 
			
		||||
                Toast.makeText(requireContext(), "Granted", Toast.LENGTH_LONG).show()
 | 
			
		||||
                getPicture()
 | 
			
		||||
            } else {
 | 
			
		||||
                Toast.makeText(requireContext(), "I need permission in order to take a picture", Toast.LENGTH_LONG).show()
 | 
			
		||||
@@ -108,19 +108,12 @@ class AddProductFragment : Fragment() {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            db.insert(ProductContract.ProductEntry.TABLE_NAME, null, values)
 | 
			
		||||
 | 
			
		||||
            findNavController().navigate(R.id.storageFragment)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.takePictureButton.setOnClickListener {
 | 
			
		||||
 | 
			
		||||
            requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
 | 
			
		||||
 | 
			
		||||
//            val imageUri: Uri = Uri.fromFile(File(File(context?.filesDir, "pictures"), "test.jpg"))
 | 
			
		||||
//            val imageUri = Uri.parse("pictures/test.jpg")
 | 
			
		||||
//            val picturesDir = File(context?.filesDir, "pictures")
 | 
			
		||||
//            picturesDir.mkdirs()
 | 
			
		||||
//            val uri = Uri.fromFile(File(picturesDir, "test.jpg"))
 | 
			
		||||
//            Log.d("", uri.toString())
 | 
			
		||||
//            takePicture.launch(uri)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.scanButton.setOnClickListener {
 | 
			
		||||
@@ -133,8 +126,6 @@ class AddProductFragment : Fragment() {
 | 
			
		||||
            scanner.startScan()
 | 
			
		||||
                .addOnSuccessListener { barcode ->
 | 
			
		||||
                    binding.productName.setText(barcode.rawValue)
 | 
			
		||||
 | 
			
		||||
//                    val url = URL()
 | 
			
		||||
                }
 | 
			
		||||
                .addOnFailureListener { e ->
 | 
			
		||||
                    Toast.makeText(
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import android.provider.BaseColumns
 | 
			
		||||
import android.view.LayoutInflater
 | 
			
		||||
import android.view.View
 | 
			
		||||
import android.view.ViewGroup
 | 
			
		||||
import androidx.constraintlayout.widget.ConstraintLayout
 | 
			
		||||
import android.widget.GridView
 | 
			
		||||
import androidx.fragment.app.Fragment
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -33,10 +33,7 @@ class StorageFragment : Fragment() {
 | 
			
		||||
        val db = DBStorageController(requireContext()).readableDatabase
 | 
			
		||||
        val projection = arrayOf(BaseColumns._ID, ProductContract.ProductEntry.PRODUCT_NAME, ProductContract.ProductEntry.PRODUCT_NET_WEIGHT, ProductContract.ProductEntry.IMAGE_FILENAME)
 | 
			
		||||
 | 
			
		||||
        val selection = "${ProductContract.ProductEntry.PRODUCT_NAME} = ?"
 | 
			
		||||
        val selectionArgs = arrayOf("test")
 | 
			
		||||
 | 
			
		||||
        val cursor = db.query(ProductContract.ProductEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, null)
 | 
			
		||||
        val cursor = db.query(ProductContract.ProductEntry.TABLE_NAME, projection, null, null, null, null, null)
 | 
			
		||||
 | 
			
		||||
        with (cursor) {
 | 
			
		||||
            while(moveToNext()) {
 | 
			
		||||
@@ -44,7 +41,7 @@ class StorageFragment : Fragment() {
 | 
			
		||||
                val netWeight = getDouble(getColumnIndexOrThrow(ProductContract.ProductEntry.PRODUCT_NET_WEIGHT))
 | 
			
		||||
                val pictureFilename = getString(getColumnIndexOrThrow(ProductContract.ProductEntry.IMAGE_FILENAME))
 | 
			
		||||
 | 
			
		||||
                getView()?.findViewById<ConstraintLayout>(R.id.storageLayout)?.addView(
 | 
			
		||||
                getView()?.findViewById<GridView>(R.id.contentGridLayout)?.addView(
 | 
			
		||||
                    AbstractProductView(
 | 
			
		||||
                        requireActivity(),
 | 
			
		||||
                        requireContext(),
 | 
			
		||||
@@ -56,7 +53,5 @@ class StorageFragment : Fragment() {
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,21 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
             xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
             xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
             android:layout_width="match_parent"
 | 
			
		||||
             android:layout_height="match_parent"
 | 
			
		||||
             tools:context=".StorageFragment">
 | 
			
		||||
    <androidx.gridlayout.widget.GridLayout
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="match_parent" android:id="@+id/contentGridLayout" app:columnCount="2"
 | 
			
		||||
            app:rowCount="100">
 | 
			
		||||
 | 
			
		||||
    </androidx.gridlayout.widget.GridLayout>
 | 
			
		||||
    <ScrollView
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="match_parent">
 | 
			
		||||
        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
 | 
			
		||||
                      android:orientation="vertical" android:id="@+id/contentLayout"/>
 | 
			
		||||
    </ScrollView>
 | 
			
		||||
    <androidx.constraintlayout.widget.ConstraintLayout
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="match_parent" android:id="@+id/storageLayout">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user