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"){
16310 manas 124
            new Analytics(ProfitTillConstants.ANALYTICS_URL,
125
                    AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this,userData.getString("id",""),"Notification","Notification Opened Referrer",getIntent().getExtras().getString("cid")),
126
                    AnalyticsJsonResponse.getAnalyticsRequestInstance(),
127
                    AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
128
 
14792 manas 129
            nameValuePairsGcm = new ArrayList<>();
130
            nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
131
            nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id", "")));
15356 manas 132
            nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
14792 manas 133
            nameValuePairsGcm.add(new BasicNameValuePair("result","referrer"));
134
            getIntent().getExtras().remove("cid");
135
            new NotificationOpenedData().execute(nameValuePairsGcm);
18082 manas 136
        }else if(getIntent().getAction()=="31"){
137
            String emailURL= String.valueOf(getIntent().getData());
138
            Uri url = Uri.parse(emailURL);
139
            String campaignId = url.getQueryParameter("campaign");
140
            if(url.getQueryParameter("intent_type").equalsIgnoreCase("url")) {
141
                t.send(new HitBuilders.EventBuilder()
142
                        .setCategory("Message/Email")
143
                        .setAction("Message/Email Opened For User Id " + UtilityFunctions.campaignUserId(url))
144
                        .setLabel("Campaign Id " + campaignId)
145
                        .build());
146
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
147
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, UtilityFunctions.campaignUserId(url), "Message", "Message Opened Referrer", campaignId),
148
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
149
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
150
 
151
                nameValuePairsGcm = new ArrayList<>();
152
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", UtilityFunctions.campaignUserId(url)));
153
                nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
154
                nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
155
                nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_referrer"));
156
                new NotificationOpenedData().execute(nameValuePairsGcm);
157
            }else{
158
                nameValuePairsGcm = new ArrayList<>();
159
                nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id","")));
160
                nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
161
                nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
162
                nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_referrer"));
163
                new NotificationOpenedData().execute(nameValuePairsGcm);
164
            }
14792 manas 165
        }
166
 
167
        referalCode.setOnClickListener(new View.OnClickListener() {
168
            @Override
169
            public void onClick(View v) {
170
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
171
                inputMethodManager.showSoftInput(referalCode, InputMethodManager.SHOW_IMPLICIT);
172
                referalCode.requestFocus();
173
            }
174
        });
175
        mobileNumber.setOnClickListener(new View.OnClickListener() {
176
            @Override
177
            public void onClick(View v) {
178
                mobileNumber.setInputType(InputType.TYPE_CLASS_PHONE);
179
            }
180
        });
181
        inviteNumber.setOnClickListener(new View.OnClickListener() {
182
            @Override
183
            public void onClick(View v) {
16278 manas 184
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
185
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Call to get Invite Code"),
186
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
187
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
14792 manas 188
                Intent callIntent = new Intent(Intent.ACTION_CALL);
189
                callIntent.setData(Uri.parse("tel:0" + apiData.getString("contactus.number", "")));
190
                startActivity(callIntent);
191
            }
192
        });
193
 
194
        JSONObject props = new JSONObject();
195
        try {
196
            props.put("Referrer", "Referrer Screen");
197
            mixpanel.track("Referrer Screen", props);
198
        } catch (JSONException e) {
199
 
200
            e.printStackTrace();
201
        }
202
        type1 = userData.getString("type",null);
203
 
204
        if(type1!=null && type1.equalsIgnoreCase("google")) {
205
            mGoogleApiClient = new GoogleApiClient.Builder(this)
206
                    .addConnectionCallbacks(this)
207
                    .addOnConnectionFailedListener(this).addApi(Plus.API)
208
                    .addScope(Plus.SCOPE_PLUS_LOGIN).build();
209
            mGoogleApiClient.connect();
210
        }
