Compare commits

...
2 Commits
Author SHA1 Message Date
waozixyz db7bb624e4 improved android data import for .db 2026-06-18 17:27:23 -03:00
waozixyz 4a8a554396 allow import db files 2026-06-18 17:09:50 -03:00
9 changed files with 176 additions and 33 deletions

No files matched your search

+4
View File
@@ -1,4 +1,8 @@
# Changelog
## [1.3.5] - 2026-06-18
### Fixed
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
## [1.3.4] - 2026-06-18
### Changed
- Reorganized WHM and Meditation into practice-owned modules for cleaner code boundaries.
+2 -2
View File
@@ -35,8 +35,8 @@ android {
defaultConfig {
minSdk 19
targetSdk 35
versionCode 32
versionName "1.3.4"
versionCode 33
versionName "1.3.5"
}
@@ -281,7 +281,8 @@ public class MainActivity extends NativeActivity {
"application/x-zip-compressed",
"application/vnd.sqlite3",
"application/x-sqlite",
"application/x-sqlite3"
"application/x-sqlite3",
"application/octet-stream"
});
startActivityForResult(intent, REQUEST_IMPORT_ZIP);
} catch (Exception e) {
@@ -0,0 +1,2 @@
### Fixed
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
+2 -2
View File
@@ -3,7 +3,7 @@
#define INBE_VERSION_MAJOR 1
#define INBE_VERSION_MINOR 3
#define INBE_VERSION_PATCH 4
#define INBE_VERSION_STRING "1.3.4"
#define INBE_VERSION_PATCH 5
#define INBE_VERSION_STRING "1.3.5"
#endif
+44 -19
View File
@@ -21,8 +21,9 @@ extern int view_width;
extern int view_height;
enum {
HABIT_WEEKLY_INITIAL_DAYS = 7,
HABIT_WEEKLY_LOAD_DAYS = 7,
HABIT_WEEKLY_MONTH_DAYS = 31,
HABIT_WEEKLY_INITIAL_DAYS = HABIT_WEEKLY_MONTH_DAYS,
HABIT_WEEKLY_LOAD_DAYS = HABIT_WEEKLY_MONTH_DAYS,
HABIT_WEEKLY_MAX_DAYS = INBE_HABIT_MAX_DAYS
};
@@ -771,6 +772,26 @@ draw_habit_link_dot(int x, int y, int w, Color color)
flint_px(3), color);
}
static Color
habit_text_color_for_background(Color background)
{
int luma = background.r * 299 + background.g * 587 + background.b * 114;
return luma >= 128000 ? BLACK : WHITE;
}
static void
habit_weekly_draw_text_line(const char *text, int x, int y, int w, int h,
int text_size, Color color)
{
int font_size;
if(text == NULL || text[0] == '\0' || w <= 0 || h <= 0)
return;
font_size = flint_px(text_size);
flint_text_draw(text, x, flint_text_y(text, y, h, font_size), font_size, color);
}
static int
habit_weekly_summary(const HabitLinkedContext *ctx, int day_index,
char *primary, size_t primary_size,
@@ -821,8 +842,9 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
int hovered;
Color fill = completed ? theme_get_button() : flint_darken(theme_get_bg(), 10);
Color text = disabled ? flint_darken(theme_get_text(), 35) : theme_get_text();
int font = flint_ui_font();
int small_font = flint_px(FLINT_TEXT_8);
int pad = flint_px(9);
int text_x;
int text_w;
const char *line1 = primary != NULL ? primary : "";
const char *line2 = secondary != NULL ? secondary : "";
@@ -841,25 +863,28 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
if(hovered)
fill = theme_get_button_hover();
if(!disabled && completed)
text = habit_text_color_for_background(fill);
DrawRectangle(x, y, w, h, fill);
ui_draw_bevel(x, y, w, h, flint_lighten(fill, 36), flint_darken(fill, 42));
text_x = x + pad;
text_w = w - pad * 2;
if(line1[0] != '\0') {
if(line2[0] != '\0') {
flint_text_draw_fitted_in_rect(line1,
(Rectangle){x + flint_px(8), y + flint_px(5),
w - flint_px(16), flint_px(18)},
font, FLINT_TEXT_12, text);
flint_text_draw_fitted_in_rect(line2,
(Rectangle){x + flint_px(8), y + flint_px(24),
w - flint_px(16), flint_px(12)},
small_font, FLINT_TEXT_8,
flint_darken(text, 16));
int line1_h = flint_px(24);
int line2_h = flint_px(16);
int block_h = line1_h + line2_h;
int block_y = y + (h - block_h) / 2;
habit_weekly_draw_text_line(line1, text_x, block_y, text_w, line1_h,
FLINT_TEXT_16, text);
habit_weekly_draw_text_line(line2, text_x, block_y + line1_h, text_w, line2_h,
FLINT_TEXT_8, flint_darken(text, 16));
} else {
flint_text_draw_fitted_in_rect(line1,
(Rectangle){x + flint_px(8), y,
w - flint_px(16), h},
font, FLINT_TEXT_16, text);
habit_weekly_draw_text_line(line1, text_x, y + flint_px(3),
text_w, h - flint_px(6),
FLINT_TEXT_16, text);
}
}
@@ -883,7 +908,7 @@ habit_weekly_visible_days(InbeHabits *habits)
static int
habit_weekly_content_height(int visible_days)
{
int row_h = flint_px(40);
int row_h = flint_px(44);
int row_gap = flint_px(6);
int load_h = flint_px(38);
@@ -908,7 +933,7 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
int gap = flint_px(8);
int button_x;
int button_w;
int row_h = flint_px(40);
int row_h = flint_px(44);
int row_gap = flint_px(6);
int day_font = flint_px(16);
int date_font = flint_px(FLINT_TEXT_8);
+13 -5
View File
@@ -1522,8 +1522,11 @@ import_tickmate_db(sqlite3 *src)
sizeof(local_habit_id)))
continue;
if(sqlite3_prepare_v2(g_storage.db,
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
"VALUES(?1,?2,1,?3)",
"INSERT INTO habit_days(habit_id,local_date,completed,updated_at) "
"VALUES(?1,?2,1,?3) "
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
"completed=CASE WHEN habit_days.completed!=0 THEN habit_days.completed ELSE excluded.completed END,"
"updated_at=CASE WHEN habit_days.completed!=0 THEN habit_days.updated_at ELSE excluded.updated_at END",
-1, &write_stmt, NULL) != SQLITE_OK)
continue;
bind_text(write_stmt, 1, local_habit_id);
@@ -1563,7 +1566,9 @@ import_settings_from_source(sqlite3 *src)
continue;
if(sqlite3_prepare_v2(g_storage.db,
"INSERT INTO settings(user_id,key,value,updated_at) VALUES(?1,?2,?3,?4) "
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value,updated_at=excluded.updated_at",
"ON CONFLICT(user_id,key) DO UPDATE SET "
"value=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.value ELSE settings.value END,"
"updated_at=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.updated_at ELSE settings.updated_at END",
-1, &write_stmt, NULL) != SQLITE_OK)
continue;
bind_text(write_stmt, 1, g_storage.user_id);
@@ -1718,8 +1723,11 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
while(sqlite3_step(hstmt) == SQLITE_ROW) {
sqlite3_stmt *day_stmt = NULL;
if(sqlite3_prepare_v2(g_storage.db,
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
"VALUES(?1,?2,?3,?4)",
"INSERT INTO habit_days(habit_id,local_date,completed,updated_at) "
"VALUES(?1,?2,?3,?4) "
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
"completed=CASE WHEN habit_days.completed!=0 THEN habit_days.completed ELSE excluded.completed END,"
"updated_at=CASE WHEN habit_days.completed!=0 THEN habit_days.updated_at ELSE excluded.updated_at END",
-1, &day_stmt, NULL) != SQLITE_OK)
continue;
bind_text(day_stmt, 1, local_habit_id);
+103
View File
@@ -159,6 +159,32 @@ write_source_database(const char *root)
inbe_storage_close();
}
static void
insert_raw_habit_day(const char *root, const char *habit_id, int local_date, int completed)
{
char db_path[512];
sqlite3 *db = NULL;
sqlite3_stmt *stmt = NULL;
make_path(db_path, sizeof(db_path), root, "inbe.db");
check_true("open raw habit day db", sqlite3_open(db_path, &db) == SQLITE_OK);
if(db == NULL)
return;
if(sqlite3_prepare_v2(db,
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
"VALUES(?1,?2,?3,0)",
-1, &stmt, NULL) == SQLITE_OK) {
sqlite3_bind_text(stmt, 1, habit_id, -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 2, local_date);
sqlite3_bind_int(stmt, 3, completed ? 1 : 0);
check_true("insert raw habit day", sqlite3_step(stmt) == SQLITE_DONE);
} else {
check_true("prepare raw habit day", 0);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
}
static void
metadata_history_callback(const char *id, int year, int month, int day,
int hour, int minute, int second,
@@ -338,6 +364,55 @@ test_habit_name_merge_import(void)
remove_tree(dest);
}
static void
test_import_conflict_prefers_data_over_empty(void)
{
char source[512], dest[512], zip_path[512];
InbeHabits habits;
InbeHabit *habit;
make_clean_root(source, sizeof(source), "conflict-source");
make_clean_root(dest, sizeof(dest), "conflict-dest");
make_path(zip_path, sizeof(zip_path), source, "conflict-export.zip");
check_true("init conflict source", inbe_storage_init(source));
memset(&habits, 0, sizeof(habits));
check_int("add conflict source habit",
inbe_habits_add_custom(&habits, "Meditation",
(Color){224, 124, 104, 255},
INBE_HABIT_SYNC_NONE, 0),
0);
inbe_storage_set_setting_text("language", "");
inbe_storage_close();
insert_raw_habit_day(source, "habit-1", 20260618, 0);
check_true("reopen conflict source", inbe_storage_init(source));
check_true("conflict source export", inbe_storage_export_zip(zip_path));
inbe_storage_close();
check_true("init conflict dest", inbe_storage_init(dest));
memset(&habits, 0, sizeof(habits));
check_int("add conflict dest habit",
inbe_habits_add_custom(&habits, "Meditation",
(Color){126, 183, 230, 255},
INBE_HABIT_SYNC_NONE, 0),
0);
inbe_habit_set_day(&habits, 0, 20260618, 1);
inbe_storage_set_setting_text("language", "en");
check_true("conflict import",
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
memset(&habits, 0, sizeof(habits));
check_true("conflict habits load", inbe_storage_habits_load(&habits));
habit = find_habit_ci(&habits, "Meditation");
check_true("conflict keeps completed day",
habit != NULL && inbe_habit_completed_day(habit, 20260618));
check_str("conflict keeps non-empty setting",
inbe_storage_get_setting_text("language"), "en");
inbe_storage_close();
remove_tree(source);
remove_tree(dest);
}
static void
write_multi_habit_source_database(const char *root, const char *zip_path)
{
@@ -583,16 +658,44 @@ test_tickmate_db_import(void)
remove_tree(dest);
}
static void
test_external_tickmate_db_import(void)
{
const char *db_path = getenv("INBE_TICKMATE_IMPORT_FIXTURE");
char dest[512];
InbeStorageImportInfo info;
InbeHabits habits;
if(db_path == NULL || db_path[0] == '\0')
return;
make_clean_root(dest, sizeof(dest), "external-tickmate-dest");
check_true("init external tickmate import dest", inbe_storage_init(dest));
memset(&info, 0, sizeof(info));
check_true("inspect external tickmate db", inbe_storage_inspect_import(db_path, &info));
check_true("external tickmate db valid", info.valid);
check_true("external tickmate db has habits", info.has_habits);
check_true("external tickmate db import", inbe_storage_import_zip(db_path));
memset(&habits, 0, sizeof(habits));
check_true("external tickmate habits load", inbe_storage_habits_load(&habits));
check_true("external tickmate habit count", habits.count > 0);
inbe_storage_close();
remove_tree(dest);
}
int
main(void)
{
test_raw_db_import();
test_zip_db_import();
test_habit_name_merge_import();
test_import_conflict_prefers_data_over_empty();
test_import_modes_preserve_habits_and_settings_choice();
test_legacy_zip_import();
test_legacy_file_startup_migration();
test_tickmate_db_import();
test_external_tickmate_db_import();
test_session_metadata();
if(g_failures != 0) {
+4 -4
View File
@@ -3,8 +3,8 @@
IDI_APP_ICON ICON "inbe.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,4,0
PRODUCTVERSION 1,3,4,0
FILEVERSION 1,3,5,0
PRODUCTVERSION 1,3,5,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -21,11 +21,11 @@ BEGIN
BEGIN
VALUE "CompanyName", "waozi"
VALUE "FileDescription", "Inner Breeze"
VALUE "FileVersion", "1.3.4"
VALUE "FileVersion", "1.3.5"
VALUE "InternalName", "inbe"
VALUE "OriginalFilename", "inbe-windows-x86_64.exe"
VALUE "ProductName", "Inner Breeze"
VALUE "ProductVersion", "1.3.4"
VALUE "ProductVersion", "1.3.5"
END
END
BLOCK "VarFileInfo"