diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 17c82e8..3064fa7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -72,6 +72,10 @@
android:name=".activities.MyGroupsActivity"
android:exported="false"
android:theme="@style/Theme.BarcodeScannerForEmployees"/>
+
{
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)
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/SettingsActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/SettingsActivity.kt
new file mode 100644
index 0000000..f15a957
--- /dev/null
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/SettingsActivity.kt
@@ -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
+ lateinit var currentGroup: String
+ lateinit var groupsNames: MutableList
+
+ 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))
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt
index afaaaef..6c75dc3 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/CategoriesFragment.kt
@@ -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(R.id.categoriesLayout)
layout?.removeAllViews()
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt
index 703bcf6..b7328d9 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt
@@ -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(R.id.contentGridLayout)
@@ -117,6 +122,7 @@ class ShelfFragment : Fragment() {
}
fun updateContent() {
+ prepareDatabaseConnection()
thread {
if (updateInProgress) return@thread
updateInProgress = true
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 31d86d5..baa2f26 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt
@@ -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{
diff --git a/app/src/main/res/drawable/seekbar_tick.xml b/app/src/main/res/drawable/seekbar_tick.xml
new file mode 100644
index 0000000..49b0d34
--- /dev/null
+++ b/app/src/main/res/drawable/seekbar_tick.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
new file mode 100644
index 0000000..8a67b35
--- /dev/null
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index cba70f6..2576407 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -111,6 +111,9 @@
Leave group
Rename group
Join or create a group
+ Image scale factor\n
+ Current group
+ Cancel
- en-US
- ru-RU
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 422d3aa..eef5b6e 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -14,4 +14,5 @@
#5AFF30
#FFF200
#ff0000
+ #FFFFFF
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 31757fa..d39507c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -109,6 +109,9 @@
Leave group
Rename group
Join or create a group
+ Image scale factor\n
+ Current group
+ Cancel
- en-US
- ru-RU