211
        referalCode.setOnKeyListener(new View.OnKeyListener() {
212
            @Override
213
            public boolean onKey(View v, int keyCode, KeyEvent event) {
214
                if (event.getAction() == KeyEvent.ACTION_DOWN)
215
                {
216
                    switch (keyCode)
217
                    {
218
                        case KeyEvent.KEYCODE_DPAD_CENTER:
219
 
220
                        case KeyEvent.KEYCODE_ENTER:
221
 
222
                            if(referalCode.getText().toString().equalsIgnoreCase("")) {
223
                                incorrect.setVisibility(View.VISIBLE);
224
                                incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
225
                                incorrect.setTextColor(Color.RED);
226
                                referalCode.setHint("Retry");
227
                                InputMethodManager imm = (InputMethodManager)getSystemService(
228
                                        Context.INPUT_METHOD_SERVICE);
229
                                imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
230
                            }
231
                            else{
232
                                if(isInternetOn()) {
233
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
234
                                            Context.INPUT_METHOD_SERVICE);
235
                                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
16278 manas 236
 
14792 manas 237
                                    new PushReferrerData().execute(referalCode.getText().toString());
238
                                }else{
239
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
240
                                            Context.INPUT_METHOD_SERVICE);
241
                                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
242
                                    Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
243
                                }
244
                            }
245
                            return true;
246
 
247
                        default:
248
                            break;
249
                    }
250
                }
251
                return false;
252
            }
253
 
254
 
255
        });
256
 
257
        mobileNumber.setOnKeyListener(new View.OnKeyListener() {
258
            @Override
259
            public boolean onKey(View v, int keyCode, KeyEvent event) {
260
                if (event.getAction() == KeyEvent.ACTION_DOWN)
261
                {
262
                    switch (keyCode)
263
                    {
264
                        case KeyEvent.KEYCODE_DPAD_CENTER:
265
 
266
                        case KeyEvent.KEYCODE_ENTER:
267
                            if(mobileNumber.getText().toString().length()==10){
268
                                if(isInternetOn()) {
269
                                    incorrect.setVisibility(View.GONE);
270
                                    referalCode.setHint("Enter Invite Code");
271
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
272
                                            Context.INPUT_METHOD_SERVICE);
273
                                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
274
                                    new pushVerification().execute();
275
                                }else{
276
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
277
                                            Context.INPUT_METHOD_SERVICE);
278
                                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
279
                                    Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
280
                                }
281
 
282
                            }
283
                            else{
284
                                InputMethodManager imm = (InputMethodManager)getSystemService(
285
                                        Context.INPUT_METHOD_SERVICE);
286
                                imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
287
                                Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
288
                            }
289
                            return true;
290
 
291
                        default:
292
                            break;
293
                    }
294
                }
295
                return false;
296
            }
297
 
298
 
299
        });
300
 
301
        referrerSend.setOnClickListener(new View.OnClickListener() {
302
            @Override
303
            public void onClick(View v) {
304
 
305
 
306
                if(referalCode.getText().toString().equalsIgnoreCase("")) {
307
                    incorrect.setVisibility(View.VISIBLE);
308
                    incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
309
                    incorrect.setTextColor(Color.RED);
310
                    referalCode.setHint("Retry");
311
                    InputMethodManager imm = (InputMethodManager)getSystemService(
312
                            Context.INPUT_METHOD_SERVICE);
313
                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
314
                }
315
                else{
316
                    if(isInternetOn()) {
317
                        InputMethodManager imm = (InputMethodManager)getSystemService(
318
                                Context.INPUT_METHOD_SERVICE);
319
                        imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
320
                        new PushReferrerData().execute(referalCode.getText().toString());
321
                    }else{
322
                        InputMethodManager imm = (InputMethodManager)getSystemService(
323
                                Context.INPUT_METHOD_SERVICE);
324
                        imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
325
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
326
                    }
327
                }
328
            }
329
        });
330
 
331
        mobileNumberSend.setOnClickListener(new View.OnClickListener() {
332
            @Override
333
            public void onClick(View v) {
334
 
335
                if(mobileNumber.getText().toString().length()==10){
336
                    if(isInternetOn()) {
337
                        InputMethodManager imm = (InputMethodManager)getSystemService(
338
                                Context.INPUT_METHOD_SERVICE);
339
                        imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
340
                        incorrect.setVisibility(View.GONE);
341
                        referalCode.setHint("Enter Invite Code");
342
                        new pushVerification().execute();
343
                    }else{
344
                        InputMethodManager imm = (InputMethodManager)getSystemService(
345
                                Context.INPUT_METHOD_SERVICE);
346
                        imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
347
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
348
                    }
349
 
350
                }
351
                else{
352
                    InputMethodManager imm = (InputMethodManager)getSystemService(
353
                            Context.INPUT_METHOD_SERVICE);
354
                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
355
                    Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
356
                }
357
            }
358
        });
