diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Net.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Net.kt index 71f9550..d18a7fd 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Net.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Net.kt @@ -14,6 +14,7 @@ import org.foxarmy.barcodescannerforemployees.dataclasses.Product import java.io.File import java.io.FileOutputStream import java.io.IOException +import java.util.concurrent.TimeUnit class Net { var language = "en-US" @@ -518,7 +519,11 @@ class Net { fun downloadImage(url: String, file: File, callback: () -> Unit) { CoroutineScope(Dispatchers.IO).launch { - val client = OkHttpClient() + val client = OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(10, TimeUnit.MINUTES) + .build() + val request = Request.Builder() .url(url) .addHeader("Authorization", "Bearer $token") diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/WebSocketClient.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/WebSocketClient.kt index fd543fc..baa7364 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/WebSocketClient.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/WebSocketClient.kt @@ -77,18 +77,20 @@ class WebSocketClient(private val context: Context, private val server: String) val url = "https://${net.server}/api/abstractproduct/getImage/${currentGroup}/${data["local_id"]}" net.downloadImage(url, pictureFile, { abstractProductDAO.addAbstractProduct(newAbstractProduct) + (context as MainActivity).updateAll() }) - } "product" -> { val newProduct = Product.createFromJSON(data) productDAO.insertNewProduct(newProduct) + (context as MainActivity).updateAll() } "category" -> { val newCategory = Category.createFromJSON(data) categoryDAO.addCategory(newCategory) + (context as MainActivity).updateAll() } } } @@ -110,16 +112,19 @@ class WebSocketClient(private val context: Context, private val server: String) val url = "https://${net.server}/api/abstractproduct/getImage/${currentGroup}/${data["local_id"]}" net.downloadImage(url, pictureFile, { abstractProductDAO.updateAbstractProduct(updatedAbstractProduct) + (context as MainActivity).updateAll() }) } "product" -> { val updatedProduct = Product.createFromJSON(data) productDAO.updateProduct(updatedProduct) + (context as MainActivity).updateAll() } "category" -> { val updatedCategory = Category.createFromJSON(data) categoryDAO.updateCategory(updatedCategory) + (context as MainActivity).updateAll() } } } @@ -130,18 +135,19 @@ class WebSocketClient(private val context: Context, private val server: String) when(item) { "abstractproduct" -> { abstractProductDAO.eraseAbstractProduct(id.toInt(), context) + (context as MainActivity).updateAll() } "product" -> { productDAO.eraseProduct(id.toInt()) + (context as MainActivity).updateAll() } "category" -> { categoryDAO.eraseCategory(id.toInt(), context) + (context as MainActivity).updateAll() } } } } - - (context as MainActivity).updateAll() } override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ManageGroupActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ManageGroupActivity.kt index 1439ab5..033d65d 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ManageGroupActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ManageGroupActivity.kt @@ -69,8 +69,10 @@ class ManageGroupActivity : AppCompatActivity() { if (response.code == 200) { val groups = sharedPreferences.getStringSet("groups", emptySet())!! groups.remove(groupId.toString()) + sharedPreferences.edit().putStringSet("groups", groups).apply() + sharedPreferences.edit().putString("currentGroup", "").apply() + if (groups.isEmpty()) { - sharedPreferences.edit().putStringSet("groups", groups).apply() runOnUiThread { val intent = Intent(this, GroupActivity::class.java) startActivity(intent) @@ -96,7 +98,7 @@ class ManageGroupActivity : AppCompatActivity() { val groupMemberView = GroupMemberView(this, this as Context, response.body!!.string(), user) groupMemberView.setOnLongClickListener { view -> - amIAnAdminIn(groupId, {amIAnAdmin -> + amIAnAdminIn(groupId, { amIAnAdmin -> if (!amIAnAdmin) return@amIAnAdminIn runOnUiThread { val popupMenu = PopupMenu(this, groupMemberView) @@ -165,9 +167,11 @@ class ManageGroupActivity : AppCompatActivity() { } fun setUpAdminRelatedButtons() { - amIAnAdminIn(groupId, {isAdmin -> - if (!isAdmin) { - binding.renameButton.visibility = View.GONE + amIAnAdminIn(groupId, { isAdmin -> + runOnUiThread { + if (!isAdmin) { + binding.renameButton.visibility = View.GONE + } } }) } 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 9fe2cad..5604d5a 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt @@ -7,6 +7,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.* +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.view.children import androidx.fragment.app.Fragment @@ -17,7 +18,6 @@ import org.foxarmy.barcodescannerforemployees.activities.FindBarcodelessAbstract import org.foxarmy.barcodescannerforemployees.database.AbstractProductDAO import org.foxarmy.barcodescannerforemployees.database.DBStorageController import org.foxarmy.barcodescannerforemployees.databinding.FragmentStorageBinding -import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct import org.foxarmy.barcodescannerforemployees.generateThumbnailForImage import org.foxarmy.barcodescannerforemployees.getPreferences import org.foxarmy.barcodescannerforemployees.views.AbstractProductView @@ -161,11 +161,25 @@ class StorageFragment : Fragment() { ) if (filterBy == "barcodeless") { - abstractProductView.setOnClickListener { - (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) - } - abstractProductView.findViewById(R.id.productNameView).setOnClickListener { - (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + abstractProductView.also { + it.setOnClickListener { + (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + } + it.findViewById(R.id.productNameView).setOnClickListener { + (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + } + it.findViewById(R.id.productLayout).setOnClickListener { + (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + } + it.findViewById(R.id.categoryView).setOnClickListener { + (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + } + it.findViewById(R.id.unitView).setOnClickListener { + (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + } + it.findViewById(R.id.productNetWeightView).setOnClickListener { + (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct) + } } } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt index 3f5b54f..4317c7e 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt @@ -114,11 +114,12 @@ class AbstractProductView : LinearLayout { } else { mainActivity.removeSelection() } - - this.background = ContextCompat.getDrawable( - context, - if (isProductSelected) R.drawable.outline_selected else R.drawable.outline - ) + activity.runOnUiThread { + this.background = ContextCompat.getDrawable( + context, + if (isProductSelected) R.drawable.outline_selected else R.drawable.outline + ) + } return true } else { return false @@ -137,22 +138,24 @@ class AbstractProductView : LinearLayout { } else { mainActivity.removeSelection() } - - this.background = ContextCompat.getDrawable( - context, - if (isProductSelected) R.drawable.outline_selected else R.drawable.outline - ) + activity.runOnUiThread { + this.background = ContextCompat.getDrawable( + context, + if (isProductSelected) R.drawable.outline_selected else R.drawable.outline + ) + } return true } else { mainActivity.addSelection() isProductSelected = !isProductSelected + activity.runOnUiThread { - 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 + ) + } return true } } @@ -182,8 +185,9 @@ class AbstractProductView : LinearLayout { private fun onNameLongClick(): Boolean { if (activity !is MainActivity) { - Toast.makeText(activity, productNameField!!.text, Toast.LENGTH_SHORT).show() - + activity.runOnUiThread { + Toast.makeText(activity, productNameField!!.text, Toast.LENGTH_SHORT).show() + } return true } val mainActivity = activity as MainActivity @@ -191,7 +195,9 @@ class AbstractProductView : LinearLayout { if (mainActivity.selectionMode) { return onAnyLongClick() } else { - Toast.makeText(activity, productNameField!!.text, Toast.LENGTH_SHORT).show() + activity.runOnUiThread { + Toast.makeText(activity, productNameField!!.text, Toast.LENGTH_SHORT).show() + } } return true } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt index 983b43b..a30f72c 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt @@ -82,6 +82,8 @@ class CategoryView : LinearLayout { } private fun updateStroke() { - this.background = ContextCompat.getDrawable(context, if (isCategorySelected) R.drawable.outline_selected else R.drawable.outline) + (context as Activity).runOnUiThread { + this.background = ContextCompat.getDrawable(context, if (isCategorySelected) R.drawable.outline_selected else R.drawable.outline) + } } } \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt index 489e00a..a1b902f 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt @@ -228,7 +228,6 @@ class ProductView : LinearLayout { this.background = ContextCompat.getDrawable(context, R.drawable.outline_selected) } else { if (product.id != 0) { - thread { this.outline = GradientDrawable() backgroundColor = evaluateColor() strokeColor = darkenColor(backgroundColor, 0.25) // (backgroundColor and 0xfefefe ) shr 1 @@ -236,7 +235,6 @@ class ProductView : LinearLayout { this.outline.setStroke(4, strokeColor) this.outline.alpha = 84 this.background = outline - } } else { this.background = ContextCompat.getDrawable(context, R.drawable.outline) } diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 8bbdbd9..2fb55f3 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -120,14 +120,12 @@ Эта возможность доступна только с онлайн аккаунтом Имя пользователя изменено. Пожалуйста, перезайдите Пароль изменён. Пожалуйста, перезайдите - Enter new group name - Kick - Transfer ownership - Are you sure you want to transfer ownership on current group to that - user? - - Loading, please wait - Loading + Введите новое имя группы + Выгнать + Передать владение группой + Вы увереных, что хотите передать владение группой этому пользователю? + Загрузка, пожалуйста ждите + Загрузка en-US ru-RU diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6af4add..8190da7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,9 +121,7 @@ Enter new group name Kick Transfer ownership - Are you sure you want to transfer ownership on current group to that - user? - + Are you sure you want to transfer ownership on current group to that user? Loading, please wait Loading