Added tabs
This commit is contained in:
parent
47bd1ae46e
commit
b3b4b1025e
|
@ -49,7 +49,7 @@ dependencies {
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
|
||||||
implementation("com.google.android.material:1.2.0")
|
// implementation("com.google.android.material:1.2.0")
|
||||||
|
|
||||||
// Barcode scanning API
|
// Barcode scanning API
|
||||||
implementation (libs.barcode.scanning)
|
implementation (libs.barcode.scanning)
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,36 +5,39 @@ import android.os.Bundle
|
||||||
import android.util.Log
|
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.core.view.children
|
||||||
import androidx.gridlayout.widget.GridLayout
|
import androidx.gridlayout.widget.GridLayout
|
||||||
import androidx.navigation.findNavController
|
import androidx.viewpager.widget.ViewPager
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
|
||||||
import androidx.navigation.ui.navigateUp
|
|
||||||
import androidx.navigation.ui.setupActionBarWithNavController
|
|
||||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
import org.foxarmy.barcodescannerforemployees.R
|
||||||
import org.foxarmy.barcodescannerforemployees.databinding.ActivityStorageBinding
|
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.fragments.StorageFragment
|
||||||
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
|
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
// private lateinit var appBarConfiguration: AppBarConfiguration
|
||||||
private lateinit var binding: ActivityStorageBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
public lateinit var adapter: ViewPagerAdapter
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
binding = ActivityStorageBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
setSupportActionBar(binding.toolbar)
|
setSupportActionBar(binding.toolbar)
|
||||||
|
setupViewPager(binding.tabViewpager)
|
||||||
|
binding.tabTablayout.setupWithViewPager(binding.tabViewpager)
|
||||||
|
|
||||||
val navController = findNavController(R.id.nav_host_fragment_content_storage)
|
// val navController = findNavController(R.id.nav_host_fragment_content_storage)
|
||||||
appBarConfiguration = AppBarConfiguration(navController.graph)
|
// appBarConfiguration = AppBarConfiguration(navController.graph)
|
||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
// setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
|
|
||||||
binding.addProductFab.setOnClickListener { view ->
|
binding.addProductFab.setOnClickListener { view ->
|
||||||
val addProductIntent = Intent(this, AddProductActivity::class.java)
|
val addProductIntent = Intent(this, AddProductActivity::class.java)
|
||||||
|
@ -43,6 +46,17 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_main, menu)
|
menuInflater.inflate(R.menu.menu_main, menu)
|
||||||
return true
|
return true
|
||||||
|
@ -55,26 +69,37 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
R.id.action_delete -> {
|
R.id.action_delete -> {
|
||||||
// if there's no selected items, write a toast about it, otherwise delete those items.
|
// 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 currentPosition = binding.tabTablayout.selectedTabPosition
|
||||||
val amountOfViews = storageFragment.view?.findViewById<GridLayout>(R.id.contentGridLayout)?.childCount
|
val fragment = adapter.getItem(currentPosition)
|
||||||
|
|
||||||
|
when (fragment::class.simpleName.toString()) {
|
||||||
|
"StorageFragment" -> {
|
||||||
|
val storageFragment = fragment as StorageFragment
|
||||||
|
storageFragment.removeSelected()
|
||||||
|
// storageFragment.updateContent()
|
||||||
|
|
||||||
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()
|
// 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
// override fun onSupportNavigateUp(): Boolean {
|
||||||
val navController = findNavController(R.id.nav_host_fragment_content_storage)
|
// val navController = findNavController(R.id.nav_host_fragment_content_storage)
|
||||||
return navController.navigateUp(appBarConfiguration)
|
// return navController.navigateUp(appBarConfiguration)
|
||||||
|| super.onSupportNavigateUp()
|
// || super.onSupportNavigateUp()
|
||||||
}
|
// }
|
||||||
}
|
}
|
|
@ -2,9 +2,12 @@ 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 androidx.core.view.children
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.gridlayout.widget.GridLayout
|
import androidx.gridlayout.widget.GridLayout
|
||||||
import org.foxarmy.barcodescannerforemployees.*
|
import org.foxarmy.barcodescannerforemployees.*
|
||||||
|
@ -37,7 +40,24 @@ class StorageFragment : Fragment() {
|
||||||
updateContent()
|
updateContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun 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() {
|
||||||
|
|
||||||
val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout)
|
val grv = getView()?.findViewById<GridLayout>(R.id.contentGridLayout)
|
||||||
grv?.removeAllViews()
|
grv?.removeAllViews()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
@ -65,6 +66,8 @@ class AbstractProductView: LinearLayout {
|
||||||
|
|
||||||
productLayout.setOnLongClickListener {
|
productLayout.setOnLongClickListener {
|
||||||
isProductSelected = !isProductSelected
|
isProductSelected = !isProductSelected
|
||||||
|
Log.d("QWERTYUIOP", "Changed to value $isProductSelected")
|
||||||
|
|
||||||
this.background = ContextCompat.getDrawable(context, if (isProductSelected) R.drawable.outline_selected else R.drawable.outline)
|
this.background = ContextCompat.getDrawable(context, if (isProductSelected) R.drawable.outline_selected else R.drawable.outline)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,23 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"/>
|
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>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<include layout="@layout/content_storage"/>
|
<!-- <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" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/add_product_fab"
|
android:id="@+id/add_product_fab"
|
||||||
|
|
Loading…
Reference in New Issue