359
    }
360
 
361
 
362
    @Override
363
    public boolean onCreateOptionsMenu(Menu menu) {
364
        // Inflate the menu; this adds items to the action bar if it is present.
365
        getMenuInflater().inflate(R.menu.menu_referrer, menu);
366
        return true;
367
    }
368
 
369
    @Override
370
    public boolean onOptionsItemSelected(MenuItem item) {
371
        // Handle action bar item clicks here. The action bar will
372
        // automatically handle clicks on the Home/Up button, so long
373
        // as you specify a parent activity in AndroidManifest.xml.
374
        int id = item.getItemId();
375
 
376
        //noinspection SimplifiableIfStatement
377
        if (id == R.id.action_settings) {
378
            return true;
379
        }
380
 
381
        return super.onOptionsItemSelected(item);
382
    }
383
    @Override
384
    public void onConnected(Bundle bundle) {
385
 
386
    }
387
 
388
    @Override
389
    public void onConnectionSuspended(int i) {
390
 
391
    }
392
 
393
    @Override
394
    public void onConnectionFailed(ConnectionResult connectionResult) {
395
 
396
    }
397
 
398
    class PushReferrerData extends AsyncTask<String, Integer, String> {
399
 
400
        @Override
401
        protected void onPreExecute() {
402
            super.onPreExecute();
403
            referrerSend.setEnabled(false);
404
            referalCode.setInputType(0);
405
            mobileNumber.setInputType(0);
406
            pd2 = new ProgressDialog(ReferrerActivity.this);
407
            pd2.setMessage("Please wait...");
408
            pd2.setCancelable(false);
409
            pd2.show();
410
 
411
        }
412
 
413
        @Override
414
        protected String doInBackground(String... arg0) {
415
            String id=null;
416
            try {
417
                HttpClient httpclient = new DefaultHttpClient();
418
 
419
                nameValuePairs = new ArrayList<>();
420
                String updateURL = apiData.getString("useredit.url","");
421
                String url = updateURL+userData.getString("id","");
17059 manas 422
                nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id",null)));
14792 manas 423
                nameValuePairs.add(new BasicNameValuePair("referrer",arg0[0]));
424
                HttpPost httppost = new HttpPost(url);
425
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
426
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
427
                HttpResponse response = httpclient.execute(httppost);
428
                HttpEntity entity = response.getEntity();
429
                int status = response.getStatusLine().getStatusCode();
430
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
431
                System.out.println("JSON Object in referrer " + jObjGmail.toString());
432
                String success = jObjGmail.getString("success");
433
                if(status == 200){
434
                    inviteDEditor.putString("referrerCode",arg0[0]);
435
                    inviteDEditor.commit();
436
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
437
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
438
                    t.send(new HitBuilders.EventBuilder()
439
                            .setCategory("Referrer ")
440
                            .setAction("Referrer Saved Successfully")
441
                            .setLabel("Referrer for User" +userData.getString("id",null) + " is " + arg0[0])
442
                            .build());
443
                }
444
                if(success.equalsIgnoreCase("true")){
445
                    MixpanelAPI mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
446
                    JSONObject props = new JSONObject();
447
                    try {
448
                        props.put("Referrer", "Referrer Saved Successfully");
449
                        mixpanel.track("Referrer Saved", props);
450
                    } catch (JSONException e) {
451
 
452
                        e.printStackTrace();
453
                    }
454
                    userDataEditor.putString("referralCodeRequired","false");;
455
                    userDataEditor.commit();
456
                    return "true";
457
                }else{
458
                    userDataEditor.putString("referralCodeRequired","true");;
459
                    userDataEditor.commit();
460
                    return "false";
461
                }
462
 
463
            } catch (Exception e) {
464
                Log.e("Fail 1", e.toString());
465
                return "false";
466
            }
467
        }
468
 
469
        @Override
470
        protected void onPostExecute(String result) {
471
            super.onPostExecute(result);
472
            pd2.dismiss();
473
            if(result.equalsIgnoreCase("true")) {
16278 manas 474
 
475
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
476
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Invite Code Entered"),
477
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
478
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
479
 
14792 manas 480
                if(userData.getString("message","false").equalsIgnoreCase("true")) {
481
                    Intent i = new Intent(ReferrerActivity.this, MobileNumber.class);
482
                    i.putExtra("displayView", "7");
483
                    startActivity(i);
484
                }else{
485
                    if(!(userData.getString("mobileNumber","").isEmpty())) {
486
                        Intent i = new Intent(ReferrerActivity.this, MobileVerificationFirstTime.class);
487
                        i.putExtra("numberVerification", userData.getString("mobileNumber",""));
488
                        startActivity(i);
489
                    }else{
490
                        Intent i = new Intent(ReferrerActivity.this, MainActivity.class);
491
                        i.putExtra("displayView", "7");
492
                        startActivity(i);
493
 
494
                    }
495
                }
496
            }else{
497
                referrerSend.setEnabled(true);
498
                incorrect.setVisibility(View.VISIBLE);
499
                incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
500
                incorrect.setTextColor(Color.RED);
501
                referalCode.setHint("Retry");
502
            }
503
        }
504
    }
