Skip to content

Instantly share code, notes, and snippets.

@Razeeman
Razeeman / LocationManagerImpl.kt
Created November 27, 2019 14:13
Android Get User Location Manager
class LocationManagerImpl @Inject constructor(
private val permissionManager: PermissionManager,
private val context: Context
) : LocationManager {
override fun getUserLocationUpdates(): Observable<UserLocation> =
if (checkIfGooglePlayAvailable()) getLocationFromGooglePlay() else getLocationFromAndroidSdk()
override fun getDefaultLocation(): UserLocation = UserLocation(DEFAULT_LATITUDE, DEFAULT_LONGITUDE)
@Razeeman
Razeeman / SubjectDelegateUnitTest.kt
Last active December 6, 2019 11:33
Util class for unit tests. Creates subject and mocks instances, resets mocks before each test. Applies Rx rule.
/**
* Util class for unit tests.
* Creates subject and mocks instances, resets mocks before each test. Applies Rx rule.
*/
abstract class SubjectDelegateUnitTest<T : Any> : BaseUnitTest() {
@PublishedApi internal var mocks = mutableListOf<Any>()
lateinit var subject: T
override fun setUp() {
@Razeeman
Razeeman / fileutils.kt
Created July 31, 2019 08:06
File Uri and Content Uri from Bitmap
class FileUtils {
companion object {
private const val FILENAME = "temp_bitmap"
@JvmStatic
fun getFileUriFromBitmap(context: Context, bitmap: Bitmap): Uri {
val file = getFileFromBitmap(context, bitmap)
return Uri.parse(file.toURI().toString())
}
@Razeeman
Razeeman / layout.xml
Created July 31, 2019 08:03
Bottom margin in ScrollView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<FrameLayout
android:id="@+id/frl"
android:layout_width="match_parent"
@Razeeman
Razeeman / util.kt
Created July 31, 2019 07:58
Format time in milliseconds to the string of the type "6 дней 23:59:59"
/**
* Format time in milliseconds to the string of the type "6 дней 23:59:59".
*
* @param millis number of milliseconds.
* @return formatted string.
*/
fun convertMillisecondsToDHMS(millis: Long): String {
val s = TimeUnit.MILLISECONDS.toSeconds(millis) % TimeUnit.MINUTES.toSeconds(1)
val m = TimeUnit.MILLISECONDS.toMinutes(millis) % TimeUnit.HOURS.toMinutes(1)
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="red_50">#FFEBEE</color>
<color name="red_100">#FFCDD2</color>
<color name="red_200">#EF9A9A</color>
<color name="red_300">#E57373</color>
<color name="red_400">#EF5350</color>
<color name="red_500">#F44336</color>
<color name="red_600">#E53935</color>
Java. Kotlin.
OOP.
Design patterns.
Solid. Clean architecture.
Rest, crud, http, soap.
Android version names.
Android system architecture.
Android components. Activity, service, broadcast receiver, content provider.
Material design.
@Razeeman
Razeeman / Singletons.md
Last active November 9, 2023 19:23
Thread safe singleton implementations in java and kotlin.

Java

Not thread safe.

class SimpleSingleton {
    private static SimpleSingleton sInstance;
  
    private SimpleSingleton() {}
 
@Razeeman
Razeeman / Util.java
Last active January 30, 2019 13:39
Get N random elements from list without shuffling whole list.
public class Main {
/**
* Returns new list of N random elements from provided list.
*
* @param list list of elements to choose from
* @param n number of elements to choose
* @param <E> type of elements in a list
* @return new list of N random elements from provided list
*/
@Razeeman
Razeeman / AsyncTaskLoader.java
Last active January 30, 2019 18:14
Android, Java, AsyncTaskLoader.
public class MainActivity extends AppCompatActivity implements
LoaderManager.LoaderCallbacks<String> {
private static final int LOADER_ID = 22;
private static final String SEARCH_QUERY_URL_EXTRA = "query";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);