Created
June 9, 2021 18:44
-
-
Save ihfazhillah/ef6d7b1e1f548e4e92eff5ace01b4144 to your computer and use it in GitHub Desktop.
Snippets of my works
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
// observer creation | |
rxObserver = object: RXObserver(){ | |
override fun onInventoryTag(tag: RXInventoryTag?) { | |
val result = tag?.strEPC?.replace(" ", "") | |
if (result != null) { | |
webView?.evaluateJavascript( | |
""" | |
var inputNewRecord = jQuery("#records-rfid") | |
var inputSearch = jQuery("[name='RecordsSearch[rfid]']") | |
var requiredInputs = [inputNewRecord, inputSearch] | |
requiredInputs.forEach(jObj => { | |
if (jObj.length > 0){ | |
jObj.val('$result') | |
} else { | |
console.log("hello world") | |
} | |
}) | |
""".trimIndent(), null | |
) | |
} | |
} | |
override fun onInventoryTagEnd(tagEnd: RXInventoryTag.RXInventoryTagEnd?) { | |
super.onInventoryTagEnd(tagEnd) | |
} | |
} | |
// create connection | |
try { | |
if (connector.connectCom("dev/ttyS4", 115200)){ | |
ModuleManager.newInstance().setUHFStatus(true) | |
try { | |
mReader = RFIDReaderHelper.getDefaultHelper() | |
mReader?.registerObserver(rxObserver) | |
mReader?.setTrigger(true) | |
} catch (e: Exception){ | |
e.printStackTrace() | |
} | |
} else { | |
Log.w(TAG, "RFID Connection failed" ) | |
} | |
} catch (e: Exception){ | |
Log.w(TAG, "Error connection to RFID", e) | |
} | |
// latest webview implementation and my changes to add realTimeInventory mehtod when do in list of records and create records | |
webView?.webViewClient = object : WebViewClient() { | |
override fun onPageFinished(view: WebView?, url: String?) { | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { | |
CookieManager.getInstance().flush(); | |
} else { | |
CookieSyncManager.getInstance().sync(); | |
} | |
endLoaderAnimate() | |
Log.i("url login view activity",url) | |
if(intent.extras !=null && intent.extras!!.containsKey("isFromNotification")){ | |
return; | |
} | |
if(url !=null && url.startsWith("https://herdsafe.com/webUI/")){ | |
if(url.contains("logout")){ | |
clearCookies(this@LoginWebViewActivity) | |
}else if(!url.contains("web/site/login")) | |
{ | |
toolbar11.visibility = GONE | |
val sharedPreference = getSharedPreferences("login", Context.MODE_PRIVATE) | |
sharedPreference.edit().putBoolean("isLogin",true).commit(); | |
}else{ | |
toolbar11.visibility = View.GONE | |
} | |
if (url.contains("web/records/index") || url.contains("web/records/create")) { | |
mReader?.realTimeInventory(0xff.toByte(), 0x01.toByte()) | |
} else { | |
} | |
} | |
//webView.loadUrl("javascript:(window.token='${fcmToken}';alert(window.token) )()") | |
} | |
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean { | |
return super.shouldOverrideUrlLoading(view, request) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Do you have library for this code? Can u help me pls