Subversion Repositories SmartDukaan

Rev

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

Rev 18082 Rev 19653
Line 78... Line 78...
78
            String apkVersionName = apkData.getString("versionName","");
78
            String apkVersionName = apkData.getString("versionName","");
79
            if(userData.getString("id","").isEmpty()) {
79
            if(userData.getString("id","").isEmpty()) {
80
 
80
 
81
            }else {
81
            }else {
82
                if (apkVersionCode.isEmpty()) {
82
                if (apkVersionCode.isEmpty()) {
83
                    /*PackageManager manager = this.getPackageManager();
-
 
84
                    PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
-
 
85
                    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
-
 
86
                    apkDataListValue = new ArrayList<>();
-
 
87
                    apkDataListValue.add(new BasicNameValuePair("user_id",userData.getString("id","")));
-
 
88
                    apkDataListValue.add(new BasicNameValuePair("versioncode",info.versionCode+""));
-
 
89
                    apkDataListValue.add(new BasicNameValuePair("versionname",info.versionName+""));
-
 
90
                    apkDataListValue.add(new BasicNameValuePair("osversion",android.os.Build.VERSION.SDK_INT+""));
-
 
91
                    apkDataListValue.add(new BasicNameValuePair("imeinumber",telephonyManager.getDeviceId()));
-
 
92
                    apkDataListValue.add(new BasicNameValuePair("manufacturer",Build.MANUFACTURER));
-
 
93
                    apkDataListValue.add(new BasicNameValuePair("model",Build.MODEL));
-
 
94
                    apkDataListValue.add(new BasicNameValuePair("brand",Build.BRAND));
-
 
95
                    apkDataEditor.putString("versionCode", info.versionCode + "");
-
 
96
                    apkDataEditor.putString("versionName", info.versionName);
-
 
97
                    apkDataEditor.putString("osVersion",android.os.Build.VERSION.SDK_INT+"");
-
 
98
                    apkDataEditor.putString("imeiNumber",telephonyManager.getDeviceId());*/
-
 
99
                    utilityFunctions=new UtilityFunctions();
83
                    utilityFunctions=new UtilityFunctions();
100
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
84
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
101
 
85
 
102
                    if(isInternetOn()) {
86
                    if(isInternetOn()) {
103
                        new pushApkData().execute();
87
                        new pushApkData().execute();
Line 119... Line 103...
119
                }
103
                }
120
            }
104
            }
121
        }catch (Exception e){
105
        }catch (Exception e){
122
            e.printStackTrace();
106
            e.printStackTrace();
123
        }
107
        }
124
 
-
 
125
 
-
 
126
        if(isInternetOn()){
108
        if(isInternetOn()){
127
                new fetchAPISettings().execute();
109
                new fetchAPISettings().execute();
128
        }
110
        }
129
        else{
111
        else{
130
            b= new AlertDialog.Builder(this);
112
            b= new AlertDialog.Builder(this);
Line 153... Line 135...
153
                }
135
                }
154
            });
136
            });
155
            dialog1 = b.create();
137
            dialog1 = b.create();
156
            dialog1.show();
138
            dialog1.show();
157
        }
139
        }
158
 
-
 
159
 
-
 
160
    }
140
    }
161
 
141
 
162
 
142
 
163
    @Override
143
    @Override
164
    public boolean onCreateOptionsMenu(Menu menu) {
144
    public boolean onCreateOptionsMenu(Menu menu) {
165
        // Inflate the menu; this adds items to the action bar if it is present.
-
 
166
        getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
145
        getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
167
        return true;
146
        return true;
168
    }
147
    }
169
 
148
 
170
    @Override
149
    @Override
