Subversion Repositories SmartDukaan

Rev

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

Rev 15977 Rev 16278
Line 1... Line 1...
1
package com.saholic.profittill.main;
1
package com.saholic.profittill.main;
2
 
2
 
3
import android.app.AlertDialog;
3
import android.app.AlertDialog;
-
 
4
import android.app.ProgressDialog;
4
import android.content.Context;
5
import android.content.Context;
5
import android.content.DialogInterface;
6
import android.content.DialogInterface;
6
import android.content.Intent;
7
import android.content.Intent;
7
import android.content.SharedPreferences;
8
import android.content.SharedPreferences;
8
import android.net.ConnectivityManager;
9
import android.net.ConnectivityManager;
Line 27... Line 28...
27
import com.google.android.gms.common.api.GoogleApiClient;
28
import com.google.android.gms.common.api.GoogleApiClient;
28
import com.google.android.gms.plus.Plus;
29
import com.google.android.gms.plus.Plus;
29
import com.mixpanel.android.mpmetrics.MixpanelAPI;
30
import com.mixpanel.android.mpmetrics.MixpanelAPI;
30
import com.saholic.profittill.Constants.ProfitTillConstants;
31
import com.saholic.profittill.Constants.ProfitTillConstants;
31
import com.saholic.profittill.R;
32
import com.saholic.profittill.R;
-
 
33
import com.saholic.profittill.Utils.AnalyticsUtility;
-
 
34
import com.saholic.profittill.Volley.Analytics;
-
 
35
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
-
 
36
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
32
import com.testin.agent.TestinAgent;
37
import com.testin.agent.TestinAgent;
33
 
38
 
34
import org.apache.http.HttpEntity;
39
import org.apache.http.HttpEntity;
35
import org.apache.http.HttpResponse;
40
import org.apache.http.HttpResponse;
36
import org.apache.http.NameValuePair;
41
import org.apache.http.NameValuePair;
Line 75... Line 80...
75
        TestinAgent.setUserInfo(userData.getString("id", ""));
80
        TestinAgent.setUserInfo(userData.getString("id", ""));
76
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
81
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
77
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
82
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
78
        t.setScreenName("First Time Mobile Entered Screen");
83
        t.setScreenName("First Time Mobile Entered Screen");
79
        t.send(new HitBuilders.ScreenViewBuilder().build());
84
        t.send(new HitBuilders.ScreenViewBuilder().build());
-
 
85
        new Analytics(ProfitTillConstants.ANALYTICS_URL,
-
 
86
                AnalyticsUtility.getAnalyticsRequest(MobileNumber.this, userData.getString("id", ""), "Screen", "Mobile Number", "Mobile Number Entering"),
-
 
87
                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
-
 
88
                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(MobileNumber.this);
80
 
89
 
81
        type1 = userData.getString("type",null);
90
        type1 = userData.getString("type",null);
82
 
91
 
83
        if(type1!=null && type1.equalsIgnoreCase("google")) {
92
        if(type1!=null && type1.equalsIgnoreCase("google")) {
84
            mGoogleApiClient = new GoogleApiClient.Builder(this)
93
            mGoogleApiClient = new GoogleApiClient.Builder(this)
Line 99... Line 108...
99
            @Override
108
            @Override
100
            public void onClick(View v) {
109
            public void onClick(View v) {
101
 
110
 
102
                JSONObject props = new JSONObject();
111
                JSONObject props = new JSONObject();
103
                try {
112
                try {
104
                    mixpanel.identify(userData.getString("id",null));
113
                    mixpanel.identify(userData.getString("id", null));
105
                    props.put("Screen", "Mobile Verification");
114
                    props.put("Screen", "Mobile Verification");
106
                    mixpanel.track("First Time Mobile Number Skipped",props);
115
                    mixpanel.track("First Time Mobile Number Skipped", props);
107
                } catch (JSONException e) {
116
                } catch (JSONException e) {
108
                    e.printStackTrace();
117
                    e.printStackTrace();
109
                }
118
                }
110
                Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
119
                Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
111
                        GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
120
                        GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
Line 113... Line 122...
113
                        .setCategory("First Time Mobile Entered ")
122
                        .setCategory("First Time Mobile Entered ")
114
                        .setAction("Number not entered")
123
                        .setAction("Number not entered")
115
                        .setLabel("First Time Mobile Not entered")
124
                        .setLabel("First Time Mobile Not entered")
116
                        .build());
125
                        .build());
117
 
126
 
-
 
127
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
-
 
128
                        AnalyticsUtility.getAnalyticsRequest(MobileNumber.this, userData.getString("id", ""), "Clicks", "Mobile Number", "Mobile Number Skipped"),
-
 
129
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
-
 
130
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(MobileNumber.this);
-
 
131
 
118
                Intent i = new Intent(MobileNumber.this,MainActivity.class);
132
                Intent i = new Intent(MobileNumber.this, MainActivity.class);
119
                i.putExtra("displayView","7");
133
                i.putExtra("displayView", "7");
120
                startActivity(i);
134
                startActivity(i);
121
            }
135
            }
122
        });
