Skip to content

Instantly share code, notes, and snippets.

View muthuraj57's full-sized avatar

Muthuraj muthuraj57

View GitHub Profile
abstract class RecyclerBaseAdapter : RecyclerView.Adapter<RecyclerViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
RecyclerViewHolder(DataBindingUtil.inflate<ViewDataBinding>(LayoutInflater.from(parent.context), viewType, parent, false))
override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {
getViewModel(position)
?.let {
val bindingSuccess = holder.binding.setVariable(BR.viewModel, it)
if (!bindingSuccess) {
/*
* Base RecyclerView ViewHolder
* */
open class RecyclerViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root)
class ExampleAdapter(
private val context: Context,
private val isAlternate: Boolean,
private val data: List<String>
) : RecyclerBaseAdapter() {
override fun getLayoutIdForPosition(position: Int) = R.layout.recycler_view_item
override fun getViewModel(position: Int) = ListItemViewModel(data[position])
override fun getItemCount() = data.size
import android.support.annotation.CallSuper
open class BaseViewModel{
protected val compositeDisposable = CompositeDisposable()
fun onAttach(){}
@CallSuper
fun onDetach(){
/*
* ViewModel variable name must be {{viewModel}}.
*
* Binds the viewModel to the DataBinding and clears the observable subscription
* on view detached from window.
* */
fun <T : ViewDataBinding, V : BaseViewModel> T.bindViewModel(viewModel: V): Boolean {
val bindSuccess = setVariable(BR.viewModel, viewModel)
if (bindSuccess) {
root.onAttachStateChanged(
public class SplashActivity extends AppCompatActivity {
private static final int REQ_CODE = 23;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
if (shouldFinishActivity()) {
return;
do shell script "/Users/user-name/Library/Android/sdk/platform-tools/adb pull sdcard/Android/data/com.example.test/files/ /Users/user-name/Desktop/"
tell application "Finder" to open POSIX file "/Users/user-name/Desktop/files/sqlite/db_name.db"
@muthuraj57
muthuraj57 / JavaClass.java
Last active April 25, 2019 10:17
Kotlin Basics
package com.muthuraj.kotlinBasics.kotlinbasics;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
class ProgressResponseBody(
private val uniqueId: String,
private val delegate: ResponseBody
) : ResponseBody() {
private val progressPublisher: MutableStateFlow<Progress>?
init {
addProgressPublisher(uniqueId)
progressPublisher = progressPublishers[uniqueId]
@muthuraj57
muthuraj57 / pre-commit
Created July 20, 2021 06:36
Pre commit hook to apply Spotless for the changes files in staging area.
#!/bin/bash
set -e
# Ref: https://blog.jdriven.com/2020/11/formatting-in-pre-commit-hook/
# command taken from https://github.com/JLLeitschuh/ktlint-gradle task addKtlintFormatGitPreCommitHook
filesToFormat="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.java|\.kt/ { print $2}')"
echo "files to format $filesToFormat"
for sourceFilePath in $filesToFormat; do