171
    public boolean onOptionsItemSelected(MenuItem item) {
150
    public boolean onOptionsItemSelected(MenuItem item) {
172
        // Handle action bar item clicks here. The action bar will
-
 
173
        // automatically handle clicks on the Home/Up button, so long
-
 
174
        // as you specify a parent activity in AndroidManifest.xml.
-
 
175
        int id = item.getItemId();
151
        int id = item.getItemId();
176
 
-
 
177
        //noinspection SimplifiableIfStatement
-
 
178
        if (id == R.id.action_settings) {
152
        if (id == R.id.action_settings) {
179
            return true;
153
            return true;
180
        }
154
        }
181
 
155
 
182
        return super.onOptionsItemSelected(item);
156
        return super.onOptionsItemSelected(item);
Line 193... Line 167...
193
        protected JSONObject doInBackground(String... arg0) {
167
        protected JSONObject doInBackground(String... arg0) {
194
            try {
168
            try {
195
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
169
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
196
                HttpClient httpclient = new DefaultHttpClient();
170
                HttpClient httpclient = new DefaultHttpClient();
197
                String url = ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0")+"&imeinumber="+telephonyManager.getDeviceId();
171
                String url = ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0")+"&imeinumber="+telephonyManager.getDeviceId();
198
                //HttpPost httppost = new HttpPost(ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0"));
-
 
199
                HttpPost httppost=new HttpPost(url);
172
                HttpPost httppost=new HttpPost(url);
200
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
173
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
201
                HttpResponse response = httpclient.execute(httppost);
174
                HttpResponse response = httpclient.execute(httppost);
202
                HttpEntity entity = response.getEntity();
175
                HttpEntity entity = response.getEntity();
203
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
176
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
Line 232... Line 205...
232
                String timestamp=result.getString("t");
205
                String timestamp=result.getString("t");
233
                String failureCount=result.getString("failureCount");
206
                String failureCount=result.getString("failureCount");
234
                apkDataEditor.putString("timestamp",timestamp);
207
                apkDataEditor.putString("timestamp",timestamp);
235
                apkDataEditor.commit();
208
                apkDataEditor.commit();
236
                final String idCheck = userData.getString("id",null);
209
                final String idCheck = userData.getString("id",null);
237
                //String check = userData.getString("which screen needs to be displayed");
-
 
238
                if(Integer.parseInt(failureCount)<=0) {
210
                if(Integer.parseInt(failureCount)<=0) {
239
                    if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
211
                    if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
240
                        Intent startActivityIntent=new Intent(SplashScreen.this, ReferrerActivity.class);
212
                        Intent startActivityIntent=new Intent(SplashScreen.this, ReferrerActivity.class);
241
                        Intent intent = getIntent();
213
                        Intent intent = getIntent();
242
                        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
214
                        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
243
                            Uri uri = intent.getData();
215
                            Uri uri = intent.getData();
244
                            startActivityIntent.setAction("31");
216
                            startActivityIntent.setAction("31");
245
                            startActivityIntent.setData(Uri.parse(uri.toString()));
217
                            startActivityIntent.setData(Uri.parse(uri.toString()));
246
                        }
218
                        }
247
                        startActivity(startActivityIntent);
219
                        startActivity(startActivityIntent);
248
                        //startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
-
 
249
                    } else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
220
                    } else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
250
                        Intent startActivityIntent=new Intent(SplashScreen.this, MobileNumber.class);
221
                        Intent startActivityIntent=new Intent(SplashScreen.this, MobileNumber.class);
251
                        Intent intent = getIntent();
222
                        Intent intent = getIntent();
252
                        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
223
                        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
253
                            Uri uri = intent.getData();
224
                            Uri uri = intent.getData();
254
                            startActivityIntent.setAction("31");
225
                            startActivityIntent.setAction("31");
255
                            startActivityIntent.setData(Uri.parse(uri.toString()));
226
                            startActivityIntent.setData(Uri.parse(uri.toString()));
256
                        }
227
                        }
257
                        startActivity(startActivityIntent);
228
                        startActivity(startActivityIntent);
258
                        //startActivity(new Intent(SplashScreen.this, MobileNumber.class));
-
 
259
                    } else if (idCheck != null) {
229
                    } else if (idCheck != null) {
260
                        Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
230
                        Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
261
                        Intent intent = getIntent();
231
                        Intent intent = getIntent();
262
                        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
232
                        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
263
                            Uri uri = intent.getData();
233
                            Uri uri = intent.getData();
Line 272... Line 242...
272
                            Uri uri = intent.getData();
242
                            Uri uri = intent.getData();
273
                            startActivityIntent.setAction("31");
243
                            startActivityIntent.setAction("31");
274
                            startActivityIntent.setData(Uri.parse(uri.toString()));
244
                            startActivityIntent.setData(Uri.parse(uri.toString()));
275
                        }
245
                        }
