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
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 / 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);
val applicationModule = module {
single<RetrofitInterface>("Retrofit") { RetrofitDependency() }
single<raghu.me.myapplication.di.ListRepository>("ListRepository"){ ListRepositoryImpl(get("Retrofit")) }
// ListScreenViewModel
viewModel { ListScreenViewModel(get("ListRepository")) }
}
class ListScreenViewModel(private val repo: ListRepositoryImpl) : ViewModel() {
fun getUsers() : LiveData<List<Users>> {
return repo.getUsers()
}
}
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) {
interface RetrofitInterface {
fun provideRetrofit(): Retrofit
}
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)
@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();
@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 / ServiceGenerator
Created February 22, 2019 05:06
Service Generator
import android.text.TextUtils;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;