Skip to content

Commit f9f648f

Browse files
author
Librelio
committed
modification in subscription handling
1 parent a5af3a8 commit f9f648f

9 files changed

+151
-19
lines changed

main/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'io.fabric'
55
apply plugin: 'com.getkeepsafe.dexcount'
66

77
ext {
8-
scriptApplicationId = "com.niveales.wind"
8+
scriptApplicationId = "com.niveales.grandsreportages"
99
}
1010

1111
buildscript {
@@ -27,10 +27,10 @@ android {
2727
buildToolsVersion '23.0.2'
2828
useLibrary 'org.apache.http.legacy'
2929
defaultConfig {
30-
applicationId "com.developer.wind"
30+
applicationId "com.niveales.grandsreportages"
3131
minSdkVersion 14
3232
targetSdkVersion 23
33-
versionCode 200
33+
versionCode 202
3434
versionName "2.0.0"
3535
buildConfigField "boolean", "CRASHLYTICS_ENABLED", "false"
3636
}

main/src/main/java/com/librelio/LibrelioApplication.java

+45-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.librelio.activity.MuPDFActivity;
1919
import com.librelio.storage.DataBaseHelper;
2020
import com.librelio.utils.GooglePlayServicesUtils;
21+
import com.librelio.utils.SubscriptionUtils;
2122
import com.librelio.utils.SystemHelper;
2223
import com.niveales.wind.BuildConfig;
2324
import com.niveales.wind.R;
@@ -30,6 +31,7 @@
3031

3132
import java.io.IOException;
3233
import java.security.GeneralSecurityException;
34+
import java.util.ArrayList;
3335

3436
import javax.net.ssl.SSLContext;
3537

@@ -267,13 +269,53 @@ public static String getUrlString(Context context, String fileName){
267269
return LibrelioApplication.getClientName(context) + PATH_SEPARATOR
268270
+ LibrelioApplication.getMagazineName(context) + PATH_SEPARATOR + fileName;
269271
}
272+
public static String[] getYearlySubsCode(Context context){
273+
return LibrelioApplication.getYearlySubsCode(context, false);
274+
}
270275

271-
public static String getYearlySubsCode(Context context){
272-
return context.getResources().getString(R.string.yearly_subs_code);
276+
public static String[] getYearlySubsCode(Context context, boolean returnOnlyActiveSubs){
277+
ArrayList<String> yearly_subs_code_array = new ArrayList<>();
278+
//yearly_subs_code_array[0] = context.getResources().getString(R.string.yearly_subs_code);
279+
//yearly_subs_code_array[1] = context.getResources().getString(R.string.previous_yearly_subs_code);
280+
yearly_subs_code_array.add(SubscriptionUtils.getSubscriptionsCode(context, "yearly_subs_code"));
281+
if (yearly_subs_code_array.isEmpty()) {
282+
yearly_subs_code_array.add(context.getResources().getString(R.string.yearly_subs_code));
283+
}
284+
if (!returnOnlyActiveSubs) {
285+
yearly_subs_code_array.add(SubscriptionUtils.getSubscriptionsCode(context, "previous_yearly_subs_code"));
286+
}
287+
return yearly_subs_code_array.toArray(new String[0]);
288+
}
289+
290+
public static String getActiveYearlySubsCode(Context context){
291+
292+
String yearly_subs_code = "";
293+
//yearly_subs_code_array[0] = context.getResources().getString(R.string.yearly_subs_code);
294+
//yearly_subs_code_array[1] = context.getResources().getString(R.string.previous_yearly_subs_code);
295+
yearly_subs_code = SubscriptionUtils.getSubscriptionsCode(context, "yearly_subs_code");
296+
if (yearly_subs_code.length() == 0) {
297+
yearly_subs_code = context.getResources().getString(R.string.yearly_subs_code);
298+
}
299+
return yearly_subs_code;
300+
}
301+
302+
public static String getYearlySubCode(Context context){
303+
String yearlySubCode;
304+
yearlySubCode = SubscriptionUtils.getSubscriptionsCode(context, "yearly_subs_code");
305+
if (yearlySubCode.length() == 0) {
306+
yearlySubCode = context.getResources().getString(R.string.yearly_subs_code);
307+
}
308+
return yearlySubCode;
273309
}
274310

275311
public static String getMonthlySubsCode(Context context){
276-
return context.getResources().getString(R.string.monthly_subs_code);
312+
//return context.getResources().getString(R.string.monthly_subs_code);
313+
String monthlySubCode;
314+
monthlySubCode = SubscriptionUtils.getSubscriptionsCode(context, "monthly_subs_code");
315+
if (monthlySubCode.length() == 0) {
316+
monthlySubCode = context.getResources().getString(R.string.monthly_subs_code);
317+
}
318+
return monthlySubCode;
277319
}
278320

279321
public static boolean isEnableCodeSubs(Context context){

main/src/main/java/com/librelio/activity/BillingActivity.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
import org.json.JSONObject;
4949

5050
import java.io.IOException;
51+
import java.sql.Array;
5152
import java.util.ArrayList;
5253
import java.util.Locale;
54+
import java.util.Arrays;
5355

5456
import fr.castorflex.android.circularprogressbar.CircularProgressBar;
5557

@@ -168,8 +170,9 @@ protected void onCreate(Bundle savedInstanceState) {
168170
}
169171

170172
private void setupDialogView() {
171-
172173
boolean includeSubscriptions = false;
174+
boolean forceSubscriptionDisplay = getResources().getBoolean(R.bool.always_enable_subscriptions);
175+
includeSubscriptions = (forceSubscriptionDisplay) ? true : includeSubscriptions;
173176

174177
String baseName = FilenameUtils.getBaseName(fileName);
175178

@@ -399,7 +402,12 @@ protected Bundle doInBackground(String... params) {
399402
skuList.add(productId);
400403

401404
// Add subscription codes
402-
skuList.add(LibrelioApplication.getYearlySubsCode(getContext()));
405+
String[] yearlySubsCode = LibrelioApplication.getYearlySubsCode(getContext(), true);
406+
for(String yearlySubCode : yearlySubsCode) {
407+
if (!yearlySubCode.equals("")) {
408+
skuList.add(yearlySubCode);
409+
}
410+
}
403411
skuList.add(LibrelioApplication.getMonthlySubsCode(getContext()));
404412

405413
Bundle querySkus = new Bundle();
@@ -452,11 +460,14 @@ protected void onPostExecute(Bundle skuDetails) {
452460
for (String s : ownedSkus) {
453461
Log.d(TAG, productId + " already purchased? " + s);
454462
}
455-
456-
if (ownedSkus.contains(LibrelioApplication.getYearlySubsCode(getContext()))) {
457-
prepareDownloadWithOwnedItem(ownedSubs, LibrelioApplication.getYearlySubsCode(getContext()));
458-
return;
463+
String[] yearlySubsCode = LibrelioApplication.getYearlySubsCode(getContext());
464+
for(String yearlySubCode : yearlySubsCode) {
465+
if (ownedSkus.contains(yearlySubCode) && !yearlySubCode.equals("")) {
466+
prepareDownloadWithOwnedItem(ownedSubs, yearlySubCode);
467+
return;
468+
}
459469
}
470+
460471
if (ownedSkus.contains(LibrelioApplication.getMonthlySubsCode(getContext()))) {
461472
prepareDownloadWithOwnedItem(ownedSubs, LibrelioApplication.getMonthlySubsCode(getContext()));
462473
return;
@@ -484,7 +495,7 @@ protected void onPostExecute(Bundle skuDetails) {
484495
if (sku.equals(productId)) {
485496
productPrice = price;
486497
productTitle = title;
487-
} else if (sku.equals(LibrelioApplication.getYearlySubsCode(getContext()))) {
498+
} else if (Arrays.asList(LibrelioApplication.getYearlySubsCode(getContext(), true)).contains(sku) && !sku.equals("")) {
488499
yearlySubPrice = price;
489500
yearlySubTitle = title;
490501

@@ -602,7 +613,7 @@ private void purchaseMonthlySub() {
602613
}
603614

604615
private void purchaseYearlySub() {
605-
new PurchaseTask().execute(LibrelioApplication.getYearlySubsCode(getContext()));
616+
new PurchaseTask().execute(LibrelioApplication.getYearlySubCode(getContext()));
606617
}
607618

608619
private boolean isNetworkConnected() {

main/src/main/java/com/librelio/activity/MainTabsActivity.java

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.librelio.model.dictitem.DictItem;
2525
import com.librelio.model.interfaces.DisplayableAsTab;
2626
import com.librelio.service.AssetDownloadService;
27+
import com.librelio.utils.PlistDownloader;
2728
import com.librelio.utils.StorageUtils;
2829
import com.longevitysoft.android.xml.plist.PListXMLHandler;
2930
import com.longevitysoft.android.xml.plist.PListXMLParser;
@@ -88,6 +89,13 @@ protected void onCreate(Bundle savedInstanceState) {
8889

8990
registerReceiver(subscriptionYear, subsFilter);
9091
registerReceiver(subscriptionMonthly, subsFilter);
92+
93+
preLoadPListFiles();
94+
}
95+
96+
private void preLoadPListFiles() {
97+
String subscriptionSCodesPlistURL = "subscriptions_codes.plist?waupdate=30";
98+
PlistDownloader.updateFromServer(this, subscriptionSCodesPlistURL, true, false);
9199
}
92100

93101
@Override

main/src/main/java/com/librelio/adapter/DictItemAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public DefaultViewHolder(Context context, MagazineGridItemView view, String plis
7474
}
7575

7676
public void bind(final DictItem dictItem) {
77+
view.setMagazine((MagazineItem) dictItem);
7778

78-
view.setMagazine((MagazineItem) dictItem);
7979

8080

8181
//// // FIXME Precache all the prices when plist is parsed - parse it while
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.librelio.utils;
2+
3+
import android.content.Context;
4+
import java.io.*;
5+
import javax.xml.parsers.DocumentBuilderFactory;
6+
import javax.xml.parsers.DocumentBuilder;
7+
import org.w3c.dom.*;
8+
9+
/**
10+
* Created by odin on 19/06/2017.
11+
*/
12+
13+
public class SubscriptionUtils {
14+
15+
public static String getSubscriptionsCode(Context context, String wantedCode) {
16+
String subscriptionSCodesPlistURL = "subscriptions_codes.plist?waupdate=30";
17+
PlistDownloader.updateFromServer(context, subscriptionSCodesPlistURL, true, false);
18+
String pList = StorageUtils.getFilePathFromAssetsOrLocalStorage(context, "subscriptions_codes.plist");
19+
20+
if (pList == null) {
21+
return null;
22+
}
23+
24+
DocumentBuilderFactory factory;
25+
DocumentBuilder builder;
26+
InputStream is;
27+
Document dom;
28+
String code = "";
29+
try {
30+
factory = DocumentBuilderFactory.newInstance();
31+
builder = factory.newDocumentBuilder();
32+
33+
is = new ByteArrayInputStream(pList.getBytes("UTF-8"));
34+
35+
dom = builder.parse(is);
36+
NodeList dictContent = dom.getElementsByTagName("dict").item(0).getChildNodes();
37+
int length = dictContent.getLength();
38+
String previousKey = "";
39+
for (int i = 0; i < length; i++) {
40+
if (dictContent.item(i).getNodeType() == Node.ELEMENT_NODE) {
41+
Element el = (Element) dictContent.item(i);
42+
if (el.getNodeName().contains("key")) {
43+
previousKey = el.getTextContent();
44+
}
45+
if(previousKey.startsWith(wantedCode)) {
46+
if (el.getNodeName().contains("string")) {
47+
code = el.getTextContent();
48+
}
49+
}
50+
}
51+
}
52+
}
53+
catch(Exception e){
54+
55+
}
56+
57+
return code;
58+
}
59+
}

main/src/main/res/values/application_.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes|MissingTranslation">
33

44
<string name="app_name">Wind</string>
5-
<string name="yearly_subs_code">yearlysubscription</string>
5+
<string name="yearly_subs_code">yearlysubscription3</string>
6+
<string name="previous_yearly_subs_code">yearlysubscription2</string>
67
<string name="monthly_subs_code">monthlysubscriptiontest</string>
78
<string name="code_service">S3</string>
89
<string name="user_service"></string>
910
<string name="google_analytics" tools:ignore="TypographyDashes">UA-1732003-23</string>
10-
<bool name="enable_subscribe_in_menu">false</bool>
11+
<bool name="enable_subscribe_in_menu">true</bool>
1112
<bool name="enable_app_rating">true</bool>
1213
<string name="gcm_project_number">1012641315687</string>
13-
<string name="dfp_prefix"></string>
14+
<string name="dfp_prefix">/166877488/niveales_vertical/niveales_vertical_</string>
1415
<bool name="enable_list_header">false</bool>
1516
<bool name="enable_image_click_dialogs">false</bool>
17+
<bool name="always_enable_subscriptions">true</bool>
1618

1719
</resources>

main/src/script/custom.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
project.ext { scriptApplicationId = "com.editor.project" }
1+
project.ext { scriptApplicationId = "com.niveales.grandsreportages" }

subscriptions_codes.plist

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>yearly_subs_code</key>
6+
<string>yearlysubscription2</string>
7+
<key>monthly_subs_code</key>
8+
<string>monthlysubscription</string>
9+
</dict>
10+
</plist>

0 commit comments

Comments
 (0)