Fix app not installed bug. Delete obsolete files. Add compose preview.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-01-07 08:51:31 +01:00
parent b7a821b9f6
commit b73ddbf4cc
10 changed files with 46 additions and 267 deletions

View File

@@ -14,8 +14,7 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="false"
android:label="@string/title_activity_main"
android:exported="true"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<meta-data

View File

@@ -1,30 +1,27 @@
package me.zobrist.tichucounter.ui.history
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.tooling.preview.Preview
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import dagger.hilt.android.AndroidEntryPoint
import me.zobrist.tichucounter.data.GameAndScore
import java.text.DateFormat
import java.util.*
/**
@@ -35,7 +32,6 @@ class HistoryFragment : Fragment() {
private val viewModel: HistoryFragmentViewModel by activityViewModels()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -47,44 +43,52 @@ class HistoryFragment : Fragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MaterialTheme {
// In Compose world
Text("Hello Compose!")
HistoryList(viewModel)
}
}
}
}
@Preview
@Composable
fun HistoryList(viewModel: HistoryFragmentViewModel) {
val games = viewModel.gameAndHistory.observeAsState().value
fun HistoryList(viewModel: IHistoryFragmentViewModel = DefaultViewModel()) {
val games = viewModel.gameAndHistory.value
LazyColumn {
if(games != null)
{
items(games) {
HistoryListItem(it)
}
}
}
}
@Composable
fun HistoryListItem(game: GameAndScore) {
val format =
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
Card() {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(horizontal = 15.dp, vertical = 10.dp)
){
Text( text = game.nameA + " - " + game.nameB)
Column(
modifier = Modifier.padding(start = 10.dp)
){
Text(text = game.scoreA.toString() + ":" + game.scoreB, fontSize = 22.sp)
Text(text = game.modified.toString(), fontSize = 18.sp)
}
Text(text = game.nameA + " - " + game.nameB, style = MaterialTheme.typography.bodyLarge)
Text(
text = game.scoreA.toString() + ":" + game.scoreB,
style = MaterialTheme.typography.bodyMedium
)
Text(text = format.format(game.modified), style = MaterialTheme.typography.bodySmall)
}
}
internal class DefaultViewModel : IHistoryFragmentViewModel {
override val gameAndHistory: State<List<GameAndScore>>
get() {
val tempData = mutableListOf<GameAndScore>()
tempData.add(GameAndScore(false, "TeamA1", "TeamB1", Date(), Date(), 1, 10, 50))
tempData.add(GameAndScore(true, "TeamA2", "TeamB2", Date(), Date(), 2, 20, 60))
tempData.add(GameAndScore(false, "TeamA3", "TeamB3", Date(), Date(), 3, 30, 70))
tempData.add(GameAndScore(false, "TeamA4", "TeamB4", Date(), Date(), 4, 40, 80))
tempData.add(GameAndScore(false, "TeamA5", "TeamB5", Date(), Date(), 5, 50, 90))
return mutableStateOf(tempData)
}
}
}

View File

@@ -1,13 +0,0 @@
package me.zobrist.tichucounter.ui.history
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import me.zobrist.tichucounter.data.GameAndScore

View File

@@ -1,8 +1,7 @@
package me.zobrist.tichucounter.ui.history
import androidx.compose.runtime.State
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -12,15 +11,19 @@ import me.zobrist.tichucounter.data.GameDao
import me.zobrist.tichucounter.data.RoundDao
import javax.inject.Inject
interface IHistoryFragmentViewModel {
val gameAndHistory: State<List<GameAndScore>>
}
@HiltViewModel
class HistoryFragmentViewModel @Inject constructor(
private val gameDao: GameDao,
private val roundDao: RoundDao
) : ViewModel() {
) : ViewModel(), IHistoryFragmentViewModel {
private val _gameAndHistory: MutableLiveData<List<GameAndScore>> = MutableLiveData()
private val _gameAndHistory = mutableStateOf(emptyList<GameAndScore>())
val gameAndHistory: LiveData<List<GameAndScore>>
override val gameAndHistory: State<List<GameAndScore>>
get() {
return _gameAndHistory
}
@@ -31,6 +34,5 @@ class HistoryFragmentViewModel @Inject constructor(
_gameAndHistory.value = games
}
}
}
}

View File

@@ -1,46 +0,0 @@
package me.zobrist.tichucounter.ui.history
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import me.zobrist.tichucounter.data.GameAndScore
import me.zobrist.tichucounter.databinding.FragmentHistoryBinding
import java.text.DateFormat
/**
* [RecyclerView.Adapter] that can display a [GameAndScore].
* TODO: Replace the implementation with code for your data type.
*/
class MyGameRecyclerViewAdapter(
private val values: List<GameAndScore>
) : RecyclerView.Adapter<MyGameRecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
FragmentHistoryBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = values[position]
holder.title.text = "${item.nameA} - ${item.nameB}"
holder.secondary.text = item.scoreA.toString() + ":" + item.scoreB
holder.support.text = DateFormat.getDateInstance().format(item.modified)
}
override fun getItemCount(): Int = values.size
inner class ViewHolder(binding: FragmentHistoryBinding) :
RecyclerView.ViewHolder(binding.root) {
val title: TextView = binding.cardTitle
val secondary: TextView = binding.cardSecondary
val support: TextView = binding.cardSupporting
}
}

View File

@@ -1,11 +0,0 @@
package me.zobrist.tichucounter.ui.history.ui.theme
import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)

View File

@@ -1,68 +0,0 @@
package me.zobrist.tichucounter.ui.history.ui.theme
import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.ViewCompat
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)
@Composable
fun TichuCounterTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
}
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
}

View File

@@ -1,34 +0,0 @@
package me.zobrist.tichucounter.ui.history.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
/* Other default text styles to override
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
*/
)

View File

@@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<!-- Title, secondary and supporting text -->
<TextView
android:id="@+id/card_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceHeadline6" />
<TextView
android:id="@+id/card_secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary" />
<TextView
android:id="@+id/card_supporting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary" />
</LinearLayout>
</LinearLayout>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:name="me.zobrist.tichucounter.ui.slideshow.HistoryFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".ui.history.HistoryFragment"
tools:listitem="@layout/fragment_history" />