This file contains 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
public final class ActivityAwesomeBinding implements ViewBinding { | |
... | |
@NonNull | |
public final IncludedButtonsBinding includes; |
This file contains 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
@NonNull | |
public static ActivityAwesomeBinding bind(@NonNull View rootView) { | |
/* Edit: Simplified code – the real generated code is an optimized version */ | |
Button button = rootView.findViewById(R.id.button); | |
TextView subtext = rootView.findViewById(R.id.subtext); | |
TextView title = rootView.findViewById(R.id.title); | |
if (button != null && subtext != null && title != null) { | |
return new ActivityAwesomeBinding((ConstraintLayout) rootView, button, subtext, title); | |
} | |
throw new NullPointerException("Missing required view […]"); |
This file contains 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 ActivityAwesomeBinding(@NonNull ConstraintLayout rootView, @NonNull Button button, | |
@NonNull TextView subtext, @NonNull TextView title) { … } | |
@NonNull | |
public static ActivityAwesomeBinding inflate(@NonNull LayoutInflater inflater) { | |
/* Edited: removed call to overload inflate(inflater, parent, attachToParent) */ | |
View root = inflater.inflate(R.layout.activity_awesome, null, false); | |
return bind(root); | |
} |
This file contains 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
public final class ActivityAwesomeBinding implements ViewBinding { | |
@NonNull | |
private final ConstraintLayout rootView; | |
@NonNull | |
public final Button button; | |
@NonNull | |
public final TextView subtext; | |
@NonNull | |
public final TextView title; |
This file contains 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
public final class ActivityAwesomeBinding implements ViewBinding { | |
@NonNull | |
private final ConstraintLayout rootView; | |
@NonNull | |
public final Button button; | |
@NonNull | |
public final TextView subtext; |
This file contains 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
// Using view binding in an Activity | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val binding = ActivityAwesomeBinding.inflate(layoutInflater) | |
binding.title.text = "Hello" | |
binding.subtext.text = "Concise, safe code" | |
binding.button.setOnClickListener { /* ... */ } | |
setContentView(binding.root) |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".AwesomeActivity"> | |
<Button |
This file contains 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
#!/usr/bin/env python | |
from collections import namedtuple | |
CoC = 0.018 # canon APS-C | |
MIN_DISTANCE = 100 # must focus 300mm away | |
MAX_DISTANCE = 1 * 1000 * 1000 # must focus one KM away | |
FOCALS = [1.3 + (x/10.0) for x in xrange(1, 40 * 10)] | |
FOCUS_DISTANCE = [100 * x for x in xrange(1, 10)] |
This file contains 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
// see the complete implementation at | |
// https://gist.github.com/objcode/7ab4e7b1df8acd88696cb0ccecad16f7#file-concurrencyhelpers-kt-L124 | |
suspend fun joinPreviousOrRun(block: suspend () -> T): T { | |
// if there is an activeTask, return it's result and don't run the block | |
activeTask?.let { | |
return it.await() | |
} | |
// ... |
This file contains 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 ProductsRepository(val productsDao: ProductsDao, val productsApi: ProductsService) { | |
var controlledRunner = ControlledRunner<List<ProductListing>>() | |
suspend fun fetchProductsFromBackend(): List<ProductListing> { | |
// if there's already a request running, return the result from the | |
// existing request. If not, start a new request by running the block. | |
return controlledRunner.joinPreviousOrRun { | |
val result = productsApi.getProducts() | |
productsDao.insertAll(result) | |
result |