Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70ac8eaf authored by Annie Chin's avatar Annie Chin
Browse files

Fix animation for RESULT state.

Fixes: 32948596

Introduce isResultState() and pass its value to HistoryAdapter. We
actually can't accurately determine RESULT state from the Evaluator.

Change-Id: Ie50c5743fac8af680073c60a3e9cc9b58ccff167
parent 9179623c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -462,6 +462,10 @@ public class Calculator extends Activity
        }
    }

    public boolean isResultState() {
        return mCurrentState == CalculatorState.RESULT;
    }

    @Override
    protected void onDestroy() {
        mDragLayout.removeDragCallback(mDragCallback);
+6 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold

    private List<HistoryItem> mDataSet;

    private boolean mIsResultState;

    public HistoryAdapter(Calculator calculator, ArrayList<HistoryItem> dataSet,
            String currentExpressionDescription) {
        mEvaluator = Evaluator.getInstance(calculator);
@@ -131,6 +133,10 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold
        }
    }

    public void setIsResultState(boolean isResult) {
        mIsResultState = isResult;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView mDate;
+11 −4
Original line number Diff line number Diff line
@@ -135,7 +135,10 @@ public class HistoryFragment extends Fragment {
        dragLayout.removeDragCallback(mDragCallback);
        dragLayout.addDragCallback(mDragCallback);

        mEvaluator = Evaluator.getInstance((Calculator) getActivity());
        final Calculator activity = (Calculator) getActivity();
        final boolean isResultState = activity.isResultState();

        mEvaluator = Evaluator.getInstance(activity);

        if (mEvaluator != null) {
            initializeController();
@@ -144,9 +147,12 @@ public class HistoryFragment extends Fragment {

            final ArrayList<HistoryItem> newDataSet = new ArrayList<>();

            if (!EvaluatorStateUtils.isDisplayEmpty(mEvaluator)) {
                // Add the current expression as the first element in the list (the layout is reversed
                // and we want the current expression to be the last one in the recyclerview).
            if (!EvaluatorStateUtils.isDisplayEmpty(mEvaluator) && !isResultState) {
                // Add the current expression as the first element in the list (the layout is
                // reversed and we want the current expression to be the last one in the
                // recyclerview).
                // If we are in the result state, the result will animate to the last history
                // element in the list and there will be no "Current Expression."
                newDataSet.add(new HistoryItem(Evaluator.MAIN_INDEX, System.currentTimeMillis(),
                        mEvaluator.getExprAsSpannable(0)));
            }
@@ -158,6 +164,7 @@ public class HistoryFragment extends Fragment {
            }
            mDataSet = newDataSet;
            mAdapter.setDataSet(mDataSet);
            mAdapter.setIsResultState(isResultState);
        }

        mAdapter.notifyDataSetChanged();