Subversion Repositories SmartDukaan

Rev

Rev 14991 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14792 manas 1
package com.saholic.profittill.main;
2
 
16278 manas 3
import android.app.Fragment;
14792 manas 4
import android.app.ProgressDialog;
5
import android.content.Context;
6
import android.content.Intent;
7
import android.content.SharedPreferences;
8
import android.graphics.Bitmap;
9
import android.graphics.BitmapShader;
10
import android.graphics.Canvas;
11
import android.graphics.Paint;
12
import android.net.ConnectivityManager;
13
import android.os.AsyncTask;
14
import android.os.Bundle;
15
import android.util.Log;
16
import android.view.KeyEvent;
17
import android.view.LayoutInflater;
18
import android.view.View;
19
import android.view.ViewGroup;
20
import android.widget.Button;
21
import android.widget.EditText;
22
import android.widget.ImageView;
23
import android.widget.TextView;
24
import android.widget.Toast;
25
 
26
import com.google.android.gms.analytics.HitBuilders;
27
import com.google.android.gms.analytics.Tracker;
28
import com.mixpanel.android.mpmetrics.MixpanelAPI;
29
import com.saholic.profittill.Constants.ProfitTillConstants;
30
import com.saholic.profittill.R;
16278 manas 31
import com.saholic.profittill.Utils.AnalyticsUtility;
32
import com.saholic.profittill.Volley.Analytics;
33
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
34
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
14792 manas 35
import com.squareup.picasso.Picasso;
36
import com.squareup.picasso.Transformation;
37
import com.testin.agent.TestinAgent;
38
 
39
import org.apache.http.HttpEntity;
40
import org.apache.http.HttpResponse;
41
import org.apache.http.NameValuePair;
42
import org.apache.http.client.ClientProtocolException;
43
import org.apache.http.client.HttpClient;
44
import org.apache.http.client.entity.UrlEncodedFormEntity;
45
import org.apache.http.client.methods.HttpGet;
46
import org.apache.http.client.methods.HttpPost;
47
import org.apache.http.impl.client.DefaultHttpClient;
48
import org.apache.http.message.BasicNameValuePair;
49
import org.apache.http.util.EntityUtils;
50
import org.json.JSONException;
51
import org.json.JSONObject;
52
 
53
import java.io.IOException;
54
import java.util.ArrayList;
55
 
56
public class MyProfile extends Fragment {
57
    SharedPreferences userData;
58
    SharedPreferences apiData;
59
    SharedPreferences.Editor userDataEditor;
60
    SharedPreferences.Editor apiSettingsEditor;
61
    ImageView profileImage;
62
    TextView phoneNumberMyProfileVerifyStatus,phoneNumberMyProfileEdit,profileNameMyProfileEdit,addressLine1MyProfileEdit,addressLine2MyProfileEdit,cityMyProfileEdit,pincodeMyProfileEdit;
63
    TextView profileName;
64
    EditText phoneNumberMyProfile,profileNameMyProfile,addressLine1MyProfile,addressLine2MyProfile,cityMyProfile,pincodeMyProfile;
65
    Button profileEdit,profileSave;
66
    ArrayList<NameValuePair> nameValuePairsProfile;
67
    public MyProfile() {
68
 
69
    }
70
 
71
 
72
    @Override
73
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
74
                             Bundle savedInstanceState) {
75
        View rootView = inflater.inflate(R.layout.fragment_my_profile, container, false);
76
        TestinAgent.init(getActivity());
77
        MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);
78
 
