Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14792 manas 1
package com.saholic.profittill.main;
2
 
3
import android.app.AlertDialog;
4
import android.app.ProgressDialog;
5
import android.content.Context;
6
import android.content.DialogInterface;
7
import android.content.Intent;
8
import android.content.SharedPreferences;
9
import android.graphics.Color;
10
import android.net.ConnectivityManager;
11
import android.net.Uri;
12
import android.os.AsyncTask;
15356 manas 13
import android.os.Bundle;
14792 manas 14
import android.support.v7.app.ActionBarActivity;
15
import android.text.InputType;
16
import android.util.Log;
17
import android.view.KeyEvent;
18
import android.view.Menu;
19
import android.view.MenuItem;
20
import android.view.View;
21
import android.view.inputmethod.InputMethodManager;
22
import android.widget.Button;
23
import android.widget.EditText;
24
import android.widget.TextView;
25
import android.widget.Toast;
26
 
27
import com.facebook.Session;
28
import com.google.android.gms.analytics.HitBuilders;
29
import com.google.android.gms.analytics.Tracker;
30
import com.google.android.gms.common.ConnectionResult;
31
import com.google.android.gms.common.api.GoogleApiClient;
32
import com.google.android.gms.plus.Plus;
33
import com.mixpanel.android.mpmetrics.MixpanelAPI;
34
import com.saholic.profittill.Constants.ProfitTillConstants;
35
import com.saholic.profittill.R;
16278 manas 36
import com.saholic.profittill.Utils.AnalyticsUtility;
15356 manas 37
import com.saholic.profittill.Utils.UtilityFunctions;
16278 manas 38
import com.saholic.profittill.Volley.Analytics;
39
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
40
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
14792 manas 41
 
42
import org.apache.http.HttpEntity;
43
import org.apache.http.HttpResponse;
44
import org.apache.http.NameValuePair;
45
import org.apache.http.client.ClientProtocolException;
46
import org.apache.http.client.HttpClient;
47
import org.apache.http.client.entity.UrlEncodedFormEntity;
48
import org.apache.http.client.methods.HttpPost;
49
import org.apache.http.impl.client.DefaultHttpClient;
50
import org.apache.http.message.BasicNameValuePair;
51
import org.apache.http.util.EntityUtils;
52
import org.json.JSONException;
53
import org.json.JSONObject;
54
 
55
import java.io.IOException;
56
import java.text.SimpleDateFormat;
57
import java.util.ArrayList;
58
import java.util.Date;
59
 
60
public class ReferrerActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
61
    EditText referalCode;
62
    EditText mobileNumber;
16278 manas 63
    MixpanelAPI mixpanel;
14792 manas 64
    TextView inviteMessage,inviteMessage1,inviteNumber,giveus,thanks,incorrect;
65
    Button referrerSend,mobileNumberSend;
66
    String type1;
67
    String invitationCode;
68
    SharedPreferences userData;
69
    SharedPreferences apiData;
70
    SharedPreferences.Editor userDataEditor;
71
    SharedPreferences.Editor apiSettingsEditor;
72
    SharedPreferences inviteD;
73
    SharedPreferences.Editor inviteDEditor;
74
    ArrayList<NameValuePair> nameValuePairsGcm;
75
    public GoogleApiClient mGoogleApiClient;
76
    boolean glogout;
77
    final ArrayList<String> invitationCodeList = new ArrayList<String>();
78
 
79
    boolean FLAG=false;
80
    ArrayList<NameValuePair> nameValuePairs;
81
    @Override
