bugfixes and translation
This commit is contained in:
		@@ -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")
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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<TextView>(R.id.productNameView).setOnClickListener {
 | 
			
		||||
                        (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                    abstractProductView.also {
 | 
			
		||||
                        it.setOnClickListener {
 | 
			
		||||
                            (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                        }
 | 
			
		||||
                        it.findViewById<TextView>(R.id.productNameView).setOnClickListener {
 | 
			
		||||
                            (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                        }
 | 
			
		||||
                        it.findViewById<ConstraintLayout>(R.id.productLayout).setOnClickListener {
 | 
			
		||||
                            (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                        }
 | 
			
		||||
                        it.findViewById<TextView>(R.id.categoryView).setOnClickListener {
 | 
			
		||||
                            (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                        }
 | 
			
		||||
                        it.findViewById<TextView>(R.id.unitView).setOnClickListener {
 | 
			
		||||
                            (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                        }
 | 
			
		||||
                        it.findViewById<TextView>(R.id.productNetWeightView).setOnClickListener {
 | 
			
		||||
                            (activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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)
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -120,14 +120,12 @@
 | 
			
		||||
    <string name="online_only_feature">Эта возможность доступна только с онлайн аккаунтом</string>
 | 
			
		||||
    <string name="username_changed">Имя пользователя изменено. Пожалуйста, перезайдите</string>
 | 
			
		||||
    <string name="password_changed">Пароль изменён. Пожалуйста, перезайдите</string>
 | 
			
		||||
    <string name="new_group_name">Enter new group name</string>
 | 
			
		||||
    <string name="kick">Kick</string>
 | 
			
		||||
    <string name="transfer_ownership">Transfer ownership</string>
 | 
			
		||||
    <string name="transfer_ownership_confirmation">Are you sure you want to transfer ownership on current group to that
 | 
			
		||||
        user?
 | 
			
		||||
    </string>
 | 
			
		||||
    <string name="loading_please_wait">Loading, please wait</string>
 | 
			
		||||
    <string name="loading">Loading</string>
 | 
			
		||||
    <string name="new_group_name">Введите новое имя группы</string>
 | 
			
		||||
    <string name="kick">Выгнать</string>
 | 
			
		||||
    <string name="transfer_ownership">Передать владение группой</string>
 | 
			
		||||
    <string name="transfer_ownership_confirmation">Вы увереных, что хотите передать владение группой этому пользователю?</string>
 | 
			
		||||
    <string name="loading_please_wait">Загрузка, пожалуйста ждите</string>
 | 
			
		||||
    <string name="loading">Загрузка</string>
 | 
			
		||||
    <string-array name="languages">
 | 
			
		||||
        <item>en-US</item>
 | 
			
		||||
        <item>ru-RU</item>
 | 
			
		||||
 
 | 
			
		||||
@@ -121,9 +121,7 @@
 | 
			
		||||
    <string name="new_group_name">Enter new group name</string>
 | 
			
		||||
    <string name="kick">Kick</string>
 | 
			
		||||
    <string name="transfer_ownership">Transfer ownership</string>
 | 
			
		||||
    <string name="transfer_ownership_confirmation">Are you sure you want to transfer ownership on current group to that
 | 
			
		||||
        user?
 | 
			
		||||
    </string>
 | 
			
		||||
    <string name="transfer_ownership_confirmation">Are you sure you want to transfer ownership on current group to that user?</string>
 | 
			
		||||
    <string name="loading_please_wait">Loading, please wait</string>
 | 
			
		||||
    <string name="loading">Loading</string>
 | 
			
		||||
    <string-array name="languages">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user