Skip to content
Open
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
72 changes: 52 additions & 20 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
plugins {
id("com.android.application")
kotlin("android")
id("com.android.application")
kotlin("android")
}

android {
compileSdk = 31
defaultConfig {
applicationId = "ge.dev.waroffingerskmm.android"
minSdk = 23
targetSdk = 30
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
compileSdk = 31
defaultConfig {
applicationId = "ge.dev.waroffingerskmm.android"
minSdk = 23
targetSdk = 30
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
buildFeatures {
// Enables Jetpack Compose for this module
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.1.1"
}
}

dependencies {
implementation(project(":shared"))
implementation("androidx.core:core-ktx:1.7.0")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
implementation(project(":shared"))
implementation("androidx.core:core-ktx:1.7.0")
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")

implementation("io.insert-koin:koin-android:3.2.0-beta-1")
implementation("io.insert-koin:koin-androidx-compose:3.2.0-beta-1")


// Integration with activities
implementation("androidx.activity:activity-compose:1.4.0")
// Navigation
implementation("androidx.navigation:navigation-compose:2.4.1")
implementation("androidx.compose.ui:ui:1.1.1")
implementation("androidx.compose.ui:ui-util:1.2.0-alpha05")
// Tooling support (Previews, etc.)
implementation("androidx.compose.ui:ui-tooling:1.1.1")
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.1.1")
// Material Design
implementation("androidx.compose.material:material:1.1.1")
// ConstraintLayout
implementation("androidx.constraintlayout:constraintlayout-compose:1.0.0")

// Material design icons
implementation("androidx.compose.material:material-icons-core:1.1.1")
implementation("androidx.compose.material:material-icons-extended:1.1.1")
// Integration with observables
implementation("androidx.compose.runtime:runtime-livedata:1.1.1")
}
1 change: 1 addition & 0 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<application
android:allowBackup="false"
android:supportsRtl="true"
android:name=".app.MyApplication"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.WarOfFingers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ge.dev.waroffingerskmm.android

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.os.Build
import android.provider.Settings
import android.view.WindowInsets
Expand All @@ -28,7 +29,7 @@ fun Activity.fullscreen() {
}

@SuppressLint("HardwareIds")
fun Activity.getDeviceId(): String {
fun Context.getDeviceId(): String {
return Settings.Secure.getString(
contentResolver,
Settings.Secure.ANDROID_ID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
package ge.dev.waroffingerskmm.android

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Button
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.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import ge.dev.waroffingerskmm.android.screens.MainApp

class SelectGameActivity : AppCompatActivity() {
class SelectGameActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_select_game)
fullscreen()

findViewById<View>(R.id.btnCrash).setOnClickListener {
val intent = Intent(this, SelectCarCrashPlayerActivity::class.java)
startActivity(intent)
setContent {
MainApp()
}
fullscreen()
}

findViewById<View>(R.id.btnRally).setOnClickListener {
val intent = Intent(this, SelectPlayerActivity::class.java)
startActivity(intent)
}
@Preview
@Composable
fun Preview() {
MainApp()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ge.dev.waroffingerskmm.android.app

import android.app.Application
import ge.dev.waroffingerskmm.android.app.di.UtilsModule
import ge.dev.waroffingerskmm.android.app.di.ViewModels
import ge.dev.waroffingerskmm.di.initKoin
import ge.dev.waroffingerskmm.network.NetworkConfig
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.logger.Level

/**
* @Author: Jemo Mgebrishvili
* @Date: 11.03.22
*/
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
initKoin(appDeclaration = {
androidLogger(Level.INFO)
androidContext(this@MyApplication)
modules(
ViewModels.module,
UtilsModule.module
)
}, NetworkConfig(baseUrl = ""))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ge.dev.waroffingerskmm.android.app.di

import ge.dev.waroffingerskmm.android.app.utils.DeviceIdRetriever
import ge.dev.waroffingerskmm.android.app.utils.DeviceIdRetrieverImpl
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module

/**
* @Author: Jemo Mgebrishvili
* @Date: 11.03.22
*/
object UtilsModule {
val module = module {
single { DeviceIdRetrieverImpl(context = androidContext()) as DeviceIdRetriever}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ge.dev.waroffingerskmm.android.app.di

import ge.dev.waroffingerskmm.android.screens.rally.RallyViewModel
import ge.dev.waroffingerskmm.android.screens.selectplayer.SelectPlayerViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

/**
* @Author: Jemo Mgebrishvili
* @Date: 11.03.22
*/
object ViewModels {
val module = module {
viewModel { SelectPlayerViewModel(socketEventsProcessor = get(), deviceIdRetriever = get()) }
viewModel { RallyViewModel(socketEventsProcessor = get()) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ge.dev.waroffingerskmm.android.app.utils

/**
* @Author: Jemo Mgebrishvili
* @Date: 11.03.22
*/
interface DeviceIdRetriever {
fun getDeviceId(): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ge.dev.waroffingerskmm.android.app.utils

import android.content.Context
import ge.dev.waroffingerskmm.android.getDeviceId

/**
* @Author: Jemo Mgebrishvili
* @Date: 11.03.22
*/
class DeviceIdRetrieverImpl(private val context: Context) : DeviceIdRetriever{
override fun getDeviceId(): String {
return context.getDeviceId()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package ge.dev.waroffingerskmm.android.extensions

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.lerp
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.lerp
import kotlin.math.min
import kotlinx.coroutines.delay

/**
* A [Modifier] that draws a border around elements that are recomposing. The border increases in
* size and interpolates from red to green as more recompositions occur before a timeout.
*/
@Stable
fun Modifier.recomposeHighlighter(): Modifier = this.then(recomposeModifier)

// Use a single instance + @Stable to ensure that recompositions can enable skipping optimizations
// Modifier.composed will still remember unique data per call site.
private val recomposeModifier =
Modifier.composed(inspectorInfo = debugInspectorInfo { name = "recomposeHighlighter" }) {
// The total number of compositions that have occurred. We're not using a State<> here be
// able to read/write the value without invalidating (which would cause infinite
// recomposition).
val totalCompositions = remember { arrayOf(0L) }
totalCompositions[0]++

// The value of totalCompositions at the last timeout.
val totalCompositionsAtLastTimeout = remember { mutableStateOf(0L) }

// Start the timeout, and reset everytime there's a recomposition. (Using totalCompositions
// as the key is really just to cause the timer to restart every composition).
LaunchedEffect(totalCompositions[0]) {
delay(3000)
totalCompositionsAtLastTimeout.value = totalCompositions[0]
}

Modifier.drawWithCache {
onDrawWithContent {
// Draw actual content.
drawContent()

// Below is to draw the highlight, if necessary. A lot of the logic is copied from
// Modifier.border
val numCompositionsSinceTimeout =
totalCompositions[0] - totalCompositionsAtLastTimeout.value

val hasValidBorderParams = size.minDimension > 0f
if (!hasValidBorderParams || numCompositionsSinceTimeout <= 0) {
return@onDrawWithContent
}

val (color, strokeWidthPx) =
when (numCompositionsSinceTimeout) {
// We need at least one composition to draw, so draw the smallest border
// color in blue.
1L -> Color.Blue to 1f
// 2 compositions is _probably_ okay.
2L -> Color.Green to 2.dp.toPx()
// 3 or more compositions before timeout may indicate an issue. lerp the
// color from yellow to red, and continually increase the border size.
else -> {
lerp(
Color.Yellow.copy(alpha = 0.8f),
Color.Red.copy(alpha = 0.5f),
min(1f, (numCompositionsSinceTimeout - 1).toFloat() / 100f)
) to numCompositionsSinceTimeout.toInt().dp.toPx()
}
}

val halfStroke = strokeWidthPx / 2
val topLeft = Offset(halfStroke, halfStroke)
val borderSize = Size(size.width - strokeWidthPx, size.height - strokeWidthPx)

val fillArea = (strokeWidthPx * 2) > size.minDimension
val rectTopLeft = if (fillArea) Offset.Zero else topLeft
val size = if (fillArea) size else borderSize
val style = if (fillArea) Fill else Stroke(strokeWidthPx)

drawRect(
brush = SolidColor(color),
topLeft = rectTopLeft,
size = size,
style = style
)
}
}
}
Loading