Skip to content

Instantly share code, notes, and snippets.

View Shvet's full-sized avatar
💻
Compose

Shvet Shvet

💻
Compose
  • Shvet Consultancy service
  • Rajkot
View GitHub Profile
@Shvet
Shvet / Session.kt
Last active June 30, 2023 13:38
Session Class to store user credential locally.
package com.shvet.composelogin.di
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.stringPreferencesKey
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
@Shvet
Shvet / ComposeNavHost.kt
Last active June 30, 2023 13:11
Compose Nav Host Wrapper Class
package com.shvet.composelogin.activity
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
@Shvet
Shvet / LoginUi.kt
Last active June 30, 2023 12:50
Simple Compose Login screen
package com.shvet.composelogin.login
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
@Shvet
Shvet / AppModule.kt
Last active June 30, 2023 11:30
Android Datastore depedency Example
@Module
@InstallIn(SingletonComponent::class)
class AppModule {
@Singleton
@Provides
fun provideDataStore(@ApplicationContext context: Context): DataStore<Preferences> {
return PreferenceDataStoreFactory.create(
corruptionHandler = ReplaceFileCorruptionHandler(produceNewData = { emptyPreferences() }),
produceFile = { context.preferencesDataStoreFile(Session.DATA) })
@Shvet
Shvet / LoginViewModel.kt
Created June 30, 2023 09:46
ViewModel For login screen
package com.shvet.composelogin.login.viewModel
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.shvet.composelogin.di.Session
import com.shvet.composelogin.login.model.LoginState
import com.shvet.composelogin.login.repository.LoginRepository
@Shvet
Shvet / maven_publish.gradle
Created January 5, 2022 10:47 — forked from viktoriia-io/maven_publish.gradle
Maven publishing script for customising pom file generation
apply plugin: 'maven-publish'
afterEvaluate {
publishing {
publications {
maven(MavenPublication) {
groupId project.ext.pomGroupID
artifactId project.name
version project.ext.pomVersion
@Shvet
Shvet / AddDarkModeButton.kt
Created July 8, 2021 05:08 — forked from HugoMatilla/AddDarkModeButton.kt
Add a DarkMode Button to your activity
fun addDarkModeButton() {
val darkButton = Button(this).apply {
text = if (getDefaultNightMode() != MODE_NIGHT_YES) "Go Dark " else "Go Light"
layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT)
}
(window.decorView as ViewGroup).addView(darkButton) // or `yourContainer.addView(darkButton)`
darkButton.setOnClickListener {
AppCompatDelegate.setDefaultNightMode(
@Shvet
Shvet / FullBottomSheet.dart
Last active June 11, 2021 06:39
Flutter Modal bottom sheet that supports full screen height
//Flutter Modal Bottom Sheet
//Modified by Shvet for null safety & tested. Also added Round corners on top.
//Based on https://gist.github.com/GiorgioBertolotti/5fc8fcca67aeda3ed9bbc74c856d06f1
import 'dart:async';
import 'package:flutter/material.dart';