add a loading bar (#159)
- when loading icons - when downloading via QR - when loading list in the browser - when loading preview/BGM in the browser - when downloading from the browser
This commit is contained in:
@@ -93,6 +93,7 @@ bool draw_confirm(const char* conf_msg, Entry_List_s* list);
|
|||||||
void draw_preview(ssize_t previewID, int preview_offset);
|
void draw_preview(ssize_t previewID, int preview_offset);
|
||||||
|
|
||||||
void draw_install(InstallType type);
|
void draw_install(InstallType type);
|
||||||
|
void draw_loading_bar(u32 current, u32 max, InstallType type);
|
||||||
|
|
||||||
void draw_base_interface(void);
|
void draw_base_interface(void);
|
||||||
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions);
|
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#define REMOTE_H
|
#define REMOTE_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "draw.h"
|
||||||
|
|
||||||
#define THEMEPLAZA_BASE_URL "https://themeplaza.eu"
|
#define THEMEPLAZA_BASE_URL "https://themeplaza.eu"
|
||||||
#define THEMEPLAZA_API_URL "/api/anemone/v1"
|
#define THEMEPLAZA_API_URL "/api/anemone/v1"
|
||||||
@@ -50,6 +51,6 @@
|
|||||||
#define CACHE_PATH_FORMAT "/3ds/" APP_TITLE "/cache/%" JSON_INTEGER_FORMAT
|
#define CACHE_PATH_FORMAT "/3ds/" APP_TITLE "/cache/%" JSON_INTEGER_FORMAT
|
||||||
|
|
||||||
bool themeplaza_browser(EntryMode mode);
|
bool themeplaza_browser(EntryMode mode);
|
||||||
u32 http_get(const char *url, char ** filename, char ** buf);
|
u32 http_get(const char *url, char ** filename, char ** buf, InstallType install_type);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ void update_qr(qr_data *data)
|
|||||||
draw_install(INSTALL_DOWNLOAD);
|
draw_install(INSTALL_DOWNLOAD);
|
||||||
char * zip_buf = NULL;
|
char * zip_buf = NULL;
|
||||||
char * filename = NULL;
|
char * filename = NULL;
|
||||||
u32 zip_size = http_get((char*)scan_data.payload, &filename, &zip_buf);
|
u32 zip_size = http_get((char*)scan_data.payload, &filename, &zip_buf, INSTALL_DOWNLOAD);
|
||||||
|
|
||||||
if(zip_size != 0)
|
if(zip_size != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -182,9 +182,8 @@ void draw_preview(ssize_t previewID, int preview_offset)
|
|||||||
pp2d_draw_texture_part(previewID, 0, 0, 40 + preview_offset, 240, 320, 240);
|
pp2d_draw_texture_part(previewID, 0, 0, 40 + preview_offset, 240, 320, 240);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_install(InstallType type)
|
static void draw_install_handler(InstallType type)
|
||||||
{
|
{
|
||||||
draw_base_interface();
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case INSTALL_LOADING_THEMES:
|
case INSTALL_LOADING_THEMES:
|
||||||
@@ -238,6 +237,25 @@ void draw_install(InstallType type)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_install(InstallType type)
|
||||||
|
{
|
||||||
|
draw_base_interface();
|
||||||
|
draw_install_handler(type);
|
||||||
|
pp2d_end_draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_loading_bar(u32 current, u32 max, InstallType type)
|
||||||
|
{
|
||||||
|
draw_base_interface();
|
||||||
|
draw_install_handler(type);
|
||||||
|
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||||
|
double percent = 100*((double)current/(double)max);
|
||||||
|
u32 width = (u32)percent;
|
||||||
|
width *= 2;
|
||||||
|
pp2d_draw_rectangle(60-1, 110-1, 200+2, 20+2, COLOR_CURSOR);
|
||||||
|
pp2d_draw_rectangle(60, 110, width, 20, COLOR_ACCENT);
|
||||||
pp2d_end_draw();
|
pp2d_end_draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,6 +230,9 @@ void load_icons_first(Entry_List_s * list, bool silent)
|
|||||||
|
|
||||||
for(int i = starti; i < endi; i++, id++)
|
for(int i = starti; i < endi; i++, id++)
|
||||||
{
|
{
|
||||||
|
if(!silent)
|
||||||
|
draw_loading_bar(i - starti, endi-starti, INSTALL_LOADING_ICONS);
|
||||||
|
|
||||||
int offset = i;
|
int offset = i;
|
||||||
if(offset < 0)
|
if(offset < 0)
|
||||||
offset += list->entries_count;
|
offset += list->entries_count;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
#include "loading.h"
|
#include "loading.h"
|
||||||
#include "draw.h"
|
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "music.h"
|
#include "music.h"
|
||||||
@@ -115,7 +114,7 @@ static void load_remote_smdh(Entry_s * entry, size_t textureID, bool ignore_cach
|
|||||||
smdh_buf = NULL;
|
smdh_buf = NULL;
|
||||||
char * api_url = NULL;
|
char * api_url = NULL;
|
||||||
asprintf(&api_url, THEMEPLAZA_SMDH_FORMAT, entry->tp_download_id);
|
asprintf(&api_url, THEMEPLAZA_SMDH_FORMAT, entry->tp_download_id);
|
||||||
smdh_size = http_get(api_url, NULL, &smdh_buf);
|
smdh_size = http_get(api_url, NULL, &smdh_buf, INSTALL_NONE);
|
||||||
free(api_url);
|
free(api_url);
|
||||||
smdh = (Icon_s *)smdh_buf;
|
smdh = (Icon_s *)smdh_buf;
|
||||||
}
|
}
|
||||||
@@ -164,7 +163,7 @@ static void load_remote_smdh(Entry_s * entry, size_t textureID, bool ignore_cach
|
|||||||
free(smdh_buf);
|
free(smdh_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_remote_entries(Entry_List_s * list, json_t *ids_array, bool ignore_cache)
|
static void load_remote_entries(Entry_List_s * list, json_t *ids_array, bool ignore_cache, InstallType type)
|
||||||
{
|
{
|
||||||
list->entries_count = json_array_size(ids_array);
|
list->entries_count = json_array_size(ids_array);
|
||||||
free(list->entries);
|
free(list->entries);
|
||||||
@@ -177,6 +176,7 @@ static void load_remote_entries(Entry_List_s * list, json_t *ids_array, bool ign
|
|||||||
json_t * id = NULL;
|
json_t * id = NULL;
|
||||||
json_array_foreach(ids_array, i, id)
|
json_array_foreach(ids_array, i, id)
|
||||||
{
|
{
|
||||||
|
draw_loading_bar(i, list->entries_count, type);
|
||||||
size_t offset = i;
|
size_t offset = i;
|
||||||
Entry_s * current_entry = &list->entries[offset];
|
Entry_s * current_entry = &list->entries[offset];
|
||||||
current_entry->tp_download_id = json_integer_value(id);
|
current_entry->tp_download_id = json_integer_value(id);
|
||||||
@@ -209,7 +209,7 @@ static void load_remote_list(Entry_List_s * list, json_int_t page, EntryMode mod
|
|||||||
char * page_json = NULL;
|
char * page_json = NULL;
|
||||||
char * api_url = NULL;
|
char * api_url = NULL;
|
||||||
asprintf(&api_url, THEMEPLAZA_PAGE_FORMAT, page, mode+1, list->tp_search);
|
asprintf(&api_url, THEMEPLAZA_PAGE_FORMAT, page, mode+1, list->tp_search);
|
||||||
u32 json_len = http_get(api_url, NULL, &page_json);
|
u32 json_len = http_get(api_url, NULL, &page_json, INSTALL_NONE);
|
||||||
free(api_url);
|
free(api_url);
|
||||||
|
|
||||||
if(json_len)
|
if(json_len)
|
||||||
@@ -232,7 +232,7 @@ static void load_remote_list(Entry_List_s * list, json_int_t page, EntryMode mod
|
|||||||
if(json_is_integer(value) && !strcmp(key, THEMEPLAZA_JSON_PAGE_COUNT))
|
if(json_is_integer(value) && !strcmp(key, THEMEPLAZA_JSON_PAGE_COUNT))
|
||||||
list->tp_page_count = json_integer_value(value);
|
list->tp_page_count = json_integer_value(value);
|
||||||
else if(json_is_array(value) && !strcmp(key, THEMEPLAZA_JSON_PAGE_IDS))
|
else if(json_is_array(value) && !strcmp(key, THEMEPLAZA_JSON_PAGE_IDS))
|
||||||
load_remote_entries(list, value, ignore_cache);
|
load_remote_entries(list, value, ignore_cache, loading_screen);
|
||||||
else if(json_is_string(value) && !strcmp(key, THEMEPLAZA_JSON_ERROR_MESSAGE) && !strcmp(json_string_value(value), THEMEPLAZA_JSON_ERROR_MESSAGE_NOT_FOUND))
|
else if(json_is_string(value) && !strcmp(key, THEMEPLAZA_JSON_ERROR_MESSAGE) && !strcmp(json_string_value(value), THEMEPLAZA_JSON_ERROR_MESSAGE_NOT_FOUND))
|
||||||
throw_error("No results for this search.", ERROR_LEVEL_WARNING);
|
throw_error("No results for this search.", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ static bool load_remote_preview(Entry_s * entry, int * preview_offset)
|
|||||||
|
|
||||||
draw_install(INSTALL_LOADING_REMOTE_PREVIEW);
|
draw_install(INSTALL_LOADING_REMOTE_PREVIEW);
|
||||||
|
|
||||||
preview_size = http_get(preview_url, NULL, &preview_png);
|
preview_size = http_get(preview_url, NULL, &preview_png, INSTALL_LOADING_REMOTE_PREVIEW);
|
||||||
free(preview_url);
|
free(preview_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ static void load_remote_bgm(Entry_s * entry)
|
|||||||
|
|
||||||
draw_install(INSTALL_LOADING_REMOTE_BGM);
|
draw_install(INSTALL_LOADING_REMOTE_BGM);
|
||||||
|
|
||||||
bgm_size = http_get(bgm_url, NULL, &bgm_ogg);
|
bgm_size = http_get(bgm_url, NULL, &bgm_ogg, INSTALL_LOADING_REMOTE_BGM);
|
||||||
free(bgm_url);
|
free(bgm_url);
|
||||||
|
|
||||||
u16 path[0x107] = {0};
|
u16 path[0x107] = {0};
|
||||||
@@ -366,7 +366,7 @@ static void download_remote_entry(Entry_s * entry, EntryMode mode)
|
|||||||
char * zip_buf = NULL;
|
char * zip_buf = NULL;
|
||||||
char * filename = NULL;
|
char * filename = NULL;
|
||||||
draw_install(INSTALL_DOWNLOAD);
|
draw_install(INSTALL_DOWNLOAD);
|
||||||
u32 zip_size = http_get(download_url, &filename, &zip_buf);
|
u32 zip_size = http_get(download_url, &filename, &zip_buf, INSTALL_DOWNLOAD);
|
||||||
free(download_url);
|
free(download_url);
|
||||||
|
|
||||||
char path_to_file[0x107] = {0};
|
char path_to_file[0x107] = {0};
|
||||||
@@ -770,7 +770,7 @@ bool themeplaza_browser(EntryMode mode)
|
|||||||
return downloaded;
|
return downloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 http_get(const char *url, char ** filename, char ** buf)
|
u32 http_get(const char *url, char ** filename, char ** buf, InstallType install_type)
|
||||||
{
|
{
|
||||||
Result ret;
|
Result ret;
|
||||||
httpcContext context;
|
httpcContext context;
|
||||||
@@ -894,6 +894,9 @@ u32 http_get(const char *url, char ** filename, char ** buf)
|
|||||||
ret = httpcDownloadData(&context, (*(u8**)buf) + size, 0x1000, &read_size);
|
ret = httpcDownloadData(&context, (*(u8**)buf) + size, 0x1000, &read_size);
|
||||||
size += read_size;
|
size += read_size;
|
||||||
|
|
||||||
|
if(content_size && install_type != INSTALL_NONE)
|
||||||
|
draw_loading_bar(size, content_size, install_type);
|
||||||
|
|
||||||
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
||||||
{
|
{
|
||||||
last_buf = *buf;
|
last_buf = *buf;
|
||||||
|
|||||||
Reference in New Issue
Block a user