Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ dependencies {
ksp(libs.androidx.room.compiler)
implementation(libs.androidx.room.ktx)

implementation(platform(libs.bom))
implementation(libs.editor)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/paulcoding/hviewer/network/Github.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object Github {
downloadAndGetConfig()
} else {
log("Already latest version", "check update")
_stateFlow.update { it.copy(siteConfigs = siteConfigs) }
_stateFlow.update { it.copy(siteConfigs = currentConfigs) }
}
}
} catch (e: Exception) {
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/com/paulcoding/hviewer/ui/component/H7Tap.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.paulcoding.hviewer.ui.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.paulcoding.hviewer.BuildConfig
import com.paulcoding.hviewer.helper.makeToast

@Composable
fun H7Tap(modifier: Modifier = Modifier, onDevModeChange: (Boolean) -> Unit) {
var tapCount by remember { mutableIntStateOf(0) }
var lastTapTime by remember { mutableLongStateOf(0L) }
Box(modifier = modifier
.padding(16.dp)
.clickable {
val current = System.currentTimeMillis()
if (current - lastTapTime > 2000) {
tapCount = 1
} else {
tapCount++
if (tapCount >= 7) {
makeToast("Dev Mode Enabled")
onDevModeChange(true)
tapCount = 0
}
}
lastTapTime = current

}) {
Text("Version ${BuildConfig.VERSION_NAME}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fun HFavoriteIcon(modifier: Modifier = Modifier, isFavorite: Boolean, onClick: (

@Composable
fun HIcon(
modifier: Modifier = Modifier,
imageVector: ImageVector = SettingsIcon,
modifier: Modifier = Modifier,
description: String = "",
tint: Color = LocalContentColor.current,
onClick: () -> Unit
Expand Down
82 changes: 82 additions & 0 deletions app/src/main/java/com/paulcoding/hviewer/ui/icon/JS.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.paulcoding.hviewer.ui.icon

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

public val Javascript: ImageVector
get() {
if (_Javascript != null) {
return _Javascript!!
}
_Javascript = ImageVector.Builder(
name = "Javascript",
defaultWidth = 24.dp,
defaultHeight = 24.dp,
viewportWidth = 960f,
viewportHeight = 960f
).apply {
path(
fill = SolidColor(Color.Black),
fillAlpha = 1.0f,
stroke = null,
strokeAlpha = 1.0f,
strokeLineWidth = 1.0f,
strokeLineCap = StrokeCap.Butt,
strokeLineJoin = StrokeJoin.Miter,
strokeLineMiter = 1.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(300f, 600f)
quadToRelative(-25f, 0f, -42.5f, -17.5f)
reflectiveQuadTo(240f, 540f)
verticalLineToRelative(-40f)
horizontalLineToRelative(60f)
verticalLineToRelative(40f)
horizontalLineToRelative(60f)
verticalLineToRelative(-180f)
horizontalLineToRelative(60f)
verticalLineToRelative(180f)
quadToRelative(0f, 25f, -17.5f, 42.5f)
reflectiveQuadTo(360f, 600f)
close()
moveToRelative(220f, 0f)
quadToRelative(-17f, 0f, -28.5f, -11.5f)
reflectiveQuadTo(480f, 560f)
verticalLineToRelative(-40f)
horizontalLineToRelative(60f)
verticalLineToRelative(20f)
horizontalLineToRelative(80f)
verticalLineToRelative(-40f)
horizontalLineTo(520f)
quadToRelative(-17f, 0f, -28.5f, -11.5f)
reflectiveQuadTo(480f, 460f)
verticalLineToRelative(-60f)
quadToRelative(0f, -17f, 11.5f, -28.5f)
reflectiveQuadTo(520f, 360f)
horizontalLineToRelative(120f)
quadToRelative(17f, 0f, 28.5f, 11.5f)
reflectiveQuadTo(680f, 400f)
verticalLineToRelative(40f)
horizontalLineToRelative(-60f)
verticalLineToRelative(-20f)
horizontalLineToRelative(-80f)
verticalLineToRelative(40f)
horizontalLineToRelative(100f)
quadToRelative(17f, 0f, 28.5f, 11.5f)
reflectiveQuadTo(680f, 500f)
verticalLineToRelative(60f)
quadToRelative(0f, 17f, -11.5f, 28.5f)
reflectiveQuadTo(640f, 600f)
close()
}
}.build()
return _Javascript!!
}

private var _Javascript: ImageVector? = null
76 changes: 76 additions & 0 deletions app/src/main/java/com/paulcoding/hviewer/ui/icon/Save.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.paulcoding.hviewer.ui.icon

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

public val Save: ImageVector
get() {
if (_Save != null) {
return _Save!!
}
_Save = ImageVector.Builder(
name = "Save",
defaultWidth = 24.dp,
defaultHeight = 24.dp,
viewportWidth = 960f,
viewportHeight = 960f
).apply {
path(
fill = SolidColor(Color.Black),
fillAlpha = 1.0f,
stroke = null,
strokeAlpha = 1.0f,
strokeLineWidth = 1.0f,
strokeLineCap = StrokeCap.Butt,
strokeLineJoin = StrokeJoin.Miter,
strokeLineMiter = 1.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(840f, 280f)
verticalLineToRelative(480f)
quadToRelative(0f, 33f, -23.5f, 56.5f)
reflectiveQuadTo(760f, 840f)
horizontalLineTo(200f)
quadToRelative(-33f, 0f, -56.5f, -23.5f)
reflectiveQuadTo(120f, 760f)
verticalLineToRelative(-560f)
quadToRelative(0f, -33f, 23.5f, -56.5f)
reflectiveQuadTo(200f, 120f)
horizontalLineToRelative(480f)
close()
moveToRelative(-80f, 34f)
lineTo(646f, 200f)
horizontalLineTo(200f)
verticalLineToRelative(560f)
horizontalLineToRelative(560f)
close()
moveTo(480f, 720f)
quadToRelative(50f, 0f, 85f, -35f)
reflectiveQuadToRelative(35f, -85f)
reflectiveQuadToRelative(-35f, -85f)
reflectiveQuadToRelative(-85f, -35f)
reflectiveQuadToRelative(-85f, 35f)
reflectiveQuadToRelative(-35f, 85f)
reflectiveQuadToRelative(35f, 85f)
reflectiveQuadToRelative(85f, 35f)
moveTo(240f, 400f)
horizontalLineToRelative(360f)
verticalLineToRelative(-160f)
horizontalLineTo(240f)
close()
moveToRelative(-40f, -86f)
verticalLineToRelative(446f)
verticalLineToRelative(-560f)
close()
}
}.build()
return _Save!!
}

private var _Save: ImageVector? = null
27 changes: 25 additions & 2 deletions app/src/main/java/com/paulcoding/hviewer/ui/page/AppEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.paulcoding.hviewer.model.PostItem
import com.paulcoding.hviewer.model.SiteConfigs
import com.paulcoding.hviewer.network.Github
import com.paulcoding.hviewer.ui.favorite.FavoritePage
import com.paulcoding.hviewer.ui.page.editor.EditorPage
import com.paulcoding.hviewer.ui.page.editor.ListScriptPage
import com.paulcoding.hviewer.ui.page.post.PostPage
import com.paulcoding.hviewer.ui.page.posts.PostsPage
import com.paulcoding.hviewer.ui.page.search.SearchPage
Expand All @@ -34,6 +36,7 @@ fun AppEntry() {
val githubState by Github.stateFlow.collectAsState()
val siteConfigs = githubState.siteConfigs ?: SiteConfigs()
val appViewModel: AppViewModel = viewModel()
val appState by appViewModel.stateFlow.collectAsState()

fun navToImages(post: PostItem) {
appViewModel.setCurrentPost(post)
Expand All @@ -42,7 +45,9 @@ fun AppEntry() {

NavHost(navController, Route.SITES) {
animatedComposable(Route.SITES) {
SitesPage(siteConfigs = siteConfigs,
SitesPage(
isDevMode = appState.isDevMode,
siteConfigs = siteConfigs,
refresh = { Github.refreshLocalConfigs() },
navToTopics = { site ->
appViewModel.setSiteConfig(site, siteConfigs.sites[site]!!)
Expand All @@ -53,10 +58,13 @@ fun AppEntry() {
navToFavorite = {
navController.navigate(Route.FAVORITE)
},
navToListScript = {
navController.navigate(Route.LIST_SCRIPT)
},
goBack = { navController.popBackStack() })
}
animatedComposable(Route.SETTINGS) {
SettingsPage(goBack = { navController.popBackStack() })
SettingsPage(appViewModel = appViewModel, goBack = { navController.popBackStack() })
}
animatedComposable(Route.POSTS) {
PostsPage(
Expand Down Expand Up @@ -94,6 +102,21 @@ fun AppEntry() {
goBack = { navController.popBackStack() }
)
}
animatedComposable(Route.LIST_SCRIPT) {
ListScriptPage(
appViewModel = appViewModel,
goBack = { navController.popBackStack() },
navToEditor = {
navController.navigate(Route.EDITOR + "/$it")
})
}
animatedComposable(Route.EDITOR + "/{scriptFile}") { backStackEntry ->
val scriptFile = backStackEntry.arguments?.getString("scriptFile")!!
EditorPage(
appViewModel = appViewModel,
scriptFile = scriptFile,
goBack = { navController.popBackStack() })
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/paulcoding/hviewer/ui/page/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ package com.paulcoding.hviewer.ui.page

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.paulcoding.hviewer.MainApp.Companion.appContext
import com.paulcoding.hviewer.database.DatabaseProvider
import com.paulcoding.hviewer.helper.scriptsDir
import com.paulcoding.hviewer.model.PostItem
import com.paulcoding.hviewer.model.SiteConfig
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.io.File

class AppViewModel : ViewModel() {
private val scriptsDir = appContext.scriptsDir
val listScriptFiles: List<File>
get() = scriptsDir.listFiles()?.toList() ?: listOf()

private var _stateFlow = MutableStateFlow(UiState())
val stateFlow = _stateFlow.asStateFlow()

Expand All @@ -27,8 +34,13 @@ class AppViewModel : ViewModel() {
data class UiState(
val post: PostItem = PostItem(),
val site: Pair<String, SiteConfig> = "" to SiteConfig(),
val isDevMode: Boolean = false,
)

fun setDevMode(isDevMode: Boolean) {
_stateFlow.update { it.copy(isDevMode = isDevMode) }
}

fun addFavorite(postItem: PostItem, reAdded: Boolean = false) {
viewModelScope.launch {
val item = if (reAdded) postItem else postItem.copy(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/paulcoding/hviewer/ui/page/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ object Route {
const val SEARCH = "search"
const val SETTINGS = "settings"
const val FAVORITE = "favorite"
const val EDITOR = "editor"
const val LIST_SCRIPT = "list_script"
}
Loading
Loading