79
        Tracker t = ((GoogleAnalyticsTracker) getActivity().getApplicationContext()).getTracker(
80
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
81
        t.setScreenName("Profile Screen");
82
        t.send(new HitBuilders.ScreenViewBuilder().build());
83
 
84
        profileImage=(ImageView)rootView.findViewById(R.id.profilePicture);
85
 
86
        phoneNumberMyProfile = (EditText)rootView.findViewById(R.id.phoneNumberMyProfile);
87
        profileNameMyProfile = (EditText)rootView.findViewById(R.id.profileNameMyProfile);
88
        addressLine1MyProfile = (EditText)rootView.findViewById(R.id.addressLine1MyProfile);
89
        addressLine2MyProfile = (EditText)rootView.findViewById(R.id.addressLine2MyProfile);
90
        cityMyProfile = (EditText)rootView.findViewById(R.id.cityMyProfile);
91
        pincodeMyProfile =(EditText) rootView.findViewById(R.id.pincodeMyProfile);
92
 
93
 
94
        phoneNumberMyProfileEdit=(TextView) rootView.findViewById(R.id.phoneNumberMyProfileEdit);
95
        profileNameMyProfileEdit=(TextView) rootView.findViewById(R.id.profileNameMyProfileEdit);
96
        addressLine1MyProfileEdit=(TextView) rootView.findViewById(R.id.addressLine1MyProfileEdit);
97
        addressLine2MyProfileEdit=(TextView) rootView.findViewById(R.id.addressLine2MyProfileEdit);
98
        cityMyProfileEdit=(TextView) rootView.findViewById(R.id.cityMyProfileEdit);
99
        pincodeMyProfileEdit=(TextView) rootView.findViewById(R.id.pincodeMyProfileEdit);
100
 
101
 
102
        phoneNumberMyProfileVerifyStatus=(TextView) rootView.findViewById(R.id.phoneNumberMyProfileVerifyStatus);
103
 
104
 
105
        profileSave=(Button) rootView.findViewById(R.id.profileSave);
106
 
107
        userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
108
        apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
109
        userDataEditor = userData.edit();
110
        apiSettingsEditor = apiData.edit();
111
        TestinAgent.setUserInfo(userData.getString("id", ""));
112
        JSONObject props = new JSONObject();
113
        try {
114
            mixpanel.identify(userData.getString("id",null));
115
            props.put("Screen", "My Profile");
116
            mixpanel.track("My Profile", props);
117
        } catch (JSONException e) {
118
            e.printStackTrace();
119
        }
120
        editTextDisabled();
121
        if(isInternetOn()){
16278 manas 122
            new Analytics(ProfitTillConstants.ANALYTICS_URL,
123
                    AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Screen", "My Profile", "My Profile Screen"),
124
                    AnalyticsJsonResponse.getAnalyticsRequestInstance(),
125
                    AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
14792 manas 126
            pd = new ProgressDialog(getActivity());
127
            pd.setTitle("Please wait");
128
            pd.setMessage("Fetching Profile Information..");
129
            pd.show();
130
            new  fetchUserData().execute();
131
        }
132
        else{
133
            SearchFragment nextFrag= new SearchFragment();
134
            Bundle args = new Bundle();
135
            args.putString("finishingurl","");
136
            args.putString("fragmentNumber","10");
137
            nextFrag.setArguments(args);
138
            getActivity().getFragmentManager().beginTransaction()
139
                    .replace(R.id.frame_container, nextFrag)
140
                    .addToBackStack(null)
141
                    .commit();
142
       }
143
        phoneNumberMyProfile.setOnClickListener(new View.OnClickListener() {
144
            @Override
145
            public void onClick(View v) {
146
                phoneNumberMyProfile.setFocusable(true);
147
                phoneNumberMyProfile.setClickable(true);
148
                phoneNumberMyProfile.setFocusableInTouchMode(true);
149
                phoneNumberMyProfile.requestFocus();
150
 
151
                profileNameMyProfile.setFocusable(false);
152
                profileNameMyProfile.setClickable(false);
153
                addressLine1MyProfile.setFocusable(false);
154
                addressLine1MyProfile.setClickable(false);
155
                addressLine2MyProfile.setFocusable(false);
156
                addressLine2MyProfile.setClickable(false);
157
                cityMyProfile.setFocusable(false);
158
                cityMyProfile.setClickable(false);
159
                pincodeMyProfile.setFocusable(false);
160
                pincodeMyProfile.setClickable(false);
14991 manas 161
                v.setOnKeyListener(new View.OnKeyListener() {
162
                    @Override
163
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
164
                        if(event.getAction() == KeyEvent.ACTION_DOWN){
165
                            switch(keyCode) {
166
                                case KeyEvent.KEYCODE_BACK:
167
                                    dealsPageOnBack();
168
                                    return true;
169
                            }
170
                        }
171
                        return false;
172
                    }
173
                });
14792 manas 174
            }
14991 manas 175
 
14792 manas 176
        });
177
 
178
        profileNameMyProfile.setOnClickListener(new View.OnClickListener() {
179
            @Override
180
            public void onClick(View v) {
181
                profileNameMyProfile.setFocusable(true);
182
                profileNameMyProfile.setClickable(true);
183
                profileNameMyProfile.setFocusableInTouchMode(true);
184
                profileNameMyProfile.requestFocus();
185
 
186
                phoneNumberMyProfile.setFocusable(false);
187
                phoneNumberMyProfile.setClickable(false);
188
                addressLine1MyProfile.setFocusable(false);
189
                addressLine1MyProfile.setClickable(false);
190
                addressLine2MyProfile.setFocusable(false);
191
                addressLine2MyProfile.setClickable(false);
192
                cityMyProfile.setFocusable(false);
193
                cityMyProfile.setClickable(false);
194
                pincodeMyProfile.setFocusable(false);
195
                pincodeMyProfile.setClickable(false);
14991 manas 196
                v.setOnKeyListener(new View.OnKeyListener() {
197
                    @Override
198
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
199
                        if(event.getAction() == KeyEvent.ACTION_DOWN){
200
                            switch(keyCode) {
201
                                case KeyEvent.KEYCODE_BACK:
202
                                    dealsPageOnBack();
203
                                    return true;
204
                            }
205
                        }
206
                        return false;
207
                    }
208
                });
14792 manas 209
            }
210
        });
