Skip to content

Instantly share code, notes, and snippets.

View thenishchalraj's full-sized avatar
Time Travelling Ambidextrous Researcher

Nishchal Raj thenishchalraj

Time Travelling Ambidextrous Researcher
View GitHub Profile
@thenishchalraj
thenishchalraj / TextWatcherForInputBox.kt
Created August 15, 2022 10:24
Text watcher that will take care of input fields in CreateInputFieldsInInputBox.kt
private fun setTextWatcher(editText: EditText?) {
editText?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.toString() != "") {
mTextMap[editText.id] = TextMapModel(s.toString(), editText)
val indexOfNext = mTextIdArray.indexOf(editText.id) + 1
@thenishchalraj
thenishchalraj / CreateInputFieldsInInputBox.kt
Last active September 8, 2022 13:22
Function to create input fields inside flexbox dynamically.
private val mTextMap: HashMap<Int, TextMapModel> = HashMap()
private val mTextIdArray: ArrayList<Int> = ArrayList()
private fun createInputFieldsInInputBox(actualText: String) {
val textLength = actualText.length
val flexboxLayout = mBinding.flexboxLayoutInput
flexboxLayout.flexDirection = FlexDirection.ROW
val filterArray = arrayOfNulls<InputFilter>(1)
filterArray[0] = InputFilter.LengthFilter(1)
@thenishchalraj
thenishchalraj / InstagramLiveAgoraSocket.java
Created May 12, 2021 14:59
Sample java class file to show the main code needed to create Instagram LIVE using Agora SDK and socket.io (Note: not everything for view is included but only the agora and socket snippet)
public class InstagramLiveAgoraSocket extends AppCompatActivity {
private static final int PERMISSION_REQ_ID = 22;
// Permission WRITE_EXTERNAL_STORAGE is not mandatory
// for Agora RTC SDK, just in case if you wanna save
// logs to external sdcard.
private static final String[] REQUESTED_PERMISSIONS = {
Manifest.permission.RECORD_AUDIO,
Manifest.permission.CAMERA,
@thenishchalraj
thenishchalraj / JavaStripeIntegrationCodeSnippet.java
Created April 25, 2021 13:56
Just the main functions calling the stripe's card dialog and fetching data when positive response from the user i.e. OK clicked in Java.
Dialog addCardDialog;
private void onAddCardButtonClicked() {
/*
below is kind of custom dialog
i.e. stripe widget is inside a card view and custom buttons
but the basic idea remains same
*/
addCardDialog = new Dialog(context, R.style.AppTheme_NoTitleBar_Main);
addCardDialog.setContentView(R.layout.dialog_add_card);
TextView addCard = addCardDialog.findViewById(R.id.addCard);
@thenishchalraj
thenishchalraj / KotlinStripeIntegrationCodeSnippet.kt
Last active April 25, 2021 14:28
Just the main functions calling the stripe's card dialog and fetching data when positive response from the user i.e. OK clicked in Kotlin.
private fun onAddCardButtonClicked() {
mBinding.buttonAddCard.setOnClickListener {
val view = layoutInflater.inflate(R.layout.dialog_add_card, null)
val cardInputWidget: CardInputWidget = view.findViewById(R.id.widget_add_card)
AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.add_card))
.setView(view)
.setPositiveButton(getString(R.string.yes)) { dialog, _ ->
try {
val paymentMethodCreateParams =
@thenishchalraj
thenishchalraj / ReactNativeStripeIntegration.js
Last active April 25, 2021 14:28
A react native component that shows integration of stripe (tipsi-stripe) consists of a dialog that shows up when a button is clicked.
import React from 'react'
import { View, Text, TouchableOpacity } from 'react-native'
import stripe from 'tipsi-stripe'
const YourCard = () => {
// initialize stripe
stripe.setOptions({
publishableKey: 'pk_test_publishableUniqueKey'
})
@thenishchalraj
thenishchalraj / BaseApplication.kt
Created March 30, 2021 16:38
[Kotlin](used dagger) MessagingServices extends FirebaseMessageService to get the FCM Device Token when the app is installed for the first time.
class BaseApplication: DaggerApplication() {
@Inject
lateinit var mSharedPrefs: SharedPreferences
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.factory().create(this)
}
override fun onCreate() {
@thenishchalraj
thenishchalraj / MessagingServices.java
Created March 30, 2021 16:31
[Java] MessagingServices extends FirebaseMessageService to get the FCM Device Token when the app is installed for the first time.
public class MessagingServices extends FirebaseMessagingService {
public MessagingServices() {
FirebaseInstallations.getInstance().getId().addOnCompleteListener(
task -> {
if (task.isSuccessful()) {
String token = task.getResult();
Log.i("token ---->>", token);
// store the token in shared preferences
@thenishchalraj
thenishchalraj / HyperLogsSample.kt
Created June 7, 2020 05:59
Basic code snippet for implementing HyperLogs using Kotlin in android
HyperLog.initialize(this)
HyperLog.setLogLevel(Log.VERBOSE)
HyperLog.d("Test logs","Debug Log")
HyperLog.setURL("https://xxxxxxx0xxxxx.x.pipedream.net/")
HyperLog.pushLogs(this, false, object: HLCallback() {
override fun onSuccess(response: Any) {
//Handle success
@thenishchalraj
thenishchalraj / ParseClickableLinksKotlin.kt
Last active January 21, 2021 07:02
Code snippet for the sample of parsing long dynamic text into clickable links, if any available, using Spannable and Matcher with Kotlin in Android
private val urlPattern: Pattern = Pattern.compile(
"(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)"
+ "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
+ "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)",
Pattern.CASE_INSENSITIVE or Pattern.MULTILINE or Pattern.DOTALL
)
private fun clickableLink{
try {
val str = SpannableString(longText)