GNHistoryManager - noxiouswinter/gnlib_android GitHub Wiki

GNHistoryManager helps in storing and retrieving the History of the State of a class. You can use it to switch in and out of History or to step through it. The History will also persist across sessions.

###Usage Mark the fields of your class representing it's State with the @GNState annotation.

public class HistoryActivity extends Activity {

    @GNState
    String name;

Initialize GNHistoryManagerFactory and get an instance of GNHistoryManager.

GNHistoryManagerFactory.init(this);
GNHistoryManager gnHistoryManager = GNHistoryManagerFactory.get();

Somewhere in the class where the current State of the class makes sense to be captured as a part of it's History, add the current object to the History manager.

gnHistoryManager.addHistory(this);

Somewhere in the future where the previously saved State needs to be retrieved, retrieve it as follows. The position in history will range from 1 to as many States that have been added to the History till then.

gnHistoryManager.stepIntoHistory(positionInHistory, this);

The current State of the class will be captured temporarily and the State of the class switched to the corresponding State in History.

The history can be stepped through backwards,

gnHistoryManager.stepBackInHistory(this);

and forward.

gnHistoryManager.stepForwardInHistory(this);

Finally the history can be stepped out of.

gnHistoryManager.stepOutOfHistory(this);

The temporarily stored State before stepping into the History will be applied back to the class.