Subversion Repositories SmartDukaan

Rev

Rev 21480 | Rev 22381 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21480 Rev 22130
Line 1... Line 1...
1
package com.saholic.profittill.main;
1
package com.saholic.profittill.main;
2
 
2
 
-
 
3
import android.annotation.SuppressLint;
-
 
4
import android.app.Activity;
3
import android.app.AlertDialog;
5
import android.app.AlertDialog;
4
import android.app.Fragment;
6
import android.app.Fragment;
5
import android.app.ProgressDialog;
7
import android.app.ProgressDialog;
-
 
8
import android.content.BroadcastReceiver;
6
import android.content.ComponentName;
9
import android.content.ComponentName;
7
import android.content.Context;
10
import android.content.Context;
8
import android.content.DialogInterface;
11
import android.content.DialogInterface;
9
import android.content.Intent;
12
import android.content.Intent;
10
import android.content.IntentFilter;
13
import android.content.IntentFilter;
11
import android.content.SharedPreferences;
14
import android.content.SharedPreferences;
12
import android.content.pm.ResolveInfo;
15
import android.content.pm.ResolveInfo;
13
import android.graphics.Bitmap;
16
import android.graphics.Bitmap;
-
 
17
import android.graphics.Color;
-
 
18
import android.graphics.PorterDuff;
-
 
19
import android.graphics.drawable.ColorDrawable;
-
 
20
import android.graphics.drawable.Drawable;
14
import android.net.ConnectivityManager;
21
import android.net.ConnectivityManager;
15
import android.net.Uri;
22
import android.net.Uri;
16
import android.os.AsyncTask;
23
import android.os.AsyncTask;
17
import android.os.Build;
24
import android.os.Build;
18
import android.os.Bundle;
25
import android.os.Bundle;
-
 
26
import android.os.Environment;
19
import android.os.Handler;
27
import android.os.Handler;
20
import android.os.Parcelable;
28
import android.os.Parcelable;
-
 
29
import android.provider.MediaStore;
21
import android.support.v4.os.AsyncTaskCompat;
30
import android.support.v4.os.AsyncTaskCompat;
-
 
31
import android.support.v7.app.ActionBar;
-
 
32
import android.support.v7.app.AppCompatActivity;
-
 
33
import android.telephony.SmsMessage;
-
 
34
import android.telephony.TelephonyManager;
22
import android.util.Base64;
35
import android.util.Base64;
23
import android.util.Log;
36
import android.util.Log;
24
import android.view.KeyEvent;
37
import android.view.KeyEvent;
25
import android.view.LayoutInflater;
38
import android.view.LayoutInflater;
26
import android.view.Menu;
39
import android.view.Menu;
Line 30... Line 43...
30
import android.webkit.CookieManager;
43
import android.webkit.CookieManager;
31
import android.webkit.CookieSyncManager;
44
import android.webkit.CookieSyncManager;
32
import android.webkit.HttpAuthHandler;
45
import android.webkit.HttpAuthHandler;
33
import android.webkit.JavascriptInterface;
46
import android.webkit.JavascriptInterface;
34
import android.webkit.ValueCallback;
47
import android.webkit.ValueCallback;
-
 
48
import android.webkit.WebChromeClient;
35
import android.webkit.WebSettings;
49
import android.webkit.WebSettings;
36
import android.webkit.WebView;
50
import android.webkit.WebView;
37
import android.webkit.WebViewClient;
51
import android.webkit.WebViewClient;
38
import android.widget.CheckBox;
52
import android.widget.CheckBox;
39
import android.widget.CompoundButton;
53
import android.widget.CompoundButton;
40
import android.widget.RelativeLayout;
-
 
41
import android.widget.TextView;
-
 
42
import android.widget.Toast;
54
import android.widget.Toast;
43
 
55
 
44
import com.google.android.gms.common.ConnectionResult;
56
import com.google.android.gms.common.ConnectionResult;
45
import com.google.android.gms.common.api.GoogleApiClient;
57
import com.google.android.gms.common.api.GoogleApiClient;
46
import com.google.android.gms.plus.Plus;
58
import com.google.android.gms.plus.Plus;
47
import com.saholic.profittill.BroadcastReceivers.SmsReceiver;
59
import com.google.firebase.iid.FirebaseInstanceId;
48
import com.saholic.profittill.Constants.ProfitTillConstants;
60
import com.saholic.profittill.Constants.ProfitTillConstants;
49
import com.saholic.profittill.Database.OrderTransactionDetails;
61
import com.saholic.profittill.Database.OrderTransactionDetails;
50
import com.saholic.profittill.Network.NotificationCount;
62
import com.saholic.profittill.Network.NotificationCount;
51
import com.saholic.profittill.R;
63
import com.saholic.profittill.R;
52
import com.saholic.profittill.Utils.UtilityFunctions;
64
import com.saholic.profittill.Utils.UtilityFunctions;
Line 66... Line 78...
66
import org.apache.http.util.EntityUtils;
78
import org.apache.http.util.EntityUtils;
67
import org.json.JSONArray;
79
import org.json.JSONArray;
68
import org.json.JSONException;
80
import org.json.JSONException;
69
import org.json.JSONObject;
81
import org.json.JSONObject;
70
 
82
 
-
 
83
import java.io.File;
71
import java.io.IOException;
84
import java.io.IOException;
72
import java.io.InputStream;
85
import java.io.InputStream;
73
import java.io.UnsupportedEncodingException;
86
import java.io.UnsupportedEncodingException;
74
import java.text.SimpleDateFormat;
87
import java.text.SimpleDateFormat;
75
import java.util.ArrayList;
88
import java.util.ArrayList;
Line 104... Line 117...
104
    OrderTransactionDetails orderDetails;
117
    OrderTransactionDetails orderDetails;
105
    LinkedList<ArrayList<NameValuePair>> orderLinkedList;
118
    LinkedList<ArrayList<NameValuePair>> orderLinkedList;
106
    SharedPreferences amazonData;
119
    SharedPreferences amazonData;
107
    String affliateUrl;
120
    String affliateUrl;
108
    String landingURL;
121
    String landingURL;
-
 
122
    String regId;
-
 
123
    String msg = "";
-
 
124
    ArrayList<NameValuePair> messageNameValuePair;
109
    boolean val = false;
125
    boolean val = false;
110
    String redirectUrls;
126
    String redirectUrls;
111
    String pageLoad;
127
    String pageLoad;
112
    SharedPreferences.Editor amazonapiSettingsEditor;
128
    SharedPreferences.Editor amazonapiSettingsEditor;
113
    List<NameValuePair> amazonOrderTrackingData;
129
    List<NameValuePair> amazonOrderTrackingData;
Line 115... Line 131...
115
    int snapdealPageLoad;
131
    int snapdealPageLoad;
116
    final ArrayList<String> redirectUrlsList = new ArrayList<String>();
132
    final ArrayList<String> redirectUrlsList = new ArrayList<String>();
117
    final ArrayList<String> pageLoadList = new ArrayList<String>();
133
    final ArrayList<String> pageLoadList = new ArrayList<String>();
118
    String flipkartUrl;
134
    String flipkartUrl;
119
    View checkBoxView;
135
    View checkBoxView;
-
 
136
    boolean glogout;
120
    boolean flipkartFlag;
137
    boolean flipkartFlag;
121
    String saholicUrl;
138
    String saholicUrl;
122
    JSONObject jSaholic;
139
    JSONObject jSaholic;
123
    JSONArray jsArraySaholic;
140
    JSONArray jsArraySaholic;
124
    String type1;
141
    String type1;
125
    ArrayList<String> orderSuccessUrlList;
142
    ArrayList<String> orderSuccessUrlList;
126
    public GoogleApiClient mGoogleApiClient;
143
    public GoogleApiClient mGoogleApiClient;
127
    ProgressDialog pd1 = null;
144
    ProgressDialog pd1 = null;
-
 
