https://akabab.github.io/superhero-api
https://rickandmortyapi.com/api/
| { | |
| "uid": "1309SS", | |
| "userType": "single" | |
| } |
| fun launchEmail(activity: FragmentActivity, subject: String, text: String) { | |
| val i = Intent(Intent.ACTION_SEND) | |
| i.type = "message/rfc822" | |
| i.putExtra(Intent.EXTRA_SUBJECT, subject) | |
| i.putExtra(Intent.EXTRA_TEXT, text) | |
| try { | |
| activity.startActivity(Intent.createChooser(i, "Send mail...")) | |
| } catch (ex: android.content.ActivityNotFoundException) { | |
| Toast.makeText(activity, "There are no email clients installed.", Toast.LENGTH_SHORT).show() | |
| } |
| fun Group.addOnClickListener(listener: (view: View) -> Unit) { | |
| referencedIds.forEach { id -> | |
| rootView.findViewById<View>(id).setOnClickListener(listener) | |
| } | |
| } |
| companion object { | |
| var callbackLoadMore: ((Int) -> Unit)? = null | |
| var callbackLikeClick: ((Promotion) -> Unit)? = null | |
| fun forPage(callbackLoadMore: (Int) -> Unit, callbackLikeClick: (Promotion) -> Unit): ShowcasePageOneFragment { | |
| this.callbackLoadMore = callbackLoadMore | |
| this.callbackLikeClick = callbackLikeClick | |
| return ShowcasePageOneFragment() | |
| } | |
| } |
| /** | |
| * A lifecycle-aware observable that sends only new updates after subscription, used for events like | |
| * navigation and Snackbar messages. | |
| * | |
| * | |
| * This avoids a common problem with events: on configuration change (like rotation) an update | |
| * can be emitted if the observer is active. This LiveData only calls the observable if there's an | |
| * explicit call to setValue() or call(). | |
| * | |
| * |
| const val CARD_NUMBER_SEPARATOR = " " | |
| const val CARD_DATE_SEPARATOR = "/" | |
| fun EditText.creditCardNumberFormatter(afterTextChanged: (String) -> Unit) { | |
| var count = 0 | |
| this.addTextChangedListener(object : TextWatcher { | |
| override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { | |
| } |
| class LuhnValidator { | |
| fun isValid(cardNumber: String): Boolean { | |
| var s1 = 0 | |
| var s2 = 0 | |
| val reverse = StringBuffer(cardNumber).reverse().toString() | |
| for (i in reverse.indices) { | |
| val digit = Character.digit(reverse[i], 10) | |
| when { | |
| i % 2 == 0 -> s1 += digit | |
| else -> { |
| /** A viewpager with possibilities of being blocked the swipe */ | |
| class BViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) { | |
| private var enabledSwipe: Boolean = false | |
| init { | |
| this.enabledSwipe = true | |
| } | |
| override fun onTouchEvent(event: MotionEvent): Boolean = when { |