211
 
212
        addressLine1MyProfile.setOnClickListener(new View.OnClickListener() {
213
            @Override
214
            public void onClick(View v) {
215
                addressLine1MyProfile.setFocusable(true);
216
                addressLine1MyProfile.setClickable(true);
217
                addressLine1MyProfile.setFocusableInTouchMode(true);
218
                addressLine1MyProfile.requestFocus();
219
 
220
                phoneNumberMyProfile.setFocusable(false);
221
                phoneNumberMyProfile.setClickable(false);
222
                profileNameMyProfile.setFocusable(false);
223
                profileNameMyProfile.setClickable(false);
224
                addressLine2MyProfile.setFocusable(false);
225
                addressLine2MyProfile.setClickable(false);
226
                cityMyProfile.setFocusable(false);
227
                cityMyProfile.setClickable(false);
228
                pincodeMyProfile.setFocusable(false);
229
                pincodeMyProfile.setClickable(false);
14991 manas 230
                v.setOnKeyListener(new View.OnKeyListener() {
231
                    @Override
232
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
233
                        if(event.getAction() == KeyEvent.ACTION_DOWN){
234
                            switch(keyCode) {
235
                                case KeyEvent.KEYCODE_BACK:
236
                                    dealsPageOnBack();
237
                                    return true;
238
                            }
239
                        }
240
                        return false;
241
                    }
242
                });
14792 manas 243
            }
244
        });
245
 
246
 
247
        addressLine2MyProfile.setOnClickListener(new View.OnClickListener() {
248
            @Override
249
            public void onClick(View v) {
250
                addressLine2MyProfile.setFocusable(true);
251
                addressLine2MyProfile.setClickable(true);
252
                addressLine2MyProfile.setFocusableInTouchMode(true);
253
                addressLine2MyProfile.requestFocus();
254
 
255
                phoneNumberMyProfile.setFocusable(false);
256
                phoneNumberMyProfile.setClickable(false);
257
                profileNameMyProfile.setFocusable(false);
258
                profileNameMyProfile.setClickable(false);
259
                addressLine1MyProfile.setFocusable(false);
260
                addressLine1MyProfile.setClickable(false);
261
                cityMyProfile.setFocusable(false);
262
                cityMyProfile.setClickable(false);
263
                pincodeMyProfile.setFocusable(false);
264
                pincodeMyProfile.setClickable(false);
14991 manas 265
                v.setOnKeyListener(new View.OnKeyListener() {
266
                    @Override
267
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
268
                        if(event.getAction() == KeyEvent.ACTION_DOWN){
269
                            switch(keyCode) {
270
                                case KeyEvent.KEYCODE_BACK:
271
                                    dealsPageOnBack();
272
                                    return true;
273
                            }
274
                        }
275
                        return false;
276
                    }
277
                });
14792 manas 278
            }
279
        });
280
 
