Subversion Repositories SmartDukaan

Rev

Rev 14792 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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