145
    private static final String TAG = DealsHomeFragment.class.getSimpleName();
-
 
146
    private String mCM;
-
 
147
    private ValueCallback<Uri> mUM;
-
 
148
    private ValueCallback<Uri[]> mUMA;
-
 
149
    private final static int FCR=1;
-
 
150
    boolean doubleBackToExitPressedOnce = false;
128
    String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
151
    String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
129
    SmsReceiver smsListener = new SmsReceiver();
-
 
130
 
152
 
131
    @Override
153
    @Override
132
    public void onCreate(Bundle savedInstanceState) {
154
    public void onCreate(Bundle savedInstanceState) {
133
        super.onCreate(savedInstanceState);
155
        super.onCreate(savedInstanceState);
134
        setRetainInstance(true);
156
        setRetainInstance(true);
135
        setHasOptionsMenu(true);
157
        setHasOptionsMenu(true);
-
 
158
 
136
    }
159
    }
137
 
160
 
138
    @Override
161
    @Override
139
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
162
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
140
        super.onCreateOptionsMenu(menu, inflater);
163
        super.onCreateOptionsMenu(menu, inflater);
141
 
164
 
142
 
165
 
143
        RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.action_notifications).getActionView();
166
     /*   RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.action_notifications).getActionView();
144
        TextView notifciationCount = (TextView) badgeLayout.findViewById(R.id.inAppNotificationText);
167
        TextView notifciationCount = (TextView) badgeLayout.findViewById(R.id.inAppNotificationText);
145
        if (userData.getInt("notification_count", 0) != 0) {
168
        if (userData.getInt("notification_count", 0) != 0) {
146
            notifciationCount.setVisibility(View.VISIBLE);
169
            notifciationCount.setVisibility(View.VISIBLE);
147
            notifciationCount.setText(userData.getInt("notification_count", 0) + "");
170
            notifciationCount.setText(userData.getInt("notification_count", 0) + "");
148
        } else {
171
        } else {
149
            notifciationCount.setVisibility(View.GONE);
172
            notifciationCount.setVisibility(View.GONE);
150
        }
173
        }*/
151
    }
174
    }
152
 
175
 
153
 
-
 
154
    @Override
176
    @Override
155
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
177
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
156
                             Bundle savedInstanceState) {
178
                             Bundle savedInstanceState) {
157
 
179
 
158
 
180
 
159
        View rootView = inflater.inflate(R.layout.fragment_deals_home, container, false);
181
        View rootView = inflater.inflate(R.layout.fragment_deals_home, container, false);
160
 
182
 
161
        TestinAgent.init(getActivity());
183
        TestinAgent.init(getActivity());
-
 
184
        AppCompatActivity activity = (AppCompatActivity) getActivity();
-
 
185
        ActionBar actionBar = activity.getSupportActionBar();
-
 
186
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
-
 
187
        final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
-
 
188
        upArrow.setColorFilter(getResources().getColor(R.color.grey_black), PorterDuff.Mode.SRC_ATOP);
-
 
189
        actionBar.setHomeAsUpIndicator(upArrow);
-
 
190
        //actionBar.setIcon(R.drawable.logo_cirlce_1);
-
 
191
        actionBar.setDisplayShowCustomEnabled(true);
-
 
192
        actionBar.setDisplayShowTitleEnabled(false);
-
 
193
        actionBar.setDisplayHomeAsUpEnabled(true);
-
 
194
        actionBar.setHomeButtonEnabled(true);
-
 
195
        actionBar.setCustomView(R.layout.actionbarprofittill);
-
 
196
        actionBar.show();
162
        amazonData = getActivity().getSharedPreferences("Amazon_Data", Context.MODE_PRIVATE);
197
        amazonData = getActivity().getSharedPreferences("Amazon_Data", Context.MODE_PRIVATE);
163
        userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
198
        userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
164
        apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
199
        apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
165
        flipkartData = getActivity().getSharedPreferences("Flipkart_Data", Context.MODE_PRIVATE);
200
        flipkartData = getActivity().getSharedPreferences("Flipkart_Data", Context.MODE_PRIVATE);
166
        userDataEditor = userData.edit();
201
        userDataEditor = userData.edit();
Line 168... Line 203...
168
        TestinAgent.setUserInfo(userData.getString("id", ""));
203
        TestinAgent.setUserInfo(userData.getString("id", ""));
169
        amazonapiSettingsEditor = amazonData.edit();
204
        amazonapiSettingsEditor = amazonData.edit();
170
        flipkartDataEditor = flipkartData.edit();
205
        flipkartDataEditor = flipkartData.edit();
171
        affliateUrl = getArguments().getString("key");
206
        affliateUrl = getArguments().getString("key");
172
        orderDetails = new OrderTransactionDetails(getActivity());
207
        orderDetails = new OrderTransactionDetails(getActivity());
173
 
-
 
174
        orderSuccessUrlList = new ArrayList<String>();
208
        orderSuccessUrlList = new ArrayList<String>();
175
        String issues = apiData.getString("list.order.success.url", "blank");
209
        String issues = apiData.getString("list.order.success.url", "blank");
176
        StringTokenizer st2 = new StringTokenizer(issues, "|");
210
        StringTokenizer st2 = new StringTokenizer(issues, "|");
177
 
211
 
178
        while (st2.hasMoreElements()) {
212
        while (st2.hasMoreElements()) {
Line 206... Line 240...
206
            }
240
            }
207
            webView = (WebView) rootView.findViewById(R.id.webView);
241
            webView = (WebView) rootView.findViewById(R.id.webView);
208
            webView.setClickable(true);
242
            webView.setClickable(true);
209
            webView.setFocusableInTouchMode(true);
243
            webView.setFocusableInTouchMode(true);
210
            webView.getSettings().setDomStorageEnabled(true);
244
            webView.getSettings().setDomStorageEnabled(true);
-
 
245
            webView.getSettings().setDatabaseEnabled(true);
211
            webView.getSettings().setJavaScriptEnabled(true);
246
            webView.getSettings().setJavaScriptEnabled(true);
212
            webView.getSettings().setBuiltInZoomControls(true);
247
            webView.getSettings().setAllowContentAccess(true);
-
 
248
            webView.getSettings().setAllowFileAccess(true);
-
 
249
            //webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
213
            webView.addJavascriptInterface(new javascriptInterface(webView), "HTMLOUT");
250
            webView.addJavascriptInterface(new javascriptInterface(webView),"HTMLOUT");
-
 
251
            if(Build.VERSION.SDK_INT >= 21){
-
 
252
                webView.getSettings().setMixedContentMode(0);
-
 
253
                webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-
 
254
            }else if(Build.VERSION.SDK_INT >= 19){
-
 
255
                webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-
 
256
            }else if(Build.VERSION.SDK_INT < 19){
-
 
257
                webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
-
 
258
            }
-
 
259
            webView.setWebViewClient(new Callback());
-
 
260
            webView.setWebChromeClient(new WebChromeClient(){
-
 
261
                //For Android 3.0+
-
 
262
                public void openFileChooser(ValueCallback<Uri> uploadMsg){
-
 
263
                    mUM = uploadMsg;
-
 
264
                    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
-
 
265
                    i.addCategory(Intent.CATEGORY_OPENABLE);
-
 
266
                    i.setType("*/*");
-
 
267
                    getActivity().startActivityForResult(Intent.createChooser(i,"File Chooser"), FCR);
-
 
268
                }
-
 
269
                // For Android 3.0+, above method not supported in some android 3+ versions, in such case we use this
-
 
270
                public void openFileChooser(ValueCallback uploadMsg, String acceptType){
-
 
271
                    mUM = uploadMsg;
-
 
272
                    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
-
 
273
                    i.addCategory(Intent.CATEGORY_OPENABLE);
-
 
274
                    i.setType("*/*");
-
 
275
                    getActivity().startActivityForResult(
-
 
276
                            Intent.createChooser(i, "File Browser"),
-
 
277
                            FCR);
-
 
278
                }
-
 
279
                //For Android 4.1+
-
 
280
                public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
-
 
281
                    mUM = uploadMsg;
-
 
282
                    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
-
 
283
                    i.addCategory(Intent.CATEGORY_OPENABLE);
-
 
284
                    i.setType("*/*");
-
 
285
                    getActivity().startActivityForResult(Intent.createChooser(i, "File Chooser"), DealsHomeFragment.FCR);
-
 
286
                }
-
 
287
                //For Android 5.0+
-
 
288
                public boolean onShowFileChooser(
-
 
289
                        WebView webView, ValueCallback<Uri[]> filePathCallback,
-
 
290
                        WebChromeClient.FileChooserParams fileChooserParams){
-
 
291
                    if(mUMA != null){
-
 
292
                        mUMA.onReceiveValue(null);
-
 
293
                    }
-
 
294
                    mUMA = filePathCallback;
-
 
295
                    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
-
 
296
                    if(takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null){
-
 
297
                        File photoFile = null;
-
 
298
                        try{
-
 
299
                            photoFile = createImageFile();
-
 
300
                            takePictureIntent.putExtra("PhotoPath", mCM);
-
 
301
                        }catch(IOException ex){
-
 
302
                            Log.e(TAG, "Image file creation failed", ex);
-
 
303
                        }
-
 
304
                        if(photoFile != null){
-
 
305
                            mCM = "file:" + photoFile.getAbsolutePath();
-
 
306
                            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
-
 
307
                        }else{
-
 
308
                            takePictureIntent = null;
-
 
309
                        }
-
 
310
                    }
-
 
311
                    Intent contentSelectionIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
-
 
312
                    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
-
 
313
                    String [] mimeTypes = {"image/*", "application/pdf"};
-
 
314
                    contentSelectionIntent.setType("*/*");
-
 
315
                    contentSelectionIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
-
 
316
                    // contentSelectionIntent.setType("image/*");
-
 
317
                    Intent[] intentArray;
-
 
318
                    if(takePictureIntent != null){
-
 
319
                        intentArray = new Intent[]{takePictureIntent};
-
 
320
                    }else{
-
 
321
                        intentArray = new Intent[0];
-
 
322
                    }
-
 
323
 
-
 
324
                    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
-
 
325
                    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
-
 
326
                    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
-
 
327
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
-
 
328
                    startActivityForResult(chooserIntent, FCR);
-
 
329
                    return true;
-
 
330
                }
-
 
331
            });