281
        cityMyProfile.setOnClickListener(new View.OnClickListener() {
282
            @Override
283
            public void onClick(View v) {
284
                cityMyProfile.setFocusable(true);
285
                cityMyProfile.setClickable(true);
286
                cityMyProfile.setFocusableInTouchMode(true);
287
                cityMyProfile.requestFocus();
288
 
289
                phoneNumberMyProfile.setFocusable(false);
290
                phoneNumberMyProfile.setClickable(false);
291
                profileNameMyProfile.setFocusable(false);
292
                profileNameMyProfile.setClickable(false);
293
                addressLine1MyProfile.setFocusable(false);
294
                addressLine1MyProfile.setClickable(false);
295
                addressLine2MyProfile.setFocusable(false);
296
                addressLine2MyProfile.setClickable(false);
297
                pincodeMyProfile.setFocusable(false);
298
                pincodeMyProfile.setClickable(false);
14991 manas 299
                v.setOnKeyListener(new View.OnKeyListener() {
300
                    @Override
301
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
302
                        if(event.getAction() == KeyEvent.ACTION_DOWN){
303
                            switch(keyCode) {
304
                                case KeyEvent.KEYCODE_BACK:
305
                                    dealsPageOnBack();
306
                                    return true;
307
                            }
308
                        }
309
                        return false;
310
                    }
311
                });
14792 manas 312
            }
313
        });
314
 
315
 
316
        pincodeMyProfile.setOnClickListener(new View.OnClickListener() {
317
            @Override
318
            public void onClick(View v) {
319
                pincodeMyProfile.setFocusable(true);
320
                pincodeMyProfile.setClickable(true);
321
                pincodeMyProfile.setFocusableInTouchMode(true);
322
                pincodeMyProfile.requestFocus();
323
 
324
                phoneNumberMyProfile.setFocusable(false);
325
                phoneNumberMyProfile.setClickable(false);
326
                profileNameMyProfile.setFocusable(false);
327
                profileNameMyProfile.setClickable(false);
328
                addressLine1MyProfile.setFocusable(false);
329
                addressLine1MyProfile.setClickable(false);
330
                addressLine2MyProfile.setFocusable(false);
331
                addressLine2MyProfile.setClickable(false);
332
                cityMyProfile.setFocusable(false);
333
                cityMyProfile.setClickable(false);
14991 manas 334
                v.setOnKeyListener(new View.OnKeyListener() {
335
                    @Override
336
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
337
                        if(event.getAction() == KeyEvent.ACTION_DOWN){
338
                            switch(keyCode) {
339
                                case KeyEvent.KEYCODE_BACK:
340
                                    dealsPageOnBack();
341
                                    return true;
342
                            }
343
                        }
344
                        return false;
345
                    }
346
                });
14792 manas 347
            }
348
        });
349
 
350
        phoneNumberMyProfileEdit.setOnClickListener(new View.OnClickListener() {
351
            @Override
352
            public void onClick(View v) {
353
                phoneNumberMyProfile.setFocusable(true);
354
                phoneNumberMyProfile.setClickable(true);
355
                phoneNumberMyProfile.setFocusableInTouchMode(true);
356
                phoneNumberMyProfile.setCursorVisible(true);
357
                phoneNumberMyProfile.requestFocus();
358
 
359
                profileNameMyProfile.setFocusable(false);
360
                profileNameMyProfile.setClickable(false);
361
                addressLine1MyProfile.setFocusable(false);
362
                addressLine1MyProfile.setClickable(false);
363
                addressLine2MyProfile.setFocusable(false);
364
                addressLine2MyProfile.setClickable(false);
365
                cityMyProfile.setFocusable(false);
366
                cityMyProfile.setClickable(false);
367
                pincodeMyProfile.setFocusable(false);
368
                pincodeMyProfile.setClickable(false);
14991 manas 369
 
14792 manas 370
            }
371
        });
372
 
373
       profileNameMyProfileEdit.setOnClickListener(new View.OnClickListener() {
374
            @Override
375
            public void onClick(View v) {
376
                profileNameMyProfile.setFocusable(true);
377
                profileNameMyProfile.setClickable(true);
378
                profileNameMyProfile.setFocusableInTouchMode(true);
379
                profileNameMyProfile.requestFocus();
380
 
381
                phoneNumberMyProfile.setFocusable(false);
382
                phoneNumberMyProfile.setClickable(false);
383
                addressLine1MyProfile.setFocusable(false);
384
                addressLine1MyProfile.setClickable(false);
385
                addressLine2MyProfile.setFocusable(false);
386
                addressLine2MyProfile.setClickable(false);
387
                cityMyProfile.setFocusable(false);
388
                cityMyProfile.setClickable(false);
389
                pincodeMyProfile.setFocusable(false);
390
                pincodeMyProfile.setClickable(false);
391
            }
392
        });
