Skip to content

Instantly share code, notes, and snippets.

@abos3d
abos3d / PermissionManager.kt
Created March 7, 2022 11:30 — forked from mkovalyk/PermissionManager.kt
Make Android permission easier
package com.example.myapplication
import android.content.pm.PackageManager
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
package com.cleanarchitectkotlinflowhiltsimplestway.presentation.splash
import androidx.lifecycle.ViewModel
import com.cleanarchitectkotlinflowhiltsimplestway.domain.SampleUseCase
import com.cleanarchitectkotlinflowhiltsimplestway.presentation.State
import com.cleanarchitectkotlinflowhiltsimplestway.utils.Utils
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import javax.inject.Inject
package com.cleanarchitectkotlinflowhiltsimplestway.presentation.splash
import android.os.Bundle
import android.widget.TextView
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.cleanarchitectkotlinflowhiltsimplestway.R
import com.cleanarchitectkotlinflowhiltsimplestway.presentation.State
import dagger.hilt.android.AndroidEntryPoint
package com.cleanarchitectkotlinflowhiltsimplestway.presentation
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class App : Application() {
override fun onCreate() {
super.onCreate()
package com.cleanarchitectkotlinflowhiltsimplestway.presentation
import org.json.JSONObject
import retrofit2.HttpException
open class NetworkErrorException(
val errorCode: Int = -1,
val errorMessage: String,
val response: String = ""
) : Exception() {
package com.cleanarchitectkotlinflowhiltsimplestway.presentation
sealed class State<out T> {
object LoadingState : State<Nothing>()
data class ErrorState(var exception: Throwable) : State<Nothing>()
data class DataState<T>(var data: T) : State<T>()
}
package com.cleanarchitectkotlinflowhiltsimplestway.domain
import com.google.gson.JsonObject
import com.cleanarchitectkotlinflowhiltsimplestway.data.APIs
import javax.inject.Inject
class SampleUseCase @Inject constructor(
private val apIs: APIs
) {
suspend operator fun invoke(): JsonObject {
package com.cleanarchitectkotlinflowhiltsimplestway.data
import com.google.gson.JsonObject
import retrofit2.http.GET
interface APIs {
@GET("api/users")
suspend fun sampleGet(): JsonObject
}
@abos3d
abos3d / DI.kt
Last active June 22, 2021 08:46
Hilt impl
package com.cleanarchitectkotlinflowhiltsimplestway.utils
import android.content.Context
import com.cleanarchitectkotlinflowhiltsimplestway.data.APIs
import com.cleanarchitectkotlinflowhiltsimplestway.presentation.App
import com.google.gson.GsonBuilder
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
package com.cleanarchitectkotlinflowhiltsimplestway.utils
import com.cleanarchitectkotlinflowhiltsimplestway.domain.AuthenticationException
import com.cleanarchitectkotlinflowhiltsimplestway.domain.NetworkErrorException
import com.cleanarchitectkotlinflowhiltsimplestway.domain.State
import retrofit2.HttpException
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.net.UnknownHostException