This commit is contained in:
leca 2024-10-07 18:22:40 +03:00
parent b3b4b1025e
commit a6c21f05f9
2 changed files with 7 additions and 24 deletions

View File

@ -2,22 +2,16 @@ package org.foxarmy.barcodescannerforemployees.activities
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.gridlayout.widget.GridLayout
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import org.foxarmy.barcodescannerforemployees.DBStorageController
import org.foxarmy.barcodescannerforemployees.R import org.foxarmy.barcodescannerforemployees.R
import org.foxarmy.barcodescannerforemployees.ViewPagerAdapter import org.foxarmy.barcodescannerforemployees.ViewPagerAdapter
import org.foxarmy.barcodescannerforemployees.databinding.ActivityMainBinding import org.foxarmy.barcodescannerforemployees.databinding.ActivityMainBinding
import org.foxarmy.barcodescannerforemployees.fragments.CategoriesFragment import org.foxarmy.barcodescannerforemployees.fragments.CategoriesFragment
import org.foxarmy.barcodescannerforemployees.fragments.StorageFragment import org.foxarmy.barcodescannerforemployees.fragments.StorageFragment
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -68,7 +62,6 @@ class MainActivity : AppCompatActivity() {
true true
} }
R.id.action_delete -> { R.id.action_delete -> {
// if there's no selected items, write a toast about it, otherwise delete those items.
val currentPosition = binding.tabTablayout.selectedTabPosition val currentPosition = binding.tabTablayout.selectedTabPosition
val fragment = adapter.getItem(currentPosition) val fragment = adapter.getItem(currentPosition)
@ -76,21 +69,9 @@ class MainActivity : AppCompatActivity() {
"StorageFragment" -> { "StorageFragment" -> {
val storageFragment = fragment as StorageFragment val storageFragment = fragment as StorageFragment
storageFragment.removeSelected() storageFragment.removeSelected()
// storageFragment.updateContent()
} }
} }
// val storageFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_content_storage)?.childFragmentManager!!.fragments[0] as StorageFragment
// val amountOfViews = storageFragment.view?.findViewById<GridLayout>(R.id.contentGridLayout)?.childCount
//
// for (view: AbstractProductView in storageFragment.view?.findViewById<GridLayout>(R.id.contentGridLayout)?.children!!.iterator() as Iterator<AbstractProductView>) {
// val db = DBStorageController(this)
// if (view.isProductSelected) {
// db.eraseAbstractProduct(db.writableDatabase , view.product.id, this)
// Log.d("QWERTYUIOP", "Removing ${view.product.id}")
// }
// }
// storageFragment.updateContent()
true true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)

View File

@ -2,11 +2,11 @@ package org.foxarmy.barcodescannerforemployees.fragments
import android.os.Bundle import android.os.Bundle
import android.provider.BaseColumns import android.provider.BaseColumns
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.Toast
import androidx.core.view.children import androidx.core.view.children
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.gridlayout.widget.GridLayout import androidx.gridlayout.widget.GridLayout
@ -44,16 +44,18 @@ class StorageFragment : Fragment() {
val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout) val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout)
val db = DBStorageController(requireContext()) val db = DBStorageController(requireContext())
var deleted = false
for (view: AbstractProductView in grv?.children!!.iterator() as Iterator<AbstractProductView>) { for (view: AbstractProductView in grv?.children!!.iterator() as Iterator<AbstractProductView>) {
view.findViewById<ImageView>(R.id.productPicture).setImageURI(null) view.findViewById<ImageView>(R.id.productPicture).setImageURI(null)
if (view.isProductSelected) { if (view.isProductSelected) {
db.eraseAbstractProduct(db.writableDatabase, view.product.id, requireContext()) db.eraseAbstractProduct(db.writableDatabase, view.product.id, requireContext())
Log.d("QWERTYUIOP", "Removing ${view.product.id}") deleted = true
} else {
Log.d("QWERTYUIOP", "Not ${view.product.id}")
} }
} }
if (!deleted) {
Toast.makeText(requireContext(), "Nothing to delete", Toast.LENGTH_SHORT).show()
}
updateContent() updateContent()
} }