本文整理汇总了Java中io.plaidapp.data.api.designernews.model.Story.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Story.Builder方法的具体用法?Java Story.Builder怎么用?Java Story.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.plaidapp.data.api.designernews.model.Story
的用法示例。
在下文中一共展示了Story.Builder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHandleIntent
import io.plaidapp.data.api.designernews.model.Story; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) return;
if (ACTION_POST_NEW_STORY.equals(intent.getAction())) {
final boolean broadcastResult = intent.getBooleanExtra(EXTRA_BROADCAST_RESULT, false);
final DesignerNewsPrefs designerNewsPrefs = DesignerNewsPrefs.get(this);
if (!designerNewsPrefs.isLoggedIn()) return; // shouldn't happen...
final String title = intent.getStringExtra(EXTRA_STORY_TITLE);
final String url = intent.getStringExtra(EXTRA_STORY_URL);
final String comment = intent.getStringExtra(EXTRA_STORY_COMMENT);
if (TextUtils.isEmpty(title)) return;
NewStoryRequest storyToPost = null;
if (!TextUtils.isEmpty(url)) {
storyToPost = NewStoryRequest.createWithUrl(title, url);
} else if (!TextUtils.isEmpty(comment)) {
storyToPost = NewStoryRequest.createWithComment(title, comment);
}
if (storyToPost == null) return;
final Call<StoriesResponse> postStoryCall =
designerNewsPrefs.getApi().postStory(storyToPost);
try {
final Response<StoriesResponse> response = postStoryCall.execute();
final StoriesResponse story = response.body();
if (story != null && story.stories != null && !story.stories.isEmpty()) {
if (broadcastResult) {
final Intent success = new Intent(BROADCAST_ACTION_SUCCESS);
// API doesn't fill in author details so add them here
final Story returnedStory = story.stories.get(0);
final Story.Builder builder = Story.Builder.from(returnedStory)
.setUserId(designerNewsPrefs.getUserId())
.setUserDisplayName(designerNewsPrefs.getUserName())
.setUserPortraitUrl(designerNewsPrefs.getUserAvatar());
// API doesn't add a self URL, so potentially add one for consistency
if (TextUtils.isEmpty(returnedStory.url)) {
builder.setDefaultUrl(returnedStory.id);
}
final Story newStory = builder.build();
newStory.dataSource = SOURCE_NEW_DN_POST;
success.putExtra(EXTRA_NEW_STORY, newStory);
LocalBroadcastManager.getInstance(getApplicationContext())
.sendBroadcast(success);
} else {
Toast.makeText(getApplicationContext(), "Story posted",
Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
final String reason = e.getMessage();
if (broadcastResult) {
final Intent failure = new Intent(BROADCAST_ACTION_FAILURE);
failure.putExtra(BROADCAST_ACTION_FAILURE_REASON, reason);
LocalBroadcastManager.getInstance(getApplicationContext())
.sendBroadcast(failure);
} else {
Toast.makeText(getApplicationContext(), reason, Toast.LENGTH_SHORT).show();
}
}
}
}
示例2: onHandleIntent
import io.plaidapp.data.api.designernews.model.Story; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) return;
if (ACTION_POST_NEW_STORY.equals(intent.getAction())) {
final boolean broadcastResult = intent.getBooleanExtra(EXTRA_BROADCAST_RESULT, false);
final DesignerNewsPrefs designerNewsPrefs = DesignerNewsPrefs.get(this);
if (!designerNewsPrefs.isLoggedIn()) return; // shouldn't happen...
final String title = intent.getStringExtra(EXTRA_STORY_TITLE);
final String url = intent.getStringExtra(EXTRA_STORY_URL);
final String comment = intent.getStringExtra(EXTRA_STORY_COMMENT);
if (TextUtils.isEmpty(title)) return;
NewStoryRequest storyToPost = null;
if (!TextUtils.isEmpty(url)) {
storyToPost = NewStoryRequest.createWithUrl(title, url);
} else if (!TextUtils.isEmpty(comment)) {
storyToPost = NewStoryRequest.createWithComment(title, comment);
}
if (storyToPost == null) return;
final Call<List<Story>> postStoryCall =
designerNewsPrefs.getApi().postStory(storyToPost);
try {
final Response<List<Story>> response = postStoryCall.execute();
final List<Story> stories = response.body();
if (stories != null && !stories.isEmpty()) {
if (broadcastResult) {
final Intent success = new Intent(BROADCAST_ACTION_SUCCESS);
// API doesn't fill in author details so add them here
final Story returnedStory = stories.get(0);
final Story.Builder builder = Story.Builder.from(returnedStory)
.setUserId(designerNewsPrefs.getUserId())
.setUserDisplayName(designerNewsPrefs.getUserName())
.setUserPortraitUrl(designerNewsPrefs.getUserAvatar());
// API doesn't add a self URL, so potentially add one for consistency
if (TextUtils.isEmpty(returnedStory.url)) {
builder.setDefaultUrl(returnedStory.id);
}
final Story newStory = builder.build();
newStory.dataSource = SOURCE_NEW_DN_POST;
success.putExtra(EXTRA_NEW_STORY, newStory);
LocalBroadcastManager.getInstance(getApplicationContext())
.sendBroadcast(success);
} else {
Toast.makeText(getApplicationContext(), "Story posted",
Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
final String reason = e.getMessage();
if (broadcastResult) {
final Intent failure = new Intent(BROADCAST_ACTION_FAILURE);
failure.putExtra(BROADCAST_ACTION_FAILURE_REASON, reason);
LocalBroadcastManager.getInstance(getApplicationContext())
.sendBroadcast(failure);
} else {
Toast.makeText(getApplicationContext(), reason, Toast.LENGTH_SHORT).show();
}
}
}
}