From 8747e44ae6e02ebb5484650de46cd1157f22bf7a Mon Sep 17 00:00:00 2001 From: leca Date: Sun, 29 Sep 2024 14:50:20 +0300 Subject: [PATCH] attempt to make gridview --- .idea/deploymentTargetSelector.xml | 12 ++++++++++-- app/build.gradle.kts | 1 + .../AbstractProductView.kt | 2 +- .../AddProductFragment.kt | 15 +++------------ .../barcodescannerforemployees/StorageFragment.kt | 11 +++-------- app/src/main/res/layout/fragment_storage.xml | 14 +++++++++++++- gradle/libs.versions.toml | 2 ++ 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index 41aa2e6..982cfc5 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,14 +4,22 @@ diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1f5c261..6e197c4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -44,6 +44,7 @@ dependencies { implementation(libs.androidx.navigation.fragment.ktx) implementation(libs.androidx.navigation.ui.ktx) implementation(libs.firebase.crashlytics.buildtools) + implementation(libs.androidx.gridlayout) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt index 61ecc22..99c0547 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt @@ -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) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt index aebf3e8..988dfd1 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt @@ -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( diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt index d4b845c..c2cad93 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt @@ -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(R.id.storageLayout)?.addView( + getView()?.findViewById(R.id.contentGridLayout)?.addView( AbstractProductView( requireActivity(), requireContext(), @@ -56,7 +53,5 @@ class StorageFragment : Fragment() { ) } } - - } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_storage.xml b/app/src/main/res/layout/fragment_storage.xml index ac0180e..b0fa424 100644 --- a/app/src/main/res/layout/fragment_storage.xml +++ b/app/src/main/res/layout/fragment_storage.xml @@ -1,9 +1,21 @@ + + + + + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 982cc60..1615d73 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,7 @@ constraintlayout = "2.1.4" navigationFragmentKtx = "2.8.0" navigationUiKtx = "2.8.0" firebaseCrashlyticsBuildtools = "3.0.2" +gridlayout = "1.0.0" [libraries] androidx-camera-view = { module = "androidx.camera:camera-view", version.ref = "cameraView" } @@ -27,6 +28,7 @@ androidx-constraintlayout = { group = "androidx.constraintlayout", name = "const androidx-navigation-fragment-ktx = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navigationFragmentKtx" } androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navigationUiKtx" } firebase-crashlytics-buildtools = { group = "com.google.firebase", name = "firebase-crashlytics-buildtools", version.ref = "firebaseCrashlyticsBuildtools" } +androidx-gridlayout = { group = "androidx.gridlayout", name = "gridlayout", version.ref = "gridlayout" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" }