136
        });
-
 
137
 
123
        phoneNumberFirstTimeButton.setOnClickListener(new View.OnClickListener() {
138
        phoneNumberFirstTimeButton.setOnClickListener(new View.OnClickListener() {
124
            @Override
139
            @Override
125
            public void onClick(View v) {
140
            public void onClick(View v) {
126
                if(phoneNumberFirstTime.getText().toString().length()==10){
141
                if(phoneNumberFirstTime.getText().toString().length()==10){
127
                    if(isInternetOn()) {
142
                    if(isInternetOn()) {
Line 131... Line 146...
131
                            props.put("Screen", "Mobile Verification");
146
                            props.put("Screen", "Mobile Verification");
132
                            mixpanel.track("First Time Mobile Number Entered",props);
147
                            mixpanel.track("First Time Mobile Number Entered",props);
133
                        } catch (JSONException e) {
148
                        } catch (JSONException e) {
134
                            e.printStackTrace();
149
                            e.printStackTrace();
135
                        }
150
                        }
-
 
151
                        if(!(userData.getString("id", "").isEmpty())) {
-
 
152
                            new Analytics(ProfitTillConstants.ANALYTICS_URL,
-
 
153
                                    AnalyticsUtility.getAnalyticsRequest(MobileNumber.this, userData.getString("id", ""), "Clicks", "Mobile Number", "Mobile Number Entered"),
-
 
154
                                    AnalyticsJsonResponse.getAnalyticsRequestInstance(),
-
 
155
                                    AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(MobileNumber.this);
-
 
156
                        }
136
                        new pushVerification().execute();
157
                        new pushVerification().execute();
137
                    }else{
158
                    }else{
138
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
159
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
139
                    }
160
                    }
140
 
161
 
Line 179... Line 200...
179
    @Override
200
    @Override
180
    public void onConnectionFailed(ConnectionResult connectionResult) {
201
    public void onConnectionFailed(ConnectionResult connectionResult) {
181
 
202
 
182
    }
203
    }
183
 
204
 
-
 
205
    ProgressDialog pMobile;
184
    class pushVerification extends AsyncTask<String, Integer, String> {
206
    class pushVerification extends AsyncTask<String, Integer, String> {
185
 
207
 
186
        @Override
208
        @Override
187
        protected void onPreExecute() {
209
        protected void onPreExecute() {
188
            super.onPreExecute();
210
            super.onPreExecute();
-
 
211
            pMobile= new ProgressDialog(MobileNumber.this);
189
            Log.e("Push Service", "Pre execute");
212
            pMobile.setMessage("Saving Data");
-
 
213
            pMobile.setCancelable(false);
-
 
214
            pMobile.show();
190
        }
215
        }
191
 
216
 
192
        @Override
217
        @Override
193
        protected String doInBackground(String... arg0) {
218
        protected String doInBackground(String... arg0) {
194
            HttpClient httpclient = new DefaultHttpClient();
219
            HttpClient httpclient = new DefaultHttpClient();
Line 207... Line 232...
207
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
232
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
208
                HttpResponse response = httpclient.execute(httppost);
233
                HttpResponse response = httpclient.execute(httppost);
209
                HttpEntity entity = response.getEntity();
234
                HttpEntity entity = response.getEntity();
210
                int status = response.getStatusLine().getStatusCode();
235
                int status = response.getStatusLine().getStatusCode();
211
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
236
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
212
                System.out.println("JSON Object in mobile " + jObjGmail.toString());
-
 
-
 
237
 
213
                String success = jObjGmail.getString("success");
238
                String success = jObjGmail.getString("success");
214
 
239
 
215
                if(status == 200){
240
                if(status == 200){
216
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
241
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
217
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
242
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
218
                    t.send(new HitBuilders.EventBuilder()
243
                    t.send(new HitBuilders.EventBuilder()
219
                            .setCategory("First Time Mobile Entered ")
244
                            .setCategory("First Time Mobile Entered ")
220
                            .setAction("Number entered")
245
                            .setAction("Number entered")
221
                            .setLabel("First Time Mobile entered")
246
                            .setLabel("First Time Mobile entered")
222
                            .build());
247
                            .build());
223
 
-
 
224
                } else {
-
 
225
                    System.out.println(" NOT Transfered");
-
 
226
 
-
 
227
                }
248
                }
228
 
-
 
229
                if(success.equalsIgnoreCase("true")){
249
                if(success.equalsIgnoreCase("true")){
230
                    userDataEditor.putString("message","false");;
250
                    userDataEditor.putString("message","false");;
231
                    userDataEditor.commit();
251
                    userDataEditor.commit();
232
                    return "true";
252
                    return "true";
233
                }else{
253
                }else{
Line 245... Line 265...
245
        }
265
        }
246
 
266
 
247
        @Override
267
        @Override
248
        protected void onPostExecute(String result) {
268
        protected void onPostExecute(String result) {
249
            super.onPostExecute(result);
269
            super.onPostExecute(result);
-
 
270
            if(pMobile!=null) {
-
 
271
                pMobile.dismiss();
-
 
272
            }
-
 
273
            if(result.equalsIgnoreCase("true")) {
250
            Intent i = new Intent(MobileNumber.this,MobileVerificationFirstTime.class);
274
                Intent i = new Intent(MobileNumber.this, MobileVerificationFirstTime.class);
251
            i.putExtra("numberVerification",phoneNumberFirstTime.getText().toString());
275
                i.putExtra("numberVerification", phoneNumberFirstTime.getText().toString());
252
            startActivity(i);
276
                startActivity(i);
-
 
277
            }
253
        }
278
        }
254
    }
279
    }
255
 
280
 
256
    @Override
281
    @Override
257
    public void onBackPressed() {
282
    public void onBackPressed() {
258
        /* super.onBackPressed();*/
-
 
259
        new AlertDialog.Builder(this)
283
        new AlertDialog.Builder(this)
260
                .setIcon(android.R.drawable.ic_dialog_alert)
284
                .setIcon(android.R.drawable.ic_dialog_alert)
261
                .setTitle("Exit!")
285
                .setTitle("Exit!")
262
                .setMessage("Are you sure you want to sign out?")
286
                .setMessage("Are you sure you want to sign out?")
263
                .setPositiveButton("Yes", new DialogInterface.OnClickListener()
287
                .setPositiveButton("Yes", new DialogInterface.OnClickListener(){
264
                {
-
 
265
                    @Override
288
                    @Override
266
                    public void onClick(DialogInterface dialog, int which) {
289
                    public void onClick(DialogInterface dialog, int which) {
267
 
-
 
268
                        if(type1.equalsIgnoreCase("facebook")) {
290
                        if(type1.equalsIgnoreCase("facebook")) {
269
                            Log.d("fblogout","logout");
291
                            Log.d("fblogout","logout");
270
                            if (Session.getActiveSession() != null) {
292
                            if (Session.getActiveSession() != null) {
271
                                Session.getActiveSession().closeAndClearTokenInformation();
293
                                Session.getActiveSession().closeAndClearTokenInformation();
272
                            }
294
                            }
273
                            Session.setActiveSession(null);
295
                            Session.setActiveSession(null);
274
/*
-
 
275
                            userDataEditor.remove("id");
-
 
276
                            userDataEditor.remove("type");
-
 
277
                            userDataEditor.remove("email");
-
 
278
*/
-
 
279
                            userDataEditor.clear().commit();
296
                            userDataEditor.clear().commit();
280
/*                            userDataEditor.commit();*/
-
 
281
                            startActivity(new Intent(MobileNumber.this, LoginActivity.class));
297
                            startActivity(new Intent(MobileNumber.this, LoginActivity.class));
282
                        }
298
                        }
283
                        else{
299
                        else{
284
                            Log.d("gmailLogout","logout");
300
                            Log.d("gmailLogout","logout");
285
                            signOutFromGplus();
301
                            signOutFromGplus();