214
            webView.getSettings().setSavePassword(true);
332
            webView.getSettings().setSavePassword(true);
215
            CookieManager cookieManager = CookieManager.getInstance();
333
            CookieManager cookieManager = CookieManager.getInstance();
216
            cookieManager.setAcceptCookie(true);
334
            cookieManager.setAcceptCookie(true);
217
 
335
 
218
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
336
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Line 268... Line 386...
268
                    }
386
                    }
269
                } else {
387
                } else {
270
                    Log.d("Amazon False", "Amazon False No orders");
388
                    Log.d("Amazon False", "Amazon False No orders");
271
                }
389
                }
272
            }
390
            }
273
            Map <String, String> extraHeaders = new HashMap<String, String>();
391
            // Map <String, String> extraHeaders = new HashMap<String, String>();
274
            extraHeaders.put("Auth-Token",userData.getString("token",""));
392
            // extraHeaders.put("Auth-Token",userData.getString("token",""));
275
            webView.setWebViewClient(webViewClient);
393
            webView.setWebViewClient(webViewClient);
276
            webView.loadUrl(url,extraHeaders);
394
            webView.loadUrl(url);
277
 
395
 
278
        }
396
        }
-
 
397
 
279
        else {
398
        else {
280
            SearchFragment nextFrag = new SearchFragment();
399
            SearchFragment nextFrag = new SearchFragment();
281
            Bundle args = new Bundle();
400
            Bundle args = new Bundle();
282
            args.putString("finishingurl", getArguments().getString("key"));
401
            args.putString("finishingurl", getArguments().getString("key"));
283
            args.putString("fragmentNumber", "1");
402
            args.putString("fragmentNumber", "1");
Line 292... Line 411...
292
    @Override
411
    @Override
293
    public void onViewCreated(View view, Bundle savedInstanceState) {
412
    public void onViewCreated(View view, Bundle savedInstanceState) {
294
        super.onViewCreated(view, savedInstanceState);
413
        super.onViewCreated(view, savedInstanceState);
295
    }
414
    }
296
 
415
 
-
 
416
    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
-
 
417
        @Override
-
 
418
        public void onReceive(Context context, Intent intent) {
-
 
419
            final Bundle bundle = intent.getExtras();
-
 
420
 
-
 
421
            try {
-
 
422
                if (bundle != null) {
-
 
423
                    final Object[] pdusObj = (Object[]) bundle.get("pdus");
-
 
424
                    for (int i = 0; i < pdusObj.length; i++) {
-
 
425
 
-
 
426
                        SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
-
 
427
                        String phoneNumber = currentMessage.getDisplayOriginatingAddress();
-
 
428
 
-
 
429
                        String senderNum = phoneNumber;
-
 
430
                        String message = currentMessage.getDisplayMessageBody();
-
 
431
 
-
 
432
                        String lastTwo = null;
-
 
433
                        if (senderNum != null && senderNum.length() >= 6) {
-
 
434
                            lastTwo = senderNum.substring(senderNum.length() - 6);
-
 
435
                        }
-
 
436
                        try {
-
 
437
                            if (lastTwo.equalsIgnoreCase(apiData.getString("Sender_CLI","PROFTM"))){
-
 
438
                                messageNameValuePair = new ArrayList<>();
-
 
439
                                messageNameValuePair.add(new BasicNameValuePair("message",message));
-
 
440
                                getActivity().unregisterReceiver(broadcastReceiver);
-
 
441
                                new SendOtpMessage().execute();
-
 
442
                            }
-
 
443
                            else{
-
 
444
                                getActivity().registerReceiver(broadcastReceiver, new IntentFilter(SMS_RECEIVED));
-
 
445
                            }}
-
 
446
                        catch(Exception e){
-
 
447
                            e.printStackTrace();
-
 
448
                        }
-
 
449
                    }
-
 
450
                }
-
 
451
 
-
 
452
            }
-
 
453
            catch (Exception e) {
-
 
454
                e.printStackTrace();
-
 
455
 
-
 
456
            }
-
 
457
        }
-
 
458
    };
-
 
459
 
297
    JSONObject obj;
460
    JSONObject obj;
298
 
461
 
299
    @Override
462
    @Override
300
    public void onConnected(Bundle bundle) {
463
    public void onConnected(Bundle bundle) {
301
 
464
 
Line 309... Line 472...
309
    @Override
472
    @Override
310
    public void onConnectionFailed(ConnectionResult connectionResult) {
473
    public void onConnectionFailed(ConnectionResult connectionResult) {
311
 
474
 
312
    }
475
    }
313
 
476
 
-
 
477
 
-
 
478
 
314
    public class WebClientClass extends WebViewClient {
479
    public class WebClientClass extends WebViewClient {
315
        ProgressDialog pd = null;
480
        ProgressDialog pd = null;
316
 
481
 
317
        ProgressDialog pd2 = null;
482
        ProgressDialog pd2 = null;
318
 
483
 
Line 365... Line 530...
365
            }
530
            }
366
            if (url.contains("apprub")) {
531
            if (url.contains("apprub")) {
367
                onShareClick(url);
532
                onShareClick(url);
368
                return true;
533
                return true;
369
            }
534
            }
370
            if (url.contains(apiData.getString("wallet.auth", "api.profittill.com/special/native/login")) || userData.getString("id", "").isEmpty()) {
535
            if (url.contains(apiData.getString("wallet.auth", "api.profittill.com/special/native/login")) /*|| userData.getString("id", "").isEmpty()*/) {
371
                android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
536
                android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
372
                android.webkit.CookieSyncManager.createInstance(getActivity());
537
                android.webkit.CookieSyncManager.createInstance(getActivity());
373
                cookieManager.removeAllCookie();
538
                cookieManager.removeAllCookie();
374
                AlertDialog alert;
539
                AlertDialog alert;
375
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
540
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Line 440... Line 605...
440
        public synchronized void onPageStarted(final WebView view, String url, Bitmap favicon) {
605
        public synchronized void onPageStarted(final WebView view, String url, Bitmap favicon) {
441
            super.onPageStarted(view, url, favicon);
606
            super.onPageStarted(view, url, favicon);
442
            final CharSequence[] items = {" Don't show me again "};
607
            final CharSequence[] items = {" Don't show me again "};
443
            final ArrayList seletedItems = new ArrayList();
608
            final ArrayList seletedItems = new ArrayList();
444
            try {
609
            try {
-
 
610
 
445
                if (Uri.parse(url).getHost().equalsIgnoreCase(ProfitTillConstants.DOMAIN)) {
611
                if (Uri.parse(url).getHost().equalsIgnoreCase(ProfitTillConstants.DOMAIN)) {
446
                    CookieSyncManager.createInstance(getActivity());
612
                    CookieSyncManager.createInstance(getActivity());
447
                    CookieManager cookieManager = CookieManager.getInstance();
613
                    CookieManager cookieManager = CookieManager.getInstance();
448
                    cookieManager.setCookie(url, "token=" + userData.getString("token", ""));
614
                    cookieManager.setCookie(url, "token=" + userData.getString("token", ""));
449
                    cookieManager.setCookie(url, "walletAuthentication=true");
615
                    cookieManager.setCookie(url, "walletAuthentication=true");
Line 552... Line 718...
552
                            startActivity(i);
718
                            startActivity(i);
553
                            pageRedirect = 0;
719
                            pageRedirect = 0;
554
                        }
720
                        }
555
                        else {
721
                        else {
556
                            landingURL = url;
722
                            landingURL = url;
557
                            if (url.contains(apiData.getString("mobile.website.url", "")) || url.equalsIgnoreCase("http://api.profittill.com/categorydeals") || url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
723
                            if (url.contains(apiData.getString("mobile.website.url"," ")) || url.equalsIgnoreCase("http://api.profittill.com/categorydeals") || url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
558
                                pd = new ProgressDialog(getActivity());
724
                                pd = new ProgressDialog(getActivity());
559
                                pd.setTitle("Please wait");
725
                                pd.setTitle("Please wait");
560
                                pd.setMessage("Loading..");
726
                                pd.setMessage("Loading..");
561
                                pd.show();
727
                                pd.show();
562
                            }
728
                            }
Line 590... Line 756...
590
            }
756
            }
591
        }
757
        }
592
 
758
 
593
        @Override
759
        @Override
594
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
760
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
-
 
761
            super.onReceivedError(view, errorCode, description, failingUrl);
595
            if (getActivity() != null) {
762
            if (getActivity() != null) {
596
                SearchFragment nextFrag = new SearchFragment();
763
                SearchFragment nextFrag = new SearchFragment();
597
                Bundle args = new Bundle();
764
                Bundle args = new Bundle();
598
                args.putString("finishingurl", failingUrl);
765
                args.putString("finishingurl", failingUrl);
599
                nextFrag.setArguments(args);
766
                nextFrag.setArguments(args);
600
                getActivity().getFragmentManager().beginTransaction().replace(R.id.frame_container, nextFrag).addToBackStack(null).commit();
767
                getActivity().getFragmentManager().beginTransaction().replace(R.id.frame_container,nextFrag).addToBackStack(null).commitAllowingStateLoss();
601
                super.onReceivedError(view, errorCode, description, failingUrl);
-
 
-
 
768
 
602
            }
769
            }
603
        }
770
        }
604
 
771
 
605
        @Override
772
        @Override
606
        public synchronized void onPageFinished(WebView view, String url) {
773
        public synchronized void onPageFinished(WebView view, String url) {
607
            super.onPageFinished(view, url);
774
            super.onPageFinished(view, url);
608
            String js =("javascript:document.getElementById('otp').value ='" +322 +"'" );
775
            if(url.contains(apiData.getString("Web_Uri","http://pm.shop2020.in/entry-point"))){
609
            if (Build.VERSION.SDK_INT >= 19) {
-
 
610
                view.evaluateJavascript(js, new ValueCallback<String>() {
-
 
611
                    @Override
-
 
612
                    public void onReceiveValue(String s) {
-
 
613
 
776
 
-
 
777
 
-
 
778
                // if(url.contains(ProfitTillConstants.Web_Uri)){
-
 
779
                String js1 =("javascript:document.getElementById('authToken').value ='" +userData.getString("token","")+"'");
-
 
780
                Log.d("authToken",js1);
-
 
781
                if(Build.VERSION.SDK_INT >= 19){
-
 
782
                    view.evaluateJavascript(js1, new ValueCallback<String>() {
-
 
783
                        @Override
-
 
784
                        public void onReceiveValue(String s) {
-
 
785
                        }
614
                    }
786
                    });
615
                });
787
                }
616
            } else {
788
                else {
-
 
789
                    view.loadUrl(js1);
-
 
790
                }
-
 
791
                String js2 =("javascript:document.getElementById('authTokenSubmit').click()");
-
 
792
                view.loadUrl(js2);
-
 
793
                String js = ("javascript:window.localStorage.removeItem('android.otpReceived');");
-
 
794
                Log.d("storage",js);
617
                view.loadUrl(js);
795
                view.loadUrl(js);
618
            }
796
            }
-
 
797
 
-
 
798
            if(url.contains("http://pm.shop2020.in")){
-
 
799
                // ((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
-
 
800
                ((AppCompatActivity)getActivity()).getSupportActionBar().hide();
-
 
801
            }
-
 
802
            else{
-
 
803
                ((AppCompatActivity)getActivity()).getSupportActionBar().show();
-
 
804
            }
619
            try {
805
            try {
620
                if (url.equalsIgnoreCase("about:blank")) {
806
                if (url.equalsIgnoreCase("about:blank")) {
621
                    Log.d("Blankl Url", "Blank Url");
807
                    Log.d("Blankl Url", "Blank Url");
622
                }
808
                }
623
                else {
809
                else {
Line 643... Line 829...
643
                            if (url.contains(s)) {
829
                            if (url.contains(s)) {
644
                                snapdealException = 0;
830
                                snapdealException = 0;
645
                            }
831
                            }
646
                        }
832
                        }
647
                    }
833
                    }
648
 
-
 
649
                    if (url.contains(apiData.getString("mobile.website.url", "")) || url.equalsIgnoreCase("http://api.profittill.com/categorydeals") || url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
834
                    if (url.contains(apiData.getString("mobile.website.url",""))|| url.equalsIgnoreCase("http://api.profittill.com/categorydeals") || url.contains(apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification"))) {
650
                        pd.dismiss();
835
                        pd.dismiss();
651
                    }
836
                    }
652
                    if (snapdealPageLoad == 1) {
837
                    if (snapdealPageLoad == 1) {
653
                        snapdealPageLoad = 0;
838
                        snapdealPageLoad = 0;
654
                    }
839
                    }
Line 763... Line 948...
763
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
948
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
764
                            if (event.getAction() == KeyEvent.ACTION_DOWN) {
949
                            if (event.getAction() == KeyEvent.ACTION_DOWN) {
765
                                WebView webView = (WebView) v;
950
                                WebView webView = (WebView) v;
766
                                switch (keyCode) {
951
                                switch (keyCode) {
767
                                    case KeyEvent.KEYCODE_BACK:
952
                                    case KeyEvent.KEYCODE_BACK:
-
 
953
                                        String veb=webView.getUrl();
768
                                        if ((webView.canGoBack() && !webView.getUrl().contains(apiData.getString("mobile.website.url", null))) || pageRedirect == 2) {
954
                                        if ((webView.canGoBack() && !webView.getUrl().contains("http://pm.shop2020.in/pages/home/dashboard") && !webView.getUrl().contains("http://pm.shop2020.in/pages/mobileOtp")&& !webView.getUrl().contains("http://pm.shop2020.in/pages/registration") && !webView.getUrl().contains("http://pm.shop2020.in/pages/checkRegistration"))|| pageRedirect == 2) {
769
                                            webView.goBack();
955
                                            webView.goBack();
770
                                            pageRedirect = 0;
956
                                            pageRedirect = 0;
771
                                            snapdealPageLoad = 0;
957
                                            snapdealPageLoad = 0;
772
                                            return true;
958
                                            return true;
773
                                        } else if (affliateUrl.contains("flipkart") || affliateUrl.contains("amazon") || affliateUrl.contains("snapdeal") || affliateUrl.contains("saholic") || affliateUrl.contains(apiData.getString("myorders.url", "")) || affliateUrl.contains(apiData.getString("search.url", ""))) {
959
                                        } else if (affliateUrl.contains("flipkart") || affliateUrl.contains("amazon") || affliateUrl.contains("snapdeal") || affliateUrl.contains("saholic") || affliateUrl.contains(apiData.getString("myorders.url", "")) || affliateUrl.contains(apiData.getString("search.url", ""))) {
774
                                            Intent i = new Intent(getActivity(), MainActivity.class);
960
                                            Intent i = new Intent(getActivity(), MainActivity.class);
775
                                            i.putExtra("displayView", "0");
961
                                            i.putExtra("displayView", "0");
776
                                            startActivity(i);
962
                                            startActivity(i);
777
                                            return true;
963
                                            return true;
-
 
964
                                        }
778
                                        } else if (webView.getUrl().contains(apiData.getString("mobile.website.url", null))) {
965
                                        else if (webView.getUrl().contains("http://pm.shop2020.in")) {
-
 
966
                                            //else if(webView.getUrl().contains(ProfitTillConstants.Web_Uri)){
-
 
967
                                            if (doubleBackToExitPressedOnce) {
779
                                            new AlertDialog.Builder(getActivity())
968
                                                new AlertDialog.Builder(getActivity())
780
                                                    .setIcon(android.R.drawable.ic_dialog_alert)
969
                                                        .setIcon(R.drawable.symbol)
781
                                                    .setTitle("Exit!")
970
                                                        .setTitle("Exit!")
782
                                                    .setMessage("Are you sure you want to close?")
971
                                                        .setMessage("Are you sure you want to close?")
783
                                                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
972
                                                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
784
                                                        @Override
973
                                                            @Override
785
                                                        public void onClick(DialogInterface dialog, int which) {
974
                                                            public void onClick(DialogInterface dialog, int which) {
-
 
975
                                                                if(userData.getString("userStatus","").equals("notRegistered"))
-
 
976
                                                                {
-
 
977
                                                                    Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
-
 
978
                                                                    mGoogleApiClient.disconnect();
-
 
979
                                                                    userDataEditor.clear().commit();
-
 
980
                                                                    mGoogleApiClient.connect();
-
 
981
                                                                    userDataEditor.clear().commit();
-
 
982
                                                                    startActivity(new Intent(getActivity(), LoginActivity.class));
-
 
983
 
-
 
984
                                                                }
-
 
985
                                                                else{
786
                                                            Intent startMain = new Intent(Intent.ACTION_MAIN);
986
                                                                    Intent startMain = new Intent(Intent.ACTION_MAIN);
787
                                                            startMain.addCategory(Intent.CATEGORY_HOME);
987
                                                                    startMain.addCategory(Intent.CATEGORY_HOME);
788
                                                            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
988
                                                                    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
789
 
989
 
790
                                                            startActivity(startMain);
990
                                                                    startActivity(startMain);
-
 
991
                                                                }
791
                                                        }
992
                                                            }
792
 
993
 
793
                                                    })
994
                                                        })
794
                                                    .setNegativeButton("No", null)
995
                                                        .setNegativeButton("No", null)
795
                                                    .show();
996
                                                        .show();
-
 
997
                                                return true;
-
 
998
                                            }
-
 
999
                                            doubleBackToExitPressedOnce = true;
-
 
1000
                                            Toast.makeText(getActivity(), "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
-
 
1001
 
-
 
1002
                                            new Handler().postDelayed(new Runnable() {
-
 
1003
 
-
 
1004
                                                @Override
-
 
1005
                                                public void run() {
-
 
1006
                                                    doubleBackToExitPressedOnce = false;
-
 
1007
                                                }
-
 
1008
                                            }, 5000);
796
                                        } else {
1009
                                        } else {
797
                                            Intent i = new Intent(getActivity(), MainActivity.class);
1010
                                            Intent i = new Intent(getActivity(), MainActivity.class);
798
                                            i.putExtra("displayView", "0");
1011
                                            i.putExtra("displayView", "0");
799
                                            startActivity(i);
1012
                                            startActivity(i);
800
                                            return true;
1013
                                            return true;
Line 809... Line 1022...
809
                }
1022
                }
810
            } catch (Exception e) {
1023
            } catch (Exception e) {
811
                e.printStackTrace();
1024
                e.printStackTrace();
812
                TestinAgent.uploadException(getActivity(), "On Page Finished", e);
1025
                TestinAgent.uploadException(getActivity(), "On Page Finished", e);
813
            }
1026
            }
-
 
1027
        }}
-
 
1028
    public class Callback extends WebViewClient{
-
 
1029
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
-
 
1030
            Toast.makeText(getActivity(), "Failed loading app!", Toast.LENGTH_SHORT).show();
814
        }
1031
        }
-
 
1032
    }
-
 
1033
    // Create an image file
-
 
1034
    private File createImageFile() throws IOException{
-
 
1035
        @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
-
 
1036
        String imageFileName = "img_"+timeStamp+"_";
-
 
1037
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
-
 
1038
        return File.createTempFile(imageFileName,".jpg",storageDir);
-
 
1039
    }
815
 
1040
 
-
 
1041
 
-
 
1042
    @Override
-
 
1043
    public void onActivityResult(int requestCode, int resultCode, Intent intent){
-
 
1044
        super.onActivityResult(requestCode, resultCode, intent);
-
 
1045
        if(Build.VERSION.SDK_INT >= 21){
-
 
1046
            Uri[] results = null;
-
 
1047
            //Check if response is positive
-
 
1048
            if(resultCode== Activity.RESULT_OK){
-
 
1049
                if(requestCode == FCR){
-
 
1050
                    if(null == mUMA){
-
 
1051
                        return;
-
 
1052
                    }
-
 
1053
                    if(intent == null){
-
 
1054
                        //Capture Photo if no image available
-
 
1055
                        if(mCM != null){
-
 
1056
                            results = new Uri[]{Uri.parse(mCM)};
-
 
1057
                        }
-
 
1058
                    }else{
-
 
1059
                        String dataString = intent.getDataString();
-
 
1060
                        if(dataString != null){
-
 
1061
                            results = new Uri[]{Uri.parse(dataString)};
-
 
1062
                        }
-
 
1063
                    }
-
 
1064
                }
-
 
1065
            }
-
 
1066
            mUMA.onReceiveValue(results);
-
 
1067
            mUMA = null;
-
 
1068
        }else{
-
 
1069
            if(requestCode == FCR){
-
 
1070
                if(null == mUM) return;
-
 
1071
                Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
-
 
1072
                mUM.onReceiveValue(result);
-
 
1073
                mUM = null;
-
 
1074
            }
-
 
1075
        }
816
    }
1076
    }
817
 
1077
 
818
    private void processFlipkartHtml() {
1078
    private void processFlipkartHtml() {
819
        FlipkartWebview fkView = new FlipkartWebview();
1079
        FlipkartWebview fkView = new FlipkartWebview();
820
        amazonOrderHistoryWebView = new WebView(webView.getContext());
1080
        amazonOrderHistoryWebView = new WebView(webView.getContext());
Line 900... Line 1160...
900
            @Override
1160
            @Override
901
            public boolean onKey(View v, int keyCode, KeyEvent event) {
1161
            public boolean onKey(View v, int keyCode, KeyEvent event) {
902
 
1162
 
903
                if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
1163
                if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
904
                    try {
1164
                    try {
905
                        if (landingURL.contains((apiData.getString("mobile.website.url", "")))) {
1165
                        if (landingURL.contains("http://pm.shop2020.in")) {
-
 
1166
                            if (doubleBackToExitPressedOnce) {
906
                            new AlertDialog.Builder(getActivity())
1167
                                new AlertDialog.Builder(getActivity())
907
                                    .setIcon(android.R.drawable.ic_dialog_alert)
1168
                                        .setIcon(R.drawable.symbol)
908
                                    .setTitle("Exit!")
1169
                                        .setTitle("Exit!")
909
                                    .setMessage("Are you sure you want to close?")
1170
                                        .setMessage("Are you sure you want to close?")
910
                                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
1171
                                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
911
                                        @Override
1172
                                            @Override
912
                                        public void onClick(DialogInterface dialog, int which) {
1173
                                            public void onClick(DialogInterface dialog, int which) {
-
 
1174
                                                if(userData.getString("userStatus","").equals("notRegistered"))
-
 
1175
                                                {
-
 
1176
                                                    Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
-
 
1177
                                                    mGoogleApiClient.disconnect();
-
 
1178
                                                    userDataEditor.clear().commit();
-
 
1179
                                                    mGoogleApiClient.connect();
-
 
1180
                                                    startActivity(new Intent(getActivity(), LoginActivity.class));
-
 
1181
 
-
 
1182
 
-
 
1183
                                                }
-
 
1184
                                                else{
913
                                            Intent startMain = new Intent(Intent.ACTION_MAIN);
1185
                                                    Intent startMain = new Intent(Intent.ACTION_MAIN);
914
                                            startMain.addCategory(Intent.CATEGORY_HOME);
1186
                                                    startMain.addCategory(Intent.CATEGORY_HOME);
915
                                            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1187
                                                    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
 
1188
 
916
                                            startActivity(startMain);
1189
                                                    startActivity(startMain);
-
 
1190
                                                }}
-
 
1191
 
917
                                        }
1192
                                        })
-
 
1193
                                        .setNegativeButton("No", null)
-
 
1194
                                        .show();
-
 
1195
                                return true;
-
 
1196
                            }
-
 
1197
                            doubleBackToExitPressedOnce = true;
-
 
1198
                            Toast.makeText(getActivity(), "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
918
 
1199
 
-
 
1200
                            new Handler().postDelayed(new Runnable() {
-
 
1201
 
919
                                    })
1202
                                @Override
-
 
1203
                                public void run() {
920
                                    .setNegativeButton("No", null)
1204
                                    doubleBackToExitPressedOnce = false;
921
                                    .show();
1205
                                }
922
                            return true;
1206
                            }, 5000);
923
                        } else {
1207
                        }else {
924
                            if (webView.canGoBack()) {
1208
                            if (webView.canGoBack()) {
925
                                webView.goBack();
1209
                                webView.goBack();
926
                            } else {
1210
                            } else {
927
                                Intent i = new Intent(getActivity(), MainActivity.class);
1211
                                Intent i = new Intent(getActivity(), MainActivity.class);
928
                                i.putExtra("displayView", "0");
1212
                                i.putExtra("displayView", "0");
Line 941... Line 1225...
941
            }
1225
            }
942
 
1226
 
943
        });
1227
        });
944
    }
1228
    }
945
 
1229
 
946
 
-
 
947
    public void fetchOrderDetails() {
1230
    public void fetchOrderDetails() {
948
        if (isInternetOn()) {
1231
        if (isInternetOn()) {
949
            new FetchOrderURLS().execute();
1232
            new FetchOrderURLS().execute();
950
        }
1233
        }
951
    }
1234
    }
Line 1104... Line 1387...
1104
 
1387
 
1105
    class javascriptInterface {
1388
    class javascriptInterface {
1106
 
1389
 
1107
        WebView view;
1390
        WebView view;
1108
 
1391
 
1109
        @JavascriptInterface
-
 
1110
        public void otpSent() {
-
 
1111
            getActivity().registerReceiver(smsListener, new IntentFilter(SMS_RECEIVED));
-
 
1112
        }
1392
 
1113
 
1393
 
1114
 
1394
 
1115
        /**
1395
        /**
1116
         * Instantiate the interface and set the context
1396
         * Instantiate the interface and set the context
1117
         */
1397
         */
1118
        public javascriptInterface(WebView c) {
1398
        public javascriptInterface(WebView c) {
1119
 
1399
 
1120
            this.view=c;
1400
            this.view=c;
1121
        }
1401
        }
-
 
1402
        @JavascriptInterface
-
 
1403
        public void otpSent() {
-
 
1404
            //Toast.makeText(getActivity(),"successfull",Toast.LENGTH_LONG).show();
-
 
1405
            getActivity().registerReceiver(broadcastReceiver, new IntentFilter(SMS_RECEIVED));
1122
 
1406
        }
1123
            @JavascriptInterface
1407
        @JavascriptInterface
1124
            public void performClick(String strl) {
1408
        public void performClick(String strl) {
1125
                Toast.makeText(getActivity(), strl, Toast.LENGTH_SHORT).show();
1409
            Toast.makeText(getActivity(), strl, Toast.LENGTH_SHORT).show();
1126
 
-
 
1127
            }
1410
        }
1128
        @JavascriptInterface
1411
        @JavascriptInterface
1129
        public void authTokenChange(String newToken) {
1412
        public void authTokenChange(String newToken) {
-
 
1413
            userDataEditor.putString("token" ,newToken);
-
 
1414
            Log.d("newtoken",newToken);
-
 
1415
            userDataEditor.commit();
1130
            new AuthtokenChange().execute();
1416
            new AuthTokenChange().execute();
-
 
1417
        }
1131
 
1418
 
-
 
1419
        @JavascriptInterface
-
 
1420
        public void logout() {
-
 
1421
            try{
-
 
1422
                if (mGoogleApiClient.isConnected()) {
-
 
1423
                    Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
-
 
1424
                    mGoogleApiClient.disconnect();
-
 
1425
                    mGoogleApiClient.connect();
-
 
1426
                    userDataEditor.clear().commit();
-
 
1427
                    startActivity(new Intent(getActivity(), LoginActivity.class));
-
 
1428
                }
-
 
1429
                else{
-
 
1430
                    if(!mGoogleApiClient.isConnected()){
-
 
1431
                        userDataEditor.clear().commit();
-
 
1432
                        startActivity(new Intent(getActivity(), LoginActivity.class));
-
 
1433
                    }
-
 
1434
 
-
 
1435
 
-
 
1436
                }
-
 
1437
            }catch (Exception e){
-
 
1438
                userDataEditor.clear().commit();
-
 
1439
                startActivity(new Intent(getActivity(), LoginActivity.class));
-
 
1440
            }
1132
        }
1441
        }
1133
 
1442
 
1134
        @JavascriptInterface
1443
        @JavascriptInterface
1135
        public void showToast(String toast) {
1444
        public void showToast(String toast) {
1136
            nameValuePairsRawHtml.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(toast)));
1445
            nameValuePairsRawHtml.add(new BasicNameValuePair("rawhtml", UtilityFunctions.compress(toast)));
Line 1180... Line 1489...
1180
 
1489
 
1181
        @JavascriptInterface
1490
        @JavascriptInterface
1182
        public void orderpage(String html) {
1491
        public void orderpage(String html) {
1183
 
1492
 
1184
            nameValuePairsRawHtml.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
1493
            nameValuePairsRawHtml.add(new BasicNameValuePair("html", UtilityFunctions.compress(html)));
1185
            nameValuePairsRawHtml.add(new BasicNameValuePair("url",apiData.getString("flipkart.response.url","")));
1494
            nameValuePairsRawHtml.add(new BasicNameValuePair("url",apiData.getString("flipkart.response.url","https://www.flipkart.com/rv/accounts")));
1186
            nameValuePairsRawHtml.add(new BasicNameValuePair("zip","1"));
1495
            nameValuePairsRawHtml.add(new BasicNameValuePair("zip","1"));
1187
            new ProcessFlipkartHtml().execute();
1496
            new ProcessFlipkartHtml().execute();
1188
        }
1497
        }
1189
 
1498
 
1190
        @JavascriptInterface
1499
        @JavascriptInterface
Line 1237... Line 1546...
1237
                j.put("url", html);
1546
                j.put("url", html);
1238
                j.put("user_id", userData.getString("id", null));
1547
                j.put("user_id", userData.getString("id", null));
1239
                j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
1548
                j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
1240
                jsArray.put(j);
1549
                jsArray.put(j);
1241
                obj.put("pushdata", jsArray);
1550
                obj.put("pushdata", jsArray);
1242
               new pushData().execute(obj);
1551
                new pushData().execute(obj);
1243
            } catch (Exception e) {
1552
            } catch (Exception e) {
1244
                e.printStackTrace();
1553
                e.printStackTrace();
1245
            }
1554
            }
1246
            if (html.contains("https://paytm.com/login")) {
1555
            if (html.contains("https://paytm.com/login")) {
1247
                if (!PAYTMFLAG) {
1556
                if (!PAYTMFLAG) {
Line 1265... Line 1574...
1265
                j.put("url", url);
1574
                j.put("url", url);
1266
                j.put("user_id", userData.getString("id", null));
1575
                j.put("user_id", userData.getString("id", null));
1267
                j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
1576
                j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
1268
                jsArray.put(j);
1577
                jsArray.put(j);
1269
                obj.put("pushdata", jsArray);
1578
                obj.put("pushdata", jsArray);
1270
                 new pushData().execute(obj);
1579
                new pushData().execute(obj);
1271
            } catch (Exception e) {
1580
            } catch (Exception e) {
1272
                e.printStackTrace();
1581
                e.printStackTrace();
1273
            }
1582
            }
1274
            if (url.contains("https://www.flipkart.com/login")) {
1583
            if (url.contains("https://www.flipkart.com/login")) {
1275
                Flipkartflag = true;
1584
                Flipkartflag = true;
1276
                userDataEditor.putString("flipkartOrder", "true").commit();
1585
                userDataEditor.putString("flipkartOrder", "true").commit();
1277
                userDataEditor.putBoolean("flipkartLoggedIn", true).commit();
1586
                userDataEditor.putBoolean("flipkartLoggedIn", true).commit();
1278
            }
1587
            }
1279
        }
1588
        }
1280
    }