393
 
394
        addressLine1MyProfileEdit.setOnClickListener(new View.OnClickListener() {
395
            @Override
396
            public void onClick(View v) {
397
                addressLine1MyProfile.setFocusable(true);
398
                addressLine1MyProfile.setClickable(true);
399
                addressLine1MyProfile.setFocusableInTouchMode(true);
400
                addressLine1MyProfile.requestFocus();
401
 
402
                phoneNumberMyProfile.setFocusable(false);
403
                phoneNumberMyProfile.setClickable(false);
404
                profileNameMyProfile.setFocusable(false);
405
                profileNameMyProfile.setClickable(false);
406
                addressLine2MyProfile.setFocusable(false);
407
                addressLine2MyProfile.setClickable(false);
408
                cityMyProfile.setFocusable(false);
409
                cityMyProfile.setClickable(false);
410
                pincodeMyProfile.setFocusable(false);
411
                pincodeMyProfile.setClickable(false);
412
            }
413
        });
414
 
415
        addressLine2MyProfileEdit.setOnClickListener(new View.OnClickListener() {
416
            @Override
417
            public void onClick(View v) {
418
                addressLine2MyProfile.setFocusable(true);
419
                addressLine2MyProfile.setClickable(true);
420
                addressLine2MyProfile.setFocusableInTouchMode(true);
421
                addressLine2MyProfile.requestFocus();
422
 
423
                phoneNumberMyProfile.setFocusable(false);
424
                phoneNumberMyProfile.setClickable(false);
425
                profileNameMyProfile.setFocusable(false);
426
                profileNameMyProfile.setClickable(false);
427
                addressLine1MyProfile.setFocusable(false);
428
                addressLine1MyProfile.setClickable(false);
429
                cityMyProfile.setFocusable(false);
430
                cityMyProfile.setClickable(false);
431
                pincodeMyProfile.setFocusable(false);
432
                pincodeMyProfile.setClickable(false);
433
 
434
            }
435
        });
436
 
437
 
438
        cityMyProfileEdit.setOnClickListener(new View.OnClickListener() {
439
            @Override
440
            public void onClick(View v) {
441
                cityMyProfile.setFocusable(true);
442
                cityMyProfile.setClickable(true);
443
                cityMyProfile.setFocusableInTouchMode(true);
444
                cityMyProfile.requestFocus();
445
 
446
                phoneNumberMyProfile.setFocusable(false);
447
                phoneNumberMyProfile.setClickable(false);
448
                profileNameMyProfile.setFocusable(false);
449
                profileNameMyProfile.setClickable(false);
450
                addressLine1MyProfile.setFocusable(false);
451
                addressLine1MyProfile.setClickable(false);
452
                addressLine2MyProfile.setFocusable(false);
453
                addressLine2MyProfile.setClickable(false);
454
                pincodeMyProfile.setFocusable(false);
455
                pincodeMyProfile.setClickable(false);
456
            }
457
        });
458
 
459
        pincodeMyProfileEdit.setOnClickListener(new View.OnClickListener() {
460
            @Override
461
            public void onClick(View v) {
462
                pincodeMyProfile.setFocusable(true);
463
                pincodeMyProfile.setClickable(true);
464
                pincodeMyProfile.setFocusableInTouchMode(true);
465
                pincodeMyProfile.requestFocus();
466
 
467
                phoneNumberMyProfile.setFocusable(false);
468
                phoneNumberMyProfile.setClickable(false);
469
                profileNameMyProfile.setFocusable(false);
470
                profileNameMyProfile.setClickable(false);
471
                addressLine1MyProfile.setFocusable(false);
472
                addressLine1MyProfile.setClickable(false);
473
                addressLine2MyProfile.setFocusable(false);
474
                addressLine2MyProfile.setClickable(false);
475
                cityMyProfile.setFocusable(false);
476
                cityMyProfile.setClickable(false);
477
            }
478
        });
479
 
480
 
