fixed activity object

This commit is contained in:
Mariotaku Lee 2016-05-14 20:26:44 +08:00
parent af79ff0255
commit ec126ecfff
6 changed files with 92 additions and 99 deletions

View File

@ -65,12 +65,14 @@ public class Activity extends TwitterResponseObject implements TwitterResponse,
User[] sources;
@JsonField(name = "targets", typeConverter = JsonStringConverter.class)
String rawTargets;
@JsonField(name = "sources", typeConverter = JsonStringConverter.class)
@JsonField(name = "target_objects", typeConverter = JsonStringConverter.class)
String rawTargetObjects;
User[] targetUsers;
User[] targetObjectUsers;
Status[] targetObjectStatuses, targetStatuses;
UserList[] targetUserLists, targetObjectUserLists;
@JsonField(name = "max_position")
String maxPosition = null;
@JsonField(name = "min_position")
@ -182,7 +184,7 @@ public class Activity extends TwitterResponseObject implements TwitterResponse,
@OnJsonParseComplete
void onParseComplete() throws IOException {
if (action == null) throw new IOException();
if (action == null) throw new IOException("Malformed Activity object");
switch (action) {
case Activity.Action.FAVORITE:
case Activity.Action.REPLY:

View File

@ -49,6 +49,7 @@ public interface IntentConstants {
String INTENT_ACTION_COMPOSE_PICK_IMAGE = INTENT_PACKAGE_PREFIX + "COMPOSE_PICK_IMAGE";
String INTENT_ACTION_HIDDEN_SETTINGS_ENTRY = INTENT_PACKAGE_PREFIX + "HIDDEN_SETTINGS_ENTRY";
String INTENT_ACTION_EMOJI_SUPPORT_ABOUT = INTENT_PACKAGE_PREFIX + "EMOJI_SUPPORT_ABOUT";
String INTENT_ACTION_PLUS_SERVICE_SIGN_IN = INTENT_PACKAGE_PREFIX + "PLUS_SERVICE_SIGN_IN";
String INTENT_ACTION_EXTENSION_EDIT_IMAGE = INTENT_PACKAGE_PREFIX + "EXTENSION_EDIT_IMAGE";
String INTENT_ACTION_EXTENSION_UPLOAD = INTENT_PACKAGE_PREFIX + "EXTENSION_UPLOAD";

View File

@ -16,5 +16,14 @@
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCVdCIMFFxdNqHnCPrJ9yKUzoTfs8jhYGc"/>
<activity
android:name="org.mariotaku.twidere.activity.PlusServiceGoogleSignInActivity"
android:exported="false"
android:theme="@style/Theme.Twidere.NoDisplay">
<intent-filter>
<action android:name="org.mariotaku.twidere.PLUS_SERVICE_SIGN_IN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,77 @@
package org.mariotaku.twidere.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
/**
* Created by mariotaku on 16/5/14.
*/
public class PlusServiceGoogleSignInActivity extends BaseActivity implements
GoogleApiClient.OnConnectionFailedListener {
private static final int REQUEST_GOOGLE_SIGN_IN = 101;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(GOOGLE_APIS_SERVER_CLIENT_ID)
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
signInWithGoogle();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == REQUEST_GOOGLE_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
private void signInWithGoogle() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, REQUEST_GOOGLE_SIGN_IN);
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d(LOGTAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// TODO Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
acct.getIdToken();
Log.d(LOGTAG, "sign in name:" + acct.getDisplayName());
} else {
// TODO Signed out, show unauthenticated UI.
}
}
}

View File

@ -1,98 +1,8 @@
package org.mariotaku.twidere.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import org.mariotaku.twidere.R;
/**
* Created by mariotaku on 16/5/11.
*/
public class PlusServiceSignInActivity extends BaseActivity implements GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {
private static final int REQUEST_GOOGLE_SIGN_IN = 101;
private GoogleApiClient mGoogleApiClient;
private View mGoogleSignInButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plus_service_sign_in);
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(GOOGLE_APIS_SERVER_CLIENT_ID)
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleSignInButton.setOnClickListener(this);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == REQUEST_GOOGLE_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
@Override
public void onContentChanged() {
super.onContentChanged();
mGoogleSignInButton = findViewById(R.id.google_sign_in);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.google_sign_in: {
signInWithGoogle();
break;
}
}
}
private void signInWithGoogle() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, REQUEST_GOOGLE_SIGN_IN);
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d(LOGTAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// TODO Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
acct.getIdToken();
Log.d(LOGTAG, "sign in name:" + acct.getDisplayName());
} else {
// TODO Signed out, show unauthenticated UI.
}
}
public class PlusServiceSignInActivity extends BaseActivity {
}

View File

@ -4,10 +4,4 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.common.SignInButton
android:id="@+id/google_sign_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>