82
    protected void onCreate(Bundle savedInstanceState) {
83
        super.onCreate(savedInstanceState);
84
        setContentView(R.layout.activity_referrer);
85
        getSupportActionBar().hide();
86
 
87
        userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
88
        apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
89
        userDataEditor = userData.edit();
90
        apiSettingsEditor = apiData.edit();
91
        inviteD = getApplicationContext().getSharedPreferences("Invite", MODE_PRIVATE);
92
        inviteDEditor = inviteD.edit();
93
 
94
        inviteMessage=(TextView)findViewById(R.id.inviteMessage);
95
        inviteMessage1=(TextView)findViewById(R.id.inviteMessage1);
96
        inviteNumber=(TextView)findViewById(R.id.inviteNumber);
97
        giveus=(TextView)findViewById(R.id.giveus);
98
        thanks=(TextView)findViewById(R.id.thanks);
99
        incorrect=(TextView)findViewById(R.id.incorrect);
100
 
101
        referalCode=(EditText)findViewById(R.id.referralCode);
102
        mobileNumber=(EditText)findViewById(R.id.mobileNumberReferrer);
103
        referrerSend =(Button)findViewById(R.id.referrerSend);
104
        mobileNumberSend =(Button)findViewById(R.id.mobileNumberReferrerSend);
105
        mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
106
        inviteMessage.setText(apiData.getString("referralinvite.text", "Got your Invite Code?"));
107
        inviteMessage1.setText(apiData.getString("no.referralinvite", "Haven't got the code..."));
108
        giveus.setText(apiData.getString("referralMobileNumber.text","Leave ur no & we'll get back to you"));
109
        inviteNumber.setVisibility(View.VISIBLE);
110
        inviteNumber.setText("Call " + apiData.getString("contactus.number", "") + " now");
16278 manas 111
 
112
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
113
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
114
        t.setScreenName("Referrer Screen");
115
        t.send(new HitBuilders.ScreenViewBuilder().build());
116
        new Analytics(ProfitTillConstants.ANALYTICS_URL,
117
                AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Screen", "Referrer", "Referrer Screen"),
118
                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
119
                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
120
 
14792 manas 121
        referalCode.setInputType(0);
122
        mobileNumber.setInputType(0);
123
        if(getIntent().getAction()=="Login"){
124
            nameValuePairsGcm = new ArrayList<>();
125
            nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
126
            nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id", "")));
15356 manas 127
            nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
14792 manas 128
            nameValuePairsGcm.add(new BasicNameValuePair("result","referrer"));
129
            getIntent().getExtras().remove("cid");
130
            new NotificationOpenedData().execute(nameValuePairsGcm);
131
        }
132
 
133
        referalCode.setOnClickListener(new View.OnClickListener() {
134
            @Override
135
            public void onClick(View v) {
136
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
137
                inputMethodManager.showSoftInput(referalCode, InputMethodManager.SHOW_IMPLICIT);
138
                referalCode.requestFocus();
139
            }
140
        });
141
        mobileNumber.setOnClickListener(new View.OnClickListener() {
142
            @Override
143
            public void onClick(View v) {
144
                mobileNumber.setInputType(InputType.TYPE_CLASS_PHONE);
145
            }
146
        });
147
        inviteNumber.setOnClickListener(new View.OnClickListener() {
148
            @Override
149
            public void onClick(View v) {
16278 manas 150
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
151
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Call to get Invite Code"),
152
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
153
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
14792 manas 154
                Intent callIntent = new Intent(Intent.ACTION_CALL);
155
                callIntent.setData(Uri.parse("tel:0" + apiData.getString("contactus.number", "")));
156
                startActivity(callIntent);
157
            }
158
        });
159
 
160
        JSONObject props = new JSONObject();
161
        try {
162
            props.put("Referrer", "Referrer Screen");
163
            mixpanel.track("Referrer Screen", props);
164
        } catch (JSONException e) {
165
 
166
            e.printStackTrace();
167
        }
168
        type1 = userData.getString("type",null);
169
 
170
        if(type1!=null && type1.equalsIgnoreCase("google")) {
171
            mGoogleApiClient = new GoogleApiClient.Builder(this)
172
                    .addConnectionCallbacks(this)
173
                    .addOnConnectionFailedListener(this).addApi(Plus.API)
174
                    .addScope(Plus.SCOPE_PLUS_LOGIN).build();
175
            mGoogleApiClient.connect();
176
        }
177
        referalCode.setOnKeyListener(new View.OnKeyListener() {
178
            @Override
179
            public boolean onKey(View v, int keyCode, KeyEvent event) {
180
                if (event.getAction() == KeyEvent.ACTION_DOWN)
181
                {
182
                    switch (keyCode)
183
                    {
184
                        case KeyEvent.KEYCODE_DPAD_CENTER:
185
 
186
                        case KeyEvent.KEYCODE_ENTER:
187
 
188
                            if(referalCode.getText().toString().equalsIgnoreCase("")) {
189
                                incorrect.setVisibility(View.VISIBLE);
190
                                incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
191
                                incorrect.setTextColor(Color.RED);
192
                                referalCode.setHint("Retry");
193
                                InputMethodManager imm = (InputMethodManager)getSystemService(
194
                                        Context.INPUT_METHOD_SERVICE);
195
                                imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
196
                            }
197
                            else{
198
                                if(isInternetOn()) {
199
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
200
                                            Context.INPUT_METHOD_SERVICE);
201
                                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
16278 manas 202
 
14792 manas 203
                                    new PushReferrerData().execute(referalCode.getText().toString());
204
                                }else{
205
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
206
                                            Context.INPUT_METHOD_SERVICE);
207
                                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
208
                                    Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
209
                                }
210
                            }
211
                            return true;
212
 
213
                        default:
214
                            break;
215
                    }
216
                }
217
                return false;
218
            }
219
 
220
 
221
        });
