Log.v(“ThreeTips”, “#10”)

1- Dagger 2 : Multiple Dependencies, Child Dependencies, explained.

We all have singleton objects in our application lifetime. ApiSource, DataSource, PreferenceHelpers, so on. We declare them as @Singleton in our AppModule.class. We also need to use scopes in our application to control our objects’ scope. If we want one object only in Activity lifetime, we create an @Activity scope and use this in our ActivityComponent as class annotation and ActivityModule as method annotation. Components can share their object with dependent components using dependencies key.

@Singleton
@Component(modules = AppModule.class)
public interface AppComponent {
//Dependent components can use this objects

ApiSource apiSource();
Gson gson();
RxBus bus();
}
@Activity
@Component(dependencies = AppComponent.class, modules = MainActivityModule.class)
public interface MainActivityComponent{
void inject(MainActivity activity);

}

2- Change textStyle using Databinding

If you want to change your textStyle in your xml using databinding library, You need to create binding adapter for it. I thought that textStyle takes an integer as parameter so I could give an integer value using databinding library. But you can not do that. So following is not possible;

public ObservableField<Integer> textStyle;
textStyle = new ObservableField<>(TypeFace.BOLD)
<TextView
android:id="@+id/textViewConversationName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="@{viewModel.textStyle}" />
public class BindingTextUtils {

@BindingAdapter({"bind:textStyle"})
public static void setTypeface(TextView v, String style) {
switch (style) {
case "bold":
v.setTypeface(null, Typeface.BOLD);
break;
default:
v.setTypeface(null, Typeface.NORMAL);
break;
}
}
}
public ObservableField<String> textStyle;
textStyle = new ObservableField<>("bold")
<TextView
android:id="@+id/textViewConversationName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:textStyle="@{viewModel.textStyle}" />

3- Be careful using animateLayoutChanges

If you have an animation in your View Component like ;

private void animateIt(View viewRoot) {
Animator anim = ...
viewRoot.setVisibility(View.VISIBLE);
anim.setDuration(300);
anim.setInterpolator(new AccelerateInterpolator());
anim.start();
}
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
....</RelativeLayout>

Software Engineer at Storytel