Skip to content

Instantly share code, notes, and snippets.

View freaksgit's full-sized avatar

Vasyl Stoliarchuk freaksgit

  • Kiev, Ukraine.
View GitHub Profile
@freaksgit
freaksgit / README.md
Created March 16, 2023 13:28 — forked from lopspower/README.md
All Android Directory Path

All Android Directory Path

Twitter

1) System directories

⚠️ We can't write to these folers

Method Result
@freaksgit
freaksgit / KeepStateNavigator.kt
Last active April 16, 2019 14:06
Navigation component keep state navigator sample
import android.content.Context
import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.navigation.NavDestination
import androidx.navigation.NavOptions
import androidx.navigation.Navigator
import androidx.navigation.fragment.FragmentNavigator
@Navigator.Name("keep_state_fragment") // `keep_state_fragment` is used in navigation xml
class KeepStateNavigator(
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21.
To use the support version of these attributes, remove the android namespace.
For instance, "android:colorControlNormal" becomes "colorControlNormal".
These attributes will be propagated to their corresponding attributes within the android namespace
for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
@freaksgit
freaksgit / tokens.md
Created March 8, 2019 10:15 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с данными сохранёнными в базе данных.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

Например после аутентификации юзер sasha получает право обращатся и получать от ресурса "super.com/vip" некие данные. Во время обращения юзера sasha к ресурсу vip система авторизации проверит имеет ли право юзер обращатся к этому ресурсу (проще говоря переходить по неким разрешенным ссылкам)

//http://stackoverflow.com/questions/4605527/converting-pixels-to-dp
//The above method results accurate method compared to below methods
//http://stackoverflow.com/questions/8309354/formula-px-to-dp-dp-to-px-android
//http://stackoverflow.com/questions/13751080/converting-pixels-to-dpi-for-mdpi-and-hdpi-screens
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
@freaksgit
freaksgit / OnVerticalScrollListener.java
Created August 16, 2018 13:56 — forked from zhanghai/OnVerticalScrollListener.java
RecyclerView.OnScrollListener that reports scrolled up/down or reached top/bottom.
/*
* Copyright (c) 2015 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
* All Rights Reserved.
*/
package com.example.android;
import android.support.v7.widget.RecyclerView;
public abstract class OnVerticalScrollListener extends RecyclerView.OnScrollListener {
class A extends Parent implements AContract.View{
@Named(DiNames.SOME_DEPENDENCY_FOR_A)
@Inject
SomeDependency dependency;
@Inject
AContract.Presenter presenter;
@Query("SELECT * FROM " + RoomCard.TABLE_NAME + " WHERE " + RoomCard.COLUMN_TYPE + " = " + Card.TYPE_QUEST)
Maybe<List<RoomQuestCardEmbedded>> getAllQuestCards();
public class RoomCard {
public static final String COLUMN_TYPE = "card_type";
...
}
public class Card{
@freaksgit
freaksgit / Interceptor
Created July 19, 2018 10:54
OkHttp3 interceptor
public class HttpInter implements Interceptor{
@Override
public Response intercept(Chain chain) throws IOException {
if (internet.isAvailable()){
return chain.proceed(chain.request());
} else {
throw new IOException(new InternetUnavailableException("No internet connection."));
}
}
public class MyAppActivityCallbacks implements Application.ActivityLifecycleCallbacks {
private Set<Class<Activity>> visibleActivities = new HashSet<>();
@Override
public void onActivityResumed(Activity activity) {
visibleActivities.add((Class<Activity>) activity.getClass());
}
@Override
public void onActivityStopped(Activity activity) {