protected override void StartPresentingState()
    {
        string monthTrackedPreviously = PlayerPrefs.GetString(k_monthTrackingKey, string.Empty);

        if (string.IsNullOrEmpty(monthTrackedPreviously))
        {
            PlayerPrefs.SetString(k_monthTrackingKey, string.Format(k_monthTrackingFormat, DateTime.Now.Month, DateTime.Now.Year));
            PlayerPrefs.Save();
            return;
        }

        if (string.Format(k_monthTrackingFormat, DateTime.Now.Month, DateTime.Now.Year) != monthTrackedPreviously)
        {
            //TODO: Allow last additions to month before saving
            MonthlyValueData monthData = MonthDataUtils.BuildCurrentMonthData();
            monthData.m_monthReflected = monthTrackedPreviously;

            string previousJson          = PlayerPrefs.GetString(k_monthCollectionKey, string.Empty);
            PreviousMonthlyValues values = default;
            if (!string.IsNullOrEmpty(previousJson))
            {
                values = JsonUtility.FromJson <PreviousMonthlyValues>(previousJson);
            }

            if (values.monthlyValues == null)
            {
                values.monthlyValues = new List <MonthlyValueData>();
            }
            values.monthlyValues.Add(monthData);
            PlayerPrefs.SetString(k_monthCollectionKey, JsonUtility.ToJson(values));
            PlayerPrefs.SetString(k_monthTrackingKey, string.Format(k_monthTrackingFormat, DateTime.Now.Month, DateTime.Now.Year));
            PlayerPrefs.DeleteKey(k_variableValuesKey);
            PlayerPrefs.Save();
        }
    }
Beispiel #2
0
    protected override void HandleMessage(object message)
    {
        switch (message)
        {
        case k_setTimeScaleMsg:
            MonthlyValueData[] allValueRanges = new MonthlyValueData[m_previousMonths.monthlyValues.Count + 1];
            m_previousMonths.monthlyValues.CopyTo(allValueRanges);
            allValueRanges[allValueRanges.Length - 1] = MonthDataUtils.BuildCurrentMonthData();

            string[] ranges    = Array.ConvertAll(allValueRanges, (element) => element.m_monthReflected);
            var      timeState = new TimeScalePopupState(ranges, m_monthsToDisplay[0].m_monthReflected,
                                                         m_monthsToDisplay[m_monthsToDisplay.Count - 1].m_monthReflected, LoadDataRangeAndRefreshGraph);
            ControllingStateStack.PushState(timeState);
            break;

        case k_backMenuMsg:
            ControllingStateStack.PopState(this);
            break;

        case string msg when msg.StartsWith(k_showStartingMsg):
            SetToggleStateFromMsg(msg);

            RefreshGraph();
            break;
        }
    }
    public void SetData(MonthlyValueData monthlyData)
    {
        SetSegmentText(m_totalFixedIncome, monthlyData.m_totalFixedIncome);
        SetSegmentText(m_totalFixedExpenses, monthlyData.m_totalFixedExpenses);
        SetSegmentText(m_totalVariableIncome, monthlyData.m_totalVariableIncome);
        SetSegmentText(m_totalVariableExpenses, monthlyData.m_totalVariableExpenses);

        float monthlyBalance = monthlyData.MonthlyBalanceRemaining;

        SetSegmentText(m_currentMonthlyBalance, monthlyBalance);

        //TODO: Set target balance remaining in app to decide colour
        m_currentMonthlyBalance.m_backingImage.color = monthlyBalance >= 0.0f ? k_incomeCol : k_expensesCol;
    }
    protected override void StartPresentingState()
    {
        MonthlyValueData monthlyValue = MonthDataUtils.BuildCurrentMonthData();

        m_uiOverview.SetData(monthlyValue);
    }