160 lines
5.1 KiB
Java
160 lines
5.1 KiB
Java
package com.twitter.sdk.android.tweetcomposer;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.ResolveInfo;
|
|
import android.net.Uri;
|
|
import android.text.TextUtils;
|
|
import com.twitter.sdk.android.core.GuestSessionProvider;
|
|
import com.twitter.sdk.android.core.Session;
|
|
import com.twitter.sdk.android.core.SessionManager;
|
|
import com.twitter.sdk.android.core.TwitterCore;
|
|
import com.twitter.sdk.android.core.TwitterSession;
|
|
import com.twitter.sdk.android.core.internal.scribe.DefaultScribeClient;
|
|
import io.fabric.sdk.android.Fabric;
|
|
import io.fabric.sdk.android.Kit;
|
|
import io.fabric.sdk.android.services.concurrency.DependsOn;
|
|
import io.fabric.sdk.android.services.network.UrlUtils;
|
|
import java.net.URL;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
@DependsOn({TwitterCore.class})
|
|
/* loaded from: classes.dex */
|
|
public class TweetComposer extends Kit<Void> {
|
|
String h;
|
|
SessionManager<TwitterSession> i;
|
|
GuestSessionProvider j;
|
|
private final ConcurrentHashMap<Session, ComposerApiClient> g = new ConcurrentHashMap<>();
|
|
private ScribeClient k = new ScribeClientImpl(null);
|
|
|
|
private static void r() {
|
|
if (Fabric.a(TweetComposer.class) == null) {
|
|
throw new IllegalStateException("Must start Twitter Kit with Fabric.with() first");
|
|
}
|
|
}
|
|
|
|
public static TweetComposer s() {
|
|
r();
|
|
return (TweetComposer) Fabric.a(TweetComposer.class);
|
|
}
|
|
|
|
public ComposerApiClient a(TwitterSession twitterSession) {
|
|
r();
|
|
if (!this.g.containsKey(twitterSession)) {
|
|
this.g.putIfAbsent(twitterSession, new ComposerApiClient(twitterSession));
|
|
}
|
|
return this.g.get(twitterSession);
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.Kit
|
|
public String g() {
|
|
return "com.twitter.sdk.android:tweet-composer";
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.Kit
|
|
public String i() {
|
|
return "2.3.1.165";
|
|
}
|
|
|
|
@Override // io.fabric.sdk.android.Kit
|
|
protected boolean o() {
|
|
this.i = TwitterCore.z().u();
|
|
this.j = TwitterCore.z().s();
|
|
return super.o();
|
|
}
|
|
|
|
String p() {
|
|
return this.h;
|
|
}
|
|
|
|
protected ScribeClient q() {
|
|
return this.k;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // io.fabric.sdk.android.Kit
|
|
public Void c() {
|
|
this.h = f().a();
|
|
this.k = new ScribeClientImpl(new DefaultScribeClient(this, "TweetComposer", this.i, this.j, f()));
|
|
return null;
|
|
}
|
|
|
|
public static class Builder {
|
|
private final Context a;
|
|
private String b;
|
|
private URL c;
|
|
private Uri d;
|
|
|
|
public Builder(Context context) {
|
|
if (context == null) {
|
|
throw new IllegalArgumentException("Context must not be null.");
|
|
}
|
|
this.a = context;
|
|
}
|
|
|
|
public Builder a(String str) {
|
|
if (str == null) {
|
|
throw new IllegalArgumentException("text must not be null.");
|
|
}
|
|
if (this.b != null) {
|
|
throw new IllegalStateException("text already set.");
|
|
}
|
|
this.b = str;
|
|
return this;
|
|
}
|
|
|
|
Intent b() {
|
|
Intent intent = new Intent("android.intent.action.SEND");
|
|
StringBuilder sb = new StringBuilder();
|
|
if (!TextUtils.isEmpty(this.b)) {
|
|
sb.append(this.b);
|
|
}
|
|
if (this.c != null) {
|
|
if (sb.length() > 0) {
|
|
sb.append(' ');
|
|
}
|
|
sb.append(this.c.toString());
|
|
}
|
|
intent.putExtra("android.intent.extra.TEXT", sb.toString());
|
|
intent.setType("text/plain");
|
|
Uri uri = this.d;
|
|
if (uri != null) {
|
|
intent.putExtra("android.intent.extra.STREAM", uri);
|
|
intent.setType("image/jpeg");
|
|
}
|
|
for (ResolveInfo resolveInfo : this.a.getPackageManager().queryIntentActivities(intent, 65536)) {
|
|
if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
|
|
intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
|
|
return intent;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Intent c() {
|
|
URL url = this.c;
|
|
return new Intent("android.intent.action.VIEW", Uri.parse(String.format("https://twitter.com/intent/tweet?text=%s&url=%s", UrlUtils.c(this.b), UrlUtils.c(url == null ? "" : url.toString()))));
|
|
}
|
|
|
|
public void d() {
|
|
this.a.startActivity(a());
|
|
}
|
|
|
|
public Builder a(Uri uri) {
|
|
if (uri != null) {
|
|
if (this.d == null) {
|
|
this.d = uri;
|
|
return this;
|
|
}
|
|
throw new IllegalStateException("imageUri already set.");
|
|
}
|
|
throw new IllegalArgumentException("imageUri must not be null.");
|
|
}
|
|
|
|
public Intent a() {
|
|
Intent b = b();
|
|
return b == null ? c() : b;
|
|
}
|
|
}
|
|
}
|