Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive: Add dynamic paths to browser tab #322

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions applications/main/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static void
model->list_offset = 0;
model->list_loading = true;
model->folder_loading = false;
browser->path_changed = true;
},
false);
archive_update_offset(browser);
Expand Down Expand Up @@ -556,6 +557,7 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
archive_set_tab(browser, tab);

furi_string_set(browser->path, archive_get_default_path(tab));
browser->path_changed = true;
bool tab_empty = true;
bool is_app_tab = furi_string_start_with_str(browser->path, "/app:");
if(tab == ArchiveTabFavorites) {
Expand Down Expand Up @@ -644,6 +646,7 @@ void archive_leave_dir(ArchiveBrowserView* browser) {

size_t dirname_start = furi_string_search_rchar(browser->path, '/');
furi_string_left(browser->path, dirname_start);
browser->path_changed = true;

const char* switch_ext = NULL;
switch(archive_get_tab(browser)) {
Expand Down
70 changes: 69 additions & 1 deletion applications/main/archive/views/archive_browser_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,53 @@ void archive_browser_set_callback(
browser->context = context;
}

static void archive_update_formatted_path(ArchiveBrowserViewModel* model) {
ArchiveBrowserView* browser = model->archive->browser;
if(!browser->path_changed) {
return;
}

ArchiveTabEnum tab = archive_get_tab(browser);
if(momentum_settings.show_browser_path && !archive_is_home(browser)) {
if(momentum_settings.show_browser_path == BrowserPathFull) {
furi_string_set(browser->formatted_path, browser->path);
} else if(momentum_settings.show_browser_path == BrowserPathBrief) {
furi_string_reset(browser->formatted_path);

char path_buf[256];
strncpy(path_buf, furi_string_get_cstr(browser->path), sizeof(path_buf) - 1);
path_buf[sizeof(path_buf) - 1] = '\0';
char* token = strtok(path_buf, "/");

while(token != NULL) {
char* next = strtok(NULL, "/");
if(next != NULL) {
furi_string_cat_printf(browser->formatted_path, "/%c", token[0]);
} else {
furi_string_cat_printf(browser->formatted_path, "/%s", token);
}
token = next;
}
} else {
size_t r_slash = furi_string_search_rchar(browser->path, '/');
if(r_slash != FURI_STRING_FAILURE) {
furi_string_set_n(
browser->formatted_path,
browser->path,
r_slash + 1,
furi_string_size(browser->path) - r_slash - 1);
} else {
furi_string_set(browser->formatted_path, browser->path);
}
}
} else {
furi_string_set(browser->formatted_path, ArchiveTabNames[tab]);
}

furi_string_set(browser->prev_path, browser->path);
browser->path_changed = false;
}

static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
if(menu_array_size(model->context_menu) == 0) {
// Need init context menu
Expand Down Expand Up @@ -279,6 +326,9 @@ static void archive_render_status_bar(Canvas* canvas, ArchiveBrowserViewModel* m
if(model->tab_idx == ArchiveTabSearch &&
scene_manager_get_scene_state(model->archive->scene_manager, ArchiveAppSceneSearch)) {
tab_name = "Searching";
} else {
archive_update_formatted_path(model);
tab_name = furi_string_get_cstr(model->archive->browser->formatted_path);
}
bool clip = model->clipboard != NULL;

Expand All @@ -293,7 +343,20 @@ static void archive_render_status_bar(Canvas* canvas, ArchiveBrowserViewModel* m
canvas_draw_rframe(canvas, 0, 0, 51, 13, 1); // frame
canvas_draw_line(canvas, 49, 1, 49, 11); // shadow right
canvas_draw_line(canvas, 1, 11, 49, 11); // shadow bottom
canvas_draw_str_aligned(canvas, 25, 9, AlignCenter, AlignBottom, tab_name);

size_t text_width = canvas_string_width(canvas, tab_name);
if(text_width > 45) {
elements_scrollable_text_line(
canvas,
3,
9,
45,
model->archive->browser->formatted_path,
model->scroll_counter,
false);
} else {
canvas_draw_str_aligned(canvas, 25, 9, AlignCenter, AlignBottom, tab_name);
}

if(clip) {
canvas_draw_rframe(canvas, 69, 0, 25, 13, 1);
Expand Down Expand Up @@ -593,6 +656,9 @@ ArchiveBrowserView* browser_alloc(void) {
browser->scroll_timer = furi_timer_alloc(browser_scroll_timer, FuriTimerTypePeriodic, browser);

browser->path = furi_string_alloc_set(archive_get_default_path(TAB_DEFAULT));
browser->prev_path = furi_string_alloc();
browser->formatted_path = furi_string_alloc();
browser->path_changed = true;

with_view_model(
browser->view,
Expand Down Expand Up @@ -626,6 +692,8 @@ void browser_free(ArchiveBrowserView* browser) {
false);

furi_string_free(browser->path);
furi_string_free(browser->prev_path);
furi_string_free(browser->formatted_path);

view_free(browser->view);
free(browser);
Expand Down
4 changes: 4 additions & 0 deletions applications/main/archive/views/archive_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../helpers/archive_files.h"
#include "../helpers/archive_favorites.h"

#include "archive/archive.h"
#include <gui/gui_i.h>
#include <gui/view.h>
#include <gui/canvas.h>
Expand Down Expand Up @@ -88,6 +89,9 @@ struct ArchiveBrowserView {
ArchiveBrowserViewCallback callback;
void* context;
FuriString* path;
FuriString* prev_path;
FuriString* formatted_path;
bool path_changed;
InputKey last_tab_switch_dir;
bool is_root;
FuriTimer* scroll_timer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ enum VarItemListIndex {
VarItemListIndexFavoriteTimeout,
};

const char* const browser_path_names[BrowserPathModeCount] = {
"OFF",
"Current",
"Brief",
"Full",
};

void momentum_app_scene_interface_filebrowser_var_item_list_callback(void* context, uint32_t index) {
MomentumApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
Expand Down Expand Up @@ -38,6 +45,15 @@ static void
app->save_settings = true;
}

static void
momentum_app_scene_interface_filebrowser_show_browser_path_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, browser_path_names[index]);
momentum_settings.show_browser_path = index;
app->save_settings = true;
}

static void momentum_app_scene_interface_filebrowser_favorite_timeout_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
uint32_t value = variable_item_get_current_value_index(item);
Expand Down Expand Up @@ -80,6 +96,16 @@ void momentum_app_scene_interface_filebrowser_on_enter(void* context) {
variable_item_set_current_value_index(item, momentum_settings.show_internal_tab);
variable_item_set_current_value_text(item, momentum_settings.show_internal_tab ? "ON" : "OFF");

item = variable_item_list_add(
var_item_list,
"Show Browser Path",
BrowserPathModeCount,
momentum_app_scene_interface_filebrowser_show_browser_path_changed,
app);
variable_item_set_current_value_index(item, momentum_settings.show_browser_path);
variable_item_set_current_value_text(
item, browser_path_names[momentum_settings.show_browser_path]);

item = variable_item_list_add(
var_item_list,
"Favorite Timeout",
Expand Down
2 changes: 2 additions & 0 deletions lib/momentum/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MomentumSettings momentum_settings = {
.sort_dirs_first = true, // ON
.show_hidden_files = false, // OFF
.show_internal_tab = false, // OFF
.show_browser_path = BrowserPathOff, // OFF
.favorite_timeout = 0, // OFF
.dark_mode = false, // OFF
.rgb_backlight = false, // OFF
Expand Down Expand Up @@ -98,6 +99,7 @@ static const struct {
{setting_bool(sort_dirs_first)},
{setting_bool(show_hidden_files)},
{setting_bool(show_internal_tab)},
{setting_bool(show_browser_path)},
{setting_uint(favorite_timeout, 0, 60)},
{setting_bool(dark_mode)},
{setting_bool(rgb_backlight)},
Expand Down
9 changes: 9 additions & 0 deletions lib/momentum/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ typedef union __attribute__((packed)) {
uint32_t value;
} ScreenFrameColor;

typedef enum {
BrowserPathOff,
BrowserPathCurrent,
BrowserPathBrief,
BrowserPathFull,
BrowserPathModeCount,
} BrowserPathMode;

typedef struct {
char asset_pack[ASSET_PACKS_NAME_LEN];
uint32_t anim_speed;
Expand All @@ -77,6 +85,7 @@ typedef struct {
bool sort_dirs_first;
bool show_hidden_files;
bool show_internal_tab;
BrowserPathMode show_browser_path;
uint32_t favorite_timeout;
bool dark_mode;
bool rgb_backlight;
Expand Down