Skip to content

Commit

Permalink
Merge pull request #15 from Nimtome/feature/gradle-housekeeping
Browse files Browse the repository at this point in the history
Code Housekeeping
  • Loading branch information
Dewyer committed Jan 2, 2022
2 parents 2d4ba23 + 270533d commit ba8b035
Show file tree
Hide file tree
Showing 43 changed files with 271 additions and 710 deletions.
25 changes: 15 additions & 10 deletions android-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id "kotlinx-serialization"
}

apply plugin: "io.gitlab.arturbosch.detekt"


android {
compileSdk 31

Expand All @@ -13,7 +15,7 @@ android {
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
versionName "0.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -50,40 +52,43 @@ android {
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.6.0'
}

}

dependencies {

//Android base
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1'

//Compose
implementation 'androidx.activity:activity-compose:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material3:material3:1.0.0-alpha02"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"

//Compose tests
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

//Tests
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

def room_version = '2.4.0'
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

def lifecycle_version = "2.4.0"
// LiveData
def lifecycle_version = "2.4.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

// Coroutine
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.material.Card
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ExtendedFloatingActionButton
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.rememberCoroutineScope
Expand All @@ -30,17 +43,16 @@ import com.nimtome.app.ui.theme.DndSpellsTheme
import com.nimtome.app.viewmodel.CharacterViewModel
import com.nimtome.app.viewmodel.SpellViewModel
import kotlinx.coroutines.launch
import kotlinx.serialization.ExperimentalSerializationApi
import kotlin.random.Random


fun roll(rollText: String): String {
var sum = 0
val diceCount = rollText.split("d")[0].toInt()
val diceSides = rollText.split("d")[1].toInt()

for (ii in 1..diceCount)
repeat(diceCount) {
sum += Random.nextInt(from = 1, until = diceSides + 1)
}

return sum.toString()
}
Expand All @@ -63,8 +75,6 @@ class CharacterDetailsActivity : ComponentActivity() {
val spells =
viewModel[SpellViewModel::class.java].allSpells.observeAsState().value
?: listOf()


Surface(color = MaterialTheme.colors.background) {
CharacterDetailContent(character, spells)
}
Expand All @@ -73,7 +83,6 @@ class CharacterDetailsActivity : ComponentActivity() {
}
}

@OptIn(ExperimentalSerializationApi::class)
@Composable
fun CharacterDetailContent(
character: DndCharacter = DndCharacter(),
Expand Down Expand Up @@ -174,4 +183,4 @@ fun CharacterDetailPreview() {
DndSpellsTheme {
CharacterDetailContent(sampleCharacter, sampleSpells)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,44 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material.*
import androidx.compose.material.AlertDialog
import androidx.compose.material.BackdropScaffold
import androidx.compose.material.BackdropScaffoldState
import androidx.compose.material.BackdropValue
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.outlined.Menu
import androidx.compose.material.rememberBackdropScaffoldState
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
Expand All @@ -31,11 +54,17 @@ import com.nimtome.app.model.SpellImporter
import com.nimtome.app.ui.components.CharacterCard
import com.nimtome.app.ui.components.EditCharacterCard
import com.nimtome.app.ui.components.MainMenuSpellCard
import com.nimtome.app.ui.theme.CARD_INNER_FILL_RATIO
import com.nimtome.app.ui.theme.CharacterListTopbarColors
import com.nimtome.app.ui.theme.DndSpellsTheme
import com.nimtome.app.viewmodel.CharacterViewModel
import com.nimtome.app.viewmodel.SpellViewModel
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class CharacterListActivity : ComponentActivity() {
private lateinit var characterViewModel: CharacterViewModel
Expand All @@ -53,7 +82,7 @@ class CharacterListActivity : ComponentActivity() {
val importer = SpellImporter()
val spellList = importer.importSpells(inputStream)

//Show snakbar
// Show snakbar
spellsViewModel.nuke()
spellList.forEach { spell ->
spellsViewModel.insert(spell)
Expand Down Expand Up @@ -187,12 +216,15 @@ private fun StorageAccessRationaleDialog(
}
},
text = {
Text("We need to use storage to access the spell list XML file. If you cancel this, you have to go into setting and enable storage access.")
Text(stringResource(R.string.storage_access_rationale))
}

)
}

private const val CARD_FILL_RATIO = .8f

@Suppress("UnusedPrivateMember")
@ExperimentalMaterialApi
@Composable
private fun MainActivityContent(
Expand Down Expand Up @@ -232,36 +264,34 @@ private fun MainActivityContent(
IconButton(onClick = { addCharacter() }) {
Icon(Icons.Default.Add, "Add Character")
}

}
)
},
backLayerContent = {
Column(
Modifier
.fillMaxWidth(.8f)
.fillMaxWidth(CARD_FILL_RATIO)
.selectableGroup()
) {
Row(verticalAlignment = Alignment.CenterVertically)
{
Row(verticalAlignment = Alignment.CenterVertically) {
androidx.compose.material3.RadioButton(
selected = menuSelection == MainMenuElements.SPELLS,
onClick = { menuSelection = MainMenuElements.SPELLS })
onClick = { menuSelection = MainMenuElements.SPELLS }
)

Text("Spells")
}

Row(verticalAlignment = Alignment.CenterVertically) {
androidx.compose.material3.RadioButton(
selected = menuSelection == MainMenuElements.CHARACTERS,
onClick = { menuSelection = MainMenuElements.CHARACTERS })
onClick = { menuSelection = MainMenuElements.CHARACTERS }
)

Text("Characters")

}

Spacer(modifier = Modifier.padding(bottom = 15.dp))

}
},
frontLayerContent = {
Expand All @@ -287,8 +317,7 @@ private fun MainActivityContent(
},
headerHeight = 32.dp,
scaffoldState = scaffoldState,

) {
) {
}
}

Expand Down Expand Up @@ -323,14 +352,15 @@ private fun CharacterList(
Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
content = {
items(items = list,
items(
items = list,
itemContent = { character ->
if (!isEditMode)
CharacterCard(
character = character,
onClick = { onClick(it) },
modifier = Modifier
.fillMaxWidth(.9f)
.fillMaxWidth(CARD_INNER_FILL_RATIO)
.padding(5.dp),
)
else
Expand All @@ -339,14 +369,14 @@ private fun CharacterList(
onClick = { onClick(it) },
onEditClick = { onEditClick(it) },
modifier = Modifier
.fillMaxWidth(.9f)
.fillMaxWidth(CARD_INNER_FILL_RATIO)
.padding(5.dp)
)
}
)
})
}
)
}

}

@ExperimentalMaterialApi
Expand All @@ -368,31 +398,26 @@ private fun SpellList(
Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
content = {
items(items = list,
items(
items = list,
itemContent = { spell ->
MainMenuSpellCard(
spell = spell,
onClick = { onClick(spell) },
isEditMode = isEditMode,
onEditClick = { onEditClick(spell) },
modifier = Modifier
.fillMaxWidth(.9f)
.fillMaxWidth(CARD_INNER_FILL_RATIO)
.padding(5.dp)
)
}
)
}
)
}

}
}

@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}

@OptIn(ExperimentalMaterialApi::class)
@Preview(showBackground = true)
@Composable
Expand All @@ -416,4 +441,4 @@ fun CharacterListPreview() {
},
)
}
}
}

0 comments on commit ba8b035

Please sign in to comment.