| 21478 |
rajender |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.AlertDialog;
|
|
|
4 |
import android.app.Fragment;
|
|
|
5 |
import android.app.ProgressDialog;
|
|
|
6 |
import android.content.ComponentName;
|
|
|
7 |
import android.content.Context;
|
|
|
8 |
import android.content.DialogInterface;
|
|
|
9 |
import android.content.Intent;
|
|
|
10 |
import android.content.IntentFilter;
|
|
|
11 |
import android.content.SharedPreferences;
|
|
|
12 |
import android.content.pm.ResolveInfo;
|
|
|
13 |
import android.graphics.Bitmap;
|
|
|
14 |
import android.net.ConnectivityManager;
|
|
|
15 |
import android.net.Uri;
|
|
|
16 |
import android.os.AsyncTask;
|
|
|
17 |
import android.os.Build;
|
|
|
18 |
import android.os.Bundle;
|
|
|
19 |
import android.os.Handler;
|
|
|
20 |
import android.os.Parcelable;
|
|
|
21 |
import android.support.v4.os.AsyncTaskCompat;
|
|
|
22 |
import android.util.Base64;
|
|
|
23 |
import android.util.Log;
|
|
|
24 |
import android.view.KeyEvent;
|
|
|
25 |
import android.view.LayoutInflater;
|
|
|
26 |
import android.view.Menu;
|
|
|
27 |
import android.view.MenuInflater;
|
|
|
28 |
import android.view.View;
|
|
|
29 |
import android.view.ViewGroup;
|
|
|
30 |
import android.webkit.CookieManager;
|
|
|
31 |
import android.webkit.CookieSyncManager;
|
|
|
32 |
import android.webkit.HttpAuthHandler;
|
|
|
33 |
import android.webkit.JavascriptInterface;
|
|
|
34 |
import android.webkit.ValueCallback;
|
|
|
35 |
import android.webkit.WebSettings;
|
|
|
36 |
import android.webkit.WebView;
|
|
|
37 |
import android.webkit.WebViewClient;
|
|
|
38 |
import android.widget.CheckBox;
|
|
|
39 |
import android.widget.CompoundButton;
|
|
|
40 |
import android.widget.RelativeLayout;
|
|
|
41 |
import android.widget.TextView;
|
|
|
42 |
import android.widget.Toast;
|
|
|
43 |
|
|
|
44 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
45 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
46 |
import com.google.android.gms.plus.Plus;
|
|
|
47 |
import com.saholic.profittill.BroadcastReceivers.SmsReceiver;
|
|
|
48 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
49 |
import com.saholic.profittill.Database.OrderTransactionDetails;
|
|
|
50 |
import com.saholic.profittill.Network.NotificationCount;
|
|
|
51 |
import com.saholic.profittill.R;
|
|
|
52 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
|
|
53 |
import com.testin.agent.TestinAgent;
|
|
|
54 |
|
|
|
55 |
import org.apache.http.HttpEntity;
|
|
|
56 |
import org.apache.http.HttpResponse;
|
|
|
57 |
import org.apache.http.NameValuePair;
|
|
|
58 |
import org.apache.http.client.ClientProtocolException;
|
|
|
59 |
import org.apache.http.client.HttpClient;
|
|
|
60 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
61 |
import org.apache.http.client.methods.HttpGet;
|
|
|
62 |
import org.apache.http.client.methods.HttpPost;
|
|
|
63 |
import org.apache.http.entity.StringEntity;
|
|
|
64 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
65 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
66 |
import org.apache.http.util.EntityUtils;
|
|
|
67 |
import org.json.JSONArray;
|
|
|
68 |
import org.json.JSONException;
|
|
|
69 |
import org.json.JSONObject;
|
|
|
70 |
|
|
|
71 |
import java.io.IOException;
|
|
|
72 |
import java.io.InputStream;
|
|
|
73 |
import java.io.UnsupportedEncodingException;
|
|
|
74 |
import java.text.SimpleDateFormat;
|
|
|
75 |
import java.util.ArrayList;
|
|
|
76 |
import java.util.Date;
|
|
|
77 |
import java.util.HashMap;
|
|
|
78 |
import java.util.Iterator;
|
|
|
79 |
import java.util.LinkedList;
|
|
|
80 |
import java.util.List;
|
|
|
81 |
import java.util.Map;
|
|
|
82 |
import java.util.StringTokenizer;
|
|
|
83 |
import java.util.regex.Matcher;
|
|
|
84 |
import java.util.regex.Pattern;
|
|
|
85 |
|
|
|
86 |
public class DealsHomeFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
|
|
87 |
|
|
|
88 |
public DealsHomeFragment() {
|
|
|
89 |
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
static boolean FLAG = false, REDIRECT = false, PAGE_LOAD = false, PAYTMFLAG = false, isPause = false, Flipkartflag = false;
|
|
|
93 |
int snapdealException = 0;
|
|
|
94 |
static String BASIC_AUTH = "Basic " + Base64.encodeToString("dtr:dtr18Feb2015".getBytes(), Base64.NO_WRAP);
|
|
|
95 |
public static WebView webView;
|
|
|
96 |
WebView amazonWebView, OrderHistoryWebView, amazonOrderHistoryWebView, amazonOrderHistoryCancelledWebView, paytmWebView;
|
|
|
97 |
WebView amazonAllUrlsWebView;
|
|
|
98 |
SharedPreferences userData;
|
|
|
99 |
SharedPreferences apiData;
|
|
|
100 |
SharedPreferences flipkartData;
|
|
|
101 |
SharedPreferences.Editor userDataEditor;
|
|
|
102 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
103 |
SharedPreferences.Editor flipkartDataEditor;
|
|
|
104 |
OrderTransactionDetails orderDetails;
|
|
|
105 |
LinkedList<ArrayList<NameValuePair>> orderLinkedList;
|
|
|
106 |
SharedPreferences amazonData;
|
|
|
107 |
String affliateUrl;
|
|
|
108 |
String landingURL;
|
|
|
109 |
boolean val = false;
|
|
|
110 |
String redirectUrls;
|
|
|
111 |
String pageLoad;
|
|
|
112 |
SharedPreferences.Editor amazonapiSettingsEditor;
|
|
|
113 |
List<NameValuePair> amazonOrderTrackingData;
|
|
|
114 |
int pageRedirect = 0;
|
|
|
115 |
int snapdealPageLoad;
|
|
|
116 |
final ArrayList<String> redirectUrlsList = new ArrayList<String>();
|
|
|
117 |
final ArrayList<String> pageLoadList = new ArrayList<String>();
|
|
|
118 |
String flipkartUrl;
|
|
|
119 |
View checkBoxView;
|
|
|
120 |
boolean flipkartFlag;
|
|
|
121 |
String saholicUrl;
|
|
|
122 |
JSONObject jSaholic;
|
|
|
123 |
JSONArray jsArraySaholic;
|
|
|
124 |
String type1;
|
|
|
125 |
ArrayList<String> orderSuccessUrlList;
|
|
|
126 |
public GoogleApiClient mGoogleApiClient;
|
|
|
127 |
ProgressDialog pd1 = null;
|
|
|
128 |
String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
|
|
|
129 |
SmsReceiver smsListener = new SmsReceiver();
|
|
|
130 |
|
|
|
131 |
@Override
|
|
|
132 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
133 |
super.onCreate(savedInstanceState);
|
|
|
134 |
setRetainInstance(true);
|
|
|
135 |
setHasOptionsMenu(true);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
@Override
|
|
|
139 |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
140 |
super.onCreateOptionsMenu(menu, inflater);
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.action_notifications).getActionView();
|
|
|
144 |
TextView notifciationCount = (TextView) badgeLayout.findViewById(R.id.inAppNotificationText);
|
|
|
145 |
if (userData.getInt("notification_count", 0) != 0) {
|
|
|
146 |
notifciationCount.setVisibility(View.VISIBLE);
|
|
|
147 |
notifciationCount.setText(userData.getInt("notification_count", 0) + "");
|
|
|
148 |
} else {
|
|
|
149 |
notifciationCount.setVisibility(View.GONE);
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
@Override
|
|
|
155 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
156 |
Bundle savedInstanceState) {
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
View rootView = inflater.inflate(R.layout.fragment_deals_home, container, false);
|
|
|
160 |
|
|
|
161 |
TestinAgent.init(getActivity());
|
|
|
162 |
amazonData = getActivity().getSharedPreferences("Amazon_Data", Context.MODE_PRIVATE);
|
|
|
163 |
userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
164 |
apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
|
|
165 |
flipkartData = getActivity().getSharedPreferences("Flipkart_Data", Context.MODE_PRIVATE);
|
|
|
166 |
userDataEditor = userData.edit();
|
|
|
167 |
apiSettingsEditor = apiData.edit();
|
|
|
168 |
TestinAgent.setUserInfo(userData.getString("id", ""));
|
|
|
169 |
amazonapiSettingsEditor = amazonData.edit();
|
|
|
170 |
flipkartDataEditor = flipkartData.edit();
|
|
|
171 |
affliateUrl = getArguments().getString("key");
|
|
|
172 |
orderDetails = new OrderTransactionDetails(getActivity());
|
|
|
173 |
|
|
|
174 |
orderSuccessUrlList = new ArrayList<String>();
|
|
|
175 |
String issues = apiData.getString("list.order.success.url", "blank");
|
|
|
176 |
StringTokenizer st2 = new StringTokenizer(issues, "|");
|
|
|
177 |
|
|
|
178 |
while (st2.hasMoreElements()) {
|
|
|
179 |
orderSuccessUrlList.add(st2.nextToken());
|
|
|
180 |
}
|
|
|
181 |
if (isInternetOn()) {
|
|
|
182 |
if (orderDetails.countTotalRecords() > 0) {
|
|
|
183 |
sendQueuedResponse();
|
|
|
184 |
}
|
|
|
185 |
type1 = userData.getString("type", null);
|
|
|
186 |
if (type1 != null && type1.equalsIgnoreCase("google")) {
|
|
|
187 |
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
|
|
|
188 |
.addConnectionCallbacks(this)
|
|
|
189 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
190 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
191 |
mGoogleApiClient.connect();
|
|
|
192 |
}
|
|
|
193 |
redirectUrls = apiData.getString("profitmandi.redirect.urls", "");
|
|
|
194 |
StringTokenizer st = new StringTokenizer(redirectUrls, "|");
|
|
|
195 |
while (st.hasMoreTokens()) {
|
|
|
196 |
redirectUrlsList.add(st.nextToken());
|
|
|
197 |
}
|
|
|
198 |
pageLoad = apiData.getString("profitmandi.pageloads.pattern", "");
|
|
|
199 |
StringTokenizer st1 = new StringTokenizer(pageLoad, "|");
|
|
|
200 |
while (st1.hasMoreTokens()) {
|
|
|
201 |
pageLoadList.add(st1.nextToken());
|
|
|
202 |
}
|
|
|
203 |
WebClientClass webViewClient = new WebClientClass();
|
|
|
204 |
if (webView != null) {
|
|
|
205 |
webView.loadUrl("about:blank");
|
|
|
206 |
}
|
|
|
207 |
webView = (WebView) rootView.findViewById(R.id.webView);
|
|
|
208 |
webView.setClickable(true);
|
|
|
209 |
webView.setFocusableInTouchMode(true);
|
|
|
210 |
webView.getSettings().setDomStorageEnabled(true);
|
|
|
211 |
webView.getSettings().setJavaScriptEnabled(true);
|
|
|
212 |
webView.getSettings().setBuiltInZoomControls(true);
|
|
|
213 |
webView.addJavascriptInterface(new javascriptInterface(webView), "HTMLOUT");
|
|
|
214 |
webView.getSettings().setSavePassword(true);
|
|
|
215 |
CookieManager cookieManager = CookieManager.getInstance();
|
|
|
216 |
cookieManager.setAcceptCookie(true);
|
|
|
217 |
|
|
|
218 |
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
219 |
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
|
|
220 |
webView.getSettings().setAllowContentAccess(true);
|
|
|
221 |
CookieManager cookieManager1 = CookieManager.getInstance();
|
|
|
222 |
cookieManager1.setAcceptThirdPartyCookies(webView, true);
|
|
|
223 |
}
|
|
|
224 |
if (Uri.parse(getArguments().getString("key")).getHost().contains("api.profittill")) {
|
|
|
225 |
userDataEditor.putString("saholic.data", UtilityFunctions.clearCookiesNew(getArguments().getString("key"), getActivity())).commit();
|
|
|
226 |
}
|
|
|
227 |
String url = getArguments().getString("key");
|
|
|
228 |
if (Uri.parse(url).getHost().equalsIgnoreCase(ProfitTillConstants.DOMAIN)) {
|
|
|
229 |
CookieSyncManager.createInstance(getActivity());
|
|
|
230 |
CookieManager cookieManager1 = CookieManager.getInstance();
|
|
|
231 |
cookieManager1.setCookie(url, "token=" + userData.getString("token", ""));
|
|
|
232 |
cookieManager1.setCookie(url, "walletAuthentication=true");
|
|
|
233 |
cookieManager1.setCookie(url, "shopcluesActive=true");
|
|
|
234 |
cookieManager1.setCookie(url, "paytmActive=true");
|
|
|
235 |
cookieManager1.setCookie(url, "shareApps=true");
|
|
|
236 |
cookieManager1.setCookie(url, "homeshop18=true");
|
|
|
237 |
cookieManager1.setCookie(url, "isRedirect=true");
|
|
|
238 |
}
|
|
|
239 |
if (!(userData.getBoolean("paytmLoggedIn", false))) {
|
|
|
240 |
Log.d("User Not Logged In", "User Not logged In");
|
|
|
241 |
} else {
|
|
|
242 |
if (userData.getString("paytmOrder", "").equalsIgnoreCase("true")) {
|
|
|
243 |
long nextFetchTime = userData.getLong("paytmNextFetchTime", 0);
|
|
|
244 |
if (nextFetchTime == 0 || nextFetchTime < System.currentTimeMillis()) {
|
|
|
245 |
if (isInternetOn()) {
|
|
|
246 |
new PaytmOrderURL().execute();
|
|
|
247 |
}
|
|
|
248 |
} else {
|
|
|
249 |
Log.d("Paytm False", "Paytm Time False");
|
|
|
250 |
}
|
|
|
251 |
} else {
|
|
|
252 |
Log.d("Paytm False", "Paytm False No orders");
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
if (!(userData.getBoolean("amazonLoggedIn", false))) {
|
|
|
256 |
Log.d("Not In Amazon", "Amazon");
|
|
|
257 |
}
|
|
|
258 |
else {
|
|
|
259 |
if (userData.getString("amazonOrder", "").equalsIgnoreCase("true")) {
|
|
|
260 |
long nextFetchTime = userData.getLong("amazonNextFetchTime", 0);
|
|
|
261 |
if (nextFetchTime == 0 || nextFetchTime < System.currentTimeMillis()) {
|
|
|
262 |
if (isInternetOn()) {
|
|
|
263 |
new FetchOrderURLS().execute();
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
else {
|
|
|
267 |
Log.d("Amazon False", "Amazon Time False" + userData.getLong("amazonNextFetchTime", 0));
|
|
|
268 |
}
|
|
|
269 |
} else {
|
|
|
270 |
Log.d("Amazon False", "Amazon False No orders");
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
Map <String, String> extraHeaders = new HashMap<String, String>();
|
|
|
274 |
extraHeaders.put("Auth-Token",userData.getString("token",""));
|
|
|
275 |
webView.setWebViewClient(webViewClient);
|
|
|
276 |
webView.loadUrl(url,extraHeaders);
|
|
|
277 |
|
|
|
278 |
}
|
|
|
279 |
else {
|
|
|
280 |
SearchFragment nextFrag = new SearchFragment();
|
|
|
281 |
Bundle args = new Bundle();
|
|
|
282 |
args.putString("finishingurl", getArguments().getString("key"));
|
|
|
283 |
args.putString("fragmentNumber", "1");
|
|
|
284 |
nextFrag.setArguments(args);
|
|
|
285 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
286 |
.replace(R.id.frame_container, nextFrag)
|
|
|
287 |
.addToBackStack(null)
|
|
|
288 |
.commit();
|
|
|
289 |
}
|
|
|
290 |
return rootView;
|
|
|
291 |
}
|
|
|
292 |
@Override
|
|
|
293 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
294 |
super.onViewCreated(view, savedInstanceState);
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
JSONObject obj;
|
|
|
298 |
|
|
|
299 |
@Override
|
|
|
300 |
public void onConnected(Bundle bundle) {
|
|
|
301 |
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
@Override
|
|
|
305 |
public void onConnectionSuspended(int i) {
|
|
|
306 |
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
@Override
|
|
|
310 |
public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
311 |
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public class WebClientClass extends WebViewClient {
|
|
|
315 |
ProgressDialog pd = null;
|
|
|
316 |
|
|
|
317 |
ProgressDialog pd2 = null;
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
@Override
|
|
|
321 |
public void onReceivedHttpAuthRequest(WebView view,
|
|
|
322 |
HttpAuthHandler handler, String host, String realm) {
|
|
|
323 |
|
|
|
324 |
handler.proceed("dtr", "dtr18Feb2015");
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
@Override
|
|
|
328 |
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
329 |
|
|
|
330 |
if (apiData.getString("snapdealException", "false").equalsIgnoreCase("true")) {
|
|
|
331 |
List<String> snapdealExceptionUrls = new ArrayList<>();
|
|
|
332 |
StringTokenizer st = new StringTokenizer(apiData.getString("snapdeal.exception.urls", ""), "|");
|
|
|
333 |
while (st.hasMoreTokens()) {
|
|
|
334 |
snapdealExceptionUrls.add(st.nextToken());
|
|
|
335 |
}
|
|
|
336 |
try {
|
|
|
337 |
Log.d("Count", "Count " + apiData.getString("snapdeal.exception.count", "1"));
|
|
|
338 |
for (String s : snapdealExceptionUrls) {
|
|
|
339 |
if (url.contains(s)) {
|
|
|
340 |
if (snapdealException <= Integer.parseInt(apiData.getString("snapdeal.exception.count", "1"))) {
|
|
|
341 |
webView.reload();
|
|
|
342 |
snapdealException += 1;
|
|
|
343 |
}
|
|
|
344 |
return false;
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
} catch (Exception e) {
|
|
|
348 |
e.printStackTrace();
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
if (apiData.getString("isRedirect", "false").equalsIgnoreCase("true")) {
|
|
|
352 |
List<String> browserRedirectUrl = new ArrayList<>();
|
|
|
353 |
StringTokenizer st = new StringTokenizer(apiData.getString("redirect.urls", ""), "|");
|
|
|
354 |
while (st.hasMoreTokens()) {
|
|
|
355 |
browserRedirectUrl.add(st.nextToken());
|
|
|
356 |
}
|
|
|
357 |
for (String s : browserRedirectUrl) {
|
|
|
358 |
if (url.contains(s)) {
|
|
|
359 |
isPause = true;
|
|
|
360 |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
|
361 |
startActivity(intent);
|
|
|
362 |
return true;
|
|
|
363 |
}
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
if (url.contains("apprub")) {
|
|
|
367 |
onShareClick(url);
|
|
|
368 |
return true;
|
|
|
369 |
}
|
|
|
370 |
if (url.contains(apiData.getString("wallet.auth", "api.profittill.com/special/native/login")) || userData.getString("id", "").isEmpty()) {
|
|
|
371 |
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
|
|
|
372 |
android.webkit.CookieSyncManager.createInstance(getActivity());
|
|
|
373 |
cookieManager.removeAllCookie();
|
|
|
374 |
AlertDialog alert;
|
|
|
375 |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
376 |
builder.setMessage(apiData.getString("wallet.auth.message", "You are not authenticated. Please log in again")).setCancelable(false);
|
|
|
377 |
alert = builder.create();
|
|
|
378 |
alert.show();
|
|
|
379 |
try {
|
|
|
380 |
if (mGoogleApiClient.isConnected()) {
|
|
|
381 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
382 |
mGoogleApiClient.disconnect();
|
|
|
383 |
mGoogleApiClient.connect();
|
|
|
384 |
redirectPage(alert);
|
|
|
385 |
} else {
|
|
|
386 |
if (!mGoogleApiClient.isConnected()) {
|
|
|
387 |
redirectPage(alert);
|
|
|
388 |
}
|
|
|
389 |
}
|
|
|
390 |
} catch (Exception e) {
|
|
|
391 |
redirectPage(alert);
|
|
|
392 |
}
|
|
|
393 |
return true;
|
|
|
394 |
}
|
|
|
395 |
if (url.contains("com.saholic.profittill")) {
|
|
|
396 |
Intent intent = null;
|
|
|
397 |
try {
|
|
|
398 |
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getActivity().getPackageName()));
|
|
|
399 |
} catch (android.content.ActivityNotFoundException anfe) {
|
|
|
400 |
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getActivity().getPackageName()));
|
|
|
401 |
}
|
|
|
402 |
startActivity(intent);
|
|
|
403 |
return true;
|
|
|
404 |
}
|
|
|
405 |
if (snapdealPageLoad == 1) {
|
|
|
406 |
pd2 = new ProgressDialog(getActivity());
|
|
|
407 |
pd2.setMessage("Wait for a moment and click again.");
|
|
|
408 |
pd2.setProgress(view.getProgress());
|
|
|
409 |
pd2.show();
|
|
|
410 |
return true;
|
|
|
411 |
}
|
|
|
412 |
if (url.startsWith("tel")) {
|
|
|
413 |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
|
414 |
startActivity(intent);
|
|
|
415 |
return true;
|
|
|
416 |
}
|
|
|
417 |
if (url.contains(apiData.getString("contactus.url", ""))) {
|
|
|
418 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
419 |
i.putExtra("displayView", "6");
|
|
|
420 |
startActivity(i);
|
|
|
421 |
return true;
|
|
|
422 |
}
|
|
|
423 |
if (url.contains(apiData.getString("howitworks.url", ""))) {
|
|
|
424 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
425 |
i.putExtra("displayView", "7");
|
|
|
426 |
startActivity(i);
|
|
|
427 |
return true;
|
|
|
428 |
}
|
|
|
429 |
if (url.contains(apiData.getString("myprofile.url", "http://api.profittill.com/aboutus/profile"))) {
|
|
|
430 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
431 |
i.putExtra("displayView", "15");
|
|
|
432 |
startActivity(i);
|
|
|
433 |
return true;
|
|
|
434 |
}
|
|
|
435 |
return false;
|
|
|
436 |
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
@Override
|
|
|
440 |
public synchronized void onPageStarted(final WebView view, String url, Bitmap favicon) {
|
|
|
441 |
super.onPageStarted(view, url, favicon);
|
|
|
442 |
final CharSequence[] items = {" Don't show me again "};
|
|
|
443 |
final ArrayList seletedItems = new ArrayList();
|
|
|
444 |
try {
|
|
|
445 |
if (Uri.parse(url).getHost().equalsIgnoreCase(ProfitTillConstants.DOMAIN)) {
|
|
|
446 |
CookieSyncManager.createInstance(getActivity());
|
|
|
447 |
CookieManager cookieManager = CookieManager.getInstance();
|
|
|
448 |
cookieManager.setCookie(url, "token=" + userData.getString("token", ""));
|
|
|
449 |
cookieManager.setCookie(url, "walletAuthentication=true");
|
|
|
450 |
cookieManager.setCookie(url, "shopcluesActive=true");
|
|
|
451 |
cookieManager.setCookie(url, "paytmActive=true");
|
|
|
452 |
cookieManager.setCookie(url, "shareApps=true");
|
|
|
453 |
cookieManager.setCookie(url, "homeshop18=true");
|
|
|
454 |
cookieManager.setCookie(url, "isRedirect=true");
|
|
|
455 |
}
|
|
|
456 |
if (false) {
|
|
|
457 |
flipkartUrl = url;
|
|
|
458 |
|
|
|
459 |
if (flipkartData.getInt("showagainflag", 0) < 3) {
|
|
|
460 |
AlertDialog dialog;
|
|
|
461 |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
462 |
builder.setMessage(apiData.getString("flipkart.message", "You won't be able to track your orders & earn cashbacks if you purchase using Flipkart App."))
|
|
|
463 |
.setView(checkBoxView)
|
|
|
464 |
.setCancelable(false)
|
|
|
465 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
466 |
@Override
|
|
|
467 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
468 |
int i = flipkartData.getInt("showagainflag", 0);
|
|
|
469 |
flipkartDataEditor.putInt("showagainflag", ++i);
|
|
|
470 |
flipkartDataEditor.commit();
|
|
|
471 |
Intent flipkartIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(flipkartUrl));
|
|
|
472 |
startActivity(flipkartIntent);
|
|
|
473 |
}
|
|
|
474 |
})
|
|
|
475 |
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
476 |
@Override
|
|
|
477 |
public void onClick(DialogInterface dialog, int id) {
|
|
|
478 |
view.loadUrl(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", ""));
|
|
|
479 |
|
|
|
480 |
}
|
|
|
481 |
});
|
|
|
482 |
dialog = builder.create();
|
|
|
483 |
dialog.show();
|
|
|
484 |
} else if (flipkartData.getInt("showagainflag", 0) == 3) {
|
|
|
485 |
AlertDialog dialog;
|
|
|
486 |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
487 |
checkBoxView = View.inflate(getActivity(), R.layout.checkboxlayout, null);
|
|
|
488 |
CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox);
|
|
|
489 |
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
490 |
|
|
|
491 |
@Override
|
|
|
492 |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
493 |
flipkartFlag = isChecked;
|
|
|
494 |
}
|
|
|
495 |
});
|
|
|
496 |
checkBox.setText("Don't show me again");
|
|
|
497 |
builder.setMessage(apiData.getString("flipkart.message", "You won't be able to track your orders & earn cashbacks if you purchase using Flipkart App."))
|
|
|
498 |
.setView(checkBoxView)
|
|
|
499 |
.setCancelable(false)
|
|
|
500 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
501 |
@Override
|
|
|
502 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
503 |
if (flipkartFlag) {
|
|
|
504 |
int i = flipkartData.getInt("showagainflag", 0);
|
|
|
505 |
flipkartDataEditor.putInt("showagainflag", ++i);
|
|
|
506 |
flipkartDataEditor.commit();
|
|
|
507 |
}
|
|
|
508 |
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(flipkartUrl));
|
|
|
509 |
startActivity(i);
|
|
|
510 |
}
|
|
|
511 |
})
|
|
|
512 |
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
513 |
@Override
|
|
|
514 |
public void onClick(DialogInterface dialog, int id) {
|
|
|
515 |
view.loadUrl(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", ""));
|
|
|
516 |
|
|
|
517 |
}
|
|
|
518 |
});
|
|
|
519 |
dialog = builder.create();
|
|
|
520 |
dialog.show();
|
|
|
521 |
} else {
|
|
|
522 |
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(flipkartUrl));
|
|
|
523 |
startActivity(i);
|
|
|
524 |
}
|
|
|
525 |
view.stopLoading();
|
|
|
526 |
} else {
|
|
|
527 |
for (String s : pageLoadList) {
|
|
|
528 |
if (url.contains(s)) {
|
|
|
529 |
PAGE_LOAD = true;
|
|
|
530 |
}
|
|
|
531 |
}
|
|
|
532 |
if (PAGE_LOAD) {
|
|
|
533 |
snapdealPageLoad = 1;
|
|
|
534 |
PAGE_LOAD = false;
|
|
|
535 |
} else {
|
|
|
536 |
snapdealPageLoad = 0;
|
|
|
537 |
for (String s : redirectUrlsList) {
|
|
|
538 |
if (url.contains(s)) {
|
|
|
539 |
REDIRECT = true;
|
|
|
540 |
break;
|
|
|
541 |
}
|
|
|
542 |
}
|
|
|
543 |
if (REDIRECT) {
|
|
|
544 |
pageRedirect = 2;
|
|
|
545 |
REDIRECT = false;
|
|
|
546 |
}
|
|
|
547 |
else if (pageRedirect == 2 || pageRedirect == 1) {
|
|
|
548 |
Toast.makeText(getActivity(), "Redirecting to deals...", Toast.LENGTH_SHORT).show();
|
|
|
549 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
550 |
i.putExtra("displayView", "31");
|
|
|
551 |
i.putExtra("redirectUrl", apiData.getString("redirect.url", "") + "?user_id=" + userData.getString("id", ""));
|
|
|
552 |
startActivity(i);
|
|
|
553 |
pageRedirect = 0;
|
|
|
554 |
}
|
|
|
555 |
else {
|
|
|
556 |
landingURL = url;
|
|
|
557 |
if (url.contains(apiData.getString("mobile.website.url", "")) || url.equalsIgnoreCase("http://api.profittill.com/categorydeals") || url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
|
|
|
558 |
pd = new ProgressDialog(getActivity());
|
|
|
559 |
pd.setTitle("Please wait");
|
|
|
560 |
pd.setMessage("Loading..");
|
|
|
561 |
pd.show();
|
|
|
562 |
}
|
|
|
563 |
getOrderSuccessUrlConfirmation(url);
|
|
|
564 |
if (displayActionBar) {
|
|
|
565 |
pd1 = new ProgressDialog(getActivity());
|
|
|
566 |
pd1.setTitle("Please wait");
|
|
|
567 |
pd1.setMessage("Loading..");
|
|
|
568 |
pd1.show();
|
|
|
569 |
}
|
|
|
570 |
}
|
|
|
571 |
}
|
|
|
572 |
if (Uri.parse(url).getHost().contains("saholic") && userData.getString("saholic.data", "false").equalsIgnoreCase("true")) {
|
|
|
573 |
|
|
|
574 |
}
|
|
|
575 |
else {
|
|
|
576 |
JSONObject j = new JSONObject();
|
|
|
577 |
JSONArray jsArray = new JSONArray();
|
|
|
578 |
j.put("url", url);
|
|
|
579 |
j.put("user_id", userData.getString("id", null));
|
|
|
580 |
j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
581 |
jsArray.put(j);
|
|
|
582 |
AsyncTaskCompat.executeParallel(new pushData(), new JSONObject().put("pushdata", jsArray));
|
|
|
583 |
|
|
|
584 |
}
|
|
|
585 |
storeSubTagId(url);
|
|
|
586 |
}
|
|
|
587 |
}
|
|
|
588 |
catch (Exception e) {
|
|
|
589 |
e.printStackTrace();
|
|
|
590 |
}
|
|
|
591 |
}
|
|
|
592 |
|
|
|
593 |
@Override
|
|
|
594 |
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
|
|
595 |
if (getActivity() != null) {
|
|
|
596 |
SearchFragment nextFrag = new SearchFragment();
|
|
|
597 |
Bundle args = new Bundle();
|
|
|
598 |
args.putString("finishingurl", failingUrl);
|
|
|
599 |
nextFrag.setArguments(args);
|
|
|
600 |
getActivity().getFragmentManager().beginTransaction().replace(R.id.frame_container, nextFrag).addToBackStack(null).commit();
|
|
|
601 |
super.onReceivedError(view, errorCode, description, failingUrl);
|
|
|
602 |
}
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
@Override
|
|
|
606 |
public synchronized void onPageFinished(WebView view, String url) {
|
|
|
607 |
super.onPageFinished(view, url);
|
|
|
608 |
String js =("javascript:document.getElementById('otp').value ='" +322 +"'" );
|
|
|
609 |
if (Build.VERSION.SDK_INT >= 19) {
|
|
|
610 |
view.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
611 |
@Override
|
|
|
612 |
public void onReceiveValue(String s) {
|
|
|
613 |
|
|
|
614 |
}
|
|
|
615 |
});
|
|
|
616 |
} else {
|
|
|
617 |
view.loadUrl(js);
|
|
|
618 |
}
|
|
|
619 |
try {
|
|
|
620 |
if (url.equalsIgnoreCase("about:blank")) {
|
|
|
621 |
Log.d("Blankl Url", "Blank Url");
|
|
|
622 |
}
|
|
|
623 |
else {
|
|
|
624 |
if (getActivity() != null) {
|
|
|
625 |
if (url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
|
|
|
626 |
String notificationUrl = apiData.getString("notification.count", "http://45.33.50.227:3001/getNotificationCount") + "?user_id=" + userData.getString("id", "") + "&android_id=" + UtilityFunctions.androidId(getActivity());
|
|
|
627 |
new NotificationCount().getCount(getActivity(), null, notificationUrl);
|
|
|
628 |
new Handler().postDelayed(new Runnable() {
|
|
|
629 |
@Override
|
|
|
630 |
public void run() {
|
|
|
631 |
getActivity().invalidateOptionsMenu();
|
|
|
632 |
}
|
|
|
633 |
}, 1000);
|
|
|
634 |
}
|
|
|
635 |
}
|
|
|
636 |
if (apiData.getString("snapdealException", "true").equalsIgnoreCase("true")) {
|
|
|
637 |
List<String> snapdealExceptionUrlsPass = new ArrayList<>();
|
|
|
638 |
StringTokenizer st = new StringTokenizer(apiData.getString("snapdeal.exception.urls.pass", ""), "|");
|
|
|
639 |
while (st.hasMoreTokens()) {
|
|
|
640 |
snapdealExceptionUrlsPass.add(st.nextToken());
|
|
|
641 |
}
|
|
|
642 |
for (String s : snapdealExceptionUrlsPass) {
|
|
|
643 |
if (url.contains(s)) {
|
|
|
644 |
snapdealException = 0;
|
|
|
645 |
}
|
|
|
646 |
}
|
|
|
647 |
}
|
|
|
648 |
|
|
|
649 |
if (url.contains(apiData.getString("mobile.website.url", "")) || url.equalsIgnoreCase("http://api.profittill.com/categorydeals") || url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
|
|
|
650 |
pd.dismiss();
|
|
|
651 |
}
|
|
|
652 |
if (snapdealPageLoad == 1) {
|
|
|
653 |
snapdealPageLoad = 0;
|
|
|
654 |
}
|
|
|
655 |
if (pd2 != null) {
|
|
|
656 |
pd2.dismiss();
|
|
|
657 |
}
|
|
|
658 |
if (Uri.parse(url).getHost().equalsIgnoreCase("paytm.com")) {
|
|
|
659 |
view.loadUrl("javascript:try{" +
|
|
|
660 |
"var lastUrl=document.URL;" +
|
|
|
661 |
"setInterval(function(){var currentUrl=document.URL;" +
|
|
|
662 |
"if(currentUrl!=lastUrl){window.HTMLOUT.paytmUrls(currentUrl);lastUrl=currentUrl;}},2000)" +
|
|
|
663 |
"}catch(error){Android.onError(error.message);}");
|
|
|
664 |
}
|
|
|
665 |
if (Uri.parse(url).getHost().contains("saholic") && userData.getString("saholic.data", "false").equalsIgnoreCase("true")) {
|
|
|
666 |
saholicUrl = url;
|
|
|
667 |
view.loadUrl("javascript:window.HTMLOUT.saholicHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
668 |
}
|
|
|
669 |
if (url.contains(apiData.getString("amazon.tracking.order.url", ""))) {
|
|
|
670 |
fetchOrderDetails();
|
|
|
671 |
}
|
|
|
672 |
if (displayActionBar) {
|
|
|
673 |
if (url.contains("amazon")) {
|
|
|
674 |
view.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
675 |
pd1.dismiss();
|
|
|
676 |
amazonWebView = new WebView(webView.getContext());
|
|
|
677 |
amazonWebView.setVisibility(View.GONE);
|
|
|
678 |
amazonWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
679 |
amazonWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
680 |
|
|
|
681 |
} else if (url.contains(ProfitTillConstants.PAYTM)) {
|
|
|
682 |
PaytmWebViewClient paytmWebViewClient = new PaytmWebViewClient();
|
|
|
683 |
pd1.dismiss();
|
|
|
684 |
paytmWebView = new WebView(webView.getContext());
|
|
|
685 |
paytmWebView.setVisibility(View.GONE);
|
|
|
686 |
paytmWebView.addJavascriptInterface(new paytmInterface(getActivity()), "HTMLOUT");
|
|
|
687 |
paytmWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
688 |
paytmWebView.loadUrl(getPaytmReferer(url));
|
|
|
689 |
paytmWebView.setWebViewClient(paytmWebViewClient);
|
|
|
690 |
} else {
|
|
|
691 |
view.loadUrl("javascript:window.HTMLOUT.flipkartHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
692 |
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
amazonOrderHistoryWebView = new WebView(webView.getContext());
|
|
|
697 |
amazonOrderHistoryWebView.setVisibility(View.GONE);
|
|
|
698 |
amazonOrderHistoryWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
699 |
amazonOrderHistoryWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
700 |
amazonOrderHistoryWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
701 |
|
|
|
702 |
amazonOrderHistoryCancelledWebView = new WebView(webView.getContext());
|
|
|
703 |
amazonOrderHistoryCancelledWebView.setVisibility(View.GONE);
|
|
|
704 |
amazonOrderHistoryCancelledWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
705 |
amazonOrderHistoryCancelledWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
706 |
amazonOrderHistoryCancelledWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
707 |
|
|
|
708 |
amazonAllUrlsWebView = new WebView(webView.getContext());
|
|
|
709 |
amazonAllUrlsWebView.setVisibility(View.GONE);
|
|
|
710 |
amazonAllUrlsWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
711 |
amazonAllUrlsWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
712 |
amazonAllUrlsWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
713 |
|
|
|
714 |
if (url.contains("https://www.amazon.in/ap/signin")) {
|
|
|
715 |
if (!FLAG) {
|
|
|
716 |
FLAG = true;
|
|
|
717 |
userDataEditor.putString("amazonOrder", "true").commit();
|
|
|
718 |
userDataEditor.putBoolean("amazonLoggedIn", true).commit();
|
|
|
719 |
}
|
|
|
720 |
} else if (FLAG) {
|
|
|
721 |
view.loadUrl("javascript:try{" +
|
|
|
722 |
"var lastUrl=document.URL;" +
|
|
|
723 |
"setInterval(function(){var currentUrl=document.URL;" +
|
|
|
724 |
"if(currentUrl!=lastUrl){window.HTMLOUT.amazonUrls(currentUrl);lastUrl=currentUrl;}},2000)" +
|
|
|
725 |
"}catch(error){Android.onError(error.message);}");
|
|
|
726 |
amazonOrderHistoryWebView = new WebView(webView.getContext());
|
|
|
727 |
amazonOrderHistoryWebView.setVisibility(View.GONE);
|
|
|
728 |
amazonOrderHistoryWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
729 |
amazonOrderHistoryWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
730 |
amazonOrderHistoryWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
731 |
amazonOrderHistoryCancelledWebView = new WebView(webView.getContext());
|
|
|
732 |
amazonOrderHistoryCancelledWebView.setVisibility(View.GONE);
|
|
|
733 |
amazonOrderHistoryCancelledWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
734 |
amazonOrderHistoryCancelledWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
735 |
amazonOrderHistoryCancelledWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
736 |
fetchOrderDetails();
|
|
|
737 |
FLAG = false;
|
|
|
738 |
}
|
|
|
739 |
|
|
|
740 |
if (url.contains("flipkart")) {
|
|
|
741 |
if (Flipkartflag) {
|
|
|
742 |
if (!url.contains("https://www.flipkart.com/login")) {
|
|
|
743 |
processFlipkartHtml();
|
|
|
744 |
Flipkartflag = false;
|
|
|
745 |
}
|
|
|
746 |
}
|
|
|
747 |
else if(url.contains("https://www.flipkart.com/rv/orderConfirmation")){
|
|
|
748 |
processFlipkartHtml();
|
|
|
749 |
}
|
|
|
750 |
else {
|
|
|
751 |
view.loadUrl("javascript:try{" +
|
|
|
752 |
"var lastUrl=document.URL;" +
|
|
|
753 |
"setInterval(function(){var currentUrl=document.URL;" +
|
|
|
754 |
"if(currentUrl!=lastUrl){window.HTMLOUT.flipkartUrls(currentUrl);lastUrl=currentUrl;}},2000)" +
|
|
|
755 |
"}catch(error){Android.onError(error.message);}");
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
}
|
|
|
759 |
|
|
|
760 |
|
|
|
761 |
view.setOnKeyListener(new View.OnKeyListener() {
|
|
|
762 |
@Override
|
|
|
763 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
764 |
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
765 |
WebView webView = (WebView) v;
|
|
|
766 |
switch (keyCode) {
|
|
|
767 |
case KeyEvent.KEYCODE_BACK:
|
|
|
768 |
if ((webView.canGoBack() && !webView.getUrl().contains(apiData.getString("mobile.website.url", null))) || pageRedirect == 2) {
|
|
|
769 |
webView.goBack();
|
|
|
770 |
pageRedirect = 0;
|
|
|
771 |
snapdealPageLoad = 0;
|
|
|
772 |
return true;
|
|
|
773 |
} else if (affliateUrl.contains("flipkart") || affliateUrl.contains("amazon") || affliateUrl.contains("snapdeal") || affliateUrl.contains("saholic") || affliateUrl.contains(apiData.getString("myorders.url", "")) || affliateUrl.contains(apiData.getString("search.url", ""))) {
|
|
|
774 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
775 |
i.putExtra("displayView", "0");
|
|
|
776 |
startActivity(i);
|
|
|
777 |
return true;
|
|
|
778 |
} else if (webView.getUrl().contains(apiData.getString("mobile.website.url", null))) {
|
|
|
779 |
new AlertDialog.Builder(getActivity())
|
|
|
780 |
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
781 |
.setTitle("Exit!")
|
|
|
782 |
.setMessage("Are you sure you want to close?")
|
|
|
783 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
784 |
@Override
|
|
|
785 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
786 |
Intent startMain = new Intent(Intent.ACTION_MAIN);
|
|
|
787 |
startMain.addCategory(Intent.CATEGORY_HOME);
|
|
|
788 |
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
789 |
|
|
|
790 |
startActivity(startMain);
|
|
|
791 |
}
|
|
|
792 |
|
|
|
793 |
})
|
|
|
794 |
.setNegativeButton("No", null)
|
|
|
795 |
.show();
|
|
|
796 |
} else {
|
|
|
797 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
798 |
i.putExtra("displayView", "0");
|
|
|
799 |
startActivity(i);
|
|
|
800 |
return true;
|
|
|
801 |
}
|
|
|
802 |
|
|
|
803 |
break;
|
|
|
804 |
}
|
|
|
805 |
}
|
|
|
806 |
return false;
|
|
|
807 |
}
|
|
|
808 |
});
|
|
|
809 |
}
|
|
|
810 |
} catch (Exception e) {
|
|
|
811 |
e.printStackTrace();
|
|
|
812 |
TestinAgent.uploadException(getActivity(), "On Page Finished", e);
|
|
|
813 |
}
|
|
|
814 |
}
|
|
|
815 |
|
|
|
816 |
}
|
|
|
817 |
|
|
|
818 |
private void processFlipkartHtml() {
|
|
|
819 |
FlipkartWebview fkView = new FlipkartWebview();
|
|
|
820 |
amazonOrderHistoryWebView = new WebView(webView.getContext());
|
|
|
821 |
amazonOrderHistoryWebView.setVisibility(View.GONE);
|
|
|
822 |
String post=apiData.getString("flipkart.response.url","https://www.flipkart.com/rv/accounts");
|
|
|
823 |
amazonOrderHistoryWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36");
|
|
|
824 |
amazonOrderHistoryWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
825 |
amazonOrderHistoryWebView.addJavascriptInterface(new javascriptInterface(webView), "HTMLOUT");
|
|
|
826 |
amazonOrderHistoryWebView.loadUrl(apiData.getString("flipkart.response.url","https://www.flipkart.com/rv/accounts"));
|
|
|
827 |
amazonOrderHistoryWebView.setWebViewClient(fkView);
|
|
|
828 |
}
|
|
|
829 |
class ProcessFlipkartHtml extends AsyncTask<String, Integer, String> {
|
|
|
830 |
ProgressDialog pg1 = null;
|
|
|
831 |
@Override
|
|
|
832 |
protected void onPreExecute() {
|
|
|
833 |
|
|
|
834 |
super.onPreExecute();
|
|
|
835 |
|
|
|
836 |
pg1.show();
|
|
|
837 |
}
|
|
|
838 |
@Override
|
|
|
839 |
protected String doInBackground(String... arg0) {
|
|
|
840 |
try {
|
|
|
841 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
842 |
HttpPost httppost = new HttpPost(apiData.getString("amazon.order.tracking.post.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code", "")), "flipkart"));
|
|
|
843 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
844 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsRawHtml));
|
|
|
845 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
846 |
HttpEntity entity = response.getEntity();
|
|
|
847 |
int status = response.getStatusLine().getStatusCode();
|
|
|
848 |
|
|
|
849 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
850 |
JSONObject jobj =jObjGmail.getJSONObject("result");
|
|
|
851 |
JSONObject headers = jobj.getJSONObject("headers");
|
|
|
852 |
JSONArray url =jobj.getJSONArray("urls");
|
|
|
853 |
for (int i = 0; i <url.length(); i++) {
|
|
|
854 |
HttpClient client = new DefaultHttpClient();
|
|
|
855 |
HttpGet get = new HttpGet(url.getString(i));
|
|
|
856 |
Map<String, String> map = new HashMap<String, String>();
|
|
|
857 |
Iterator iter = headers.keys();
|
|
|
858 |
while (iter.hasNext()) {
|
|
|
859 |
String key = (String) iter.next();
|
|
|
860 |
String value = headers.getString(key);
|
|
|
861 |
get.setHeader(key, value);
|
|
|
862 |
}
|
|
|
863 |
HttpResponse resp = client.execute(get);
|
|
|
864 |
HttpEntity ent = resp.getEntity();
|
|
|
865 |
JSONObject jOb = new JSONObject(EntityUtils.toString(ent));
|
|
|
866 |
|
|
|
867 |
HttpClient http = new DefaultHttpClient();
|
|
|
868 |
ArrayList<NameValuePair> namevaluepairs = new ArrayList<>();
|
|
|
869 |
namevaluepairs.add(new BasicNameValuePair("html",UtilityFunctions.compress(jOb.toString())));
|
|
|
870 |
namevaluepairs.add(new BasicNameValuePair("url", url.getString(i)));
|
|
|
871 |
namevaluepairs.add(new BasicNameValuePair("zip","1"));
|
|
|
872 |
HttpPost post = new HttpPost(apiData.getString("amazon.order.tracking.post.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code", "")), "flipkart"));
|
|
|
873 |
post.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
874 |
post.setEntity(new UrlEncodedFormEntity(namevaluepairs));
|
|
|
875 |
HttpResponse res = http.execute(post);
|
|
|
876 |
int sta = res.getStatusLine().getStatusCode();
|
|
|
877 |
}
|
|
|
878 |
|
|
|
879 |
}
|
|
|
880 |
catch (Exception e) {
|
|
|
881 |
e.printStackTrace();
|
|
|
882 |
return null;
|
|
|
883 |
}
|
|
|
884 |
return null;
|
|
|
885 |
}
|
|
|
886 |
@Override
|
|
|
887 |
protected void onPostExecute(String jsonObject) {
|
|
|
888 |
super.onPostExecute(jsonObject);
|
|
|
889 |
|
|
|
890 |
pg1.dismiss();
|
|
|
891 |
|
|
|
892 |
}}
|
|
|
893 |
|
|
|
894 |
@Override
|
|
|
895 |
public void onResume() {
|
|
|
896 |
super.onResume();
|
|
|
897 |
getView().setFocusableInTouchMode(true);
|
|
|
898 |
getView().requestFocus();
|
|
|
899 |
getView().setOnKeyListener(new View.OnKeyListener() {
|
|
|
900 |
@Override
|
|
|
901 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
902 |
|
|
|
903 |
if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
904 |
try {
|
|
|
905 |
if (landingURL.contains((apiData.getString("mobile.website.url", "")))) {
|
|
|
906 |
new AlertDialog.Builder(getActivity())
|
|
|
907 |
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
908 |
.setTitle("Exit!")
|
|
|
909 |
.setMessage("Are you sure you want to close?")
|
|
|
910 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
911 |
@Override
|
|
|
912 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
913 |
Intent startMain = new Intent(Intent.ACTION_MAIN);
|
|
|
914 |
startMain.addCategory(Intent.CATEGORY_HOME);
|
|
|
915 |
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
916 |
startActivity(startMain);
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
})
|
|
|
920 |
.setNegativeButton("No", null)
|
|
|
921 |
.show();
|
|
|
922 |
return true;
|
|
|
923 |
} else {
|
|
|
924 |
if (webView.canGoBack()) {
|
|
|
925 |
webView.goBack();
|
|
|
926 |
} else {
|
|
|
927 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
928 |
i.putExtra("displayView", "0");
|
|
|
929 |
startActivity(i);
|
|
|
930 |
}
|
|
|
931 |
return true;
|
|
|
932 |
|
|
|
933 |
}
|
|
|
934 |
|
|
|
935 |
} catch (Exception e) {
|
|
|
936 |
e.printStackTrace();
|
|
|
937 |
return false;
|
|
|
938 |
}
|
|
|
939 |
}
|
|
|
940 |
return false;
|
|
|
941 |
}
|
|
|
942 |
|
|
|
943 |
});
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
|
|
|
947 |
public void fetchOrderDetails() {
|
|
|
948 |
if (isInternetOn()) {
|
|
|
949 |
new FetchOrderURLS().execute();
|
|
|
950 |
}
|
|
|
951 |
}
|
|
|
952 |
|
|
|
953 |
public void pushDataInAmazon(String orderId) {
|
|
|
954 |
|
|
|
955 |
AmazonOrderDetails amazonOrderClient = new AmazonOrderDetails();
|
|
|
956 |
nameValuePairsRawHtmlAmazon = new ArrayList<NameValuePair>();
|
|
|
957 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
|
|
|
958 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("id", orderId));
|
|
|
959 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("store_id", apiData.getString("store.code.amazon", null)));
|
|
|
960 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("order_url", amazonData.getString("amazonurl", "")));
|
|
|
961 |
//nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("sub_tag",userData.getString("subtag",null)));
|
|
|
962 |
amazonWebView.loadUrl(amazonData.getString("amazonurl", ""));
|
|
|
963 |
amazonWebView.setWebViewClient(amazonOrderClient);
|
|
|
964 |
|
|
|
965 |
}
|
|
|
966 |
|
|
|
967 |
public void storeSubTagId(String url) {
|
|
|
968 |
|
|
|
969 |
if (url.contains(apiData.getString("store.subtag.snapdeal", null)) || url.contains(apiData.getString("store.subtag.flipkart", null)) || url.contains(apiData.getString("store.subtag.amazon", null)) || url.contains(apiData.getString("store.subtag.shopclues", "UID")) || url.contains(apiData.getString("store.subtag.paytm", "utm_term"))) {
|
|
|
970 |
StringTokenizer st2 = new StringTokenizer(url, "&");
|
|
|
971 |
while (st2.hasMoreElements()) {
|
|
|
972 |
String token = st2.nextToken();
|
|
|
973 |
if (token.contains(apiData.getString("store.subtag.snapdeal", null)) || token.contains(apiData.getString("store.subtag.flipkart", null)) || token.contains(apiData.getString("store.subtag.amazon", null)) || token.contains(apiData.getString("store.subtag.shopclues", "UID")) || token.contains(apiData.getString("store.subtag.paytm", "utm_term"))) {
|
|
|
974 |
String subtagId = userData.getString("subtag", "null");
|
|
|
975 |
if (subtagId == null) {
|
|
|
976 |
userDataEditor.putString("subtag", token.split("=")[1]);
|
|
|
977 |
userDataEditor.commit();
|
|
|
978 |
} else {
|
|
|
979 |
userDataEditor.remove("subtag");
|
|
|
980 |
userDataEditor.commit();
|
|
|
981 |
userDataEditor.putString("subtag", token.split("=")[1]);
|
|
|
982 |
userDataEditor.commit();
|
|
|
983 |
}
|
|
|
984 |
} else
|
|
|
985 |
continue;
|
|
|
986 |
}
|
|
|
987 |
} else
|
|
|
988 |
return;
|
|
|
989 |
}
|
|
|
990 |
|
|
|
991 |
|
|
|
992 |
boolean displayActionBar;
|
|
|
993 |
|
|
|
994 |
public void getDisplayActionBar(String url) throws Exception {
|
|
|
995 |
String snapdealConfirmation = apiData.getString("snapdeal.order.success.url", null);
|
|
|
996 |
String flipkartConfirmation = apiData.getString("flipkart.order.success.url", null);
|
|
|
997 |
String amazonConfirmation = apiData.getString("amazon.order.success.url", null);
|
|
|
998 |
String amazonThankYouConfirmation = apiData.getString("amazon.order.success.thankyou.url", null);
|
|
|
999 |
String saholicConfirmation = apiData.getString("saholic.order.success.url", null);
|
|
|
1000 |
if (url.contains(snapdealConfirmation) || url.contains(flipkartConfirmation) || url.contains(amazonConfirmation) || url.contains(amazonThankYouConfirmation) || url.contains(saholicConfirmation)) {
|
|
|
1001 |
displayActionBar = true;
|
|
|
1002 |
String storeID = getStoreId(url);
|
|
|
1003 |
if (storeID == null) {
|
|
|
1004 |
Log.e("Deals Page Activity", "Null value returned for storeID");
|
|
|
1005 |
} else {
|
|
|
1006 |
nameValuePairsRawHtml = new ArrayList<NameValuePair>();
|
|
|
1007 |
nameValuePairsRawHtml.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
|
|
|
1008 |
nameValuePairsRawHtml.add(new BasicNameValuePair("store_id", storeID));
|
|
|
1009 |
nameValuePairsRawHtml.add(new BasicNameValuePair("order_url", url));
|
|
|
1010 |
nameValuePairsRawHtml.add(new BasicNameValuePair("sub_tag", userData.getString("subtag", null)));
|
|
|
1011 |
}
|
|
|
1012 |
} else {
|
|
|
1013 |
displayActionBar = false;
|
|
|
1014 |
}
|
|
|
1015 |
return;
|
|
|
1016 |
}
|
|
|
1017 |
|
|
|
1018 |
public void getOrderSuccessUrlConfirmation(String url) throws Exception {
|
|
|
1019 |
for (String s : orderSuccessUrlList) {
|
|
|
1020 |
if (url.contains(s)) {
|
|
|
1021 |
displayActionBar = true;
|
|
|
1022 |
String storeID = getStoreId(url);
|
|
|
1023 |
if (storeID == null) {
|
|
|
1024 |
Log.e("Deals Page Activity", "Null value returned for storeID");
|
|
|
1025 |
} else {
|
|
|
1026 |
nameValuePairsRawHtml = new ArrayList<NameValuePair>();
|
|
|
1027 |
nameValuePairsRawHtml.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
|
|
|
1028 |
nameValuePairsRawHtml.add(new BasicNameValuePair("store_id", storeID));
|
|
|
1029 |
nameValuePairsRawHtml.add(new BasicNameValuePair("order_url", url));
|
|
|
1030 |
nameValuePairsRawHtml.add(new BasicNameValuePair("sub_tag", userData.getString("subtag", "")));
|
|
|
1031 |
}
|
|
|
1032 |
break;
|
|
|
1033 |
} else {
|
|
|
1034 |
displayActionBar = false;
|
|
|
1035 |
}
|
|
|
1036 |
}
|
|
|
1037 |
return;
|
|
|
1038 |
}
|
|
|
1039 |
|
|
|
1040 |
public String getStoreId(String url) {
|
|
|
1041 |
/* if(url.contains("snapdeal")){
|
|
|
1042 |
pageRedirect=Integer.parseInt(apiData.getString("pageredirect.snapdeal","0"));
|
|
|
1043 |
return apiData.getString("store.code.snapdeal",null);
|
|
|
1044 |
}
|
|
|
1045 |
else if(url.contains("flipkart")){
|
|
|
1046 |
pageRedirect=Integer.parseInt(apiData.getString("pageredirect.flipkart","0"));
|
|
|
1047 |
return apiData.getString("store.code.flipkart",null);
|
|
|
1048 |
}
|
|
|
1049 |
else if(url.contains("amazon")){
|
|
|
1050 |
pageRedirect=Integer.parseInt(apiData.getString("pageredirect.amazon","0"));
|
|
|
1051 |
return apiData.getString("store.code.amazon",null);
|
|
|
1052 |
}
|
|
|
1053 |
else if(url.contains("saholic")){
|
|
|
1054 |
return apiData.getString("store.code.spice",null);
|
|
|
1055 |
}
|
|
|
1056 |
else if(url.contains("shopclues")){
|
|
|
1057 |
return "7";
|
|
|
1058 |
}*/
|
|
|
1059 |
return UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code", "amazon=1,flipkart=2,snapdeal=3,saholic=4,shopclues=5,")), url);
|
|
|
1060 |
}
|
|
|
1061 |
|
|
|
1062 |
class pushData extends AsyncTask<JSONObject, Integer, String> {
|
|
|
1063 |
|
|
|
1064 |
@Override
|
|
|
1065 |
protected void onPreExecute() {
|
|
|
1066 |
|
|
|
1067 |
super.onPreExecute();
|
|
|
1068 |
}
|
|
|
1069 |
|
|
|
1070 |
@Override
|
|
|
1071 |
protected String doInBackground(JSONObject... objs) {
|
|
|
1072 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1073 |
try {
|
|
|
1074 |
ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
|
|
|
1075 |
nameValuePairs.add(new BasicNameValuePair("pushdata",objs[0].toString()));
|
|
|
1076 |
HttpPost httppost = new HttpPost(apiData.getString("url.push.api", null));
|
|
|
1077 |
httppost.setHeader("Authorization", BASIC_AUTH);
|
|
|
1078 |
|
|
|
1079 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
1080 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1081 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1082 |
|
|
|
1083 |
if (status == 200) {
|
|
|
1084 |
return "success";
|
|
|
1085 |
} else {
|
|
|
1086 |
return "failure";
|
|
|
1087 |
}
|
|
|
1088 |
|
|
|
1089 |
} catch (ClientProtocolException e) {
|
|
|
1090 |
return "failure";
|
|
|
1091 |
} catch (IOException e) {
|
|
|
1092 |
return "failure";
|
|
|
1093 |
}
|
|
|
1094 |
}
|
|
|
1095 |
|
|
|
1096 |
@Override
|
|
|
1097 |
protected void onPostExecute(String result) {
|
|
|
1098 |
super.onPostExecute(result);
|
|
|
1099 |
}
|
|
|
1100 |
}
|
|
|
1101 |
|
|
|
1102 |
ArrayList<NameValuePair> nameValuePairsRawHtml = new ArrayList<NameValuePair>();
|
|
|
1103 |
ArrayList<NameValuePair> nameValuePairsRawHtmlAmazon = new ArrayList<NameValuePair>();
|
|
|
1104 |
|
|
|
1105 |
class javascriptInterface {
|
|
|
1106 |
|
|
|
1107 |
WebView view;
|
|
|
1108 |
|
|
|
1109 |
@JavascriptInterface
|
|
|
1110 |
public void otpSent() {
|
|
|
1111 |
getActivity().registerReceiver(smsListener, new IntentFilter(SMS_RECEIVED));
|
|
|
1112 |
}
|
|
|
1113 |
|
|
|
1114 |
|
|
|
1115 |
/**
|
|
|
1116 |
* Instantiate the interface and set the context
|
|
|
1117 |
*/
|
|
|
1118 |
public javascriptInterface(WebView c) {
|
|
|
1119 |
|
|
|
1120 |
this.view=c;
|
|
|
1121 |
}
|
|
|
1122 |
|
|
|
1123 |
@JavascriptInterface
|
|
|
1124 |
public void performClick(String strl) {
|
|
|
1125 |
Toast.makeText(getActivity(), strl, Toast.LENGTH_SHORT).show();
|
|
|
1126 |
|
|
|
1127 |
}
|
|
|
1128 |
@JavascriptInterface
|
|
|
1129 |
public void authTokenChange(String newToken) {
|
|
|
1130 |
new AuthtokenChange().execute();
|
|
|
1131 |
|
|
|
1132 |
}
|
|
|
1133 |
|
|
|
1134 |
@JavascriptInterface
|
|
|
1135 |
public void showToast(String toast) {
|
|
|
1136 |
nameValuePairsRawHtml.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(toast)));
|
|
|
1137 |
long x = orderDetails.insertOrderDetails(nameValuePairsRawHtml);
|
|
|
1138 |
List<List<NameValuePair>> postDataNameValuePair = new ArrayList<List<NameValuePair>>();
|
|
|
1139 |
postDataNameValuePair = orderDetails.readData1();
|
|
|
1140 |
for (List<NameValuePair> orderDetail : postDataNameValuePair) {
|
|
|
1141 |
orderDetail.add(new BasicNameValuePair("zip", "1"));
|
|
|
1142 |
orderDetail.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1143 |
orderDetail.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1144 |
orderDetail.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1145 |
PushRawHTML pm = new PushRawHTML();
|
|
|
1146 |
pm.execute(orderDetail);
|
|
|
1147 |
}
|
|
|
1148 |
}
|
|
|
1149 |
|
|
|
1150 |
@JavascriptInterface
|
|
|
1151 |
public void amazonOrderTrackingHTML(String html) {
|
|
|
1152 |
amazonOrderTrackingData.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(html)));
|
|
|
1153 |
amazonOrderTrackingData.add(new BasicNameValuePair("zip", "1"));
|
|
|
1154 |
amazonOrderTrackingData.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1155 |
amazonOrderTrackingData.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1156 |
amazonOrderTrackingData.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1157 |
new AmazonOrderTrackingDetails().execute(amazonOrderTrackingData);
|
|
|
1158 |
}
|
|
|
1159 |
|
|
|
1160 |
@JavascriptInterface
|
|
|
1161 |
public void showHTML(String html) {
|
|
|
1162 |
|
|
|
1163 |
showToast(html);
|
|
|
1164 |
}
|
|
|
1165 |
|
|
|
1166 |
@JavascriptInterface
|
|
|
1167 |
public void flipkartHTML(String html) {
|
|
|
1168 |
nameValuePairsRawHtml.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(html)));
|
|
|
1169 |
long x = orderDetails.insertOrderDetails(nameValuePairsRawHtml);
|
|
|
1170 |
List<List<NameValuePair>> postDataNameValuePair = new ArrayList<List<NameValuePair>>();
|
|
|
1171 |
postDataNameValuePair = orderDetails.readData1();
|
|
|
1172 |
for (List<NameValuePair> orderDetail : postDataNameValuePair) {
|
|
|
1173 |
orderDetail.add(new BasicNameValuePair("zip", "1"));
|
|
|
1174 |
orderDetail.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1175 |
orderDetail.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1176 |
orderDetail.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1177 |
new loadData().execute(orderDetail);
|
|
|
1178 |
}
|
|
|
1179 |
}
|
|
|
1180 |
|
|
|
1181 |
@JavascriptInterface
|
|
|
1182 |
public void orderpage(String html) {
|
|
|
1183 |
|
|
|
1184 |
nameValuePairsRawHtml.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
|
|
|
1185 |
nameValuePairsRawHtml.add(new BasicNameValuePair("url",apiData.getString("flipkart.response.url","")));
|
|
|
1186 |
nameValuePairsRawHtml.add(new BasicNameValuePair("zip","1"));
|
|
|
1187 |
new ProcessFlipkartHtml().execute();
|
|
|
1188 |
}
|
|
|
1189 |
|
|
|
1190 |
@JavascriptInterface
|
|
|
1191 |
public void saholicHTML(String html) {
|
|
|
1192 |
|
|
|
1193 |
try {
|
|
|
1194 |
obj = new JSONObject();
|
|
|
1195 |
jSaholic = new JSONObject();
|
|
|
1196 |
jSaholic.put("html", UtilityFunctions.compress(html));
|
|
|
1197 |
jSaholic.put("zip", "1");
|
|
|
1198 |
jSaholic.put("user_id", userData.getString("id", null));
|
|
|
1199 |
} catch (Exception e) {
|
|
|
1200 |
|
|
|
1201 |
}
|
|
|
1202 |
new checkGateWayProblem().execute(saholicUrl);
|
|
|
1203 |
}
|
|
|
1204 |
|
|
|
1205 |
@JavascriptInterface
|
|
|
1206 |
public void amazonUrls(String url) {
|
|
|
1207 |
try {
|
|
|
1208 |
obj = new JSONObject();
|
|
|
1209 |
JSONObject j = new JSONObject();
|
|
|
1210 |
JSONArray jsArray = new JSONArray();
|
|
|
1211 |
j.put("url", url);
|
|
|
1212 |
j.put("user_id", userData.getString("id", null));
|
|
|
1213 |
j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
1214 |
jsArray.put(j);
|
|
|
1215 |
obj.put("pushdata", jsArray);
|
|
|
1216 |
new pushData().execute(obj);
|
|
|
1217 |
} catch (Exception e) {
|
|
|
1218 |
e.printStackTrace();
|
|
|
1219 |
}
|
|
|
1220 |
|
|
|
1221 |
try {
|
|
|
1222 |
getOrderSuccessUrlConfirmation(url);
|
|
|
1223 |
if (displayActionBar) {
|
|
|
1224 |
fetchAmazonOrder(url);
|
|
|
1225 |
}
|
|
|
1226 |
} catch (Exception e) {
|
|
|
1227 |
e.printStackTrace();
|
|
|
1228 |
}
|
|
|
1229 |
}
|
|
|
1230 |
|
|
|
1231 |
@JavascriptInterface
|
|
|
1232 |
public void paytmUrls(String html) {
|
|
|
1233 |
try {
|
|
|
1234 |
obj = new JSONObject();
|
|
|
1235 |
JSONObject j = new JSONObject();
|
|
|
1236 |
JSONArray jsArray = new JSONArray();
|
|
|
1237 |
j.put("url", html);
|
|
|
1238 |
j.put("user_id", userData.getString("id", null));
|
|
|
1239 |
j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
1240 |
jsArray.put(j);
|
|
|
1241 |
obj.put("pushdata", jsArray);
|
|
|
1242 |
new pushData().execute(obj);
|
|
|
1243 |
} catch (Exception e) {
|
|
|
1244 |
e.printStackTrace();
|
|
|
1245 |
}
|
|
|
1246 |
if (html.contains("https://paytm.com/login")) {
|
|
|
1247 |
if (!PAYTMFLAG) {
|
|
|
1248 |
PAYTMFLAG = true;
|
|
|
1249 |
userDataEditor.putString("paytmOrder", "true").commit();
|
|
|
1250 |
userDataEditor.putBoolean("paytmLoggedIn", true).commit();
|
|
|
1251 |
}
|
|
|
1252 |
} else if (PAYTMFLAG) {
|
|
|
1253 |
new PaytmOrderURL().execute();
|
|
|
1254 |
PAYTMFLAG = false;
|
|
|
1255 |
}
|
|
|
1256 |
|
|
|
1257 |
}
|
|
|
1258 |
|
|
|
1259 |
@JavascriptInterface
|
|
|
1260 |
public void flipkartUrls(String url) {
|
|
|
1261 |
try {
|
|
|
1262 |
obj = new JSONObject();
|
|
|
1263 |
JSONObject j = new JSONObject();
|
|
|
1264 |
JSONArray jsArray = new JSONArray();
|
|
|
1265 |
j.put("url", url);
|
|
|
1266 |
j.put("user_id", userData.getString("id", null));
|
|
|
1267 |
j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
1268 |
jsArray.put(j);
|
|
|
1269 |
obj.put("pushdata", jsArray);
|
|
|
1270 |
new pushData().execute(obj);
|
|
|
1271 |
} catch (Exception e) {
|
|
|
1272 |
e.printStackTrace();
|
|
|
1273 |
}
|
|
|
1274 |
if (url.contains("https://www.flipkart.com/login")) {
|
|
|
1275 |
Flipkartflag = true;
|
|
|
1276 |
userDataEditor.putString("flipkartOrder", "true").commit();
|
|
|
1277 |
userDataEditor.putBoolean("flipkartLoggedIn", true).commit();
|
|
|
1278 |
}
|
|
|
1279 |
}
|
|
|
1280 |
}
|
|
|
1281 |
class AuthtokenChange extends AsyncTask<String, Integer, String> {
|
|
|
1282 |
|
|
|
1283 |
@Override
|
|
|
1284 |
protected void onPreExecute() {
|
|
|
1285 |
|
|
|
1286 |
super.onPreExecute();
|
|
|
1287 |
}
|
|
|
1288 |
@Override
|
|
|
1289 |
protected String doInBackground(String... params) {
|
|
|
1290 |
try {
|
|
|
1291 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1292 |
HttpPost httppost = new HttpPost(ProfitTillConstants.Web_Api+"/user/token-info");
|
|
|
1293 |
httppost.setHeader("Auth-Token",userData.getString("token",""));
|
|
|
1294 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1295 |
HttpEntity entity = response.getEntity();
|
|
|
1296 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1297 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
1298 |
return String.valueOf(jObjGmail);
|
|
|
1299 |
|
|
|
1300 |
}
|
|
|
1301 |
catch (UnsupportedEncodingException e) {
|
|
|
1302 |
e.printStackTrace();
|
|
|
1303 |
}
|
|
|
1304 |
catch (IOException e) {
|
|
|
1305 |
e.printStackTrace();
|
|
|
1306 |
} catch (JSONException e) {
|
|
|
1307 |
e.printStackTrace();
|
|
|
1308 |
}
|
|
|
1309 |
return null;
|
|
|
1310 |
}
|
|
|
1311 |
|
|
|
1312 |
}
|
|
|
1313 |
|
|
|
1314 |
class loadData extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
|
|
|
1315 |
|
|
|
1316 |
@Override
|
|
|
1317 |
protected void onPreExecute() {
|
|
|
1318 |
super.onPreExecute();
|
|
|
1319 |
}
|
|
|
1320 |
|
|
|
1321 |
@Override
|
|
|
1322 |
protected JSONObject doInBackground(List<NameValuePair>... orderDetail) {
|
|
|
1323 |
|
|
|
1324 |
|
|
|
1325 |
try {
|
|
|
1326 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1327 |
HttpPost httppost = new HttpPost(apiData.getString("orderpagehtml.push.api", null));
|
|
|
1328 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1329 |
|
|
|
1330 |
httppost.setEntity(new UrlEncodedFormEntity(orderDetail[0]));
|
|
|
1331 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1332 |
HttpEntity entity = response.getEntity();
|
|
|
1333 |
|
|
|
1334 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1335 |
|
|
|
1336 |
if (status == 200) {
|
|
|
1337 |
NameValuePair y = orderDetail[0].get(2);
|
|
|
1338 |
int z = orderDetails.deleteRecord(y.getName(), new String[]{y.getValue()});
|
|
|
1339 |
} else {
|
|
|
1340 |
Log.d("Status in load Data ", "Status Load data " + status);
|
|
|
1341 |
|
|
|
1342 |
}
|
|
|
1343 |
String getJSON = EntityUtils.toString(entity);
|
|
|
1344 |
if (getJSON == null) {
|
|
|
1345 |
return null;
|
|
|
1346 |
} else {
|
|
|
1347 |
JSONObject jObjGmail = new JSONObject(getJSON);
|
|
|
1348 |
return jObjGmail;
|
|
|
1349 |
}
|
|
|
1350 |
} catch (Exception e) {
|
|
|
1351 |
return null;
|
|
|
1352 |
}
|
|
|
1353 |
}
|
|
|
1354 |
|
|
|
1355 |
|
|
|
1356 |
@Override
|
|
|
1357 |
protected void onPostExecute(JSONObject result) {
|
|
|
1358 |
if (result == null) {
|
|
|
1359 |
//Log.d("Error in fetching result ", "Flipkart html ");
|
|
|
1360 |
} else {
|
|
|
1361 |
try {
|
|
|
1362 |
if (result.getString("message").equalsIgnoreCase("PROCESSED"))
|
|
|
1363 |
orderDetails.deleterecords();
|
|
|
1364 |
} catch (Exception e) {
|
|
|
1365 |
}
|
|
|
1366 |
}
|
|
|
1367 |
super.onPostExecute(result);
|
|
|
1368 |
}
|
|
|
1369 |
}
|
|
|
1370 |
|
|
|
1371 |
class AmazonOrderDetails extends WebViewClient {
|
|
|
1372 |
|
|
|
1373 |
@Override
|
|
|
1374 |
public void onReceivedHttpAuthRequest(WebView view,
|
|
|
1375 |
HttpAuthHandler handler, String host, String realm) {
|
|
|
1376 |
|
|
|
1377 |
handler.proceed("dtr", "dtr18Feb2015");
|
|
|
1378 |
|
|
|
1379 |
}
|
|
|
1380 |
|
|
|
1381 |
@Override
|
|
|
1382 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
1383 |
super.onPageStarted(view, url, favicon);
|
|
|
1384 |
}
|
|
|
1385 |
|
|
|
1386 |
@Override
|
|
|
1387 |
public void onPageFinished(WebView view, String url) {
|
|
|
1388 |
view.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
1389 |
super.onPageFinished(view, url);
|
|
|
1390 |
}
|
|
|
1391 |
}
|
|
|
1392 |
|
|
|
1393 |
class amazonInterface {
|
|
|
1394 |
|
|
|
1395 |
Context mContext;
|
|
|
1396 |
|
|
|
1397 |
/**
|
|
|
1398 |
* Instantiate the interface and set the context
|
|
|
1399 |
*/
|
|
|
1400 |
public amazonInterface(Context c) {
|
|
|
1401 |
mContext = c;
|
|
|
1402 |
}
|
|
|
1403 |
|
|
|
1404 |
/**
|
|
|
1405 |
* Show a toast from the web page
|
|
|
1406 |
*/
|
|
|
1407 |
@JavascriptInterface
|
|
|
1408 |
public void showToast(String toast) {
|
|
|
1409 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(toast)));
|
|
|
1410 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("zip", "1"));
|
|
|
1411 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1412 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1413 |
nameValuePairsRawHtmlAmazon.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1414 |
if (isInternetOn()) {
|
|
|
1415 |
new amazonPushData().execute(nameValuePairsRawHtmlAmazon);
|
|
|
1416 |
}
|
|
|
1417 |
}
|
|
|
1418 |
|
|
|
1419 |
|
|
|
1420 |
@JavascriptInterface
|
|
|
1421 |
public void showHTML(String html) {
|
|
|
1422 |
showToast(html);
|
|
|
1423 |
}
|
|
|
1424 |
|
|
|
1425 |
@JavascriptInterface
|
|
|
1426 |
public void orderHistory(String html) {
|
|
|
1427 |
List<NameValuePair> amazonOrderHistory = new ArrayList<>();
|
|
|
1428 |
amazonOrderHistory.add(new BasicNameValuePair("url", str.get(0)));
|
|
|
1429 |
amazonOrderHistory.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
|
|
|
1430 |
amazonOrderHistory.add(new BasicNameValuePair("zip", "1"));
|
|
|
1431 |
amazonOrderHistory.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1432 |
amazonOrderHistory.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1433 |
amazonOrderHistory.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1434 |
if (isInternetOn()) {
|
|
|
1435 |
new pushQueuedData().execute(amazonOrderHistory);
|
|
|
1436 |
userDataEditor.putLong("amazonNextFetchTime", System.currentTimeMillis() + ProfitTillConstants.DURATION_TRACKING_ORDERS).commit();
|
|
|
1437 |
}
|
|
|
1438 |
}
|
|
|
1439 |
|
|
|
1440 |
@JavascriptInterface
|
|
|
1441 |
public void cancelledHistory(String html) {
|
|
|
1442 |
List<NameValuePair> amazonOrderHistory = new ArrayList<>();
|
|
|
1443 |
amazonOrderHistory.add(new BasicNameValuePair("url", str.get(j++)));
|
|
|
1444 |
amazonOrderHistory.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
|
|
|
1445 |
amazonOrderHistory.add(new BasicNameValuePair("zip", "1"));
|
|
|
1446 |
amazonOrderHistory.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1447 |
amazonOrderHistory.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1448 |
amazonOrderHistory.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1449 |
if (isInternetOn()) {
|
|
|
1450 |
new pushCancelledQueuedData().execute(amazonOrderHistory);
|
|
|
1451 |
userDataEditor.putLong("amazonNextFetchTime", System.currentTimeMillis() + ProfitTillConstants.DURATION_TRACKING_ORDERS).commit();
|
|
|
1452 |
}
|
|
|
1453 |
}
|
|
|
1454 |
|
|
|
1455 |
@JavascriptInterface
|
|
|
1456 |
public void amazonOrderUrls(String html) {
|
|
|
1457 |
//Log.e("OrderUrls","Order amazonOrderUrls" + html);
|
|
|
1458 |
List<NameValuePair> amazonOrderHistory = new ArrayList<>();
|
|
|
1459 |
amazonOrderHistory.add(new BasicNameValuePair("url", str.get(1)));
|
|
|
1460 |
amazonOrderHistory.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
|
|
|
1461 |
amazonOrderHistory.add(new BasicNameValuePair("zip", "1"));
|
|
|
1462 |
amazonOrderHistory.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1463 |
amazonOrderHistory.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1464 |
amazonOrderHistory.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1465 |
if (isInternetOn()) {
|
|
|
1466 |
new pushCancelledQueuedData().execute(amazonOrderHistory);
|
|
|
1467 |
} else {
|
|
|
1468 |
|
|
|
1469 |
}
|
|
|
1470 |
}
|
|
|
1471 |
|
|
|
1472 |
}
|
|
|
1473 |
|
|
|
1474 |
int j;
|
|
|
1475 |
|
|
|
1476 |
class amazonPushData extends AsyncTask<List<NameValuePair>, Integer, String> {
|
|
|
1477 |
private StringBuilder sb;
|
|
|
1478 |
|
|
|
1479 |
private HttpResponse req;
|
|
|
1480 |
private InputStream is;
|
|
|
1481 |
|
|
|
1482 |
@Override
|
|
|
1483 |
protected void onPreExecute() {
|
|
|
1484 |
super.onPreExecute();
|
|
|
1485 |
Log.e("Pre execute", "Pre execute");
|
|
|
1486 |
|
|
|
1487 |
}
|
|
|
1488 |
|
|
|
1489 |
@Override
|
|
|
1490 |
protected String doInBackground(List<NameValuePair>... orderDetail) {
|
|
|
1491 |
try {
|
|
|
1492 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1493 |
HttpPost httppost = new HttpPost(apiData.getString("orderpagehtml.push.api", null));
|
|
|
1494 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1495 |
httppost.setEntity(new UrlEncodedFormEntity(orderDetail[0]));
|
|
|
1496 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1497 |
HttpEntity entity = response.getEntity();
|
|
|
1498 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1499 |
|
|
|
1500 |
if (status == 200) {
|
|
|
1501 |
System.out.println("ResponseCode of record: " + status + " is " + status);
|
|
|
1502 |
NameValuePair y = orderDetail[0].get(2);
|
|
|
1503 |
int z = orderDetails.deleteRecord(y.getName(), new String[]{y.getValue()});
|
|
|
1504 |
amazonapiSettingsEditor.remove("amazonurl");
|
|
|
1505 |
amazonapiSettingsEditor.commit();
|
|
|
1506 |
} else {
|
|
|
1507 |
/*Log.d("ResponseCode",status+"");
|
|
|
1508 |
System.out.println(" NOT Transfered");
|
|
|
1509 |
Log.d("ResponseCode",status+"");*/
|
|
|
1510 |
}
|
|
|
1511 |
/* Log.e("pass 1", "Amazon success ");*/
|
|
|
1512 |
} catch (Exception e) {
|
|
|
1513 |
/* Log.e("Fail 1", e.toString());*/
|
|
|
1514 |
|
|
|
1515 |
}
|
|
|
1516 |
return "success";
|
|
|
1517 |
}
|
|
|
1518 |
|
|
|
1519 |
@Override
|
|
|
1520 |
protected void onPostExecute(String result) {
|
|
|
1521 |
super.onPostExecute(result);
|
|
|
1522 |
new FetchOrderURLS().execute();
|
|
|
1523 |
}
|
|
|
1524 |
}
|
|
|
1525 |
|
|
|
1526 |
|
|
|
1527 |
class PushRawHTML extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
|
|
|
1528 |
@Override
|
|
|
1529 |
protected void onPreExecute() {
|
|
|
1530 |
super.onPreExecute();
|
|
|
1531 |
}
|
|
|
1532 |
|
|
|
1533 |
@Override
|
|
|
1534 |
protected JSONObject doInBackground(List<NameValuePair>... orderDetail) {
|
|
|
1535 |
|
|
|
1536 |
try {
|
|
|
1537 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1538 |
HttpPost httppost = new HttpPost(apiData.getString("orderpagehtml.push.api", null));
|
|
|
1539 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1540 |
httppost.setEntity(new UrlEncodedFormEntity(orderDetail[0]));
|
|
|
1541 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1542 |
HttpEntity entity = response.getEntity();
|
|
|
1543 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1544 |
|
|
|
1545 |
if (status == 200) {
|
|
|
1546 |
NameValuePair y = orderDetail[0].get(2);
|
|
|
1547 |
int z = orderDetails.deleteRecord(y.getName(), new String[]{y.getValue()});
|
|
|
1548 |
} else {
|
|
|
1549 |
}
|
|
|
1550 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
1551 |
|
|
|
1552 |
return jObjGmail;
|
|
|
1553 |
} catch (Exception e) {
|
|
|
1554 |
return null;
|
|
|
1555 |
}
|
|
|
1556 |
}
|
|
|
1557 |
|
|
|
1558 |
@Override
|
|
|
1559 |
protected void onPostExecute(JSONObject result) {
|
|
|
1560 |
super.onPostExecute(result);
|
|
|
1561 |
try {
|
|
|
1562 |
userDataEditor.putString("amazonOrder", "true").commit();
|
|
|
1563 |
userDataEditor.putBoolean("amazonLoggedIn", true).commit();
|
|
|
1564 |
userDataEditor.putLong("amazonNextFetchTime", System.currentTimeMillis() + ProfitTillConstants.DURATION_TRACKING_ORDERS).commit();
|
|
|
1565 |
if (result.getString("htmlRequired").equalsIgnoreCase("true")) {
|
|
|
1566 |
String orderId = result.getString("orderId");
|
|
|
1567 |
amazonapiSettingsEditor.putString("amazonurl", result.getString("url"));
|
|
|
1568 |
amazonapiSettingsEditor.commit();
|
|
|
1569 |
pushDataInAmazon(orderId);
|
|
|
1570 |
}
|
|
|
1571 |
} catch (Exception e) {
|
|
|
1572 |
|
|
|
1573 |
}
|
|
|
1574 |
}
|
|
|
1575 |
}
|
|
|
1576 |
|
|
|
1577 |
class AmazonOrderTrackingDetails extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
|
|
|
1578 |
@Override
|
|
|
1579 |
protected void onPreExecute() {
|
|
|
1580 |
super.onPreExecute();
|
|
|
1581 |
}
|
|
|
1582 |
|
|
|
1583 |
@Override
|
|
|
1584 |
protected JSONObject doInBackground(List<NameValuePair>... arg0) {
|
|
|
1585 |
try {
|
|
|
1586 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1587 |
HttpPost httppost = new HttpPost(apiData.getString("orderpagehtml.push.api", null));
|
|
|
1588 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1589 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
1590 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1591 |
HttpEntity entity = response.getEntity();
|
|
|
1592 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1593 |
|
|
|
1594 |
if (status == 200) {
|
|
|
1595 |
} else {
|
|
|
1596 |
}
|
|
|
1597 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
1598 |
return jObjGmail;
|
|
|
1599 |
|
|
|
1600 |
} catch (Exception e) {
|
|
|
1601 |
return null;
|
|
|
1602 |
}
|
|
|
1603 |
}
|
|
|
1604 |
|
|
|
1605 |
@Override
|
|
|
1606 |
protected void onPostExecute(JSONObject result) {
|
|
|
1607 |
super.onPostExecute(result);
|
|
|
1608 |
}
|
|
|
1609 |
}
|
|
|
1610 |
|
|
|
1611 |
class pushQueuedData extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
|
|
|
1612 |
@Override
|
|
|
1613 |
protected void onPreExecute() {
|
|
|
1614 |
super.onPreExecute();
|
|
|
1615 |
}
|
|
|
1616 |
|
|
|
1617 |
@Override
|
|
|
1618 |
protected JSONObject doInBackground(List<NameValuePair>... pushOrder) {
|
|
|
1619 |
|
|
|
1620 |
try {
|
|
|
1621 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1622 |
//Get store id
|
|
|
1623 |
// NameValuePair nvp = pushOrder[1].get(0);
|
|
|
1624 |
//String storeId = nvp.getValue();
|
|
|
1625 |
|
|
|
1626 |
String fetchUrl = apiData.getString("amazon.order.tracking.post.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + apiData.getString("store.code.amazon", "1");
|
|
|
1627 |
HttpPost httppost = new HttpPost(fetchUrl);
|
|
|
1628 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1629 |
httppost.setEntity(new UrlEncodedFormEntity(pushOrder[0]));
|
|
|
1630 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1631 |
HttpEntity entity = response.getEntity();
|
|
|
1632 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
1633 |
return jObjGmail;
|
|
|
1634 |
|
|
|
1635 |
} catch (Exception e) {
|
|
|
1636 |
return null;
|
|
|
1637 |
}
|
|
|
1638 |
|
|
|
1639 |
}
|
|
|
1640 |
|
|
|
1641 |
@Override
|
|
|
1642 |
protected void onPostExecute(JSONObject result) {
|
|
|
1643 |
super.onPostExecute(result);
|
|
|
1644 |
try {
|
|
|
1645 |
if (result == null) {
|
|
|
1646 |
|
|
|
1647 |
} else if (result.getString("result").equalsIgnoreCase("PARSE_ERROR")) {
|
|
|
1648 |
userDataEditor.putBoolean("amazonLoggedIn", false).commit();
|
|
|
1649 |
} else {
|
|
|
1650 |
addOrderHistoryCancelled(str.get(1));
|
|
|
1651 |
}
|
|
|
1652 |
} catch (Exception e) {
|
|
|
1653 |
e.printStackTrace();
|
|
|
1654 |
}
|
|
|
1655 |
}
|
|
|
1656 |
}
|
|
|
1657 |
|
|
|
1658 |
class pushCancelledQueuedData extends AsyncTask<List<NameValuePair>, Integer, String> {
|
|
|
1659 |
|
|
|
1660 |
@Override
|
|
|
1661 |
protected void onPreExecute() {
|
|
|
1662 |
super.onPreExecute();
|
|
|
1663 |
}
|
|
|
1664 |
|
|
|
1665 |
@Override
|
|
|
1666 |
protected String doInBackground(List<NameValuePair>... pushOrder) {
|
|
|
1667 |
|
|
|
1668 |
try {
|
|
|
1669 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1670 |
|
|
|
1671 |
String fetchUrl = apiData.getString("amazon.order.tracking.post.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + apiData.getString("store.code.amazon", "1");
|
|
|
1672 |
HttpPost httppost = new HttpPost(fetchUrl);
|
|
|
1673 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1674 |
httppost.setEntity(new UrlEncodedFormEntity(pushOrder[0]));
|
|
|
1675 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1676 |
HttpEntity entity = response.getEntity();
|
|
|
1677 |
|
|
|
1678 |
return "success";
|
|
|
1679 |
} catch (Exception e) {
|
|
|
1680 |
return "failure";
|
|
|
1681 |
}
|
|
|
1682 |
|
|
|
1683 |
}
|
|
|
1684 |
|
|
|
1685 |
@Override
|
|
|
1686 |
protected void onPostExecute(String result) {
|
|
|
1687 |
super.onPostExecute(result);
|
|
|
1688 |
try {
|
|
|
1689 |
addOrderHistoryCancelled(str.get(++sizeList));
|
|
|
1690 |
} catch (Exception e) {
|
|
|
1691 |
e.printStackTrace();
|
|
|
1692 |
}
|
|
|
1693 |
FLAG = false;
|
|
|
1694 |
}
|
|
|
1695 |
}
|
|
|
1696 |
|
|
|
1697 |
int sizeList;
|
|
|
1698 |
|
|
|
1699 |
class FetchOrderURLS extends AsyncTask<String, Integer, JSONObject> {
|
|
|
1700 |
|
|
|
1701 |
@Override
|
|
|
1702 |
protected void onPreExecute() {
|
|
|
1703 |
super.onPreExecute();
|
|
|
1704 |
}
|
|
|
1705 |
|
|
|
1706 |
@Override
|
|
|
1707 |
protected JSONObject doInBackground(String... arg0) {
|
|
|
1708 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1709 |
try {
|
|
|
1710 |
String fetchUrl = apiData.getString("amazon.order.tracking.get.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + apiData.getString("store.code.amazon", "1");
|
|
|
1711 |
HttpGet httppost = new HttpGet(fetchUrl);
|
|
|
1712 |
|
|
|
1713 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1714 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1715 |
HttpEntity entity = response.getEntity();
|
|
|
1716 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
1717 |
return jObjGmail;
|
|
|
1718 |
|
|
|
1719 |
} catch (ClientProtocolException e) {
|
|
|
1720 |
return null;
|
|
|
1721 |
} catch (IOException e) {
|
|
|
1722 |
return null;
|
|
|
1723 |
}
|
|
|
1724 |
catch (Exception e) {
|
|
|
1725 |
e.printStackTrace();
|
|
|
1726 |
return null;
|
|
|
1727 |
}
|
|
|
1728 |
}
|
|
|
1729 |
|
|
|
1730 |
@Override
|
|
|
1731 |
protected void onPostExecute(JSONObject result) {
|
|
|
1732 |
super.onPostExecute(result);
|
|
|
1733 |
try {
|
|
|
1734 |
if (result == null) {
|
|
|
1735 |
userDataEditor.putString("amazonOrder", "false").commit();
|
|
|
1736 |
} else {
|
|
|
1737 |
if (result.length() == 0) {
|
|
|
1738 |
userDataEditor.putString("amazonOrder", "false").commit();
|
|
|
1739 |
} else {
|
|
|
1740 |
JSONArray js = result.getJSONArray("result");
|
|
|
1741 |
if (js.length() != 0) {
|
|
|
1742 |
str = new ArrayList<>();
|
|
|
1743 |
for (int i = 0; i < js.length(); i++) {
|
|
|
1744 |
String s = js.getString(i);
|
|
|
1745 |
str.add(s);
|
|
|
1746 |
}
|
|
|
1747 |
sizeList = 1;
|
|
|
1748 |
j = 1;
|
|
|
1749 |
addOrderHistory(str.get(0));
|
|
|
1750 |
} else {
|
|
|
1751 |
userDataEditor.putString("amazonOrder", "false").commit();
|
|
|
1752 |
}
|
|
|
1753 |
}
|
|
|
1754 |
}
|
|
|
1755 |
} catch (Exception e) {
|
|
|
1756 |
}
|
|
|
1757 |
}
|
|
|
1758 |
}
|
|
|
1759 |
|
|
|
1760 |
int count = 0;
|
|
|
1761 |
List<String> str;
|
|
|
1762 |
|
|
|
1763 |
public void addOrderHistory(String s) {
|
|
|
1764 |
AmazonOrderHistoryDetails amazonOrderClient = new AmazonOrderHistoryDetails();
|
|
|
1765 |
amazonOrderHistoryWebView = new WebView(webView.getContext());
|
|
|
1766 |
amazonOrderHistoryWebView.setVisibility(View.GONE);
|
|
|
1767 |
amazonOrderHistoryWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
1768 |
amazonOrderHistoryWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
1769 |
amazonOrderHistoryWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
1770 |
amazonOrderHistoryWebView.loadUrl(s);
|
|
|
1771 |
amazonOrderHistoryWebView.setWebViewClient(amazonOrderClient);
|
|
|
1772 |
}
|
|
|
1773 |
|
|
|
1774 |
public void addOrderHistoryCancelled(String s) {
|
|
|
1775 |
AmazonOrderCancelledDetails amazonOrderClient1 = new AmazonOrderCancelledDetails();
|
|
|
1776 |
amazonOrderHistoryCancelledWebView = new WebView(webView.getContext());
|
|
|
1777 |
amazonOrderHistoryCancelledWebView.setVisibility(View.GONE);
|
|
|
1778 |
amazonOrderHistoryCancelledWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
1779 |
amazonOrderHistoryCancelledWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36");
|
|
|
1780 |
amazonOrderHistoryCancelledWebView.addJavascriptInterface(new amazonInterface(getActivity()), "HTMLOUT");
|
|
|
1781 |
amazonOrderHistoryCancelledWebView.loadUrl(s);
|
|
|
1782 |
amazonOrderHistoryCancelledWebView.setWebViewClient(amazonOrderClient1);
|
|
|
1783 |
}
|
|
|
1784 |
|
|
|
1785 |
class AmazonOrderHistoryDetails extends WebViewClient {
|
|
|
1786 |
|
|
|
1787 |
@Override
|
|
|
1788 |
public void onReceivedHttpAuthRequest(WebView view,
|
|
|
1789 |
HttpAuthHandler handler, String host, String realm) {
|
|
|
1790 |
|
|
|
1791 |
handler.proceed("dtr", "dtr18Feb2015");
|
|
|
1792 |
|
|
|
1793 |
}
|
|
|
1794 |
|
|
|
1795 |
@Override
|
|
|
1796 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
1797 |
super.onPageStarted(view, url, favicon);
|
|
|
1798 |
}
|
|
|
1799 |
|
|
|
1800 |
@Override
|
|
|
1801 |
public void onPageFinished(WebView view, String url) {
|
|
|
1802 |
super.onPageFinished(view, url);
|
|
|
1803 |
if (url.contains("signin")) {
|
|
|
1804 |
userDataEditor.putBoolean("amazonLoggedIn", false).commit();
|
|
|
1805 |
} else {
|
|
|
1806 |
view.loadUrl("javascript:window.HTMLOUT.orderHistory('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
1807 |
}
|
|
|
1808 |
}
|
|
|
1809 |
}
|
|
|
1810 |
|
|
|
1811 |
class AmazonOrderCancelledDetails extends WebViewClient {
|
|
|
1812 |
|
|
|
1813 |
@Override
|
|
|
1814 |
public void onReceivedHttpAuthRequest(WebView view,
|
|
|
1815 |
HttpAuthHandler handler, String host, String realm) {
|
|
|
1816 |
|
|
|
1817 |
handler.proceed("dtr", "dtr18Feb2015");
|
|
|
1818 |
|
|
|
1819 |
}
|
|
|
1820 |
|
|
|
1821 |
@Override
|
|
|
1822 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
1823 |
super.onPageStarted(view, url, favicon);
|
|
|
1824 |
}
|
|
|
1825 |
|
|
|
1826 |
@Override
|
|
|
1827 |
public void onPageFinished(WebView view, String url) {
|
|
|
1828 |
super.onPageFinished(view, url);
|
|
|
1829 |
view.loadUrl("javascript:window.HTMLOUT.cancelledHistory('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
1830 |
}
|
|
|
1831 |
}
|
|
|
1832 |
|
|
|
1833 |
|
|
|
1834 |
public final boolean isInternetOn() {
|
|
|
1835 |
|
|
|
1836 |
ConnectivityManager connec =
|
|
|
1837 |
(ConnectivityManager) getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
1838 |
|
|
|
1839 |
if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
1840 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
1841 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
1842 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED) {
|
|
|
1843 |
return true;
|
|
|
1844 |
|
|
|
1845 |
} else if (
|
|
|
1846 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
1847 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED) {
|
|
|
1848 |
|
|
|
1849 |
return false;
|
|
|
1850 |
}
|
|
|
1851 |
return false;
|
|
|
1852 |
}
|
|
|
1853 |
|
|
|
1854 |
class checkGateWayProblem extends AsyncTask<String, Integer, String> {
|
|
|
1855 |
@Override
|
|
|
1856 |
protected void onPreExecute() {
|
|
|
1857 |
super.onPreExecute();
|
|
|
1858 |
}
|
|
|
1859 |
|
|
|
1860 |
@Override
|
|
|
1861 |
protected String doInBackground(String... arg0) {
|
|
|
1862 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1863 |
try {
|
|
|
1864 |
HttpPost httppost = new HttpPost(arg0[0]);
|
|
|
1865 |
final String basicAuth = "Basic " + Base64.encodeToString("dtr:dtr18Feb2015".getBytes(), Base64.NO_WRAP);
|
|
|
1866 |
httppost.setHeader("Authorization", basicAuth);
|
|
|
1867 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1868 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1869 |
|
|
|
1870 |
jsArraySaholic = new JSONArray();
|
|
|
1871 |
jSaholic.put("url", arg0[0]);
|
|
|
1872 |
|
|
|
1873 |
jSaholic.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
1874 |
jSaholic.put("httpstatus", status);
|
|
|
1875 |
jSaholic.put("cookies", CookieManager.getInstance().getCookie(arg0[0]));
|
|
|
1876 |
jsArraySaholic.put(jSaholic);
|
|
|
1877 |
obj.put("pushdata", jsArraySaholic);
|
|
|
1878 |
Log.d("status ", "Status in checkGatewayProbelm " + status);
|
|
|
1879 |
if (status == 200) {
|
|
|
1880 |
return "success";
|
|
|
1881 |
} else {
|
|
|
1882 |
return "failure";
|
|
|
1883 |
}
|
|
|
1884 |
|
|
|
1885 |
} catch (ClientProtocolException e) {
|
|
|
1886 |
return "failure";
|
|
|
1887 |
} catch (IOException e) {
|
|
|
1888 |
return "failure";
|
|
|
1889 |
} catch (JSONException e) {
|
|
|
1890 |
return "failure";
|
|
|
1891 |
}
|
|
|
1892 |
}
|
|
|
1893 |
|
|
|
1894 |
@Override
|
|
|
1895 |
protected void onPostExecute(String result) {
|
|
|
1896 |
super.onPostExecute(result);
|
|
|
1897 |
new pushData1().execute(obj);
|
|
|
1898 |
}
|
|
|
1899 |
}
|
|
|
1900 |
|
|
|
1901 |
class pushData1 extends AsyncTask<JSONObject, Integer, String> {
|
|
|
1902 |
|
|
|
1903 |
@Override
|
|
|
1904 |
protected void onPreExecute() {
|
|
|
1905 |
super.onPreExecute();
|
|
|
1906 |
}
|
|
|
1907 |
|
|
|
1908 |
@Override
|
|
|
1909 |
protected String doInBackground(JSONObject... arg0) {
|
|
|
1910 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1911 |
try {
|
|
|
1912 |
ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
|
|
|
1913 |
nameValuePairs.add(new BasicNameValuePair("pushdata", arg0[0].toString()));
|
|
|
1914 |
HttpPost httppost = new HttpPost(apiData.getString("url.push.api", null));
|
|
|
1915 |
final String basicAuth = "Basic " + Base64.encodeToString("dtr:dtr18Feb2015".getBytes(), Base64.NO_WRAP);
|
|
|
1916 |
httppost.setHeader("Authorization", basicAuth);
|
|
|
1917 |
|
|
|
1918 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
1919 |
System.out.println("JSON object in push Data 1 " + arg0[0].toString());
|
|
|
1920 |
StringEntity se = new StringEntity(arg0[0].toString());
|
|
|
1921 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1922 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1923 |
|
|
|
1924 |
if (status == 200) {
|
|
|
1925 |
return "success";
|
|
|
1926 |
} else {
|
|
|
1927 |
return "failure";
|
|
|
1928 |
}
|
|
|
1929 |
|
|
|
1930 |
} catch (ClientProtocolException e) {
|
|
|
1931 |
return "failure";
|
|
|
1932 |
} catch (IOException e) {
|
|
|
1933 |
return "failure";
|
|
|
1934 |
}
|
|
|
1935 |
}
|
|
|
1936 |
|
|
|
1937 |
@Override
|
|
|
1938 |
protected void onPostExecute(String result) {
|
|
|
1939 |
super.onPostExecute(result);
|
|
|
1940 |
}
|
|
|
1941 |
}
|
|
|
1942 |
|
|
|
1943 |
public void redirectPage(final AlertDialog builder) {
|
|
|
1944 |
Handler h = new Handler();
|
|
|
1945 |
h.postDelayed(new Runnable() {
|
|
|
1946 |
@Override
|
|
|
1947 |
public void run() {
|
|
|
1948 |
if (builder != null) {
|
|
|
1949 |
builder.dismiss();
|
|
|
1950 |
}
|
|
|
1951 |
userDataEditor.clear().commit();
|
|
|
1952 |
startActivity(new Intent(getActivity(), LoginActivity.class));
|
|
|
1953 |
}
|
|
|
1954 |
}, 3000);
|
|
|
1955 |
|
|
|
1956 |
}
|
|
|
1957 |
|
|
|
1958 |
public void sendQueuedResponse() {
|
|
|
1959 |
|
|
|
1960 |
List<List<NameValuePair>> postDataNameValuePair = new ArrayList<List<NameValuePair>>();
|
|
|
1961 |
postDataNameValuePair = orderDetails.readData1();
|
|
|
1962 |
for (List<NameValuePair> orderDetail : postDataNameValuePair) {
|
|
|
1963 |
orderDetail.add(new BasicNameValuePair("zip", "1"));
|
|
|
1964 |
orderDetail.add(new BasicNameValuePair("wifi", UtilityFunctions.checkWifi(getActivity()) + ""));
|
|
|
1965 |
orderDetail.add(new BasicNameValuePair("imeinumber", UtilityFunctions.getImeiNumber(getActivity())));
|
|
|
1966 |
orderDetail.add(new BasicNameValuePair("appversion", UtilityFunctions.getAppVersion(getActivity())));
|
|
|
1967 |
PushRawHTML pm = new PushRawHTML();
|
|
|
1968 |
pm.execute(orderDetail);
|
|
|
1969 |
}
|
|
|
1970 |
}
|
|
|
1971 |
|
|
|
1972 |
|
|
|
1973 |
class PaytmWebViewClient extends WebViewClient {
|
|
|
1974 |
@Override
|
|
|
1975 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
1976 |
super.onPageStarted(view, url, favicon);
|
|
|
1977 |
}
|
|
|
1978 |
|
|
|
1979 |
@Override
|
|
|
1980 |
public void onPageFinished(WebView view, String url) {
|
|
|
1981 |
super.onPageFinished(view, url);
|
|
|
1982 |
if (url.contains(apiData.getString("paytm.myorders.url", "paytm.com/myorders"))) {
|
|
|
1983 |
view.loadUrl("javascript:window.location='" + getPaytmUrl(url) + "';");
|
|
|
1984 |
} else {
|
|
|
1985 |
view.loadUrl("javascript:window.HTMLOUT.showHTML(document.getElementsByTagName('html')[0].innerHTML);");
|
|
|
1986 |
}
|
|
|
1987 |
}
|
|
|
1988 |
}
|
|
|
1989 |
|
|
|
1990 |
public String getPaytmUrl(String url) {
|
|
|
1991 |
String returnUrl = null;
|
|
|
1992 |
//Pattern p = Pattern.compile("[/]myorders/(\\d+)");
|
|
|
1993 |
Pattern p = Pattern.compile(apiData.getString("paytm.myorders.pattern", "[/]myorders/(\\d+)"));
|
|
|
1994 |
Matcher m = p.matcher(url);
|
|
|
1995 |
if (m.find()) {
|
|
|
1996 |
returnUrl = m.group(1);
|
|
|
1997 |
}
|
|
|
1998 |
System.out.println(apiData.getString("paytm.orderdetail.url", "https://paytm.com/shop/orderdetail/") + returnUrl + "?actions=1&channel=web&version=2");
|
|
|
1999 |
return apiData.getString("paytm.orderdetail.url", "https://paytm.com/shop/orderdetail/") + returnUrl + "?actions=1&channel=web&version=2";
|
|
|
2000 |
}
|
|
|
2001 |
|
|
|
2002 |
|
|
|
2003 |
public String getPaytmReferer(String url) {
|
|
|
2004 |
String returnUrl = null;
|
|
|
2005 |
Pattern p = Pattern.compile(apiData.getString("paytm.summary.pattern", "[/]summary/(\\d+)"));
|
|
|
2006 |
//Pattern p = Pattern.compile("[/]summary/(\\d+)");
|
|
|
2007 |
Matcher m = p.matcher(url);
|
|
|
2008 |
if (m.find()) {
|
|
|
2009 |
returnUrl = m.group(1);
|
|
|
2010 |
}
|
|
|
2011 |
System.out.println("In paytm Referer" + apiData.getString("paytm.myorders.url", "https://paytm.com/myorders/") + returnUrl);
|
|
|
2012 |
return apiData.getString("paytm.myorders.url", "https://paytm.com/myorders/") + returnUrl;
|
|
|
2013 |
}
|
|
|
2014 |
|
|
|
2015 |
|
|
|
2016 |
class PaytmOrderURL extends AsyncTask<String, Integer, JSONObject> {
|
|
|
2017 |
|
|
|
2018 |
@Override
|
|
|
2019 |
protected void onPreExecute() {
|
|
|
2020 |
super.onPreExecute();
|
|
|
2021 |
}
|
|
|
2022 |
|
|
|
2023 |
@Override
|
|
|
2024 |
protected JSONObject doInBackground(String... arg0) {
|
|
|
2025 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
2026 |
try {
|
|
|
2027 |
String fetchUrl = apiData.getString("amazon.order.tracking.get.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code", "")), "paytm");
|
|
|
2028 |
HttpGet httppost = new HttpGet(fetchUrl);
|
|
|
2029 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
2030 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
2031 |
HttpEntity entity = response.getEntity();
|
|
|
2032 |
int status = response.getStatusLine().getStatusCode();
|
|
|
2033 |
|
|
|
2034 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
2035 |
return jObjGmail;
|
|
|
2036 |
} catch (JSONException e) {
|
|
|
2037 |
return null;
|
|
|
2038 |
} catch (ClientProtocolException e) {
|
|
|
2039 |
return null;
|
|
|
2040 |
} catch (IOException e) {
|
|
|
2041 |
e.printStackTrace();
|
|
|
2042 |
return null;
|
|
|
2043 |
}
|
|
|
2044 |
}
|
|
|
2045 |
|
|
|
2046 |
@Override
|
|
|
2047 |
protected void onPostExecute(JSONObject result) {
|
|
|
2048 |
super.onPostExecute(result);
|
|
|
2049 |
try {
|
|
|
2050 |
if (result != null) {
|
|
|
2051 |
if (result.length() == 0) {
|
|
|
2052 |
userDataEditor.putString("paytmOrder", "false").commit();
|
|
|
2053 |
} else {
|
|
|
2054 |
JSONArray js = result.getJSONArray("result");
|
|
|
2055 |
if (js.length() != 0) {
|
|
|
2056 |
strPaytmUrls = new ArrayList<>();
|
|
|
2057 |
strPaytmReferer = new ArrayList<>();
|
|
|
2058 |
for (int i = 0; i < js.length(); i++) {
|
|
|
2059 |
JSONObject paytmURLRef = js.getJSONObject(i);
|
|
|
2060 |
String url = paytmURLRef.getString("url");
|
|
|
2061 |
String referer = paytmURLRef.getString("referer");
|
|
|
2062 |
strPaytmUrls.add(url);
|
|
|
2063 |
strPaytmReferer.add(referer);
|
|
|
2064 |
}
|
|
|
2065 |
paytmOrderTracking(strPaytmUrls.get(0), strPaytmReferer.get(0));
|
|
|
2066 |
} else {
|
|
|
2067 |
userDataEditor.putString("paytmOrder", "false").commit();
|
|
|
2068 |
}
|
|
|
2069 |
}
|
|
|
2070 |
}
|
|
|
2071 |
} catch (Exception e) {
|
|
|
2072 |
e.printStackTrace();
|
|
|
2073 |
}
|
|
|
2074 |
|
|
|
2075 |
}
|
|
|
2076 |
}
|
|
|
2077 |
|
|
|
2078 |
|
|
|
2079 |
class PaytmOrderCreation extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
|
|
|
2080 |
|
|
|
2081 |
@Override
|
|
|
2082 |
protected void onPreExecute() {
|
|
|
2083 |
super.onPreExecute();
|
|
|
2084 |
}
|
|
|
2085 |
|
|
|
2086 |
@Override
|
|
|
2087 |
protected JSONObject doInBackground(List<NameValuePair>... orderDetail) {
|
|
|
2088 |
|
|
|
2089 |
|
|
|
2090 |
try {
|
|
|
2091 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
2092 |
HttpPost httppost = new HttpPost(apiData.getString("orderpagehtml.push.api", null));
|
|
|
2093 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
2094 |
httppost.setEntity(new UrlEncodedFormEntity(orderDetail[0]));
|
|
|
2095 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
2096 |
HttpEntity entity = response.getEntity();
|
|
|
2097 |
|
|
|
2098 |
int status = response.getStatusLine().getStatusCode();
|
|
|
2099 |
|
|
|
2100 |
if (status == 200) {
|
|
|
2101 |
NameValuePair y = orderDetail[0].get(2);
|
|
|
2102 |
int z = orderDetails.deleteRecord(y.getName(), new String[]{y.getValue()});
|
|
|
2103 |
} else {
|
|
|
2104 |
}
|
|
|
2105 |
String getJSON = EntityUtils.toString(entity);
|
|
|
2106 |
if (getJSON == null) {
|
|
|
2107 |
return null;
|
|
|
2108 |
} else {
|
|
|
2109 |
JSONObject jObjGmail = new JSONObject(getJSON);
|
|
|
2110 |
return jObjGmail;
|
|
|
2111 |
}
|
|
|
2112 |
} catch (Exception e) {
|
|
|
2113 |
return null;
|
|
|
2114 |
}
|
|
|
2115 |
}
|
|
|
2116 |
|
|
|
2117 |
|
|
|
2118 |
@Override
|
|
|
2119 |
protected void onPostExecute(JSONObject result) {
|
|
|
2120 |
if (result == null) {
|
|
|
2121 |
|
|
|
2122 |
} else {
|
|
|
2123 |
userDataEditor.putString("paytmOrder", "true").commit();
|
|
|
2124 |
userDataEditor.putLong("paytmNextFetchTime", System.currentTimeMillis() + 21600000).commit();
|
|
|
2125 |
try {
|
|
|
2126 |
if (result.getString("message").equalsIgnoreCase("PROCESSED"))
|
|
|
2127 |
orderDetails.deleterecords();
|
|
|
2128 |
} catch (Exception e) {
|
|
|
2129 |
}
|
|
|
2130 |
}
|
|
|
2131 |
super.onPostExecute(result);
|
|
|
2132 |
}
|
|
|
2133 |
}
|
|
|
2134 |
|
|
|
2135 |
public void paytmOrderTracking(List<String> paytmUrls, List<String> paytmReferers) {
|
|
|
2136 |
for (int i = 1; i < paytmReferers.size(); i++) {
|
|
|
2137 |
PaytmOrderTrackingClient paytmOrderTrackingClient = new PaytmOrderTrackingClient(paytmUrls.get(i));
|
|
|
2138 |
paytmWebView = new WebView(webView.getContext());
|
|
|
2139 |
paytmWebView.setVisibility(View.GONE);
|
|
|
2140 |
paytmWebView.addJavascriptInterface(new paytmInterface(getActivity()), "HTMLOUT");
|
|
|
2141 |
paytmWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
2142 |
paytmWebView.loadUrl(paytmReferers.get(i));
|
|
|
2143 |
paytmWebView.setWebViewClient(paytmOrderTrackingClient);
|
|
|
2144 |
}
|
|
|
2145 |
userDataEditor.putLong("paytmNextFetchTime", System.currentTimeMillis() + 21600000).commit();
|
|
|
2146 |
}
|
|
|
2147 |
|
|
|
2148 |
public void paytmOrderTracking(String paytmUrl, String paytmReferer) {
|
|
|
2149 |
PaytmOrderTrackingClient paytmOrderTrackingClient = new PaytmOrderTrackingClient(paytmUrl);
|
|
|
2150 |
paytmWebView = new WebView(webView.getContext());
|
|
|
2151 |
paytmWebView.setVisibility(View.GONE);
|
|
|
2152 |
paytmWebView.addJavascriptInterface(new paytmInterface(getActivity()), "HTMLOUT");
|
|
|
2153 |
paytmWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
2154 |
paytmWebView.loadUrl(paytmReferer);
|
|
|
2155 |
paytmWebView.setWebViewClient(paytmOrderTrackingClient);
|
|
|
2156 |
userDataEditor.putLong("paytmNextFetchTime", System.currentTimeMillis() + 21600000).commit();
|
|
|
2157 |
}
|
|
|
2158 |
|
|
|
2159 |
class PaytmOrderTrackingClient extends WebViewClient {
|
|
|
2160 |
String paytmUrlAfterReferer;
|
|
|
2161 |
|
|
|
2162 |
public PaytmOrderTrackingClient(String paytmUrl) {
|
|
|
2163 |
paytmUrlAfterReferer = paytmUrl;
|
|
|
2164 |
}
|
|
|
2165 |
|
|
|
2166 |
@Override
|
|
|
2167 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
2168 |
super.onPageStarted(view, url, favicon);
|
|
|
2169 |
}
|
|
|
2170 |
|
|
|
2171 |
@Override
|
|
|
2172 |
public void onPageFinished(WebView view, String url) {
|
|
|
2173 |
super.onPageFinished(view, url);
|
|
|
2174 |
if (url.contains(apiData.getString("paytm.myorders.url", "paytm.com/myorders"))) {
|
|
|
2175 |
view.loadUrl("javascript:window.location='" + paytmUrlAfterReferer + "';");
|
|
|
2176 |
} else {
|
|
|
2177 |
view.loadUrl("javascript:window.HTMLOUT.paytmTracking(document.getElementsByTagName('html')[0].innerHTML);");
|
|
|
2178 |
}
|
|
|
2179 |
}
|
|
|
2180 |
}
|
|
|
2181 |
|
|
|
2182 |
List<String> strPaytmUrls, strPaytmReferer;
|
|
|
2183 |
int paytmCounter = 0;
|
|
|
2184 |
|
|
|
2185 |
class PaytmPushTrackingUrls extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
|
|
|
2186 |
@Override
|
|
|
2187 |
protected void onPreExecute() {
|
|
|
2188 |
super.onPreExecute();
|
|
|
2189 |
}
|
|
|
2190 |
|
|
|
2191 |
@Override
|
|
|
2192 |
protected JSONObject doInBackground(List<NameValuePair>... pushOrder) {
|
|
|
2193 |
|
|
|
2194 |
try {
|
|
|
2195 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
2196 |
String fetchUrl = apiData.getString("amazon.order.tracking.post.url", null) + "?user_id=" + userData.getString("id", "") + "&store_id=" + "&store_id=" + UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code", "")), "paytm");
|
|
|
2197 |
HttpPost httppost = new HttpPost(fetchUrl);
|
|
|
2198 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
2199 |
httppost.setEntity(new UrlEncodedFormEntity(pushOrder[0]));
|
|
|
2200 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
2201 |
HttpEntity entity = response.getEntity();
|
|
|
2202 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
2203 |
return jObjGmail;
|
|
|
2204 |
} catch (Exception e) {
|
|
|
2205 |
return null;
|
|
|
2206 |
}
|
|
|
2207 |
}
|
|
|
2208 |
|
|
|
2209 |
@Override
|
|
|
2210 |
protected void onPostExecute(JSONObject result) {
|
|
|
2211 |
super.onPostExecute(result);
|
|
|
2212 |
try {
|
|
|
2213 |
if (result == null) {
|
|
|
2214 |
|
|
|
2215 |
} else if (result.getString("result").equalsIgnoreCase("PARSE_ERROR")) {
|
|
|
2216 |
userDataEditor.putBoolean("paytmLoggedIn", false).commit();
|
|
|
2217 |
} else {
|
|
|
2218 |
paytmOrderTracking(strPaytmUrls, strPaytmReferer);
|
|
|
2219 |
}
|
|
|
2220 |
} catch (Exception e) {
|
|
|
2221 |
e.printStackTrace();
|
|
|
2222 |
}
|
|
|
2223 |
}
|
|
|
2224 |
}
|
|
|
2225 |
|
|
|
2226 |
class paytmInterface {
|
|
|
2227 |
|
|
|
2228 |
Context mContext;
|
|
|
2229 |
|
|
|
2230 |
public paytmInterface(Context c) {
|
|
|
2231 |
mContext = c;
|
|
|
2232 |
}
|
|
|
2233 |
|
|
|
2234 |
@JavascriptInterface
|
|
|
2235 |
public void showHTML(String html) {
|
|
|
2236 |
nameValuePairsRawHtml.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(html)));
|
|
|
2237 |
long x = orderDetails.insertOrderDetails(nameValuePairsRawHtml);
|
|
|
2238 |
List<List<NameValuePair>> postDataNameValuePair = new ArrayList<List<NameValuePair>>();
|
|
|
2239 |
postDataNameValuePair = orderDetails.readData1();
|
|
|
2240 |
for (List<NameValuePair> orderDetail : postDataNameValuePair) {
|
|
|
2241 |
orderDetail.add(new BasicNameValuePair("zip", "1"));
|
|
|
2242 |
new PaytmOrderCreation().execute(orderDetail);
|
|
|
2243 |
}
|
|
|
2244 |
}
|
|
|
2245 |
|
|
|
2246 |
@JavascriptInterface
|
|
|
2247 |
public void paytmTracking(String html) {
|
|
|
2248 |
try {
|
|
|
2249 |
String url = strPaytmUrls.get(paytmCounter++);
|
|
|
2250 |
List<NameValuePair> amazonOrderHistory = new ArrayList<NameValuePair>();
|
|
|
2251 |
amazonOrderHistory.add(new BasicNameValuePair("url", url));
|
|
|
2252 |
amazonOrderHistory.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
|
|
|
2253 |
amazonOrderHistory.add(new BasicNameValuePair("zip", "1"));
|
|
|
2254 |
if (isInternetOn()) {
|
|
|
2255 |
new PaytmPushTrackingUrls().execute(amazonOrderHistory);
|
|
|
2256 |
} else {
|
|
|
2257 |
|
|
|
2258 |
}
|
|
|
2259 |
} catch (Exception e) {
|
|
|
2260 |
e.printStackTrace();
|
|
|
2261 |
}
|
|
|
2262 |
|
|
|
2263 |
}
|
|
|
2264 |
}
|
|
|
2265 |
|
|
|
2266 |
public void onShareClick(String url) {
|
|
|
2267 |
try {
|
|
|
2268 |
List<Intent> targetShareIntents = new ArrayList<Intent>();
|
|
|
2269 |
Intent shareIntent = new Intent();
|
|
|
2270 |
shareIntent.setAction(Intent.ACTION_SEND);
|
|
|
2271 |
shareIntent.setType("text/plain");
|
|
|
2272 |
List<ResolveInfo> resInfos = getActivity().getPackageManager().queryIntentActivities(shareIntent, 0);
|
|
|
2273 |
if (!resInfos.isEmpty()) {
|
|
|
2274 |
for (ResolveInfo resInfo : resInfos) {
|
|
|
2275 |
String packageName = resInfo.activityInfo.packageName;
|
|
|
2276 |
Intent intent = new Intent();
|
|
|
2277 |
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
|
|
|
2278 |
intent.setAction(Intent.ACTION_SEND);
|
|
|
2279 |
intent.setType("text/plain");
|
|
|
2280 |
intent.putExtra(Intent.EXTRA_TEXT, Uri.parse(url).getQueryParameter("message"));
|
|
|
2281 |
intent.setPackage(packageName);
|
|
|
2282 |
targetShareIntents.add(intent);
|
|
|
2283 |
}
|
|
|
2284 |
if (!targetShareIntents.isEmpty()) {
|
|
|
2285 |
Intent chooserIntent = Intent.createChooser(targetShareIntents.remove(0), "Choose app to share");
|
|
|
2286 |
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
|
|
|
2287 |
startActivity(chooserIntent);
|
|
|
2288 |
}
|
|
|
2289 |
}
|
|
|
2290 |
} catch (Exception e) {
|
|
|
2291 |
e.printStackTrace();
|
|
|
2292 |
}
|
|
|
2293 |
}
|
|
|
2294 |
|
|
|
2295 |
public void fetchAmazonOrder(String url) {
|
|
|
2296 |
pd1 = new ProgressDialog(getActivity());
|
|
|
2297 |
pd1.setTitle("Please wait");
|
|
|
2298 |
pd1.setMessage("Placing your order...");
|
|
|
2299 |
pd1.show();
|
|
|
2300 |
webView.post(new Runnable() {
|
|
|
2301 |
@Override
|
|
|
2302 |
public void run() {
|
|
|
2303 |
webView.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
2304 |
}
|
|
|
2305 |
});
|
|
|
2306 |
|
|
|
2307 |
}
|
|
|
2308 |
|
|
|
2309 |
@Override
|
|
|
2310 |
public void onPause() {
|
|
|
2311 |
super.onPause();
|
|
|
2312 |
if (apiData.getString("deal.redirect", "false").equalsIgnoreCase("true")) {
|
|
|
2313 |
if (webView != null) {
|
|
|
2314 |
if (isPause) {
|
|
|
2315 |
webView.loadUrl(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", ""));
|
|
|
2316 |
isPause = false;
|
|
|
2317 |
}
|
|
|
2318 |
}
|
|
|
2319 |
}
|
|
|
2320 |
}
|
|
|
2321 |
|
|
|
2322 |
class FlipkartWebview extends WebViewClient {
|
|
|
2323 |
|
|
|
2324 |
@Override
|
|
|
2325 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
2326 |
super.onPageStarted(view, url, favicon);
|
|
|
2327 |
}
|
|
|
2328 |
|
|
|
2329 |
@Override
|
|
|
2330 |
public void onPageFinished(WebView view, String url) {
|
|
|
2331 |
super.onPageFinished(view, url);
|
|
|
2332 |
if(url.contains(apiData.getString("flipkart.response.url","https://www.flipkart.com/rv/accounts"))) {
|
|
|
2333 |
view.loadUrl("javascript:window.HTMLOUT.orderpage('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
|
|
|
2334 |
}
|
|
|
2335 |
|
|
|
2336 |
}
|
|
|
2337 |
}
|
|
|
2338 |
}
|