This file contains 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
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) { |
This file contains 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
/* | |
* Base RecyclerView ViewHolder | |
* */ | |
open class RecyclerViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) |
This file contains 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
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 |
This file contains 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
import android.support.annotation.CallSuper | |
open class BaseViewModel{ | |
protected val compositeDisposable = CompositeDisposable() | |
fun onAttach(){} | |
@CallSuper | |
fun onDetach(){ |
This file contains 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
/* | |
* 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( |
This file contains 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 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; |
This file contains 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
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" |
This file contains 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
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; |
This file contains 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
class ProgressResponseBody( | |
private val uniqueId: String, | |
private val delegate: ResponseBody | |
) : ResponseBody() { | |
private val progressPublisher: MutableStateFlow<Progress>? | |
init { | |
addProgressPublisher(uniqueId) | |
progressPublisher = progressPublishers[uniqueId] |
This file contains 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
#!/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 |