222
 
223
        mobileNumber.setOnKeyListener(new View.OnKeyListener() {
224
            @Override
225
            public boolean onKey(View v, int keyCode, KeyEvent event) {
226
                if (event.getAction() == KeyEvent.ACTION_DOWN)
227
                {
228
                    switch (keyCode)
229
                    {
230
                        case KeyEvent.KEYCODE_DPAD_CENTER:
231
 
232
                        case KeyEvent.KEYCODE_ENTER:
233
                            if(mobileNumber.getText().toString().length()==10){
234
                                if(isInternetOn()) {
235
                                    incorrect.setVisibility(View.GONE);
236
                                    referalCode.setHint("Enter Invite Code");
237
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
238
                                            Context.INPUT_METHOD_SERVICE);
239
                                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
240
                                    new pushVerification().execute();
241
                                }else{
242
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
243
                                            Context.INPUT_METHOD_SERVICE);
244
                                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
245
                                    Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
246
                                }
247
 
248
                            }
249
                            else{
250
                                InputMethodManager imm = (InputMethodManager)getSystemService(
251
                                        Context.INPUT_METHOD_SERVICE);
252
                                imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
253
                                Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
254
                            }
255
                            return true;
256
 
257
                        default:
258
                            break;
259
                    }
260
                }
261
                return false;
262
            }
263
 
264
 
265
        });
266
 
267
        referrerSend.setOnClickListener(new View.OnClickListener() {
268
            @Override
269
            public void onClick(View v) {
270
 
271
 
272
                if(referalCode.getText().toString().equalsIgnoreCase("")) {
273
                    incorrect.setVisibility(View.VISIBLE);
274
                    incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
275
                    incorrect.setTextColor(Color.RED);
276
                    referalCode.setHint("Retry");
277
                    InputMethodManager imm = (InputMethodManager)getSystemService(
278
                            Context.INPUT_METHOD_SERVICE);
279
                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
280
                }
281
                else{
282
                    if(isInternetOn()) {
283
                        InputMethodManager imm = (InputMethodManager)getSystemService(
284
                                Context.INPUT_METHOD_SERVICE);
285
                        imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
286
                        new PushReferrerData().execute(referalCode.getText().toString());
287
                    }else{
288
                        InputMethodManager imm = (InputMethodManager)getSystemService(
289
                                Context.INPUT_METHOD_SERVICE);
290
                        imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
291
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
292
                    }
293
                }
294
            }
295
        });
296
 
