Building DotShredzilla (Part 7): Logging From the Lock Screen, 36 Free Badges, and the Backup That Signed Everyone Out
DEV Community

Building DotShredzilla (Part 7): Logging From the Lock Screen, 36 Free Badges, and the Backup That Signed Everyone Out

Part 6 ended with version 1.6.0 in Play review: no forced ads, Pro for life, and ad hours a server can trust.

Version 1.7.0 came from the same place as every other release, a training session. Between sets my phone is in my pocket or on the bench, locked. Unlocking it with chalk on my hands to tap "Log set" got old fast. So the biggest feature of 1.7.0 doesn't live in the app at all. It lives in the notification shade.

DotShredzilla is an Android workout tracker from FreeRave (DotSuite), written in Kotlin with Jetpack Compose and Firebase, and open source under Apache License 2.0: github.com/kareem2099/Shredzilla.

Logging a set without unlocking your phone

When a workout starts, a notification shows what you're doing and what comes next, on the lock screen too. Its buttons cover most of a workout:

  • Log 60 kg × 10 repeats your last set with one tap.
  • +1 rep for the set where you got one more than last time.
  • Next: Leg Press once the target sets are done, and Finish on the last exercise.
  • Edit opens an inline reply. Type 8 for eight reps at the same load, or 9 8 for 9 kg × 8.

The timer in the notification is the system's, not mine. The notification is posted once with a target time, and Android draws the clock. It counts up the workout time and counts down the rest:

NotificationCompat.Builder(context, CHANNEL_ID)
  // Counts down the rest, otherwise counts up the workout time
  .setWhen(if (resting) notice.restEndsAt else notice.startedAt)
  .setShowWhen(true)
  .setUsesChronometer(true)
  .setChronometerCountDown(resting)
  .setOngoing(true)
  .setOnlyAlertOnce(true)
  .setCategory(NotificationCompat.CATEGORY_WORKOUT)
  .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)

VISIBILITY_PUBLIC is what makes the buttons usable without unlocking. That's a choice worth making on purpose: the lock screen shows the list, the exercise and your last set, and nothing else from your account.

Reading "9 8" from a keyboard

The reply box gets whatever the keyboard sends. On my phone that can be Arabic-Indic digits (٩ ٨) or a decimal comma, so the parser normalizes first, then counts the numbers:

fun parseSetInput(text: String, template: SetEntry?): SetEntry? {
  val normalized = text.map { c -> when (c) {
    in '٠'..'٩' -> '0' + (c - '٠')
    in '۰'..'۹' -> '0' + (c - '۰')
    '٫', ',' -> '.' else -> c
  } }.joinToString("")
  val numbers = Regex("""\d+(?:\.\d+)?""").findAll(normalized).map { it.value.toDouble() }.toList()
  val base = template ?: SetEntry()
  return when (numbers.size) {
    1 -> template?.copy(reps = numbers[0].toInt())
    2 -> {
      val (load, reps) = numbers
      when {
        base.plates != null -> base.copy(plates = load.toInt(), reps = reps.toInt())
        base.perSide -> base.copy(weight = load * 2, reps = reps.toInt())
        else -> base.copy(weight = load, reps = reps.toInt())
      }
    }
    else -> null
  }?.takeIf { it.reps >= 1 }?.copy(notes = "")
}

One number means reps at the same load. Two numbers mean load and reps, and the load follows the last set's kind: plates stay plates, and a per-side machine doubles what you typed. Anything else gets a short "Try 8, or 9 8" message instead of a wrong set.

What a notification can't do

Buttons on a notification go to a BroadcastReceiver, and a receiver isn't allowed to open screens. So Finish is a normal tap target that opens the app on the workout summary, not a background action.

The receiver also needs the running workout. If Android has killed the app in the meantime, the buttons say "Open DotShredzilla to continue your workout" rather than logging a set into nothing. Tapping the notification itself brings the workout back.

Four looks

Detailed and Compact are free. Rest focus puts the countdown first, and Progress bar uses NotificationCompat.ProgressStyle with a segment per exercise. On Android 16 it also asks to be promoted, which turns it into a Live Update chip in the status bar:

builder.setStyle(style)
  .setRequestPromotedOngoing(true)
  .setShortCriticalText(if (resting) "Rest" else "${notice.progress}/${notice.totalSets}")

Here's the whole thing in 20 seconds, recorded on my own phone:

Reminders that know your training

1.7.0 also added the first notifications that aren't about a workout in progress. Every one of them is judged against your own training, not a fixed schedule:

  • Workout reminder after the number of days without training you choose, then again every that many days while the break lasts. It opens the next day of your split, not just the app.
  • Weekly goal alert on the last day you can still hit your goal.
  • Measurement reminder following the rhythm you measure in, weekly or monthly.
  • Pro time ending when banked ad hours are about to run out.

The permission isn't requested on first launch. It's requested on your first rest, the moment a notification is obviously useful. Quiet hours (10 PM to 8 AM by default) hold everything back, and each kind has its own switch.

The rules themselves are plain functions that take a snapshot of your training and return what's due today. A WorkManager job runs them in the background, and unit tests cover the edges, like a deload week that shouldn't trigger a weekly goal alert.

36 badges, free for everyone