481
        profileSave.setOnClickListener(new View.OnClickListener() {
482
            @Override
483
            public void onClick(View v) {
484
 
485
                if((phoneNumberMyProfile.getText().toString().length()==10 || phoneNumberMyProfile.getText().toString().isEmpty()) && (pincodeMyProfile.getText().toString().length()==6 || pincodeMyProfile.getText().toString().isEmpty())) {
486
                    if (isInternetOn()) {
16278 manas 487
 
488
                        new Analytics(ProfitTillConstants.ANALYTICS_URL,
489
                                AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Clicks", "My Profile", "Save Address Details"),
490
                                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
491
                                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
492
 
14792 manas 493
                        nameValuePairsProfile = new ArrayList<NameValuePair>();
494
                        nameValuePairsProfile.add(new BasicNameValuePair("id", userData.getString("id", null)));
495
                        nameValuePairsProfile.add(new BasicNameValuePair("mobile_number", phoneNumberMyProfile.getText().toString()));
496
                        nameValuePairsProfile.add(new BasicNameValuePair("address_line_1", addressLine1MyProfile.getText().toString()));
497
                        nameValuePairsProfile.add(new BasicNameValuePair("address_line_2", addressLine2MyProfile.getText().toString()));
498
                        nameValuePairsProfile.add(new BasicNameValuePair("city", cityMyProfile.getText().toString()));
499
                        nameValuePairsProfile.add(new BasicNameValuePair("pincode", pincodeMyProfile.getText().toString()));
500
                        nameValuePairsProfile.add(new BasicNameValuePair("first_name", profileNameMyProfile.getText().toString()));
501
                        new PushDataProfile().execute();
502
                    } else {
503
                        Toast.makeText(getActivity(), "Sorry could not update the details. Please try again later", Toast.LENGTH_SHORT).show();
504
                    }
505
                }else if(phoneNumberMyProfile.getText().toString().length()!=10){
506
                    Toast.makeText(getActivity(), "Mobile Number not valid", Toast.LENGTH_SHORT).show();
507
                }else if(pincodeMyProfile.getText().toString().length()!=6){
508
                    Toast.makeText(getActivity(), "Pincode not valid", Toast.LENGTH_SHORT).show();
509
                }
510
            }
511
        });
512
        rootView.setOnKeyListener(new View.OnKeyListener() {
513
            @Override
514
            public boolean onKey(View v, int keyCode, KeyEvent event) {
14991 manas 515
                Log.d("In my profile" , "In my profile " );
14792 manas 516
                if(event.getAction() == KeyEvent.ACTION_DOWN){
517
                    switch(keyCode) {
518
                        case KeyEvent.KEYCODE_BACK:
519
                            Intent i = new Intent(getActivity(), MainActivity.class);
520
                            i.putExtra("displayView", "0");
521
                            startActivity(i);
522
                            return true;
523
                    }
524
                }
525
                return false;
526
            }
527
        });
528
        return rootView;
529
 
530
    }
531
 
532
   private void editTextDisabled(){
533
            phoneNumberMyProfile.setFocusable(false);
534
            phoneNumberMyProfile.setClickable(false);
535
 
536
            profileNameMyProfile.setFocusable(false);
537
            profileNameMyProfile.setClickable(false);
538
 
539
            addressLine1MyProfile.setFocusable(false);
540
            addressLine1MyProfile.setClickable(false);
541
 
542
            addressLine2MyProfile.setFocusable(false);
543
            addressLine2MyProfile.setClickable(false);
544
 
545
            cityMyProfile.setFocusable(false);
546
            cityMyProfile.setClickable(false);
547
 
548
            pincodeMyProfile.setFocusable(false);
549
            pincodeMyProfile.setClickable(false);
550
 
551
    }
552
 
553
    @Override
554
    public void onViewCreated(View view, Bundle savedInstanceState) {
555
        super.onViewCreated(view, savedInstanceState);
556
    }
557
 
558
 
