mobile/android/base/home/HomeConfigLoader.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial