Skip to content

Instantly share code, notes, and snippets.

Working from home


Working from home
View GitHub Profile
macsystems / ViewDebounceClickListenerExt.kt
Created Jan 28, 2020
Debounce Click Listener Extension which prevents user invoking some function to often
View ViewDebounceClickListenerExt.kt
private const val defaultDebounce: Long = 500
* Prevents that the click events gets called too often by fast clicking user
fun View.setDebounceOnClickListener(@IntRange(from = 0, to = Integer.MAX_VALUE.toLong()) debounceTime: Long = defaultDebounce, listener: (View) -> Unit) {
this.setOnClickListener(object : View.OnClickListener {
private var lastClickTime: Long = 0
override fun onClick(v: View) {
macsystems / ProgressBarExt.kt
Last active Jan 22, 2020
Using sealed class to change progressbar visibility
View ProgressBarExt.kt
fun ProgressBar.handleState(resource: Resource<Any>) {
visibility = when (resource) {
is Loading -> View.VISIBLE
is Error -> View.GONE
is Success -> View.GONE
macsystems / BottomSheetExt.kt
Created Jan 19, 2020
Extension for BottomSheet.BottomSheetBehavior which invokes an function when sheet is collapsed, this can be useful is the sheet need to display new data
View BottomSheetExt.kt
* Call to populate new data for Bottomsheet.
* If Bottomsheet is shown it will collapse first, then it will invoke doWhenCollapsed
inline fun <reified T : View> BottomSheetBehavior<T>.colapseAndShow(noinline doWhenCollapsed: () -> Unit) {
when (state) {
addBottomSheetCallback(WaitForCollapsedState(this, doWhenCollapsed))
macsystems / IntentExt.kt
Created Dec 1, 2019
write any type in an Intent
View IntentExt.kt
fun Intent.putAnyExtra(name: String, value: Any) {
when (value) {
is Int -> putExtra(name, value)
is Byte -> putExtra(name, value)
is Short -> putExtra(name, value)
is Long -> putExtra(name, value)
is Char -> putExtra(name, value)
is Float -> putExtra(name, value)
is Double -> putExtra(name, value)
is Boolean -> putExtra(name, value)
macsystems /
Created Dec 12, 2016
Custom JUnit Test Rule which allows to override the Main Thread and oder Threads used by RxJava
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
macsystems /
Last active Apr 14, 2016
Timezones problem
public void timezoneProblem() throws ParseException {
TimeZone utcTime = TimeZone.getTimeZone("UTC");
TimeZone berlinTime = TimeZone.getTimeZone("Europe/Berlin");
Calendar calendar = new GregorianCalendar();
int hourOfDay_1 = calendar.get(Calendar.HOUR_OF_DAY);
int hourOfDay_2 = calendar.get(Calendar.HOUR_OF_DAY);
macsystems /
Last active Aug 15, 2017
Font Families on Android Versions
Added in Android Jelly Bean (4.1) - API 16 :
Regular (default):
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">normal</item>
<item name="android:fontFamily">sans-serif</item>
macsystems / build.gradle
Created May 3, 2015
Get Implementation-Version from Jar(s)
View build.gradle
* Returns the Version from the Manifest Entry
* @return
String getVersion() {
def files = fileTree(include: ['*.jar'], dir: 'libs')
def latestVersion;
for (File file : files) {
def jar = new JarFile(file);
macsystems /
Last active Aug 29, 2015
An DatePicker Dialog Fragment which respects rotation change. Also you can customize the setMin/Max Date using the extended OnDateSetListener interface.
public class CoreDatePickerDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
public final static String TAG = CoreDatePickerDialogFragment.class.getName();
private final static int REQUEST_CODE = -1;
private final static String SAVED_PICKER_STATE = "CoreDatePickerDialogFragment.internal_state";
private DatePickerDialog datePickerDialog;
private CoreOnDateSetListener callback;
macsystems /
Last active Jan 20, 2020
If you want to parse an RSS Feed using SimpleXML you can use this as an Start. I used this to parse RSS using RetroFit from Square
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.NamespaceList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Text;
import java.util.List;