Skip to content

Instantly share code, notes, and snippets.

View Kolyall's full-sized avatar
📱

Nick Unuchek Kolyall

📱
View GitHub Profile
@austynmahoney
austynmahoney / CachedRefreshable.java
Last active September 26, 2016 15:15
RxJava Refreshable Pattern
public abstract class CachedRefreshable<P, T> extends Refreshable<P, T> {
protected abstract Observable<T> getSourceObservable(P parameters);
/**
* Return the Observable that gets data from a cached source.
*
* @return Observable from cache item, or null if the cache misses.
*/
protected abstract Observable<T> getCachedObservable(P parameters);
@tsuharesu
tsuharesu / AddCookiesInterceptor.java
Last active June 8, 2024 07:30
Handle Cookies easily with Retrofit/OkHttp
/**
* This interceptor put all the Cookies in Preferences in the Request.
* Your implementation on how to get the Preferences MAY VARY.
* <p>
* Created by tsuharesu on 4/1/15.
*/
public class AddCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
@alex-shpak
alex-shpak / Interceptor.java
Last active June 14, 2024 02:40
Refreshing OAuth token with okhttp interceptors. All requests will wait until token refresh finished, and then will continue with the new token.
private class HttpInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//Build new request
Request.Builder builder = request.newBuilder();
builder.header("Accept", "application/json"); //if necessary, say to consume JSON
@Dogesmith
Dogesmith / Code.java
Last active April 22, 2025 11:22
Android Multi-line EditText which prevents newline characters from being added
mContent = (EditText) v.findViewById(R.id.dialog_item_content_EditText);
mContent.setText(mContentInit);
mContent.setRawInputType(InputType.TYPE_CLASS_TEXT);
mContent.setImeActionLabel(getResources().getString(R.string.done), EditorInfo.IME_ACTION_DONE);
mContent.setImeOptions(EditorInfo.IME_ACTION_DONE);
mContent.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event == null) {
@carlonzo
carlonzo / CacheFragmentStatePagerAdapter.java
Created August 2, 2015 17:08
FragmentStatePagerAdapter that caches each pages.
/*
* Copyright 2014 Soichiro Kashima
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@cesarferreira
cesarferreira / RxJava.md
Last active March 30, 2025 00:28
Party tricks with RxJava, RxAndroid & Retrolambda

View Click

Instead of the verbose setOnClickListener:

RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));

Filter even numbers

Observable
    .just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Observable.just(1)
.doOnSubscribe(() -> System.out.println("before 1st doOnSubscribe: " + Thread.currentThread().getName()))
.subscribeOn(Schedulers.newThread())
.doOnSubscribe(() -> System.out.println("before 2nd doOnSubscribe: " + Thread.currentThread().getName()))
.subscribeOn(Schedulers.io())
.doOnSubscribe(() -> System.out.println("before 3rd doOnSubscribe: " + Thread.currentThread().getName()))
.subscribeOn(Schedulers.computation())
.doOnSubscribe(() -> System.out.println("before subscribe: " + Thread.currentThread().getName()))
.subscribe(new Subscriber<Integer>() {
@Override
@lopspower
lopspower / README.md
Last active January 20, 2024 09:18
Publish AAR to jCenter and Maven Central

Publish AAR to jCenter and Maven Central

Twitter

EDIT: You can find this same updated tutorial here -> Medium

Now I'm going to list how to publish an Android libray to jCenter and then syncronize it with Maven Central:

  1. I use "Android Studio" and I have this simple android lib that I would like to be available on maven: CircularImageView
package com.amulyakhare.textdrawable;
import android.graphics.*;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RectShape;
import android.graphics.drawable.shapes.RoundRectShape;
/**
* @author amulya
@arthtilva
arthtilva / download.java
Last active March 21, 2023 12:15
DownloadManager - download files using DownloadManager
public class NewsDetailActivity extends AppCompatActivity implements View.OnClickListener {
Activity activity;
Toolbar toolbar;
File TEMP_FILE_SAVE_PATH = Environment.getExternalStorageDirectory();
String TEMP_FILE_NAME = "news_";
String URL="";
private DownloadManager downloadManager;
@Override