mobile/android/base/background/db/Tab.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.background.db;
     7 import org.json.simple.JSONArray;
     8 import org.mozilla.gecko.db.BrowserContract;
     9 import org.mozilla.gecko.db.BrowserContract.Tabs;
    10 import org.mozilla.gecko.sync.Utils;
    11 import org.mozilla.gecko.sync.repositories.android.RepoUtils;
    13 import android.content.ContentValues;
    14 import android.database.Cursor;
    16 // Immutable.
    17 public class Tab {
    18   public final String    title;
    19   public final String    icon;
    20   public final JSONArray history;
    21   public final long      lastUsed;
    23   public Tab(String title, String icon, JSONArray history, long lastUsed) {
    24     this.title    = title;
    25     this.icon     = icon;
    26     this.history  = history;
    27     this.lastUsed = lastUsed;
    28   }
    30   public ContentValues toContentValues(String clientGUID, int position) {
    31     ContentValues out = new ContentValues();
    32     out.put(BrowserContract.Tabs.POSITION,    position);
    33     out.put(BrowserContract.Tabs.CLIENT_GUID, clientGUID);
    35     out.put(BrowserContract.Tabs.FAVICON,   this.icon);
    36     out.put(BrowserContract.Tabs.LAST_USED, this.lastUsed);
    37     out.put(BrowserContract.Tabs.TITLE,     this.title);
    38     out.put(BrowserContract.Tabs.URL,       (String) this.history.get(0));
    39     out.put(BrowserContract.Tabs.HISTORY,   this.history.toJSONString());
    40     return out;
    41   }
    43   @Override
    44   public boolean equals(Object o) {
    45     if (!(o instanceof Tab)) {
    46       return false;
    47     }
    48     final Tab other = (Tab) o;
    50     if (!RepoUtils.stringsEqual(this.title, other.title)) {
    51       return false;
    52     }
    53     if (!RepoUtils.stringsEqual(this.icon, other.icon)) {
    54       return false;
    55     }
    57     if (!(this.lastUsed == other.lastUsed)) {
    58       return false;
    59     }
    61     return Utils.sameArrays(this.history, other.history);
    62   }
    64   /**
    65    * Extract a <code>Tab</code> from a cursor row.
    66    * <p>
    67    * Caller is responsible for creating, positioning, and closing the cursor.
    68    *
    69    * @param cursor
    70    *          to inspect.
    71    * @return <code>Tab</code> instance.
    72    */
    73   public static Tab fromCursor(final Cursor cursor) {
    74     final String title = RepoUtils.getStringFromCursor(cursor, Tabs.TITLE);
    75     final String icon = RepoUtils.getStringFromCursor(cursor, Tabs.FAVICON);
    76     final JSONArray history = RepoUtils.getJSONArrayFromCursor(cursor, Tabs.HISTORY);
    77     final long lastUsed = RepoUtils.getLongFromCursor(cursor, Tabs.LAST_USED);
    79     return new Tab(title, icon, history, lastUsed);
    80   }
    81 }

mercurial