-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add export button to account settings (#54)
- 2025.03.1113-dev
- 2025.03.1112-dev
- 2025.02.1111
- 2025.02.1110-dev
- 2025.02.1109-dev
- 2025.02.1108
- 2025.02.1107-dev
- 2025.02.1106-dev
- 2025.02.1105
- 2025.02.1104-dev
- 2025.02.1103
- 2025.02.1102-dev
- 2025.02.1101
- 2025.01.1100-dev
- 2025.01.1099-dev
- 2025.01.1098-dev
- 2025.01.1097
- 2025.01.1096-dev
- 2025.01.1095
- 2025.01.1094
- 2025.01.1093-dev
- 2025.01.1092-dev
- 2025.01.1091-dev
- 2025.01.1090-dev
- 2025.01.1089
- 2024.12.1088-dev
- 2024.12.1087
- 2024.12.1086
- 2024.12.1085-dev
- 2024.12.1084-dev
- 2024.12.1083
- 2024.12.1082-dev
- 2024.12.1081-dev
- 2024.12.1080-dev
- 2024.12.1079-dev
- 2024.11.1078-dev
- 2024.11.1077
- 2024.11.1076-dev
- 2024.11.1075-dev
- 2024.11.1074-dev
- 2024.11.1073
- 2024.11.1072
- 2024.11.1071-dev
- 2024.11.1070
- 2024.10.1069-dev
- 2024.10.1068-dev
- 2024.10.1067
- 2024.10.1066
- 2024.10.1065-dev
- 2024.10.1064-dev
- 2024.10.1063
- 2024.10.1062
- 2024.10.1061
- 2024.10.1060-dev
- 2024.10.1059
- 2024.10.1058
- 2024.10.1057-dev
- 2024.10.1056-dev
- 2024.10.1055
- 2024.10.1054-dev
- 2024.09.1053-dev
- 2024.09.1052
- 2024.09.1051
- 2024.09.1050-dev
- 2024.09.1049
- 2024.09.1048
- 2024.09.1047-dev
- 2024.09.1046
- 2024.09.1045
- 2024.09.1044-dev
- 2024.09.1043-dev
- 2024.09.1042-dev
- 2024.09.1041
- 2024.09.1040
- 2024.09.1039-dev
- 2024.08.1038-dev
- 2024.08.1037
- 2024.08.1036-dev
- 2024.08.1035-dev
- 2024.08.1034-dev
- 2024.08.1033-dev
- 2024.08.1032-dev
- 2024.08.1031
- 2024.08.1030
- 2024.08.1029-dev
- 2024.08.1028-dev
- 2024.08.1027
- 2024.08.1026-dev
- 2024.08.1025-dev
- 2024.08.1024-dev
- 2024.08.1023-dev
- 2024.08.1022-dev
- 2024.08.1021-dev
- 2024.08.1020
- 2024.07.1019
- 2024.07.1018-dev
- 2024.07.1017-dev
- 2024.07.1016
- 2024.07.1015
- 2024.07.1014
- 2024.07.1013
- 2024.07.1012
- 2024.07.1011
- 2024.07.1010
- 2024.07.1009
- 2024.07.1008
- 2024.07.1007
- 2024.07.1006
- 2024.07.1005
- 2024.07.1004
- 2024.07.1003
- 2024.07.1002
- 2024.07.1001
Showing
8 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.jocmp.basilreader | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.core.content.FileProvider | ||
import com.jocmp.basil.Account | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.nio.file.StandardCopyOption | ||
|
||
class OPMLExporter( | ||
private val context: Context, | ||
) { | ||
fun export(account: Account) { | ||
val exports = File(context.filesDir, "exports") | ||
exports.mkdirs() | ||
val export = File(exports, "${account.displayName}.xml") | ||
|
||
val source = File(account.opmlFile.path).toPath() | ||
val target = export.toPath() | ||
|
||
val result = Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING) | ||
|
||
return try { | ||
val uri = context.fileURI(result.toFile()) | ||
val shareIntent = Intent(Intent.ACTION_SEND).apply { | ||
type = "text/xml" | ||
putExtra(Intent.EXTRA_STREAM, uri) | ||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||
} | ||
|
||
context.startActivity( | ||
Intent.createChooser( | ||
shareIntent, | ||
context.getString(R.string.opml_exporter_chooser_title, account.displayName) | ||
) | ||
) | ||
} catch (e: IllegalArgumentException) { | ||
// return | ||
} | ||
} | ||
} | ||
|
||
private fun Context.fileURI(file: File) = | ||
FileProvider.getUriForFile(this, "${packageName}.fileprovider", file) |
11 changes: 10 additions & 1 deletion
11
app/src/main/java/com/jocmp/basilreader/ui/accounts/AccountSettingsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
package com.jocmp.basilreader.ui.accounts | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.jocmp.basil.Account | ||
import com.jocmp.basilreader.OPMLExporter | ||
import org.koin.androidx.compose.koinViewModel | ||
|
||
@Composable | ||
fun AccountSettingsScreen( | ||
viewModel: AccountSettingsViewModel = koinViewModel(), | ||
goBack: () -> Unit, | ||
) { | ||
val context = LocalContext.current | ||
|
||
AccountSettingsView( | ||
defaultDisplayName = viewModel.displayName, | ||
removeAccount = { | ||
viewModel.removeAccount() | ||
goBack() | ||
}, | ||
submit = viewModel::submitName | ||
submit = viewModel::submitName, | ||
exportOPML = { | ||
context.exportOPML(account = viewModel.account) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/jocmp/basilreader/ui/accounts/ContextExportOPMLExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.jocmp.basilreader.ui.accounts | ||
|
||
import android.content.Context | ||
import com.jocmp.basil.Account | ||
import com.jocmp.basilreader.OPMLExporter | ||
|
||
fun Context.exportOPML(account: Account) { | ||
OPMLExporter(this).export(account) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<paths> | ||
<files-path name="exports" path="exports/"/> | ||
</paths> |