Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/share/ShareParams.java

Issue 2917703004: [Android] Wrap all share parameters into the ShareParams class (Closed)
Patch Set: Update based on Ted and Yusuf's comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 package org.chromium.chrome.browser.share;
5
6 import android.app.Activity;
7 import android.net.Uri;
8 import android.support.annotation.Nullable;
9
10 import org.chromium.chrome.browser.share.ShareHelper.TargetChosenCallback;
11
12 /**
13 * A container object for passing share parameters to {@link ShareHelper}.
14 */
15 public class ShareParams {
16 /**
17 * Whether it should share directly with the activity that was most recently used to share.
18 */
19 private final boolean mShareDirectly;
20
21 /** Whether to save the chosen activity for future direct sharing. */
22 private final boolean mSaveLastUsed;
23
24 /** The activity that is used to access package manager. */
25 private final Activity mActivity;
26
27 /** The title of the page to be shared. */
28 private final String mTitle;
29
30 /**
31 * The text to be shared. If both |text| and |url| are supplied, they are co ncatenated with a
32 * space.
33 */
34 private final String mText;
35
36 /** The URL of the page to be shared. */
37 private final String mUrl;
38
39 /** The Uri to the offline MHTML file to be shared. */
40 private final Uri mOfflineUri;
41
42 /** The Uri of the screenshot of the page to be shared. */
43 private final Uri mScreenshotUri;
44
45 /**
46 * Optional callback to be called when user makes a choice. Will not be call ed if receiving a
47 * response when the user makes a choice is not supported (on older Android versions).
48 */
49 private final TargetChosenCallback mCallback;
50
51 private ShareParams(boolean shareDirectly, boolean saveLastUsed, Activity ac tivity,
52 String title, String text, String url, @Nullable Uri offlineUri,
Yusuf 2017/06/02 20:07:47 These Nullables would actually help in the builder
ltian 2017/06/02 23:44:39 Done.
53 @Nullable Uri screenshotUri, @Nullable TargetChosenCallback callback ) {
54 mShareDirectly = shareDirectly;
55 mSaveLastUsed = saveLastUsed;
56 mActivity = activity;
57 mTitle = title;
58 mText = text;
59 mUrl = url;
60 mOfflineUri = offlineUri;
61 mScreenshotUri = screenshotUri;
62 mCallback = callback;
63 }
64
65 /**
66 * @return Whether it should share directly with the activity that was most recently used to
67 * share.
68 */
69 public boolean isShareDirectly() {
70 return mShareDirectly;
71 }
72
73 /**
74 * @return Whether to save the chosen activity for future direct sharing.
75 */
76 public boolean isSaveLastUsed() {
77 return mSaveLastUsed;
78 }
79
80 /**
81 * @return The activity that is used to access package manager.
82 */
83 public Activity getActivity() {
84 return mActivity;
85 }
86
87 /**
88 * @return The title of the page to be shared.
89 */
90 public String getTitle() {
91 return mTitle;
92 }
93
94 /**
95 * @return The text to be shared.
96 */
97 public String getText() {
98 return mText;
99 }
100
101 /**
102 * @return The URL of the page to be shared.
103 */
104 public String getUrl() {
105 return mUrl;
106 }
107
108 /**
109 * @return The Uri to the offline MHTML file to be shared.
110 */
111 @Nullable
112 public Uri getOfflineUri() {
113 return mOfflineUri;
114 }
115
116 /**
117 * @return The Uri of the screenshot of the page to be shared.
118 */
119 @Nullable
120 public Uri getScreenshotUri() {
121 return mScreenshotUri;
122 }
123
124 /**
125 * @return The callback to be called when user makes a choice.
126 */
127 @Nullable
128 public TargetChosenCallback getCallback() {
129 return mCallback;
130 }
131
132 /** The builder for {@link ShareParams} objects. */
133 public static class Builder {
134 private boolean mShareDirectly;
135 private boolean mSaveLastUsed;
136 private Activity mActivity;
137 private String mTitle;
138 private String mText;
139 private String mUrl;
140 private Uri mOfflineUri;
141 private Uri mScreenshotUri;
142 private TargetChosenCallback mCallback;
143
144 public Builder(Activity activity, String title, String url) {
145 mActivity = activity;
146 mUrl = url;
147 mTitle = title;
148 }
149
150 /**
151 * Sets the text to be shared.
152 */
153 public Builder setText(String text) {
154 mText = text;
155 return this;
156 }
157
158 /**
159 * Sets whether it should share directly with the activity that was most recently used to
160 * share.
161 */
162 public Builder setShareDirectly(boolean shareDirectly) {
163 mShareDirectly = shareDirectly;
164 assert !(mShareDirectly & mSaveLastUsed);
165 return this;
166 }
167
168 /**
169 * Sets whether to save the chosen activity for future direct sharing.
170 */
171 public Builder setSaveLastUsed(boolean saveLastUsed) {
172 mSaveLastUsed = saveLastUsed;
173 return this;
174 }
175
176 /**
177 * Sets the URL of the page to be shared.
178 */
179 public Builder setUrl(String url) {
180 mUrl = url;
181 return this;
182 }
183
184 /**
185 * Sets the Uri of the offline MHTML file to be shared.
186 */
187 public Builder setOfflineUri(Uri offlineUri) {
188 mOfflineUri = offlineUri;
189 return this;
190 }
191
192 /**
193 * Sets the Uri of the screenshot of the page to be shared.
194 */
195 public Builder setScreenshotUri(Uri screenshotUri) {
196 mScreenshotUri = screenshotUri;
197 return this;
198 }
199
200 /**
201 * Sets the callback to be called when user makes a choice.
202 */
203 public Builder setCallback(TargetChosenCallback callback) {
204 mCallback = callback;
205 return this;
206 }
207
208 /** @return A fully constructed {@link ShareParams} object. */
209 public ShareParams build() {
210 if (mShareDirectly) {
Yusuf 2017/06/02 20:07:46 one line!
ltian 2017/06/02 23:44:39 Done.
211 assert !mSaveLastUsed;
212 }
213 return new ShareParams(mShareDirectly, mSaveLastUsed, mActivity, mTi tle, mText, mUrl,
214 mOfflineUri, mScreenshotUri, mCallback);
215 }
216 }
217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698