Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YangDai2003 committed Jun 7, 2024
1 parent 6e5479c commit b68ba7d
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ the [Guide](Guide.md).
- **Build Tool**: Gradle with Kotlin DSL
- **Android Version**: The application targets Android SDK version 34 and is compatible with devices
running Android SDK version 29 and above.
- **Kotlin Version**: The application uses Kotlin version 1.5.11.
- **Kotlin Version**: The application uses Kotlin version 2.0.0.
- **Java Version**: The application uses Java version 17.

## Architecture
Expand Down
2 changes: 1 addition & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ OpenNote是一款完全使用Compose构建的现代化Android记事本应用程
- **编程语言**:Kotlin
- **构建工具**:Gradle和Kotlin DSL
- **Android版本**:应用程序目标为Android SDK版本34,并且与运行Android SDK版本29及以上的设备兼容。
- **Kotlin版本**应用程序使用Kotlin版本1.5.11
- **Kotlin版本**应用程序使用Kotlin版本2.0.0
- **Java版本**:应用程序使用Java版本17。

## 架构
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId = "com.yangdai.opennote"
minSdk = 29
targetSdk = 34
versionCode = 129
versionName = "1.2.9"
versionCode = 130
versionName = "1.3.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
<application
android:name=".NoteApp"
android:allowBackup="true"
android:appCategory="productivity"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:appCategory="productivity"
android:manageSpaceActivity=".ManageSpaceActivity"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
Expand All @@ -41,13 +41,20 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.CREATE_NOTE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down Expand Up @@ -86,8 +93,8 @@
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.yangdai.opennote.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
Expand Down
15 changes: 3 additions & 12 deletions app/src/main/java/com/yangdai/opennote/ManageSpaceActivity.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package com.yangdai.opennote

import android.app.Activity
import android.app.PendingIntent
import android.content.Intent
import android.os.Bundle
import androidx.core.app.TaskStackBuilder
import androidx.core.net.toUri
import com.yangdai.opennote.presentation.navigation.Screen
import com.yangdai.opennote.presentation.util.Constants.LINK
import com.yangdai.opennote.presentation.util.sendPendingIntent

class ManageSpaceActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val intent =
Intent(this, MainActivity::class.java).setData("$LINK/${Screen.Settings.route}".toUri())
val pendingIntent = TaskStackBuilder.create(this).run {
addNextIntentWithParentStack(intent)
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
pendingIntent?.send()
this.sendPendingIntent("$LINK/${Screen.Settings.route}")
finish()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,42 @@ import androidx.compose.ui.viewinterop.AndroidView
import com.yangdai.opennote.presentation.theme.linkColor
import com.yangdai.opennote.presentation.util.rememberCustomTabsIntent

data class MarkdownStyles(
val hexTextColor: String,
val hexCodeBackgroundColor: String,
val hexPreBackgroundColor: String,
val hexQuoteBackgroundColor: String,
val hexLinkColor: String,
val hexBorderColor: String
)

private fun Int.toHexColor(): String {
return String.format("#%06X", 0xFFFFFF and this)
}

private fun createMarkdownStyles(colorScheme: ColorScheme) =
MarkdownStyles(
hexTextColor = colorScheme.onSurface.toArgb().toHexColor(),
hexCodeBackgroundColor = colorScheme.surfaceVariant.toArgb().toHexColor(),
hexPreBackgroundColor = colorScheme.surfaceColorAtElevation(1.dp).toArgb().toHexColor(),
hexQuoteBackgroundColor = colorScheme.secondaryContainer.toArgb().toHexColor(),
hexLinkColor = linkColor.toArgb().toHexColor(),
hexBorderColor = colorScheme.outline.toArgb().toHexColor()
)


@SuppressLint("SetJavaScriptEnabled")
@Composable
fun MarkdownText(
html: String,
colorScheme: ColorScheme = MaterialTheme.colorScheme
) {

val hexTextColor = remember(colorScheme) {
String.format("#%06X", 0xFFFFFF and colorScheme.onSurface.toArgb())
}
val hexCodeBackgroundColor = remember(colorScheme) {
String.format("#%06X", 0xFFFFFF and colorScheme.surfaceVariant.toArgb())
}
val hexPreBackgroundColor = remember(colorScheme) {
String.format("#%06X", 0xFFFFFF and colorScheme.surfaceColorAtElevation(1.dp).toArgb())
}
val hexQuoteBackgroundColor = remember(colorScheme) {
String.format("#%06X", 0xFFFFFF and colorScheme.secondaryContainer.toArgb())
}
val hexLinkColor = remember(colorScheme) {
String.format("#%06X", 0xFFFFFF and linkColor.toArgb())
}
val hexBorderColor = remember(colorScheme) {
String.format("#%06X", 0xFFFFFF and colorScheme.outline.toArgb())
val markdownStyles = remember(colorScheme) {
createMarkdownStyles(colorScheme)
}

val data by remember(
html,
hexTextColor,
hexCodeBackgroundColor,
hexPreBackgroundColor,
hexQuoteBackgroundColor,
hexLinkColor,
hexBorderColor
) {
val data by remember(html, markdownStyles) {
mutableStateOf(
"""
<!DOCTYPE html>
Expand All @@ -66,7 +67,7 @@ fun MarkdownText(
<script>
MathJax = {
tex: {
inlineMath: [['${'$'}', '${'$'}'], ['\\(', '\\)']]
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
Expand All @@ -78,17 +79,17 @@ fun MarkdownText(
mermaid.initialize({ startOnLoad: true });
</script>
<style type="text/css">
body { color: $hexTextColor; padding: 0px; margin: 0px; }
a { color: $hexLinkColor; }
p code { background-color: $hexCodeBackgroundColor; padding: 4px 4px 2px 4px; margin: 4px; border-radius: 4px; }
td code { background-color: $hexCodeBackgroundColor; padding: 4px 4px 2px 4px; margin: 4px; border-radius: 4px; }
pre { background-color: $hexPreBackgroundColor; display: block; white-space: nowrap; padding: 16px; overflow-x: auto; }
blockquote { border-left: 4px solid ${hexQuoteBackgroundColor}; padding-left: 0px; margin-left: 0px; padding-right: 0px; margin-right: 0px; }
body { color: ${markdownStyles.hexTextColor}; padding: 0px; margin: 0px; }
a { color: ${markdownStyles.hexLinkColor}; }
p code { background-color: ${markdownStyles.hexCodeBackgroundColor}; padding: 4px 4px 2px 4px; margin: 4px; border-radius: 4px; }
td code { background-color: ${markdownStyles.hexCodeBackgroundColor}; padding: 4px 4px 2px 4px; margin: 4px; border-radius: 4px; }
pre { background-color: ${markdownStyles.hexPreBackgroundColor}; display: block; padding: 16px; overflow-x: auto; }
blockquote { border-left: 4px solid ${markdownStyles.hexQuoteBackgroundColor}; padding-left: 0px; margin-left: 0px; padding-right: 0px; margin-right: 0px; }
blockquote > * { margin-left: 16px; padding: 0px; }
blockquote blockquote { margin: 16px; }
table { border-collapse: collapse; display: block; white-space: nowrap; overflow-x: auto; margin-right: 1px; }
th, td { border: 1px solid $hexBorderColor; padding: 6px 13px; line-height: 1.5; }
tr:nth-child(even) { background-color: $hexPreBackgroundColor; }
th, td { border: 1px solid ${markdownStyles.hexBorderColor}; padding: 6px 13px; line-height: 1.5; }
tr:nth-child(even) { background-color: ${markdownStyles.hexPreBackgroundColor}; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.yangdai.opennote.presentation.glance

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.app.TaskStackBuilder
import androidx.core.net.toUri
import androidx.glance.GlanceId
import androidx.glance.GlanceModifier
import androidx.glance.GlanceTheme
Expand Down Expand Up @@ -50,6 +46,7 @@ import com.yangdai.opennote.data.di.AppModule
import com.yangdai.opennote.data.local.entity.NoteEntity
import com.yangdai.opennote.data.repository.NoteRepositoryImpl
import com.yangdai.opennote.presentation.util.Constants.LINK
import com.yangdai.opennote.presentation.util.sendPendingIntent

class NoteListWidget : GlanceAppWidget() {

Expand Down Expand Up @@ -124,7 +121,7 @@ class NoteListWidget : GlanceAppWidget() {
Column(
modifier = GlanceModifier
.fillMaxWidth()
.padding(horizontal = 10.dp)
.padding(horizontal = 10.dp, vertical = 2.dp)
.background(GlanceTheme.colors.secondaryContainer)
.appWidgetInnerCornerRadius()
.padding(4.dp)
Expand Down Expand Up @@ -184,13 +181,7 @@ class NoteAction : ActionCallback {
glanceId: GlanceId,
parameters: ActionParameters
) {
val intent = Intent(context, MainActivity::class.java)
.setData("$LINK/note/${parameters[destinationKey]}".toUri())
val pendingIntent = TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(intent)
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
pendingIntent?.send()
context.sendPendingIntent("$LINK/note/${parameters[destinationKey]}")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yangdai.opennote.presentation.navigation

import android.content.Intent
import android.os.Build
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.FastOutLinearInEasing
Expand Down Expand Up @@ -114,21 +115,31 @@ fun AnimatedNavHost(
)
}

composable(
route = Note.route,
deepLinks = listOf(
navDeepLink {
action = Intent.ACTION_SEND
mimeType = "text/*"
},
navDeepLink {
action = Intent.ACTION_VIEW
mimeType = "text/*"
},
val noteNavDeepLink = mutableListOf(
navDeepLink {
action = Intent.ACTION_SEND
mimeType = "text/*"
},
navDeepLink {
action = Intent.ACTION_VIEW
mimeType = "text/*"
},
navDeepLink {
uriPattern = "$LINK/${Note.route}"
}
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
noteNavDeepLink.add(
navDeepLink {
uriPattern = "$LINK/${Note.route}"
action = Intent.ACTION_CREATE_NOTE
}
),
)
}

composable(
route = Note.route,
deepLinks = noteNavDeepLink,
arguments = listOf(
navArgument("id") {
type = NavType.LongType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sealed class Screen(val route: String) {
@Serializable
data object Home : Screen("home")

@Serializable
data object Note : Screen("note/{id}") {
fun passId(id: Long): String {
return this.route.replace("{id}", id.toString())
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/yangdai/opennote/presentation/util/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.yangdai.opennote.presentation.util

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.icu.text.DateFormat
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.core.app.TaskStackBuilder
import androidx.core.net.toUri
import com.yangdai.opennote.MainActivity
import java.util.Date

fun Intent.isTextMimeType() = type?.startsWith(Constants.MIME_TYPE_TEXT) == true
Expand Down Expand Up @@ -55,3 +59,13 @@ fun rememberCustomTabsIntent(): CustomTabsIntent {
.build()
}
}

fun Context.sendPendingIntent(data: String) {
val intent = Intent(this, MainActivity::class.java)
.setData(data.toUri())
val pendingIntent = TaskStackBuilder.create(this).run {
addNextIntentWithParentStack(intent)
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
pendingIntent?.send()
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ class SharedViewModel @Inject constructor(
val html = snapshotFlow { contentState.text }
.debounce(100)
.mapLatest { renderer.render(parser.parse(it.toString())) }
.flowOn(Dispatchers.IO)
.flowOn(Dispatchers.Default)
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
started = SharingStarted.WhileSubscribed(5_000L),
initialValue = ""
)

Expand Down
Loading

0 comments on commit b68ba7d

Please sign in to comment.