DEV Community

Cover image for Building DotShredzilla (Part 3): What a Real Gym Session Taught My Data Model
freerave
freerave

Posted on

Building DotShredzilla (Part 3): What a Real Gym Session Taught My Data Model

After the redesign in Part 2, DotShredzilla looked finished. Then I took it to the gym and logged a real leg day with it.

Three problems showed up before the first exercise was done:

  1. The gym had poor signal, and the app wasn't built for that.
  2. Most machines use a weight stack, and you count plates, not kilograms. The app only accepted kilograms.
  3. I wanted leg curl first, but the list order was fixed.

This part is about turning that session into changes in the data model. DotShredzilla is an Android workout tracker from FreeRave (DotSuite), written in Kotlin, Jetpack Compose and Firestore, and open source under Apache License 2.0: github.com/kareem2099/Shredzilla.

Offline-first with Firestore

Firestore already queues writes offline, so I assumed the app worked without signal. It mostly didn't. Three things were waiting on the server:

  • Refreshing after a save. The UI refreshed history in the write's success listener. Offline, that listener doesn't fire until the device reconnects, so a saved set seemed to vanish. Local writes are applied to the cache immediately, so the refresh now runs right after the write is issued.
  • A transaction for adding an exercise. Transactions need the server. Because the exercise id is derived from its name, a merge write does the same job and queues offline.
  • Loading 90 days of history from the server. On weak signal that was slow and sometimes empty. History now loads from the cache first, so it shows instantly, then refreshes from the server.

An offline banner appears when the default network isn't validated, so gym Wi-Fi that's connected but has no real internet counts as offline too.

The bug hiding in an "empty" history

While testing history I found a deeper bug: the progress chart and exercise history were always empty, even with sets logged.

Sets were written to users/{uid}/dailyActivity/{date}/recordedSets/{id}, but the day document dailyActivity/{date} itself was never created. Firestore can't list documents that don't exist, even when they have subcollections, so listing the days returned nothing.

The fix had two parts. History reads the last 90 days by date key instead of listing the collection, and every new set also writes its day document with a merge. Existing days are backfilled the first time they're read.

Loads aren't just kilograms

A set's "load" turned out to have four shapes:

  • Weight, stored in kilograms and shown in the user's unit.
  • Plates on a weight-stack machine: "6 plates × 13".
  • Bodyweight, optionally with weight added on top: "BW + 10 kg".
  • Per side on plate-loaded machines: "30 kg/side". The total (60 kg) is stored, so volume and records stay correct.

The record sheet has one load card with a kg | Plates | Bodyweight switch, and the next set starts from the last one you logged. Choose plates once on the leg press and it stays on plates.

New Firestore fields are written only when they differ from the default. Older sets simply read as "normal set, kilograms, both sides", and no migration was needed. Edits explicitly delete fields that were turned off, so switching a set from plates back to kilograms doesn't leave a stale plate count behind.

The record sheet on a cable machine: reps for both sides or one, the Load switch set to plates (15 plates), set type and tempo

One leg at a time

My measurements showed one thigh noticeably bigger than the other, and the usual answer is to train one side at a time. That needed more than a "left/right" label:

  • The next set opens on the other side automatically.
  • The rest timer starts only after both sides are done, not between them.
  • A left and a right set count as one set toward the target, so "3 sets" means three per leg.

The counting rule is small enough to show in full:

fun List<LoggedSet>.workingSetCount(): Int {
    val working = filter { it.setType != SetType.WARMUP }
    return working.count { it.side == null } +
        maxOf(working.count { it.side == Side.LEFT }, working.count { it.side == Side.RIGHT })
}
Enter fullscreen mode Exit fullscreen mode

And the rest timer waits until the pair is complete:

// One side at a time: rest once both sides of the pair are done, not between them
val pairComplete = entry.side == null ||
    todaySets.count { it.side == entry.side } + 1 <= todaySets.count { it.side == entry.side.opposite }
Enter fullscreen mode Exit fullscreen mode

Warm-ups and tempo

My training log was full of notes like "warm-up", "5 seconds down", "2 second hold at the top", and "rest-pause: to 7 reps, 5 seconds, then to 13". Typing those every set was tedious, and warm-ups were inflating my volume.

Each set now has a type (normal, warm-up, rest-pause, drop set, to failure) and a tempo (lowering and hold seconds, as quick chips). Tempo carries over to the next set, so "5 seconds down" is chosen once per exercise.

Warm-ups are still logged but stay out of set counts, daily totals, volume, personal records and progression suggestions. That one rule fixed several numbers at once.

Putting leg curl first

The last problem was the simplest: lists now support drag-to-reorder through a handle on each row. The order updates live while dragging and saves once when you let go. It's one Firestore write, and it queues offline like everything else.

A smaller catalog problem

Several machines from my log weren't in the app, and adding one meant knowing that the search box doubled as a "create" field. The add-exercise page now has a catalog grouped by muscle (legs, chest, back, shoulders, biceps, triceps, forearms, core) with the common machines, and typing still creates anything missing.

What I took from it

  • Test offline on purpose: airplane mode, then a weak connection, then back online.
  • If a Firestore path has subcollections, write the parent document too, or you can't list it later.
  • Model a set around how people actually train. "Kilograms × reps" is one case, not the whole model.

Next, in Part 4: the features built on top of this data, including workout mode with supersets, last-session comparison, personal records, deload reminders and body-measurement insights.

How do you log machine exercises: by plate number, by weight, or not at all?

Google Play: DotShredzilla

Source: github.com/kareem2099/Shredzilla

Project: DotSuite

Top comments (0)