276
                        startActivity(startActivityIntent);
246
                        startActivity(startActivityIntent);
277
                        //startActivity(new Intent(SplashScreen.this, LoginActivity.class));
-
 
278
 
-
 
279
                    }
247
                    }
280
                }else{
248
                }else{
281
                    registerGCM();
249
                    registerGCM();
282
                }
250
                }
283
            }catch (Exception e){
251
            }catch (Exception e){
Line 330... Line 298...
330
        ConnectivityManager connection =
298
        ConnectivityManager connection =
331
                (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
299
                (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
332
 
300
 
333
        if (    connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
301
        if (    connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
334
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
302
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
335
 
-
 
336
            /*Toast.makeText(this, " Connected ", Toast.LENGTH_LONG).show();*/
-
 
337
            return true;
303
            return true;
338
 
304
 
339
        } else if (
305
        } else if (
340
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
306
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
341
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
307
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
342
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
308
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
343
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
309
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
344
 
-
 
345
/*            Toast.makeText(this, " Not Connected ", Toast.LENGTH_LONG).show();*/
-
 
346
            return false;
310
            return false;
347
        }
311
        }
348
        return false;
312
        return false;
349
    }
313
    }
350
 
314
 
Line 356... Line 320...
356
        pDlg.show();
320
        pDlg.show();
357
    }
321
    }
358
 
322
 
359
    ProgressDialog pDlg;
323
    ProgressDialog pDlg;
360
 
324
 
361
/*
-
 
362
 
-
 
363
    @Override
-
 
364
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
-
 
365
        Log.d("On Restore Instance","On Restore Instance");
-
 
366
        super.onRestoreInstanceState(savedInstanceState);
-
 
367
    }
-
 
368
 
-
 
369
    @Override
-
 
370
    protected void onRestart() {
-
 
371
        Log.d("On Restart","On Restart");
-
 
372
        super.onRestart();
-
 
373
 
-
 
374
        try {
-
 
375
            String apkVersionCode = apkData.getString("versionCode","");
-
 
376
            String apkVersionName = apkData.getString("versionName","");
-
 
377
            if(userData.getString("id","").isEmpty()) {
-
 
378
 
-
 
379
            }else {
-
 
380
                if (apkVersionCode.isEmpty()) {
-
 
381
                    apkDataListValue = getDeviceInformation();
-
 
382
 
-
 
383
                    if(isInternetOn()) {
-
 
384
                        new pushApkData().execute();
-
 
385
                    }
-
 
386
                } else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
-
 
387
                    apkDataListValue = getDeviceInformation();
-
 
388
                    if(isInternetOn()) {
-
 
389
                        new pushApkData().execute();
-
 
390
                    }
-
 
391
                } else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
-
 
392
 
-
 
393
                }  else {
-
 
394
                    apkDataListValue = getDeviceInformation();
-
 
395
                    if(isInternetOn()) {
-
 
396
                        new pushApkData().execute();
-
 
397
                    }
-
 
398
                }
-
 
399
            }
-
 
400
        }catch (Exception e){
-
 
401
            e.printStackTrace();
-
 
402
        }
-
 
403
 
-
 
404
        if(isInternetOn()){
-
 
405
            new fetchAPISettings().execute();
-
 
406
        }
-
 
407
        else{
-
 
408
            b= new AlertDialog.Builder(this);
-
 
409
            b.setMessage("No internet connection. Please try again.");
-
 
410
            b.setCancelable(false);
-
 
411
            b.setPositiveButton("Retry", new DialogInterface.OnClickListener()
-
 
412
            {
-
 
413
                @Override
-
 
414
                public void onClick(DialogInterface dialog, int which) {
-
 
415
                    if(isInternetOn()){
-
 
416
                        new fetchAPISettings().execute();
-
 
417
                        dialog1.dismiss();
-
 
418
                    }
-
 
419
                    else{
-
 
420
                        dialog1 = b.create();
-
 
421
                        dialog1.show();
-
 
422
                    }
-
 
423
                }
-
 
424
 
-
 
425
            });
-
 
426
            b.setNegativeButton("No", new DialogInterface.OnClickListener() {
-
 
427
                @Override
-
 
428
                public void onClick(DialogInterface dialog, int which) {
-
 
429
                    finish();
-
 
430
 
-
 
431
                }
-
 
432
            });
-
 
433
            dialog1 = b.create();
-
 
434
            dialog1.show();
-
 
435
        }
-
 
436
 
-
 
437
    }
-
 
438
 
-
 
439
 
-
 
440
    public ArrayList<NameValuePair> getDeviceInformation(){
-
 
441
        ArrayList<NameValuePair> deviceDataList=null;
-
 
442
        try {
-
 
443
            PackageManager manager = this.getPackageManager();
-
 
444
            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
-
 
445
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-
 
446
            deviceDataList = new ArrayList<>();
-
 
447
            deviceDataList.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
-
 
448
            deviceDataList.add(new BasicNameValuePair("versioncode", info.versionCode + ""));
-
 
449
            deviceDataList.add(new BasicNameValuePair("versionname", info.versionName + ""));
-
 
450
            deviceDataList.add(new BasicNameValuePair("osversion", android.os.Build.VERSION.SDK_INT + ""));
-
 
451
            deviceDataList.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
-
 
452
            deviceDataList.add(new BasicNameValuePair("manufacturer", Build.MANUFACTURER));
-
 
453
            deviceDataList.add(new BasicNameValuePair("model", Build.MODEL));
-
 
454
            deviceDataList.add(new BasicNameValuePair("brand", Build.BRAND));
-
 
455
            apkDataEditor.putString("versionCode", info.versionCode + "");
-
 
456
            apkDataEditor.putString("versionName", info.versionName);
-
 
457
            apkDataEditor.putString("osVersion", android.os.Build.VERSION.SDK_INT + "");
-
 
458
            apkDataEditor.putString("imeiNumber", telephonyManager.getDeviceId());
-
 
459
        }catch (Exception e){
-
 
460
            e.printStackTrace();
-
 
461
        }
-
 
462
        return deviceDataList;
-
 
463
    }
-
 
464
*/
-
 
