-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from pixlee/CR-3256/KB
Cr 3256/kb
- Loading branch information
Showing
11 changed files
with
163 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPdpAlbum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |