Subversion Repositories SmartDukaan

Rev

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

Rev 16080 Rev 16278
Line 19... Line 19...
19
 
19
 
20
import com.google.android.gms.analytics.HitBuilders;
20
import com.google.android.gms.analytics.HitBuilders;
21
import com.google.android.gms.analytics.Tracker;
21
import com.google.android.gms.analytics.Tracker;
22
import com.google.android.gms.gcm.GoogleCloudMessaging;
22
import com.google.android.gms.gcm.GoogleCloudMessaging;
23
import com.saholic.profittill.Constants.ProfitTillConstants;
23
import com.saholic.profittill.Constants.ProfitTillConstants;
-
 
24
import com.saholic.profittill.Utils.AnalyticsUtility;
24
import com.saholic.profittill.Utils.UtilityFunctions;
25
import com.saholic.profittill.Utils.UtilityFunctions;
-
 
26
import com.saholic.profittill.Volley.Analytics;
-
 
27
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
-
 
28
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
25
import com.saholic.profittill.main.GoogleAnalyticsTracker;
29
import com.saholic.profittill.main.GoogleAnalyticsTracker;
26
import com.saholic.profittill.main.LoginActivity;
30
import com.saholic.profittill.main.LoginActivity;
27
import com.saholic.profittill.main.MainActivity;
31
import com.saholic.profittill.main.MainActivity;
28
import com.saholic.profittill.main.MobileNumber;
32
import com.saholic.profittill.main.MobileNumber;
29
import com.saholic.profittill.main.ReferrerActivity;
33
import com.saholic.profittill.main.ReferrerActivity;
Line 66... Line 70...
66
        apkData = getApplicationContext().getSharedPreferences("APK_Data", MODE_PRIVATE);
70
        apkData = getApplicationContext().getSharedPreferences("APK_Data", MODE_PRIVATE);
67
        apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
71
        apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
68
        apkDataEditor = apkData.edit();
72
        apkDataEditor = apkData.edit();
69
        userEditor = userData.edit();
73
        userEditor = userData.edit();
70
        apiEditor = apiData.edit();
74
        apiEditor = apiData.edit();
71
        String url="";
-
 
72
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
75
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
73
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
76
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
74
        t.setScreenName("Splash Screen");
77
        t.setScreenName("Splash Screen");
75
        t.send(new HitBuilders.ScreenViewBuilder().build());
78
        t.send(new HitBuilders.ScreenViewBuilder().build());
76
        try {
79
        try {
Line 78... Line 81...
78
            String apkVersionName = apkData.getString("versionName","");
81
            String apkVersionName = apkData.getString("versionName","");
79
            if(userData.getString("id","").isEmpty()) {
82
            if(userData.getString("id","").isEmpty()) {
80
 
83
 
81
            }else {
84
            }else {
82
                if (apkVersionCode.isEmpty()) {
85
                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();
86
                    utilityFunctions=new UtilityFunctions();
100
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
87
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
101
 
88
 
102
                    if(isInternetOn()) {
89
                    if(isInternetOn()) {
-
 
90
                        new Analytics(ProfitTillConstants.ANALYTICS_URL,
-
 
91
                                AnalyticsUtility.getAnalyticsRequest(SplashScreen.this, userData.getString("id", ""), "Screen", "Splash", "Splash Screen"),
-
 
92
                                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
-
 
93
                                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(SplashScreen.this);
103
                        new pushApkData().execute();
94
                        new pushApkData().execute();
104
                    }
95
                    }
105
                } else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
96
                } else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
106
                    utilityFunctions=new UtilityFunctions();
97
                    utilityFunctions=new UtilityFunctions();
107
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
98
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
108
                    if(isInternetOn()) {
99
                    if(isInternetOn()) {
-
 
100
                        new Analytics(ProfitTillConstants.ANALYTICS_URL,
-
 
101
                                AnalyticsUtility.getAnalyticsRequest(SplashScreen.this, userData.getString("id", ""), "Screen", "Splash", "Splash Screen"),
-
 
102
                                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
-
 
103
                                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(SplashScreen.this);
109
                        new pushApkData().execute();
104
                        new pushApkData().execute();
110
                    }
105
                    }
111
                } else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
106
                } else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
112
 
107
 
113
                }  else {
108
                }  else {
114
                    utilityFunctions=new UtilityFunctions();
109
                    utilityFunctions=new UtilityFunctions();
115
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
110
                    apkDataListValue = utilityFunctions.getDeviceInformation(this);
116
                    if(isInternetOn()) {
111
                    if(isInternetOn()) {
-
 
112
                        new Analytics(ProfitTillConstants.ANALYTICS_URL,
-
 
113
                                AnalyticsUtility.getAnalyticsRequest(SplashScreen.this, userData.getString("id", ""), "Screen", "Splash", "Splash Screen"),
-
 
114
                                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
-
 
115
                                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(SplashScreen.this);
117
                        new pushApkData().execute();
116
                        new pushApkData().execute();
118
                    }
117
                    }
119
                }
118
                }
120
            }
119
            }
