Skip to content

Commit

Permalink
fix identation
Browse files Browse the repository at this point in the history
  • Loading branch information
serggl committed Sep 9, 2014
1 parent 209dc08 commit 4c6a3eb
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 302 deletions.
10 changes: 5 additions & 5 deletions library/src/com/anjlab/android/iab/v3/BillingBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BillingBase {
private WeakReference<Activity> contextReference;

public BillingBase(Activity context) {
contextReference = new WeakReference<Activity>(context);
contextReference = new WeakReference<Activity>(context);
}

public Activity getContext() {
Expand All @@ -38,10 +38,10 @@ protected String getPreferencesBaseKey() {
}

private SharedPreferences getPreferences() {
if(contextReference.get() != null)
return PreferenceManager.getDefaultSharedPreferences(contextReference.get());
return null;
}
if (contextReference.get() != null)
return PreferenceManager.getDefaultSharedPreferences(contextReference.get());
return null;
}

public void release() {
if (contextReference != null)
Expand Down
72 changes: 36 additions & 36 deletions library/src/com/anjlab/android/iab/v3/BillingCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
import java.util.regex.Pattern;

class BillingCache extends BillingBase {
private static final String ENTRY_DELIMITER = "#####";
private static final String LINE_DELIMITER = ">>>>>";
private static final String ENTRY_DELIMITER = "#####";
private static final String LINE_DELIMITER = ">>>>>";

private HashMap<String, PurchaseInfo> data;
private String cacheKey;
private HashMap<String, PurchaseInfo> data;
private String cacheKey;

public BillingCache(Activity context, String key) {
super(context);
data = new HashMap<String, PurchaseInfo>();
cacheKey = key;
data = new HashMap<String, PurchaseInfo>();
cacheKey = key;
load();
}

Expand All @@ -42,54 +42,54 @@ private String getPreferencesCacheKey() {
}

private void load() {
for(String entry : loadString(getPreferencesCacheKey(), "").split(Pattern.quote(ENTRY_DELIMITER))) {
if (!TextUtils.isEmpty(entry)) {
String[] parts = entry.split(Pattern.quote(LINE_DELIMITER));
if (parts.length > 1)
data.put(parts[0], new PurchaseInfo(parts[1], parts[2]));
}
for (String entry : loadString(getPreferencesCacheKey(), "").split(Pattern.quote(ENTRY_DELIMITER))) {
if (!TextUtils.isEmpty(entry)) {
String[] parts = entry.split(Pattern.quote(LINE_DELIMITER));
if (parts.length > 1)
data.put(parts[0], new PurchaseInfo(parts[1], parts[2]));
}
}
}

private void flush() {
ArrayList<String> output = new ArrayList<String>();
for(String productId : data.keySet()) {
PurchaseInfo info = data.get(productId);
output.add(productId + LINE_DELIMITER + info.responseData + LINE_DELIMITER + info.signature);
}
ArrayList<String> output = new ArrayList<String>();
for (String productId : data.keySet()) {
PurchaseInfo info = data.get(productId);
output.add(productId + LINE_DELIMITER + info.responseData + LINE_DELIMITER + info.signature);
}
saveString(getPreferencesCacheKey(), TextUtils.join(ENTRY_DELIMITER, output));
}

public boolean includesProduct(String productId) {
return data != null && data.containsKey(productId);
}

public PurchaseInfo getDetails(String productId) {
return data.containsKey(productId) ? data.get(productId) : null;
}
public PurchaseInfo getDetails(String productId) {
return data.containsKey(productId) ? data.get(productId) : null;
}

public void put(String productId, String details, String signature) {
if (!data.containsKey(productId)) {
data.put(productId, new PurchaseInfo(details, signature));
flush();
}
}
public void put(String productId, String details, String signature) {
if (!data.containsKey(productId)) {
data.put(productId, new PurchaseInfo(details, signature));
flush();
}
}

public void remove(String productId) {
if (data.containsKey(productId)) {
data.remove(productId);
flush();
}
}
public void remove(String productId) {
if (data.containsKey(productId)) {
data.remove(productId);
flush();
}
}

public void clear() {
data.clear();
data.clear();
flush();
}

public List<String> getContents() {
return new ArrayList<String>(data.keySet());
}
public List<String> getContents() {
return new ArrayList<String>(data.keySet());
}

@Override
public String toString() {
Expand Down
Loading

0 comments on commit 4c6a3eb

Please sign in to comment.