Skip to content

Instantly share code, notes, and snippets.

View mohamed-khaled-hsn's full-sized avatar

Mohamed Khaled mohamed-khaled-hsn

View GitHub Profile
/**
* @return [LiveData] with value produced from combining [source1] and [source2] using [combiner]
*
* This function produces new value only if [source1] and [source2] values are not null
*/
fun <T1, T2, R> combineNonNull(
source1: LiveData<T1>,
source2: LiveData<T2>,
combiner: (T1, T2) -> R
@mohamed-khaled-hsn
mohamed-khaled-hsn / DiskLruCachePicassoDownloader.kt
Last active May 8, 2020 15:52
Picasso downloader that uses DiskLruCache and last Uri last path segment as key (useful for pre-signed url that changes frequently)
import android.net.Uri
import app.choco.tracking.logger.Logger
import com.jakewharton.disklrucache.DiskLruCache
import com.squareup.picasso.Downloader
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
import java.util.Locale
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@mohamed-khaled-hsn
mohamed-khaled-hsn / MarginItemDecoration.kt
Created November 1, 2019 14:13
MarginItemDecoration
class MarginItemDecoration(
private val left: Int? = null,
private val top: Int? = null,
private val right: Int? = null,
private val bottom: Int? = null
) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
@mohamed-khaled-hsn
mohamed-khaled-hsn / build.gradle
Created April 9, 2019 16:22
Auto incrementing versionCode based on Jenkins build
android {
defaultConfig {
//..
versionCode computeVersionCode()
versionName computeVersionName()
//..
}
ext {
versionMajor = 1
versionMinor = 0
@mohamed-khaled-hsn
mohamed-khaled-hsn / SwipeRevealLayout.java
Created March 25, 2019 10:35
Swipe to reveal layout, to be used as an item viewType in RecyclerView or ListView
public class SwipeRevealLayout extends ViewGroup {
// These states are used only for ViewBindHelper
protected static final int STATE_CLOSE = 0;
protected static final int STATE_CLOSING = 1;
protected static final int STATE_OPEN = 2;
protected static final int STATE_OPENING = 3;
protected static final int STATE_DRAGGING = 4;
private static final int DEFAULT_MIN_FLING_VELOCITY = 300; // dp per second
private static final int DEFAULT_MIN_DIST_REQUEST_DISALLOW_PARENT = 1; // dp
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;