Skip to content

Instantly share code, notes, and snippets.

View mrahimygk's full-sized avatar
🎯
Focusing

Mojtaba Rahimy mrahimygk

🎯
Focusing
View GitHub Profile
import android.graphics.Point
import android.os.Parcel
import android.os.Parcelable
import android.util.Size
import java.io.PrintWriter
/**
* Point holds two integer coordinates
*/
class GithubSearchViewModel(
private val searchGithubUseCase: SearchGithubUseCase,
private val likeGithubUseCase: LikeGithubRepoUseCase
) : BaseViewModel(), EmptyObservableHost {
val shouldClearCurrentSearchResults = false
private val searchEvent: MediatorLiveData<String?> = searchQuery.map {
if (it.isNullOrBlank() || (restoredSearchQuery != null && restoredSearchQuery == it)) null
abstract class BaseFragment<VM : BaseViewModel, DB : ViewDataBinding> : Fragment() {
abstract val viewModel: VM
@CallSuper
open fun bindObservables() {
(viewModel as? EmptyObservableHost)?.let {
it.getObservableLiveDataList().forEach {
it.observe(viewLifecycleOwner, {})
fun map(eventData: AboutData, club: ClubSupportItem, matches: LatestMatchItem?,
subData: EventFragmentBundleCapsule?, match: Match?, news: SearchResult<SMNews>?)
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
private fun bindParentObservables() {
viewModel.snackMessageCommand.observe(viewLifecycleOwner, EventObserver { command ->
when (command) {
is SnackCommand.StringResSnackCommand ->
view?.showSnackBar(
command.message,
duration = command.duration
)
is SnackCommand.StringSnackCommand ->
abstract class BaseAdapter<T>(
private var itemSimilarityPredicate: (T, T) -> Boolean,
private var contentSimilarityPredicate: (T, T) -> Boolean
) : ListAdapter<T, BaseAdapter<T>.DataBindingViewHolder>(object : DiffUtil.ItemCallback<T>() {
override fun areContentsTheSame(
oldItem: T,
newItem: T
) = contentSimilarityPredicate.invoke(oldItem, newItem)
override fun areItemsTheSame(
@mrahimygk
mrahimygk / MergerLiveData.kt
Created July 18, 2019 07:06 — forked from guness/CombinedLiveData.java
LiveData merger that takes two live data inputs and a merger function. Merges two results using merger function, and returning result allowing null inputs and outputs. Input and out types are parametric. However only supports two live data inputs for now.
class CombinedLiveData<T, K, S>(source1: LiveData<T>, source2: LiveData<K>, private val combine: (data1: T?, data2: K?) -> S) : MediatorLiveData<S>() {
private var data1: T? = null
private var data2: K? = null
init {
super.addSource(source1) {
data1 = it
value = combine(data1, data2)
}
@mrahimygk
mrahimygk / glossy_effect_background.xml
Last active July 11, 2017 06:12
An xml file for android. It is best used with tall (portrait) elements like navigation drawer backgrounds and overlay on portrait images with RelativeLayouts. I kept it single-filed, you can use @Dimen or @color. See the result in https://pasteboard.co/GAotgJ8.png
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp">
<shape android:shape="rectangle" >
<corners android:radius="11dp" />
@mrahimygk
mrahimygk / system_info.c
Last active January 31, 2017 11:08 — forked from mortymacs/system_info.c
Showing system info
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
int main(int argc, char *argv[]) {
struct utsname *_system_ = malloc(sizeof(struct utsname));
uname(_system_);
if(argc==2 &&
(strcmp(argv[1], "version")==0
|| strcmp(argv[1],"VERSION" ) == 0))