1589
    }
1281
    class AuthtokenChange extends AsyncTask<String, Integer, String> {
1590
    class AuthTokenChange extends AsyncTask<String, Integer, String> {
1282
 
1591
 
1283
        @Override
1592
        @Override
1284
        protected void onPreExecute() {
1593
        protected void onPreExecute() {
1285
 
1594
 
1286
            super.onPreExecute();
1595
            super.onPreExecute();
1287
        }
1596
        }
-
 
1597
 
1288
        @Override
1598
        @Override
1289
        protected String doInBackground(String... params) {
1599
        protected String doInBackground(String... params) {
1290
            try {
1600
            try {
1291
                HttpClient httpclient = new DefaultHttpClient();
1601
                HttpClient httpclient = new DefaultHttpClient();
-
 
1602
                HttpGet httpget=new HttpGet(apiData.getString("Web_Api","http://shop2020.in:8080/profitmandi-web")+"/user/token-info");
1292
                HttpPost httppost = new HttpPost(ProfitTillConstants.Web_Api+"/user/token-info");
1603
                // HttpGet httpget = new HttpGet(ProfitTillConstants.Web_Api + "/user/token-info");
1293
                httppost.setHeader("Auth-Token",userData.getString("token",""));
1604
                httpget.setHeader("Auth-Token", userData.getString("token", ""));
1294
                HttpResponse response = httpclient.execute(httppost);
1605
                HttpResponse response = httpclient.execute(httpget);
1295
                HttpEntity entity = response.getEntity();
1606
                HttpEntity entity = response.getEntity();
1296
                int status = response.getStatusLine().getStatusCode();
1607
                int status = response.getStatusLine().getStatusCode();
1297
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
1608
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
-
 
1609
                Log.d("Json",String.valueOf(jObjGmail));
1298
                return String.valueOf(jObjGmail);
1610
                return String.valueOf(jObjGmail);
1299
 
1611
 
1300
            }
-
 
1301
            catch (UnsupportedEncodingException e) {
1612
            } catch (UnsupportedEncodingException e) {
1302
                e.printStackTrace();
1613
                e.printStackTrace();
1303
            }
-
 
1304
            catch (IOException e) {
1614
            } catch (IOException e) {
1305
                e.printStackTrace();
1615
                e.printStackTrace();
1306
            } catch (JSONException e) {
1616
            } catch (JSONException e) {
1307
                e.printStackTrace();
1617
                e.printStackTrace();
1308
            }
1618
            }
1309
            return null;
1619
            return null;
1310
        }
1620
        }
1311
 
1621
 
-
 
1622
        @Override
-
 
1623
        protected void onPostExecute(String result) {
-
 
1624
            super.onPostExecute(result);
-
 
1625
            try {
-
 
1626
                JSONObject jsonObject = new JSONObject(result);
-
 
1627
                JSONObject jobj=jsonObject.getJSONObject("response");
-
 
1628
                String userStatus=jobj.getString("userStatus");
-
 
1629
                userDataEditor.putString("userStatus",userStatus);
-
 
1630
                userDataEditor.commit();
-
 
1631
                if(!(userData.getString("userStatus","").equals("notRegistered"))) {
-
 
1632
                    String user_id = jobj.getString("userId");
-
 
1633
                    userDataEditor.putString("id", user_id);
-
 
1634
                    userDataEditor.commit();
-
 
1635
                    if(!(userData.getString("id", "").equals(""))){
-
 
1636
                        UtilityFunctions utf = new UtilityFunctions();
-
 
1637
                        new pushApkData().execute(utf.getDeviceInformation(getActivity()));
-
 
1638
                    }
-
 
1639
                    else {
-
 
1640
                        Toast.makeText(getActivity(),"Network issue",Toast.LENGTH_LONG).show();
-
 
1641
                    }}
-
 
1642
                else{
-
 
1643
 
-
 
1644
                }
-
 
1645
            }
-
 
1646
            catch (JSONException e) {
-
 
1647
                e.printStackTrace();
-
 
1648
            }
-
 
1649
        }
-
 
1650
    }
-
 
1651
    class pushApkData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
-
 
1652
 
-
 
1653
        @Override
-
 
1654
        protected void onPreExecute() {
-
 
1655
            super.onPreExecute();
1312
        }
1656
        }
