Skip to content

Commit

Permalink
feat(export): add attach info option when export as opml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jan 26, 2024
1 parent 69d225c commit 5183883
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class OpmlService @Inject constructor(
mutableMapOf(
"text" to it.group.name,
"title" to it.group.name,
"isDefault" to (it.group.id == defaultGroup.id).toString()
).apply {
if (attachInfo) {
put("isDefault", (it.group.id == defaultGroup.id).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class CrashHandler(private val context: Context) : UncaughtExceptionHandler {
*/
override fun uncaughtException(p0: Thread, p1: Throwable) {
val causeMessage = getCauseMessage(p1)
Log.e("RLog", "uncaughtException: $causeMessage")
Log.e("RLog", "uncaughtException: $causeMessage", p1)
Looper.myLooper() ?: Looper.prepare()
context.showToastLong(causeMessage)
Looper.loop()
p1.printStackTrace()
// android.os.Process.killProcess(android.os.Process.myPid());
// exitProcess(1)
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/me/ash/reader/ui/component/base/RadioDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package me.ash.reader.ui.component.base

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
Expand All @@ -27,6 +29,7 @@ fun RadioDialog(
modifier: Modifier = Modifier,
visible: Boolean = false,
title: String = "",
description: String? = null,
options: List<RadioDialogOption> = emptyList(),
onDismissRequest: () -> Unit = {},
) {
Expand All @@ -44,6 +47,14 @@ fun RadioDialog(
},
text = {
LazyColumn {
if (description != null) {
item {
Text(text = description)
if (options.isNotEmpty()) {
Spacer(modifier = Modifier.height(16.dp))
}
}
}
items(options) { option ->
Row(
modifier = Modifier
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/me/ash/reader/ui/ext/DateExt.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package me.ash.reader.ui.ext

import android.annotation.SuppressLint
import android.content.Context
import androidx.core.os.ConfigurationCompat
import me.ash.reader.R
import java.text.DateFormat
import java.text.ParsePosition
import java.text.SimpleDateFormat
import java.util.*
import java.util.Calendar
import java.util.Date

@SuppressLint("SimpleDateFormat")
object DateFormat {
val YYYY_MM_DD_HH_MM_SS = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val YYYY_MM_DD_DASH_HH_MM_SS = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")
}

fun Date.toString(format: SimpleDateFormat): String {
return format.format(this)
}

fun Date.formatAsString(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ import me.ash.reader.ui.component.base.RadioDialogOption
import me.ash.reader.ui.component.base.Subtitle
import me.ash.reader.ui.component.base.TextFieldDialog
import me.ash.reader.ui.component.base.Tips
import me.ash.reader.ui.ext.DateFormat
import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.getCurrentVersion
import me.ash.reader.ui.ext.showToast
import me.ash.reader.ui.ext.showToastLong
import me.ash.reader.ui.ext.toString
import me.ash.reader.ui.page.settings.SettingItem
import me.ash.reader.ui.page.settings.accounts.connection.AccountConnection
import me.ash.reader.ui.theme.palette.onLight
Expand Down Expand Up @@ -403,16 +405,17 @@ fun AccountDetailsPage(
RadioDialog(
visible = exportOPMLModeDialogVisible,
title = stringResource(R.string.export_as_opml),
description = stringResource(R.string.additional_info_desc),
options = listOf(
RadioDialogOption(
text = stringResource(R.string.attach_info),
text = stringResource(R.string.include_additional_info),
selected = uiState.exportOPMLMode == ExportOPMLMode.ATTACH_INFO,
) {
viewModel.changeExportOPMLMode(ExportOPMLMode.ATTACH_INFO)
launcherOPMLFile(context, launcher)
},
RadioDialogOption(
text = stringResource(R.string.no_attach),
text = stringResource(R.string.exclude),
selected = uiState.exportOPMLMode == ExportOPMLMode.NO_ATTACH,
) {
viewModel.changeExportOPMLMode(ExportOPMLMode.NO_ATTACH)
Expand All @@ -424,6 +427,12 @@ fun AccountDetailsPage(
}
}

private fun launcherOPMLFile(context: Context, launcher: ManagedActivityResultLauncher<String, Uri?>) {
launcher.launch("${context.getString(R.string.read_you)}-${context.getCurrentVersion()}-export-${Date()}.opml")
private fun launcherOPMLFile(
context: Context,
launcher: ManagedActivityResultLauncher<String, Uri?>,
) {
launcher.launch("" +
"${context.getString(R.string.read_you)}-" +
"${context.getCurrentVersion()}-export-" +
"${Date().toString(DateFormat.YYYY_MM_DD_DASH_HH_MM_SS)}.opml")
}
5 changes: 3 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
<string name="default_browser">强制使用默认浏览器</string>
<string name="open_link_something_wrong">“打开链接”设置被忽略,因为出现了错误。</string>
<string name="open_link_specific_browser_not_selected">未选择</string>
<string name="attach_info">附加信息</string>
<string name="no_attach">无附加</string>
<string name="include_additional_info">包含附加信息</string>
<string name="exclude">不包含</string>
<string name="additional_info_desc">附加信息中包含了每个订阅源的配置选项,例如是否允许通知、是否全文解析等。当您期望将导出的 OPML 文件用于其他阅读器时,请选择“不包含”。</string>
</resources>
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
<string name="open_link_specific_browser">Browser</string>
<string name="open_link_something_wrong">\"Open Link\" setting ignored because something went wrong.</string>
<string name="open_link_ask_dialog_title">Open with…</string>
<string name="attach_info">Attach info</string>
<string name="no_attach">No attach</string>
<string name="include_additional_info">Include additional info</string>
<string name="exclude">Exclude</string>
<string name="additional_info_desc">Additional information includes configuration options for each feed, such as whether to allow notification, parse full content, etc. When you intend to use the exported OPML file with other readers, please select \"Exclude\".</string>
</resources>

0 comments on commit 5183883

Please sign in to comment.