added settings activity, group swapping, working on image scale factor
This commit is contained in:
parent
617dcf2e7d
commit
3a296e7a26
|
@ -72,6 +72,10 @@
|
|||
android:name=".activities.MyGroupsActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.BarcodeScannerForEmployees"/>
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.BarcodeScannerForEmployees"/>
|
||||
<activity
|
||||
android:name=".activities.FullscreenActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
|
@ -85,7 +89,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.AddAbstractProductActivity.provider;com.google.firebase.components.activities.AddProductActivity.provider;com.google.firebase.components.activities.ExpiryCalendarActivity.provider;com.google.firebase.components.activities.FindBarcodelessAbstractProduct.provider;com.google.firebase.components.activities.ExpiryCalendarGroupActivity.provider;com.google.firebase.components.activities.AccountSettingsActivity.provider;com.google.firebase.components.activities.GroupActivity.provider"
|
||||
android:authorities="com.google.firebase.components.activities.MainActivity.provider;com.google.firebase.components.activities.FullscreenActivity.provider;com.google.firebase.components.activities.AddAbstractProductActivity.provider;com.google.firebase.components.activities.AddProductActivity.provider;com.google.firebase.components.activities.ExpiryCalendarActivity.provider;com.google.firebase.components.activities.FindBarcodelessAbstractProduct.provider;com.google.firebase.components.activities.ExpiryCalendarGroupActivity.provider;com.google.firebase.components.activities.AccountSettingsActivity.provider;com.google.firebase.components.activities.GroupActivity.provider;com.google.firebase.components.activities.SettingsActivity.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package org.foxarmy.barcodescannerforemployees.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -144,6 +146,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
syncAbstractProducts(net, currentGroup, abstractProductDAO, remoteAbstractProducts, localAbstractProducts)
|
||||
syncProducts(productDAO, remoteProducts, localProducts)
|
||||
syncCategories(categoryDAO, remoteCategories, localCategories)
|
||||
|
||||
}
|
||||
|
||||
private fun syncCategories(
|
||||
|
@ -179,7 +182,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
if (categoryInLocalDB == null && remoteCategory != null) {
|
||||
var newCategory: Category
|
||||
|
||||
with (remoteCategory) {
|
||||
with(remoteCategory) {
|
||||
newCategory = Category(
|
||||
this["local_id"].toString().toInt(),
|
||||
this["name"].toString()
|
||||
|
@ -372,9 +375,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
adapter.addFragment(ShelfFragment(), getString(R.string.shelf_title))
|
||||
adapter.addFragment(CategoriesFragment(), getString(R.string.categories_title))
|
||||
|
||||
//TODO: Settings
|
||||
|
||||
// setting adapter to view pager.
|
||||
viewpager.adapter = adapter
|
||||
}
|
||||
|
||||
|
@ -389,6 +389,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
when (item.itemId) {
|
||||
R.id.nav_account -> {
|
||||
intent = Intent(this, AccountSettingsActivity::class.java)
|
||||
settingsActivityLauncher.launch(intent)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.nav_groups -> {
|
||||
|
@ -396,8 +398,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
}
|
||||
|
||||
R.id.nav_settings -> {
|
||||
//TODO: Settings
|
||||
return false
|
||||
intent = Intent(this, SettingsActivity::class.java)
|
||||
}
|
||||
}
|
||||
startActivity(intent)
|
||||
|
@ -405,6 +406,25 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
return true
|
||||
}
|
||||
|
||||
private val settingsActivityLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
synchronize()
|
||||
updateAll()
|
||||
}/* else if (result.resultCode == Activity.RESULT_CANCELED) {
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
fun updateAll() {
|
||||
val storageFragment: StorageFragment = adapter.getItem(0) as StorageFragment
|
||||
val shelfFragment: ShelfFragment = adapter.getItem(1) as ShelfFragment
|
||||
val categoriesFragment: CategoriesFragment = adapter.getItem(2) as CategoriesFragment
|
||||
|
||||
storageFragment.updateContent()
|
||||
shelfFragment.updateContent()
|
||||
categoriesFragment.updateContent()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (actionBarDrawerToggle!!.onOptionsItemSelected(item)) {
|
||||
return true
|
||||
|
@ -415,11 +435,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
|
||||
return when (item.itemId) {
|
||||
R.id.action_settings -> {
|
||||
val intent = Intent(this, SettingsActivity::class.java)
|
||||
settingsActivityLauncher.launch(intent)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_delete -> {
|
||||
|
||||
when (fragment::class.simpleName.toString()) {
|
||||
"StorageFragment" -> {
|
||||
AlertDialog.Builder(this)
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package org.foxarmy.barcodescannerforemployees.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.security.crypto.EncryptedSharedPreferences
|
||||
import androidx.security.crypto.MasterKeys
|
||||
import org.foxarmy.barcodescannerforemployees.Net
|
||||
import org.foxarmy.barcodescannerforemployees.databinding.ActivitySettingsBinding
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
lateinit var binding: ActivitySettingsBinding
|
||||
lateinit var sharedPreferences: SharedPreferences
|
||||
lateinit var myGroups: List<String>
|
||||
lateinit var currentGroup: String
|
||||
lateinit var groupsNames: MutableList<String>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
sharedPreferences = EncryptedSharedPreferences.create(
|
||||
"sensitive",
|
||||
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
|
||||
applicationContext,
|
||||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||
)
|
||||
|
||||
myGroups = sharedPreferences.getStringSet("groups", emptySet())!!.toList()
|
||||
currentGroup = sharedPreferences.getString("currentGroup", "offline")!!
|
||||
val net = Net()
|
||||
|
||||
net.token = sharedPreferences.getString("token", "")!!
|
||||
net.language = sharedPreferences.getString("language", "")!!
|
||||
net.server = sharedPreferences.getString("server", "")!!
|
||||
|
||||
groupsNames = mutableListOf()
|
||||
|
||||
for (myGroup in myGroups) {
|
||||
groupsNames.add(net.getGroupName(myGroup.toInt()))
|
||||
}
|
||||
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setUpImageCompressionSeekBar()
|
||||
fillUpCurrentGroupSpinner()
|
||||
|
||||
binding.saveButton.setOnClickListener {
|
||||
sharedPreferences.edit().putString("currentGroup", net.getGroupId(binding.currentGroupSpinner.selectedItem.toString())).apply()
|
||||
sharedPreferences.edit().putInt("imageCompression", binding.imageCompressionFactorSeekBar.progress)
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.cancelButton.setOnClickListener {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpImageCompressionSeekBar() {
|
||||
val compressionFactor = sharedPreferences.getInt("imageCompression", 0)
|
||||
binding.imageCompressionFactorSeekBar.progress = compressionFactor
|
||||
}
|
||||
|
||||
private fun fillUpCurrentGroupSpinner() {
|
||||
|
||||
|
||||
if (currentGroup == "offline") {
|
||||
binding.currentGroupSetting.visibility = View.GONE
|
||||
}
|
||||
|
||||
val arrayAdapter =
|
||||
ArrayAdapter(this, androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, groupsNames)
|
||||
arrayAdapter.setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item)
|
||||
binding.currentGroupSpinner.adapter = arrayAdapter
|
||||
binding.currentGroupSpinner.setSelection(myGroups.indexOf(currentGroup))
|
||||
}
|
||||
}
|
|
@ -36,6 +36,10 @@ class CategoriesFragment : Fragment() {
|
|||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||
)
|
||||
|
||||
prepareDatabaseConnection()
|
||||
}
|
||||
|
||||
private fun prepareDatabaseConnection() {
|
||||
val dbHelper = DBStorageController(requireContext(), sharedPreferences.getString("currentGroup", "database")!!)
|
||||
categoryDAO = CategoryDAO(dbHelper)
|
||||
}
|
||||
|
@ -95,6 +99,7 @@ class CategoriesFragment : Fragment() {
|
|||
}
|
||||
|
||||
fun updateContent() {
|
||||
prepareDatabaseConnection()
|
||||
val layout = view?.findViewById<LinearLayout>(R.id.categoriesLayout)
|
||||
layout?.removeAllViews()
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ import androidx.gridlayout.widget.GridLayout
|
|||
import androidx.security.crypto.EncryptedSharedPreferences
|
||||
import androidx.security.crypto.MasterKeys
|
||||
import org.foxarmy.barcodescannerforemployees.Net
|
||||
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.R
|
||||
import org.foxarmy.barcodescannerforemployees.activities.AddProductActivity
|
||||
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.database.ProductDAO
|
||||
import org.foxarmy.barcodescannerforemployees.databinding.FragmentShelfBinding
|
||||
import org.foxarmy.barcodescannerforemployees.views.ProductView
|
||||
|
@ -46,8 +46,8 @@ class ShelfFragment : Fragment() {
|
|||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||
)
|
||||
|
||||
val dbHelper = DBStorageController(requireContext(), sharedPreferences.getString("currentGroup", "database")!!)
|
||||
productDAO = ProductDAO(dbHelper)
|
||||
prepareDatabaseConnection()
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
@ -79,6 +79,11 @@ class ShelfFragment : Fragment() {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
private fun prepareDatabaseConnection() {
|
||||
val dbHelper = DBStorageController(requireContext(), sharedPreferences.getString("currentGroup", "database")!!)
|
||||
productDAO = ProductDAO(dbHelper)
|
||||
}
|
||||
|
||||
fun updateSelected() {
|
||||
val grv = view?.findViewById<GridLayout>(R.id.contentGridLayout)
|
||||
|
||||
|
@ -117,6 +122,7 @@ class ShelfFragment : Fragment() {
|
|||
}
|
||||
|
||||
fun updateContent() {
|
||||
prepareDatabaseConnection()
|
||||
thread {
|
||||
if (updateInProgress) return@thread
|
||||
updateInProgress = true
|
||||
|
|
|
@ -13,11 +13,11 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.security.crypto.EncryptedSharedPreferences
|
||||
import androidx.security.crypto.MasterKeys
|
||||
import org.foxarmy.barcodescannerforemployees.Net
|
||||
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.R
|
||||
import org.foxarmy.barcodescannerforemployees.activities.AddAbstractProductActivity
|
||||
import org.foxarmy.barcodescannerforemployees.activities.FindBarcodelessAbstractProduct
|
||||
import org.foxarmy.barcodescannerforemployees.database.AbstractProductDAO
|
||||
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.databinding.FragmentStorageBinding
|
||||
import org.foxarmy.barcodescannerforemployees.generateThumbnailForImage
|
||||
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
|
||||
|
@ -45,8 +45,7 @@ class StorageFragment : Fragment() {
|
|||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||
)
|
||||
|
||||
val dbHelper = DBStorageController(requireContext(), sharedPreferences.getString("currentGroup", "database")!!)
|
||||
abstractProductDAO = AbstractProductDAO(dbHelper)
|
||||
prepareDatabaseConnection()
|
||||
|
||||
binding = FragmentStorageBinding.inflate(inflater)
|
||||
|
||||
|
@ -73,6 +72,11 @@ class StorageFragment : Fragment() {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
private fun prepareDatabaseConnection() {
|
||||
val dbHelper = DBStorageController(requireContext(), sharedPreferences.getString("currentGroup", "database")!!)
|
||||
abstractProductDAO = AbstractProductDAO(dbHelper)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
|
@ -137,6 +141,7 @@ class StorageFragment : Fragment() {
|
|||
}
|
||||
|
||||
fun updateContent() {
|
||||
prepareDatabaseConnection()
|
||||
thread {
|
||||
val grv = binding.contentGridLayout
|
||||
activity!!.runOnUiThread{
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<size android:width="4dp" android:height="4dp" />
|
||||
<solid android:color="#FFFFFF" />
|
||||
</shape>
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" android:id="@+id/imageCompressionSetting"
|
||||
android:layout_marginTop="16dp">
|
||||
<TextView
|
||||
android:text="@string/image_scale_factor"
|
||||
android:layout_width="187dp"
|
||||
android:layout_height="30dp" android:id="@+id/imageCompressionFactorTextView" android:textSize="20sp"
|
||||
android:textAlignment="center"
|
||||
/>
|
||||
<SeekBar
|
||||
style="@style/Widget.AppCompat.SeekBar.Discrete"
|
||||
android:layout_width="219dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="16"
|
||||
android:progress="0"
|
||||
android:id="@+id/imageCompressionFactorSeekBar"
|
||||
android:tickMark="@drawable/seekbar_tick"
|
||||
android:tickMarkTint="@color/seekbar_tick_color"
|
||||
android:layout_marginTop="6dp" android:indeterminateOnly="false" android:splitTrack="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/currentGroupSetting"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageCompressionSetting">
|
||||
<TextView
|
||||
android:text="@string/current_group"
|
||||
android:layout_width="81dp"
|
||||
android:layout_height="wrap_content" android:id="@+id/currentGroupTextView" android:layout_weight="1"
|
||||
android:textSize="20sp" android:textAlignment="center"/>
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/currentGroupSpinner" android:layout_weight="1"
|
||||
android:layout_marginTop="-1dp"/>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:text="@string/saveButton"
|
||||
android:layout_width="88dp"
|
||||
android:layout_height="wrap_content" android:id="@+id/saveButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/currentGroupSetting"
|
||||
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@+id/cancelButton"
|
||||
android:layout_marginTop="32dp"/>
|
||||
<Button
|
||||
android:text="@string/cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/cancelButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/currentGroupSetting" app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/saveButton" android:layout_marginTop="32dp"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -111,6 +111,9 @@
|
|||
<string name="leave_group">Leave group</string>
|
||||
<string name="rename_group">Rename group</string>
|
||||
<string name="join_or_create_group">Join or create a group</string>
|
||||
<string name="image_scale_factor">Image scale factor\n</string>
|
||||
<string name="current_group">Current group</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string-array name="languages">
|
||||
<item>en-US</item>
|
||||
<item>ru-RU</item>
|
||||
|
|
|
@ -14,4 +14,5 @@
|
|||
<color name="full_freshness">#5AFF30</color>
|
||||
<color name="half_freshness">#FFF200</color>
|
||||
<color name="expired_freshness">#ff0000</color>
|
||||
<color name="seekbar_tick_color">#FFFFFF</color>
|
||||
</resources>
|
|
@ -109,6 +109,9 @@
|
|||
<string name="leave_group">Leave group</string>
|
||||
<string name="rename_group">Rename group</string>
|
||||
<string name="join_or_create_group">Join or create a group</string>
|
||||
<string name="image_scale_factor">Image scale factor\n</string>
|
||||
<string name="current_group">Current group</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string-array name="languages">
|
||||
<item>en-US</item>
|
||||
<item>ru-RU</item>
|
||||
|
|
Loading…
Reference in New Issue