505
    class pushVerification extends AsyncTask<String, Integer, String> {
506
 
507
        @Override
508
        protected void onPreExecute() {
509
            super.onPreExecute();
510
            JSONObject props = new JSONObject();
511
            try {
512
                mixpanel.identify(userData.getString("id",null));
513
                props.put("Screen", "Mobile Entered Referrer");
514
                mixpanel.track("Mobile Number Entered Referrer",props);
515
            } catch (JSONException e) {
516
                e.printStackTrace();
517
            }
518
            referalCode.setInputType(0);
519
            mobileNumber.setInputType(0);
520
            pd2 = new ProgressDialog(ReferrerActivity.this);
521
            pd2.setMessage("Please wait...");
522
            pd2.setCancelable(false);
523
            pd2.show();
524
 
525
        }
526
 
527
        @Override
528
        protected String doInBackground(String... arg0) {
529
            HttpClient httpclient = new DefaultHttpClient();
530
            try {
531
 
532
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
533
                SimpleDateFormat sdf = new SimpleDateFormat(ProfitTillConstants.SQL_DATE_FORMAT);
534
                String dateUpdated = sdf.format(new Date());
535
                nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id","")));
536
                nameValuePairs.add(new BasicNameValuePair("mobile_number",mobileNumber.getText().toString()));
537
                nameValuePairs.add(new BasicNameValuePair("mobile_number_last_updated",dateUpdated));
538
                String updateURL = apiData.getString("useredit.url","");
539
                String url = updateURL+userData.getString("id","");
540
                HttpPost httppost = new HttpPost(url);
541
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
542
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
543
                HttpResponse response = httpclient.execute(httppost);
544
                HttpEntity entity = response.getEntity();
545
                int status = response.getStatusLine().getStatusCode();
546
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
547
                System.out.println("JSON Object in mobile " + jObjGmail.toString());
548
                String success = jObjGmail.getString("success");
549
 
550
                if(status == 200){
551
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
552
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
553
                    t.send(new HitBuilders.EventBuilder()
554
                            .setCategory("First Time Mobile Entered ")
555
                            .setAction("Number entered")
556
                            .setLabel("First Time Mobile entered")
557
                            .build());
16278 manas 558
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
559
                            AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Number Entered"),
560
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
561
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
14792 manas 562
                }
563
                if(success.equalsIgnoreCase("true")){
564
                    userDataEditor.putString("message","false");;
565
                    userDataEditor.putString("mobileNumber",mobileNumber.getText().toString());
566
                    userDataEditor.commit();
567
                    return "true";
568
                }else{
569
                    userDataEditor.putString("message","true");;
570
                    userDataEditor.commit();
571
                    return "false";
572
                }
573
            } catch (ClientProtocolException e) {
574
                return "false";
575
            } catch (IOException e) {
576
                return "false";
577
            }catch (Exception e){
578
                return "false";
579
            }
580
        }
581
 
582
        @Override
583
        protected void onPostExecute(String result) {
584
            super.onPostExecute(result);
585
            pd2.dismiss();
586
            thanks.setText(apiData.getString("thanks.referrer.message","Thanks and we will get back to you"));
587
            thanks.setVisibility(View.VISIBLE);
588
        }
589
    }
