Skip to content

Instantly share code, notes, and snippets.

view.setOnTouchListener { _, event ->
val x = event.x.toInt() + 200
val y = event.y.toInt()
if (pickMode != 5 && event.action == ACTION_DOWN) {
viewModel.products.observeOnce(viewLifecycleOwner) { products ->
products.forEach {
if (it.rectName?.contains(x, y) == true && it.isVisible) {
findNavController().navigate(
R.id.action_pickFragment_to_productFragment,
bundleOf(PRODUCT_ID to it.id.toString())
class BarcodeGraphic internal constructor(
overlay: GraphicOverlay<*>?,
private val viewModel: PickCompleteViewModel?,
private val lifecycleOwner: LifecycleOwner
) : Graphic(overlay!!) {
var id = 0
private val rectPaint = Paint().apply {
color = GREEN
style = Paint.Style.FILL
class PickCompleteViewModel(
private val repository: ApiRepository,
private val preferences: SharedPreferences
) : ViewModel() {
val response = MutableLiveData<ResponseMessage>()
val error = MutableLiveData<String>()
val products = MutableLiveData<MutableSet<Product>>()
val currentProduct = MutableLiveData<PickProduct>()
val sentSuccess = MutableLiveData<Boolean>()
<LinearLayout
android:id="@+id/top_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:orientation="vertical">
<team.marker.util.camera.CameraSourcePreview
android:id="@+id/preview"
android:layout_width="match_parent"
class CameraSourcePreview(
private val mContext: Context,
attrs: AttributeSet?
) : ViewGroup(mContext, attrs) {
private val mSurfaceView: SurfaceView = SurfaceView(mContext)
private var mStartRequested = false
private var mSurfaceAvailable = false
private var mCameraSource: CameraSource? = null
private var mOverlay: GraphicOverlay<*>? = null
class GraphicOverlay<T : Graphic?>(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
private val mLock = Any()
private var mPreviewWidth = 0
/**
* Returns the horizontal scale factor.
*/
var widthScaleFactor = 1.0f
private set
private var mPreviewHeight = 0
fun validMountainArray(arr: IntArray): Boolean {
if (arr.size < 3 || arr[0] > arr[1]) return false
var ascend = true
for (i in 1 until arr.size) {
if (arr[i - 1] == arr[i]) return false
if (ascend) {
if (arr[i - 1] > arr[i]) ascend = false
} else {
if (arr[i - 1] < arr[i]) return false
}
public boolean validMountainArray(int[] arr) {
if (arr.length < 3 || arr[0] > arr[1]) return false;
boolean ascend = true;
for (int i = 1; i < arr.length; i++) {
if (arr[i - 1] == arr[i]) return false;
if (ascend) {
if (arr[i - 1] > arr[i]) ascend = false;
} else {
if (arr[i - 1] < arr[i]) return false;
}
fun countSubstrings(s: String): Int {
var c = 0
for (i in s.indices) {
val sb = StringBuilder()
for (j in i until s.length) if (isPal(sb.append(s[j]).toString())) c++
}
return c
}
fun countSubstrings(s: String): Int {
var c = 0
for (i in s.indices) {
val sb = StringBuilder()
for (j in i until s.length) if (sb.append(s[j]).toString() == sb.toString().reversed()) c++
}
return c
}