@@ -9,31 +9,40 @@ import androidx.compose.foundation.layout.fillMaxWidth
99import androidx.compose.foundation.layout.padding
1010import androidx.compose.foundation.lazy.LazyColumn
1111import androidx.compose.foundation.lazy.itemsIndexed
12+ import androidx.compose.material3.DropdownMenu
13+ import androidx.compose.material3.DropdownMenuItem
1214import androidx.compose.material3.HorizontalDivider
1315import androidx.compose.material3.LinearProgressIndicator
1416import androidx.compose.material3.Text
1517import androidx.compose.runtime.Composable
1618import androidx.compose.runtime.LaunchedEffect
19+ import androidx.compose.runtime.getValue
1720import androidx.compose.runtime.mutableStateListOf
1821import androidx.compose.runtime.mutableStateOf
1922import androidx.compose.runtime.remember
2023import androidx.compose.runtime.rememberCoroutineScope
24+ import androidx.compose.runtime.setValue
2125import androidx.compose.ui.Modifier
2226import androidx.compose.ui.platform.LocalContext
2327import androidx.compose.ui.res.stringResource
2428import androidx.compose.ui.text.font.FontWeight
2529import androidx.compose.ui.text.style.TextAlign
2630import androidx.compose.ui.unit.dp
2731import androidx.compose.ui.unit.sp
32+ import com.raival.compose.file.explorer.App.Companion.globalClass
2833import com.raival.compose.file.explorer.R
2934import com.raival.compose.file.explorer.common.emptyString
35+ import com.raival.compose.file.explorer.common.fromJson
36+ import com.raival.compose.file.explorer.common.toJson
3037import com.raival.compose.file.explorer.common.ui.BottomSheetDialog
3138import com.raival.compose.file.explorer.common.ui.DynamicSelectTextField
3239import com.raival.compose.file.explorer.common.ui.Space
3340import com.raival.compose.file.explorer.screen.main.tab.files.FilesTab
3441import com.raival.compose.file.explorer.screen.main.tab.files.holder.LocalFileHolder
3542import com.raival.compose.file.explorer.screen.main.tab.files.holder.OpenWithActivityHolder
43+ import com.raival.compose.file.explorer.screen.main.tab.files.misc.DefaultOpeningMethods
3644import com.raival.compose.file.explorer.screen.main.tab.files.misc.FileMimeType.anyFileType
45+ import com.raival.compose.file.explorer.screen.main.tab.files.misc.OpeningMethod
3746import com.raival.compose.file.explorer.screen.main.tab.files.ui.ItemRow
3847import com.raival.compose.file.explorer.screen.main.tab.files.ui.ItemRowIcon
3948import kotlinx.coroutines.Dispatchers
@@ -122,10 +131,13 @@ fun OpenWithAppListDialog(
122131
123132 LazyColumn {
124133 itemsIndexed(appsList, key = { index, item -> item.id }) { index, item ->
125- Modifier
126- .fillMaxWidth()
134+ var showOptionsMenu by remember(item.id) {
135+ mutableStateOf(false )
136+ }
137+
127138 Column (
128139 Modifier
140+ .fillMaxWidth()
129141 .animateItem()
130142 .combinedClickable(
131143 onClick = {
@@ -135,6 +147,9 @@ fun OpenWithAppListDialog(
135147 item.name
136148 )
137149 onDismissRequest()
150+ },
151+ onLongClick = {
152+ showOptionsMenu = true
138153 }
139154 )
140155 ) {
@@ -158,6 +173,35 @@ fun OpenWithAppListDialog(
158173 modifier = Modifier .padding(start = 56 .dp),
159174 thickness = 0.5 .dp
160175 )
176+
177+ DropdownMenu (
178+ expanded = showOptionsMenu,
179+ onDismissRequest = { showOptionsMenu = false }
180+ ) {
181+ DropdownMenuItem (
182+ text = { Text (text = stringResource(R .string.set_as_default_for_this_type)) },
183+ onClick = {
184+ val defOpeningMethods: DefaultOpeningMethods =
185+ fromJson(globalClass.preferencesManager.defaultOpeningMethods)
186+ ? : DefaultOpeningMethods ()
187+ globalClass.preferencesManager.defaultOpeningMethods =
188+ DefaultOpeningMethods (
189+ (defOpeningMethods.openingMethods.filter { it.extension != contentHolder.extension } + OpeningMethod (
190+ extension = contentHolder.extension,
191+ packageName = item.packageName,
192+ className = item.name
193+ ))
194+ ).toJson()
195+ contentHolder.openFileWithPackage(
196+ context,
197+ item.packageName,
198+ item.name
199+ )
200+ showOptionsMenu = false
201+ onDismissRequest()
202+ }
203+ )
204+ }
161205 }
162206 }
163207 }
0 commit comments