animation_manager.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. #include <gui/view_stack.h>
  2. #include <stdint.h>
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. #include <portmacro.h>
  6. #include <dolphin/dolphin.h>
  7. #include <power/power_service/power.h>
  8. #include <storage/storage.h>
  9. #include <assets_icons.h>
  10. #include "views/bubble_animation_view.h"
  11. #include "views/one_shot_animation_view.h"
  12. #include "animation_storage.h"
  13. #include "animation_manager.h"
  14. #define TAG "AnimationManager"
  15. #define HARDCODED_ANIMATION_NAME "L1_Tv_128x47"
  16. #define NO_SD_ANIMATION_NAME "L1_NoSd_128x49"
  17. #define BAD_BATTERY_ANIMATION_NAME "L1_BadBattery_128x47"
  18. #define NO_DB_ANIMATION_NAME "L0_NoDb_128x51"
  19. #define BAD_SD_ANIMATION_NAME "L0_SdBad_128x51"
  20. #define SD_OK_ANIMATION_NAME "L0_SdOk_128x51"
  21. #define URL_ANIMATION_NAME "L0_Url_128x51"
  22. #define NEW_MAIL_ANIMATION_NAME "L0_NewMail_128x51"
  23. typedef enum {
  24. AnimationManagerStateIdle,
  25. AnimationManagerStateBlocked,
  26. AnimationManagerStateFreezedIdle,
  27. AnimationManagerStateFreezedBlocked,
  28. } AnimationManagerState;
  29. struct AnimationManager {
  30. bool sd_show_url;
  31. bool sd_shown_no_db;
  32. bool sd_shown_sd_ok;
  33. bool levelup_pending;
  34. bool levelup_active;
  35. AnimationManagerState state;
  36. FuriPubSubSubscription* pubsub_subscription_storage;
  37. FuriPubSubSubscription* pubsub_subscription_dolphin;
  38. BubbleAnimationView* animation_view;
  39. OneShotView* one_shot_view;
  40. FuriTimer* idle_animation_timer;
  41. StorageAnimation* current_animation;
  42. AnimationManagerInteractCallback interact_callback;
  43. AnimationManagerSetNewIdleAnimationCallback new_idle_callback;
  44. AnimationManagerSetNewIdleAnimationCallback check_blocking_callback;
  45. void* context;
  46. FuriString* freezed_animation_name;
  47. int32_t freezed_animation_time_left;
  48. ViewStack* view_stack;
  49. bool dummy_mode;
  50. };
  51. static StorageAnimation*
  52. animation_manager_select_idle_animation(AnimationManager* animation_manager);
  53. static void animation_manager_replace_current_animation(
  54. AnimationManager* animation_manager,
  55. StorageAnimation* storage_animation);
  56. static void animation_manager_start_new_idle(AnimationManager* animation_manager);
  57. static bool animation_manager_check_blocking(AnimationManager* animation_manager);
  58. static bool animation_manager_is_valid_idle_animation(
  59. const StorageAnimationManifestInfo* info,
  60. const DolphinStats* stats);
  61. static void animation_manager_switch_to_one_shot_view(AnimationManager* animation_manager);
  62. static void animation_manager_switch_to_animation_view(AnimationManager* animation_manager);
  63. void animation_manager_set_context(AnimationManager* animation_manager, void* context) {
  64. furi_assert(animation_manager);
  65. animation_manager->context = context;
  66. }
  67. void animation_manager_set_new_idle_callback(
  68. AnimationManager* animation_manager,
  69. AnimationManagerSetNewIdleAnimationCallback callback) {
  70. furi_assert(animation_manager);
  71. animation_manager->new_idle_callback = callback;
  72. }
  73. void animation_manager_set_check_callback(
  74. AnimationManager* animation_manager,
  75. AnimationManagerCheckBlockingCallback callback) {
  76. furi_assert(animation_manager);
  77. animation_manager->check_blocking_callback = callback;
  78. }
  79. void animation_manager_set_interact_callback(
  80. AnimationManager* animation_manager,
  81. AnimationManagerInteractCallback callback) {
  82. furi_assert(animation_manager);
  83. animation_manager->interact_callback = callback;
  84. }
  85. void animation_manager_set_dummy_mode_state(AnimationManager* animation_manager, bool enabled) {
  86. furi_assert(animation_manager);
  87. animation_manager->dummy_mode = enabled;
  88. animation_manager_start_new_idle(animation_manager);
  89. }
  90. static void animation_manager_check_blocking_callback(const void* message, void* context) {
  91. const StorageEvent* storage_event = message;
  92. switch(storage_event->type) {
  93. case StorageEventTypeCardMount:
  94. case StorageEventTypeCardUnmount:
  95. case StorageEventTypeCardMountError:
  96. furi_assert(context);
  97. AnimationManager* animation_manager = context;
  98. if(animation_manager->check_blocking_callback) {
  99. animation_manager->check_blocking_callback(animation_manager->context);
  100. }
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. static void animation_manager_timer_callback(void* context) {
  107. furi_assert(context);
  108. AnimationManager* animation_manager = context;
  109. if(animation_manager->new_idle_callback) {
  110. animation_manager->new_idle_callback(animation_manager->context);
  111. }
  112. }
  113. static void animation_manager_interact_callback(void* context) {
  114. furi_assert(context);
  115. AnimationManager* animation_manager = context;
  116. if(animation_manager->interact_callback) {
  117. animation_manager->interact_callback(animation_manager->context);
  118. }
  119. }
  120. /* reaction to animation_manager->check_blocking_callback() */
  121. void animation_manager_check_blocking_process(AnimationManager* animation_manager) {
  122. furi_assert(animation_manager);
  123. if(animation_manager->state == AnimationManagerStateIdle) {
  124. bool blocked = animation_manager_check_blocking(animation_manager);
  125. if(!blocked) {
  126. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  127. DolphinStats stats = dolphin_stats(dolphin);
  128. furi_record_close(RECORD_DOLPHIN);
  129. const StorageAnimationManifestInfo* manifest_info =
  130. animation_storage_get_meta(animation_manager->current_animation);
  131. bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats);
  132. if(!valid) {
  133. animation_manager_start_new_idle(animation_manager);
  134. }
  135. }
  136. }
  137. }
  138. /* reaction to animation_manager->new_idle_callback() */
  139. void animation_manager_new_idle_process(AnimationManager* animation_manager) {
  140. furi_assert(animation_manager);
  141. if(animation_manager->state == AnimationManagerStateIdle) {
  142. animation_manager_start_new_idle(animation_manager);
  143. }
  144. }
  145. /* reaction to animation_manager->interact_callback() */
  146. bool animation_manager_interact_process(AnimationManager* animation_manager) {
  147. furi_assert(animation_manager);
  148. bool consumed = true;
  149. if(animation_manager->levelup_pending) {
  150. animation_manager->levelup_pending = false;
  151. animation_manager->levelup_active = true;
  152. animation_manager_switch_to_one_shot_view(animation_manager);
  153. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  154. dolphin_upgrade_level(dolphin);
  155. furi_record_close(RECORD_DOLPHIN);
  156. } else if(animation_manager->levelup_active) {
  157. animation_manager->levelup_active = false;
  158. animation_manager_start_new_idle(animation_manager);
  159. animation_manager_switch_to_animation_view(animation_manager);
  160. } else if(animation_manager->state == AnimationManagerStateBlocked) {
  161. bool blocked = animation_manager_check_blocking(animation_manager);
  162. if(!blocked) {
  163. animation_manager_start_new_idle(animation_manager);
  164. }
  165. } else {
  166. consumed = false;
  167. }
  168. return consumed;
  169. }
  170. static void animation_manager_start_new_idle(AnimationManager* animation_manager) {
  171. furi_assert(animation_manager);
  172. StorageAnimation* new_animation = animation_manager_select_idle_animation(animation_manager);
  173. animation_manager_replace_current_animation(animation_manager, new_animation);
  174. const BubbleAnimation* bubble_animation =
  175. animation_storage_get_bubble_animation(animation_manager->current_animation);
  176. animation_manager->state = AnimationManagerStateIdle;
  177. furi_timer_start(animation_manager->idle_animation_timer, bubble_animation->duration * 1000);
  178. }
  179. static bool animation_manager_check_blocking(AnimationManager* animation_manager) {
  180. furi_assert(animation_manager);
  181. StorageAnimation* blocking_animation = NULL;
  182. Storage* storage = furi_record_open(RECORD_STORAGE);
  183. FS_Error sd_status = storage_sd_status(storage);
  184. if(sd_status == FSE_INTERNAL) {
  185. blocking_animation = animation_storage_find_animation(BAD_SD_ANIMATION_NAME);
  186. furi_assert(blocking_animation);
  187. } else if(sd_status == FSE_NOT_READY) {
  188. animation_manager->sd_shown_sd_ok = false;
  189. animation_manager->sd_shown_no_db = false;
  190. } else if(sd_status == FSE_OK) {
  191. if(!animation_manager->sd_shown_sd_ok) {
  192. blocking_animation = animation_storage_find_animation(SD_OK_ANIMATION_NAME);
  193. furi_assert(blocking_animation);
  194. animation_manager->sd_shown_sd_ok = true;
  195. } else if(!animation_manager->sd_shown_no_db) {
  196. if(!storage_file_exists(storage, EXT_PATH("Manifest"))) {
  197. blocking_animation = animation_storage_find_animation(NO_DB_ANIMATION_NAME);
  198. furi_assert(blocking_animation);
  199. animation_manager->sd_shown_no_db = true;
  200. animation_manager->sd_show_url = true;
  201. }
  202. } else if(animation_manager->sd_show_url) {
  203. blocking_animation = animation_storage_find_animation(URL_ANIMATION_NAME);
  204. furi_assert(blocking_animation);
  205. animation_manager->sd_show_url = false;
  206. }
  207. }
  208. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  209. DolphinStats stats = dolphin_stats(dolphin);
  210. furi_record_close(RECORD_DOLPHIN);
  211. if(!blocking_animation && stats.level_up_is_pending) {
  212. blocking_animation = animation_storage_find_animation(NEW_MAIL_ANIMATION_NAME);
  213. furi_check(blocking_animation);
  214. animation_manager->levelup_pending = true;
  215. }
  216. if(blocking_animation) {
  217. furi_timer_stop(animation_manager->idle_animation_timer);
  218. animation_manager_replace_current_animation(animation_manager, blocking_animation);
  219. /* no timer starting because this is blocking animation */
  220. animation_manager->state = AnimationManagerStateBlocked;
  221. }
  222. furi_record_close(RECORD_STORAGE);
  223. return !!blocking_animation;
  224. }
  225. static void animation_manager_replace_current_animation(
  226. AnimationManager* animation_manager,
  227. StorageAnimation* storage_animation) {
  228. furi_assert(storage_animation);
  229. StorageAnimation* previous_animation = animation_manager->current_animation;
  230. const BubbleAnimation* animation = animation_storage_get_bubble_animation(storage_animation);
  231. bubble_animation_view_set_animation(animation_manager->animation_view, animation);
  232. const char* new_name = animation_storage_get_meta(storage_animation)->name;
  233. FURI_LOG_I(TAG, "Select \'%s\' animation", new_name);
  234. animation_manager->current_animation = storage_animation;
  235. if(previous_animation) {
  236. animation_storage_free_storage_animation(&previous_animation);
  237. }
  238. }
  239. AnimationManager* animation_manager_alloc(void) {
  240. AnimationManager* animation_manager = malloc(sizeof(AnimationManager));
  241. animation_manager->animation_view = bubble_animation_view_alloc();
  242. animation_manager->view_stack = view_stack_alloc();
  243. View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
  244. view_stack_add_view(animation_manager->view_stack, animation_view);
  245. animation_manager->freezed_animation_name = furi_string_alloc();
  246. animation_manager->idle_animation_timer =
  247. furi_timer_alloc(animation_manager_timer_callback, FuriTimerTypeOnce, animation_manager);
  248. bubble_animation_view_set_interact_callback(
  249. animation_manager->animation_view, animation_manager_interact_callback, animation_manager);
  250. Storage* storage = furi_record_open(RECORD_STORAGE);
  251. animation_manager->pubsub_subscription_storage = furi_pubsub_subscribe(
  252. storage_get_pubsub(storage), animation_manager_check_blocking_callback, animation_manager);
  253. furi_record_close(RECORD_STORAGE);
  254. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  255. animation_manager->pubsub_subscription_dolphin = furi_pubsub_subscribe(
  256. dolphin_get_pubsub(dolphin), animation_manager_check_blocking_callback, animation_manager);
  257. furi_record_close(RECORD_DOLPHIN);
  258. animation_manager->sd_shown_sd_ok = true;
  259. if(!animation_manager_check_blocking(animation_manager)) {
  260. animation_manager_start_new_idle(animation_manager);
  261. }
  262. return animation_manager;
  263. }
  264. void animation_manager_free(AnimationManager* animation_manager) {
  265. furi_assert(animation_manager);
  266. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  267. furi_pubsub_unsubscribe(
  268. dolphin_get_pubsub(dolphin), animation_manager->pubsub_subscription_dolphin);
  269. furi_record_close(RECORD_DOLPHIN);
  270. Storage* storage = furi_record_open(RECORD_STORAGE);
  271. furi_pubsub_unsubscribe(
  272. storage_get_pubsub(storage), animation_manager->pubsub_subscription_storage);
  273. furi_record_close(RECORD_STORAGE);
  274. furi_string_free(animation_manager->freezed_animation_name);
  275. View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
  276. view_stack_remove_view(animation_manager->view_stack, animation_view);
  277. bubble_animation_view_free(animation_manager->animation_view);
  278. furi_timer_free(animation_manager->idle_animation_timer);
  279. }
  280. View* animation_manager_get_animation_view(AnimationManager* animation_manager) {
  281. furi_assert(animation_manager);
  282. return view_stack_get_view(animation_manager->view_stack);
  283. }
  284. static bool animation_manager_is_valid_idle_animation(
  285. const StorageAnimationManifestInfo* info,
  286. const DolphinStats* stats) {
  287. furi_assert(info);
  288. furi_assert(info->name);
  289. bool result = true;
  290. if(!strcmp(info->name, BAD_BATTERY_ANIMATION_NAME)) {
  291. Power* power = furi_record_open(RECORD_POWER);
  292. bool battery_is_well = power_is_battery_healthy(power);
  293. furi_record_close(RECORD_POWER);
  294. result = !battery_is_well;
  295. }
  296. if(!strcmp(info->name, NO_SD_ANIMATION_NAME)) {
  297. Storage* storage = furi_record_open(RECORD_STORAGE);
  298. FS_Error sd_status = storage_sd_status(storage);
  299. furi_record_close(RECORD_STORAGE);
  300. result = (sd_status == FSE_NOT_READY);
  301. }
  302. if((stats->butthurt < info->min_butthurt) || (stats->butthurt > info->max_butthurt)) {
  303. result = false;
  304. }
  305. if((stats->level < info->min_level) || (stats->level > info->max_level)) {
  306. result = false;
  307. }
  308. return result;
  309. }
  310. static StorageAnimation*
  311. animation_manager_select_idle_animation(AnimationManager* animation_manager) {
  312. if(animation_manager->dummy_mode) {
  313. return animation_storage_find_animation(HARDCODED_ANIMATION_NAME);
  314. }
  315. StorageAnimationList_t animation_list;
  316. StorageAnimationList_init(animation_list);
  317. animation_storage_fill_animation_list(&animation_list);
  318. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  319. DolphinStats stats = dolphin_stats(dolphin);
  320. furi_record_close(RECORD_DOLPHIN);
  321. uint32_t whole_weight = 0;
  322. StorageAnimationList_it_t it;
  323. for(StorageAnimationList_it(it, animation_list); !StorageAnimationList_end_p(it);) {
  324. StorageAnimation* storage_animation = *StorageAnimationList_ref(it);
  325. const StorageAnimationManifestInfo* manifest_info =
  326. animation_storage_get_meta(storage_animation);
  327. bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats);
  328. if(valid) {
  329. whole_weight += manifest_info->weight;
  330. StorageAnimationList_next(it);
  331. } else {
  332. animation_storage_free_storage_animation(&storage_animation);
  333. /* remove and increase iterator */
  334. StorageAnimationList_remove(animation_list, it);
  335. }
  336. }
  337. uint32_t lucky_number = furi_hal_random_get() % whole_weight;
  338. uint32_t weight = 0;
  339. StorageAnimation* selected = NULL;
  340. for
  341. M_EACH(item, animation_list, StorageAnimationList_t) {
  342. if(lucky_number < weight) {
  343. break;
  344. }
  345. weight += animation_storage_get_meta(*item)->weight;
  346. selected = *item;
  347. }
  348. for
  349. M_EACH(item, animation_list, StorageAnimationList_t) {
  350. if(*item != selected) {
  351. animation_storage_free_storage_animation(item);
  352. }
  353. }
  354. StorageAnimationList_clear(animation_list);
  355. /* cache animation, if failed - choose reliable animation */
  356. if(!animation_storage_get_bubble_animation(selected)) {
  357. const char* name = animation_storage_get_meta(selected)->name;
  358. FURI_LOG_E(TAG, "Can't upload animation described in manifest: \'%s\'", name);
  359. animation_storage_free_storage_animation(&selected);
  360. selected = animation_storage_find_animation(HARDCODED_ANIMATION_NAME);
  361. }
  362. furi_assert(selected);
  363. return selected;
  364. }
  365. bool animation_manager_is_animation_loaded(AnimationManager* animation_manager) {
  366. furi_assert(animation_manager);
  367. return animation_manager->current_animation;
  368. }
  369. void animation_manager_unload_and_stall_animation(AnimationManager* animation_manager) {
  370. furi_assert(animation_manager);
  371. furi_assert(animation_manager->current_animation);
  372. furi_assert(!furi_string_size(animation_manager->freezed_animation_name));
  373. furi_assert(
  374. (animation_manager->state == AnimationManagerStateIdle) ||
  375. (animation_manager->state == AnimationManagerStateBlocked));
  376. if(animation_manager->state == AnimationManagerStateBlocked) {
  377. animation_manager->state = AnimationManagerStateFreezedBlocked;
  378. } else if(animation_manager->state == AnimationManagerStateIdle) { //-V547
  379. animation_manager->state = AnimationManagerStateFreezedIdle;
  380. animation_manager->freezed_animation_time_left =
  381. xTimerGetExpiryTime(animation_manager->idle_animation_timer) - xTaskGetTickCount();
  382. if(animation_manager->freezed_animation_time_left < 0) {
  383. animation_manager->freezed_animation_time_left = 0;
  384. }
  385. furi_timer_stop(animation_manager->idle_animation_timer);
  386. } else {
  387. furi_assert(0);
  388. }
  389. FURI_LOG_I(
  390. TAG,
  391. "Unload animation \'%s\'",
  392. animation_storage_get_meta(animation_manager->current_animation)->name);
  393. StorageAnimationManifestInfo* meta =
  394. animation_storage_get_meta(animation_manager->current_animation);
  395. /* copy str, not move, because it can be internal animation */
  396. furi_string_set(animation_manager->freezed_animation_name, meta->name);
  397. bubble_animation_freeze(animation_manager->animation_view);
  398. animation_storage_free_storage_animation(&animation_manager->current_animation);
  399. }
  400. void animation_manager_load_and_continue_animation(AnimationManager* animation_manager) {
  401. furi_assert(animation_manager);
  402. furi_assert(!animation_manager->current_animation);
  403. furi_assert(furi_string_size(animation_manager->freezed_animation_name));
  404. furi_assert(
  405. (animation_manager->state == AnimationManagerStateFreezedIdle) ||
  406. (animation_manager->state == AnimationManagerStateFreezedBlocked));
  407. if(animation_manager->state == AnimationManagerStateFreezedBlocked) {
  408. StorageAnimation* restore_animation = animation_storage_find_animation(
  409. furi_string_get_cstr(animation_manager->freezed_animation_name));
  410. /* all blocked animations must be in flipper -> we can
  411. * always find blocking animation */
  412. furi_assert(restore_animation);
  413. animation_manager_replace_current_animation(animation_manager, restore_animation);
  414. animation_manager->state = AnimationManagerStateBlocked;
  415. } else if(animation_manager->state == AnimationManagerStateFreezedIdle) { //-V547
  416. /* check if we missed some system notifications, and set current_animation */
  417. bool blocked = animation_manager_check_blocking(animation_manager);
  418. if(!blocked) {
  419. /* if no blocking - try restore last one idle */
  420. StorageAnimation* restore_animation = animation_storage_find_animation(
  421. furi_string_get_cstr(animation_manager->freezed_animation_name));
  422. if(restore_animation) {
  423. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  424. DolphinStats stats = dolphin_stats(dolphin);
  425. furi_record_close(RECORD_DOLPHIN);
  426. const StorageAnimationManifestInfo* manifest_info =
  427. animation_storage_get_meta(restore_animation);
  428. bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats);
  429. if(valid) {
  430. animation_manager_replace_current_animation(
  431. animation_manager, restore_animation);
  432. animation_manager->state = AnimationManagerStateIdle;
  433. if(animation_manager->freezed_animation_time_left) {
  434. furi_timer_start(
  435. animation_manager->idle_animation_timer,
  436. animation_manager->freezed_animation_time_left);
  437. } else {
  438. const BubbleAnimation* animation = animation_storage_get_bubble_animation(
  439. animation_manager->current_animation);
  440. furi_timer_start(
  441. animation_manager->idle_animation_timer, animation->duration * 1000);
  442. }
  443. }
  444. } else {
  445. FURI_LOG_E(
  446. TAG,
  447. "Failed to restore \'%s\'",
  448. furi_string_get_cstr(animation_manager->freezed_animation_name));
  449. }
  450. }
  451. } else {
  452. /* Unknown state is an error. But not in release version.*/
  453. furi_assert(0);
  454. }
  455. /* if can't restore previous animation - select new */
  456. if(!animation_manager->current_animation) {
  457. animation_manager_start_new_idle(animation_manager);
  458. }
  459. FURI_LOG_I(
  460. TAG,
  461. "Load animation \'%s\'",
  462. animation_storage_get_meta(animation_manager->current_animation)->name);
  463. bubble_animation_unfreeze(animation_manager->animation_view);
  464. furi_string_reset(animation_manager->freezed_animation_name);
  465. furi_assert(animation_manager->current_animation);
  466. }
  467. static void animation_manager_switch_to_one_shot_view(AnimationManager* animation_manager) {
  468. furi_assert(animation_manager);
  469. furi_assert(!animation_manager->one_shot_view);
  470. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  471. DolphinStats stats = dolphin_stats(dolphin);
  472. furi_record_close(RECORD_DOLPHIN);
  473. animation_manager->one_shot_view = one_shot_view_alloc();
  474. one_shot_view_set_interact_callback(
  475. animation_manager->one_shot_view, animation_manager_interact_callback, animation_manager);
  476. View* prev_view = bubble_animation_get_view(animation_manager->animation_view);
  477. View* next_view = one_shot_view_get_view(animation_manager->one_shot_view);
  478. view_stack_remove_view(animation_manager->view_stack, prev_view);
  479. view_stack_add_view(animation_manager->view_stack, next_view);
  480. if(stats.level == 1) {
  481. one_shot_view_start_animation(animation_manager->one_shot_view, &A_Levelup1_128x64);
  482. } else if(stats.level == 2) {
  483. one_shot_view_start_animation(animation_manager->one_shot_view, &A_Levelup2_128x64);
  484. } else {
  485. furi_assert(0);
  486. }
  487. }
  488. static void animation_manager_switch_to_animation_view(AnimationManager* animation_manager) {
  489. furi_assert(animation_manager);
  490. furi_assert(animation_manager->one_shot_view);
  491. View* prev_view = one_shot_view_get_view(animation_manager->one_shot_view);
  492. View* next_view = bubble_animation_get_view(animation_manager->animation_view);
  493. view_stack_remove_view(animation_manager->view_stack, prev_view);
  494. view_stack_add_view(animation_manager->view_stack, next_view);
  495. one_shot_view_free(animation_manager->one_shot_view);
  496. animation_manager->one_shot_view = NULL;
  497. }