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