Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds old news section, images as webp #61

Merged
merged 1 commit into from
Aug 17, 2024
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
16 changes: 16 additions & 0 deletions app/src/main/java/app/jerboa/spp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import app.jerboa.spp.composable.NewsItem
import app.jerboa.spp.viewmodel.MUSIC
import app.jerboa.spp.viewmodel.REVIEW_RATE_LIMIT_MILLIS
import app.jerboa.spp.viewmodel.SPPViewModel
Expand Down Expand Up @@ -511,6 +512,8 @@ class MainActivity : AppCompatActivity() {
prefs.getLong("reviewTries", 0L)
}

Log.d("review", "$lastReviewTries")

if (!prefs.contains("playTime")) {
prefsEdit.putLong("playTime", 0L)
prefsEdit.apply()
Expand Down Expand Up @@ -589,6 +592,18 @@ class MainActivity : AppCompatActivity() {
Log.d("density", appInfo.density.toString())
}

val news: List<NewsItem> = listOf(
NewsItem(R.string.news1, R.drawable.__5_0),
NewsItem(R.string.news2, null),
NewsItem(R.string.news3, null),
NewsItem(R.string.news4, R.drawable.__5_3),
NewsItem(R.string.news5, null),
NewsItem(R.string.news6, R.drawable.__5_5),
NewsItem(R.string.news7, null),
NewsItem(R.string.news8, R.drawable.__6_0),
NewsItem(R.string.news9, null)
).reversed()

window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()

Expand All @@ -603,6 +618,7 @@ class MainActivity : AppCompatActivity() {
aboutViewModel,
menuPromptViewModel,
toyMenuViewModel,
news,
Pair(width, height),
imageResources,
appInfo,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/app/jerboa/spp/composable/about.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fun about(
width75Percent: Double,
images: Map<String,Int>,
info: AppInfo,
newsItems: List<NewsItem>
){
val displayingAbout: Boolean by aboutViewModel.displayingAbout.observeAsState(initial = false)

Expand Down Expand Up @@ -111,7 +112,8 @@ fun about(
}
Spacer(modifier = Modifier.size(8.dp))
socials(images, info) { aboutViewModel.onRequestingSocial(it) }
Spacer(modifier = Modifier.size(2.dp))
newsLog(newsItems = newsItems, width = width75Percent*0.75, density = info.density)
}
}

}
10 changes: 8 additions & 2 deletions app/src/main/java/app/jerboa/spp/composable/adaptiveTextBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ fun Modifier.simpleVerticalScrollbar(
}