590
    ProgressDialog pd2;
591
    @Override
592
    public void onBackPressed() {
593
        new AlertDialog.Builder(this)
594
                .setIcon(android.R.drawable.ic_dialog_alert)
595
                .setTitle("Exit!")
596
                .setMessage("Are you sure you want to sign out?")
597
                .setPositiveButton("Yes", new DialogInterface.OnClickListener()
598
                {
599
                    @Override
600
                    public void onClick(DialogInterface dialog, int which) {
601
                        JSONObject props = new JSONObject();
602
                        try {
603
                            mixpanel.identify(userData.getString("id",null));
604
                            props.put("Screen", "Signing Out");
605
                            mixpanel.track("Signing Out Referrer",props);
606
                        } catch (JSONException e) {
607
                            e.printStackTrace();
608
                        }
609
 
610
                        if(type1.equalsIgnoreCase("facebook")) {
611
                            Log.d("fblogout","logout");
612
                            if (Session.getActiveSession() != null) {
613
                                Session.getActiveSession().closeAndClearTokenInformation();
614
                            }
615
                            Session.setActiveSession(null);
616
                            userDataEditor.clear().commit();
617
                            startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
618
                        }
619
                        else{
620
                            Log.d("gmailLogout","logout");
621
                            signOutFromGplus();
622
                            if(glogout==true){
623
                                startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
624
                            }
625
                        }
626
 
627
                    }
628
 
629
                })
630
                .setNegativeButton("No", null)
631
                .show();
632
    }
633
    public void signOutFromGplus() {
634
        if (mGoogleApiClient.isConnected()) {
635
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
636
            mGoogleApiClient.disconnect();
637
            mGoogleApiClient.connect();
638
            glogout=true;
639
            userDataEditor.clear().commit();
640
        } else {
641
            glogout=false;
642
        }
643
    }
644
 
645
    public final boolean isInternetOn() {
646
 
647
        ConnectivityManager connection =
648
                (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
649
 
650
        if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
651
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
652
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
653
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
654
            return true;
655
 
656
        } else if (
657
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
658
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
659
            return false;
660
        }
661
        return false;
662
    }
663
 
664
 
665
    class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
666
 
667
        @Override
668
        protected void onPreExecute() {
669
            super.onPreExecute();
670
 
671
        }
672
 
673
        @Override
674
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
675
 
676
            try {
677
                HttpClient httpclient = new DefaultHttpClient();
678
                HttpPost httppost = new HttpPost(apiData.getString("notication.data.url","http://api.profittill.com/pushnotifications/add"));
679
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
680
                httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
681
                HttpResponse response = httpclient.execute(httppost);
682
                HttpEntity entity = response.getEntity();
683
                int status = response.getStatusLine().getStatusCode();
684
 
685
                if(status == 200){
686
                    Log.d("Notification Opened","Notication opened and sent to server");
687
                    Log.d("ResponseCode GCM ",status+"");
688
                } else {
689
                    Log.d("ResponseCode GCM ",status+"");
690
                }
691
 
692
                nameValuePairsGcm.clear();
693
                Log.e("pass 1", "connection success ");
694
            } catch (Exception e) {
695
                Log.e("Fail 1", e.toString());
696
 
697
            }
698
            return "success";
699
        }
700
 
701
        @Override
702
        protected void onPostExecute(String result) {
703
            super.onPostExecute(result);
704
            Log.d("Notification Opened","Notication opened and login page");
705
        }
706
    }
707
}
708