Skip to content

Commit 8d8c001

Browse files
authored
Merge pull request #46 from jblanked/dev
FlipSocial - v2.0.8 - Updated auto-complete functionality to accept and return multi-word suggestions. - Moved the keyboard class to its own folder for better organization. - Added more suggestions to the auto-complete dictionary. - Fixed some minor bugs in file saving/loading.
2 parents 8eb0006 + f967217 commit 8d8c001

File tree

12 files changed

+321
-103
lines changed

12 files changed

+321
-103
lines changed

app.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ bool FlipSocialApp::loadFileChunk(const char *filePath, char *buffer, size_t siz
356356
// Change the current access position in a file.
357357
if (!storage_file_seek(file, iteration * sizeOfChunk, true))
358358
{
359+
storage_file_close(file);
359360
storage_file_free(file);
360361
furi_record_close(RECORD_STORAGE);
361362
FURI_LOG_E(TAG, "Failed to seek file: %s", filePath);
@@ -365,7 +366,9 @@ bool FlipSocialApp::loadFileChunk(const char *filePath, char *buffer, size_t siz
365366
// Check whether the current access position is at the end of the file.
366367
if (storage_file_eof(file))
367368
{
368-
FURI_LOG_E(TAG, "End of file reached: %s", filePath);
369+
storage_file_close(file);
370+
storage_file_free(file);
371+
furi_record_close(RECORD_STORAGE);
369372
return false;
370373
}
371374

@@ -406,15 +409,28 @@ void FlipSocialApp::runDispatcher()
406409
view_dispatcher_run(viewDispatcher);
407410
}
408411

409-
bool FlipSocialApp::saveChar(const char *path_name, const char *value, const char *appId)
412+
bool FlipSocialApp::saveChar(const char *path_name, const char *value, const char *appId, bool overwrite)
410413
{
411414
Storage *storage = static_cast<Storage *>(furi_record_open(RECORD_STORAGE));
412415
File *file = storage_file_alloc(storage);
413416
char file_path[256];
414417
snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/%s/data/%s.txt", appId, path_name);
415-
storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS);
416-
size_t data_size = strlen(value) + 1; // Include null terminator
417-
storage_file_write(file, value, data_size);
418+
if (!storage_file_open(file, file_path, FSAM_WRITE, overwrite ? FSOM_CREATE_ALWAYS : FSOM_OPEN_APPEND))
419+
{
420+
storage_file_free(file);
421+
furi_record_close(RECORD_STORAGE);
422+
return false;
423+
}
424+
size_t append = overwrite ? 1 : 0; // add null terminator if overwriting
425+
size_t data_size = strlen(value) + append;
426+
if (storage_file_write(file, value, data_size) != data_size)
427+
{
428+
FURI_LOG_E(TAG, "Failed to write complete data to file: %s", file_path);
429+
storage_file_close(file);
430+
storage_file_free(file);
431+
furi_record_close(RECORD_STORAGE);
432+
return false;
433+
}
418434
storage_file_close(file);
419435
storage_file_free(file);
420436
furi_record_close(RECORD_STORAGE);

app.hpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "about/about.hpp"
88

99
#define TAG "FlipSocial"
10-
#define VERSION "2.0.7"
10+
#define VERSION "2.0.8"
1111
#define VERSION_TAG TAG " " VERSION
1212
#define APP_ID "flip_social"
1313

@@ -52,30 +52,30 @@ class FlipSocialApp
5252
ViewDispatcher *viewDispatcher = nullptr; // ViewDispatcher for managing views
5353
ViewPort *viewPort = nullptr; // ViewPort for drawing and input handling (run instance)
5454
//
55-
size_t getBytesReceived() const noexcept { return flipperHttp ? flipperHttp->bytes_received : 0; } // get the number of bytes received
56-
size_t getContentLength() const noexcept { return flipperHttp ? flipperHttp->content_length : 0; } // get the content length of the last response
57-
HTTPState getHttpState() const noexcept { return flipperHttp ? flipperHttp->state : INACTIVE; } // get the HTTP state
58-
bool hasWiFiCredentials(); // check if WiFi credentials are set
59-
bool hasUserCredentials(); // check if user credentials are set
60-
FuriString *httpRequest( // synchronous HTTP request
61-
const char *url, // URL to send the request to
62-
HTTPMethod method = GET, // HTTP method to use (GET, POST, etc.)
63-
const char *headers = "{\"Content-Type\": \"application/json\"}", // Headers to include in the request
64-
const char *payload = nullptr); // Payload to send with the request (for POST, PUT, etc.)
65-
bool httpRequestAsync( // asynchronous HTTP request (check the HttpState to see if the request is finished)
66-
const char *saveLocation, // location to save the response (filename)
67-
const char *url, // URL to send the request to
68-
HTTPMethod method = GET, // HTTP method to use (GET, POST, etc.)
69-
const char *headers = "{\"Content-Type\": \"application/json\"}", // Headers to include in the request
70-
const char *payload = nullptr); // Payload to send with the request (for POST, PUT, etc.)
71-
bool isBoardConnected(); // check if the board is connected
72-
bool loadChar(const char *path_name, char *value, size_t value_size, const char *appId = APP_ID); // load a string from storage
73-
bool loadFileChunk(const char *filePath, char *buffer, size_t sizeOfChunk, uint8_t iteration); // Load a file chunk from storage
74-
void runDispatcher(); // run the app's view dispatcher to handle views and events
75-
bool saveChar(const char *path_name, const char *value, const char *appId = APP_ID); // save a string to storage
76-
bool setHttpState(HTTPState state = IDLE) noexcept; // set the HTTP state
77-
bool sendWiFiCredentials(const char *ssid, const char *password); // send WiFi credentials to the board
78-
void updateApp(); // update the app (used in the main function)
79-
static void viewPortDraw(Canvas *canvas, void *context); // draw callback for the ViewPort (used in run instance)
80-
static void viewPortInput(InputEvent *event, void *context); // input callback for the ViewPort (used in run instance)
55+
size_t getBytesReceived() const noexcept { return flipperHttp ? flipperHttp->bytes_received : 0; } // get the number of bytes received
56+
size_t getContentLength() const noexcept { return flipperHttp ? flipperHttp->content_length : 0; } // get the content length of the last response
57+
HTTPState getHttpState() const noexcept { return flipperHttp ? flipperHttp->state : INACTIVE; } // get the HTTP state
58+
bool hasWiFiCredentials(); // check if WiFi credentials are set
59+
bool hasUserCredentials(); // check if user credentials are set
60+
FuriString *httpRequest( // synchronous HTTP request
61+
const char *url, // URL to send the request to
62+
HTTPMethod method = GET, // HTTP method to use (GET, POST, etc.)
63+
const char *headers = "{\"Content-Type\": \"application/json\"}", // Headers to include in the request
64+
const char *payload = nullptr); // Payload to send with the request (for POST, PUT, etc.)
65+
bool httpRequestAsync( // asynchronous HTTP request (check the HttpState to see if the request is finished)
66+
const char *saveLocation, // location to save the response (filename)
67+
const char *url, // URL to send the request to
68+
HTTPMethod method = GET, // HTTP method to use (GET, POST, etc.)
69+
const char *headers = "{\"Content-Type\": \"application/json\"}", // Headers to include in the request
70+
const char *payload = nullptr); // Payload to send with the request (for POST, PUT, etc.)
71+
bool isBoardConnected(); // check if the board is connected
72+
bool loadChar(const char *path_name, char *value, size_t value_size, const char *appId = APP_ID); // load a string from storage
73+
bool loadFileChunk(const char *filePath, char *buffer, size_t sizeOfChunk, uint8_t iteration); // Load a file chunk from storage
74+
void runDispatcher(); // run the app's view dispatcher to handle views and events
75+
bool saveChar(const char *path_name, const char *value, const char *appId = APP_ID, bool overwrite = true); // save a string to storage
76+
bool setHttpState(HTTPState state = IDLE) noexcept; // set the HTTP state
77+
bool sendWiFiCredentials(const char *ssid, const char *password); // send WiFi credentials to the board
78+
void updateApp(); // update the app (used in the main function)
79+
static void viewPortDraw(Canvas *canvas, void *context); // draw callback for the ViewPort (used in run instance)
80+
static void viewPortInput(InputEvent *event, void *context); // input callback for the ViewPort (used in run instance)
8181
};

application.fam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ App(
99
fap_icon_assets="assets",
1010
fap_author="JBlanked",
1111
fap_weburl="https://github.com/jblanked/FlipSocial",
12-
fap_version="2.0.7",
12+
fap_version="2.0.8",
1313
fap_description="Social media platform for the Flipper Zero.",
1414
)

assets/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.8
2+
- Updated auto-complete functionality to accept and return multi-word suggestions.
3+
- Moved the keyboard class to its own folder for better organization.
4+
- Added more suggestions to the auto-complete dictionary.
5+
- Fixed some minor bugs in file saving/loading.
6+
17
## 2.0.7
28
- Fixed crashes that occurred in menu navigation when trying to access an item that was out of bounds.
39
- Updated the keyboard input: pressing BACK now deletes the current character instead of exiting the keyboard (hold BACK to exit the keyboard).

auto_complete/auto_complete.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#include "auto_complete.h"
22

3-
// Get index for character (a-z maps to 0-25)
3+
// Get index for character (a-z maps to 0-25, space maps to 26)
44
static int char_to_index(char c)
55
{
66
c = tolower(c);
77
if (c >= 'a' && c <= 'z')
88
{
99
return c - 'a';
1010
}
11+
if (c == ' ')
12+
{
13+
return 26; // Space gets index 26
14+
}
1115
return -1; // Invalid character
1216
}
1317

auto_complete/auto_complete.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#define MAX_WORD_LENGTH 32
1212
#define MAX_SUGGESTIONS 10
13-
#define ALPHABET_SIZE 26 // a-z
13+
#define ALPHABET_SIZE 27 // a-z + space
1414

1515
#ifdef __cplusplus
1616
extern "C"

0 commit comments

Comments
 (0)