Created
August 16, 2018 07:12
-
-
Save aohua/3e0037effdb76eb98f79fa2f40fc41fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.axinan.samwise | |
import android.app.ProgressDialog | |
import android.content.BroadcastReceiver | |
import android.content.Context | |
import android.content.Intent | |
import android.content.IntentFilter | |
import android.support.v7.app.AppCompatActivity | |
import android.os.Bundle | |
import android.support.v7.widget.LinearLayoutManager | |
import android.util.Log | |
import android.widget.Toast | |
import com.axinan.samwise.data.API | |
import com.axinan.samwise.data.model.ReturnProduct | |
import kotlinx.android.synthetic.main.activity_multiple_items.* | |
import retrofit2.Call | |
import retrofit2.Callback | |
import java.text.FieldPosition | |
class MultipleItemsActivity : AppCompatActivity() { | |
private var scanner: ScannerInterface = ScannerInterface(this) | |
private var intentFilter: IntentFilter = IntentFilter() | |
private var scanReceiver: BroadcastReceiver = ScannerResultReceiver() | |
private val api: API = API() | |
private var itemList: ArrayList<ReturnProduct> = ArrayList() | |
private var scanningItem: DataHolder.ScanningItemPosition? = DataHolder.ScanningItemPosition(null) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_multiple_items) | |
actionBar?.setDisplayHomeAsUpEnabled(true) | |
itemList = intent.getParcelableArrayListExtra<ReturnProduct>("products") | |
stockInItems?.setHasFixedSize(false) | |
stockInItems?.layoutManager = LinearLayoutManager(this) | |
// init scanner | |
initScanner() | |
stockInItems.adapter = ItemListAdapter(itemList, "scanItem", scanner, scanningItem, this) | |
Toast.makeText(this, itemList[0].axinanId.toString(), Toast.LENGTH_SHORT).show() | |
} | |
private fun initScanner() { | |
scanner.resultScan() | |
scanner.enablePlayBeep(true) | |
scanner.enableFailurePlayBeep(true) | |
scanner.enableAddKeyValue(1) | |
scanner.setOutputMode(1) | |
scanner.lockScanKey() | |
intentFilter = IntentFilter(RES_ACTION) | |
scanReceiver = ScannerResultReceiver() | |
registerReceiver(scanReceiver, intentFilter) | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
finishScanner() | |
} | |
private fun finishScanner() { | |
scanner.scan_stop() | |
unregisterReceiver(scanReceiver) | |
} | |
private inner class ScannerResultReceiver : BroadcastReceiver() { | |
override | |
fun onReceive(context: Context, intent: Intent) { | |
if (intent.getAction().equals(RES_ACTION)) { | |
DisplayProgressDialog() | |
val scanResult = intent.getStringExtra("value") | |
itemList[scanningItem!!.position!!].axinanId = scanResult | |
stockInItems.adapter.notifyItemChanged(scanningItem!!.position!!) | |
} | |
} | |
lateinit var pDialog: ProgressDialog | |
fun DisplayProgressDialog() { | |
pDialog = ProgressDialog(this@MultipleItemsActivity) | |
pDialog!!.setMessage("Loading..") | |
pDialog!!.setCancelable(false) | |
pDialog!!.isIndeterminate = false | |
pDialog!!.show() | |
} | |
} | |
companion object { | |
private val RES_ACTION = "android.intent.action.SCANRESULT" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
notify list changes