Skip to content

Commit

Permalink
Added filtering pokemons which you wish to show (#175)
Browse files Browse the repository at this point in the history
* Added the S2 geometry library

* Included the S2 geometry library; added RxJava and a suitable Retrofit/OkHTTP client

* Work in progress

* Work in progress

* Work in progress

* Working on location stuff

* Made Dagger components static

* Added optimization to proguard rules

* Disabled debug builds minification and enabled multidex

* Formatting fixes

* Fixed gradle issues

* Minor change

* Work in progress

* Removed constraint layout

* Removed s2-geometry-library folder

* Added presenters to start implementing the MVP pattern

* Added model which makes use of Observable

* Added model that makes use of Observables

* Added retrofit-rxjava

* Work in progress

* Removed unnecessary files

* Added a stub preference which stores IDs of pokemons to show on the map

* Work in progress

* Added pokemon display filtering

* Incorporated changes from PR #169

* Using localized pokemon names in the preferences

* Fixed: the plural of Pokemon is Pokemon

* Added pokemon icons to the filter
  • Loading branch information
fess89 authored and comann committed Jul 26, 2016
1 parent fd2dd38 commit 1c78492
Show file tree
Hide file tree
Showing 14 changed files with 524 additions and 127 deletions.
Expand Up @@ -2,6 +2,11 @@

import android.support.annotation.NonNull;

import java.util.List;
import java.util.Set;

import POGOProtos.Enums.PokemonIdOuterClass;

/**
* A contract which defines a user's app preferences
*/
Expand Down Expand Up @@ -60,4 +65,11 @@ public interface PokemapAppPreferences {
boolean isServiceEnabled();

int getServiceRefreshRate();

/**
* @return a set of pokemonIDs which can be shown according to the preferences.
*/
Set<PokemonIdOuterClass.PokemonId> getShowablePokemonIDs();

void setShowablePokemonIDs(Set<PokemonIdOuterClass.PokemonId> pokemonIDs);
}
Expand Up @@ -5,6 +5,11 @@
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;

import java.util.HashSet;
import java.util.Set;

import POGOProtos.Enums.PokemonIdOuterClass;

/**
* Provide convenience methods to access shared preferences
*/
Expand All @@ -18,6 +23,7 @@ public final class PokemapSharedPreferences implements PokemapAppPreferences {
private static final String SHOW_GYMS = "gyms_checkbox";
private static final String SERVICE_KEY = "background_poke_service";
private static final String SERVICE_REFRESH_KEY = "service_refresh_rate";
private static final String POKEMONS_TO_SHOW = "pokemons_to_show";

private final SharedPreferences sharedPreferences;

Expand All @@ -35,6 +41,22 @@ public boolean isPasswordSet() {
return sharedPreferences.contains(PASSWORD_KEY);
}

public Set<PokemonIdOuterClass.PokemonId> getShowablePokemonIDs() {
Set<String> showablePokemonStringIDs = sharedPreferences.getStringSet(POKEMONS_TO_SHOW, new HashSet<String>());
Set<PokemonIdOuterClass.PokemonId> showablePokemonIDs = new HashSet<>();
for (String stringId : showablePokemonStringIDs) {
showablePokemonIDs.add(PokemonIdOuterClass.PokemonId.forNumber(Integer.valueOf(stringId)));
}
return showablePokemonIDs;
}

public void setShowablePokemonIDs(Set<PokemonIdOuterClass.PokemonId> ids) {
Set<String> showablePokemonStringIDs = new HashSet<>();
for (PokemonIdOuterClass.PokemonId pokemonId : ids) {
showablePokemonStringIDs.add(String.valueOf(pokemonId.getNumber()));
}
sharedPreferences.edit().putStringSet(POKEMONS_TO_SHOW, showablePokemonStringIDs).apply();
}

@Override
public String getUsername() {
Expand Down Expand Up @@ -68,7 +90,7 @@ public String getGoogleToken() {

@Override
public void setServiceState(@NonNull boolean isEnabled) {
sharedPreferences.edit().putBoolean(SERVICE_KEY,isEnabled).apply();
sharedPreferences.edit().putBoolean(SERVICE_KEY, isEnabled).apply();
}

@Override
Expand All @@ -91,7 +113,7 @@ public boolean getShowGyms() {
return sharedPreferences.getBoolean(SHOW_GYMS, false);
}

@Override
@Override
public void clearLoginCredentials() {

sharedPreferences.edit().remove(GOOGLE_TOKEN_KEY).apply();
Expand All @@ -102,11 +124,11 @@ public void clearLoginCredentials() {

@Override
public boolean isServiceEnabled() {
return sharedPreferences.getBoolean(SERVICE_KEY,false);
return sharedPreferences.getBoolean(SERVICE_KEY, false);
}

@Override
public int getServiceRefreshRate() {
return Integer.valueOf(sharedPreferences.getString(SERVICE_REFRESH_KEY,"60"));
return Integer.valueOf(sharedPreferences.getString(SERVICE_REFRESH_KEY, "60"));
}
}
@@ -0,0 +1,34 @@
package com.omkarmoghe.pokemap.network.response;

import com.google.gson.annotations.SerializedName;

/**
* Response for the initial call.
* <p>
* Created by fess on 21.07.16.
*/
public class InitialResponse {

@SerializedName("lt")
private String lt;

@SerializedName("execution")
private String execution;

public String getLt() {
return lt;
}

public void setLt(String lt) {
this.lt = lt;
}

public String getExecution() {
return execution;
}

public void setExecution(String execution) {
this.execution = execution;
}

}
58 changes: 58 additions & 0 deletions app/src/main/java/com/omkarmoghe/pokemap/util/PokemonIdUtils.java
@@ -0,0 +1,58 @@
package com.omkarmoghe.pokemap.util;

import android.content.Context;
import android.content.res.Resources;

import com.omkarmoghe.pokemap.R;
import com.pokegoapi.util.Log;

import java.lang.reflect.Field;

import POGOProtos.Enums.PokemonIdOuterClass;

/**
* Utility methods to ease localization and handling of pokemon IDs.
* <p>
* Created by fess on 26.07.16.
*/
public class PokemonIdUtils {

/**
* try to resolve PokemonName from Resources
*
* @param pokemonId the PokemonID from the API.
* @return a localized name of the pokemon.
*/
public static String getLocalePokemonName(Resources resources,
PokemonIdOuterClass.PokemonId pokemonId) {
String apiPokeName = pokemonId.name();
int resId = 0;
try {
Class resClass = R.string.class;
Field field = resClass.getField(apiPokeName.toLowerCase());
resId = field.getInt(null);
} catch (Exception e) {
Log.e("PokemonTranslation", "Failure to get Name", e);
resId = -1;
}
return resId > 0 ? resources.getString(resId) : apiPokeName;
}

//Getting correct pokemon Id eg: 1 must be 001, 10 must be 010
public static String getCorrectPokemonImageId(int pokemonNumber) {
String actualNumber = String.valueOf(pokemonNumber);
if (pokemonNumber < 10) {
return "00" + actualNumber;
} else if (pokemonNumber < 100) {
return "0" + actualNumber;
} else {
return actualNumber;
}
}

public static int getPokemonIconResource(Context context,
int position) {
String iconName = "p" + position;
return context.getResources().getIdentifier(iconName, "drawable", context.getPackageName());
}
}

0 comments on commit 1c78492

Please sign in to comment.