refactor(hello): 视图框架批次② — hello.c 拆分为 app.c+ui/{home,full,demo}.c+ui/common/chrome.c+logic/{notify,state}.c(定案B: demo视图态留ui/;定案b: page导航包装activity栈);test_p1p2p3_repro 改多文件链接形态 (agent-177)

hello f45ba051→c06b3b4f; mipsel -Wall -Wextra 0 warning; 宿主 P1c/P2/P3+widgets 全 PASS
出入(诚实): view on_draw/on_event 路径暂未启用(注册表直绘已覆盖, on_draw 双画风险), 留批③实测; home/full 仍手绘未迁注册表
This commit is contained in:
MeowOS committed 2026-08-31 03:31:09 +08:00
1 parent 896f391fee
commit 1d2496b38c
12 files changed
+668 -364

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
/* logic/logic.h — 业务层接口(纯 C,不依赖 meow_ui.h / meow_view)。
*
* 分层契约(SDK_VIEW_FRAMEWORK_DESIGN.md §B.1):
* ① UI→业务 = 纯函数命令 + getter(logic_* / notify_* 返回业务态,业务不回调 UI);
* ② 业务→UI = 可选 push 监听器(logic_listener_fn + logic_set_listener);
* ③ view 的 ctx = 视图控制器(biz-UI 绑定点)。
* 本头只声明数据类型与函数原型,不含任何 meow_ui.h / meow_ui_view.h 依赖——
* logic/state.c 因此保持纯 C;logic/notify.c 仅因要用 SDK 通知 API 而 include meow_ui.h。
*/
#ifndef HELLO_LOGIC_H
#define HELLO_LOGIC_H
/* 监听器事件类型(业务态变化 → 通知 UI) */
#define LOGIC_EV_TAPS 1 /* taps 计数变化 */
#define LOGIC_EV_SECS 2 /* secs 秒计数变化 */
typedef void (*logic_listener_fn)(int ev, void *ctx); /* ctx = 监听器注册时给的视图控制器 */
/* ---- 计数业务态(logic/state.c)---- */
int logic_taps_get(void); /* 返回累计 taps */
void logic_taps_bump(void); /* taps++,并触发监听器(若已注册) */
int logic_secs_get(void); /* 返回过去秒数 */
void logic_secs_add(int n); /* secs += n,并触发监听器(若已注册) */
void logic_set_listener(logic_listener_fn cb, void *ctx); /* 注册业务→UI 推送监听器(可 NULL 注销) */
/* ---- 通知业务(logic/notify.c)---- */
void notif_send(int which); /* 按索引发一条通知(数据/超时/优先级在业务层定) */
void notif_cancel(void); /* 取消最近一条发送的通知 */
#endif /* HELLO_LOGIC_H */
+56
View File
@@ -0,0 +1,56 @@
/* logic/notify.c — 通知业务(notif_send/notif_cancel)。
*
* 纯业务:只依赖 SDK 通知数据类型/API(meow_notify_*)+ meow_log,不碰任何 UI 控件/view。
* UI 只经 notif_send()/notif_cancel() 调用(契约 ①);本层不回调 UI,最近一条 id 由本层持有。
* 注:boundary 折中——通知是 SDK 服务(§9.1),故本文件 include meow_ui.h 仅用其通知类型/函数。
*/
#include "logic.h"
#include "meow_ui.h"
#include <string.h>
#include <stdint.h>
static uint32_t g_last_notif = 0; /* 最近一次 send 返回的 id,供 cancel */
void notif_send(int which)
{
meow_notify n;
memset(&n, 0, sizeof n);
n.progress = -1;
n.timeout_ms = MEOW_NOTIFY_TIMEOUT_NEVER;
n.urgency = MEOW_NOTIFY_URG_NORMAL;
const char *label = "?";
switch (which) {
case 0: label = "INFO"; n.cat = MEOW_NOTIFY_CAT_GENERAL;
n.title = "测试-普通通知"; n.body = "普通 INFO 通知,timeout=5000ms"; n.timeout_ms = 5000; break;
case 1: label = "MEDIA"; n.cat = MEOW_NOTIFY_CAT_MEDIA; n.urgency = MEOW_NOTIFY_URG_LOW;
n.title = "测试-媒体通知"; n.body = "媒体单例,正在播放,timeout=-1 常驻";
n.timeout_ms = MEOW_NOTIFY_TIMEOUT_ONGOING; break;
case 2: label = "HIGH"; n.cat = MEOW_NOTIFY_CAT_GENERAL; n.urgency = MEOW_NOTIFY_URG_HIGH;
n.title = "测试-紧急度HIGH"; n.body = "高紧急度:顶部横幅+提示音"; n.timeout_ms = 3000; break;
case 3: label = "PROG"; n.cat = MEOW_NOTIFY_CAT_PROGRESS;
n.title = "测试-进度通知"; n.body = "下载进度 40%"; n.timeout_ms = 8000; n.progress = 40; break;
case 4: label = "ONGO"; n.cat = MEOW_NOTIFY_CAT_GENERAL;
n.title = "测试-常驻通知"; n.body = "常驻不自动过期(timeout=-1),需手动取消";
n.timeout_ms = MEOW_NOTIFY_TIMEOUT_ONGOING; break;
case 5: label = "TGT"; n.cat = MEOW_NOTIFY_CAT_MESSAGE;
n.title = "测试-跳转Activity"; n.body = "点击跳转 target_activity=main";
n.timeout_ms = 6000; n.target_activity = "main"; n.icon = NULL; break;
default: return;
}
uint32_t id = meow_notify_send(&n);
g_last_notif = id;
meow_log(MEOW_LOG_INFO,
"notify btn=%s id=%u cat=%s urg=%s tmo=%d prog=%d target=%s title=%s",
label, (unsigned)id, meow_notify_category_str(n.cat),
meow_notify_urgency_str(n.urgency), n.timeout_ms, n.progress,
n.target_activity ? n.target_activity : "-", n.title ? n.title : "-");
}
void notif_cancel(void)
{
int r = meow_notify_cancel(g_last_notif);
meow_log(MEOW_LOG_INFO, "notify cancel id=%u result=%d", (unsigned)g_last_notif, r);
g_last_notif = 0;
}
+38
View File
@@ -0,0 +1,38 @@
/* logic/state.c — 计数业务态(taps/secs)+ 可选推送监听器(biz→UI)。
*
* 纯 C(无 meow_ui.h 依赖):状态 + getter/setter + 监听器。UI 经 logic_taps_bump()/
* logic_secs_add() 改状态;业务改后触发监听器(若已注册)通知 UI 刷新——契约 ①②(§B.1)。
*/
#include "logic.h"
#include <stddef.h>
static int g_taps = 0;
static int g_secs = 0;
static logic_listener_fn g_listener = NULL;
static void *g_listener_ctx = NULL;
int logic_taps_get(void)
{
return g_taps;
}
void logic_taps_bump(void)
{
g_taps++;
if (g_listener) g_listener(LOGIC_EV_TAPS, g_listener_ctx);
}
int logic_secs_get(void)
{
return g_secs;
}
void logic_secs_add(int n)
{
g_secs += n;
if (g_listener) g_listener(LOGIC_EV_SECS, g_listener_ctx);
}
void logic_set_listener(logic_listener_fn cb, void *ctx)
{
g_listener = cb;
g_listener_ctx = ctx;
}