mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Implement a reset in apps (clear memory)
Change-Id: I158d5db92196ccfd5400a95de16ee4804e426e65
This commit is contained in:
@@ -7,6 +7,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Shared;
|
||||
|
||||
AppsContainer::AppsContainer() :
|
||||
Container(),
|
||||
@@ -51,6 +52,12 @@ App * AppsContainer::appAtIndex(int index) {
|
||||
return apps[index];
|
||||
}
|
||||
|
||||
void AppsContainer::reset() {
|
||||
for (int i = 0; i < numberOfApps(); i++) {
|
||||
((ResettableApp *)appAtIndex(i))->reset();
|
||||
}
|
||||
}
|
||||
|
||||
Context * AppsContainer::globalContext() {
|
||||
return &m_globalContext;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
|
||||
int numberOfApps();
|
||||
App * appAtIndex(int index);
|
||||
void reset();
|
||||
Poincare::Context * globalContext();
|
||||
MathToolbox * mathToolbox();
|
||||
VariableBoxController * variableBoxController();
|
||||
|
||||
@@ -20,4 +20,8 @@ Context * App::localContext() {
|
||||
return &m_localContext;
|
||||
}
|
||||
|
||||
void App::reset() {
|
||||
m_calculationStore.deleteAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class App : public Shared::TextFieldDelegateApp {
|
||||
public:
|
||||
App(Container * container, Poincare::Context * context);
|
||||
Poincare::Context * localContext() override;
|
||||
void reset() override;
|
||||
private:
|
||||
LocalContext m_localContext;
|
||||
CalculationStore m_calculationStore;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "exam_pop_up_controller.h"
|
||||
#include "i18n.h"
|
||||
#include "global_preferences.h"
|
||||
#include "apps_container.h"
|
||||
#include <assert.h>
|
||||
|
||||
ExamPopUpController::ExamPopUpController() :
|
||||
@@ -51,9 +52,9 @@ ExamPopUpController::ContentView::ContentView(Responder * parentResponder) :
|
||||
ExamPopUpController * controller = (ExamPopUpController *)context;
|
||||
GlobalPreferences::ExamMode nextExamMode = controller->isActivatingExamMode() ? GlobalPreferences::ExamMode::Activate : GlobalPreferences::ExamMode::Desactivate;
|
||||
GlobalPreferences::sharedGlobalPreferences()->setExamMode(nextExamMode);
|
||||
Container * container = (Container *)controller->app()->container();
|
||||
AppsContainer * container = (AppsContainer *)controller->app()->container();
|
||||
if (controller->isActivatingExamMode()) {
|
||||
//container->reset();
|
||||
container->reset();
|
||||
} else {
|
||||
Ion::LED::setColor(KDColorBlack);
|
||||
}
|
||||
|
||||
@@ -39,4 +39,8 @@ Context * App::localContext() {
|
||||
return TextFieldDelegateApp::localContext();
|
||||
}
|
||||
|
||||
void App::reset() {
|
||||
m_functionStore.removeAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
* use a temporary local context (on the stack). That way, we avoid keeping
|
||||
* weird x values after drawing curves or displaying the value table. */
|
||||
Poincare::Context * localContext() override;
|
||||
void reset() override;
|
||||
private:
|
||||
CartesianFunctionStore m_functionStore;
|
||||
Poincare::VariableContext m_xContext;
|
||||
|
||||
@@ -8,7 +8,7 @@ extern "C" {
|
||||
namespace HardwareTest {
|
||||
|
||||
App::App(AppsContainer * container) :
|
||||
::App(container, &m_keyboardController),
|
||||
Shared::ResettableApp(container, &m_keyboardController),
|
||||
m_keyboardController(KeyboardController(&m_modalViewController))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "keyboard_controller.h"
|
||||
#include "../shared/resettable_app.h"
|
||||
|
||||
class AppsContainer;
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
class App : public ::App {
|
||||
class App : public Shared::ResettableApp {
|
||||
public:
|
||||
App(AppsContainer * container);
|
||||
private:
|
||||
|
||||
@@ -9,7 +9,7 @@ extern "C" {
|
||||
namespace Home {
|
||||
|
||||
App::App(AppsContainer * container) :
|
||||
::App(container, &m_controller, I18n::Message::Apps, I18n::Message::AppsCapital, nullptr, I18n::Message::Warning),
|
||||
Shared::ResettableApp(container, &m_controller, I18n::Message::Apps, I18n::Message::AppsCapital, nullptr),
|
||||
m_controller(Controller(&m_modalViewController, container))
|
||||
{
|
||||
assert(container->appAtIndex(0) == this);
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "controller.h"
|
||||
#include "../shared/resettable_app.h"
|
||||
|
||||
class AppsContainer;
|
||||
|
||||
namespace Home {
|
||||
|
||||
class App : public ::App {
|
||||
class App : public Shared::ResettableApp {
|
||||
public:
|
||||
App(AppsContainer * container);
|
||||
private:
|
||||
|
||||
@@ -23,4 +23,8 @@ App::App(Container * container) :
|
||||
{
|
||||
}
|
||||
|
||||
void App::reset() {
|
||||
m_store.deleteAllPairs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Regression {
|
||||
class App : public Shared::TextFieldDelegateApp {
|
||||
public:
|
||||
App(Container * container);
|
||||
void reset() override;
|
||||
private:
|
||||
Store m_store;
|
||||
CalculationController m_calculationController;
|
||||
|
||||
@@ -37,6 +37,10 @@ Context * App::localContext() {
|
||||
return TextFieldDelegateApp::localContext();
|
||||
}
|
||||
|
||||
void App::reset() {
|
||||
m_sequenceStore.removeAll();
|
||||
}
|
||||
|
||||
const char * App::XNT() {
|
||||
return "n";
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
App(Container * container, Poincare::Context * context);
|
||||
InputViewController * inputViewController();
|
||||
Poincare::Context * localContext() override;
|
||||
void reset() override;
|
||||
const char * XNT() override;
|
||||
private:
|
||||
SequenceStore m_sequenceStore;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Settings {
|
||||
|
||||
App::App(Container * container) :
|
||||
::App(container, &m_stackViewController, I18n::Message::SettingsApp, I18n::Message::SettingsAppCapital, ImageStore::SettingsIcon, I18n::Message::Warning),
|
||||
Shared::ResettableApp(container, &m_stackViewController, I18n::Message::SettingsApp, I18n::Message::SettingsAppCapital, ImageStore::SettingsIcon),
|
||||
m_mainController(MainController(nullptr)),
|
||||
m_stackViewController(StackViewController(&m_modalViewController, &m_mainController))
|
||||
{
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "main_controller.h"
|
||||
#include "../shared/resettable_app.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class App : public ::App {
|
||||
class App : public Shared::ResettableApp {
|
||||
public:
|
||||
App(Container * container);
|
||||
private:
|
||||
|
||||
@@ -29,6 +29,7 @@ app_objs += $(addprefix apps/shared/,\
|
||||
ok_view.o\
|
||||
range_parameter_controller.o\
|
||||
regular_table_view_data_source.o\
|
||||
resettable_app.o\
|
||||
store_controller.o\
|
||||
store_parameter_controller.o\
|
||||
tab_table_controller.o\
|
||||
|
||||
@@ -62,4 +62,10 @@ int FunctionStore::numberOfDefinedFunctions() {
|
||||
return result;
|
||||
}
|
||||
|
||||
void FunctionStore::removeAll() {
|
||||
for (int i = 0; i < numberOfFunctions(); i++) {
|
||||
removeFunction(functionAtIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
virtual Function * definedFunctionAtIndex(int i);
|
||||
virtual Function * addEmptyFunction() = 0;
|
||||
virtual void removeFunction(Function * f) = 0;
|
||||
void removeAll();
|
||||
int numberOfFunctions();
|
||||
// Functions can be undefined when they have a color and a name but no content
|
||||
int numberOfDefinedFunctions();
|
||||
|
||||
13
apps/shared/resettable_app.cpp
Normal file
13
apps/shared/resettable_app.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "resettable_app.h"
|
||||
|
||||
namespace Shared {
|
||||
|
||||
ResettableApp::ResettableApp(Container * container, ViewController * rootViewController, I18n::Message name, I18n::Message upperName, const Image * icon) :
|
||||
::App(container, rootViewController, name, upperName, icon, I18n::Message::Warning)
|
||||
{
|
||||
}
|
||||
|
||||
void ResettableApp::reset() {
|
||||
}
|
||||
|
||||
}
|
||||
17
apps/shared/resettable_app.h
Normal file
17
apps/shared/resettable_app.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SHARED_RESETTABLE_APP_H
|
||||
#define SHARED_RESETTABLE_APP_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "../i18n.h"
|
||||
|
||||
namespace Shared {
|
||||
|
||||
class ResettableApp : public ::App {
|
||||
public:
|
||||
ResettableApp(Container * container, ViewController * rootViewController, I18n::Message name = (I18n::Message)0, I18n::Message upperName = (I18n::Message)0, const Image * icon = nullptr);
|
||||
virtual void reset();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@ using namespace Poincare;
|
||||
namespace Shared {
|
||||
|
||||
TextFieldDelegateApp::TextFieldDelegateApp(Container * container, ViewController * rootViewController, I18n::Message name, I18n::Message upperName, const Image * icon) :
|
||||
::App(container, rootViewController, name, upperName, icon, I18n::Message::Warning),
|
||||
ResettableApp(container, rootViewController, name, upperName, icon),
|
||||
TextFieldDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
#ifndef SHARED_TEXT_FIELD_DELEGATE_APP_H
|
||||
#define SHARED_TEXT_FIELD_DELEGATE_APP_H
|
||||
|
||||
#include <escher.h>
|
||||
#include <poincare.h>
|
||||
#include "../i18n.h"
|
||||
#include "resettable_app.h"
|
||||
|
||||
class AppsContainer;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
class TextFieldDelegateApp : public ::App, public TextFieldDelegate {
|
||||
class TextFieldDelegateApp : public ResettableApp, public TextFieldDelegate {
|
||||
public:
|
||||
TextFieldDelegateApp(Container * container, ViewController * rootViewController, I18n::Message name = (I18n::Message)0, I18n::Message upperName = (I18n::Message)0, const Image * icon = nullptr);
|
||||
virtual Poincare::Context * localContext();
|
||||
|
||||
@@ -25,4 +25,8 @@ App::App(Container * container) :
|
||||
{
|
||||
}
|
||||
|
||||
void App::reset() {
|
||||
m_store.deleteAllPairs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Statistics {
|
||||
class App : public Shared::TextFieldDelegateApp {
|
||||
public:
|
||||
App(Container * container);
|
||||
void reset() override;
|
||||
private:
|
||||
Store m_store;
|
||||
CalculationController m_calculationController;
|
||||
|
||||
@@ -39,7 +39,6 @@ public:
|
||||
|
||||
virtual void didBecomeActive(Window * window);
|
||||
virtual void willBecomeInactive();
|
||||
|
||||
protected:
|
||||
ModalViewController m_modalViewController;
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user