Skip to content

Commit

Permalink
Initial starter_m3 branch commit
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshea committed May 16, 2023
1 parent 2946b66 commit 9fab31f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 103 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Affirmations App - Intermediate Code
Affirmations App - Starter Code
================================

Intermediate code for the Android Basics with Compose: Affirmations app.
Starter code for the Android Basics with Compose: Affirmations app.


Introduction
Expand Down
59 changes: 0 additions & 59 deletions app/src/main/java/com/example/affirmations/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,11 @@ package com.example.affirmations
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
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.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
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 com.example.affirmations.data.Datasource
import com.example.affirmations.model.Affirmation
import com.example.affirmations.ui.theme.AffirmationsTheme

class MainActivity : ComponentActivity() {
Expand All @@ -62,46 +45,4 @@ class MainActivity : ComponentActivity() {

@Composable
fun AffirmationsApp() {
AffirmationList(
affirmationList = Datasource().loadAffirmations(),
)
}

@Composable
fun AffirmationList(affirmationList: List<Affirmation>, modifier: Modifier = Modifier) {
LazyColumn(modifier = modifier) {
items(affirmationList) { affirmation ->
AffirmationCard(
affirmation = affirmation,
modifier = Modifier.padding(8.dp)
)
}
}
}

@Composable
fun AffirmationCard(affirmation: Affirmation, modifier: Modifier = Modifier) {
Card(modifier = modifier) {
Column {
Image(
painter = painterResource(affirmation.imageResourceId),
contentDescription = stringResource(affirmation.stringResourceId),
modifier = Modifier
.fillMaxWidth()
.height(194.dp),
contentScale = ContentScale.Crop
)
Text(
text = LocalContext.current.getString(affirmation.stringResourceId),
modifier = Modifier.padding(16.dp),
style = MaterialTheme.typography.headlineSmall
)
}
}
}

@Preview
@Composable
private fun AffirmationCardPreview() {
AffirmationCard(Affirmation(R.string.affirmation1, R.drawable.image1))
}
30 changes: 15 additions & 15 deletions app/src/main/java/com/example/affirmations/data/Datasource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
*/
package com.example.affirmations.data

import com.example.affirmations.R
import com.example.affirmations.model.Affirmation
//import com.example.affirmations.R
//import com.example.affirmations.model.Affirmation

/**
* [Datasource] generates a list of [Affirmation]
*/
class Datasource() {
fun loadAffirmations(): List<Affirmation> {
return listOf<Affirmation>(
Affirmation(R.string.affirmation1, R.drawable.image1),
Affirmation(R.string.affirmation2, R.drawable.image2),
Affirmation(R.string.affirmation3, R.drawable.image3),
Affirmation(R.string.affirmation4, R.drawable.image4),
Affirmation(R.string.affirmation5, R.drawable.image5),
Affirmation(R.string.affirmation6, R.drawable.image6),
Affirmation(R.string.affirmation7, R.drawable.image7),
Affirmation(R.string.affirmation8, R.drawable.image8),
Affirmation(R.string.affirmation9, R.drawable.image9),
Affirmation(R.string.affirmation10, R.drawable.image10))
}
// fun loadAffirmations(): List<Affirmation> {
// return listOf<Affirmation>(
// Affirmation(R.string.affirmation1, R.drawable.image1),

This comment has been minimized.

Copy link
@MagicalMeghan

MagicalMeghan May 16, 2023

why are these commented out?

// Affirmation(R.string.affirmation2, R.drawable.image2),
// Affirmation(R.string.affirmation3, R.drawable.image3),
// Affirmation(R.string.affirmation4, R.drawable.image4),
// Affirmation(R.string.affirmation5, R.drawable.image5),
// Affirmation(R.string.affirmation6, R.drawable.image6),
// Affirmation(R.string.affirmation7, R.drawable.image7),
// Affirmation(R.string.affirmation8, R.drawable.image8),
// Affirmation(R.string.affirmation9, R.drawable.image9),
// Affirmation(R.string.affirmation10, R.drawable.image10))
// }
}
27 changes: 0 additions & 27 deletions app/src/main/java/com/example/affirmations/model/Affirmation.kt

This file was deleted.

0 comments on commit 9fab31f

Please sign in to comment.