153 lines
5.9 KiB
Java
153 lines
5.9 KiB
Java
package com.twitter.sdk.android.tweetcomposer;
|
|
|
|
import android.app.IntentService;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import com.twitter.sdk.android.core.Callback;
|
|
import com.twitter.sdk.android.core.Result;
|
|
import com.twitter.sdk.android.core.TwitterAuthToken;
|
|
import com.twitter.sdk.android.core.TwitterException;
|
|
import com.twitter.sdk.android.core.TwitterSession;
|
|
import com.twitter.sdk.android.core.models.Media;
|
|
import com.twitter.sdk.android.core.models.Tweet;
|
|
import com.twitter.sdk.android.tweetcomposer.internal.CardCreate;
|
|
import io.fabric.sdk.android.Fabric;
|
|
import java.io.File;
|
|
import okhttp3.MediaType;
|
|
import okhttp3.RequestBody;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class TweetUploadService extends IntentService {
|
|
DependencyProvider a;
|
|
TwitterSession b;
|
|
String c;
|
|
Card d;
|
|
Intent e;
|
|
|
|
static class DependencyProvider {
|
|
DependencyProvider() {
|
|
}
|
|
|
|
ComposerApiClient a(TwitterSession twitterSession) {
|
|
return TweetComposer.s().a(twitterSession);
|
|
}
|
|
|
|
String a() {
|
|
return TweetComposer.s().p();
|
|
}
|
|
}
|
|
|
|
public TweetUploadService() {
|
|
this(new DependencyProvider());
|
|
}
|
|
|
|
void a(TwitterSession twitterSession, String str) {
|
|
this.a.a(twitterSession).e().update(str, null).enqueue(new Callback<Tweet>() { // from class: com.twitter.sdk.android.tweetcomposer.TweetUploadService.1
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(Result<Tweet> result) {
|
|
TweetUploadService.this.a(result.a.a());
|
|
TweetUploadService.this.stopSelf();
|
|
}
|
|
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(TwitterException twitterException) {
|
|
TweetUploadService.this.a(twitterException);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // android.app.IntentService
|
|
protected void onHandleIntent(Intent intent) {
|
|
TwitterAuthToken twitterAuthToken = (TwitterAuthToken) intent.getParcelableExtra("EXTRA_USER_TOKEN");
|
|
this.e = intent;
|
|
this.b = new TwitterSession(twitterAuthToken, -1L, "");
|
|
this.c = intent.getStringExtra("EXTRA_TWEET_TEXT");
|
|
this.d = (Card) intent.getSerializableExtra("EXTRA_TWEET_CARD");
|
|
if (Card.isAppCard(this.d)) {
|
|
a(this.b, this.c, this.d);
|
|
} else {
|
|
a(this.b, this.c);
|
|
}
|
|
}
|
|
|
|
/* renamed from: com.twitter.sdk.android.tweetcomposer.TweetUploadService$2, reason: invalid class name */
|
|
class AnonymousClass2 extends Callback<Media> {
|
|
final /* synthetic */ Card a;
|
|
final /* synthetic */ ComposerApiClient b;
|
|
final /* synthetic */ String c;
|
|
|
|
AnonymousClass2(Card card, ComposerApiClient composerApiClient, String str) {
|
|
this.a = card;
|
|
this.b = composerApiClient;
|
|
this.c = str;
|
|
}
|
|
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(Result<Media> result) {
|
|
this.b.d().create(CardDataFactory.a(this.a, Long.valueOf(result.a.a), TweetUploadService.this.a.a())).enqueue(new Callback<CardCreate>() { // from class: com.twitter.sdk.android.tweetcomposer.TweetUploadService.2.1
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(Result<CardCreate> result2) {
|
|
AnonymousClass2.this.b.e().update(AnonymousClass2.this.c, result2.a.a).enqueue(new Callback<Tweet>() { // from class: com.twitter.sdk.android.tweetcomposer.TweetUploadService.2.1.1
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(Result<Tweet> result3) {
|
|
TweetUploadService.this.a(result3.a.a());
|
|
TweetUploadService.this.stopSelf();
|
|
}
|
|
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(TwitterException twitterException) {
|
|
TweetUploadService.this.a(twitterException);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(TwitterException twitterException) {
|
|
TweetUploadService.this.a(twitterException);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // com.twitter.sdk.android.core.Callback
|
|
public void a(TwitterException twitterException) {
|
|
TweetUploadService.this.a(twitterException);
|
|
}
|
|
}
|
|
|
|
TweetUploadService(DependencyProvider dependencyProvider) {
|
|
super("TweetUploadService");
|
|
this.a = dependencyProvider;
|
|
}
|
|
|
|
void a(TwitterSession twitterSession, String str, Card card) {
|
|
ComposerApiClient a = this.a.a(twitterSession);
|
|
String a2 = FileUtils.a(this, Uri.parse(card.imageUri));
|
|
if (a2 == null) {
|
|
a(new TwitterException("Uri file path resolved to null"));
|
|
return;
|
|
}
|
|
File file = new File(a2);
|
|
a.c().upload(RequestBody.create(MediaType.parse(FileUtils.a(file)), file), null, null).enqueue(new AnonymousClass2(card, a, str));
|
|
}
|
|
|
|
void a(TwitterException twitterException) {
|
|
a(this.e);
|
|
Fabric.g().b("TweetUploadService", "Post Tweet failed", twitterException);
|
|
stopSelf();
|
|
}
|
|
|
|
void a(long j) {
|
|
Intent intent = new Intent("com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS");
|
|
intent.putExtra("EXTRA_TWEET_ID", j);
|
|
intent.setPackage(getApplicationContext().getPackageName());
|
|
sendBroadcast(intent);
|
|
}
|
|
|
|
void a(Intent intent) {
|
|
Intent intent2 = new Intent("com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE");
|
|
intent2.putExtra("EXTRA_RETRY_INTENT", intent);
|
|
intent2.setPackage(getApplicationContext().getPackageName());
|
|
sendBroadcast(intent2);
|
|
}
|
|
}
|