darker outline of a productView, fixed duplications of abstract ones
This commit is contained in:
parent
b1030ac8c1
commit
224887422c
|
@ -27,6 +27,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
private lateinit var takePictureButton: Button
|
private lateinit var takePictureButton: Button
|
||||||
private lateinit var scanButton: Button
|
private lateinit var scanButton: Button
|
||||||
|
|
||||||
|
private lateinit var barcodeText: EditText
|
||||||
private lateinit var productNameText: TextView
|
private lateinit var productNameText: TextView
|
||||||
private lateinit var netWeightText: TextView
|
private lateinit var netWeightText: TextView
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
private var abstractProduct: AbstractProduct? = null
|
private var abstractProduct: AbstractProduct? = null
|
||||||
private lateinit var pictureFile: File
|
private lateinit var pictureFile: File
|
||||||
private lateinit var picturesPath: File
|
private lateinit var picturesPath: File
|
||||||
private lateinit var barcode: String
|
private var barcode: String = ""
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -58,6 +59,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
takePictureButton = findViewById(R.id.takePictureButton)
|
takePictureButton = findViewById(R.id.takePictureButton)
|
||||||
scanButton = findViewById(R.id.scan_button)
|
scanButton = findViewById(R.id.scan_button)
|
||||||
|
|
||||||
|
barcodeText = findViewById(R.id.barcodeTextEdit)
|
||||||
productNameText = findViewById(R.id.productName)
|
productNameText = findViewById(R.id.productName)
|
||||||
netWeightText = findViewById(R.id.netWeight)
|
netWeightText = findViewById(R.id.netWeight)
|
||||||
|
|
||||||
|
@ -79,11 +81,15 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
val productName = productNameText.text.toString()
|
val productName = productNameText.text.toString()
|
||||||
val netWeight = netWeightText.text
|
val netWeight = netWeightText.text
|
||||||
if (abstractProduct == null && (!this::pictureFile.isInitialized || !pictureFile.exists())) {
|
if (abstractProduct == null && (!this::pictureFile.isInitialized || !pictureFile.exists())) {
|
||||||
|
|
||||||
Toast.makeText(this, "Please, make a picture of a product!", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Please, make a picture of a product!", Toast.LENGTH_SHORT).show()
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (barcode == "") {
|
||||||
|
Toast.makeText(this, "Please, scan barcode on a product", Toast.LENGTH_SHORT).show()
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
if (productName == "") {
|
if (productName == "") {
|
||||||
Toast.makeText(this, "Please, write a name of a product!", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Please, write a name of a product!", Toast.LENGTH_SHORT).show()
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
@ -124,6 +130,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
scanner.startScan()
|
scanner.startScan()
|
||||||
.addOnSuccessListener { barcode ->
|
.addOnSuccessListener { barcode ->
|
||||||
this.barcode = barcode.rawValue.toString()
|
this.barcode = barcode.rawValue.toString()
|
||||||
|
barcodeText.setText(this.barcode)
|
||||||
val requester = Requester("https://ean-online.ru", "match.php")
|
val requester = Requester("https://ean-online.ru", "match.php")
|
||||||
requester.request(this, barcode.rawValue!!.toString())
|
requester.request(this, barcode.rawValue!!.toString())
|
||||||
var abstractProduct: AbstractProduct
|
var abstractProduct: AbstractProduct
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.foxarmy.barcodescannerforemployees.fragments.StorageFragment
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
public lateinit var adapter: ViewPagerAdapter
|
lateinit var adapter: ViewPagerAdapter
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -50,9 +50,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
"CategoriesFragment" -> {
|
"CategoriesFragment" -> {
|
||||||
val addCategoryIntent = Intent(this, AddCategoryActivity::class.java)
|
val addCategoryIntent = Intent(this, AddCategoryActivity::class.java)
|
||||||
val extras = Bundle()
|
val extras = Bundle()
|
||||||
//TODO: Implement parcellable for Category class to simplify this
|
|
||||||
// extras.putInt("categoryid", 0)
|
|
||||||
// extras.putString("categoryname", "New category")
|
|
||||||
extras.putParcelable("category", Category(0, "New category"))
|
extras.putParcelable("category", Category(0, "New category"))
|
||||||
addCategoryIntent.putExtras(extras)
|
addCategoryIntent.putExtras(extras)
|
||||||
ContextCompat.startActivity(this, addCategoryIntent, extras)
|
ContextCompat.startActivity(this, addCategoryIntent, extras)
|
||||||
|
|
|
@ -30,6 +30,19 @@ class StorageFragment : Fragment() {
|
||||||
return inflater.inflate(R.layout.fragment_storage, container, false)
|
return inflater.inflate(R.layout.fragment_storage, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
updateContent()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
|
||||||
|
val grv = view?.findViewById<GridLayout>(R.id.contentGridLayout)
|
||||||
|
grv?.removeAllViews()
|
||||||
|
}
|
||||||
|
|
||||||
fun removeSelected() {
|
fun removeSelected() {
|
||||||
thread {
|
thread {
|
||||||
val grv = view?.findViewById<GridLayout>(R.id.contentGridLayout)
|
val grv = view?.findViewById<GridLayout>(R.id.contentGridLayout)
|
||||||
|
@ -71,7 +84,7 @@ class StorageFragment : Fragment() {
|
||||||
|
|
||||||
fun updateContent() {
|
fun updateContent() {
|
||||||
thread {
|
thread {
|
||||||
val grv = view?.findViewById<GridLayout>(R.id.contentGridLayout)
|
val grv:GridLayout? = view?.findViewById(R.id.contentGridLayout)
|
||||||
activity!!.runOnUiThread{
|
activity!!.runOnUiThread{
|
||||||
grv?.removeAllViews()
|
grv?.removeAllViews()
|
||||||
}
|
}
|
||||||
|
@ -106,12 +119,13 @@ class StorageFragment : Fragment() {
|
||||||
requireContext(),
|
requireContext(),
|
||||||
product
|
product
|
||||||
)
|
)
|
||||||
|
|
||||||
activity!!.runOnUiThread{
|
activity!!.runOnUiThread{
|
||||||
grv?.addView(abstractProduct)
|
grv?.addView(abstractProduct)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.Color
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
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
|
||||||
|
@ -16,6 +17,7 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.blue
|
import androidx.core.graphics.blue
|
||||||
import androidx.core.graphics.green
|
import androidx.core.graphics.green
|
||||||
import androidx.core.graphics.red
|
import androidx.core.graphics.red
|
||||||
|
import androidx.core.math.MathUtils.clamp
|
||||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
import org.foxarmy.barcodescannerforemployees.R
|
||||||
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
||||||
|
@ -26,6 +28,7 @@ import java.io.File
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class ProductView: LinearLayout {
|
class ProductView: LinearLayout {
|
||||||
var product: Product = Product()
|
var product: Product = Product()
|
||||||
|
@ -38,6 +41,9 @@ class ProductView: LinearLayout {
|
||||||
private lateinit var productAmountTextView: TextView
|
private lateinit var productAmountTextView: TextView
|
||||||
private lateinit var productCategoryView: TextView
|
private lateinit var productCategoryView: TextView
|
||||||
private lateinit var productLifeSpan: TextView
|
private lateinit var productLifeSpan: TextView
|
||||||
|
private var backgroundColor: Int = 0xffffff
|
||||||
|
private var strokeColor: Int = 0x000000
|
||||||
|
private lateinit var outline: GradientDrawable
|
||||||
|
|
||||||
constructor(context: Context, a: AttributeSet) : super(context, a) {
|
constructor(context: Context, a: AttributeSet) : super(context, a) {
|
||||||
activity = getActivity(context)!!
|
activity = getActivity(context)!!
|
||||||
|
@ -72,11 +78,12 @@ class ProductView: LinearLayout {
|
||||||
fun update () {
|
fun update () {
|
||||||
val linkedAbstractProduct: AbstractProduct = DBStorageController(activity).findAbstractProductById(DBStorageController(activity).readableDatabase, product.abstractProductId)!!
|
val linkedAbstractProduct: AbstractProduct = DBStorageController(activity).findAbstractProductById(DBStorageController(activity).readableDatabase, product.abstractProductId)!!
|
||||||
|
|
||||||
val picturesDir = File(activity.filesDir, "pictures")
|
val thumbnailsDir = File(activity.cacheDir, "thumbnails")
|
||||||
picturesDir.mkdirs()
|
thumbnailsDir.mkdirs()
|
||||||
val pictureFile = File(picturesDir, "${linkedAbstractProduct.imageHash}.png")
|
val pictureFile = File(thumbnailsDir, "${linkedAbstractProduct.imageHash}.webp")
|
||||||
val imageUri = getImageUri(activity, pictureFile)
|
val imageUri = getImageUri(activity, pictureFile)
|
||||||
productImageView.setImageURI(imageUri)
|
productImageView.setImageURI(imageUri)
|
||||||
|
productImageView.rotation = 90f
|
||||||
|
|
||||||
productNameTextView.text = linkedAbstractProduct.name
|
productNameTextView.text = linkedAbstractProduct.name
|
||||||
productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString()
|
productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString()
|
||||||
|
@ -84,6 +91,7 @@ class ProductView: LinearLayout {
|
||||||
productCategoryView.text = DBStorageController(activity).getCategoryNameById(DBStorageController(activity).readableDatabase, linkedAbstractProduct.category)
|
productCategoryView.text = DBStorageController(activity).getCategoryNameById(DBStorageController(activity).readableDatabase, linkedAbstractProduct.category)
|
||||||
productLifeSpan.text = "${product.dateOfProduction}-${product.dateOfExpiry}"
|
productLifeSpan.text = "${product.dateOfProduction}-${product.dateOfExpiry}"
|
||||||
|
|
||||||
|
|
||||||
updateStroke()
|
updateStroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +101,15 @@ class ProductView: LinearLayout {
|
||||||
this.background = ContextCompat.getDrawable(context, R.drawable.outline_selected)
|
this.background = ContextCompat.getDrawable(context, R.drawable.outline_selected)
|
||||||
} else {
|
} else {
|
||||||
if (product.id != 0) {
|
if (product.id != 0) {
|
||||||
val color = evaluateColor()
|
thread {
|
||||||
val outline = GradientDrawable()
|
this.outline = GradientDrawable()
|
||||||
this.background = outline
|
backgroundColor = evaluateColor()
|
||||||
(this.background.current as GradientDrawable).setStroke(3, color)
|
strokeColor = darkenColor(backgroundColor, 0.25) // (backgroundColor and 0xfefefe ) shr 1
|
||||||
|
this.outline.setColor(backgroundColor)
|
||||||
|
this.outline.setStroke(4, strokeColor)
|
||||||
|
this.outline.alpha = 84
|
||||||
|
this.background = outline
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.background = ContextCompat.getDrawable(context, R.drawable.outline)
|
this.background = ContextCompat.getDrawable(context, R.drawable.outline)
|
||||||
}
|
}
|
||||||
|
@ -125,21 +138,37 @@ class ProductView: LinearLayout {
|
||||||
|
|
||||||
val gradientPosition = 1 - if (percentage > 0.5) (percentage - 0.5) * 2 else percentage * 2
|
val gradientPosition = 1 - if (percentage > 0.5) (percentage - 0.5) * 2 else percentage * 2
|
||||||
|
|
||||||
val red = (startColor.red + gradientPosition * (endColor.red - startColor.red )).toInt()
|
val red = clamp((startColor.red + gradientPosition * (endColor.red - startColor.red )).toInt(), 0, 255)
|
||||||
val green = (startColor.green + gradientPosition * (endColor.green - startColor.green)).toInt()
|
val green = clamp((startColor.green + gradientPosition * (endColor.green - startColor.green)).toInt(), 0, 255)
|
||||||
val blue = (startColor.blue + gradientPosition * (endColor.blue - startColor.blue)).toInt()
|
val blue = clamp((startColor.blue + gradientPosition * (endColor.blue - startColor.blue)).toInt(), 0, 255)
|
||||||
|
|
||||||
var redHex = java.lang.Integer.toHexString(red)
|
var redHex = Integer.toHexString(red)
|
||||||
if (redHex.length == 1) redHex = "0$redHex"
|
if (redHex.length == 1) redHex = "0$redHex"
|
||||||
|
|
||||||
var greenHex = java.lang.Integer.toHexString(green)
|
var greenHex = Integer.toHexString(green)
|
||||||
if (greenHex.length == 1) greenHex = "0$greenHex"
|
if (greenHex.length == 1) greenHex = "0$greenHex"
|
||||||
|
|
||||||
var blueHex = java.lang.Integer.toHexString(blue)
|
var blueHex = Integer.toHexString(blue)
|
||||||
if (blueHex.length == 1 ) blueHex = "0$blueHex"
|
if (blueHex.length == 1 ) blueHex = "0$blueHex"
|
||||||
|
|
||||||
|
|
||||||
val colorString = "#$redHex$greenHex$blueHex"
|
val colorString = "#$redHex$greenHex$blueHex"
|
||||||
|
Log.d("QWERTYUIOP", "$red:$green:$blue")
|
||||||
|
Log.d("QWERTYUIOP", "$redHex-$greenHex-$blueHex")
|
||||||
|
Log.d("QWERTYUIOP", colorString)
|
||||||
return Color.parseColor(colorString)
|
return Color.parseColor(colorString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
fun darkenColor(color: Int, darkPercent: Double) : Int {
|
||||||
|
val c = Color.valueOf(color)
|
||||||
|
|
||||||
|
val red = c.red() * (1 - darkPercent)
|
||||||
|
val green = c.green() * (1 - darkPercent)
|
||||||
|
val blue = c.blue() * (1 - darkPercent)
|
||||||
|
Log.d("QWERTYUIOP", "....A:${c.red()}, ${c.green()}, ${c.blue()}")
|
||||||
|
Log.d("QWERTYUIOP", "....B:${red.toFloat()}, ${green.toFloat()}, ${blue.toFloat()}")
|
||||||
|
|
||||||
|
return Color.rgb(red.toFloat(), green.toFloat(), blue.toFloat())
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -38,7 +38,7 @@
|
||||||
app:layout_constraintBottom_toTopOf="@+id/netWeight"
|
app:layout_constraintBottom_toTopOf="@+id/netWeight"
|
||||||
app:layout_constraintHorizontal_bias="0.5"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
android:visibility="visible" android:hint="@string/product_name_label" android:textColorHint="#737373"
|
android:visibility="visible" android:hint="@string/product_name_label" android:textColorHint="#737373"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/imageView"/>
|
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/barcodeTextEdit"/>
|
||||||
<EditText
|
<EditText
|
||||||
android:layout_width="350dp"
|
android:layout_width="350dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
|
@ -51,6 +51,14 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:visibility="visible" android:hint="@string/netWeight" android:textColorHint="#737373"
|
android:visibility="visible" android:hint="@string/netWeight" android:textColorHint="#737373"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/productName"/>
|
app:layout_constraintTop_toBottomOf="@+id/productName"/>
|
||||||
|
<EditText
|
||||||
|
android:layout_width="350dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="text"
|
||||||
|
android:ems="10"
|
||||||
|
android:id="@+id/barcodeTextEdit" app:layout_constraintTop_toBottomOf="@+id/imageView"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
|
||||||
|
android:layout_marginTop="8dp" android:hint="Barcode" android:textColorHint="#737373"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:text="@string/category"
|
android:text="@string/category"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -63,7 +71,7 @@
|
||||||
android:layout_height="wrap_content" android:id="@+id/categorySpinner"
|
android:layout_height="wrap_content" android:id="@+id/categorySpinner"
|
||||||
app:layout_constraintStart_toEndOf="@+id/categoryTextView"
|
app:layout_constraintStart_toEndOf="@+id/categoryTextView"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/netWeight" android:layout_marginStart="8dp"
|
app:layout_constraintTop_toBottomOf="@+id/netWeight" android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="20dp"/>
|
android:layout_marginTop="18dp"/>
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/saveButton"
|
android:text="@string/saveButton"
|
||||||
android:layout_width="100dp"
|
android:layout_width="100dp"
|
||||||
|
|
|
@ -15,9 +15,4 @@
|
||||||
|
|
||||||
</androidx.gridlayout.widget.GridLayout>
|
</androidx.gridlayout.widget.GridLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" android:id="@+id/storageLayout">
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
Reference in New Issue