Skip to content

Commit

Permalink
Added cluster icon styling and improved fetch algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiliano Iacopini committed May 31, 2022
1 parent 75b73a6 commit e14abfe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.emidev.moviesincisco"
minSdk 21
targetSdk 32
versionCode 8
versionName "1.7.1"
versionCode 9
versionName "1.7.2"


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

Expand All @@ -14,14 +15,18 @@
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.clustering.view.DefaultClusterRenderer;
import com.google.maps.android.ui.IconGenerator;

import java.util.Objects;

public class MoviesClusterRenderer extends DefaultClusterRenderer<MovieLocation> {
Context context;

private final IconGenerator iconGenerator;

public MoviesClusterRenderer(Context context, GoogleMap map, ClusterManager<MovieLocation> clusterManager) {
super(context, map, clusterManager);
iconGenerator = new IconGenerator(context);
this.context = context;
}

Expand Down Expand Up @@ -54,4 +59,13 @@ protected void onBeforeClusterItemRendered(MovieLocation item, MarkerOptions mar
markerOptions.title(item.getTitle());
super.onBeforeClusterItemRendered(item, markerOptions);
}

@Override
protected void onBeforeClusterRendered(Cluster<MovieLocation> cluster, MarkerOptions markerOptions) {
iconGenerator.setBackground(ContextCompat.getDrawable(context, R.drawable.cluster_icon_small));
//set icon number
iconGenerator.makeIcon(String.valueOf(cluster.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon()));
//markerOptions.icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.cluster_icon), 100, 100, false)));
}
}
16 changes: 12 additions & 4 deletions app/src/main/java/com/emidev/moviesincisco/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static boolean parseCredits(InputStreamReader file, MovieLocation movie)
for(int i = 0; i < results.size(); i++) {
JSONObject movieEntry = (JSONObject) results.get(i);
String name = (String) movieEntry.get("name");
if(name.equalsIgnoreCase(movie.getMainActor())) {
if(name.equalsIgnoreCase(movie.getMainActor()) || name.contains(movie.getMainActor())) {
return true;
}
}
Expand Down Expand Up @@ -158,11 +158,19 @@ public static ArrayList<MovieLocation> parseMovies(InputStreamReader file) throw
Log.d("doc", doc.toString());

for (int i = 0; i < doc.size(); i++) {
String title;
JSONObject movie = (JSONObject) doc.get(i);
MovieLocation m = new MovieLocation();
String title = ((String) movie.get("title")).split("Season")[0].trim();
title = title.split("episode")[0].trim();
m.setTitle(trimDash(title));
title = ((String) movie.get("title"));
if(title.equalsIgnoreCase("Cardinal X")){
Log.d("Cardinal", title);
title = "MDMA";
} else {
title = title.split("Season")[0].trim();
title = title.split("episode")[0].trim();
trimDash(title);
}
m.setTitle(title);

if(movie.get("locations") != null) {
Log.d("LocationOfJSONFile", (String) movie.get("locations"));
Expand Down
Binary file added app/src/main/res/drawable/cluster_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/cluster_icon_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e14abfe

Please sign in to comment.