297
        mobileNumberSend.setOnClickListener(new View.OnClickListener() {
298
            @Override
299
            public void onClick(View v) {
300
 
301
                if(mobileNumber.getText().toString().length()==10){
302
                    if(isInternetOn()) {
303
                        InputMethodManager imm = (InputMethodManager)getSystemService(
304
                                Context.INPUT_METHOD_SERVICE);
305
                        imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
306
                        incorrect.setVisibility(View.GONE);
307
                        referalCode.setHint("Enter Invite Code");
308
                        new pushVerification().execute();
309
                    }else{
310
                        InputMethodManager imm = (InputMethodManager)getSystemService(
311
                                Context.INPUT_METHOD_SERVICE);
312
                        imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
313
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
314
                    }
315
 
316
                }
317
                else{
318
                    InputMethodManager imm = (InputMethodManager)getSystemService(
319
                            Context.INPUT_METHOD_SERVICE);
320
                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
321
                    Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
322
                }
323
            }
324
        });
325
    }
326
 
327
 
328
    @Override
329
    public boolean onCreateOptionsMenu(Menu menu) {
330
        // Inflate the menu; this adds items to the action bar if it is present.
331
        getMenuInflater().inflate(R.menu.menu_referrer, menu);
332
        return true;
333
    }
334
 
335
    @Override
336
    public boolean onOptionsItemSelected(MenuItem item) {
337
        // Handle action bar item clicks here. The action bar will
338
        // automatically handle clicks on the Home/Up button, so long
339
        // as you specify a parent activity in AndroidManifest.xml.
340
        int id = item.getItemId();
341
 
342
        //noinspection SimplifiableIfStatement
343
        if (id == R.id.action_settings) {
344
            return true;
345
        }
346
 
347
        return super.onOptionsItemSelected(item);
348
    }
349
    @Override
350
    public void onConnected(Bundle bundle) {
351
 
352
    }
353
 
354
    @Override
355
    public void onConnectionSuspended(int i) {
356
 
357
    }
358
 
359
    @Override
360
    public void onConnectionFailed(ConnectionResult connectionResult) {
361
 
362
    }
363
 
364
    class PushReferrerData extends AsyncTask<String, Integer, String> {
365
 
366
        @Override
367
        protected void onPreExecute() {
368
            super.onPreExecute();
369
            referrerSend.setEnabled(false);
370
            referalCode.setInputType(0);
371
            mobileNumber.setInputType(0);
372
            pd2 = new ProgressDialog(ReferrerActivity.this);
373
            pd2.setMessage("Please wait...");
374
            pd2.setCancelable(false);
375
            pd2.show();
376
 
377
        }
378
 
379
        @Override
380
        protected String doInBackground(String... arg0) {
381
            String id=null;
382
            try {
383
                HttpClient httpclient = new DefaultHttpClient();
384
 
385
                nameValuePairs = new ArrayList<>();
386
                String updateURL = apiData.getString("useredit.url","");
387
                String url = updateURL+userData.getString("id","");
388
                 nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id",null)));
389
                nameValuePairs.add(new BasicNameValuePair("referrer",arg0[0]));
390
                HttpPost httppost = new HttpPost(url);
391
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
392
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
393
                HttpResponse response = httpclient.execute(httppost);
394
                HttpEntity entity = response.getEntity();
395
                int status = response.getStatusLine().getStatusCode();
396
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
397
                System.out.println("JSON Object in referrer " + jObjGmail.toString());
398
                String success = jObjGmail.getString("success");
399
                if(status == 200){
400
                    inviteDEditor.putString("referrerCode",arg0[0]);
401
                    inviteDEditor.commit();
402
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
403
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
404
                    t.send(new HitBuilders.EventBuilder()
405
                            .setCategory("Referrer ")
406
                            .setAction("Referrer Saved Successfully")
407
                            .setLabel("Referrer for User" +userData.getString("id",null) + " is " + arg0[0])
408
                            .build());
409
                }
410
                if(success.equalsIgnoreCase("true")){
411
                    MixpanelAPI mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
412
                    JSONObject props = new JSONObject();
413
                    try {
414
                        props.put("Referrer", "Referrer Saved Successfully");
415
                        mixpanel.track("Referrer Saved", props);
416
                    } catch (JSONException e) {
417
 
418
                        e.printStackTrace();
419
                    }
420
                    userDataEditor.putString("referralCodeRequired","false");;
421
                    userDataEditor.commit();
422
                    return "true";
423
                }else{
424
                    userDataEditor.putString("referralCodeRequired","true");;
425
                    userDataEditor.commit();
426
                    return "false";
427
                }
428
 
429
            } catch (Exception e) {
430
                Log.e("Fail 1", e.toString());
431
                return "false";
432
            }
433
        }
434
 
435
        @Override
436
        protected void onPostExecute(String result) {
437
            super.onPostExecute(result);
438
            pd2.dismiss();
439
            if(result.equalsIgnoreCase("true")) {
16278 manas 440
 
441
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
442
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Invite Code Entered"),
443
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
444
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
445
 
14792 manas 446
                if(userData.getString("message","false").equalsIgnoreCase("true")) {
447
                    Intent i = new Intent(ReferrerActivity.this, MobileNumber.class);
448
                    i.putExtra("displayView", "7");
449
                    startActivity(i);
450
                }else{
451
                    if(!(userData.getString("mobileNumber","").isEmpty())) {
452
                        Intent i = new Intent(ReferrerActivity.this, MobileVerificationFirstTime.class);
453
                        i.putExtra("numberVerification", userData.getString("mobileNumber",""));
454
                        startActivity(i);
455
                    }else{
456
                        Intent i = new Intent(ReferrerActivity.this, MainActivity.class);
457
                        i.putExtra("displayView", "7");
458
                        startActivity(i);
459
 
460
                    }
461
                }
462
            }else{
463
                referrerSend.setEnabled(true);
464
                incorrect.setVisibility(View.VISIBLE);
465
                incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
466
                incorrect.setTextColor(Color.RED);
467
                referalCode.setHint("Retry");
468
            }
469
        }
470
    }
