From ec126ecfff1e75b6b6e28538cb6c4fdd01d0953c Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sat, 14 May 2016 20:26:44 +0800 Subject: [PATCH] fixed activity object --- .../library/twitter/model/Activity.java | 6 +- .../twidere/constant/IntentConstants.java | 1 + twidere/src/google/AndroidManifest.xml | 9 ++ .../PlusServiceGoogleSignInActivity.java | 77 ++++++++++++++++ .../activity/PlusServiceSignInActivity.java | 92 +------------------ .../layout/activity_plus_service_sign_in.xml | 6 -- 6 files changed, 92 insertions(+), 99 deletions(-) create mode 100644 twidere/src/google/java/org/mariotaku/twidere/activity/PlusServiceGoogleSignInActivity.java diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Activity.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Activity.java index 45d5f7c41..04a303dbf 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Activity.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Activity.java @@ -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: diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index eee5c7c2c..892167cf5 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -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"; diff --git a/twidere/src/google/AndroidManifest.xml b/twidere/src/google/AndroidManifest.xml index 6787aeef2..e4fa3380b 100644 --- a/twidere/src/google/AndroidManifest.xml +++ b/twidere/src/google/AndroidManifest.xml @@ -16,5 +16,14 @@ android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCVdCIMFFxdNqHnCPrJ9yKUzoTfs8jhYGc"/> + + + + + + \ No newline at end of file diff --git a/twidere/src/google/java/org/mariotaku/twidere/activity/PlusServiceGoogleSignInActivity.java b/twidere/src/google/java/org/mariotaku/twidere/activity/PlusServiceGoogleSignInActivity.java new file mode 100644 index 000000000..4abb392b0 --- /dev/null +++ b/twidere/src/google/java/org/mariotaku/twidere/activity/PlusServiceGoogleSignInActivity.java @@ -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. + } + } + +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/PlusServiceSignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/PlusServiceSignInActivity.java index f56484b5a..781fdf81d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/PlusServiceSignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/PlusServiceSignInActivity.java @@ -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 { } diff --git a/twidere/src/main/res/layout/activity_plus_service_sign_in.xml b/twidere/src/main/res/layout/activity_plus_service_sign_in.xml index 063aebe4f..4d879559d 100644 --- a/twidere/src/main/res/layout/activity_plus_service_sign_in.xml +++ b/twidere/src/main/res/layout/activity_plus_service_sign_in.xml @@ -4,10 +4,4 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - \ No newline at end of file