-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,636 additions
and
14 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
api/src/commonMain/graphql/com/materiiapps/gloom/gql/fragments/NodeId.fragment.graphql
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 @@ | ||
fragment NodeId on Node { | ||
id | ||
__typename | ||
} |
3 changes: 3 additions & 0 deletions
3
...c/commonMain/graphql/com/materiiapps/gloom/gql/fragments/RawMarkdownFile.fragment.graphql
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,3 @@ | ||
fragment RawMarkdownFile on MarkdownFileType { | ||
contentRaw | ||
} |
40 changes: 40 additions & 0 deletions
40
api/src/commonMain/graphql/com/materiiapps/gloom/gql/fragments/RepoFile.fragment.graphql
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,40 @@ | ||
fragment RepoFile on Repository { | ||
id | ||
gitObject: object(expression: $branch) { | ||
__typename | ||
...NodeId | ||
... on Commit { | ||
file(path: $path) { | ||
extension | ||
path | ||
fileType { | ||
__typename | ||
... on MarkdownFileType { | ||
contentHTML | ||
} | ||
... on ImageFileType { | ||
url | ||
} | ||
... on PdfFileType { | ||
url | ||
} | ||
... on TextFileType { | ||
contentRaw | ||
} | ||
} | ||
} | ||
id | ||
} | ||
} | ||
viewerCanPush | ||
ref(qualifiedName: $branch) { | ||
id | ||
viewerCanCommitToBranch | ||
target { | ||
id | ||
oid | ||
} | ||
__typename | ||
} | ||
__typename | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/commonMain/graphql/com/materiiapps/gloom/gql/queries/RawMarkdown.query.graphql
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,18 @@ | ||
query RawMarkdown( | ||
$owner: String! | ||
$name: String! | ||
$branch: String! | ||
$path: String! | ||
) { | ||
repository(owner: $owner, name: $name) { | ||
gitObject: object(expression: $branch) { | ||
... on Commit { | ||
file(path: $path) { | ||
fileType { | ||
...RawMarkdownFile | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
api/src/commonMain/graphql/com/materiiapps/gloom/gql/queries/RepoFile.query.graphql
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,12 @@ | ||
query RepoFile( | ||
$owner: String! | ||
$name: String! | ||
$branch: String! | ||
$path: String! | ||
) { | ||
repository(owner: $owner, name: $name) { | ||
__typename | ||
...RepoFile | ||
id | ||
} | ||
} |
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
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
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
72 changes: 72 additions & 0 deletions
72
ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/components/CodeText.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,72 @@ | ||
package com.materiiapps.gloom.ui.components | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.buildAnnotatedString | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.TextUnit | ||
import androidx.compose.ui.unit.sp | ||
import com.materiiapps.gloom.ui.utils.fromExtension | ||
import dev.snipme.highlights.Highlights | ||
import dev.snipme.highlights.model.BoldHighlight | ||
import dev.snipme.highlights.model.ColorHighlight | ||
import dev.snipme.highlights.model.SyntaxLanguage | ||
import dev.snipme.highlights.model.SyntaxTheme | ||
|
||
@Composable | ||
fun CodeText( | ||
text: String, | ||
extension: String, | ||
theme: SyntaxTheme, | ||
softWrap: Boolean = false, | ||
fontSize: TextUnit = 13.sp, | ||
modifier: Modifier = Modifier | ||
) { | ||
val hl = remember(text, theme) { | ||
Highlights | ||
.default() | ||
.getBuilder() | ||
.code(text) | ||
.language(SyntaxLanguage.fromExtension(extension)) | ||
.theme(theme) | ||
.build() | ||
} | ||
val highlights = remember(hl) { hl.getHighlights() } | ||
|
||
Text( | ||
text = buildAnnotatedString { | ||
append(hl.getCode()) | ||
|
||
if(!(extension.isBlank() || extension == ".txt")) { | ||
highlights | ||
.filterIsInstance<ColorHighlight>() | ||
.forEach { | ||
addStyle( | ||
SpanStyle(color = Color(it.rgb).copy(alpha = 1f)), | ||
start = it.location.start, | ||
end = it.location.end | ||
) | ||
} | ||
|
||
highlights | ||
.filterIsInstance<BoldHighlight>() | ||
.forEach { | ||
addStyle( | ||
SpanStyle(fontWeight = FontWeight.Bold), | ||
start = it.location.start, | ||
end = it.location.end | ||
) | ||
} | ||
} | ||
}, | ||
fontFamily = FontFamily.Monospace, | ||
softWrap = softWrap, | ||
fontSize = fontSize, | ||
modifier = modifier | ||
) | ||
} |
44 changes: 44 additions & 0 deletions
44
ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/components/DownloadButton.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,44 @@ | ||
package com.materiiapps.gloom.ui.components | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Download | ||
import androidx.compose.material.icons.outlined.CheckCircleOutline | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.benasher44.uuid.uuid4 | ||
import com.materiiapps.gloom.Res | ||
import com.materiiapps.gloom.domain.manager.DownloadManager | ||
import com.materiiapps.gloom.ui.widgets.alerts.LocalAlertController | ||
import dev.icerock.moko.resources.compose.stringResource | ||
import org.koin.androidx.compose.get | ||
|
||
@Composable | ||
fun DownloadButton( | ||
downloadUrl: String, | ||
modifier: Modifier = Modifier, | ||
fileName: String = downloadUrl.split("/").lastOrNull() ?: "${uuid4()}.blob", | ||
onDownloadFinished: (String) -> Unit = {} | ||
) { | ||
val downloadManager: DownloadManager = get() | ||
val alertController = LocalAlertController.current | ||
val downloadingText = stringResource(Res.strings.msg_downloading_file, fileName) | ||
val downloadedText = stringResource(Res.strings.msg_download_completed) | ||
|
||
IconButton( | ||
onClick = { | ||
alertController.showText(downloadingText, icon = Icons.Filled.Download) | ||
downloadManager.download(downloadUrl) { | ||
alertController.showText(downloadedText, icon = Icons.Outlined.CheckCircleOutline) | ||
onDownloadFinished(it) | ||
} | ||
}, | ||
modifier = modifier | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Download, | ||
contentDescription = stringResource(Res.strings.action_download) | ||
) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/components/ErrorMessage.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,60 @@ | ||
package com.materiiapps.gloom.ui.components | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Cancel | ||
import androidx.compose.material3.FilledTonalButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import com.materiiapps.gloom.Res | ||
import dev.icerock.moko.resources.compose.stringResource | ||
|
||
@Composable | ||
fun ErrorMessage( | ||
message: String, | ||
modifier: Modifier = Modifier, | ||
onRetryClick: (() -> Unit)? = null | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = modifier | ||
.padding(16.dp) | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Cancel, | ||
contentDescription = null, | ||
tint = MaterialTheme.colorScheme.error, | ||
modifier = Modifier.size(50.dp) | ||
) | ||
|
||
Text( | ||
message, | ||
style = MaterialTheme.typography.titleMedium, | ||
fontWeight = FontWeight.Bold, | ||
textAlign = TextAlign.Center | ||
) | ||
|
||
Spacer(modifier = Modifier.height(16.dp)) | ||
|
||
onRetryClick?.let { | ||
FilledTonalButton( | ||
onClick = onRetryClick, | ||
) { | ||
Text(stringResource(Res.strings.action_try_again)) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.