animation_manager.c 23 KB

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