1313
 
1657
 
-
 
1658
        @Override
-
 
1659
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
-
 
1660
            try {
-
 
1661
                HttpClient httpclient = new DefaultHttpClient();
-
 
1662
                HttpPost httppost = new HttpPost("http://api.profittill.com/devices/add");
-
 
1663
                //HttpPost httppost = new HttpPost(ProfitTillConstants.Push_Url);
-
 
1664
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
-
 
1665
                httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
-
 
1666
                HttpResponse response = httpclient.execute(httppost);
-
 
1667
                HttpEntity entity = response.getEntity();
-
 
1668
                int status = response.getStatusLine().getStatusCode();
-
 
1669
                if(status == 200){
-
 
1670
                    return "success";
-
 
1671
                } else {
-
 
1672
                    return "failure";
-
 
1673
                }
-
 
1674
            } catch (Exception e) {
-
 
1675
                return null;
-
 
1676
            }
-
 
1677
        }
-
 
1678
        @Override
-
 
1679
        protected void onPostExecute(String result) {
-
 
1680
            super.onPostExecute(result);
-
 
1681
            if (userData.getString("fcm_token_sent", "false").equals("false") && (!userData.getString("id", "").equals(""))) {
-
 
1682
                regId = FirebaseInstanceId.getInstance().getToken();
-
 
1683
                Log.d("RegisterActivity", "registerInBackground - regId: "
-
 
1684
                        + regId);
-
 
1685
                msg = "Device registered";
-
 
1686
                new gcmPushData().execute(msg);
-
 
1687
            }}}
