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
// https://www.reddit.com/r/androiddev/comments/ert88w/asking_if_this_is_possible_to_do_with_maps_api/ | |
fun closestDistance(point:LatLng, route:Polyline) : Double { | |
var minDist = Double.MAX_VALUE | |
for (i in 0 until (route.points?.size ?: 0) - 1) { | |
val dist=lineDistance(point,route.points[i],route.points[i+1]) | |
if (dist<minDist){ | |
minDist=dist | |
} |
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
// https://stackoverflow.com/questions/57752301/dagger2-10-inject-viewmodel-in-fragment-activity-which-has-run-time-dependenci | |
class ProductViewModel( | |
val product: Product, | |
val resourceProvider: ResourceProvider, | |
val appUtils: AppUtils, | |
val alertManager: AlertManager | |
) { | |
// ... | |
} |
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
List<out T> is like List<? extends T> in Java | |
List<in T> is like List<? super T> in Java |
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
// oroginal: | |
// variable?.let { // doStuff } | |
// replacement: | |
inline fun <T:Any, R> whenNotNull(input: T?, callback: (T)->R): R? { | |
return input?.let(callback) | |
} |
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
// One shot operation that returns a value (ie GET, shared prefs)? Single. | |
// One shot operation that returns nothing? (POST) Completable. | |
// One shot operation that might return null (ie fetch from a DB)? Maybe. | |
// An operation that returns multiple objects over time (ie websockets or a list)? Observable. | |
// use Kotlin coroutines? Deferred<T> |
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
// to avoid this situation: https://kinnrot.github.io/live-data-pitfall-you-should-be-aware-of/ | |
fun <T> MutableLiveData<T>.safeSetValue(newValue: T) { if(Thread.currentThread() == Looper.getMainLooper().thread) value = newValue else postValue(newValue) } |
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
public class TextViewOutline extends AppCompatTextView { | |
/* | |
Add to attr.xml: | |
<declare-styleable name="TextViewOutline"> | |
<attr name="outlineSize" format="dimension"/> | |
<attr name="outlineColor" format="color|reference"/> | |
<attr name="android:shadowRadius"/> | |
<attr name="android:shadowDx"/> | |
<attr name="android:shadowDy"/> |
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
@After | |
public void release() { | |
Espresso.unregisterIdlingResources(); | |
} | |
@Test | |
public void buttonShouldUpdateText() { | |
// may put following 3 lines into @BeforeEach annotaded method as well | |
rxEspressoScheduleHandler = new RxEspressoScheduleHandler(); | |
RxJavaPlugins.setScheduleHandler(rxEspressoScheduleHandler); |
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
// https://github.com/ReactiveX/RxJava/issues/1323#issuecomment-45149897 | |
// thank you, akarnokd ! | |
public class ThrottleNotFirst { | |
public static void main(String[] args) throws Exception { | |
for (int firstWait = 0; firstWait < 2; firstWait++) { | |
PublishSubject<String> source = PublishSubject.create(); | |
PublishSubject<Observable<String>> immediates = PublishSubject.create(); |
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
content.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
if ((Build.VERSION.SDK_INT >= 17 && LWQSettingsActivity.this.isDestroyed()) || LWQSettingsActivity.this.isFinishing()) { | |
return; | |
} | |
requestNewInterstitial(); | |
} | |
}, 1000); |