@Composable
fun adaptiveTextBox(text: String, fontSize: TextUnit, maxLines: Int, textAlign: TextAlign = TextAlign.Center, colour: Color = Color.Black){
fun adaptiveTextBox(
text: String,
fontSize: TextUnit,
maxLines: Int,
modifier: Modifier = Modifier,
textAlign: TextAlign = TextAlign.Center,
colour: Color = Color.Black){
val scroll = rememberScrollState(0)
var isOverflowing by remember { mutableStateOf<Boolean?>(null) }
val maybeScrollText = @Composable {
Expand All @@ -63,7 +69,7 @@ fun adaptiveTextBox(text: String, fontSize: TextUnit, maxLines: Int, textAlign:
onTextLayout = { textLayoutResult: TextLayoutResult ->
isOverflowing = textLayoutResult.lineCount > maxLines
},
modifier = Modifier
modifier = modifier
.drawWithContent {
if (isOverflowing != null) {
drawContent()
Expand Down
102 changes: 102 additions & 0 deletions app/src/main/java/app/jerboa/spp/composable/newsLog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package app.jerboa.spp.composable

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import app.jerboa.spp.R

data class NewsItem (val textResourceId: Int, val imageResourceId: Int?)

@Composable
fun newsItem(
item: NewsItem,
width: Double,
density: Float
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.width(width.dp)
.heightIn(0.dp, width.dp)
.background(shape = RoundedCornerShape(2.dp), color = Color.White)
) {
if (item.imageResourceId != null) {
Image(
modifier = androidx.compose.ui.Modifier
.width(width.dp)
.weight(1f),
painter = painterResource(id = item.imageResourceId),
contentDescription = "News item"
)
}
Text(
text = stringResource(id = item.textResourceId),
textAlign = TextAlign.Center
)
}
}

@Composable
fun newsLog(
newsItems: List<NewsItem>,
spacing: Dp = 2.dp,
width: Double,
density: Float
) {
val scrollState = rememberScrollState()

Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
Text(
text = stringResource(id = R.string.newsIntro),
modifier = Modifier
.background(shape = RoundedCornerShape(2.dp), color = Color.White)
.width(width.dp),
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.size(spacing))
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.verticalScroll(scrollState)
) {

for (item in newsItems) {
newsItem(item, width*0.9, density)
Spacer(modifier = Modifier.size(spacing))
}
}
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/app/jerboa/spp/composable/screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fun screen(
aboutViewModel: AboutViewModel,
menuPromptViewModel: MenuPromptViewModel,
toyMenuViewModel: ToyMenuViewModel,
newsItems: List<NewsItem>,
resolution: Pair<Int,Int>,
images: Map<String,Int>,
info: AppInfo,
Expand Down Expand Up @@ -163,7 +164,8 @@ fun screen(
aboutViewModel,
width75Percent,
images,
info
info,
newsItems
)

menuPrompt(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/jerboa/spp/composable/socials.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun socials(
Box(
Modifier
.width(width75Percent.dp)
.height(height25Percent.dp)
.height(menuItemHeight.dp)
.background(
color = Color(255, 255, 255, 0),
shape = RoundedCornerShape(5)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/app/jerboa/spp/composable/toyMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ fun toyMenu(
Spacer(modifier = Modifier.size(8.dp))
slider(log10(mass), MIN_LOG_MASS, MAX_LOG_MASS, "Mass", {toyMenuViewModel.onParameterChanged(Pair(it, PARAM.MASS))}, width75Percent)
Spacer(modifier = Modifier.size(8.dp))
Log.d("fade", "$fade")
slider(
fade,
10.0f.pow(MIN_LOG_FADE),
Expand Down
Binary file removed app/src/main/res/drawable-hdpi/weblink_icon_.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-ldpi/weblink_icon_.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-mdpi/weblink_icon_.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-xhdpi/weblink_icon_.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-xxhdpi/weblink_icon_.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-xxxhdpi/weblink_icon_.png
Binary file not shown.
Binary file added app/src/main/res/drawable/__5_0.webp
Binary file not shown.
Binary file added app/src/main/res/drawable/__5_3.webp
Binary file not shown.
Binary file added app/src/main/res/drawable/__5_5.webp
Binary file not shown.
Binary file added app/src/main/res/drawable/__6_0.webp
Binary file not shown.
Binary file added app/src/main/res/drawable/news.webp
Binary file not shown.
Binary file removed app/src/main/res/drawable/tutorial.png
Binary file not shown.
Binary file added app/src/main/res/drawable/tutorial.webp
Binary file not shown.
12 changes: 12 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@
<string name="attrib">Some colour maps from/modified from ColorCET, CC-BY. Some Sounds mixed from freesound.org inc. CC-BY: "Rain on Windows, Interior, B.wav" by InspectorJ (www.jshaw.co.uk) and CC0: FlatHill, bsyapril88, suoguolh, deleted_user_229898, jackthemurray, Lydmakeren, and Sandermotions.</string>
<string name="rate">"If you had fun, why not rate us on the Play Store? Thanks!"</string>
<string name="resetTutorial">Click to show the tutorial</string>
<!-- News items -->
<string name="newsIntro">Scroll to checkout the old news.\nMy thanks especially to all reviewers, who suggested many of these changes!</string>
<string name="news1">0.5.0 29th July 2023\nAdds toy dragging, fades in on changing particle number, basic tutorial card, and the code is now open source on Github.</string>
<string name="news2">0.5.1 1st November 2023\nDragging empty space now places toys, plus some performance improvements.</string>
<string name="news3">0.5.2 21st December 2023\nAndroid SDK upgrade to 34.</string>
<string name="news4">0.5.3 21st December 2023\nAdds a pause button, and freezer toys, plus stability improvements.</string>
<string name="news5">0.5.4 22nd December 2023\nAdds particle speed slider.</string>
<string name="news6">0.5.5 1st January 2024\nAdds tracer effect, checkbox to show/hide toys, fixes crashes on pausing.</string>
<string name="news7">0.5.6 20th July 2024\nFixes crashes on app links and concurrent writing, upgrades kotlin/compose.</string>
<string name="news8">0.6.0 24th July 2024\nAdds various new sliders and orbiter toy.</string>
<string name="news9">0.6.1 31st July 2024\nFixes shader and concurrent write crashes.</string>

</resources>
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Loading