mobile/android/base/home/HomeConfigLoader.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko.home;
     8 import org.mozilla.gecko.home.HomeConfig.PanelConfig;
     9 import org.mozilla.gecko.home.HomeConfig.OnReloadListener;
    11 import android.content.Context;
    12 import android.support.v4.content.AsyncTaskLoader;
    14 import java.util.List;
    16 public class HomeConfigLoader extends AsyncTaskLoader<HomeConfig.State> {
    17     private final HomeConfig mConfig;
    18     private HomeConfig.State mConfigState;
    20     private final Context mContext;
    22     public HomeConfigLoader(Context context, HomeConfig homeConfig) {
    23         super(context);
    24         mContext = context;
    25         mConfig = homeConfig;
    26     }
    28     @Override
    29     public HomeConfig.State loadInBackground() {
    30         return mConfig.load();
    31     }
    33     @Override
    34     public void deliverResult(HomeConfig.State configState) {
    35         if (isReset()) {
    36             mConfigState = null;
    37             return;
    38         }
    40         mConfigState = configState;
    41         mConfig.setOnReloadListener(new ForceReloadListener());
    43         if (isStarted()) {
    44             super.deliverResult(configState);
    45         }
    46     }
    48     @Override
    49     protected void onStartLoading() {
    50         if (mConfigState != null) {
    51             deliverResult(mConfigState);
    52         }
    54         if (takeContentChanged() || mConfigState == null) {
    55             forceLoad();
    56         }
    57     }
    59     @Override
    60     protected void onStopLoading() {
    61         cancelLoad();
    62     }
    64     @Override
    65     public void onCanceled(HomeConfig.State configState) {
    66         mConfigState = null;
    67     }
    69     @Override
    70     protected void onReset() {
    71         super.onReset();
    73         // Ensure the loader is stopped.
    74         onStopLoading();
    76         mConfigState = null;
    77         mConfig.setOnReloadListener(null);
    78     }
    80     private class ForceReloadListener implements OnReloadListener {
    81         @Override
    82         public void onReload() {
    83             onContentChanged();
    84         }
    85     }
    86 }

mercurial