Skip to content

Commit

Permalink
Remove barcode reader
Browse files Browse the repository at this point in the history
  • Loading branch information
AIDEA775 committed May 21, 2023
1 parent b0ca4fb commit 54c5de6
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 288 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

// Database
def room_version = "2.4.3"
Expand All @@ -80,7 +81,6 @@ dependencies {

// Charts
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'

// Parse HTML
implementation("org.jsoup:jsoup:1.14.3")
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCSp9NAfXyfp4RTPawVvfYcS_tZaWoXA_g" />

<activity
android:name=".balance.BarcodeActivity"
android:screenOrientation="landscape"
android:theme="@style/AppTheme.NoActionBar">
</activity>

<receiver android:name=".reservations.AlarmReceiver" />
<receiver android:name=".reservations.BootReceiver"
android:enabled="false"
Expand Down
16 changes: 2 additions & 14 deletions app/src/main/java/com/uncmorfi/balance/BalanceFragment.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.uncmorfi.balance

import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.zxing.integration.android.IntentIntegrator
import com.uncmorfi.MainViewModel
import com.uncmorfi.R
import com.uncmorfi.balance.dialogs.UserOptionsDialog
Expand Down Expand Up @@ -50,11 +48,9 @@ class BalanceFragment : Fragment() {

initRecyclerAndAdapter()

newUser.init(this) { code ->
newUser.onDone { code ->
activity?.hideKeyboard()
if (code.isNotBlank()) {
updateCards(parseCards(code))
}
updateCards(parseCards(code))
}

observe(viewModel.status) {
Expand Down Expand Up @@ -124,14 +120,6 @@ class BalanceFragment : Fragment() {
}
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if (result != null && result.contents != null) {
updateCards(parseCards(result.contents))
}
}

private fun parseCards(cards: String): List<String> {
return cards.split("\\s+".toRegex())
}
Expand Down
95 changes: 0 additions & 95 deletions app/src/main/java/com/uncmorfi/balance/BarcodeActivity.kt

This file was deleted.

49 changes: 9 additions & 40 deletions app/src/main/java/com/uncmorfi/balance/NewUserView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.inputmethod.EditorInfo
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import com.google.zxing.integration.android.IntentIntegrator
import com.uncmorfi.R
import com.uncmorfi.shared.invisible
import com.uncmorfi.shared.onTextChanged
import kotlinx.android.synthetic.main.view_user_new.view.*

Expand All @@ -19,7 +18,6 @@ class NewUserView @JvmOverloads constructor(
) : LinearLayout(context, attr, defStyleAttr) {

private lateinit var doneListener: (String) -> Unit
private lateinit var scannerListener: Fragment

init {
LayoutInflater.from(context).inflate(R.layout.view_user_new, this, true)
Expand All @@ -32,50 +30,21 @@ class NewUserView @JvmOverloads constructor(
false
}

newUserInput.onTextChanged { onTextChanged(it) }

// Por defecto llama al lector
newUserScanner.setOnClickListener { onScanner() }
}

private fun onTextChanged(s: CharSequence) {
newUserScanner.apply {
if (s.isNotEmpty()) {
// Cuando hay texto, cambia la función del botón por newUser.
setImageResource(R.drawable.ic_done)
contentDescription = context.getString(R.string.balance_new_user_button_enter)
setOnClickListener {
onDone()
}
} else {
// Si es está vacio, llama al lector.
setImageResource(R.drawable.ic_barcode)
contentDescription = context.getString(R.string.balance_new_user_button_code)
setOnClickListener {

}
}
newUserInput.onTextChanged {
newUserDone.invisible(it.isBlank())
}

newUserDone.invisible(true)
newUserDone.contentDescription = context.getString(R.string.balance_new_user_button_enter)
newUserDone.setOnClickListener { onDone() }
}

private fun onDone() {
val input = newUserInput.text.toString()
val input = newUserInput.text.toString().trim()
doneListener(input)
}

// Inicia el lector de barras.
// Devuelve el resultado por scannerListener.onActivityResult.
private fun onScanner() {
val integrator = IntentIntegrator.forSupportFragment(scannerListener)
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES)
integrator.setPrompt(context.getString(R.string.balance_align_barcode))
integrator.setBeepEnabled(false)
integrator.setBarcodeImageEnabled(true)
integrator.initiateScan()
}

fun init(f: Fragment, l: (String) -> Unit) {
scannerListener = f
fun onDone(l: (String) -> Unit) {
doneListener = l
}

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/drawable/ic_access_time.xml

This file was deleted.

10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M18,13h-5v5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1v-5H6c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1h5V6c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v5h5c0.55,0 1,0.45 1,1s-0.45,1 -1,1z"/>
</vector>
8 changes: 0 additions & 8 deletions app/src/main/res/drawable/ic_barcode.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/drawable/ic_done.xml

This file was deleted.

86 changes: 0 additions & 86 deletions app/src/main/res/layout/activity_barcode.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_user_new.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
android:importantForAutofill="no" />

<ImageButton
android:id="@+id/newUserScanner"
android:id="@+id/newUserDone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackgroundBorderless"
android:maxLines="1"
android:padding="16dp"
android:src="@drawable/ic_barcode"
android:src="@drawable/ic_add"
android:contentDescription="@string/balance_new_user_button_code" />

</merge>
Loading

0 comments on commit 54c5de6

Please sign in to comment.