Skip to content

Commit

Permalink
Merge pull request #6 from pixlee/CR-3256/KB
Browse files Browse the repository at this point in the history
Cr 3256/kb
  • Loading branch information
kj13ennett authored May 16, 2019
2 parents 0aa693a + 42faef4 commit a7ad146
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 14 additions & 16 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ To load the photos in an album, you'll want to use the `PXLAlbum` class. Instant
PXLAlbum pxlAlbum = new PXLAlbum(<ALBUM ID>, context);
```

To load the photos in an Product album, you'll want to use the `PXLPdpAlbum` class. Instantiate one with your desired sku and context:


```
#!java
PXLPdpAlbum pxlPdpAlbum = new PXLPdpAlbum(<SKU>, context);
```


You can then set sort and filter options if desired and use `loadNextPageOfPhotos` to kick off the async request.

Expand All @@ -61,11 +70,11 @@ Each successive call of `loadNextPageOfPhotos` will load the next page of photos

Once an album has loaded photos from the server, it will instantiate `PXLPhoto` objects that can be consumed by your UI. `PXLPhoto` exposes all of the data for a photo available through the Pixlee API and offers several image url sizes depending on your needs.

###Analytics
####Opened Widget
### Analytics
#### Opened Widget
On the first load of an album, an "Opened Widget" analytics event will be fired automatically

####Opened Lightbox
#### Opened Lightbox
To fire an opened ligtbox event, simply call the `openedLightbox` method of the PXLPhoto that is being opened, and an "Opened Lightbox" event will be fired containing all of the necessary analytics information.

```
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.pixlee.pixleeandroidsdk"
minSdkVersion 15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.pixlee.pixleesdk.PXLAlbum;
import com.pixlee.pixleesdk.PXLPdpAlbum;
import com.pixlee.pixleesdk.PXLAlbumFilterOptions;
import com.pixlee.pixleesdk.PXLAlbumSortOptions;
import com.pixlee.pixleesdk.PXLAlbumSortType;
Expand Down Expand Up @@ -168,12 +169,12 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
private void createAlbum() {
Context c = this.getApplicationContext();
PXLClient.initialize("196i8ZzIAhKU8dO2kDe");
album = new PXLAlbum("2696111", c);
album = new PXLPdpAlbum("rr", c);
PXLAlbumFilterOptions fo = new PXLAlbumFilterOptions();
fo.minTwitterFollowers = 0;
fo.minInstagramFollowers = 1;
fo.minInstagramFollowers = 0;
PXLAlbumSortOptions so = new PXLAlbumSortOptions();
so.sortType = PXLAlbumSortType.PHOTORANK;
so.sortType = PXLAlbumSortType.RECENCY;
so.descending = true;
album.setPerPage(20);
album.setFilterOptions(fo);
Expand Down Expand Up @@ -234,7 +235,7 @@ private void populateDetailActions(PXLPhoto photo) {
}

private void samplePhotoLoad() {
String identifier = "170008554";
String identifier = "282742015";
PXLPhoto.getPhotoWithId(getApplicationContext(), identifier, new PXLPhoto.PhotoLoadHandlers() {
@Override
public void photoLoaded(PXLPhoto photo) {
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,9 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 05 16:06:26 PDT 2017
#Thu May 16 17:06:08 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
3 changes: 1 addition & 2 deletions pixleesdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 15
Expand Down Expand Up @@ -31,7 +30,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.volley:volley:1.1.0'
testCompile 'junit:junit:4.12'
testCompile 'org.json:json:20160810'
}
25 changes: 13 additions & 12 deletions pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLAlbum.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ public class PXLAlbum implements RequestCallbacks {
public static final int DefaultPerPage = 20;

public String id = null;
private int page;
private int perPage;
private boolean hasMore;
private int lastPageLoaded;
private ArrayList<PXLPhoto> photos;
private PXLAlbumFilterOptions filterOptions;
private PXLAlbumSortOptions sortOptions;
private HashMap<Integer, Boolean> pagesLoading;
private RequestHandlers handlers;
private Context context;
protected int page;
protected int perPage;
protected boolean hasMore;
protected int lastPageLoaded;
protected ArrayList<PXLPhoto> photos;
protected PXLAlbumFilterOptions filterOptions;
protected PXLAlbumSortOptions sortOptions;
protected HashMap<Integer, Boolean> pagesLoading;
protected RequestHandlers handlers;
protected Context context;


/***
* Callback for a successful call to the api. Parses the response and converts the json data
Expand Down Expand Up @@ -162,14 +163,14 @@ public void setSortOptions(PXLAlbumSortOptions sortOptions) {
this.resetState();
}

private void resetState() {
protected void resetState() {
this.photos.clear();
this.lastPageLoaded = 0;
this.hasMore = true;
this.pagesLoading.clear();
}

private HashMap<String, Object> getRequestParams(int desiredPage) {
protected HashMap<String, Object> getRequestParams(int desiredPage) {
HashMap<String, Object> paramMap = new HashMap<>();
if (filterOptions != null) {
paramMap.put(PXLClient.KeyFilters, filterOptions.toParamString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class PXLClient {
public static final String KeyApiKey = "api_key";
public static final String KeyPage = "page";
public static final String KeyPerPage = "per_page";
public static final String KeySku = "sku";

public static final String ACTION_MEDIA = "media";

Expand Down
107 changes: 107 additions & 0 deletions pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPdpAlbum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.pixlee.pixleesdk;

import android.content.Context;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class PXLPdpAlbum extends PXLAlbum {
private static final String TAG = "PXLPdpAlbum";
private final String sku;

/***
* Constructor requires the product sku and context, which will be passed along to the PXLClient
* for volley configuration.
* @param sku - product sku
* @param context - context which will be used for volley configuration
*/
public PXLPdpAlbum(String sku, Context context) {
super(sku, context);
this.sku = sku;
this.page = 0;
this.perPage = DefaultPerPage;
this.hasMore = true;
this.lastPageLoaded = 0;
this.photos = new ArrayList<>();
this.pagesLoading = new HashMap<>();
this.context = context;
}


/***
* Requests the next page of photos from the Pixlee album. Make sure to set perPage,
* sort order, and filter options before calling.
* @param handlers - called upon success/failure of the request
* @return true if the request was attempted, false if aborted before the attempt was made
*/
@Override
public boolean loadNextPageOfPhotos(final RequestHandlers handlers) {
if (sku == null) {
Log.w(TAG, "No sku specified");
return false;
}
if (this.hasMore) {
int desiredPage = this.lastPageLoaded + 1;
if (pagesLoading.get(desiredPage) != null && pagesLoading.get(desiredPage)) {
Log.d(TAG, String.format("page %s already loading", desiredPage));
return false;
}
PXLClient pxlClient = PXLClient.getInstance(context);
String requestPath = "albums/from_sku";
this.pagesLoading.put(desiredPage, true);
this.handlers = handlers;
pxlClient.makeCall(requestPath, getRequestParams(desiredPage), this);
}

return true;
}

@Override
protected HashMap<String, Object> getRequestParams(int desiredPage) {
HashMap<String, Object> paramMap = new HashMap<>();
if (filterOptions != null) {
paramMap.put(PXLClient.KeyFilters, filterOptions.toParamString());
}
if (sortOptions != null) {
paramMap.put(PXLClient.KeySort, sortOptions.toParamString());
}
paramMap.put(PXLClient.KeyPerPage, perPage);
paramMap.put(PXLClient.KeyPage, desiredPage);
paramMap.put(PXLClient.KeySku, sku);
return paramMap;
}

@Override
public boolean openedWidget() {
PXLClient pxlClient = PXLClient.getInstance(context);
JSONObject body = new JSONObject();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < this.photos.size(); i++) {
try {
stringBuilder.append(this.photos.get(i).id);
if(i != this.photos.size() - 1){
stringBuilder.append(",");
}
} catch (Exception e) {
e.printStackTrace();
}
}

try{
body.put("sku", this.sku);
body.put("per_page", this.perPage);
body.put("page", this.page);
body.put("photos", stringBuilder.toString());

} catch (JSONException e) {
e.printStackTrace();
}

pxlClient.makeAnalyticsCall("events/openedWidget", body);
return true;
}
}

0 comments on commit a7ad146

Please sign in to comment.