aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java
blob: 568119ee0e4a42a2aa76ba6bf40ebfca97f1a666 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package cgeo.geocaching.ui;

import cgeo.geocaching.activity.AbstractViewPagerActivity.PageViewCreator;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import android.os.Bundle;
import android.view.View;

/**
 * View creator which destroys the created view on every {@link #notifyDataSetChanged()}.
 *
 * @param <ViewClass>
 */
public abstract class AbstractCachingPageViewCreator<ViewClass extends View> implements PageViewCreator {

    public ViewClass view;

    @Override
    public final void notifyDataSetChanged() {
        view = null;
    }

    @Override
    public final View getView() {
        if (view == null) {
            view = getDispatchedView();
        }

        return view;
    }

    @Override
    @SuppressFBWarnings("USM_USELESS_ABSTRACT_METHOD")
    public abstract ViewClass getDispatchedView();

    /**
     * Gets the state of the view but returns an empty state if not overridden
     *
     * @return empty bundle
     */
    @Override
    public Bundle getViewState() {
        return new Bundle();
    }

    /**
     * Restores the state of the view but just returns if not overridden.
     */
    @Override
    public void setViewState(Bundle state) {
        return;
    }
}