I could hardly recall an app without scrollable/recylerView element in design.Often, business intend to seek impressions i.e if user has viewed an item or not. Analytics platform like google/firebase analytics is certainly a best bet for this. However, implementing the same could be a challenging when it comes to recylerview.


Debounce for android button clicks via bindingAdapter

@BindingAdapter("android:onClick")
fun setDebounceListener(view: Button, onClickListener: View.OnClickListener) {
val scope = ViewTreeLifecycleOwner.get(view)!!.lifecycleScope
val clickWithDebounce: (view: View) -> Unit =
debounce(scope = scope) {
onClickListener.onClick(it)
}

view.setOnClickListener(clickWithDebounce)
}


fun <T> debounce(
delayMillis: Long = 300L,
scope: CoroutineScope,
action: (T) -> Unit
): (T) -> Unit {
var debounceJob: Job? = null
return { param: T ->
if (debounceJob == null) {
debounceJob = scope.launch {
action(param)
delay(delayMillis)
debounceJob = null
}
}
}
}

Usage :

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{ () -> activity.youOnClickCallbackHere()}"
android:text="Click with debounce" />


Having multiple products flavors in android project can take it toll over build time. Below is the pro tip to force gradle to build only your desired build.

in your app.gradle

android{

….

if (project.rootProject.file('dev.props').exists()) {
def devProps = new Properties()
devProps.load(project.rootProject.file('dev.props').newDataInputStream())
def currentDevFlavor = devProps.DEV_FLAVOR

project.logger.lifecycle('preffered falvour ===>' + currentDevFlavor)

android.variantFilter { variant ->

def flavorName = variant.getFlavors().get(0).name +
variant.getFlavors().get(1).name + buildType.name

project.logger.lifecycle('Variant Flavor Name ==>' + flavorName)

if (currentDevFlavor && (flavorName != currentDevFlavor)) {
project.logger.lifecycle('Ignoring ==>' + flavorName)
variant.setIgnore(true)
} else {
project.logger.lifecycle("Building..===>" + currentDevFlavor)
}
}
}

}

and create one file namely dev.props and add below line to it

DEV_FLAVOR= myappdevdebug //name of your desired build flavour with dimension


File →Invalidate cache is not a solution for every problem especially when it comes to incognito mode errors :P . Errors that won’t show up in android studio.

Why?
There is a limit(or rather i would say default ) enforced by javac compiler to show only 100 errors.

but luckily can be modified by passing an argument to the compiler as mentioned below.

Solution : add this to your top-level build.gradle file.

allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "4000"
options.compilerArgs << "-Xmaxwarns" << "4000"
}
}
}

Enjoy :)


An application architecture is a consistent plan that needs to be made before the development process starts. This plan provides a map of how the different application components should be organized and tied together. It presents guidelines that should be followed during the development process and forces some sacrifices (generally related to more classes and boilerplate) that in the end will help you to construct a well-written application that’s more testable, expandable, and maintainable.

Having said that, I have created an app architecture using android architecture components(ViewModel, LiveData , Room), RetroFit and Dagger2.

GitHub Repo : https://lnkd.in/fAgbMxG

I would look forward for any suggestions and contributions in this repo.

#Android #androiddevelopment #androidstudio #androidsdk #retrofit #dagger2


As you know android tablets/phones comes in variety of shapes and screen densities and accordingly we need to handle image resolutions so as to support all densities and resolution(tablet only in our case for this project).

Having said that, its recommended to create images as per below guidelines.

Android devices…

Balwinder Singh Rajput

Tech Lead |Mobile Apps| Trainer | Certified Scrum Master .GitHub : balwinderSingh1989

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store