Subversion Repositories SmartDukaan

Rev

Rev 22834 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22834 Rev 24857
Line 1... Line 1...
1
package com.saholic.profittill;
1
package com.saholic.profittill;
2
 
2
 
3
import android.Manifest;
3
import android.Manifest;
-
 
4
import android.annotation.SuppressLint;
4
import android.app.AlertDialog;
5
import android.app.AlertDialog;
5
import android.app.FragmentManager;
6
import android.app.FragmentManager;
6
import android.app.ProgressDialog;
7
import android.app.ProgressDialog;
7
import android.content.Context;
8
import android.content.Context;
8
import android.content.DialogInterface;
9
import android.content.DialogInterface;
Line 16... Line 17...
16
import android.os.Build;
17
import android.os.Build;
17
import android.os.Bundle;
18
import android.os.Bundle;
18
import android.support.annotation.NonNull;
19
import android.support.annotation.NonNull;
19
import android.support.v4.app.ActivityCompat;
20
import android.support.v4.app.ActivityCompat;
20
import android.support.v4.content.ContextCompat;
21
import android.support.v4.content.ContextCompat;
21
import android.support.v7.app.ActionBarActivity;
-
 
-
 
22
 
22
import android.support.v7.app.AppCompatActivity;
23
import android.support.v7.app.AppCompatActivity;
23
import android.telephony.TelephonyManager;
24
import android.telephony.TelephonyManager;
24
import android.util.Log;
25
import android.util.Log;
25
import android.view.Menu;
26
import android.view.Menu;
26
import android.view.MenuItem;
27
import android.view.MenuItem;
Line 48... Line 49...
48
import org.apache.http.HttpEntity;
49
import org.apache.http.HttpEntity;
49
import org.apache.http.HttpResponse;
50
import org.apache.http.HttpResponse;
50
import org.apache.http.NameValuePair;
51
import org.apache.http.NameValuePair;
51
import org.apache.http.client.HttpClient;
52
import org.apache.http.client.HttpClient;
52
import org.apache.http.client.entity.UrlEncodedFormEntity;
53
import org.apache.http.client.entity.UrlEncodedFormEntity;
-
 
54
import org.apache.http.client.methods.HttpGet;
53
import org.apache.http.client.methods.HttpPost;
55
import org.apache.http.client.methods.HttpPost;
54
import org.apache.http.impl.client.DefaultHttpClient;
56
import org.apache.http.impl.client.DefaultHttpClient;
55
import org.apache.http.message.BasicNameValuePair;
57
import org.apache.http.message.BasicNameValuePair;
56
import org.apache.http.util.EntityUtils;
58
import org.apache.http.util.EntityUtils;
57
import org.json.JSONArray;
59
import org.json.JSONArray;
-
 
60
import org.json.JSONException;
58
import org.json.JSONObject;
61
import org.json.JSONObject;
59
 
62
 
-
 
63
import java.io.IOException;
-
 
64
import java.io.UnsupportedEncodingException;
60
import java.util.ArrayList;
65
import java.util.ArrayList;
61
 
66
 
62
 
67
 
63
public class SplashScreen extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
68
public class SplashScreen extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
64
    SharedPreferences apiData, userData, apkData;
69
    SharedPreferences apiData, userData, apkData;
65
    SharedPreferences.Editor apiEditor, userEditor, apkDataEditor,userDataEditor;
70
    SharedPreferences.Editor apiEditor, userEditor, apkDataEditor,userDataEditor;
66
    UtilityFunctions utilityFunctions;
71
    UtilityFunctions utilityFunctions;
67
    AlertDialog dialog1;
72
    AlertDialog dialog1;
68
    public GoogleApiClient mGoogleApiClient;
73
    public GoogleApiClient mGoogleApiClient;
Line 194... Line 199...
194
 
199
 
