|
1 | | -package com.pluto.plugins.datastore.pref.compose.internal |
2 | | - |
3 | | -import android.os.Bundle |
4 | | -import android.view.LayoutInflater |
5 | | -import android.view.View |
6 | | -import android.view.ViewGroup |
7 | | -import androidx.compose.foundation.layout.Box |
8 | | -import androidx.compose.foundation.layout.fillMaxHeight |
9 | | -import androidx.compose.foundation.layout.fillMaxWidth |
10 | | -import androidx.compose.material3.MaterialTheme |
11 | | -import androidx.compose.runtime.collectAsState |
12 | | -import androidx.compose.runtime.mutableStateOf |
13 | | -import androidx.compose.ui.Modifier |
14 | | -import androidx.compose.ui.platform.ComposeView |
15 | | -import androidx.compose.ui.platform.ViewCompositionStrategy |
16 | | -import androidx.core.graphics.Insets |
17 | | -import androidx.core.view.ViewCompat |
18 | | -import androidx.core.view.WindowInsetsCompat |
19 | | -import androidx.fragment.app.Fragment |
20 | | -import androidx.fragment.app.viewModels |
21 | | -import com.pluto.plugins.datastore.pref.compose.internal.compose.FilterView |
22 | | -import com.pluto.plugins.datastore.pref.compose.internal.compose.MainComposable |
23 | | -import kotlin.math.max |
24 | | -import kotlinx.coroutines.flow.update |
25 | | - |
26 | | -internal class BaseFragment : Fragment() { |
27 | | - |
28 | | - private val viewModel by viewModels<BaseViewModel>() |
29 | | - private val insets = mutableStateOf(Insets.NONE) |
30 | | - |
31 | | - override fun onCreateView( |
32 | | - inflater: LayoutInflater, |
33 | | - container: ViewGroup?, |
34 | | - savedInstanceState: Bundle? |
35 | | - ) = ComposeView(context = requireContext()).apply { |
36 | | - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow) |
37 | | - setContent { |
38 | | - MaterialTheme { |
39 | | - Box( |
40 | | - Modifier |
41 | | - .fillMaxWidth() |
42 | | - .fillMaxHeight() |
43 | | - ) { |
44 | | - val state = viewModel.output.collectAsState(initial = null) |
45 | | - state.value?.let { |
46 | | - MainComposable( |
47 | | - data = it, |
48 | | - insets = insets, |
49 | | - onExit = { activity?.finish() }, |
50 | | - onFilterClick = { viewModel.showFilterView.update { true } }, |
51 | | - updateValue = viewModel.updateValue |
52 | | - ) |
53 | | - } |
54 | | - FilterView( |
55 | | - showFilterState = viewModel.showFilterView, |
56 | | - filterState = viewModel.filteredPref, |
57 | | - insets = insets, |
58 | | - ) |
59 | | - } |
60 | | - } |
61 | | - } |
62 | | - } |
63 | | - |
64 | | - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
65 | | - super.onViewCreated(view, savedInstanceState) |
66 | | - ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets -> |
67 | | - val systemBarsInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) |
68 | | - val imeInsets = windowInsets.getInsets(WindowInsetsCompat.Type.ime()) |
69 | | - insets.value = Insets.of( |
70 | | - 0, |
71 | | - max(systemBarsInsets.top, imeInsets.top), |
72 | | - 0, |
73 | | - max(systemBarsInsets.bottom, imeInsets.bottom) |
74 | | - ) |
75 | | - windowInsets |
76 | | - } |
77 | | - } |
78 | | -} |
| 1 | +// package com.pluto.plugins.datastore.pref.compose.internal |
| 2 | +// |
| 3 | +// import android.os.Bundle |
| 4 | +// import android.view.LayoutInflater |
| 5 | +// import android.view.View |
| 6 | +// import android.view.ViewGroup |
| 7 | +// import androidx.compose.foundation.layout.Box |
| 8 | +// import androidx.compose.foundation.layout.fillMaxHeight |
| 9 | +// import androidx.compose.foundation.layout.fillMaxWidth |
| 10 | +// import androidx.compose.material3.MaterialTheme |
| 11 | +// import androidx.compose.runtime.collectAsState |
| 12 | +// import androidx.compose.runtime.mutableStateOf |
| 13 | +// import androidx.compose.ui.Modifier |
| 14 | +// import androidx.compose.ui.platform.ComposeView |
| 15 | +// import androidx.compose.ui.platform.ViewCompositionStrategy |
| 16 | +// import androidx.core.graphics.Insets |
| 17 | +// import androidx.core.view.ViewCompat |
| 18 | +// import androidx.core.view.WindowInsetsCompat |
| 19 | +// import androidx.fragment.app.Fragment |
| 20 | +// import androidx.fragment.app.viewModels |
| 21 | +// import com.pluto.plugins.datastore.pref.compose.internal.compose.FilterView |
| 22 | +// import com.pluto.plugins.datastore.pref.compose.internal.compose.MainComposable |
| 23 | +// import kotlin.math.max |
| 24 | +// import kotlinx.coroutines.flow.update |
| 25 | +// |
| 26 | +// internal class BaseFragment : Fragment() { |
| 27 | +// |
| 28 | +// private val viewModel by viewModels<BaseViewModel>() |
| 29 | +// private val insets = mutableStateOf(Insets.NONE) |
| 30 | +// |
| 31 | +// override fun onCreateView( |
| 32 | +// inflater: LayoutInflater, |
| 33 | +// container: ViewGroup?, |
| 34 | +// savedInstanceState: Bundle? |
| 35 | +// ) = ComposeView(context = requireContext()).apply { |
| 36 | +// setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow) |
| 37 | +// setContent { |
| 38 | +// MaterialTheme { |
| 39 | +// Box( |
| 40 | +// Modifier |
| 41 | +// .fillMaxWidth() |
| 42 | +// .fillMaxHeight() |
| 43 | +// ) { |
| 44 | +// val state = viewModel.output.collectAsState(initial = null) |
| 45 | +// state.value?.let { |
| 46 | +// MainComposable( |
| 47 | +// data = it, |
| 48 | +// insets = insets, |
| 49 | +// onExit = { activity?.finish() }, |
| 50 | +// onFilterClick = { viewModel.showFilterView.update { true } }, |
| 51 | +// updateValue = viewModel.updateValue |
| 52 | +// ) |
| 53 | +// } |
| 54 | +// FilterView( |
| 55 | +// showFilterState = viewModel.showFilterView, |
| 56 | +// filterState = viewModel.filteredPref, |
| 57 | +// insets = insets, |
| 58 | +// ) |
| 59 | +// } |
| 60 | +// } |
| 61 | +// } |
| 62 | +// } |
| 63 | +// |
| 64 | +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| 65 | +// super.onViewCreated(view, savedInstanceState) |
| 66 | +// ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets -> |
| 67 | +// val systemBarsInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) |
| 68 | +// val imeInsets = windowInsets.getInsets(WindowInsetsCompat.Type.ime()) |
| 69 | +// insets.value = Insets.of( |
| 70 | +// 0, |
| 71 | +// max(systemBarsInsets.top, imeInsets.top), |
| 72 | +// 0, |
| 73 | +// max(systemBarsInsets.bottom, imeInsets.bottom) |
| 74 | +// ) |
| 75 | +// windowInsets |
| 76 | +// } |
| 77 | +// } |
| 78 | +// } |
0 commit comments