559
    class fetchUserData extends AsyncTask<String, Integer, JSONObject> {
560
 
561
        @Override
562
        protected void onPreExecute() {
563
            super.onPreExecute();
564
        }
565
 
566
        @Override
567
        protected JSONObject doInBackground(String... arg0) {
568
            HttpClient httpclient = new DefaultHttpClient();
569
            try {
570
                String fetchUrl = apiData.getString("userprofile.url",null)+"?user_id="+ userData.getString("id",null);
571
                HttpGet httppost = new HttpGet(fetchUrl);
572
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
573
                HttpResponse response = httpclient.execute(httppost);
574
 
575
                HttpEntity entity = response.getEntity();
576
                int status = response.getStatusLine().getStatusCode();
577
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
578
                System.out.println(jObjGmail.toString());
579
 
580
                return jObjGmail;
581
 
582
 
583
            } catch (ClientProtocolException e) {
584
                Log.e("data","data " + e.getMessage());
585
                return null;
586
            } catch (IOException e) {
587
                Log.e("data","data " + e.getMessage());
588
                return null;
589
            }catch (Exception e){
590
                Log.e("data","data " + e.getMessage());
591
                return null;
592
            }
593
        }
594
 
595
        @Override
596
        protected void onPostExecute(JSONObject result) {
597
            super.onPostExecute(result);
598
            if(result==null){
599
                pd.dismiss();
600
            }else {
601
                try {
602
                    if (result.getString("first_name") == "null") {
603
 
604
                    } else {
605
                        profileNameMyProfile.setText(result.getString("first_name").toString());
606
                    }
607
                    if (result.getString("mobile_number") == "null") {
608
 
609
                    } else {
610
                        phoneNumberMyProfile.setText(result.getString("mobile_number").toString());
611
                    }
612
                    if (result.getString("address_line_1") == "null") {
613
 
614
                    } else {
615
                        addressLine1MyProfile.setText(result.getString("address_line_1").toString());
616
                    }
617
                    if (result.getString("address_line_2") == "null") {
618
 
619
                    } else {
620
                        addressLine2MyProfile.setText(result.getString("address_line_2").toString());
621
                    }
622
                    if (result.getString("city") == "null") {
623
 
624
                    } else {
625
                        cityMyProfile.setText(result.getString("city").toString());
626
                    }
627
                    if (result.getString("pincode") == "null" || result.getString("pincode") == "0") {
628
 
629
                    } else {
630
                        pincodeMyProfile.setText(result.getString("pincode").toString());
631
                    }
632
                    if (result.getString("profile_pic").equalsIgnoreCase("null")) {
633
                            profileImage.setImageResource(R.drawable.noimageavailable);
634
                            profileImage.setMaxHeight(300);
635
                            profileImage.setMaxWidth(300);
636
                        } else if (userData.getString("type", null).equalsIgnoreCase("google")) {
637
                            String profileImageUrl = result.getString("profile_pic");
638
                            String x = profileImageUrl.split("sz=")[1];
639
                            String updatedUrl = profileImageUrl.replace("sz=" + x, "sz=300");
640
                            Picasso.with(getActivity())
641
                                    .load(updatedUrl)
642
                                    .transform(new CircleTransform())
643
                                    .into(profileImage);
644
                        } else if (userData.getString("type", null).equalsIgnoreCase("facebook")) {
645
                            String profileImageUrl = result.getString("profile_pic").toString();
646
                            String replaceString = profileImageUrl.replace("http", "https");
647
                            String appendDimen = "?&height=300&type=normal&width=300";
648
                            String updatedUrl = replaceString.concat(appendDimen);
649
 
650
                            Picasso.with(getActivity())
651
                                    .load(updatedUrl)
652
                                    .transform(new CircleTransform())
653
                                    .into(profileImage);
654
                        } else {
655
                            profileImage.setImageResource(R.drawable.noimageavailable);
656
                            profileImage.setMaxHeight(300);
657
                            profileImage.setMaxWidth(300);
658
                        }
659
 
660
                    if (result.getString("mobile_verified") == "true") {
661
                        phoneNumberMyProfileVerifyStatus.setText("Verified");
662
                    } else {
663
                        phoneNumberMyProfileVerifyStatus.setText("Verify Now to get Cashback");
664
                        phoneNumberMyProfileVerifyStatus.setClickable(true);
665
                        if (isInternetOn()) {
666
                            if (phoneNumberMyProfile.getText().toString().isEmpty() || phoneNumberMyProfile.getText().toString().length() != 10) {
667
                                Toast.makeText(getActivity(), "Please Enter a number to be verified", Toast.LENGTH_SHORT).show();
668
                            } else {
669
                                phoneNumberMyProfileVerifyStatus.setOnClickListener(new View.OnClickListener() {
670
                                    @Override
671
                                    public void onClick(View v) {
16278 manas 672
                                        new Analytics(ProfitTillConstants.ANALYTICS_URL,
673
                                                AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Clicks", "My Profile", "Verify Number"),
674
                                                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
675
                                                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
14792 manas 676
                                        Intent i = new Intent(getActivity(), MObileNumberVerificationActivity.class);
677
                                        i.putExtra("numberVerification", phoneNumberMyProfile.getText().toString());
678
                                        startActivity(i);
679
                                    }
680
                                });
681
                            }
682
                        } else {
683
                            Toast.makeText(getActivity(), "No internet connection.Phone number could not be verified", Toast.LENGTH_SHORT).show();
684
                        }
685
                    }
686
 
687
                    pd.dismiss();
688
                } catch (JSONException e) {
689
                    e.printStackTrace();
690
                }
691
            }
692
        }
693
    }
694
 
695
    public class CircleTransform implements Transformation {
696
        @Override
697
        public Bitmap transform(Bitmap source) {
698
            int size = Math.min(source.getWidth(), source.getHeight());
699
 
700
            int x = (source.getWidth() - size) / 2;
701
            int y = (source.getHeight() - size) / 2;
702
 
703
            Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
704
            if (squaredBitmap != source) {
705
                source.recycle();
706
            }
707
 
708
            Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
709
 
710
            Canvas canvas = new Canvas(bitmap);
711
            Paint paint = new Paint();
712
            BitmapShader shader = new BitmapShader(squaredBitmap,
713
                    BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
714
            paint.setShader(shader);
715
            paint.setAntiAlias(true);
716
 
717
            float r = size / 2f;
718
            canvas.drawCircle(r, r, r, paint);
719
 
720
            squaredBitmap.recycle();
721
            return bitmap;
722
        }
723
 
724
        @Override
725
        public String key() {
726
            return "circle";
727
        }
728
    }
729
 
730
    ProgressDialog pd = null;
731
 
732
    public final boolean isInternetOn() {
733
 
734
        ConnectivityManager connec =
735
                (ConnectivityManager)getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);
736
 
737
        if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
738
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
739
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
740
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
741
 
742
            return true;
743
 
744
        } else if (
745
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
746
                        connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
747
            return false;
748
        }
749
        return false;
750
    }
