Skip to content

Instantly share code, notes, and snippets.

View slavkoder's full-sized avatar

Slava Ukrayini slavkoder

View GitHub Profile
@slavkoder
slavkoder / Convention.kt
Created August 19, 2019 22:16
An example of defining kotlin sealed classes
// Good example - Do!
sealed class GoodExample
class AwesomeSubclass : GoodExample()
object WorksToo : GoodExample()
// ! Bad example - do NOT do
sealed class BadExample {
class PrettyBadSubclass : BadExample()
object NotOkay : BadExample()
import androidx.recyclerview.widget.RecyclerView;
public class RecyclerViewSwipeListener extends RecyclerView.OnFlingListener {
private static final int SWIPE_VELOCITY_THRESHOLD = 2000;
boolean mIsScrollingVertically;
// change swipe listener depending on whether we are scanning items horizontally or vertically
RecyclerViewSwipeListener(boolean vertical) {
@slavkoder
slavkoder / CaptureFragment.java
Created July 11, 2019 04:43
A snippet demonstrating uploading an image and posting to Parse.
final String description = "";
// Create ParseFile to save image from camera on Parse backend
final ParseFile imageFile = new ParseFile(photoFile);
// make an async call to save image on backend
imageFile.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
// if upload is successful let's create and save post
final Post post = new Post();
@slavkoder
slavkoder / NativeAdUnitView.kt
Created March 15, 2019 00:39
Example of inner class
class FindViewHolder(val parent: View) {
val adunitTitle: TextView = parent.findViewById(R.id.adunitTitle)
val companyText: TextView = parent.findViewById(R.id.companyText)
val companyLogo: ImageView = parent.findViewById(R.id.companyLogo)
val unifiedNativeAdView: UnifiedNativeAdView = parent.findViewById(R.id.unifiedNativeAdView)
val mediaView: MediaView = parent.findViewById(R.id.mediaView)
val textWrapper: View = parent.findViewById(R.id.textWrapper)
}
private val vh: FindViewHolder
@slavkoder
slavkoder / PR_template.md
Last active December 27, 2018 18:27
A template for PR that helps to tell a story and focus on important changes

Resolves Ticket

Post merge

Why this change is needed?

What has changed in this PR?

What are trade-offs or considered alternatives?

@slavkoder
slavkoder / ApptimizeBivariantTestFeature.kt
Created August 17, 2018 19:26
Add onErrorResumeNext
class ApptimizeBivariantTestFeature(private val experimentTag: String) : IFeature {
override fun isEnabled(): Single<Boolean> {
return Single.create<Boolean> { emitter: SingleEmitter<Boolean> ->
Apptimize.runTest(experimentTag, object : ApptimizeTest() {
override fun baseline() {
// Variant: control, treat as disabled
emitter.onSuccess(false)
}
@Suppress("unused")
@slavkoder
slavkoder / DebugBillingActivity.kt
Created June 19, 2018 00:34
Add handling for touch outside billing window.
override fun onCreate(savedInstanceState: Bundle?) {
// ...
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL)
window.addFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH)
}
override fun onBackPressed() {
broadcastUserCanceled()
super.onBackPressed()
}
@slavkoder
slavkoder / DebugBillingClient.kt
Created June 18, 2018 23:56
Fix crash in DebugBillingClient when billing returns error/empty result.
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// Receiving the result from local broadcast and triggering a callback on listener.
@BillingResponse
val responseCode = intent?.getIntExtra(DebugBillingActivity.RESPONSE_CODE, BillingResponse.ERROR)
?: BillingResponse.ERROR
var purchases: List<Purchase>? = null
if (responseCode == BillingResponse.OK) {
val resultData = intent?.getBundleExtra(DebugBillingActivity.RESPONSE_BUNDLE)
@slavkoder
slavkoder / DebugBillingActivity.kt
Created June 18, 2018 23:53
Add back button handler with response USER_CANCELED.
override fun onBackPressed() {
broadcastResult(BillingResponse.USER_CANCELED, Bundle())
super.onBackPressed()
}
@slavkoder
slavkoder / success.json
Created April 27, 2018 02:10
Quizlet username checker successful response
{
"data": {
"checkUsername": {
"success": true,
"suggestions": [
"username6303",
"greatusername6303"
]
}
}