465
 
-
 
466
    /*@Override
-
 
467
    protected void onPause() {
-
 
468
        Log.d("On Pause","On Pause");
-
 
469
        super.onPause();
-
 
470
    }*/
-
 
471
    public void registerGCM() {
325
    public void registerGCM() {
472
 
326
 
473
        gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
327
        gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
474
        registerInBackground();
328
        registerInBackground();
475
 
329
 
Line 511... Line 365...
511
        @Override
365
        @Override
512
        protected String doInBackground(String... arg0) {
366
        protected String doInBackground(String... arg0) {
513
            String id = null;
367
            String id = null;
514
            try {
368
            try {
515
                HttpClient httpclient = new DefaultHttpClient();
369
                HttpClient httpclient = new DefaultHttpClient();
516
                HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://staging.profittill.com/gcm_users/add"));
370
                HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://api.profittill.com/gcm_users/add"));
517
                nameValuePairsGcm = new ArrayList<>();
371
                nameValuePairsGcm = new ArrayList<>();
518
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
372
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
519
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
373
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
520
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
374
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
521
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
375
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
522
                nameValuePairsGcm.add(new BasicNameValuePair("device_message", arg0[0]));
376
                nameValuePairsGcm.add(new BasicNameValuePair("device_message", arg0[0]));
-
 
377
                nameValuePairsGcm.add(new BasicNameValuePair("androidid", UtilityFunctions.androidId(SplashScreen.this)));
523
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
378
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
524
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
379
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
525
                HttpResponse response = httpclient.execute(httppost);
380
                HttpResponse response = httpclient.execute(httppost);
526
                HttpEntity entity = response.getEntity();
381
                HttpEntity entity = response.getEntity();
527
                int status = response.getStatusLine().getStatusCode();
382
                int status = response.getStatusLine().getStatusCode();