Compare commits

..

No commits in common. "b3b4b1025ecab31b8792fa87d8213bdc89068bbe" and "9d52a8192362af346822d6c4de6973d2e07d53c1" have entirely different histories.

13 changed files with 87 additions and 263 deletions

View File

@ -49,8 +49,6 @@ dependencies {
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
// implementation("com.google.android.material:1.2.0")
// Barcode scanning API
implementation (libs.barcode.scanning)
// CameraX library

View File

@ -37,7 +37,7 @@
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.google.firebase.components.activities.MainActivity.provider;com.google.firebase.components.activities.FullscreenActivity.provider;com.google.firebase.components.activities.AddProductActivity.provider"
android:authorities="com.google.firebase.components.activities.StorageActivity.provider;com.google.firebase.components.activities.FullscreenActivity.provider;com.google.firebase.components.activities.AddProductActivity.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
@ -51,7 +51,7 @@
</meta-data>
<activity
android:name=".activities.MainActivity"
android:name=".activities.StorageActivity"
android:exported="true"
android:theme="@style/Theme.BarcodeScannerForEmployees">
<intent-filter>

View File

@ -1,29 +0,0 @@
package org.foxarmy.barcodescannerforemployees
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
class ViewPagerAdapter
public constructor(supportFragmentManager: FragmentManager) : FragmentPagerAdapter(supportFragmentManager) {
private final var fragmentList1: ArrayList<Fragment> = ArrayList()
private final var fragmentTitleList1: ArrayList<String> = ArrayList()
public override fun getItem(position: Int): Fragment {
return fragmentList1.get(position)
}
override fun getPageTitle(position: Int): CharSequence {
return fragmentTitleList1.get(position)
}
override fun getCount(): Int {
return fragmentList1.size
}
fun addFragment(fragment: Fragment, title: String) {
fragmentList1.add(fragment)
fragmentTitleList1.add(title)
}
}

View File

@ -1,105 +0,0 @@
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() {
// private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
public lateinit var adapter: ViewPagerAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)
setupViewPager(binding.tabViewpager)
binding.tabTablayout.setupWithViewPager(binding.tabViewpager)
// val navController = findNavController(R.id.nav_host_fragment_content_storage)
// appBarConfiguration = AppBarConfiguration(navController.graph)
// setupActionBarWithNavController(navController, appBarConfiguration)
binding.addProductFab.setOnClickListener { view ->
val addProductIntent = Intent(this, AddProductActivity::class.java)
val extras = Bundle()
ContextCompat.startActivity(this, addProductIntent, extras)
}
}
private fun setupViewPager(viewpager: ViewPager) {
adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(CategoriesFragment(), "Categories")
adapter.addFragment(StorageFragment(), "Storage")
//TODO: shelf and settings fragments
// setting adapter to view pager.
viewpager.setAdapter(adapter)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_settings -> {
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)
when (fragment::class.simpleName.toString()) {
"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<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
}
else -> super.onOptionsItemSelected(item)
}
}
// override fun onSupportNavigateUp(): Boolean {
// val navController = findNavController(R.id.nav_host_fragment_content_storage)
// return navController.navigateUp(appBarConfiguration)
// || super.onSupportNavigateUp()
// }
}

View File

@ -0,0 +1,80 @@
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 androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.gridlayout.widget.GridLayout
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import org.foxarmy.barcodescannerforemployees.DBStorageController
import org.foxarmy.barcodescannerforemployees.R
import org.foxarmy.barcodescannerforemployees.databinding.ActivityStorageBinding
import org.foxarmy.barcodescannerforemployees.fragments.StorageFragment
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
class StorageActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityStorageBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityStorageBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)
val navController = findNavController(R.id.nav_host_fragment_content_storage)
appBarConfiguration = AppBarConfiguration(navController.graph)
setupActionBarWithNavController(navController, appBarConfiguration)
binding.addProductFab.setOnClickListener { view ->
val addProductIntent = Intent(this, AddProductActivity::class.java)
val extras = Bundle()
ContextCompat.startActivity(this, addProductIntent, extras)
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_settings -> {
true
}
R.id.action_delete -> {
// if there's no selected items, write a toast about it, otherwise delete those items.
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
}
else -> super.onOptionsItemSelected(item)
}
}
override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment_content_storage)
return navController.navigateUp(appBarConfiguration)
|| super.onSupportNavigateUp()
}
}

