Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add 20 medals in 3D, the celebration and saving the card to the gallery
InlitX1b383b56b086
diff --git a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.ktindex 976db0e..d36f81c 100644--- a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt+++ b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt@@ -1,5 +1,64 @@package com.gymmane.app+import android.content.ContentValues+import android.os.Build+import android.os.Environment+import android.provider.MediaStoreimport io.flutter.embedding.android.FlutterActivity+import io.flutter.embedding.engine.FlutterEngine+import io.flutter.plugin.common.MethodChannel+import java.io.File+import java.io.FileOutputStream-class MainActivity : FlutterActivity()+class MainActivity : FlutterActivity() {+ override fun configureFlutterEngine(flutterEngine: FlutterEngine) {+ super.configureFlutterEngine(flutterEngine)+ MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "gymmane/gallery")+ .setMethodCallHandler { call, result ->+ if (call.method != "savePng") {+ result.notImplemented()+ return@setMethodCallHandler+ }+ val bytes = call.argument<ByteArray>("bytes")+ val name = call.argument<String>("name") ?: "gymmane.png"+ if (bytes == null) {+ result.error("no-bytes", "missing image", null)+ return@setMethodCallHandler+ }+ try {+ result.success(savePng(bytes, name))+ } catch (e: Exception) {+ result.error("save-failed", e.message, null)+ }+ }+ }++ private fun savePng(bytes: ByteArray, name: String): Boolean {+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {+ val values = ContentValues().apply {+ put(MediaStore.Images.Media.DISPLAY_NAME, name)+ put(MediaStore.Images.Media.MIME_TYPE, "image/png")+ put(MediaStore.Images.Media.RELATIVE_PATH, "${Environment.DIRECTORY_PICTURES}/GymMane")+ put(MediaStore.Images.Media.IS_PENDING, 1)+ }+ val resolver = contentResolver+ val uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)+ ?: return false+ resolver.openOutputStream(uri)?.use { it.write(bytes) } ?: return false+ values.clear()+ values.put(MediaStore.Images.Media.IS_PENDING, 0)+ resolver.update(uri, values, null, null)+ return true+ }++ val dir = File(+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),+ "GymMane",+ )+ if (!dir.exists() && !dir.mkdirs()) return false+ val file = File(dir, name)+ FileOutputStream(file).use { it.write(bytes) }+ MediaStore.Images.Media.insertImage(contentResolver, file.absolutePath, name, null)+ return true+ }+}diff --git a/assets/badges/firstRecord.webp b/assets/badges/firstRecord.webpnew file mode 100644index 0000000..f28c012Binary files /dev/null and b/assets/badges/firstRecord.webp differdiff --git a/assets/badges/firstRecord_off.webp b/assets/badges/firstRecord_off.webpnew file mode 100644index 0000000..662f16aBinary files /dev/null and b/assets/badges/firstRecord_off.webp differdiff --git a/assets/badges/firstRoutine.webp b/assets/badges/firstRoutine.webpnew file mode 100644index 0000000..e2eb682Binary files /dev/null and b/assets/badges/firstRoutine.webp differdiff --git a/assets/badges/firstRoutine_off.webp b/assets/badges/firstRoutine_off.webpnew file mode 100644index 0000000..1e2bf64Binary files /dev/null and b/assets/badges/firstRoutine_off.webp differdiff --git a/assets/badges/firstStep.webp b/assets/badges/firstStep.webpnew file mode 100644index 0000000..89a9c24Binary files /dev/null and b/assets/badges/firstStep.webp differdiff --git a/assets/badges/firstStep_off.webp b/assets/badges/firstStep_off.webpnew file mode 100644index 0000000..89b56abBinary files /dev/null and b/assets/badges/firstStep_off.webp differdiff --git a/assets/badges/firstWorkout.webp b/assets/badges/firstWorkout.webpnew file mode 100644index 0000000..a3a3d9aBinary files /dev/null and b/assets/badges/firstWorkout.webp differdiff --git a/assets/badges/firstWorkout_off.webp b/assets/badges/firstWorkout_off.webpnew file mode 100644index 0000000..b28370fBinary files /dev/null and b/assets/badges/firstWorkout_off.webp differdiff --git a/assets/badges/hours10.webp b/assets/badges/hours10.webpnew file mode 100644index 0000000..0b2e48bBinary files /dev/null and b/assets/badges/hours10.webp differdiff --git a/assets/badges/hours100.webp b/assets/badges/hours100.webpnew file mode 100644index 0000000..890f9d5Binary files /dev/null and b/assets/badges/hours100.webp differdiff --git a/assets/badges/hours100_off.webp b/assets/badges/hours100_off.webpnew file mode 100644index 0000000..d5efa2fBinary files /dev/null and b/assets/badges/hours100_off.webp differdiff --git a/assets/badges/hours10_off.webp b/assets/badges/hours10_off.webpnew file mode 100644index 0000000..0e3ee10Binary files /dev/null and b/assets/badges/hours10_off.webp differdiff --git a/assets/badges/hours50.webp b/assets/badges/hours50.webpnew file mode 100644index 0000000..7899123Binary files /dev/null and b/assets/badges/hours50.webp differdiff --git a/assets/badges/hours50_off.webp b/assets/badges/hours50_off.webpnew file mode 100644index 0000000..7a5470eBinary files /dev/null and b/assets/badges/hours50_off.webp differdiff --git a/assets/badges/sets100.webp b/assets/badges/sets100.webpnew file mode 100644index 0000000..936e677Binary files /dev/null and b/assets/badges/sets100.webp differdiff --git a/assets/badges/sets1000.webp b/assets/badges/sets1000.webpnew file mode 100644index 0000000..fee8491Binary files /dev/null and b/assets/badges/sets1000.webp differdiff --git a/assets/badges/sets1000_off.webp b/assets/badges/sets1000_off.webpnew file mode 100644index 0000000..1f28fd3Binary files /dev/null and b/assets/badges/sets1000_off.webp differdiff --git a/assets/badges/sets100_off.webp b/assets/badges/sets100_off.webpnew file mode 100644index 0000000..1cce5acBinary files /dev/null and b/assets/badges/sets100_off.webp differdiff --git a/assets/badges/streak100.webp b/assets/badges/streak100.webpnew file mode 100644index 0000000..eb34f2eBinary files /dev/null and b/assets/badges/streak100.webp differdiff --git a/assets/badges/streak100_off.webp b/assets/badges/streak100_off.webpnew file mode 100644index 0000000..4ed8754Binary files /dev/null and b/assets/badges/streak100_off.webp differdiff --git a/assets/badges/streak3.webp b/assets/badges/streak3.webpnew file mode 100644index 0000000..442bd9eBinary files /dev/null and b/assets/badges/streak3.webp differdiff --git a/assets/badges/streak30.webp b/assets/badges/streak30.webpnew file mode 100644index 0000000..8a1ab6dBinary files /dev/null and b/assets/badges/streak30.webp differdiff --git a/assets/badges/streak30_off.webp b/assets/badges/streak30_off.webpnew file mode 100644index 0000000..537ea86Binary files /dev/null and b/assets/badges/streak30_off.webp differdiff --git a/assets/badges/streak3_off.webp b/assets/badges/streak3_off.webpnew file mode 100644index 0000000..808ed23Binary files /dev/null and b/assets/badges/streak3_off.webp differdiff --git a/assets/badges/streak7.webp b/assets/badges/streak7.webpnew file mode 100644index 0000000..b99d8dcBinary files /dev/null and b/assets/badges/streak7.webp differdiff --git a/assets/badges/streak7_off.webp b/assets/badges/streak7_off.webpnew file mode 100644index 0000000..d60ae1dBinary files /dev/null and b/assets/badges/streak7_off.webp differdiff --git a/assets/badges/tonne1.webp b/assets/badges/tonne1.webpnew file mode 100644index 0000000..cc87e4eBinary files /dev/null and b/assets/badges/tonne1.webp differdiff --git a/assets/badges/tonne1_off.webp b/assets/badges/tonne1_off.webpnew file mode 100644index 0000000..d80cd6cBinary files /dev/null and b/assets/badges/tonne1_off.webp differdiff --git a/assets/badges/tonnes10.webp b/assets/badges/tonnes10.webpnew file mode 100644index 0000000..101e54eBinary files /dev/null and b/assets/badges/tonnes10.webp differdiff --git a/assets/badges/tonnes100.webp b/assets/badges/tonnes100.webpnew file mode 100644index 0000000..da41d76Binary files /dev/null and b/assets/badges/tonnes100.webp differdiff --git a/assets/badges/tonnes100_off.webp b/assets/badges/tonnes100_off.webpnew file mode 100644index 0000000..ccc45a7Binary files /dev/null and b/assets/badges/tonnes100_off.webp differdiff --git a/assets/badges/tonnes10_off.webp b/assets/badges/tonnes10_off.webpnew file mode 100644index 0000000..0120657Binary files /dev/null and b/assets/badges/tonnes10_off.webp differdiff --git a/assets/badges/workouts10.webp b/assets/badges/workouts10.webpnew file mode 100644index 0000000..6315d63Binary files /dev/null and b/assets/badges/workouts10.webp differdiff --git a/assets/badges/workouts100.webp b/assets/badges/workouts100.webpnew file mode 100644index 0000000..6e3dd9cBinary files /dev/null and b/assets/badges/workouts100.webp differdiff --git a/assets/badges/workouts100_off.webp b/assets/badges/workouts100_off.webpnew file mode 100644index 0000000..6260eb1Binary files /dev/null and b/assets/badges/workouts100_off.webp differdiff --git a/assets/badges/workouts10_off.webp b/assets/badges/workouts10_off.webpnew file mode 100644index 0000000..ed1d09fBinary files /dev/null and b/assets/badges/workouts10_off.webp differdiff --git a/assets/badges/workouts365.webp b/assets/badges/workouts365.webpnew file mode 100644index 0000000..b70fad6Binary files /dev/null and b/assets/badges/workouts365.webp differdiff --git a/assets/badges/workouts365_off.webp b/assets/badges/workouts365_off.webpnew file mode 100644index 0000000..636516dBinary files /dev/null and b/assets/badges/workouts365_off.webp differdiff --git a/assets/badges/workouts50.webp b/assets/badges/workouts50.webpnew file mode 100644index 0000000..15597e7Binary files /dev/null and b/assets/badges/workouts50.webp differdiff --git a/assets/badges/workouts50_off.webp b/assets/badges/workouts50_off.webpnew file mode 100644index 0000000..399b6d4Binary files /dev/null and b/assets/badges/workouts50_off.webp differdiff --git a/assets/shaders/medal.frag b/assets/shaders/medal.fragnew file mode 100644index 0000000..b2e98d6--- /dev/null+++ b/assets/shaders/medal.frag@@ -0,0 +1,247 @@+#version 460 core+#include <flutter/runtime_effect.glsl>++precision highp float;++uniform vec2 uSize;+uniform float uAngle;+uniform float uTilt;+uniform float uTime;+uniform float uLocked;+uniform float uShape;+uniform float uGem;+uniform float uIconSpan;+uniform vec3 uBase;+uniform vec3 uLip;+uniform vec3 uPlateTop;+uniform vec3 uPlateLow;+uniform vec3 uInk;+uniform vec3 uGemColor;+uniform sampler2D uIcon;+uniform sampler2D uBack;++out vec4 fragColor;+++const float R_BODY = 1.0;+const float R_STEP = 0.875;+const float R_PLATE = 0.735;+const float Z_BACK = -0.145;++float sdHex(vec2 p, float r) {+ const vec3 k = vec3(-0.866025404, 0.5, 0.577350269);+ p = abs(p);+ p -= 2.0 * min(dot(k.xy, p), 0.0) * k.xy;+ p -= vec2(clamp(p.x, -k.z * r, k.z * r), r);+ return length(p) * sign(p.y);+}++float outline2d(vec2 p, float r) {+ // hexagono en punta arriba, como el arte+ vec2 q = vec2(p.x * 0.866025404 - p.y * 0.5, p.x * 0.5 + p.y * 0.866025404);+ float k = r * 0.19;+ return mix(sdHex(q, r * 0.94 - k) - k, length(p) - r, uShape);+}++// slab between zBack and zFront with rounded edges+float prism(vec3 p, float r, float zFront, float round) {+ float d2 = outline2d(p.xy, r - round);+ float zc = (zFront + Z_BACK) * 0.5;+ float hz = (zFront - Z_BACK) * 0.5 - round;+ vec2 w = vec2(d2, abs(p.z - zc) - hz);+ return min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - round;+}++float mapMedal(vec3 p) {+ float body = prism(p, R_BODY, 0.145, 0.070);+ float step = prism(p, R_STEP, 0.180, 0.050);+ float plate = prism(p, R_PLATE, 0.212, 0.055);+ return min(body, min(step, plate));+}++vec3 normalAt(vec3 p) {+ vec2 e = vec2(0.0016, 0.0);+ return normalize(vec3(+ mapMedal(p + e.xyy) - mapMedal(p - e.xyy),+ mapMedal(p + e.yxy) - mapMedal(p - e.yxy),+ mapMedal(p + e.yyx) - mapMedal(p - e.yyx)));+}++const float BACK_SPAN = 0.92;++float backAt(vec2 xy) {+ vec2 uv = vec2(0.5 - xy.x / BACK_SPAN * 0.5, 0.5 - xy.y / BACK_SPAN * 0.5);+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) return 0.0;+ return texture(uBack, uv).a;+}++float iconAt(vec2 xy) {+ vec2 uv = vec2(0.5 + xy.x / uIconSpan * 0.5, 0.5 - xy.y / uIconSpan * 0.5);+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) return 0.0;+ return texture(uIcon, uv).a;+}++// estudio: cielo suave y dos focos alargados en diagonal que cruzan el borde+float bank(vec3 d, vec3 dir, vec3 up, float len, float wid, float soft) {+ float z = dot(d, dir);+ if (z < 0.08) return 0.0;+ vec3 side = normalize(cross(up, dir));+ float x = dot(d, side) / z;+ float y = dot(d, up) / z;+ float dx = max(abs(x) - len, 0.0);+ float dy = max(abs(y) - wid, 0.0);+ return exp(-(dx * dx + dy * dy) * soft);+}++vec3 env(vec3 d, float t) {+ float up = smoothstep(-0.9, 1.0, d.y);+ vec3 sky = mix(vec3(0.14, 0.145, 0.16), vec3(0.82, 0.85, 0.92), up * 0.55 + up * up * 0.45);+ float sway = sin(t * 0.45) * 0.35;++ vec3 a = normalize(vec3(-0.45 + sway, 0.72, 0.62));+ vec3 b = normalize(vec3(0.78, -0.28 + sway * 0.4, 0.56));+ vec3 c = normalize(vec3(0.10, 0.96, -0.25));++ float s1 = bank(d, a, normalize(vec3(0.62, 0.55, 0.0)), 0.95, 0.055, 26.0);+ float s2 = bank(d, b, normalize(vec3(-0.5, 0.7, 0.0)), 0.70, 0.05, 34.0);+ float s3 = bank(d, c, normalize(vec3(1.0, 0.0, 0.0)), 0.6, 0.35, 6.0);++ return sky+ + vec3(1.0, 0.97, 0.92) * s1 * 9.5+ + vec3(1.0, 0.86, 0.70) * s2 * 4.4+ + vec3(0.72, 0.80, 0.95) * s3 * 1.7;+}++vec3 metalShade(vec3 n, vec3 rd, vec3 tint, float rough, float t) {+ vec3 r = reflect(rd, n);+ vec3 sharp = env(r, t);+ vec3 wide = env(normalize(r + vec3(0.22, 0.30, 0.0)), t)+ + env(normalize(r - vec3(0.24, 0.18, 0.0)), t);+ vec3 refl = mix(sharp, wide * 0.5, clamp(rough * 1.6, 0.0, 1.0));+ float fres = pow(1.0 - max(dot(n, -rd), 0.0), 5.0);+ return tint * refl * 1.15 + vec3(fres) * 0.22;+}++vec3 dull(vec3 c) {+ float g = dot(c, vec3(0.30, 0.59, 0.11));+ return mix(c, vec3(g), 0.45) * 0.40;+}++vec3 matteShade(vec3 n, vec3 tint) {+ vec3 l = normalize(vec3(0.34, 0.78, 0.52));+ float d = max(dot(n, l), 0.0) * 0.74 + 0.30;+ float sheen = pow(max(dot(reflect(vec3(0.0, 0.0, -1.0), n), l), 0.0), 16.0) * 0.18;+ float rim = pow(1.0 - abs(n.z), 3.0) * 0.13;+ return tint * d + vec3(sheen + rim * 0.5);+}++void main() {+ vec2 fc = FlutterFragCoord().xy;+ vec2 uv = (fc - 0.5 * uSize) / (0.5 * min(uSize.x, uSize.y));+ uv.y = -uv.y;++ vec3 ro = vec3(0.0, 0.0, 3.4);+ vec3 rd = normalize(vec3(uv * 0.405, -1.0));++ float ca = cos(-uAngle), sa = sin(-uAngle);+ float ct = cos(-uTilt), st = sin(-uTilt);+ mat3 toObj = mat3(ca, 0.0, -sa, 0.0, 1.0, 0.0, sa, 0.0, ca)+ * mat3(1.0, 0.0, 0.0, 0.0, ct, st, 0.0, -st, ct);+ vec3 o = toObj * ro;+ vec3 d = toObj * rd;++ float tHit = 2.0;+ float tNear = 2.0;+ float near = 1.0;+ float hit = 0.0;+ for (int i = 0; i < 80; i++) {+ vec3 p = o + d * tHit;+ float dist = mapMedal(p);+ if (dist < near) { near = dist; tNear = tHit; }+ if (dist < 0.0008) { hit = 1.0; break; }+ tHit += max(dist, 0.0015);+ if (tHit > 5.2) break;+ }+ float px = fwidth(uv.x) * 1.35;+ float cover = hit > 0.5 ? 1.0 : 1.0 - smoothstep(0.0, px, near);+ if (cover < 0.004) {+ fragColor = vec4(0.0);+ return;+ }+ if (hit < 0.5) tHit = tNear;++ vec3 p = o + d * tHit;+ vec3 n = normalAt(p);+ float t = uTime;++ float dPlate = outline2d(p.xy, R_PLATE);+ float dStep = outline2d(p.xy, R_STEP);+ bool onPlate = dPlate < -0.02 && p.z > 0.16;+ bool onGem = uGem > 0.5 && dPlate > -0.05 && dStep < 0.0 && p.z > 0.12;++ vec3 tint = uBase;+ float rough = 0.28;+ if (dStep > 0.0) { tint = uLip; rough = 0.20; }++ if (!onPlate && uGem < 0.5 && p.z > 0.15 && dStep < 0.0) {+ tint = uLip;+ rough = 0.18;+ }++ if (onPlate) {+ float ink = iconAt(p.xy);+ float shade = clamp(p.y / (R_PLATE * 1.35) * 0.5 + 0.5, 0.0, 1.0);+ tint = mix(uPlateLow, uPlateTop, shade) * 1.14;+ rough = 0.19;+ if (ink > 0.5) {+ tint = uInk;+ rough = 0.45;+ }+ float e = 0.006;+ vec2 g = vec2(iconAt(p.xy + vec2(e, 0.0)) - iconAt(p.xy - vec2(e, 0.0)),+ iconAt(p.xy + vec2(0.0, e)) - iconAt(p.xy - vec2(0.0, e)));+ n = normalize(n + vec3(-g * 0.55, 0.0));+ }++ if (onGem) {+ float ang = atan(p.y, p.x);+ float seg = 30.0;+ float k = floor(ang / (6.2831853 / seg));+ float odd = mod(k, 2.0) * 2.0 - 1.0;+ vec2 dir = normalize(p.xy + vec2(1e-5));+ vec2 tang = vec2(-dir.y, dir.x);+ n = normalize(n + vec3(dir * 0.42 * odd + tang * 0.30 * odd, 0.0));+ tint = uGemColor;+ rough = 0.05;+ }++ // sombra de contacto donde el plato y el escalon se apoyan+ float ao = 1.0;+ ao *= mix(0.62, 1.0, smoothstep(0.0, 0.055, abs(dPlate)));+ ao *= mix(0.70, 1.0, smoothstep(0.0, 0.05, abs(dStep)));++ if (p.z < Z_BACK + 0.02) {+ float dInner = outline2d(p.xy, R_STEP - 0.05);+ tint = dInner < 0.0 ? uBase : uLip;+ rough = dInner < 0.0 ? 0.30 : 0.20;+ ao *= mix(0.74, 1.0, smoothstep(0.0, 0.05, abs(dInner)));+ float mark = backAt(p.xy);+ if (mark > 0.5) {+ tint = mix(tint, uInk, 0.86);+ rough = 0.40;+ }+ float e = 0.0055;+ vec2 g = vec2(backAt(p.xy + vec2(e, 0.0)) - backAt(p.xy - vec2(e, 0.0)),+ backAt(p.xy + vec2(0.0, e)) - backAt(p.xy - vec2(0.0, e)));+ n = normalize(n + vec3(g * 0.5, 0.0));+ }++ vec3 col = uLocked > 0.5+ ? matteShade(n, dull(onGem ? uGemColor : uBase)) * ao+ : metalShade(n, normalize(d), tint, rough, t) * ao * 1.16;++ col = col / (col + vec3(0.82));+ col = pow(col, vec3(1.0 / 2.2));+ col += (fract(sin(dot(fc, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) / 255.0;+ fragColor = vec4(col * cover, cover);+}diff --git a/lib/catalog/awards.dart b/lib/catalog/awards.dartnew file mode 100644index 0000000..b66bf2b--- /dev/null+++ b/lib/catalog/awards.dart@@ -0,0 +1,54 @@+import '../l10n/l10n.dart';+import '../state/fit_state.dart';++String medalAsset(AwardId id) => 'assets/badges/${id.name}.webp';++String medalOffAsset(AwardId id) => 'assets/badges/${id.name}_off.webp';++String medalSpinAsset(AwardId id) => 'assets/badges/spin/${id.name}.webp';++String awardName(AwardId id) => switch (id) {+ AwardId.firstStep => t.awardFirstStepName,+ AwardId.firstWorkout => t.awardFirstWorkoutName,+ AwardId.firstRoutine => t.awardFirstRoutineName,+ AwardId.firstRecord => t.awardFirstRecordName,+ AwardId.streak3 => t.awardStreak3Name,+ AwardId.streak7 => t.awardStreak7Name,+ AwardId.workouts10 => t.awardWorkouts10Name,+ AwardId.tonne1 => t.awardTonne1Name,+ AwardId.sets100 => t.awardSets100Name,+ AwardId.hours10 => t.awardHours10Name,+ AwardId.workouts50 => t.awardWorkouts50Name,+ AwardId.tonnes10 => t.awardTonnes10Name,+ AwardId.hours50 => t.awardHours50Name,+ AwardId.streak30 => t.awardStreak30Name,+ AwardId.sets1000 => t.awardSets1000Name,+ AwardId.workouts100 => t.awardWorkouts100Name,+ AwardId.hours100 => t.awardHours100Name,+ AwardId.streak100 => t.awardStreak100Name,+ AwardId.tonnes100 => t.awardTonnes100Name,+ AwardId.workouts365 => t.awardWorkouts365Name,+ };++String awardLine(AwardId id) => switch (id) {+ AwardId.firstStep => t.awardFirstStepLine,+ AwardId.firstWorkout => t.awardFirstWorkoutLine,+ AwardId.firstRoutine => t.awardFirstRoutineLine,+ AwardId.firstRecord => t.awardFirstRecordLine,+ AwardId.streak3 => t.awardStreak3Line,+ AwardId.streak7 => t.awardStreak7Line,+ AwardId.workouts10 => t.awardWorkouts10Line,+ AwardId.tonne1 => t.awardTonne1Line,+ AwardId.sets100 => t.awardSets100Line,+ AwardId.hours10 => t.awardHours10Line,+ AwardId.workouts50 => t.awardWorkouts50Line,+ AwardId.tonnes10 => t.awardTonnes10Line,+ AwardId.hours50 => t.awardHours50Line,+ AwardId.streak30 => t.awardStreak30Line,+ AwardId.sets1000 => t.awardSets1000Line,+ AwardId.workouts100 => t.awardWorkouts100Line,+ AwardId.hours100 => t.awardHours100Line,+ AwardId.streak100 => t.awardStreak100Line,+ AwardId.tonnes100 => t.awardTonnes100Line,+ AwardId.workouts365 => t.awardWorkouts365Line,+ };diff --git a/lib/catalog/medal_look.dart b/lib/catalog/medal_look.dartnew file mode 100644index 0000000..741b97d--- /dev/null+++ b/lib/catalog/medal_look.dart@@ -0,0 +1,56 @@+import 'package:flutter/widgets.dart';+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';++import '../state/fit_state.dart';++class MedalMetal {+ const MedalMetal(this.base, this.lip, this.plateTop, this.plateLow, this.ink);++ final int base;+ final int lip;+ final int plateTop;+ final int plateLow;+ final int ink;+}++const _bronze = MedalMetal(0xa96a38, 0xe3a878, 0xf1b585, 0xab6635, 0x40251a);+const _silver = MedalMetal(0xa3abb6, 0xe2e9f0, 0xf7fafd, 0xa9b4c1, 0x272e37);+const _gold = MedalMetal(0xc6982c, 0xf6d97b, 0xf8e296, 0xbf8f1c, 0x43300c);+const _diamond = MedalMetal(0xb2c9dc, 0xeaf5fd, 0xffffff, 0xc1d6e6, 0x1f3646);++const _ruby = 0xc02347;+const _sapphire = 0x2f63c4;+const _emerald = 0x1f9f74;++class MedalLook {+ const MedalLook(this.icon, this.metal, {this.round = false, this.gem});++ final IconData icon;+ final MedalMetal metal;+ final bool round;+ final int? gem;+}++MedalLook medalLook(AwardId id) => switch (id) {+ AwardId.firstStep => const MedalLook(PhosphorIconsFill.flag, _bronze),+ AwardId.firstWorkout => const MedalLook(PhosphorIconsFill.barbell, _bronze, round: true),+ AwardId.firstRoutine => const MedalLook(PhosphorIconsFill.calendarCheck, _bronze),+ AwardId.firstRecord => const MedalLook(PhosphorIconsFill.trendUp, _bronze, round: true),+ AwardId.streak3 => const MedalLook(PhosphorIconsFill.fire, _bronze),+ AwardId.tonne1 => const MedalLook(PhosphorIconsFill.scales, _bronze, round: true),+ AwardId.sets100 => const MedalLook(PhosphorIconsFill.repeat, _bronze),+ AwardId.streak7 => const MedalLook(PhosphorIconsFill.fire, _silver),+ AwardId.workouts10 => const MedalLook(PhosphorIconsFill.barbell, _silver, round: true),+ AwardId.hours10 => const MedalLook(PhosphorIconsFill.hourglass, _silver),+ AwardId.workouts50 => const MedalLook(PhosphorIconsFill.sneakerMove, _silver, round: true),+ AwardId.tonnes10 => const MedalLook(PhosphorIconsFill.scales, _silver),+ AwardId.sets1000 => const MedalLook(PhosphorIconsFill.repeat, _silver, round: true),+ AwardId.streak30 => const MedalLook(PhosphorIconsFill.fire, _gold),+ AwardId.hours50 => const MedalLook(PhosphorIconsFill.hourglass, _gold, round: true),+ AwardId.workouts100 => const MedalLook(PhosphorIconsFill.medal, _gold),+ AwardId.hours100 => const MedalLook(PhosphorIconsFill.clock, _gold, round: true),+ AwardId.streak100 => const MedalLook(PhosphorIconsFill.fire, _diamond, gem: _ruby),+ AwardId.tonnes100 => const MedalLook(PhosphorIconsFill.stack, _diamond, gem: _sapphire),+ AwardId.workouts365 =>+ const MedalLook(PhosphorIconsFill.trophy, _diamond, round: true, gem: _emerald),+ };diff --git a/lib/screens/awards_screen.dart b/lib/screens/awards_screen.dartnew file mode 100644index 0000000..5db62e8--- /dev/null+++ b/lib/screens/awards_screen.dart@@ -0,0 +1,109 @@+import 'package:flutter/material.dart';++import '../catalog/awards.dart';+import '../l10n/l10n.dart';+import '../state/fit_state.dart';+import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import '../widgets/medal.dart';+import '../widgets/medal_shelf.dart';+import '../widgets/ui_kit.dart';++class AwardsScreen extends StatelessWidget {+ const AwardsScreen({super.key});++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final won = AwardId.values.where(fit.hasAward).toList();+ final left = AwardId.values.where((a) => !fit.hasAward(a)).toList();++ return SafeArea(+ bottom: false,+ child: SingleChildScrollView(+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 32),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ ScreenHeader(title: t.awardsTitle, onBack: fit.backFromAwards),+ const SizedBox(height: 22),+ if (won.isNotEmpty) ...[+ _section(gc, t.awardsEarned, won.length),+ const SizedBox(height: 14),+ _grid(context, won),+ const SizedBox(height: 30),+ ],+ if (left.isNotEmpty) ...[+ _section(gc, t.awardsLocked, left.length),+ const SizedBox(height: 14),+ _grid(context, left),+ ],+ ],+ ),+ ),+ );+ }++ Widget _section(GymColors gc, String label, int count) {+ return Row(+ children: [+ Text(label, style: AppTheme.f(19, color: gc.text)),+ const SizedBox(width: 8),+ Text('$count', style: AppTheme.f(16, weight: FontWeight.w600, color: gc.textTertiary)),+ ],+ );+ }++ Widget _grid(BuildContext context, List<AwardId> ids) {+ return GridView.builder(+ shrinkWrap: true,+ physics: const NeverScrollableScrollPhysics(),+ itemCount: ids.length,+ gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(+ crossAxisCount: 2,+ mainAxisSpacing: 12,+ crossAxisSpacing: 12,+ childAspectRatio: 0.86,+ ),+ itemBuilder: (_, i) => _card(context, ids[i]),+ );+ }++ Widget _card(BuildContext context, AwardId id) {+ final gc = context.gc;+ final won = fit.hasAward(id);+ final at = fit.awardWonAt(id);+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => showMedalSheet(context, id),+ child: Container(+ padding: const EdgeInsets.fromLTRB(12, 16, 12, 14),+ decoration: BoxDecoration(+ color: gc.bgRaised,+ borderRadius: BorderRadius.circular(20),+ ),+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Medal(id: id, size: 96, locked: !won),+ const SizedBox(height: 14),+ Text(+ awardName(id),+ maxLines: 2,+ textAlign: TextAlign.center,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(14, color: won ? gc.text : gc.textSecondary),+ ),+ const SizedBox(height: 4),+ Text(+ won && at != null+ ? t.shortDateYear(at)+ : '${medalShort(fit.awardValue(id))} / ${medalShort(fit.awardGoal(id))}',+ style: AppTheme.f(11.5, weight: FontWeight.w600, color: gc.textTertiary),+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/lib/services/gallery.dart b/lib/services/gallery.dartnew file mode 100644index 0000000..a6e93b9--- /dev/null+++ b/lib/services/gallery.dart@@ -0,0 +1,12 @@+import 'package:flutter/services.dart';++const _channel = MethodChannel('gymmane/gallery');++Future<bool> saveImageToGallery(Uint8List png, String name) async {+ try {+ final ok = await _channel.invokeMethod<bool>('savePng', {'bytes': png, 'name': name});+ return ok ?? false;+ } catch (_) {+ return false;+ }+}diff --git a/lib/state/awards_state.dart b/lib/state/awards_state.dartnew file mode 100644index 0000000..2151746--- /dev/null+++ b/lib/state/awards_state.dart@@ -0,0 +1,120 @@+part of 'fit_state.dart';++enum AwardId {+ firstStep,+ firstWorkout,+ firstRoutine,+ firstRecord,+ streak3,+ streak7,+ workouts10,+ tonne1,+ sets100,+ hours10,+ workouts50,+ tonnes10,+ hours50,+ streak30,+ sets1000,+ workouts100,+ hours100,+ streak100,+ tonnes100,+ workouts365,+}++mixin AwardsState on FitCore, StatsState, SettingsState {+ final Map<String, DateTime> awards = {};+ final List<AwardId> pendingAwards = [];+ final Set<String> awardsSeen = {};++ int awardGoal(AwardId id) => switch (id) {+ AwardId.firstStep ||+ AwardId.firstWorkout ||+ AwardId.firstRoutine ||+ AwardId.firstRecord =>+ 1,+ AwardId.streak3 => 3,+ AwardId.streak7 => 7,+ AwardId.streak30 => 30,+ AwardId.streak100 => 100,+ AwardId.workouts10 => 10,+ AwardId.workouts50 => 50,+ AwardId.workouts100 => 100,+ AwardId.workouts365 => 365,+ AwardId.tonne1 => 1000,+ AwardId.tonnes10 => 10000,+ AwardId.tonnes100 => 100000,+ AwardId.sets100 => 100,+ AwardId.sets1000 => 1000,+ AwardId.hours10 => 10,+ AwardId.hours50 => 50,+ AwardId.hours100 => 100,+ };++ int awardValue(AwardId id) => switch (id) {+ AwardId.firstStep => onboarded ? 1 : 0,+ AwardId.firstRoutine => routines.length,+ AwardId.firstRecord => personalRecords.length,+ AwardId.streak3 ||+ AwardId.streak7 ||+ AwardId.streak30 ||+ AwardId.streak100 =>+ currentStreak,+ AwardId.firstWorkout ||+ AwardId.workouts10 ||+ AwardId.workouts50 ||+ AwardId.workouts100 ||+ AwardId.workouts365 =>+ totalSessions,+ AwardId.tonne1 || AwardId.tonnes10 || AwardId.tonnes100 => totalVolumeKg.round(),+ AwardId.sets100 || AwardId.sets1000 => totalSets,+ AwardId.hours10 || AwardId.hours50 || AwardId.hours100 => totalTime.inHours,+ };++ double awardProgress(AwardId id) =>+ (awardValue(id) / awardGoal(id)).clamp(0.0, 1.0);++ bool hasAward(AwardId id) => awards.containsKey(id.name);++ DateTime? awardWonAt(AwardId id) => awards[id.name];++ int get awardCount => awards.length;++ List<AwardId> get unseenAwards =>+ AwardId.values.where((a) => hasAward(a) && !awardsSeen.contains(a.name)).toList();++ @override+ void refreshAwards({bool silent = false}) {+ var won = false;+ for (final id in AwardId.values) {+ if (hasAward(id) || awardValue(id) < awardGoal(id)) continue;+ awards[id.name] = DateTime.now();+ if (!silent) pendingAwards.add(id);+ won = true;+ }+ if (!won) return;+ _persist();+ notifyListeners();+ }++ void goAwards() => pushRoute('awards');++ void backFromAwards() => popRoute(fallback: 'settings');++ AwardId? get nextCelebration => pendingAwards.isEmpty ? null : pendingAwards.first;++ void celebrationShown() {+ if (pendingAwards.isEmpty) return;+ awardsSeen.add(pendingAwards.removeAt(0).name);+ _persist();+ notifyListeners();+ }++ void markAwardsSeen() {+ if (unseenAwards.isEmpty) return;+ awardsSeen.addAll(awards.keys);+ _persist();+ notifyListeners();+ }+}diff --git a/lib/widgets/award_celebration.dart b/lib/widgets/award_celebration.dartnew file mode 100644index 0000000..cf35b47--- /dev/null+++ b/lib/widgets/award_celebration.dart@@ -0,0 +1,413 @@+import 'dart:math' as math;+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:flutter/services.dart';++import '../catalog/awards.dart';+import '../catalog/medal_look.dart';+import '../l10n/l10n.dart';+import '../services/gallery.dart';+import '../state/fit_state.dart';+import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import 'medal.dart';+import 'profile_avatar.dart';+import 'ui_kit.dart';++const _confettiColors = [+ Color(0xFFFF4D6D),+ Color(0xFF4CC3FF),+ Color(0xFF57D68D),+ Color(0xFFFFC93C),+ Color(0xFFB06CFF),+ Color(0xFFFF8A3D),+ Color(0xFFF4F6FA),+];++class AwardCelebration extends StatefulWidget {+ const AwardCelebration({super.key, required this.id, required this.onClose});++ final AwardId id;+ final VoidCallback onClose;++ @override+ State<AwardCelebration> createState() => _AwardCelebrationState();+}++class _AwardCelebrationState extends State<AwardCelebration> with TickerProviderStateMixin {+ final _cardKey = GlobalKey();+ late final AnimationController _in = AnimationController(+ vsync: this,+ duration: const Duration(milliseconds: 900),+ )..forward();+ late final AnimationController _fall = AnimationController(+ vsync: this,+ duration: const Duration(milliseconds: 5200),+ )..forward();+ late final List<_Bit> _bits = _seedBits(widget.id);+ bool _saving = false;+ String? _toast;++ @override+ void initState() {+ super.initState();+ HapticFeedback.mediumImpact();+ }++ @override+ void dispose() {+ _in.dispose();+ _fall.dispose();+ super.dispose();+ }++ double _stagger(double start, double end) {+ final v = ((_in.value - start) / (end - start)).clamp(0.0, 1.0);+ return Curves.easeOutCubic.transform(v);+ }++ Future<void> _save() async {+ if (_saving) return;+ setState(() => _saving = true);+ var message = t.shareFailed;+ try {+ final boundary = _cardKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;+ if (boundary != null) {+ final image = await boundary.toImage(pixelRatio: 3);+ final data = await image.toByteData(format: ui.ImageByteFormat.png);+ image.dispose();+ if (data != null) {+ final stamp = DateTime.now().millisecondsSinceEpoch;+ final ok = await saveImageToGallery(+ data.buffer.asUint8List(),+ 'gymmane-${widget.id.name}-$stamp.png',+ );+ if (ok) message = t.awardSaved;+ }+ }+ } catch (_) {+ message = t.shareFailed;+ }+ if (!mounted) return;+ HapticFeedback.lightImpact();+ setState(() {+ _saving = false;+ _toast = message;+ });+ await Future<void>.delayed(const Duration(milliseconds: 2600));+ if (mounted) setState(() => _toast = null);+ }++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final look = medalLook(widget.id);+ final glow = Color(0xFF000000 | look.metal.lip);+ final size = MediaQuery.sizeOf(context);+ final medal = math.min(math.min(size.width * 0.72, 300.0), size.height * 0.3);++ return AnimatedBuilder(+ animation: _in,+ builder: (context, _) {+ final scrim = Curves.easeOut.transform((_in.value * 2.2).clamp(0.0, 1.0));+ return Material(+ color: gc.pageBg.withValues(alpha: 0.95 * scrim),+ child: Stack(+ clipBehavior: Clip.none,+ children: [+ Positioned(+ left: -1400,+ top: 0,+ child: RepaintBoundary(+ key: _cardKey,+ child: _SaveCard(id: widget.id, gc: gc, bits: _bits),+ ),+ ),+ Positioned.fill(+ child: RepaintBoundary(+ child: CustomPaint(painter: _ConfettiPainter(_fall, _bits)),+ ),+ ),+ Positioned.fill(+ child: SafeArea(+ child: Padding(+ padding: const EdgeInsets.fromLTRB(26, 12, 26, 22),+ child: Column(+ children: [+ const Spacer(),+ Transform.scale(+ scale: 0.74 + 0.26 * _stagger(0, 0.55),+ child: Opacity(+ opacity: _stagger(0, 0.3),+ child: SizedBox(+ width: medal,+ height: medal,+ child: Stack(+ alignment: Alignment.center,+ children: [+ DecoratedBox(+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ gradient: RadialGradient(+ colors: [+ glow.withValues(alpha: 0.30 * _stagger(0.1, 0.7)),+ glow.withValues(alpha: 0),+ ],+ stops: const [0.18, 0.74],+ ),+ ),+ child: const SizedBox.expand(),+ ),+ MedalSpin(+ id: widget.id, size: medal, spinIn: true, faceFront: true),+ ],+ ),+ ),+ ),+ ),+ const SizedBox(height: 28),+ _fade(+ 0.3,+ 0.65,+ Text(+ t.awardUnlocked.toUpperCase(),+ textAlign: TextAlign.center,+ style: AppTheme.f(11.5,+ weight: FontWeight.w700,+ color: gc.textSecondary,+ letterSpacing: 2.6),+ ),+ ),+ const SizedBox(height: 12),+ _fade(+ 0.38,+ 0.75,+ Text(+ awardName(widget.id),+ textAlign: TextAlign.center,+ style: AppTheme.f(32, weight: FontWeight.w800, color: gc.text),+ ),+ ),+ const SizedBox(height: 12),+ _fade(+ 0.46,+ 0.85,+ Text(+ awardLine(widget.id),+ textAlign: TextAlign.center,+ style: AppTheme.f(13.5,+ weight: FontWeight.w500, color: gc.textSecondary, height: 1.45),+ ),+ ),+ const Spacer(),+ _fade(0.54, 0.95, _Signature(gc: gc, avatar: 34)),+ const SizedBox(height: 26),+ if (_toast != null)+ Padding(+ padding: const EdgeInsets.only(bottom: 14),+ child: Text(_toast!,+ style: AppTheme.f(12.5,+ weight: FontWeight.w600, color: gc.textSecondary)),+ ),+ _fade(0.6, 1, PrimaryButton(label: t.awardNice, onTap: widget.onClose)),+ const SizedBox(height: 4),+ _fade(+ 0.68,+ 1,+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: _saving ? null : _save,+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: 14),+ child: Text(+ _saving ? '…' : t.awardSaveImage,+ textAlign: TextAlign.center,+ style: AppTheme.f(13.5,+ weight: FontWeight.w700, color: gc.textSecondary),+ ),+ ),+ ),+ ),+ ],+ ),+ ),+ ),+ ),+ ],+ ),+ );+ },+ );+ }++ Widget _fade(double from, double to, Widget child) {+ final v = _stagger(from, to);+ return Opacity(+ opacity: v,+ child: Transform.translate(offset: Offset(0, 16 * (1 - v)), child: child),+ );+ }+}++class _SaveCard extends StatelessWidget {+ const _SaveCard({required this.id, required this.gc, required this.bits});++ final AwardId id;+ final GymColors gc;+ final List<_Bit> bits;++ @override+ Widget build(BuildContext context) {+ final at = fit.awardWonAt(id) ?? DateTime.now();+ return SizedBox(+ width: 360,+ height: 760,+ child: ColoredBox(+ color: gc.pageBg,+ child: Stack(+ children: [+ Positioned.fill(+ child: CustomPaint(+ painter: _ConfettiPainter(const AlwaysStoppedAnimation(0.4), bits),+ ),+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(28, 36, 28, 32),+ child: Column(+ children: [+ Text('GymMane', style: AppTheme.f(17, weight: FontWeight.w800, color: gc.text)),+ const Spacer(),+ Medal(id: id, size: 208),+ const SizedBox(height: 36),+ Text(t.awardUnlocked.toUpperCase(),+ textAlign: TextAlign.center,+ style: AppTheme.f(10.5,+ weight: FontWeight.w700, color: gc.textSecondary, letterSpacing: 2.4)),+ const SizedBox(height: 10),+ Text(awardName(id),+ textAlign: TextAlign.center,+ style: AppTheme.f(30, weight: FontWeight.w800, color: gc.text)),+ const SizedBox(height: 8),+ Text(awardLine(id),+ textAlign: TextAlign.center,+ style: AppTheme.f(13,+ weight: FontWeight.w500, color: gc.textSecondary, height: 1.4)),+ const Spacer(),+ _Signature(gc: gc, at: at),+ ],+ ),+ ),+ ],+ ),+ ),+ );+ }+}++class _Signature extends StatelessWidget {+ const _Signature({required this.gc, this.at, this.avatar = 40});++ final GymColors gc;+ final DateTime? at;+ final double avatar;++ @override+ Widget build(BuildContext context) {+ final date = at;+ return Column(+ children: [+ Container(width: 86, height: 1, color: gc.bgRaised2),+ SizedBox(height: avatar * 0.5),+ Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ ProfileAvatar(size: avatar),+ const SizedBox(width: 12),+ Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(fit.displayName,+ style: AppTheme.f(15, weight: FontWeight.w700, color: gc.text)),+ Text('@${fit.profileHandle}',+ style: AppTheme.f(12.5, weight: FontWeight.w500, color: gc.textSecondary)),+ ],+ ),+ ],+ ),+ if (date != null) ...[+ const SizedBox(height: 16),+ Text(t.shortDateYear(date),+ style: AppTheme.f(11.5, weight: FontWeight.w600, color: gc.textTertiary)),+ ],+ ],+ );+ }+}++class _Bit {+ _Bit(this.x, this.delay, this.fall, this.sway, this.spin, this.w, this.h, this.color);++ final double x;+ final double delay;+ final double fall;+ final double sway;+ final double spin;+ final double w;+ final double h;+ final Color color;+}++List<_Bit> _seedBits(AwardId id) {+ final rnd = math.Random(id.index * 7717 + 13);+ return List.generate(84, (_) {+ final strip = rnd.nextDouble() < 0.35;+ return _Bit(+ rnd.nextDouble(),+ rnd.nextDouble() * 0.30,+ 0.34 + rnd.nextDouble() * 0.12,+ (rnd.nextDouble() - 0.5) * 0.16,+ (rnd.nextDouble() - 0.5) * 15,+ strip ? 5 : 8 + rnd.nextDouble() * 4,+ strip ? 16 + rnd.nextDouble() * 8 : 8 + rnd.nextDouble() * 4,+ _confettiColors[rnd.nextInt(_confettiColors.length)],+ );+ });+}++class _ConfettiPainter extends CustomPainter {+ _ConfettiPainter(this.t, this.bits) : super(repaint: t);++ final Animation<double> t;+ final List<_Bit> bits;++ @override+ void paint(Canvas canvas, Size size) {+ final paint = Paint();+ for (final b in bits) {+ final life = (t.value - b.delay) / b.fall;+ if (life <= 0 || life >= 1.2) continue;+ final y = -0.08 + life * 1.22;+ final x = b.x + math.sin(life * 5.4 + b.x * 9) * b.sway;+ final fade = life < 0.05+ ? life / 0.05+ : (life > 0.86 ? (1 - (life - 0.86) / 0.14).clamp(0.0, 1.0) : 1.0);+ paint.color = b.color.withValues(alpha: fade);+ canvas.save();+ canvas.translate(x * size.width, y * size.height);+ canvas.rotate(life * b.spin);+ canvas.drawRRect(+ RRect.fromRectAndRadius(+ Rect.fromCenter(center: Offset.zero, width: b.w, height: b.h),+ const Radius.circular(1.6),+ ),+ paint,+ );+ canvas.restore();+ }+ }++ @override+ bool shouldRepaint(_ConfettiPainter old) => false;+}diff --git a/lib/widgets/medal.dart b/lib/widgets/medal.dartnew file mode 100644index 0000000..6cb66f6--- /dev/null+++ b/lib/widgets/medal.dart@@ -0,0 +1,359 @@+import 'dart:math' as math;+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/scheduler.dart';+import 'package:flutter/services.dart';++import '../catalog/awards.dart';+import '../catalog/medal_look.dart';+import '../l10n/l10n.dart';+import '../state/fit_state.dart';+import '../theme/app_theme.dart';++const double _restTilt = 0.13;++class Medal extends StatelessWidget {+ const Medal({super.key, required this.id, required this.size, this.locked = false});++ final AwardId id;+ final double size;+ final bool locked;++ @override+ Widget build(BuildContext context) {+ return Image.asset(+ locked ? medalOffAsset(id) : medalAsset(id),+ width: size,+ height: size,+ fit: BoxFit.contain,+ filterQuality: FilterQuality.medium,+ cacheWidth: (size * MediaQuery.devicePixelRatioOf(context)).round(),+ );+ }+}++Future<ui.FragmentProgram>? _programOnce;+final Map<int, Future<ui.Image>> _iconCache = {};++Future<ui.Image> _iconImage(IconData icon) {+ return _iconCache.putIfAbsent(icon.codePoint, () async {+ const px = 384.0;+ final recorder = ui.PictureRecorder();+ final canvas = Canvas(recorder);+ final painter = TextPainter(+ text: TextSpan(+ text: String.fromCharCode(icon.codePoint),+ style: TextStyle(+ fontSize: px * 0.84,+ fontFamily: icon.fontFamily,+ package: icon.fontPackage,+ color: const Color(0xFFFFFFFF),+ height: 1,+ ),+ ),+ textDirection: TextDirection.ltr,+ )..layout();+ painter.paint(canvas, Offset((px - painter.width) / 2, (px - painter.height) / 2));+ return recorder.endRecording().toImage(px.toInt(), px.toInt());+ });+}++Future<ui.Image> _backImage(String? handle, String title, String? date) {+ const px = 448.0;+ const width = px * 0.76;+ final recorder = ui.PictureRecorder();+ final canvas = Canvas(recorder);++ TextPainter paint(String text, double size, FontWeight weight, double spacing) => TextPainter(+ text: TextSpan(+ text: text,+ style: TextStyle(+ fontFamily: AppTheme.round,+ fontSize: size,+ fontWeight: weight,+ letterSpacing: spacing,+ color: const Color(0xFFFFFFFF),+ height: 1.12,+ ),+ ),+ textDirection: TextDirection.ltr,+ textAlign: TextAlign.center,+ )..layout(maxWidth: width);++ final lines = <(TextPainter, double)>[+ if (handle != null) (paint('@$handle', px * 0.055, FontWeight.w600, 0.5), px * 0.055),+ (paint(title.toUpperCase(), px * 0.072, FontWeight.w700, 1.6), px * 0.05),+ if (date != null) (paint(date, px * 0.062, FontWeight.w600, 0.2), px * 0.075),+ (paint('GYMMANE', px * 0.046, FontWeight.w700, 3.2), 0),+ ];++ var total = 0.0;+ for (final (tp, gap) in lines) {+ total += tp.height + gap;+ }+ var y = (px - total) / 2;+ for (final (tp, gap) in lines) {+ tp.paint(canvas, Offset((px - tp.width) / 2, y));+ y += tp.height + gap;+ }+ return recorder.endRecording().toImage(px.toInt(), px.toInt());+}++class MedalSpin extends StatefulWidget {+ const MedalSpin({+ super.key,+ required this.id,+ required this.size,+ this.locked = false,+ this.spinIn = false,+ this.faceFront = false,+ });++ final AwardId id;+ final double size;+ final bool locked;+ final bool spinIn;+ final bool faceFront;++ @override+ State<MedalSpin> createState() => _MedalSpinState();+}++class _MedalSpinState extends State<MedalSpin> with SingleTickerProviderStateMixin {+ final _pose = _Pose();+ late final Ticker _ticker = createTicker(_tick);+ ui.FragmentShader? _shader;+ ui.Image? _icon;+ ui.Image? _back;+ Duration _last = Duration.zero;+ double _yaw = 0;+ double _yawVel = 0;+ double _tilt = _restTilt;+ double _tiltVel = 0;+ double _time = 0;+ bool _held = false;+ bool _landed = true;+ int _face = 0;++ @override+ void initState() {+ super.initState();+ if (widget.spinIn) {+ _yaw = -math.pi * 2;+ _yawVel = 13;+ _landed = false;+ }+ _ticker.start();+ _load();+ }++ Future<void> _load() async {+ try {+ final program =+ await (_programOnce ??= ui.FragmentProgram.fromAsset('assets/shaders/medal.frag'));+ final icon = await _iconImage(medalLook(widget.id).icon);+ final at = fit.awardWonAt(widget.id);+ final back = await _backImage(+ fit.hasOwnIdentity ? fit.profileHandle : null,+ awardName(widget.id),+ at == null ? null : t.shortDateYear(at),+ );+ if (!mounted) return;+ setState(() {+ _shader = program.fragmentShader();+ _icon = icon;+ _back = back;+ });+ } catch (_) {}+ }++ @override+ void dispose() {+ _ticker.dispose();+ _pose.dispose();+ _shader?.dispose();+ _back?.dispose();+ super.dispose();+ }++ double get _restAngle {+ final turn = widget.faceFront ? 2 * math.pi : math.pi;+ return (_yaw / turn).roundToDouble() * turn;+ }++ double _spring(double x, double target, double vel, double stiffness, double damping, double dt) {+ return vel + (-(x - target) * stiffness - vel * damping) * dt;+ }++ void _tick(Duration now) {+ final dt = ((now - _last).inMicroseconds / 1e6).clamp(0.0, 0.04);+ _last = now;+ if (dt == 0) return;+ _time += dt;++ if (!_held) {+ if (_yawVel.abs() > 5.5) {+ _yaw += _yawVel * dt;+ _yawVel *= math.exp(-dt / 1.9);+ } else {+ final rest = _restAngle;+ _yawVel = _spring(_yaw, rest, _yawVel, 78, 11.5, dt);+ _yaw += _yawVel * dt;+ if (!_landed && (_yaw - rest).abs() < 0.045 && _yawVel.abs() < 0.9) {+ _landed = true;+ HapticFeedback.lightImpact();+ }+ }+ _tiltVel = _spring(_tilt, _restTilt, _tiltVel, 96, 13, dt);+ _tilt += _tiltVel * dt;+ _clickAtFace();+ }+ if (_atRest) {+ _yaw = _restAngle;+ _yawVel = 0;+ _tilt = _restTilt;+ _tiltVel = 0;+ _ticker.stop();+ }+ _pose.set(_yaw, _tilt, _time);+ }++ bool get _atRest {+ final rest = _restAngle;+ return !_held &&+ _yawVel.abs() < 0.02 &&+ (_yaw - rest).abs() < 0.002 &&+ _tiltVel.abs() < 0.02 &&+ (_tilt - _restTilt).abs() < 0.002;+ }++ void _wake() {+ if (!_ticker.isTicking) _ticker.start();+ }++ void _clickAtFace() {+ final face = (_yaw / math.pi).round();+ if (face == _face) return;+ _face = face;+ if (_yawVel.abs() > 1.6 && _yawVel.abs() < 13) HapticFeedback.selectionClick();+ }++ void _flip() {+ _wake();+ _landed = false;+ _yawVel = _yawVel.abs() < 1.5 ? 8.2 : _yawVel + 4.5;+ }++ @override+ Widget build(BuildContext context) {+ final shader = _shader;+ final icon = _icon;+ final back = _back;+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: _flip,+ onPanStart: (_) {+ _wake();+ _held = true;+ _yawVel = 0;+ _tiltVel = 0;+ _landed = false;+ },+ onPanUpdate: (d) {+ _yaw += d.delta.dx * 0.017;+ _tilt = (_tilt - d.delta.dy * 0.011).clamp(-0.55, 0.62);+ _pose.set(_yaw, _tilt, _time);+ },+ onPanEnd: (d) {+ _held = false;+ _yawVel = (d.velocity.pixelsPerSecond.dx * 0.016).clamp(-22.0, 22.0);+ _tiltVel = (-d.velocity.pixelsPerSecond.dy * 0.010).clamp(-9.0, 9.0);+ },+ child: SizedBox(+ width: widget.size,+ height: widget.size,+ child: shader == null || icon == null || back == null+ ? Center(child: Medal(id: widget.id, size: widget.size * 0.86, locked: widget.locked))+ : RepaintBoundary(+ child: CustomPaint(+ painter: _MedalPainter(+ shader: shader,+ icon: icon,+ back: back,+ look: medalLook(widget.id),+ pose: _pose,+ locked: widget.locked,+ ),+ ),+ ),+ ),+ );+ }+}++class _Pose extends ChangeNotifier {+ double yaw = 0;+ double tilt = _restTilt;+ double time = 0;++ void set(double y, double t, double tm) {+ yaw = y;+ tilt = t;+ time = tm;+ notifyListeners();+ }+}++class _MedalPainter extends CustomPainter {+ _MedalPainter({+ required this.shader,+ required this.icon,+ required this.back,+ required this.look,+ required this.pose,+ required this.locked,+ }) : super(repaint: pose);++ final ui.FragmentShader shader;+ final ui.Image icon;+ final ui.Image back;+ final MedalLook look;+ final _Pose pose;+ final bool locked;++ int _rgb(int hex, int at) {+ var i = at;+ for (final channel in [hex >> 16 & 255, hex >> 8 & 255, hex & 255]) {+ shader.setFloat(i++, math.pow(channel / 255, 2.2).toDouble());+ }+ return i;+ }++ @override+ void paint(Canvas canvas, Size size) {+ shader+ ..setFloat(0, size.width)+ ..setFloat(1, size.height)+ ..setFloat(2, pose.yaw)+ ..setFloat(3, pose.tilt)+ ..setFloat(4, pose.time)+ ..setFloat(5, locked ? 1 : 0)+ ..setFloat(6, look.round ? 1 : 0)+ ..setFloat(7, look.gem == null ? 0 : 1)+ ..setFloat(8, look.gem == null ? 0.46 : 0.40);+ var i = _rgb(look.metal.base, 9);+ i = _rgb(look.metal.lip, i);+ i = _rgb(look.metal.plateTop, i);+ i = _rgb(look.metal.plateLow, i);+ i = _rgb(look.metal.ink, i);+ _rgb(look.gem ?? 0x84c4e8, i);+ shader.setImageSampler(0, icon);+ shader.setImageSampler(1, back);+ canvas.drawRect(Offset.zero & size, Paint()..shader = shader);+ }++ @override+ bool shouldRepaint(_MedalPainter old) =>+ old.shader != shader || old.icon != icon || old.locked != locked;+}diff --git a/lib/widgets/medal_shelf.dart b/lib/widgets/medal_shelf.dartnew file mode 100644index 0000000..e5c153c--- /dev/null+++ b/lib/widgets/medal_shelf.dart@@ -0,0 +1,167 @@+import 'package:flutter/material.dart';++import '../catalog/awards.dart';+import '../l10n/l10n.dart';+import '../state/fit_state.dart';+import '../theme/app_colors.dart';+import '../theme/app_theme.dart';+import 'medal.dart';+import 'ui_kit.dart';++class MedalShelf extends StatelessWidget {+ const MedalShelf({super.key, this.size = 66});++ final double size;++ @override+ Widget build(BuildContext context) {+ final order = [+ ...AwardId.values.where(fit.hasAward),+ ...AwardId.values.where((a) => !fit.hasAward(a)),+ ];+ return SizedBox(+ height: size + 32,+ child: ListView.separated(+ scrollDirection: Axis.horizontal,+ itemCount: order.length,+ separatorBuilder: (_, _) => const SizedBox(width: 12),+ itemBuilder: (_, i) => _slot(context, order[i]),+ ),+ );+ }++ Widget _slot(BuildContext context, AwardId id) {+ final won = fit.hasAward(id);+ final fresh = fit.unseenAwards.contains(id);+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => showMedalSheet(context, id),+ child: Semantics(+ button: true,+ label: awardName(id),+ child: SizedBox(+ width: size + 12,+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ SizedBox(+ width: size,+ height: size,+ child: Stack(+ children: [+ Medal(id: id, size: size, locked: !won),+ if (fresh)+ Positioned(+ right: 2,+ top: 2,+ child: Container(+ width: 9,+ height: 9,+ decoration:+ BoxDecoration(color: context.gc.accent, shape: BoxShape.circle),+ ),+ ),+ ],+ ),+ ),+ if (won) ...[+ const SizedBox(height: 7),+ Text(+ awardName(id),+ maxLines: 2,+ textAlign: TextAlign.center,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(9.5,+ weight: FontWeight.w600, color: context.gc.textSecondary, height: 1.15),+ ),+ ],+ ],+ ),+ ),+ ),+ );+ }+}++Future<void> showMedalSheet(BuildContext context, AwardId id) {+ fit.markAwardsSeen();+ return showModalBottomSheet<void>(+ context: context,+ backgroundColor: Colors.transparent,+ builder: (_) => _MedalSheet(id: id),+ );+}++class _MedalSheet extends StatelessWidget {+ const _MedalSheet({required this.id});++ final AwardId id;++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ final won = fit.hasAward(id);+ final at = fit.awardWonAt(id);++ return Container(+ padding: sheetPad(context),+ decoration: BoxDecoration(+ color: gc.bgRaised,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ const SheetHandle(margin: EdgeInsets.only(bottom: 22)),+ MedalSpin(id: id, size: 236, locked: !won),+ const SizedBox(height: 8),+ Text(t.awardSpinHint,+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary)),+ const SizedBox(height: 22),+ Text(awardName(id), textAlign: TextAlign.center, style: AppTheme.f(21, color: gc.text)),+ const SizedBox(height: 8),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 22),+ child: Text(awardLine(id),+ textAlign: TextAlign.center,+ style: AppTheme.f(13,+ weight: FontWeight.w500, color: gc.textSecondary, height: 1.45)),+ ),+ const SizedBox(height: 18),+ if (won && at != null)+ Text(t.awardWonOn(t.shortDateYear(at)),+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.textTertiary))+ else+ _progress(gc),+ ],+ ),+ );+ }++ Widget _progress(GymColors gc) {+ final value = fit.awardValue(id);+ final goal = fit.awardGoal(id);+ return Column(+ children: [+ SizedBox(+ width: 190,+ child: ClipRRect(+ borderRadius: BorderRadius.circular(100),+ child: LinearProgressIndicator(+ value: fit.awardProgress(id),+ minHeight: 5,+ backgroundColor: gc.bgRaised2,+ valueColor: AlwaysStoppedAnimation<Color>(gc.textSecondary),+ ),+ ),+ ),+ const SizedBox(height: 10),+ Text('${medalShort(value)} / ${medalShort(goal)}',+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.textTertiary)),+ ],+ );+ }+}++String medalShort(int v) =>+ v >= 1000 ? '${(v / 1000).toStringAsFixed(v % 1000 == 0 ? 0 : 1)}k' : '$v';