-
-
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 branch information
Showing
28 changed files
with
588 additions
and
12 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 | ||
} |
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 | ||
} |
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
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 | ||
) | ||
} |
3 changes: 2 additions & 1 deletion
3
...iapps/gloom/ui/components/LargeToolbar.kt → ...oom/ui/components/toolbar/LargeToolbar.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
24 changes: 24 additions & 0 deletions
24
ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/components/toolbar/SmallToolbar.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,24 @@ | ||
package com.materiiapps.gloom.ui.components.toolbar | ||
|
||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.material3.TopAppBarScrollBehavior | ||
import androidx.compose.runtime.Composable | ||
import com.materiiapps.gloom.ui.components.BackButton | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
fun SmallToolbar( | ||
title: String, | ||
actions: @Composable RowScope.() -> Unit = {}, | ||
scrollBehavior: TopAppBarScrollBehavior? = null | ||
) { | ||
TopAppBar( | ||
title = { Text(text = title) }, | ||
navigationIcon = { BackButton() }, | ||
actions = actions, | ||
scrollBehavior = scrollBehavior | ||
) | ||
} |
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
106 changes: 106 additions & 0 deletions
106
ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screens/explorer/FileViewerScreen.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,106 @@ | ||
package com.materiiapps.gloom.ui.screens.explorer | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Cancel | ||
import androidx.compose.material.pullrefresh.pullRefresh | ||
import androidx.compose.material.pullrefresh.rememberPullRefreshState | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.material3.TopAppBarScrollBehavior | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
import cafe.adriel.voyager.core.screen.Screen | ||
import cafe.adriel.voyager.koin.getScreenModel | ||
import com.materiiapps.gloom.gql.fragment.RepoFile | ||
import com.materiiapps.gloom.ui.components.RefreshIndicator | ||
import com.materiiapps.gloom.ui.components.toolbar.SmallToolbar | ||
import com.materiiapps.gloom.ui.screens.explorer.viewers.MarkdownFileViewer | ||
import com.materiiapps.gloom.ui.screens.explorer.viewers.TextFileViewer | ||
import com.materiiapps.gloom.ui.viewmodels.explorer.FileViewerViewModel | ||
import org.koin.core.parameter.parametersOf | ||
|
||
class FileViewerScreen( | ||
private val owner: String, | ||
private val name: String, | ||
private val branch: String, | ||
private val path: String | ||
): Screen { | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class) | ||
override fun Content() { | ||
val viewModel: FileViewerViewModel = getScreenModel { parametersOf(FileViewerViewModel.Input(owner, name, branch, path)) } | ||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() | ||
val pullRefreshState = rememberPullRefreshState(viewModel.isLoading, onRefresh = { viewModel.getRepoFile() }) | ||
val file = viewModel.file?.gitObject?.onCommit?.file | ||
|
||
Scaffold( | ||
topBar = { Toolbar(scrollBehavior, file) }, | ||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), | ||
contentWindowInsets = WindowInsets(0, 0, 0, 0) | ||
) { pv -> | ||
Box( | ||
modifier = Modifier | ||
.padding(pv) | ||
.fillMaxSize() | ||
.pullRefresh(pullRefreshState) | ||
) { | ||
when(viewModel.hasError) { | ||
true -> { | ||
Icon( | ||
Icons.Filled.Cancel, | ||
contentDescription = null, | ||
tint = MaterialTheme.colorScheme.error, | ||
modifier = Modifier.align(Alignment.Center) | ||
) | ||
} | ||
|
||
false -> FileContent(file) | ||
} | ||
|
||
RefreshIndicator(pullRefreshState, viewModel.isLoading) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun FileContent(file: RepoFile.File?) { | ||
when(file?.fileType?.__typename) { | ||
"MarkdownFileType" -> MarkdownFileViewer(file.fileType?.onMarkdownFileType!!) | ||
"ImageFileType" -> Box(Modifier.fillMaxSize()) | ||
"PdfFileType" -> Box(Modifier.fillMaxSize()) | ||
"TextFileType" -> TextFileViewer(file.fileType?.onTextFileType!!, file.extension ?: "") | ||
else -> {} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun RowScope.FileActions(file: RepoFile.File?) { | ||
// TODO: Different actions for each file type | ||
} | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
private fun Toolbar( | ||
scrollBehavior: TopAppBarScrollBehavior, | ||
file: RepoFile.File? | ||
) { | ||
SmallToolbar( | ||
title = path.split("/").lastOrNull() ?: "File", | ||
actions = { FileActions(file) }, | ||
scrollBehavior = scrollBehavior | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.