471
    class pushVerification extends AsyncTask<String, Integer, String> {
472
 
473
        @Override
474
        protected void onPreExecute() {
475
            super.onPreExecute();
476
            JSONObject props = new JSONObject();
477
            try {
478
                mixpanel.identify(userData.getString("id",null));
479
                props.put("Screen", "Mobile Entered Referrer");
480
                mixpanel.track("Mobile Number Entered Referrer",props);
481
            } catch (JSONException e) {
482
                e.printStackTrace();
483
            }
484
            referalCode.setInputType(0);
485
            mobileNumber.setInputType(0);
486
            pd2 = new ProgressDialog(ReferrerActivity.this);
487
            pd2.setMessage("Please wait...");
488
            pd2.setCancelable(false);
489
            pd2.show();
490
 
491
        }
492
 
493
        @Override
494
        protected String doInBackground(String... arg0) {
495
            HttpClient httpclient = new DefaultHttpClient();
496
            try {
497
 
498
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
499
                SimpleDateFormat sdf = new SimpleDateFormat(ProfitTillConstants.SQL_DATE_FORMAT);
500
                String dateUpdated = sdf.format(new Date());
501
                nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id","")));
502
                nameValuePairs.add(new BasicNameValuePair("mobile_number",mobileNumber.getText().toString()));
503
                nameValuePairs.add(new BasicNameValuePair("mobile_number_last_updated",dateUpdated));
504
                String updateURL = apiData.getString("useredit.url","");
505
                String url = updateURL+userData.getString("id","");
506
                HttpPost httppost = new HttpPost(url);
507
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
508
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
509
                HttpResponse response = httpclient.execute(httppost);
510
                HttpEntity entity = response.getEntity();
511
                int status = response.getStatusLine().getStatusCode();
512
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
513
                System.out.println("JSON Object in mobile " + jObjGmail.toString());
514
                String success = jObjGmail.getString("success");
515
 
516
                if(status == 200){
517
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
518
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
519
                    t.send(new HitBuilders.EventBuilder()
520
                            .setCategory("First Time Mobile Entered ")
521
                            .setAction("Number entered")
522
                            .setLabel("First Time Mobile entered")
523
                            .build());
16278 manas 524
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
525
                            AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Number Entered"),
526
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
527
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
14792 manas 528
                }
529
                if(success.equalsIgnoreCase("true")){
530
                    userDataEditor.putString("message","false");;
531
                    userDataEditor.putString("mobileNumber",mobileNumber.getText().toString());
532
                    userDataEditor.commit();
533
                    return "true";
534
                }else{
535
                    userDataEditor.putString("message","true");;
536
                    userDataEditor.commit();
537
                    return "false";
538
                }
539
            } catch (ClientProtocolException e) {
540
                return "false";
541
            } catch (IOException e) {
542
                return "false";
543
            }catch (Exception e){
544
                return "false";
545
            }
546
        }
547
 
548
        @Override
549
        protected void onPostExecute(String result) {
550
            super.onPostExecute(result);
551
            pd2.dismiss();
552
            thanks.setText(apiData.getString("thanks.referrer.message","Thanks and we will get back to you"));
553
            thanks.setVisibility(View.VISIBLE);
554
        }
555
    }