121
        }catch (Exception e){
120
        }catch (Exception e){
Line 167... Line 166...
167
        return true;
166
        return true;
168
    }
167
    }
169
 
168
 
170
    @Override
169
    @Override
171
    public boolean onOptionsItemSelected(MenuItem item) {
170
    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();
171
        int id = item.getItemId();
176
 
-
 
177
        //noinspection SimplifiableIfStatement
-
 
178
        if (id == R.id.action_settings) {
172
        if (id == R.id.action_settings) {
179
            return true;
173
            return true;
180
        }
174
        }
181
 
175
 
182
        return super.onOptionsItemSelected(item);
176
        return super.onOptionsItemSelected(item);
Line 193... Line 187...
193
        protected JSONObject doInBackground(String... arg0) {
187
        protected JSONObject doInBackground(String... arg0) {
194
            try {
188
            try {
195
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
189
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
196
                HttpClient httpclient = new DefaultHttpClient();
190
                HttpClient httpclient = new DefaultHttpClient();
197
                String url = ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0")+"&imeinumber="+telephonyManager.getDeviceId();
191
                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);
192
                HttpPost httppost=new HttpPost(url);
200
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
193
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
201
                HttpResponse response = httpclient.execute(httppost);
194
                HttpResponse response = httpclient.execute(httppost);
202
                HttpEntity entity = response.getEntity();
195
                HttpEntity entity = response.getEntity();
203
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
196
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
204
                System.out.println(jObjGmail.toString());
-
 
205
                return jObjGmail;
197
                return jObjGmail;
206
 
198
 
207
            } catch (Exception e) {
199
            } catch (Exception e) {
208
                return null;
200
                return null;
209
 
201
 
Line 235... Line 227...
235
                String timestamp=result.getString("t");
227
                String timestamp=result.getString("t");
236
                String failureCount=result.getString("failureCount");
228
                String failureCount=result.getString("failureCount");
237
                apkDataEditor.putString("timestamp",timestamp);
229
                apkDataEditor.putString("timestamp",timestamp);
238
                apkDataEditor.commit();
230
                apkDataEditor.commit();
239
                final String idCheck = userData.getString("id",null);
231
                final String idCheck = userData.getString("id",null);
240
                //String check = userData.getString("which screen needs to be displayed");
-
 
241
                if(Integer.parseInt(failureCount)<=0) {
232
                if(Integer.parseInt(failureCount)<=0) {
242
                    if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
233
                    if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
243
                        startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
234
                        startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
244
                    } else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
235
                    } else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
245
                        startActivity(new Intent(SplashScreen.this, MobileNumber.class));
236
                        startActivity(new Intent(SplashScreen.this, MobileNumber.class));
Line 335... Line 326...
335
        pDlg.show();
326
        pDlg.show();
336
    }
327
    }
337
 
328
 
338
    ProgressDialog pDlg;
329
    ProgressDialog pDlg;
339
 
330
 
340
/*
-
 
341
 
-
 
342
    @Override
-
 
343
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
-
 
344
        Log.d("On Restore Instance","On Restore Instance");
-
 
345
        super.onRestoreInstanceState(savedInstanceState);
-
 
346
    }
-
 
347
 
-
 
348
    @Override
-
 
349
    protected void onRestart() {
-
 
350
        Log.d("On Restart","On Restart");
-
 
351
        super.onRestart();
-
 
352
 
-
 
353
        try {
-
 
354
            String apkVersionCode = apkData.getString("versionCode","");
-
 
355
            String apkVersionName = apkData.getString("versionName","");
-
 
356
            if(userData.getString("id","").isEmpty()) {
-
 
357
 
-
 
358
            }else {
-
 
359
                if (apkVersionCode.isEmpty()) {
-
 
360
                    apkDataListValue = getDeviceInformation();
-
 
361
 
-
 
362
                    if(isInternetOn()) {
-
 
363
                        new pushApkData().execute();
-
 
364
                    }
-
 
365
                } else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
-
 
366
                    apkDataListValue = getDeviceInformation();
-
 
367
                    if(isInternetOn()) {
-
 
368
                        new pushApkData().execute();
-
 
369
                    }
-
 
370
                } else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
-
 
371
 
-
 
372
                }  else {
-
 
373
                    apkDataListValue = getDeviceInformation();
-
 
374
                    if(isInternetOn()) {
-
 
375
                        new pushApkData().execute();
-
 
376
                    }
-
 
377
                }
-
 
378
            }
-
 
379
        }catch (Exception e){
-
 
380
            e.printStackTrace();
-
 
381
        }
-
 
382
 
-
 
383
        if(isInternetOn()){
-
 
384
            new fetchAPISettings().execute();
-
 
385
        }
-
 
386
        else{
-
 
387
            b= new AlertDialog.Builder(this);
-
 
388
            b.setMessage("No internet connection. Please try again.");
-
 
389
            b.setCancelable(false);
-
 
390
            b.setPositiveButton("Retry", new DialogInterface.OnClickListener()
-
 
391
            {
-
 
392
                @Override
-
 
393
                public void onClick(DialogInterface dialog, int which) {
-
 
394
                    if(isInternetOn()){
-
 
395
                        new fetchAPISettings().execute();
-
 
396
                        dialog1.dismiss();
-
 
397
                    }
-
 
398
                    else{
-
 
399
                        dialog1 = b.create();
-
 
400
                        dialog1.show();
-
 
401
                    }
-
 
402
                }
-
 
403
 
-
 
404
            });
-
 
405
            b.setNegativeButton("No", new DialogInterface.OnClickListener() {
-
 
406
                @Override
-
 
407
                public void onClick(DialogInterface dialog, int which) {
-
 
408
                    finish();
-
 
409
 
-
 
410
                }
-
 
411
            });
-
 
412
            dialog1 = b.create();
-
 
413
            dialog1.show();
-
 
414
        }
-
 
415
 
-
 
416
    }
-
 
417
 
-
 
418
 
-
 
419
    public ArrayList<NameValuePair> getDeviceInformation(){
-
 
420
        ArrayList<NameValuePair> deviceDataList=null;
-
 
421
        try {
-
 
422
            PackageManager manager = this.getPackageManager();
-
 
423
            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
-
 
424
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-
 
425
            deviceDataList = new ArrayList<>();
-
 
426
            deviceDataList.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
-
 
427
            deviceDataList.add(new BasicNameValuePair("versioncode", info.versionCode + ""));
-
 
428
            deviceDataList.add(new BasicNameValuePair("versionname", info.versionName + ""));
-
 
429
            deviceDataList.add(new BasicNameValuePair("osversion", android.os.Build.VERSION.SDK_INT + ""));
-
 
430
            deviceDataList.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
-
 
431
            deviceDataList.add(new BasicNameValuePair("manufacturer", Build.MANUFACTURER));
-
 
432
            deviceDataList.add(new BasicNameValuePair("model", Build.MODEL));
-
 
433
            deviceDataList.add(new BasicNameValuePair("brand", Build.BRAND));
-
 
434
            apkDataEditor.putString("versionCode", info.versionCode + "");
-
 
435
            apkDataEditor.putString("versionName", info.versionName);
-
 
436
            apkDataEditor.putString("osVersion", android.os.Build.VERSION.SDK_INT + "");
-
 
437
            apkDataEditor.putString("imeiNumber", telephonyManager.getDeviceId());
-
 
438
        }catch (Exception e){
-
 
439
            e.printStackTrace();
-
 
440
        }
-
 
441
        return deviceDataList;
-
 
442
    }
-
 
443
*/
-
 
444
 
-
 
445
    /*@Override
-
 
446
    protected void onPause() {
-
 
447
        Log.d("On Pause","On Pause");
-
 
448
        super.onPause();
-
 
449
    }*/
-
 
450
    public void registerGCM() {
331
    public void registerGCM() {
451
 
332
 
452
        gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
333
        gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
453
        registerInBackground();
334
        registerInBackground();
454
 
335
 
Line 490... Line 371...
490
        @Override
371
        @Override
491
        protected String doInBackground(String... arg0) {
372
        protected String doInBackground(String... arg0) {
492
            String id = null;
373
            String id = null;
493
            try {
374
            try {
494
                HttpClient httpclient = new DefaultHttpClient();
375
                HttpClient httpclient = new DefaultHttpClient();
495
                HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://staging.profittill.com/gcm_users/add"));
376
                HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://api.profittill.com/gcm_users/add"));
496
                nameValuePairsGcm = new ArrayList<>();
377
                nameValuePairsGcm = new ArrayList<>();
497
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
378
                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
498
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
379
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
499
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
380
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
500
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
381
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));