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
| /** | |
| * Definition for singly-linked list. | |
| * function ListNode(val, next) { | |
| * this.val = (val===undefined ? 0 : val) | |
| * this.next = (next===undefined ? null : next) | |
| * } | |
| */ | |
| /** | |
| * @param {ListNode} head | |
| * @return {boolean} |
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
| override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
| super.onActivityResult(requestCode, resultCode, data) | |
| when (requestCode) { | |
| REQUEST_SMS_CONSENT -> { | |
| if (resultCode == Activity.RESULT_OK) { | |
| data?.let { | |
| val message = it.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE) | |
| parseMessageForOtp(message) | |
| } | |
| } |
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
| val hintRequest = HintRequest.Builder() | |
| .setPhoneNumberIdentifierSupported(true) | |
| .build() | |
| val credentialsClient = Credentials.getClient(this) | |
| val intent = credentialsClient.getHintPickerIntent(hintRequest) | |
| try { | |
| startIntentSenderForResult( | |
| intent.intentSender, | |
| CREDENTIAL_PICKER_REQUEST, | |
| null, 0, 0, 0 |
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
| val task = SmsRetriever.getClient(this).startSmsUserConsent(null) | |
| task.addOnCompleteListener { | |
| task?.exception?.let { | |
| // handle possible exception | |
| Log.e(TAG, "Task Exception: $it") | |
| return@addOnCompleteListener | |
| } | |
| if (task.isSuccessful) { | |
| val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION) |
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
| class SmsBroadcastReceiver : BroadcastReceiver() { | |
| companion object { | |
| const val TAG = "SmsBroadcastReceiver" | |
| const val REQUEST_SMS_CONSENT = 1001 | |
| } | |
| override fun onReceive(context: Context?, intent: Intent?) { | |
| if (SmsRetriever.SMS_RETRIEVED_ACTION == intent?.action) { | |
| val extras = intent.extras | |
| val smsRetrieverStatus = extras?.get(SmsRetriever.EXTRA_STATUS) as Status |
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
| private val telephonyManager by lazy { | |
| context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager } | |
| // requires Android v26 | |
| // requries CALL_PHONE permission | |
| private fun requestAirtimeBalance(){ | |
| when (telephonyManager.simState) { | |
| Telephony.SIM_STATE_READY -> dialUssdCode() | |
| else -> Unit | |
| } |
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
| class RoomActivity: AppCompatActivity() { | |
| private lateinit var mAdapter: RoomAdapter | |
| private val userManager: UserManager by inject() // koin user injection | |
| override fun onCreate(savedInstance: Bundle?) { | |
| super.onCreate(savedInstance) | |
| mAdapter = RoomAdapter(userManager.currentUser.id) | |
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
| class RoomAdapter(val championId: String) : RecyclerView.Adapter<RoomViewHolder>() { | |
| private var messages = mutableListOf<Message>() | |
| fun addMessage(message: Message) { | |
| messages.add(message) | |
| notifyItemChanged(messages.size - 1) | |
| } | |
| override fun onCreateViewHolder(parent: ViewGroup, layoutResource: Int): RoomViewHolder = |
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
| class RoomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
| fun bind(message: Message, championId: String) { | |
| val layoutParams = itemView.message_root_view.layoutParams as LinearLayoutCompat.LayoutParams | |
| if (message.sender.id == championId) { | |
| layoutParams.gravity = Gravity.END | |
| itemView.message_root_view.layoutParams = layoutParams | |
| } else { |