~aleteoryx/muditaos

ref: 9a7982f8efa4974f7f1396232fa2c09db0f6908e muditaos/module-apps/application-notes/windows/NotesEditWindow.cpp -rw-r--r-- 2.5 KiB
9a7982f8 — Marcin Smoczyński changelog: update changelog for v0.48.1 (#1104) (#1106) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <memory>
#include <functional>

#include <service-appmgr/model/ApplicationManager.hpp>

#include "bsp/rtc/rtc.hpp"

#include "../ApplicationNotes.hpp"

#include <service-db/DBMessage.hpp>
#include "i18/i18.hpp"

#include "Label.hpp"
#include "Margins.hpp"
#include "Text.hpp"
#include "NotesEditWindow.hpp"
#include <Style.hpp>

UTF8 textString = "Very long test line ABCDEFGHIJKLMNOPQRST123456789\n"
                  "abcdefghijklmnopqrs 123456789 ABCDEFGHIJKLMONPQRSTUW 12345\n    test\nnew line\n\n\n12345";

namespace gui
{

    NotesEditWindow::NotesEditWindow(app::Application *app) : AppWindow(app, "EditWindow")
    {
        buildInterface();
    }

    void NotesEditWindow::rebuild()
    {
        destroyInterface();
        buildInterface();
    }
    void NotesEditWindow::buildInterface()
    {
        AppWindow::buildInterface();

        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("app_notes_save"));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("app_notes_back"));

        setTitle(utils::localize.get("app_notes_new_note"));

        text = new gui::Text(this, 11, 105, 480 - 22, 600 - 105 - 50);
        text->setFont(style::window::font::medium);
        text->setRadius(5);
        text->setMargins(gui::Margins(10, 5, 10, 5));
        text->activatedCallback = [=](gui::Item &item) {
            UTF8 getstr = text->getText();
            time_t timestamp;
            bsp::rtc_GetCurrentTimestamp(&timestamp);

            UTF8 filename = "sys/data/applications/notes/" + std::to_string(timestamp) + ".txt";

            auto file = vfs.fopen(filename.c_str(), "wb");
            vfs.fwrite(getstr.c_str(), getstr.used() - 1, 1, file);
            vfs.fclose(file);
            return true;
        };
        text->setTextType(TextType::MULTI_LINE);
        text->setEditMode(EditMode::BROWSE);
        text->setInputMode(new InputMode({InputMode::ABC, InputMode::abc}));

        topBar->setActive(TopBar::Elements::TIME, true);
    }

    void NotesEditWindow::destroyInterface()
    {
        erase();
    }

    NotesEditWindow::~NotesEditWindow()
    {
        destroyInterface();
    }

    void NotesEditWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        text->setText(textString);
        setFocusItem(text);
    }

} /* namespace gui */