-
 
1688
 
-
 
1689
    class gcmPushData extends AsyncTask<String, Integer, String> {
-
 
1690
 
-
 
1691
        @Override
-
 
1692
        protected void onPreExecute() {
-
 
1693
            super.onPreExecute();
-
 
1694
        }
-
 
1695
 
-
 
1696
        @Override
-
 
1697
        protected String doInBackground(String... arg0) {
-
 
1698
            String id = null;
-
 
1699
            try {
-
 
1700
                HttpClient httpclient = new DefaultHttpClient();
-
 
1701
                HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", ""));
-
 
1702
                //HttpPost httppost = new HttpPost(ProfitTillConstants.gcm_url);
-
 
1703
                ArrayList<NameValuePair> nameValuePairsGcm = new ArrayList<>();
-
 
1704
                TelephonyManager telephonyManager = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
-
 
1705
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
-
 
1706
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
-
 
1707
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
-
 
1708
                nameValuePairsGcm.add(new BasicNameValuePair("notification_type","fcm"));
-
 
1709
                nameValuePairsGcm.add(new BasicNameValuePair("device_message", arg0[0]));
-
 
1710
                nameValuePairsGcm.add(new BasicNameValuePair("androidid", UtilityFunctions.androidId(getActivity())));
-
 
1711
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
-
 
1712
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
-
 
1713
                HttpResponse response = httpclient.execute(httppost);
-
 
1714
                HttpEntity entity = response.getEntity();
-
 
1715
                int status = response.getStatusLine().getStatusCode();
-
 
1716
 
-
 
1717
                if (status == 200) {
-
 
1718
                    Log.d("ResponseCode GCM ", status + "");
-
 
1719
                    userDataEditor.putString("fcm_token_sent", "true");
-
 
1720
                    userDataEditor.commit();
-
 
1721
                } else {
-
 
1722
                    Log.d("ResponseCode GCM ", status + "");
-
 
1723
                }
-
 
1724
                nameValuePairsGcm.clear();
-
 
1725
                Log.e("pass 1", "connection success ");
-
 
1726
            } catch (Exception e) {
-
 
1727
                Log.e("Fail 1", e.toString());
-
 
1728
 
-
 
1729
            }
-
 
1730
            return null;
-
 
1731
        }
-
 
1732
 
-
 
1733
        @Override
-
 
1734
        protected void onPostExecute(String result)
-
 
1735
        {
-
 
1736
 
-
 
1737
            super.onPostExecute(result);
-
 
1738
        }}
