Skip to content

Commit

Permalink
Update: Opml export/import handling
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Dec 16, 2024
1 parent 2c16dc9 commit d4f0b76
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions app/src/main/java/com/saulhdev/feeder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
if (uri != null) {
CoroutineScope(Dispatchers.Main).launch {
importOpml(uri)
when (pendingOperation) {
DocumentOperation.IMPORT -> importOpml(uri)
else -> {} // No relevant operation pending
}
}
}
}
Expand All @@ -83,16 +86,25 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {
) { uri ->
if (uri != null) {
CoroutineScope(Dispatchers.Main).launch {
exportOpml(uri)
when (pendingOperation) {
DocumentOperation.EXPORT -> exportOpml(uri)
else -> {} // No relevant operation pending
}
}
}
}

private enum class DocumentOperation { IMPORT, EXPORT }

private var pendingOperation: DocumentOperation? = null

private fun launchOpmlImporter() {
pendingOperation = DocumentOperation.IMPORT
opmlImporterLauncher.launch(arrayOf("application/xml", "text/xml", "text/opml"))
}

private fun launchOpmlExporter() {
pendingOperation = DocumentOperation.EXPORT
opmlExporter.launch("NF-${localTime}.opml")
}

Expand All @@ -101,9 +113,12 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {

WindowCompat.setDecorFitsSystemWindows(window, false)
prefs = FeedPreferences.getInstance(this)
if (intent.hasExtra("import") || intent.hasExtra("export")) {
startTargetActivity()

when {
intent.hasExtra("import") -> launchOpmlImporter()
intent.hasExtra("export") -> launchOpmlExporter()
}

setContent {
navController = rememberNavController()
TransparentSystemBars()
Expand All @@ -128,24 +143,6 @@ class MainActivity : ComponentActivity(), SavedStateRegistryOwner {
NFApplication.mainActivity = this
}

private fun startTargetActivity() {
when {
intent.hasExtra("import") -> {
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
launchOpmlImporter()
finish()
}.launch(intent.getParcelableExtra("import"))
}

else -> {
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
launchOpmlExporter()
finish()
}.launch(intent.getParcelableExtra("export"))
}
}
}

@Composable
fun TransparentSystemBars() {
DisposableEffect(isDarkTheme, prefs.overlayTheme.getValue()) {
Expand Down

0 comments on commit d4f0b76

Please sign in to comment.