searles / FractviewAndroid

Fractview, a customizable fractal viewing app for Android
6 stars 1 forks source link

Reduce coupling of history in bitmap fragment #35

Closed searles closed 7 years ago

searles commented 7 years ago

Idea is to get to a single-responsibility design. Therefore, history should not be part of BitmapFragment. Maybe it can be its own Fragment. Anyways, the historyMaintainer should register as a listener with the BitmapFragment. BitmapFragment itself should not do anything fancy.

The BitmapFragmentListeners should be informed when the specification changed (which excludes changes of the image size).

    setFractal(f) {
        edit((...) -> { ...; fireFractalChanged(f); } )
    }

    setScale(f) {
        edit(... -> { ...; fireFractalChanged(f); })
    }

      Listener: fractalChanged(BitmapFragment src, Fractal f)

History itself is the recipient of 'back'-keys.

History is a List + a current-field.

current
stack

setCurrent(Fractal) 

push() : if(current != null) stack.push(current); current = null;
current can be null if imageSize was changed.

pop() : return stack.pop(); null if no more elements. 'current is kept'

calculationStarted calls push().

This way, MainActivity.back calls bitmapFragment.setFractal(history.pop()) and the popped fractal is added as current again.

searles commented 7 years ago

Complexity was reduced.