summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/overlays/service/ShareData.java
blob: df233d74a0bcd63fe10a979ff6197c82285085eb (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.overlays.service;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import org.mozilla.gecko.overlays.OverlayConstants;
import org.mozilla.gecko.overlays.service.sharemethods.ShareMethod;

import static org.mozilla.gecko.overlays.OverlayConstants.EXTRA_SHARE_METHOD;

/**
 * Class to hold information related to a particular request to perform a share.
 */
public class ShareData {
    private static final String LOGTAG = "GeckoShareRequest";

    public final String url;
    public final String title;
    public final Parcelable extra;
    public final ShareMethod.Type shareMethodType;

    public ShareData(String url, String title, Parcelable extra, ShareMethod.Type shareMethodType) {
        if (url == null) {
            throw new IllegalArgumentException("Null url passed to ShareData!");
        }

        this.url = url;
        this.title = title;
        this.extra = extra;
        this.shareMethodType = shareMethodType;
    }

    public static ShareData fromIntent(Intent intent) {
        Bundle extras = intent.getExtras();

        // Fish the parameters out of the Intent.
        final String url = extras.getString(OverlayConstants.EXTRA_URL);
        final String title = extras.getString(OverlayConstants.EXTRA_TITLE);
        final Parcelable extra = extras.getParcelable(OverlayConstants.EXTRA_PARAMETERS);
        ShareMethod.Type shareMethodType = (ShareMethod.Type) extras.get(EXTRA_SHARE_METHOD);

        return new ShareData(url, title, extra, shareMethodType);
    }
}