blob: 5ccfdcf5db66224c4aeefd99ec7b367812b2a2cc (
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package com.mapswithme.util.sharing;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import com.mapswithme.util.statistics.AlohaHelper;
abstract class BaseShareable
{
private final Activity mActivity;
protected Intent mBaseIntent;
protected String mText;
protected String mSubject;
public BaseShareable(Activity activity)
{
mActivity = activity;
mBaseIntent = new Intent(Intent.ACTION_SEND);
}
public Activity getActivity()
{
return mActivity;
}
protected void modifyIntent(Intent intent, @Nullable SharingTarget target) {}
protected Intent getBaseIntent()
{
return mBaseIntent;
}
public Intent getTargetIntent(@Nullable SharingTarget target)
{
Intent res = getBaseIntent();
if (!TextUtils.isEmpty(mText))
res.putExtra(Intent.EXTRA_TEXT, mText);
if (!TextUtils.isEmpty(mSubject))
res.putExtra(Intent.EXTRA_SUBJECT, mSubject);
String mime = getMimeType();
if (!TextUtils.isEmpty(mime))
res.setType(mime);
modifyIntent(res, target);
return res;
}
public void share(SharingTarget target)
{
Intent intent = getTargetIntent(target);
target.setupComponentName(intent);
try
{
mActivity.startActivity(intent);
} catch (ActivityNotFoundException ignored)
{
AlohaHelper.logException(ignored);
}
}
public BaseShareable setBaseIntent(Intent intent)
{
mBaseIntent = intent;
return this;
}
public BaseShareable setText(String text)
{
mText = text;
return this;
}
public BaseShareable setSubject(String subject)
{
mSubject = subject;
return this;
}
public BaseShareable setText(@StringRes int textRes)
{
mText = getActivity().getString(textRes);
return this;
}
public BaseShareable setSubject(@StringRes int subjectRes)
{
mSubject = getActivity().getString(subjectRes);
return this;
}
public abstract String getMimeType();
}
|