Skip to content

Instantly share code, notes, and snippets.

:octocat:

Ali Rezaiyan rezaiyan

:octocat:
Block or report user

Report or block rezaiyan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rezaiyan
rezaiyan / SharedViewModel.java
Last active Nov 11, 2019
This is a simple example of a shared viewmodel
View SharedViewModel.java
class SharedViewModel extends ViewModel {
public MutableLiveData<String> liveData = new MutableLiveData<>();
}
class parentFragment {
sharedVm = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
@rezaiyan
rezaiyan / BObserver.java
Last active Oct 14, 2019
Binding Observer with LiveData
View BObserver.java
public class BObserver<T> extends DisposableObserver<T> {
private StateLiveData<T> liveData;
public BObserver(StateLiveData<T> liveData) {
this.liveData = liveData;
}
@Override
@rezaiyan
rezaiyan / OnTouchListener.java
Created Jun 11, 2019
This is a sample to swipe a layout to left and right
View OnTouchListener.java
import android.view.MotionEvent;
import android.view.View;
/**
* @author ali (alirezaiyann@gmail.com)
* @since 6/11/19 12:24 PM.
*/
public class OnTouchListener implements View.OnTouchListener {
View OnSwipeTouchListener.kt
import android.annotation.SuppressLint
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import java.util.*
/**
* Detects left and right swipes across a view.
*/
@rezaiyan
rezaiyan / PrettyLogger.kt
Created Apr 26, 2019
Pretty Json Logger
View PrettyLogger.kt
//Reference//
//https://github.com/orhanobut/logger
//https://github.com/JakeWharton/timber
// 1- Add this initializations to the oncreate method of Application class
Logger.addLogAdapter(AndroidLogAdapter())
Timber.plant(Timber.DebugTree())
// 2- Create a snippet to detect log is a json format (I used a string extention function)
fun String.isJson(): Boolean {
@rezaiyan
rezaiyan / build.gradle
Created Apr 24, 2019
Androidx conflict
View build.gradle
/* packagingOptions {
exclude 'META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version'
exclude 'META-INF/androidx.appcompat_appcompat.version'
exclude 'META-INF/androidx.customview_customview.version'
exclude 'META-INF/androidx.legacy_legacy-support-core-ui.version'
exclude 'META-INF/androidx.drawerlayout_drawerlayout.version'
exclude 'META-INF/androidx.interpolator_interpolator.version'
exclude 'META-INF/androidx.legacy_legacy-support-core-utils.version'
exclude 'META-INF/androidx.slidingpanelayout_slidingpanelayout.version'
exclude 'META-INF/androidx.swiperefreshlayout_swiperefreshlayout.version'
@rezaiyan
rezaiyan / DrawableToBitmap.kt
Created Apr 21, 2019
A snippet code to do convert drawable to bitmap
View DrawableToBitmap.kt
fun Drawable.toBitmap(): Bitmap {
val bitmap = if (this.intrinsicWidth <= 0 || this.intrinsicHeight <= 0) {
Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) // Single color bitmap will be created of 1x1 pixel
} else {
Bitmap.createBitmap(this.intrinsicWidth, this.intrinsicHeight, Bitmap.Config.ARGB_8888)
}
if (this is BitmapDrawable) {
if (this.bitmap != null) {
return this.bitmap
@rezaiyan
rezaiyan / MergeIntervals.java
Last active Apr 5, 2019
Given a collection of intervals, merge all overlapping intervals.
View MergeIntervals.java
/*
Given a collection of intervals, merge all overlapping intervals.
Example 1:
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
Example 2:
@rezaiyan
rezaiyan / MaxSubArray.java
Last active Apr 1, 2019
Maximum sum of a sub-array
View MaxSubArray.java
//Given an integer array nums,
//find the contiguous subarray (containing at least one number)
//which has the largest sum and return its sum.
class Solution {
public int maxSubArray(int[] nums) {
if (nums.length == 1)
return nums[0];
int sum = 0;
View Factorial.kt
fun factorial(number: Int): Int {
var factor = 1
return if (number <= 1)
factor
else {
(1 until number).forEach { factor*=(it+1) }
factor
}
}
You can’t perform that action at this time.