attempt to make gridview

This commit is contained in:
leca 2024-09-29 14:50:20 +03:00
parent 9ea70a30d8
commit 8747e44ae6
7 changed files with 33 additions and 24 deletions

View File

@ -4,14 +4,22 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2024-09-26T16:53:52.475667960Z">
<DropdownSelection timestamp="2024-09-29T11:44:40.817070813Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=RF8X50341NV" />
</handle>
</Target>
</DropdownSelection>
<DialogSelection />
<DialogSelection>
<targets>
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=RF8X50341NV" />
</handle>
</Target>
</targets>
</DialogSelection>
</SelectionState>
</selectionStates>
</component>

View File

@ -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)

View File

@ -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(

View File

@ -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() {
)
}
}
}
}

View File

@ -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">

View File

@ -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" }