Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Comments and feedback #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ class MainActivity : AppCompatActivity() {

companion object {
const val STATE_TAPS = "tapCount"
const val STATE_TAPPOW = "tapPower"
const val STATE_TAP_POWER = "tapPower" //Preferred
const val STATE_IDLEPOW = "idlePower"
const val STATE_UPGRADES = "upgrades"
}

val TAG = "mainActivity"
// You missed removing this tag with your Log statements, I would guess. It surfaced in a warning.

private var tapCount = 0
private var tapPower = 1 //amount tapCount increments when tap button is pressed
Expand All @@ -41,7 +40,7 @@ class MainActivity : AppCompatActivity() {
if (savedInstanceState != null) {
with(savedInstanceState) {
tapCount = getInt(STATE_TAPS)
tapPower = getInt(STATE_TAPPOW)
tapPower = getInt(STATE_TAP_POWER)
idlePower = getInt(STATE_IDLEPOW)
upgrades = getIntArray(STATE_UPGRADES)!!

Expand Down Expand Up @@ -83,7 +82,7 @@ class MainActivity : AppCompatActivity() {
super.onSaveInstanceState(outState)
outState.run {
putInt(STATE_TAPS, tapCount)
putInt(STATE_TAPPOW, tapPower)
putInt(STATE_TAP_POWER, tapPower)
putInt(STATE_IDLEPOW, idlePower)
putIntArray(STATE_UPGRADES, upgrades)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import com.example.idletapperversion2.databinding.ActivityStoreBinding

class StoreActivity : AppCompatActivity() {

//You shouldn't really need to define an identical companion object twice. Rather, access it on
//the activity instance via dot notation.
companion object {
const val STATE_TAPS = "tapCount"
const val STATE_TAPPOW = "tapPower"
const val STATE_IDLEPOW = "idlePower"
const val STATE_IDLE_POWER = "idlePower" //As in MainActivity
const val STATE_UPGRADES = "upgrades"
}

val TAG = "storeActivity"

//As in MainActivity
//flag to prevent overwriting loaded savedInstanceState variables with extras from MainActivity
private var savedState = false

Expand Down Expand Up @@ -61,7 +62,7 @@ class StoreActivity : AppCompatActivity() {
with(savedInstanceState) {
tapCount = getInt(STATE_TAPS)
tapPower = getInt(STATE_TAPPOW)
idlePower = getInt(STATE_IDLEPOW)
idlePower = getInt(STATE_IDLE_POWER)
upgrades = getIntArray(STATE_UPGRADES)!!

savedState = true
Expand Down Expand Up @@ -100,9 +101,9 @@ class StoreActivity : AppCompatActivity() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.run {
putInt(STATE_TAPS, tapCount)
putInt(intent.extras?.getString(STATE_TAPS), tapCount) // See comment above regarding companion objects
putInt(STATE_TAPPOW, tapPower)
putInt(STATE_IDLEPOW, idlePower)
putInt(STATE_IDLE_POWER, idlePower)
putIntArray(STATE_UPGRADES, upgrades)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class ItemAdapter(
item.baseCost, item.costIncreaseFactor,
store.upgrades[item.upgradeIndex]
)
// You may have noticed the "No speakable text present" error in your list_item.xml file.
// The preferred, and more accessible way to manage this is not to put dynamic text directly
// on a button. Rather, you should include a small 'Purchase' button on the right hand side
// your list_item view and place the text as a label in a regular TextView.
holder.binding.storeButton.text = context.resources.getString(
item.stringResourceID,
store.upgrades[item.upgradeIndex], upgradeCost
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
tools:context=".MainActivity">

<!-- Note the change to snake_case for IDs. This is a more idiomatic approach -->
<!-- snake_case is still preferred for ID names. :) -->
<!-- Note also the extracted string resource in the first Button - this should be done for all views-->
<!-- The width and height choices look fairly arbitrary - this is going to bite you if you try to load this app on a small screen. Better to no define them unless necessary, and rarely should you define width and height large enough to cause problems on smaller screens - such as with the main tap button. -->

<TextView
android:id="@+id/tapPowerText"
android:id="@+id/tap_power_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand Down Expand Up @@ -43,7 +44,7 @@
app:layout_constraintBottom_toTopOf="@id/storeButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tapPowerText" />
app:layout_constraintTop_toBottomOf="@id/tap_power_text" />

<TextView
android:id="@+id/tapCounter"
Expand Down
Binary file added dgl114-coding-rubric-tyson.docx
Binary file not shown.