Skip to content

Instantly share code, notes, and snippets.

View raghunandankavi2010's full-sized avatar
🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.

Raghunandan Kavi raghunandankavi2010

🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.
View GitHub Profile
@raghunandankavi2010
raghunandankavi2010 / auth.java
Created February 12, 2019 14:34
Okhttp authenticator
final OkHttpClient client = new OkHttpClient.Builder()
. authenticator(new Authenticator() {
@Override public Request authenticate(Route route, Response response) throws IOException {
if (response.request().header("Authorization") != null) {
return null; // Give up, we've already attempted to authenticate.
}
String credential = Credentials.basic("jesse", "password1");
return response.request().newBuilder()
.header("Authorization", credential)
.build();
@raghunandankavi2010
raghunandankavi2010 / BackPress
Created February 5, 2019 04:12
Fragment back stack back press handling
@Override
public void onBackPressed() {
if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawers();
}
else if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
String fragmentTag = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName();
if (fragmentTag.equals("dashboard")) {
//Toast.makeText(this.getApplicationContext(),""+fragmentTag,Toast.LENGTH_SHORT).show();
finish();
class class RetrofitDependency : RetrofitInterface {
override fun provideRetrofit(): Retrofit {
val logging = HttpLoggingInterceptor()
logging.level = HttpLoggingInterceptor.Level.BASIC
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(logging)
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
interface RetrofitInterface {
fun provideRetrofit(): Retrofit
}
class ListRepositoryImpl(private val retrofitDependency: RetrofitDependency): ListRepository {
var data = MutableLiveData<List<Users>>()
override fun getUsers(): MutableLiveData<List<Users>>{
val service = retrofitDependency.provideRetrofit().create(Api::class.java)
service.users.enqueue(object : Callback<List<Users>> {
override fun onResponse(call: Call<List<Users>>, response: Response<List<Users>>) {
if (response.isSuccessful) {
class ListScreenViewModel(private val repo: ListRepositoryImpl) : ViewModel() {
fun getUsers() : LiveData<List<Users>> {
return repo.getUsers()
}
}
val applicationModule = module {
single<RetrofitInterface>("Retrofit") { RetrofitDependency() }
single<raghu.me.myapplication.di.ListRepository>("ListRepository"){ ListRepositoryImpl(get("Retrofit")) }
// ListScreenViewModel
viewModel { ListScreenViewModel(get("ListRepository")) }
}
@raghunandankavi2010
raghunandankavi2010 / drawlabels
Created November 9, 2018 16:28
labels without rounded rect
private void drawLabels(Canvas canvas) {
weekWidth = (getWidth () - getPaddingLeft () - getPaddingRight ()) / weeksCount;
graphHeight = getHeight () - getPaddingTop () - getPaddingBottom ();
float centerX = getPaddingLeft() + (weekWidth/2);
for(int i=0;i<weeksCount;i++) {
String week = "week "+i;
mTextPaint.getTextBounds(week, 0, week.length(), textBounds);
package com.santalu.diagonalimageview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
@raghunandankavi2010
raghunandankavi2010 / GridItemDecoration
Created June 27, 2017 05:56
GridItemDecoration for recyclerview
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
/**
* Created by Raghunandan on 17-11-2015.
*/
public class GridItemDecoration extends RecyclerView.ItemDecoration {