Skip to content

Commit

Permalink
Google Auth Helper (#77)
Browse files Browse the repository at this point in the history
* renamed NianticEventListener to just Listener.

* adds providing a custom google auth token to the NianticManager.

* Adds some missing imports.

* Updates minify enabled true for release builds.

* Bug Fix.
  • Loading branch information
comann authored and omkarmoghe committed Jul 23, 2016
1 parent 829aa8a commit 18d6575
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/omkarmoghe/pokemap/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void credentialsIntroduced(String username, String password) {
}


private NianticManager.NianticEventListener mEventListener = new AbstractNianticEventListener(){
private NianticManager.Listener mEventListener = new AbstractNianticEventListener(){
@Override
public void onOperationFailure(Exception ex) {
super.onOperationFailure(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Created by coreymann on 7/22/16.
*/

public class AbstractNianticEventListener implements NianticManager.NianticEventListener {
public class AbstractNianticEventListener implements NianticManager.Listener {
@Override
public void onLogin(RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo info, PokemonGo pokemonGo) {

Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/com/omkarmoghe/pokemap/common/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.List;

import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass;
import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;


Expand All @@ -32,18 +31,18 @@ public static Notifier instance(){

//region Members
private Handler mHandler = new Handler(Looper.getMainLooper());
private List<NianticManager.NianticEventListener> mListeners = new ArrayList<>();
private List<NianticManager.Listener> mListeners = new ArrayList<>();


public void addListener(NianticManager.NianticEventListener listener){ this.mListeners.add(listener); }
public void removeListener(NianticManager.NianticEventListener listener) { this.mListeners.remove(listener); }
public void addListener(NianticManager.Listener listener){ this.mListeners.add(listener); }
public void removeListener(NianticManager.Listener listener) { this.mListeners.remove(listener); }


public void dispatchOnLogin(final AuthInfo info, final PokemonGo pokemonGo){
mHandler.post(new Runnable() {
@Override
public void run() {
for(NianticManager.NianticEventListener l : mListeners){
for(NianticManager.Listener l : mListeners){
try{
l.onLogin(info, pokemonGo);
}catch(Exception ex){
Expand All @@ -58,7 +57,7 @@ public void dispatchOnCatchablePokemonFound(final List<CatchablePokemon> pokemon
mHandler.post(new Runnable() {
@Override
public void run() {
for(NianticManager.NianticEventListener l : mListeners){
for(NianticManager.Listener l : mListeners){
l.onCatchablePokemonFound(pokemons);
}
}
Expand All @@ -68,7 +67,7 @@ public void dispatchOnOperationFailure(final Exception ex){
mHandler.post(new Runnable() {
@Override
public void run() {
for(NianticManager.NianticEventListener l : mListeners){
for(NianticManager.Listener l : mListeners){
try{
l.onOperationFailure(ex);
}catch(Exception ex){
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.omkarmoghe.pokemap.network;

import android.content.Context;
import android.location.Location;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;

import com.omkarmoghe.pokemap.common.Notifier;
import com.omkarmoghe.pokemap.utils.Varint;
import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.map.pokemon.CatchResult;
import com.pokegoapi.api.map.pokemon.CatchablePokemon;
import com.pokegoapi.api.map.pokemon.EncounterResult;
import com.pokegoapi.auth.GoogleLogin;
import com.pokegoapi.auth.PtcLogin;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
Expand All @@ -22,7 +22,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand All @@ -31,8 +30,6 @@

import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
* Created by vanshilshah on 20/07/16.
Expand All @@ -48,7 +45,7 @@ public class NianticManager {

private static NianticManager instance;

private List<NianticEventListener> listeners;
private List<Listener> listeners;
private Context context;
private AuthInfo mAuthInfo;

Expand Down Expand Up @@ -88,7 +85,27 @@ public boolean verify(String s, SSLSession sslSession) {
.build();
}

public void login(final String username, final String password) {
/**
* Sets the google auth token for the auth info also invokes the onLogin callback.
* @param token - a valid google auth token.
*/
public void setGoogleAuthToken(@NonNull final String token) {
mHandler.post(new Runnable() {
@Override
public void run() {
try {
mAuthInfo = new GoogleLogin(client).login(token);
Notifier.instance().dispatchOnLogin(mAuthInfo, new PokemonGo(mAuthInfo, client));
} catch (LoginFailedException e) {
e.printStackTrace();
} catch (RemoteServerException e) {
e.printStackTrace();
}
}
});
}

public void login(@NonNull final String username, @NonNull final String password) {
mHandler.post(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -194,7 +211,7 @@ private byte[] encode(ArrayList<Integer> walk) {
return mainBytes;
}

public interface NianticEventListener {
public interface Listener {
void onLogin(AuthInfo info, PokemonGo pokemonGo);
void onOperationFailure(Exception ex);

Expand Down

0 comments on commit 18d6575

Please sign in to comment.