View File

@ -1,70 +0,0 @@
package org.foxarmy.barcodescannerforemployees.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.foxarmy.barcodescannerforemployees.R
class CategoriesFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_categories, container, false)
}
override fun onResume() {
super.onResume()
// updateContent()
}
// public fun updateContent() {
//
// val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout)
// grv?.removeAllViews()
//
// val db = DBStorageController(requireContext()).readableDatabase
// val projection = arrayOf(
// BaseColumns._ID,
// ProductContract.ProductEntry.PRODUCT_NAME,
// ProductContract.ProductEntry.PRODUCT_NET_WEIGHT,
// ProductContract.ProductEntry.IMAGE_FILENAME
// )
//
// val cursor = db.query(ProductContract.ProductEntry.TABLE_NAME, projection, null, null, null, null, null)
//
// with (cursor) {
// while(moveToNext()) {
// val productId = getInt(getColumnIndexOrThrow(BaseColumns._ID))
// val productName = getString(getColumnIndexOrThrow(ProductContract.ProductEntry.PRODUCT_NAME))
// val netWeight = getDouble(getColumnIndexOrThrow(ProductContract.ProductEntry.PRODUCT_NET_WEIGHT))
// val productImageHash = getString(getColumnIndexOrThrow(ProductContract.ProductEntry.IMAGE_FILENAME))
//
// val product = AbstractProduct(productId, productName, netWeight, productImageHash, 1)
//
// generateThumbnailForImage(context!!, productImageHash)
//
// val abstractProduct = AbstractProductView(
// requireActivity(),
// requireContext(),
// product
// )
// grv?.addView(abstractProduct)
// }
// }
// }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// updateContent()
}
}

View File

@ -2,12 +2,9 @@ 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 androidx.core.view.children
import androidx.fragment.app.Fragment
import androidx.gridlayout.widget.GridLayout
import org.foxarmy.barcodescannerforemployees.*
@ -40,24 +37,7 @@ class StorageFragment : Fragment() {
updateContent()
}
fun removeSelected() {
val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout)
val db = DBStorageController(requireContext())
for (view: AbstractProductView in grv?.children!!.iterator() as Iterator<AbstractProductView>) {
view.findViewById<ImageView>(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}")
}
}
updateContent()
}
fun updateContent() {
public fun updateContent() {
val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout)
grv?.removeAllViews()

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.LinearLayout
@ -66,8 +65,6 @@ class AbstractProductView: LinearLayout {
productLayout.setOnLongClickListener {
isProductSelected = !isProductSelected
Log.d("QWERTYUIOP", "Changed to value $isProductSelected")
this.background = ContextCompat.getDrawable(context, if (isProductSelected) R.drawable.outline_selected else R.drawable.outline)
true
}

View File

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
tools:context=".activities.StorageActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
@ -24,23 +24,9 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#FFF"
app:tabIndicatorHeight="3dp"
app:tabMode="fixed" />
</com.google.android.material.appbar.AppBarLayout>
<!-- <include layout="@layout/content_storage"/>-->
<androidx.viewpager.widget.ViewPager
android:id="@+id/tab_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/content_storage"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_product_fab"

View File

@ -16,5 +16,5 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph_main"/>
app:navGraph="@navigation/nav_graph_storage"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:id="@+id/fragment_storage"
tools:context=".fragments.CategoriesFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/categoriesLayout">
</ScrollView>
</FrameLayout>

View File

@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.foxarmy.barcodescannerforemployees.activities.MainActivity">
tools:context="org.foxarmy.barcodescannerforemployees.activities.StorageActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"