-
 
1739
 
1314
        class loadData extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
1740
    class loadData extends AsyncTask<List<NameValuePair>, Integer, JSONObject> {
1315
 
1741
 
1316
        @Override
1742
        @Override
1317
        protected void onPreExecute() {
1743
        protected void onPreExecute() {
1318
            super.onPreExecute();
1744
            super.onPreExecute();
1319
        }
1745
        }
Line 1692... Line 2118...
1692
            }
2118
            }
1693
            FLAG = false;
2119
            FLAG = false;
1694
        }
2120
        }
1695
    }
2121
    }
1696
 
2122
 
-
 
2123
    class SendOtpMessage extends AsyncTask<String, Integer, String> {
-
 
2124
 
-
 
2125
        @Override
-
 
2126
        protected void onPreExecute() {
-
 
2127
 
-
 
2128
            super.onPreExecute();
-
 
2129
        }
-
 
2130
 
-
 
2131
        @Override
-
 
2132
        protected String doInBackground(String... params) {
-
 
2133
            try {
-
 
2134
 
-
 
2135
                HttpClient httpclient = new DefaultHttpClient();
-
 
2136
                HttpPost httppost = new HttpPost(apiData.getString("Web_Api","http://shop2020.in:8080/profitmandi-web") + "/otp/parseOTP");
-
 
2137
                //HttpPost httppost = new HttpPost(ProfitTillConstants.Web_Api + "/otp/parseOTP");
-
 
2138
                httppost.setHeader("Auth-Token", userData.getString("token", ""));
-
 
2139
                httppost.setEntity(new UrlEncodedFormEntity(messageNameValuePair));
-
 
2140
                HttpResponse response = httpclient.execute(httppost);
-
 
2141
                HttpEntity entity = response.getEntity();
-
 
2142
                int status = response.getStatusLine().getStatusCode();
-
 
2143
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
-
 
2144
                return String.valueOf(jObjGmail);
-
 
2145
 
-
 
2146
            }
-
 
2147
            catch (UnsupportedEncodingException e) {
-
 
2148
                e.printStackTrace();
-
 
2149
            }
-
 
2150
            catch (IOException e) {
-
 
2151
                e.printStackTrace();
-
 
2152
            }
-
 
2153
            catch (JSONException e) {
-
 
2154
                e.printStackTrace();
-
 
2155
            }
-
 
2156
            return null;
-
 
2157
        }
-
 
2158
        @Override
-
 
2159
        protected void onPostExecute(String result) {
-
 
2160
            super.onPostExecute(result);
-
 
2161
            try {
-
 
2162
                JSONObject jsonObject = new JSONObject(result);
-
 
2163
                String response=jsonObject.getString("response");
-
 
2164
 
-
 
2165
                String js = ("javascript:window.localStorage.setItem('android.otpReceived','"+response +"');");
-
 
2166
                webView.loadUrl(js);
-
 
2167
                //webView.loadUrl("javascript:alert(window.localStorage.getItem('android.otpReceived'))");
-
 
2168
 
-
 
2169
                Log.d("otp",js);
-
 
2170
           /* for(int i=1; i<6; i++){
-
 
2171
                js += "document.getElementsByName('otp" + i + "')[0].value ='" +response.substring(i-1,i) + "';";
-
 
2172
 
-
 
2173
            }
-
 
2174
                 /* String js = ("javascript:document.getElementsByName('otp1')[0].value ='"+response +"';");
-
 
2175
                //js +="document.getElementsByName('otpForm')[0].submit();";
-
 
2176
               // Log.d("otp",js);
-
 
2177
            if (Build.VERSION.SDK_INT >= 19) {
-
 
2178
                webView.evaluateJavascript(js, new ValueCallback<String>() {
-
 
2179
                    @Override
-
 
2180
                    public void onReceiveValue(String s) {
-
 
2181
 
-
 
2182
                    }
-
 
2183
                });
-
 
2184
            } else {
-
 
2185
                webView.loadUrl(js);
-
 
2186
            }*/
-
 
2187
                //String js2 =("javascript:document.getElementById('').click()");
-
 
2188
                //webView.loadUrl(js2);
-
 
2189
            } catch (JSONException e) {
-
 
2190
                e.printStackTrace();
-
 
2191
            }
-
 
2192
        }
-
 
2193
 
-
 
2194
    }
-
 
2195
 
1697
    int sizeList;
2196
    int sizeList;
1698
 
2197
 
1699
    class FetchOrderURLS extends AsyncTask<String, Integer, JSONObject> {
2198
    class FetchOrderURLS extends AsyncTask<String, Integer, JSONObject> {
1700
 
2199
 
1701
        @Override
2200
        @Override