frankiesardo/icepick

Add support for visibility state

Opened this issue · 3 comments

Currently if there are views whose visibility changes at runtime, we have to explicitly add member variables that represent the visibility status for each view.

This is tedious & error prone.

It would be much better if we add a new annotation @VisibilityState that can auto save the visibility status of a view.

The annotation processor can add a new variable (whose name can be derived from the name of the variable, for eg., mycustomViewRef$$visibility) in the bundle during saveInstanceState & auto apply the visibility status on restoreInstanceState

Here is an example

class MyActivity {
 @State
 int regularState;

 @VisibilityState
 TextView dynamicVisibilityTv;
 @VisibilityState
 CustomView customView;

 public void onSaveInstanceState(Bundle outState) {
  super.onSaveInstanceState(outState);
  Icepick.saveInstanceState(this, outState); // this should save `regularState`, `dynamicVisibilityTv$$visibility` & `customView$$visibility`
 }

 public void onRestoreInstanceState(Bundle savedInstanceState) {
  // Always call the superclass so it can restore the view hierarchy
  super.onRestoreInstanceState(savedInstanceState);
  Icepick.restoreInstanceState(this, savedInstanceState); // this should auto restore `regularState`, `dynamicVisibilityTv$$visibility` & `customView$$visibility`
 }

}

Yes, it would be excellent.

Along with visibility state, we should identify additional common views/components whose state we would want to be restore out of the box such as LinearLayoutManager, e.t.c.

Why does anyone needs to pollute code with most basic things when its apt can do this much better

@frankiesardo Any views on this?

FYI: I'm not comfortable clojure, else, I would have submitted a pull request :(