Suggested change to RunFragment.updateUI()


#1

The existing code has behavior that seems unexpected to me:

[ul]1. Create a new run through the menu in RunListFragment.
2. Start the run.
3. Press the back button to return to RunListFragment.
4. Create a new run through the menu in RunListFragment.
5. The new run’s start and stop button are both disabled. This surprised me.
6. Press the back button to return to RunListFragment.
7. Only the first run shows up on the list. This surprised me.[/ul]

The surprising behavior occurs because of the following lines in RunFragment.updateUI():

        boolean started = mRunManager.isTrackingRun();
        mStartButton.setEnabled(!started);

Because the first run is being tracked, the start button does not show up for the new run. Hence the click listener that calls mRunManager.startNewRun() is never called.

The behavior I expected was that creating a new run would stop the current run. This could be addressed by either:
[ul]
[li] Disabling the menu when a run is in progress.[/li]
[li] Stopping any run in progress when a new run is created.[/li][/ul]

I chose the latter and added four lines to the beginning of RunFragment.updateUI():

private void updatUI() {
        // If another run is in progress and the user starts a new run,
        // stop the existing run before creating the new one.
        if (mRunManager.isTrackingRun() && mRun == null) {
            mRunManager.stopRun();
        }

I’d be curious what others think.