195
        if (appLastBuildVersion == appCurrentBuildVersion ) {
200
        if (appLastBuildVersion == appCurrentBuildVersion ) {
196
            final String idCheck = userData.getString("id", null);
201
            final String idCheck = userData.getString("id", null);
197
 
202
 
198
            if(idCheck != null){
203
            if(idCheck != null){
199
                Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
-
 
200
                Intent intent = getIntent();
204
                new AuthTokenChange().execute();
201
                if (Intent.ACTION_VIEW.equals(intent.getAction())) {
-
 
202
                    Uri uri = intent.getData();
-
 
203
                    startActivityIntent.setAction("31");
-
 
204
                    startActivityIntent.setData(Uri.parse(uri.toString()));
-
 
205
                }
-
 
206
                startActivity(startActivityIntent);
-
 
-
 
205
 
207
            }
206
            }
208
            else{
207
            else{
209
                Intent startActivityIntent=new Intent(SplashScreen.this,LoginActivity   .class);
208
                Intent startActivityIntent=new Intent(SplashScreen.this,LoginActivity   .class);
210
                Intent intent = getIntent();
209
                Intent intent = getIntent();
211
                if (Intent.ACTION_VIEW.equals(intent.getAction())) {
210
                if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Line 441... Line 440...
441
            try {
440
            try {
442
                HttpClient httpclient = new DefaultHttpClient();
441
                HttpClient httpclient = new DefaultHttpClient();
443
                HttpPost httppost = new HttpPost(apiData.getString("devices_info","http://api.profittill.com/devices/add"));
442
                HttpPost httppost = new HttpPost(apiData.getString("devices_info","http://api.profittill.com/devices/add"));
444
                //HttpPost httppost = new HttpPost(ProfitTillConstants.Push_Url);
443
                //HttpPost httppost = new HttpPost(ProfitTillConstants.Push_Url);
445
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
444
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
-
 
445
               // HttpPost httppost = new HttpPost("http://192.168.120.52:8080/profitmandi-web/devices/add");
-
 
446
                //httppost.setHeader("Auth-Token", userData.getString("token", ""));
446
                httppost.setEntity(new UrlEncodedFormEntity(apkDataListValue));
447
                httppost.setEntity(new UrlEncodedFormEntity(apkDataListValue));
447
                HttpResponse response = httpclient.execute(httppost);
448
                HttpResponse response = httpclient.execute(httppost);
448
                HttpEntity entity = response.getEntity();
449
                HttpEntity entity = response.getEntity();
449
                int status = response.getStatusLine().getStatusCode();
450
                int status = response.getStatusLine().getStatusCode();
450
 
451
 
Line 523... Line 524...
523
        @Override
524
        @Override
524
        protected void onPreExecute() {
525
        protected void onPreExecute() {
525
            super.onPreExecute();
526
            super.onPreExecute();
526
        }
527
        }
527
 
528
 
-
 
529
        @SuppressLint("MissingPermission")
528
        @Override
530
        @Override
529
        protected String doInBackground(String... arg0) {
531
        protected String doInBackground(String... arg0) {
530
            String id = null;
532
            String id = null;
531
            try {
533
            try {
532
                HttpClient httpclient = new DefaultHttpClient();
534
                HttpClient httpclient = new DefaultHttpClient();
Line 615... Line 617...
615
                startActivity(startActivityIntent);
617
                startActivity(startActivityIntent);
616
 
618
 
617
            }
619
            }
618
        }
620
        }
619
    }
621
    }
-
 
622
 
-
 
623
    class AuthTokenChange extends AsyncTask<String, Integer, String> {
-
 
624
 
-
 
625
        @Override
-
 
626
        protected void onPreExecute() {
-
 
627
 
-
 
628
            super.onPreExecute();
-
 
629
        }
-
 
630
 
-
 
631
        @Override
-
 
632
        protected String doInBackground(String... params) {
-
 
633
            try {
-
 
634
                HttpClient httpclient = new DefaultHttpClient();
-
 
635
                HttpGet httpget = new HttpGet(apiData.getString("Web_Api_Tokendetail","http://192.168.120.52/apis/user/detail/token"));
-
 
636
               // HttpGet httpget = new HttpGet("http://192.168.120.52:8080/profitmandi-web/user/detail/token");
-
 
637
                httpget.setHeader("Auth-Token", userData.getString("token", ""));
-
 
638
                HttpResponse response = httpclient.execute(httpget);
-
 
639
                HttpEntity entity = response.getEntity();
-
 
640
                int status = response.getStatusLine().getStatusCode();
-
 
641
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
-
 
642
                Log.d("Json",String.valueOf(jObjGmail));
-
 
643
                return String.valueOf(jObjGmail);
-
 
644
 
-
 
645
            } catch (UnsupportedEncodingException e) {
-
 
646
                e.printStackTrace();
-
 
647
            } catch (IOException e) {
-
 
648
                e.printStackTrace();
-
 
649
            } catch (JSONException e) {
-
 
650
                e.printStackTrace();
-
 
651
            }
-
 
652
            return null;
-
 
653
        }
-
 
654
 
-
 
655
        @Override
-
 
656
        protected void onPostExecute(String result) {
-
 
657
            super.onPostExecute(result);
-
 
658
            try {
-
 
659
                JSONObject jsonObject = new JSONObject(result);
-
 
660
                JSONObject jobj = jsonObject.getJSONObject("response");
-
 
661
                String status =jsonObject.getString("statusMessage" );
-
 
662
                if(jsonObject.getString("statusMessage" ).equalsIgnoreCase("FORBIDDEN")){
-
 
663
                    try{
-
 
664
                        if (mGoogleApiClient.isConnected()) {
-
 
665
                            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
-
 
666
                            mGoogleApiClient.disconnect();
-
 
667
                            mGoogleApiClient.connect();
-
 
668
                            userDataEditor.clear().commit();
-
 
669
                            startActivity(new Intent(SplashScreen.this, LoginActivity.class));
-
 
670
                        }
-
 
671
                        else{
-
 
672
                            if(!mGoogleApiClient.isConnected()){
-
 
673
                                userDataEditor.clear().commit();
-
 
674
                                startActivity(new Intent(SplashScreen.this, LoginActivity.class));
-
 
675
                            }
-
 
676
 
-
 
677
 
-
 
678
                        }
-
 
679
                    }catch (Exception e){
-
 
680
                        userDataEditor.clear().commit();
-
 
681
                        startActivity(new Intent(SplashScreen.this, LoginActivity.class));
-
 
682
                    }
-
 
683
                }
-
 
684
                else{
-
 
685
                    Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
-
 
686
                    Intent intent = getIntent();
-
 
687
                    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
-
 
688
                        Uri uri = intent.getData();
-
 
689
                        startActivityIntent.setAction("31");
-
 
690
                        startActivityIntent.setData(Uri.parse(uri.toString()));
-
 
691
                    }
-
 
692
                    startActivity(startActivityIntent);
-
 
693
                }
-
 
694
            }catch (Exception e){
-
 
695
              e.printStackTrace();
-
 
696
            }
-
 
697
 
-
 
698
    }}
620
}
699
}
621
700