556
    ProgressDialog pd2;
557
    @Override
558
    public void onBackPressed() {
559
        new AlertDialog.Builder(this)
560
                .setIcon(android.R.drawable.ic_dialog_alert)
561
                .setTitle("Exit!")
562
                .setMessage("Are you sure you want to sign out?")
563
                .setPositiveButton("Yes", new DialogInterface.OnClickListener()
564
                {
565
                    @Override
566
                    public void onClick(DialogInterface dialog, int which) {
567
                        JSONObject props = new JSONObject();
568
                        try {
569
                            mixpanel.identify(userData.getString("id",null));
570
                            props.put("Screen", "Signing Out");
571
                            mixpanel.track("Signing Out Referrer",props);
572
                        } catch (JSONException e) {
573
                            e.printStackTrace();
574
                        }
575
 
576
                        if(type1.equalsIgnoreCase("facebook")) {
577
                            Log.d("fblogout","logout");
578
                            if (Session.getActiveSession() != null) {
579
                                Session.getActiveSession().closeAndClearTokenInformation();
580
                            }
581
                            Session.setActiveSession(null);
582
                            userDataEditor.clear().commit();
583
                            startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
584
                        }
585
                        else{
586
                            Log.d("gmailLogout","logout");
587
                            signOutFromGplus();
588
                            if(glogout==true){
589
                                startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
590
                            }
591
                        }
592
 
593
                    }
594
 
595
                })
596
                .setNegativeButton("No", null)
597
                .show();
598
    }
599
    public void signOutFromGplus() {
600
        if (mGoogleApiClient.isConnected()) {
601
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
602
            mGoogleApiClient.disconnect();
603
            mGoogleApiClient.connect();
604
            glogout=true;
605
            userDataEditor.clear().commit();
606
        } else {
607
            glogout=false;
608
        }
609
    }
610
 
611
    public final boolean isInternetOn() {
612
 
613
        ConnectivityManager connection =
614
                (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
615
 
616
        if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
617
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
618
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
619
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
620
            return true;
621
 
622
        } else if (
623
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
624
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
625
            return false;
626
        }
627
        return false;
628
    }
629
 
630
 
631
    class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
632
 
633
        @Override
634
        protected void onPreExecute() {
635
            super.onPreExecute();
636
 
637
        }
638
 
639
        @Override
640
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
641
 
642
            try {
643
                HttpClient httpclient = new DefaultHttpClient();
644
                HttpPost httppost = new HttpPost(apiData.getString("notication.data.url","http://api.profittill.com/pushnotifications/add"));
645
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
646
                httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
647
                HttpResponse response = httpclient.execute(httppost);
648
                HttpEntity entity = response.getEntity();
649
                int status = response.getStatusLine().getStatusCode();
650
 
651
                if(status == 200){
652
                    Log.d("Notification Opened","Notication opened and sent to server");
653
                    Log.d("ResponseCode GCM ",status+"");
654
                } else {
655
                    Log.d("ResponseCode GCM ",status+"");
656
                }
657
 
658
                nameValuePairsGcm.clear();
659
                Log.e("pass 1", "connection success ");
660
            } catch (Exception e) {
661
                Log.e("Fail 1", e.toString());
662
 
663
            }
664
            return "success";
665
        }
666
 
667
        @Override
668
        protected void onPostExecute(String result) {
669
            super.onPostExecute(result);
670
            Log.d("Notification Opened","Notication opened and login page");
671
        }
672
    }
673
}
674