Skip to content

Instantly share code, notes, and snippets.

View dmitriy-chernysh's full-sized avatar
🚀
Building Android apps

Dmitri Chernysh dmitriy-chernysh

🚀
Building Android apps
View GitHub Profile
class GridRecyclerView : RecyclerView {
private lateinit var manager: GridLayoutManager
private var columnWidth = -1
constructor(context: Context) : super(context) {
init(context, null)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs)
@dmitriy-chernysh
dmitriy-chernysh / RecyclerViewAdapter.kt
Created June 12, 2020 19:11
RecyclerView + BindingAdapter [Kotlin]
class RecyclerViewAdapter : RecyclerView.Adapter<BindingViewHolder>() {
private val items = mutableListOf<RecyclerItem>()
private var eventHandler: RecyclerViewHandler? = null
override fun getItemCount(): Int {
return items.size
}
override fun getItemViewType(position: Int): Int {
@dmitriy-chernysh
dmitriy-chernysh / BaseRxUseCase.kt
Created May 18, 2020 19:46
Template | Use Case | Domain Layer
package com.mobiledevpro.interactor.usecase.base
import com.mobiledevpro.interactor.usecase.base.executor.ExecutionThread
import com.mobiledevpro.interactor.usecase.base.executor.PostExecutionThread
import io.reactivex.Scheduler
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
abstract class BaseRxUseCase(
executionThread: ExecutionThread,
@dmitriy-chernysh
dmitriy-chernysh / 01. TemplateFragment.kt
Last active November 24, 2022 23:02
File Templates. Android Studio. Kotlin. Fragment and ViewModel
/*
How to add this template to Android Studio:
1. Settings -> Edditor -> File and Code Templated;
2. Open "Files" tab;
3. Click icon "Plus" and paste the code below;
4. "Enable Live Templates" should be turned off.
*/
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
@dmitriy-chernysh
dmitriy-chernysh / Fragment.kt
Last active April 27, 2020 06:15
Check runtime permissions in ViewModel
class VehicleDetailsFragmentKt : BaseFragment() {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
observeLiveData()
return inflater.inflate(getLayoutResId(), container, false);
}
@dmitriy-chernysh
dmitriy-chernysh / .circleci > config.yml
Last active January 25, 2023 18:50
CircleCI 2.1 | Config | Run tests, build & deploy app release | Android
version: 2.1
# Updated on May 10, 2022
config_docker: &config_docker
docker:
- image: cimg/android:2021.10.2
resource_class: large
working_directory: ~/code
config_env: &config_env
@dmitriy-chernysh
dmitriy-chernysh / HandleHttpErrorsInterceptor.java
Last active April 24, 2020 19:22
OkHttp Interceptor to handle errors
/**
* Interceptor to handle connection errors and return a readable message to user
* <p>
* Created by Dmitriy Chernysh on 12/3/19.
* <p>
* https://instagr.am/mobiledevpro
* #MobileDevPro
*
*
* NOTE: add this to:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case Constants.REQUEST_CODE_ADD_VIDEO_FROM_GALLERY:
boolean isGranted = false;
for (int result : grantResults) {
if (result == PackageManager.PERMISSION_GRANTED) {
isGranted = true;
} else {
isGranted = false;
/**
* This class helps to encrypt passwords before saving and decrypt then
* <p>
* Created by Dmitriy V. Chernysh
* <p>
* https://instagr.am/mobiledevpro
* <p>
* #MobileDevPro
*/
public class EncryptDataHelper {
@dmitriy-chernysh
dmitriy-chernysh / screenBrightness.java
Last active May 23, 2018 11:50
Set full brightness for activity window
//set screen brightness to max
Window window = getActivity().getWindow();
if (window != null) {
WindowManager.LayoutParams lp = window.getAttributes();
lp.screenBrightness = 1; //from dark (0) to full bright (1)
window.setAttributes(lp);
}