diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt index a5bf251..e5d15db 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt @@ -2,22 +2,16 @@ package org.foxarmy.barcodescannerforemployees.activities import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.Menu import android.view.MenuItem -import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat -import androidx.core.view.children -import androidx.gridlayout.widget.GridLayout import androidx.viewpager.widget.ViewPager -import org.foxarmy.barcodescannerforemployees.DBStorageController import org.foxarmy.barcodescannerforemployees.R import org.foxarmy.barcodescannerforemployees.ViewPagerAdapter import org.foxarmy.barcodescannerforemployees.databinding.ActivityMainBinding import org.foxarmy.barcodescannerforemployees.fragments.CategoriesFragment import org.foxarmy.barcodescannerforemployees.fragments.StorageFragment -import org.foxarmy.barcodescannerforemployees.views.AbstractProductView class MainActivity : AppCompatActivity() { @@ -68,7 +62,6 @@ class MainActivity : AppCompatActivity() { true } 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 fragment = adapter.getItem(currentPosition) @@ -76,21 +69,9 @@ class MainActivity : AppCompatActivity() { "StorageFragment" -> { val storageFragment = fragment as StorageFragment 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(R.id.contentGridLayout)?.childCount -// -// for (view: AbstractProductView in storageFragment.view?.findViewById(R.id.contentGridLayout)?.children!!.iterator() as Iterator) { -// 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 } else -> super.onOptionsItemSelected(item) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt index 0cf0fa0..6264160 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt @@ -2,11 +2,11 @@ package org.foxarmy.barcodescannerforemployees.fragments import android.os.Bundle import android.provider.BaseColumns -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView +import android.widget.Toast import androidx.core.view.children import androidx.fragment.app.Fragment import androidx.gridlayout.widget.GridLayout @@ -44,16 +44,18 @@ class StorageFragment : Fragment() { val grv = getView()?.findViewById(R.id.contentGridLayout) val db = DBStorageController(requireContext()) - + var deleted = false for (view: AbstractProductView in grv?.children!!.iterator() as Iterator) { view.findViewById(R.id.productPicture).setImageURI(null) if (view.isProductSelected) { db.eraseAbstractProduct(db.writableDatabase, view.product.id, requireContext()) - Log.d("QWERTYUIOP", "Removing ${view.product.id}") - } else { - Log.d("QWERTYUIOP", "Not ${view.product.id}") + deleted = true } } + + if (!deleted) { + Toast.makeText(requireContext(), "Nothing to delete", Toast.LENGTH_SHORT).show() + } updateContent() }