/* * Unitto is a unit converter for Android * Copyright (c) 2022-2022 Elshan Agaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.sadellie.unitto import android.app.Activity import android.content.Context import android.os.Bundle import android.util.AttributeSet import android.view.View import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.core.view.WindowCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.sadellie.unitto.core.ui.Formatter import com.sadellie.unitto.data.userprefs.UserPreferencesRepository import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.onEach import javax.inject.Inject @AndroidEntryPoint internal class MainActivity : ComponentActivity() { @Inject lateinit var userPrefsRepository: UserPreferencesRepository override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val userPrefsFlow = userPrefsRepository.userPreferencesFlow .onEach { Formatter.setSeparator(it.separator) } setContent { val userPrefs = userPrefsFlow .collectAsStateWithLifecycle(null).value if (userPrefs != null) UnittoApp(userPrefs) } } override fun onCreateView( parent: View?, name: String, context: Context, attrs: AttributeSet ): View? { val window = (parent?.context as? Activity)?.window if (window != null) { WindowCompat.setDecorFitsSystemWindows(window, false) } return super.onCreateView(parent, name, context, attrs) } }