Skip to content

Commit

Permalink
29/04/2024.
Browse files Browse the repository at this point in the history
  • Loading branch information
youndon committed Apr 29, 2024
1 parent 421e4f0 commit ddfe9dd
Show file tree
Hide file tree
Showing 60 changed files with 477 additions and 534 deletions.
36 changes: 13 additions & 23 deletions app/src/main/java/city/zouitel/jetnote/IntentHandler.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package city.zouitel.jetnote

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.widget.Toast
import androidx.navigation.NavHostController
import androidx.compose.runtime.Composable
import cafe.adriel.voyager.navigator.Navigator
import city.zouitel.logic.codeUrl
import city.zouitel.logic.asShortToast
import city.zouitel.note.ui.add_screen.AddScreen
import city.zouitel.screens.home_screen.HomeScreen
import kotlinx.coroutines.CoroutineScope
Expand All @@ -14,49 +14,39 @@ import java.util.UUID

internal interface IntentHandler: CoroutineScope {

fun intentHandler(
context (Context)
@SuppressLint("NotConstructor")
@Composable
fun IntentHandler(
intent: Intent,
context: Context,
navHC: NavHostController,
navigator: Navigator?,
composer: (@Composable () -> Unit) -> Unit
) {
intent.apply {
if (action == Intent.ACTION_SEND && type == "text/plain") {
getStringExtra(Intent.EXTRA_TEXT)?.let {
getStringExtra(Intent.EXTRA_TEXT)?.let { title ->
launch {
// navigator?.push(listOf(HomeScreen(), AddScreen(UUID.randomUUID().toString(), codeUrl(it))))
navigator?.push(
listOf(
AddScreen(UUID.randomUUID().toString(), codeUrl(it))
)
)
title.asShortToast()
}
Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
}
}
if (action == Intent.ACTION_VIEW) {
if (extras?.containsKey("new_note_shortcut") == true) {
getBooleanExtra("new_note_shortcut", false)
launch {
// navigator?.push(AddScreen(UUID.randomUUID().toString()))
navigator?.push(
listOf(
HomeScreen(),
AddScreen(UUID.randomUUID().toString())
)
)
"new_note_shortcut".asShortToast()
}
}
if (extras?.containsKey("quick_note") == true) {
getBooleanExtra("quick_note", false)
launch {
// navHC.navigate("${Cons.ADD_ROUTE}/${UUID.randomUUID()}/${Cons.NUL}")
// TODO:
}
}
if (extras?.containsKey("new_record") == true) {
getBooleanExtra("new_record", false)
launch {
// navHC.navigate("${Cons.ADD_ROUTE}/${UUID.randomUUID()}/${Cons.NUL}")
// TODO:
}
}

Expand Down
32 changes: 16 additions & 16 deletions app/src/main/java/city/zouitel/jetnote/NoteActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@ package city.zouitel.jetnote

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.collectAsState
import androidx.core.view.WindowCompat
import androidx.navigation.compose.rememberNavController
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.Navigator
import city.zouitel.links.ui.LinkVM
import city.zouitel.links.ui.LinkScreenModel
import city.zouitel.logic.asLongToast
import city.zouitel.screens.home_screen.HomeScreen
import city.zouitel.root.RootViewModel
import city.zouitel.root.RootScreenModel
import city.zouitel.shortcuts.checkNoteActivityShortcut
import city.zouitel.systemDesign.DataStoreScreenModel
import city.zouitel.systemDesign.MainTheme
import city.zouitel.widget.WidgetReceiver
import kotlinx.coroutines.*
import org.koin.android.ext.android.inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import kotlin.coroutines.CoroutineContext

class NoteActivity : ComponentActivity(), KoinComponent, IntentHandler {

private val linkViewModel: LinkVM by inject()
private val rootViewModel: RootViewModel by inject()
private val linkScreenModel: LinkScreenModel by inject()
private val rootScreenModel: RootScreenModel by inject()
private val dataStoreModel: DataStoreScreenModel by inject()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
val navHostController = rememberNavController()
val navigator = LocalNavigator.current
val isDeviceRooted = rootViewModel.isDeviceRooted.collectAsState()
val isDeviceRooted = rootScreenModel.isDeviceRooted.collectAsState()

require(!isDeviceRooted.value.getOrNull()?.isDeviceRooted!!) {
Toast.makeText(this, "Cannot run JetNote on rooted device!", Toast.LENGTH_SHORT).show()
"Cannot run JetNote on rooted device!".asLongToast()
}

intentHandler(
IntentHandler(
intent,
this@NoteActivity,
navHostController,
navigator
navigator,
{}
)

MainTheme {
MainTheme(dataStoreModel) {
Navigator(HomeScreen())
}
}
Expand All @@ -57,7 +57,7 @@ class NoteActivity : ComponentActivity(), KoinComponent, IntentHandler {

override fun onDestroy() {
super.onDestroy()
linkViewModel.urlPreview(this, null, null, null, null)?.cleanUp()
linkScreenModel.urlPreview(this, null, null, null, null)?.cleanUp()
WidgetReceiver.updateBroadcast(this)
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/city/zouitel/jetnote/NoteApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import city.zouitel.recoder.di.recorderKoinModule
import city.zouitel.repository.di.repositoryKoinModule
import city.zouitel.root.di.rootKoinModule
import city.zouitel.security.di.securityKoinModule
import city.zouitel.systemDesign.di.datastoreVMKoinModule
import city.zouitel.systemDesign.di.commonSystemDesignKoinModule
import city.zouitel.tags.di.tagsKoinModule
import city.zouitel.tasks.di.tasksKoinModule
import city.zouitel.widget.di.widgetKoinModule
Expand Down Expand Up @@ -48,7 +48,7 @@ class NoteApplication: Application(), KoinComponent {
tasksKoinModule,
widgetKoinModule,
notificationKoinModule,
datastoreVMKoinModule,
commonSystemDesignKoinModule,
navigationKoinModule,
initializerKoinModule,
rootKoinModule
Expand Down
11 changes: 4 additions & 7 deletions common/logic/src/main/java/city/zouitel/logic/toasts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import android.content.Context
import android.widget.Toast

context (Context)
val String.shortToast : () -> Unit
get() = {
fun String.asShortToast() {
Toast.makeText(this@Context, this, Toast.LENGTH_SHORT).show()
}

context (Context)
val String.longToast : () -> Unit
get() = {
Toast.makeText(this@Context, this, Toast.LENGTH_LONG).show()
}

fun String.asLongToast() {
Toast.makeText(this@Context, this, Toast.LENGTH_LONG).show()
}
1 change: 1 addition & 0 deletions common/systemDesign/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
plugins {
alias(libs.plugins.cityzouitel.androidLibrary)
alias(libs.plugins.cityzouitel.androidCompose)
alias(libs.plugins.cityzouitel.androidNavigation)
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package city.zouitel.jetnote
package city.zouitel.systemDesign

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
Expand All @@ -9,13 +9,13 @@ import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import city.zouitel.systemDesign.DataStoreVM
import cafe.adriel.voyager.koin.getNavigatorScreenModel
import cafe.adriel.voyager.navigator.LocalNavigator
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import org.koin.androidx.compose.koinViewModel

@Composable
fun MainTheme(
dataStoreVM: DataStoreVM = koinViewModel(),
dataStoreVM: DataStoreScreenModel,
content: @Composable () -> Unit
) {
val currentTheme = remember(dataStoreVM, dataStoreVM::getTheme).collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Cons {
const val NUL = "null"
const val NONE = "unspecified"

const val APP_VERSION = "5.2.4"
const val APP_VERSION = "5.3.0"

const val ID = "Id"
const val TITLE = "Title"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package city.zouitel.systemDesign

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import city.zouitel.datastore.Cons
import city.zouitel.datastore.DataStoreRepo
import kotlinx.coroutines.Dispatchers
Expand All @@ -11,58 +11,58 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

class DataStoreVM(
class DataStoreScreenModel(
private val dataStoreRepo: DataStoreRepo
) : ViewModel() {
): ScreenModel {

val getLayout: StateFlow<String> = dataStoreRepo.getLayout.filter {
it.isNotEmpty()
}.stateIn(
viewModelScope,
screenModelScope,
SharingStarted.WhileSubscribed(),
Cons.GRID
)

val getSound: StateFlow<Boolean> = dataStoreRepo.getSound
.stateIn(
viewModelScope,
screenModelScope,
SharingStarted.WhileSubscribed(),
false
)

val getOrdination: StateFlow<String> = dataStoreRepo.getOrdination
.stateIn(
viewModelScope,
screenModelScope,
SharingStarted.WhileSubscribed(),
city.zouitel.systemDesign.Cons.BY_NAME
)

val getTheme: StateFlow<String> = dataStoreRepo.getTheme
.stateIn(
viewModelScope,
screenModelScope,
SharingStarted.WhileSubscribed(),
Cons.DARK
)

fun setSound(sound: Boolean) {
viewModelScope.launch(Dispatchers.IO) {
screenModelScope.launch(Dispatchers.IO) {
dataStoreRepo.setSound(sound)
}
}
fun setOrdination(order: String) {
viewModelScope.launch(Dispatchers.IO) {
screenModelScope.launch(Dispatchers.IO) {
dataStoreRepo.setOrdination(order)
}
}

fun setLayout(layout: String) {
viewModelScope.launch(Dispatchers.IO) {
screenModelScope.launch(Dispatchers.IO) {
dataStoreRepo.setLayout(layout)
}
}

fun setTheme(theme: String) {
viewModelScope.launch(Dispatchers.IO) {
screenModelScope.launch(Dispatchers.IO) {
dataStoreRepo.setTheme(theme)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package city.zouitel.systemDesign.di

import org.koin.dsl.module
import city.zouitel.systemDesign.DataStoreScreenModel
import org.koin.core.module.dsl.factoryOf

val commonSystemDesignKoinModule = module {
factoryOf(::DataStoreScreenModel)
}

This file was deleted.

4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ kotlin = "1.9.22"
compilesdk-v = "34"
minsdk-v = "26"
targetsdk-v = "34"
code-v = "524"
name-v = "5.2.4"
code-v = "530"
name-v = "5.3.0"
compose-v = "1.5.10"

#Android.
Expand Down
1 change: 1 addition & 0 deletions root/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias(libs.plugins.cityzouitel.androidLibrary)
alias(libs.plugins.cityzouitel.androidNavigation)
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package city.zouitel.root

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import city.zouitel.domain.usecase.RootUseCase
import city.zouitel.root.mapper.RootMapper
import city.zouitel.root.model.Root as InRoot
Expand All @@ -12,23 +12,23 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

class RootViewModel(
class RootScreenModel(
rootUseCase: RootUseCase.RootUseCase,
private val mapper: RootMapper
): ViewModel() {
): ScreenModel {

private val _isDeviceRooted = MutableStateFlow(runCatching { InRoot(false) })

val isDeviceRooted: StateFlow<Result<InRoot>> =
_isDeviceRooted.stateIn(
viewModelScope,
screenModelScope,
SharingStarted.WhileSubscribed(),
runCatching { InRoot(false) }
)


init {
viewModelScope.launch(Dispatchers.IO) {
screenModelScope.launch(Dispatchers.IO) {
rootUseCase.invoke().collect { result ->
_isDeviceRooted.value = result.map { mapper.toView(it) }
}
Expand Down
5 changes: 2 additions & 3 deletions root/src/main/java/city/zouitel/root/di/rootKoinModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package city.zouitel.root.di

import city.zouitel.root.mapper.RootMapper
import city.zouitel.root.RootViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import city.zouitel.root.RootScreenModel
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.module

val rootKoinModule = module {

viewModel { RootViewModel(get(), get()) }
factory { RootScreenModel(get(), get()) }
factoryOf(::RootMapper)
}
Loading

0 comments on commit ddfe9dd

Please sign in to comment.