Skip to content

Commit

Permalink
M3 Beta -> M3 Alpha
Browse files Browse the repository at this point in the history
"Capture More" now works properly
Pumbility Page
  • Loading branch information
kr3st1k committed Jun 28, 2024
1 parent 7a64e73 commit 31296fe
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/dev/kr3st1k/piucompanion/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import dev.kr3st1k.piucompanion.core.db.AppDatabase
import dev.kr3st1k.piucompanion.ui.screens.HomeScreen
import dev.kr3st1k.piucompanion.ui.pages.HomeScreen
import dev.kr3st1k.piucompanion.ui.theme.PIUCompanionTheme

class MainActivity : ComponentActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.kr3st1k.piucompanion.core.network.data.LatestScore
import dev.kr3st1k.piucompanion.core.network.data.LoadableList
import dev.kr3st1k.piucompanion.core.network.data.News
import dev.kr3st1k.piucompanion.core.network.data.NewsBanner
import dev.kr3st1k.piucompanion.core.network.data.Pumbility
import dev.kr3st1k.piucompanion.core.network.data.User
import io.ktor.http.Parameters
import org.jsoup.nodes.Document
Expand All @@ -24,6 +25,7 @@ interface NetworkRepository {
suspend fun getNewsBanners(): MutableList<NewsBanner>
suspend fun getNewsList(): MutableList<News>
suspend fun getUserInfo(): User?
suspend fun getPumbilityInfo(): Pumbility?
suspend fun getBestUserScores(
page: Int? = null,
lvl: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import dev.kr3st1k.piucompanion.core.network.data.LatestScore
import dev.kr3st1k.piucompanion.core.network.data.LoadableList
import dev.kr3st1k.piucompanion.core.network.data.News
import dev.kr3st1k.piucompanion.core.network.data.NewsBanner
import dev.kr3st1k.piucompanion.core.network.data.Pumbility
import dev.kr3st1k.piucompanion.core.network.data.User
import dev.kr3st1k.piucompanion.core.network.parsers.BestUserScoresParser
import dev.kr3st1k.piucompanion.core.network.parsers.LatestScoresParser
import dev.kr3st1k.piucompanion.core.network.parsers.NewsBannerParser
import dev.kr3st1k.piucompanion.core.network.parsers.NewsListParser
import dev.kr3st1k.piucompanion.core.network.parsers.PumbilityParser
import dev.kr3st1k.piucompanion.core.network.parsers.UserParser
import io.ktor.client.HttpClient
import io.ktor.client.call.body
Expand Down Expand Up @@ -124,6 +126,12 @@ object NetworkRepositoryImpl : NetworkRepository {
return NewsListParser.parse(document)
}

override suspend fun getPumbilityInfo(): Pumbility? {
val document = getDocument(BASEPIUURL, "my_page/pumbility.php", checkLogin = true)
?: return null
return PumbilityParser.parse(document)
}

override suspend fun getUserInfo(): User? {
val document = getDocument(BASEPIUURL, "my_page/pumbility.php", checkLogin = true)
?: return null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.kr3st1k.piucompanion.core.network.data

data class Pumbility(
val user: User,
val scores: List<PumbilityScore>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.kr3st1k.piucompanion.core.network.data

data class PumbilityScore(
override val songName: String,
override val songBackgroundUri: String,
override val difficulty: String,
override val score: String,
override val rank: String,
val datetime: String,
) : Score(songName, songBackgroundUri, difficulty, score, rank)
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dev.kr3st1k.piucompanion.core.network.parsers

import dev.kr3st1k.piucompanion.core.helpers.Utils
import dev.kr3st1k.piucompanion.core.helpers.Utils.getBackgroundImg
import dev.kr3st1k.piucompanion.core.helpers.Utils.parseTypeDifficultyFromUri
import dev.kr3st1k.piucompanion.core.network.data.Pumbility
import dev.kr3st1k.piucompanion.core.network.data.PumbilityScore
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.util.Locale

object PumbilityParser : Parser<Pumbility>() {

private fun parsePumbilityScore(element: Element): PumbilityScore {

val score = element
.select("div.score")
.first()!!
.select("i.tt.en")
.first()!!
.text()

val songName = element.select("div.profile_name").first()!!.select("p.t1").first()!!.text()

val typeDiffImgUri = element.select("div.tw").select("img").attr("src")

val typeDiff = parseTypeDifficultyFromUri(typeDiffImgUri)!!

val bg = getBackgroundImg(element.select("div.re.bgfix").first()!!, false)

val diffElems = element.select("div.imG")

var diff = ""

for (i in diffElems) {
diff += Utils.parseDifficultyFromUri(i.select("img").attr("src"))
}

diff = typeDiff.uppercase(Locale.ENGLISH) + diff


val rankImg = element.select("div.grade_wrap").first()!!.select("img").attr("src")
var rank = Utils.parseRankFromUri(rankImg).toString()
rank = rank.uppercase(Locale.ENGLISH).replace("_p", "+").replace("_P", "+")
.replace("X_", "Broken ")

val datePlay = element.select("div.date").first()!!.select("i.tt").text()


return PumbilityScore(
songName,
bg,
diff,
score,
rank,
Utils.convertDateFromSite(datePlay)
)
}


override fun parse(document: Document): Pumbility {
val res: MutableList<PumbilityScore> = mutableListOf()

val user = UserParser.parse(document)

val scoreTable = document
.select("div.rating_rangking_list_w.top_songSt.pumblitiySt.mgT1")
.first()!!
.select("ul.list")
.first()!!
val scores = scoreTable.select("li").filter { element ->
element.select("div.in.flex.vc.wrap").count() == 1
}
for (element in scores) {
res.add(parsePumbilityScore(element))
}
return Pumbility(user, res)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import dev.kr3st1k.piucompanion.ui.screens.TopLevelDestination
import dev.kr3st1k.piucompanion.ui.pages.TopLevelDestination

@Composable
fun HomeBottomBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import dev.kr3st1k.piucompanion.core.helpers.Utils.removeUrlParameters
import dev.kr3st1k.piucompanion.core.network.data.LatestScore
import dev.kr3st1k.piucompanion.core.network.data.PumbilityScore
import dev.kr3st1k.piucompanion.core.network.data.Score

@Composable
Expand Down Expand Up @@ -111,6 +112,14 @@ fun ScoreCard(score: Score) {
color = Color(0xffadadad),
textAlign = TextAlign.End
)
if (score is PumbilityScore)
Text(
text = score.datetime,
fontSize = MaterialTheme.typography.titleSmall.fontSize,
color = Color(0xffadadad),
textAlign = TextAlign.End
)

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.dp
import dev.kr3st1k.piucompanion.core.network.data.LatestScore
import dev.kr3st1k.piucompanion.core.network.data.Score
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LazyLatestScore(
scores: List<LatestScore>,
scores: List<Score>,
onRefresh: () -> Unit,
listState: LazyListState,
item: @Composable() (() -> Unit)? = null,
) {
var isRefreshing by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -66,6 +67,10 @@ fun LazyLatestScore(
}
)
) {
item {
if (item != null)
item()
}
items(scores) { data ->
ScoreCard(data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import coil.compose.AsyncImage
import dev.kr3st1k.piucompanion.core.network.data.User

@Composable
fun UserCard(user: User)
fun UserCard(user: User, small: Boolean = false)
{
Card(
modifier = Modifier
Expand Down Expand Up @@ -65,7 +65,7 @@ fun UserCard(user: User)
Text(
text = user.titleName,
fontSize = MaterialTheme.typography.titleMedium.fontSize,
color = Color.White.copy(0.7f),
color = Color.White.copy(0.6f),
textAlign = TextAlign.Center
)
Text(
Expand All @@ -74,23 +74,26 @@ fun UserCard(user: User)
textAlign = TextAlign.Center,
color = Color.White,
)
Text(
text = user.recentGameAccess,
fontSize = MaterialTheme.typography.titleMedium.fontSize,
color = Color.White.copy(0.7f)
)
Row(verticalAlignment = Alignment.CenterVertically) {
if (!small)
Text(
text = "PUMBILITY ${user.pumbility}",
text = user.recentGameAccess,
fontSize = MaterialTheme.typography.titleMedium.fontSize,
color = Color.White.copy(0.8f) // or any other color you want
color = Color.White.copy(0.7f)
)
Spacer(modifier = Modifier.width(8.dp)) // Add some space between the two texts
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = "$${user.coinValue}",
fontSize = MaterialTheme.typography.titleSmall.fontSize,
color = Color.Green // or any other color you want
text = "${user.pumbility}pp",
fontSize = MaterialTheme.typography.titleMedium.fontSize,
color = Color.White.copy(0.9f) // or any other color you want
)
if (!small) {
Spacer(modifier = Modifier.width(8.dp)) // Add some space between the two texts
Text(
text = "$${user.coinValue}",
fontSize = MaterialTheme.typography.titleMedium.fontSize,
color = Color.Green.copy(0.9f) // or any other color you want
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens
package dev.kr3st1k.piucompanion.ui.pages

sealed class Screen(val route: String)
{
Expand All @@ -8,6 +8,6 @@ sealed class Screen(val route: String)
object LoginPage : Screen("login_page")
object HistoryPage : Screen("history_page")
object BestUserPage : Screen("best_user_page")

object PumbilityPage : Screen("pumbility_page")
object SettingsPage : Screen("settings_page")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens
package dev.kr3st1k.piucompanion.ui.pages

import androidx.compose.ui.graphics.vector.ImageVector

Expand All @@ -7,5 +7,6 @@ data class TopLevelDestination(
val selectedIcon: ImageVector,
val unselectedIcon: ImageVector,
val iconText: String,
val showTitle: Boolean = true,
val summary: String? = null,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens
package dev.kr3st1k.piucompanion.ui.pages

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down Expand Up @@ -63,7 +63,7 @@ public val homeDestinations = listOf(
summary = "Read latest news about Pump It Up"
),
TopLevelDestination(
route = Screen.NewsPage.route,
route = Screen.PumbilityPage.route,
selectedIcon = Icons.Filled.Analytics,
unselectedIcon = Icons.Filled.Analytics,
iconText = "PUMBILITY",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens.home
package dev.kr3st1k.piucompanion.ui.pages.home

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -42,7 +42,7 @@ import dev.kr3st1k.piucompanion.core.helpers.Crypto
import dev.kr3st1k.piucompanion.core.modules.LoginManager
import dev.kr3st1k.piucompanion.core.network.NetworkRepositoryImpl
import dev.kr3st1k.piucompanion.ui.components.AlertDialogWithButton
import dev.kr3st1k.piucompanion.ui.screens.Screen
import dev.kr3st1k.piucompanion.ui.pages.Screen
import kotlinx.coroutines.launch

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens.home
package dev.kr3st1k.piucompanion.ui.pages.home

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -12,7 +12,7 @@ import dev.kr3st1k.piucompanion.core.helpers.Crypto
import dev.kr3st1k.piucompanion.core.modules.LoginManager
import dev.kr3st1k.piucompanion.core.network.NetworkRepositoryImpl
import dev.kr3st1k.piucompanion.ui.components.YouSpinMeRightRoundBabyRightRound
import dev.kr3st1k.piucompanion.ui.screens.Screen
import dev.kr3st1k.piucompanion.ui.pages.Screen
import kotlinx.coroutines.launch

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens.home
package dev.kr3st1k.piucompanion.ui.pages.home

import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
Expand All @@ -13,7 +13,7 @@ import dev.kr3st1k.piucompanion.core.network.data.BestUserScore
import dev.kr3st1k.piucompanion.ui.components.DropdownMenuBestScores
import dev.kr3st1k.piucompanion.ui.components.YouSpinMeRightRoundBabyRightRound
import dev.kr3st1k.piucompanion.ui.components.home.scores.LazyBestScore
import dev.kr3st1k.piucompanion.ui.screens.Screen
import dev.kr3st1k.piucompanion.ui.pages.Screen
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens.home
package dev.kr3st1k.piucompanion.ui.pages.home

import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
Expand All @@ -11,7 +11,7 @@ import dev.kr3st1k.piucompanion.core.network.NetworkRepositoryImpl
import dev.kr3st1k.piucompanion.core.network.data.LatestScore
import dev.kr3st1k.piucompanion.ui.components.YouSpinMeRightRoundBabyRightRound
import dev.kr3st1k.piucompanion.ui.components.home.scores.LazyLatestScore
import dev.kr3st1k.piucompanion.ui.screens.Screen
import dev.kr3st1k.piucompanion.ui.pages.Screen
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.kr3st1k.piucompanion.ui.screens.home
package dev.kr3st1k.piucompanion.ui.pages.home

import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
Expand Down
Loading

0 comments on commit 31296fe

Please sign in to comment.