751
    @Override
752
    public void onResume() {
753
        super.onResume();
754
        getView().setFocusableInTouchMode(true);
755
        getView().requestFocus();
756
        getView().setOnKeyListener(new View.OnKeyListener() {
757
            @Override
758
            public boolean onKey(View v, int keyCode, KeyEvent event) {
759
 
760
                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
761
                    Intent i = new Intent(getActivity(), MainActivity.class);
762
                    i.putExtra("displayView", "0");
763
                    startActivity(i);
764
                    return true;
765
                }
766
                return false;
767
            }
768
        });
769
    }
770
 
771
 
772
 
773
    class PushDataProfile extends AsyncTask<String, Integer, String> {
774
 
775
        @Override
776
        protected void onPreExecute() {
777
            super.onPreExecute();
778
        }
779
 
780
        @Override
781
        protected String doInBackground(String... arg0) {
782
            HttpClient httpclient = new DefaultHttpClient();
783
            try {
784
 
785
                String fetchUrl = apiData.getString("useredit.url",null)+ userData.getString("id",null);
786
                HttpPost httppost = new HttpPost(fetchUrl);
787
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
788
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsProfile));
789
                HttpResponse response = httpclient.execute(httppost);
790
                HttpEntity entity = response.getEntity();
791
                return "success";
792
            } catch (ClientProtocolException e) {
793
                return "failure";
794
            } catch (IOException e) {
795
                return "failure";
796
            }catch (Exception e){
797
                return "failure";
798
            }
799
        }
800
 
801
        @Override
802
        protected void onPostExecute(String result) {
803
            Intent i = new Intent(getActivity(),MainActivity.class);
804
            i.putExtra("displayView","15");
805
            startActivity(i);
806
            super.onPostExecute(result);
807
        }
808
    }
14991 manas 809
 
810
    public void dealsPageOnBack(){
811
        Intent i = new Intent(getActivity(), MainActivity.class);
812
        i.putExtra("displayView", "0");
813
        startActivity(i);
814
    }
14792 manas 815
}