Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ShareOption.java « sharing « util « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 77b72bac16175ff5fb3a133e908f6d03755b0871 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.mapswithme.util.sharing;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;

import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.BookmarkInfo;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.widget.placepage.Sponsored;
import com.mapswithme.util.Utils;

public abstract class ShareOption
{
  @StringRes
  private final int mNameResId;
  @NonNull
  private final Intent mBaseIntent;

  ShareOption(int nameResId, @NonNull Intent baseIntent)
  {
    mNameResId = nameResId;
    mBaseIntent = baseIntent;
  }

  public boolean isSupported(Context context)
  {
    return Utils.isIntentSupported(context, mBaseIntent);
  }

  public void shareMapObject(Activity activity, @NonNull MapObject mapObject, @Nullable Sponsored sponsored)
  {
    MapObjectShareable mapObjectShareable = new MapObjectShareable(activity, mapObject, sponsored);
    shareObjectInternal(mapObjectShareable);
  }

  public void shareBookmarkObject(Activity activity, @NonNull BookmarkInfo mapObject,
                                  @Nullable Sponsored sponsored)
  {
    BookmarkInfoShareable<BookmarkInfo> shareable =
        new BookmarkInfoShareable<>(activity, mapObject, sponsored);
    shareObjectInternal(shareable);
  }

  private void shareObjectInternal(@NonNull BaseShareable shareable)
  {
    SharingHelper.shareOutside(shareable
                                   .setBaseIntent(new Intent(mBaseIntent)), mNameResId);
  }

  public static class EmailShareOption extends ShareOption
  {
    protected EmailShareOption()
    {
      super(R.string.share_by_email, new Intent(Intent.ACTION_SEND).setType(TargetUtils.TYPE_MESSAGE_RFC822));
    }
  }

  public static class AnyShareOption extends ShareOption
  {
    public static final AnyShareOption ANY = new AnyShareOption();

    AnyShareOption()
    {
      super(R.string.share, new Intent(Intent.ACTION_SEND).setType(TargetUtils.TYPE_TEXT_PLAIN));
    }

    public void share(Activity activity, String body)
    {
      SharingHelper.shareOutside(new TextShareable(activity, body));
    }

    public void share(Activity activity, String body, @StringRes int titleRes)
    {
      SharingHelper.shareOutside(new TextShareable(activity, body), titleRes);
    }
  }
}