Pro is the layer that interprets your data. Badges are motivation, and motivation shouldn't be paywalled. So all 36 are free: milestones, training, strength, consistency, body and community.

Two lessons from earlier parts showed up again: Count all-time, not 90 days. History loads 90 days, so the Centurion badge (train on 100 different days) can't be counted from it. Training days, sets and records are counters on the account, the same way records moved to their own collection in Part 4. Compare in one unit. The weight clubs are 60 to 180 kg, or 135 to 405 lb. Progress is stored in tenths of a kilogram, so 225 lb logged in pounds reaches the 225 lb goal exactly, without a rounding error in between.

Badges earned before the feature existed are saved quietly. The first launch after the update would otherwise have shown a stack of banners for things you did months ago. After that, each new badge gets its own banner. My favorite one is Pocket logger: log a set from the notification.

Event badges come from Remote Config. A JSON list in badge_events defines a title, a window and a goal ("train 3 times this week"), so an event can start without an app update. A broken entry is skipped instead of breaking the badges page, and an earned event badge stays on the account after the event ends.

Founding member: from a date to a number

The first version of the Founding member badge used a Remote Config date: sign up before it, get the badge. That had two problems. A date doesn't mean "the first 100", and the app decided who qualified. Version 1.7.1 gives out numbers instead, #1 to #100, from a Cloud Function in a Firestore transaction:

const result = await db.runTransaction(async (tx) => {
  const meta = await tx.get(foundingMeta());
  const existing = await tx.get(founderRef(user.uid));
  if (existing.exists) return "already";
  const count = meta.exists ? meta.data().count || 0 : 0;
  if (count >= FOUNDING_LIMIT) return "full";
  tx.set(founderRef(user.uid), { number: count + 1, at: Timestamp.now() });
  tx.set(foundingMeta(), { count: count + 1, limit: FOUNDING_LIMIT }, { merge: true });
  return `#${count + 1}`;
});

The number lives in founders/{uid}, which its member can read and nobody can write from the app. I first wanted to put it in the profile document, but version 1.6.0 creates email accounts with a plain set(), which replaces the whole document. A field there could be wiped by an app version that's still installed. A separate document no app version ever writes is safer than any rule about fields.

Since then the function has moved from "account created" to "onboarding finished", so a sign-up someone abandons halfway doesn't take one of the hundred numbers.

The backup that signed everyone out

The worst bug of this release was simple to describe: on some installs, the app forgot the sign-in every time it closed. Sign in, close, open: signed out.

The cause was Android's Auto Backup. Firebase Auth stores the signed-in user encrypted, with a key from the Android Keystore. Auto Backup happily restored Firebase's files to the new install, including the encrypted keyset. The Keystore key that opens it never leaves the device, by design. So Firebase found a keyset it couldn't use, couldn't save any sign-in with it, and every launch started signed out.

The fix has two halves. New backups leave those files out, in both rule files, because Android 12 and later read data_extraction_rules.xml and older versions read backup_rules.xml:

<cloud-backup>
  <exclude domain="sharedpref" path="com.google.firebase.auth.api.crypto.….xml" />
  <exclude domain="sharedpref" path="com.google.firebase.auth.api.Store.….xml" />
</cloud-backup>

Phones that already restored a broken keyset needed more. At startup, if no sign-in is saved, the old keyset protects nothing, so it's removed before Firebase Auth starts and Firebase creates a working one on the next sign-in:

private fun resetUnusableAuthKey() {
  val store = getSharedPreferences("com.google.firebase.auth.api.Store.$suffix", MODE_PRIVATE)
  if (store.contains("com.google.firebase.auth.FIREBASE_USER")) return
  val crypto = "com.google.firebase.auth.api.crypto.$suffix"
  if (getSharedPreferences(crypto, MODE_PRIVATE).all.isNotEmpty())
    deleteSharedPreferences(crypto)
}

While I was in there, I removed a second way to get signed out. The app used to sign out when the profile couldn't be loaded, which on a weak gym connection happened often. Now only an account that was deleted or disabled is signed out. Anything else opens the app and syncs later.

1.7.0 had already been approved by Play. I never published it, and shipped 1.7.1 with the fix instead.

Smaller things

  • Separate units for weights (kg or lb) and body measurements (cm or in), chosen during onboarding and defaulting to your region.
  • No camera permission. "Take photo" hands off to the system camera app, which needs no permission at all.
  • About 900 KB smaller. The R8 rules no longer keep whole libraries.
  • Set numbers that make sense. Left and right share a number (1, 1, 2, 3), warm-ups show "W", and a one-sided set counts once both sides are logged.

What I'd tell myself before 1.7.0

  • Put the action where your hands already are. For a gym app, that's the lock screen.
  • Anything restored from a backup has to survive without the old device's keys.
  • Hand out scarce things, like the first 100 numbers, from a server in a transaction.
  • Don't sign people out because the network is slow.

Version 1.7.1 is live on Google Play. Next, DotShredzilla learns five languages, including right-to-left Arabic. What would you want to do from a notification without opening the app?

Google Play: DotShredzilla
Source: github.com/kareem2099/Shredzilla
Privacy & terms: dotsuite.dev
Support: s******@dotsuite.dev

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.