Design pattern for activity state controll
<p>I have an actvivity which contain several fragments and views. When I started working on my app the activity had several states which I changed throw click listeners in fragments and views.</p>

<p>Currently the code grew up to >1.5k lines and I realize that I need to introduce some pattern to make it maintainable.
The problem is that when I change my activitie's property I need to change layout in several fragments or views.</p>

<p>For example I have a handler which listens to network response:</p>

<pre><code>//Handler to process messages from VendorCache
    private Handler vendorCacheHandler = new Handler(){
        @Override
          public void handleMessage(Message msg) {
            if(msg.what == VendorCache.RECEIVED_OPTIONS){

                String id = (String)msg.obj;

                vendorOptionsManager = new VendorOptionsManager(id);

                detailsPagerAdapter.updateOptions(vendorOptionsManager.isPickupTime(), vendorOptionsManager.hasOptions());

                //Update Optional/Required labels
                updateDestinationReqs();

                //Enable/disable quote button depending on the pickupSite and booking options
                checkQuoteStateAndUpdate();

                if(pendingOrderOptions != null &amp;&amp; pendingOrderOptions.size() &gt; 0 &amp;&amp; vendorOptionsManager != null){                      
                    //Spinner is hidden and options are populated with new values
                    detailsPagerAdapter.updateOptionsView(VendorUtils.getReadableString(pendingOrderOptions,vendorOptionsManager.getAllOptions()), getResources().getColor(R.color.default_color_main));
                }

            }
            else if(msg.what == VendorCache.MALFORMED_ID || msg.what == VendorCache.REQUEST_FAILED){
                vendorOptionsManager = null;

                //Update Optional/Required labels
                updateDestinationReqs();



                //Enable quote button
                taskBar.setQuoteEnabled(true);

                //Disable any options
                detailsPagerAdapter.updateOptions(false, false);
            }

        }
    };
</code></pre>

<p>As you can see methods in handler change layout in views or fragment. Drawback is that I need to call the same methods with different params depending on the response. Similar situation occurs for other activity properties.</p>

<p>I am not saying that my activity is overloaded with views. I am saying that I have several properties that are interconnected. For example if property A=true and B= true then C="required" or if A=true and B = false then C = "optional" etc. Because of that I have a lot of calls to similar methods.</p>

<p>I am thinking of introducing ActivityStateController class which will implement Observer pattern. This will allow me to hide state management inside views and fragments. But I still doubt about that(e.g. what to do to show progress in views?)</p>

<p>What are the ways to manage complex activity state? Is there something similar to key value coding in Android or Java?</p>
