Skip to content

Instantly share code, notes, and snippets.

View dmytrodanylyk's full-sized avatar

Dmytro Danylyk dmytrodanylyk

View GitHub Profile
@dmytrodanylyk
dmytrodanylyk / res_color_btn_flat_selector.xml
Last active March 4, 2023 07:52
Material Flat Button Style
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:color="@color/flat_disabled_text"/>
<item android:color="@color/flat_normal_text"/>
</selector>
@dmytrodanylyk
dmytrodanylyk / ErrorLabelLayout.java
Created January 21, 2015 15:35
Android Error Label
public class ErrorLabelLayout extends LinearLayout implements ViewGroup.OnHierarchyChangeListener {
private static final int ERROR_LABEL_TEXT_SIZE = 12;
private static final int ERROR_LABEL_PADDING = 4;
private TextView mErrorLabel;
private Drawable mDrawable;
private int mErrorColor;
public ErrorLabelLayout(Context context) {
@dmytrodanylyk
dmytrodanylyk / description.md
Last active June 20, 2022 15:00
Where this dependency comes from?

Did you ever have android build failed​ issue because of dependency resolution?

… or you were curious where all these old rxjava dependencies come from?

You can pretty easy track the module causing issues via following gradle command.

gradlew :root-module:dependencyInsight \
--configuration debugRuntimeClasspath \ // or debugCompileClasspath
--dependency io.reactivex:rxjava:1.1.0 &gt; dependencies.txt // saves result to 'dependencies.txt' file
Android Volley
@dmytrodanylyk
dmytrodanylyk / Test1.java
Last active March 6, 2018 12:57
Realm test
// Test 1
for (int i = 0; i < 10; i++) {
// spawn new thread which call queryNoTransaction()
}
void queryNoTransaction() {
try (Realm realm = Realm.getDefaultInstance()) {
long start = System.currentTimeMillis();
RealmResults<UserProfile> users = realm.where(UserProfile.class).findAll();
List<UserProfile> userCopy = realm.copyFromRealm(users);
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutineVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutineVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutineVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutineVersion"
@Test
fun test() {
val dataProvider = Mockito.mock(DataProviderAPI::class.java)
val mockView = Mockito.mock(MainView::class.java)
val presenter = MainPresenter(mockView, dataProvider, Unconfined, Unconfined)
presenter.startPresenting()
...
}
private fun loadData() = launch(uiContext) {
view.showLoading() // ui thread
// non ui thread, suspend until task is finished
val result1 = async(bgContext) { dataProvider.loadData("Task 1") }.await()
// non ui thread, suspend until task is finished
val result2 = async(bgContext) { dataProvider.loadData("Task 2") }.await()
val result = "$result1 $result2" // ui thread
private fun loadData() = launch(uiContext) {
view.showLoading() // ui thread
val task = async(bgContext) { dataProvider.loadData("Task") }
val result = task.await() // non ui thread, suspend until finished
view.showData(result) // ui thread
}