Skip to content

Instantly share code, notes, and snippets.

View VitalyPeryatin's full-sized avatar
🎯
Focusing

Vitaly Peryatin VitalyPeryatin

🎯
Focusing
View GitHub Profile
class ConnectionLiveData(context: Context) :
MutableLiveData<ConnectionLiveData.ServerConnectionType>() {
enum class ServerConnectionType { ONLINE, OFFLINE }
private var connectivityManager: ConnectivityManager =
context.getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
private val connectivityManagerCallback: ConnectivityManager.NetworkCallback =
object : ConnectivityManager.NetworkCallback() {
package ru.energyhouse.energyhouse.data.network.socket
import com.google.gson.annotations.SerializedName
import ru.energyhouse.energyhouse.utils.consts.CONNECT_VALUE
data class ConnectModel(
@SerializedName("operation")
val command: String = CONNECT_VALUE,
var token: String = ""
)
@VitalyPeryatin
VitalyPeryatin / AppThemeDelegate.kt
Created June 2, 2020 15:04
Смена дневной/ночной темы
import android.content.res.Configuration
import android.os.Build
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import ru.dit.smartstaff.R
import ru.dit.smartstaff.repositories.AppThemeRepository
class AppThemeDelegate {
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.TextView
import java.util.*
const val ARG_ACTIVITY_NO = "ARG_ACTIVITY_NO"
import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@VitalyPeryatin
VitalyPeryatin / AppNavGraph.kt
Created July 6, 2022 19:14
SharedViewModelHolder (Compose)
// Inner navigation graph
val sharedViewModelHolder = SharedViewModelHolder<PostCreateViewModel>()
navGraphBuilder.navigation(
route = PostCreateDestination.RootCreatePostRoute,
startDestination = PostCreateDestination.SelectCreatablePost.createRoute()
) {
composable(PostCreateDestination.SelectCreatablePost) {
SelectCreatablePostScreen(
modifier = modifier,
@VitalyPeryatin
VitalyPeryatin / AppActivity.kt
Created July 6, 2022 19:17
Open screen chain (Compose)
class AppActivity : BaseActivity() {
private val viewModel: AppViewModel by viewModel()
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
tryOpenScreenChain(intent)
}
private fun tryOpenScreenChain(intent: Intent?) {
@VitalyPeryatin
VitalyPeryatin / AppNavGraph.kt
Created July 6, 2022 19:26
Pass parcelable arguments (Compose)
...
override fun registerGraph(
navGraphBuilder: NavGraphBuilder,
navController: NavHostController,
modifier: Modifier,
parameters: NavGraphParameters
) {
...
navGraphBuilder.composable(VideoAnswerDestination) { navBackStackEntry ->
val arguments: VideoAnswerDestination.Arguments =
@VitalyPeryatin
VitalyPeryatin / SharedViewModel.kt
Created July 6, 2022 19:54
SharedViewModel (Compose Navigation)
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.lifecycle.ViewModel
import org.koin.androidx.compose.getViewModel
import java.lang.ref.WeakReference
class SharedViewModelHolder<T: ViewModel> {
var sharedViewModelReference = WeakReference<T>(null)
}
val sharedViewModelHolder = SharedViewModelHolder<PostCreateViewModel>()
navGraphBuilder.navigation(
route = PostCreateDestination.RootCreatePostRoute,
startDestination = PostCreateDestination.SelectCreatablePost.createRoute()
) {
composable(PostCreateDestination.SelectCreatablePost) {
SelectCreatablePostScreen(
modifier = modifier,
navController = navController,
sharedViewModel = sharedViewModelHolder.createNewSharedViewModel()