| 21480 |
rajender |
1 |
package com.saholic.profittill;
|
|
|
2 |
|
|
|
3 |
import android.Manifest;
|
| 24857 |
tejbeer |
4 |
import android.annotation.SuppressLint;
|
| 21480 |
rajender |
5 |
import android.app.AlertDialog;
|
| 22834 |
rajender |
6 |
import android.app.FragmentManager;
|
| 21480 |
rajender |
7 |
import android.app.ProgressDialog;
|
|
|
8 |
import android.content.Context;
|
|
|
9 |
import android.content.DialogInterface;
|
|
|
10 |
import android.content.Intent;
|
|
|
11 |
import android.content.SharedPreferences;
|
| 22834 |
rajender |
12 |
import android.content.pm.PackageInfo;
|
| 21480 |
rajender |
13 |
import android.content.pm.PackageManager;
|
|
|
14 |
import android.net.ConnectivityManager;
|
|
|
15 |
import android.net.Uri;
|
|
|
16 |
import android.os.AsyncTask;
|
|
|
17 |
import android.os.Build;
|
|
|
18 |
import android.os.Bundle;
|
|
|
19 |
import android.support.annotation.NonNull;
|
|
|
20 |
import android.support.v4.app.ActivityCompat;
|
|
|
21 |
import android.support.v4.content.ContextCompat;
|
| 24857 |
tejbeer |
22 |
|
| 22834 |
rajender |
23 |
import android.support.v7.app.AppCompatActivity;
|
| 21480 |
rajender |
24 |
import android.telephony.TelephonyManager;
|
|
|
25 |
import android.util.Log;
|
|
|
26 |
import android.view.Menu;
|
|
|
27 |
import android.view.MenuItem;
|
| 22834 |
rajender |
28 |
import android.view.View;
|
|
|
29 |
import android.view.ViewGroup;
|
| 21480 |
rajender |
30 |
import android.widget.ProgressBar;
|
|
|
31 |
import android.widget.Toast;
|
|
|
32 |
|
|
|
33 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
34 |
import com.google.android.gms.analytics.Tracker;
|
|
|
35 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
36 |
import com.google.android.gms.common.api.GoogleApiClient;
|
| 22834 |
rajender |
37 |
import com.google.android.gms.plus.Plus;
|
| 21480 |
rajender |
38 |
import com.google.firebase.iid.FirebaseInstanceId;
|
|
|
39 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
40 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
| 22834 |
rajender |
41 |
import com.saholic.profittill.main.DealsHomeFragment;
|
| 21480 |
rajender |
42 |
import com.saholic.profittill.main.GoogleAnalyticsTracker;
|
| 22834 |
rajender |
43 |
import com.saholic.profittill.main.HowItWorks;
|
| 21480 |
rajender |
44 |
import com.saholic.profittill.main.LoginActivity;
|
|
|
45 |
import com.saholic.profittill.main.MainActivity;
|
| 22834 |
rajender |
46 |
import com.saholic.profittill.main.ScreenActivity;
|
| 21480 |
rajender |
47 |
import com.testin.agent.TestinAgent;
|
|
|
48 |
|
|
|
49 |
import org.apache.http.HttpEntity;
|
|
|
50 |
import org.apache.http.HttpResponse;
|
|
|
51 |
import org.apache.http.NameValuePair;
|
|
|
52 |
import org.apache.http.client.HttpClient;
|
|
|
53 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| 24857 |
tejbeer |
54 |
import org.apache.http.client.methods.HttpGet;
|
| 21480 |
rajender |
55 |
import org.apache.http.client.methods.HttpPost;
|
|
|
56 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
57 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
58 |
import org.apache.http.util.EntityUtils;
|
|
|
59 |
import org.json.JSONArray;
|
| 24857 |
tejbeer |
60 |
import org.json.JSONException;
|
| 21480 |
rajender |
61 |
import org.json.JSONObject;
|
|
|
62 |
|
| 24857 |
tejbeer |
63 |
import java.io.IOException;
|
|
|
64 |
import java.io.UnsupportedEncodingException;
|
| 21480 |
rajender |
65 |
import java.util.ArrayList;
|
|
|
66 |
|
|
|
67 |
|
| 24857 |
tejbeer |
68 |
public class SplashScreen extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
|
| 21480 |
rajender |
69 |
SharedPreferences apiData, userData, apkData;
|
|
|
70 |
SharedPreferences.Editor apiEditor, userEditor, apkDataEditor,userDataEditor;
|
|
|
71 |
UtilityFunctions utilityFunctions;
|
|
|
72 |
AlertDialog dialog1;
|
| 22834 |
rajender |
73 |
public GoogleApiClient mGoogleApiClient;
|
| 21480 |
rajender |
74 |
AlertDialog.Builder b;
|
|
|
75 |
ProgressBar pd;
|
| 22834 |
rajender |
76 |
Context c;
|
|
|
77 |
String type1;
|
| 21480 |
rajender |
78 |
FirebaseInstanceId fcm;
|
|
|
79 |
String regId;
|
|
|
80 |
ArrayList<NameValuePair> apkDataListValue;
|
|
|
81 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
|
|
82 |
public static final int READ_PHONE_STATE_PERMISSION = 100;
|
|
|
83 |
private boolean PermissionIngranted=false;
|
|
|
84 |
@Override
|
|
|
85 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
86 |
TestinAgent.init(this);
|
|
|
87 |
super.onCreate(savedInstanceState);
|
|
|
88 |
setContentView(R.layout.activity_splash_screen);
|
| 22834 |
rajender |
89 |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
|
|
90 |
getSupportActionBar().hide();
|
|
|
91 |
}
|
| 22133 |
rajender |
92 |
GIFView gifImageView = (GIFView) findViewById(R.id.gif);
|
|
|
93 |
gifImageView.setGifImageResource(R.drawable.progressbar);
|
| 21480 |
rajender |
94 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
|
|
95 |
apkData = getApplicationContext().getSharedPreferences("APK_Data", MODE_PRIVATE);
|
|
|
96 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
|
|
97 |
apkDataEditor = apkData.edit();
|
| 22834 |
rajender |
98 |
userDataEditor = userData.edit();
|
| 21480 |
rajender |
99 |
apiEditor = apiData.edit();
|
| 22834 |
rajender |
100 |
|
| 21480 |
rajender |
101 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
102 |
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, READ_PHONE_STATE_PERMISSION);
|
|
|
103 |
}
|
|
|
104 |
else{
|
|
|
105 |
PermissionIngranted=true;
|
|
|
106 |
}
|
| 22834 |
rajender |
107 |
|
|
|
108 |
type1 = userData.getString("type", null);
|
|
|
109 |
if (type1 != null && type1.equalsIgnoreCase("google")) {
|
|
|
110 |
mGoogleApiClient = new GoogleApiClient.Builder(SplashScreen.this)
|
|
|
111 |
.addConnectionCallbacks(this)
|
|
|
112 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
113 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
114 |
mGoogleApiClient.connect();
|
|
|
115 |
}
|
| 21480 |
rajender |
116 |
String url = "";
|
|
|
117 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
118 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
119 |
t.setScreenName("Splash Screen");
|
|
|
120 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
121 |
try {
|
|
|
122 |
String apkVersionCode = apkData.getString("versionCode","");
|
|
|
123 |
String apkVersionName = apkData.getString("versionName","");
|
|
|
124 |
if(userData.getString("id","").isEmpty()) {
|
|
|
125 |
|
|
|
126 |
}else {
|
|
|
127 |
if (apkVersionCode.isEmpty()) {
|
|
|
128 |
utilityFunctions=new UtilityFunctions();
|
|
|
129 |
apkDataListValue = utilityFunctions.getDeviceInformation(this);
|
|
|
130 |
|
|
|
131 |
if(isInternetOn()) {
|
|
|
132 |
new pushApkData().execute();
|
|
|
133 |
}
|
|
|
134 |
} else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
|
|
|
135 |
utilityFunctions=new UtilityFunctions();
|
|
|
136 |
apkDataListValue = utilityFunctions.getDeviceInformation(this);
|
|
|
137 |
if(isInternetOn()) {
|
|
|
138 |
new pushApkData().execute();
|
|
|
139 |
}
|
|
|
140 |
} else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
|
|
|
141 |
|
|
|
142 |
} else {
|
|
|
143 |
utilityFunctions=new UtilityFunctions();
|
|
|
144 |
apkDataListValue = utilityFunctions.getDeviceInformation(this);
|
|
|
145 |
if(isInternetOn()) {
|
|
|
146 |
new pushApkData().execute();
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
}catch (Exception e){
|
|
|
151 |
e.printStackTrace();
|
|
|
152 |
}
|
|
|
153 |
if(isInternetOn()){
|
|
|
154 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
155 |
requestphoneUpdates();
|
|
|
156 |
}
|
|
|
157 |
else{
|
|
|
158 |
new fetchAPISettings().execute();
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
else{
|
|
|
162 |
b= new AlertDialog.Builder(this);
|
| 22381 |
rajender |
163 |
b.setIcon(R.drawable.interet);
|
|
|
164 |
b.setTitle("No Internet Connection");
|
| 21480 |
rajender |
165 |
b.setMessage("No internet connection. Please try again.");
|
|
|
166 |
b.setCancelable(false);
|
|
|
167 |
b.setPositiveButton("Retry", new DialogInterface.OnClickListener()
|
|
|
168 |
{
|
|
|
169 |
@Override
|
|
|
170 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
171 |
if(isInternetOn()){
|
|
|
172 |
new fetchAPISettings().execute();
|
|
|
173 |
dialog1.dismiss();
|
|
|
174 |
}
|
|
|
175 |
else{
|
|
|
176 |
dialog1 = b.create();
|
|
|
177 |
dialog1.show();
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
});
|
|
|
182 |
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
183 |
@Override
|
|
|
184 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
185 |
finish();
|
|
|
186 |
|
|
|
187 |
}
|
|
|
188 |
});
|
|
|
189 |
dialog1 = b.create();
|
|
|
190 |
dialog1.show();
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
| 22834 |
rajender |
195 |
private int getFirstTimeRun() throws PackageManager.NameNotFoundException {
|
|
|
196 |
SharedPreferences appPreferences = getSharedPreferences("MyAPP", 0);
|
|
|
197 |
int appCurrentBuildVersion = BuildConfig.VERSION_CODE;
|
|
|
198 |
int appLastBuildVersion = appPreferences.getInt("app_first_time", 0);
|
| 21480 |
rajender |
199 |
|
| 22834 |
rajender |
200 |
if (appLastBuildVersion == appCurrentBuildVersion ) {
|
|
|
201 |
final String idCheck = userData.getString("id", null);
|
|
|
202 |
|
|
|
203 |
if(idCheck != null){
|
| 24857 |
tejbeer |
204 |
new AuthTokenChange().execute();
|
|
|
205 |
|
| 22834 |
rajender |
206 |
}
|
|
|
207 |
else{
|
|
|
208 |
Intent startActivityIntent=new Intent(SplashScreen.this,LoginActivity .class);
|
|
|
209 |
Intent intent = getIntent();
|
|
|
210 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
211 |
Uri uri = intent.getData();
|
|
|
212 |
startActivityIntent.setAction("31");
|
|
|
213 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
214 |
}
|
|
|
215 |
startActivity(startActivityIntent);
|
|
|
216 |
}
|
|
|
217 |
return 1;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
else {
|
|
|
221 |
appPreferences.edit().putInt("app_first_time",
|
|
|
222 |
appCurrentBuildVersion).apply();
|
|
|
223 |
if (appLastBuildVersion == 0) {
|
|
|
224 |
Intent startActivityIntent=new Intent(SplashScreen.this, ScreenActivity.class);
|
|
|
225 |
startActivity(startActivityIntent);
|
|
|
226 |
|
|
|
227 |
}
|
|
|
228 |
else {
|
|
|
229 |
try{
|
|
|
230 |
if (mGoogleApiClient.isConnected()) {
|
|
|
231 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
232 |
mGoogleApiClient.disconnect();
|
|
|
233 |
mGoogleApiClient.connect();
|
|
|
234 |
userDataEditor.clear().commit();
|
|
|
235 |
startActivity(new Intent(SplashScreen.this,LoginActivity.class));
|
|
|
236 |
}
|
|
|
237 |
else{
|
|
|
238 |
if(!mGoogleApiClient.isConnected()){
|
|
|
239 |
userDataEditor.clear().commit();
|
|
|
240 |
startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
}
|
|
|
244 |
}catch (Exception e){
|
|
|
245 |
userDataEditor.clear().commit();
|
|
|
246 |
startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
return 2;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
@Override
|
|
|
254 |
public Intent getIntent() {
|
|
|
255 |
return super.getIntent();
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
@Override
|
|
|
259 |
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
|
|
260 |
super.setContentView(view, params);
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
public SplashScreen() {
|
|
|
264 |
super();
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public void requestphoneUpdates(){
|
|
|
268 |
|
| 21480 |
rajender |
269 |
if (ContextCompat.checkSelfPermission(SplashScreen.this,
|
|
|
270 |
Manifest.permission.READ_PHONE_STATE)
|
|
|
271 |
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
272 |
if (ActivityCompat.shouldShowRequestPermissionRationale(SplashScreen.this,
|
|
|
273 |
Manifest.permission.READ_PHONE_STATE)) {
|
|
|
274 |
|
|
|
275 |
} else {
|
|
|
276 |
ActivityCompat.requestPermissions(SplashScreen.this,
|
|
|
277 |
new String[]{Manifest.permission.READ_PHONE_STATE},
|
|
|
278 |
READ_PHONE_STATE_PERMISSION);
|
|
|
279 |
}
|
|
|
280 |
return;
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
@Override
|
|
|
284 |
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
285 |
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
286 |
switch (requestCode){
|
|
|
287 |
|
|
|
288 |
case READ_PHONE_STATE_PERMISSION:
|
|
|
289 |
try {
|
|
|
290 |
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
291 |
PermissionIngranted = true;
|
|
|
292 |
|
|
|
293 |
if(isInternetOn()) {
|
|
|
294 |
new fetchAPISettings().execute();
|
|
|
295 |
|
|
|
296 |
} else {
|
|
|
297 |
b = new AlertDialog.Builder(this);
|
| 22381 |
rajender |
298 |
b.setIcon(R.drawable.interet);
|
|
|
299 |
b.setTitle("No Internet Connection");
|
| 21480 |
rajender |
300 |
b.setMessage("No internet connection. Please try again.");
|
|
|
301 |
b.setCancelable(false);
|
|
|
302 |
b.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
|
|
|
303 |
@Override
|
|
|
304 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
305 |
if (isInternetOn()) {
|
|
|
306 |
new fetchAPISettings().execute();
|
|
|
307 |
dialog1.dismiss();
|
|
|
308 |
} else {
|
|
|
309 |
dialog1 = b.create();
|
|
|
310 |
dialog1.show();
|
|
|
311 |
}
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
});
|
|
|
315 |
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
316 |
@Override
|
|
|
317 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
318 |
finish();
|
|
|
319 |
|
|
|
320 |
}
|
|
|
321 |
});
|
|
|
322 |
dialog1 = b.create();
|
|
|
323 |
dialog1.show();
|
|
|
324 |
}}
|
|
|
325 |
else {
|
| 22834 |
rajender |
326 |
// Toast.makeText(getApplicationContext(),"Permission is required to enter in application",Toast.LENGTH_LONG).show();
|
| 21480 |
rajender |
327 |
PermissionIngranted = false;
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
catch (Exception e){
|
|
|
331 |
e.printStackTrace();
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
break;
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
@Override
|
|
|
340 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
341 |
getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
|
|
|
342 |
return true;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
@Override
|
|
|
346 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
347 |
int id = item.getItemId();
|
|
|
348 |
if (id == R.id.action_settings) {
|
|
|
349 |
return true;
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
return super.onOptionsItemSelected(item);
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
@Override
|
|
|
356 |
public void onConnected(Bundle bundle) {
|
|
|
357 |
requestphoneUpdates();
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
@Override
|
|
|
361 |
public void onConnectionSuspended(int i) {
|
|
|
362 |
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
@Override
|
|
|
366 |
public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
367 |
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
class fetchAPISettings extends AsyncTask<String, Integer, JSONObject> {
|
|
|
371 |
|
|
|
372 |
@Override
|
|
|
373 |
protected void onPreExecute() {
|
|
|
374 |
super.onPreExecute();
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
@Override
|
|
|
378 |
protected JSONObject doInBackground(String... arg0) {
|
|
|
379 |
try {
|
|
|
380 |
|
|
|
381 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
382 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
383 |
String url = ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0")+"&imeinumber="+telephonyManager.getDeviceId();
|
|
|
384 |
HttpPost httppost=new HttpPost(url);
|
|
|
385 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
386 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
387 |
HttpEntity entity = response.getEntity();
|
|
|
388 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
389 |
return jObjGmail;
|
|
|
390 |
|
| 22834 |
rajender |
391 |
}
|
|
|
392 |
catch(Exception e) {
|
| 21480 |
rajender |
393 |
e.printStackTrace();
|
|
|
394 |
return null;
|
|
|
395 |
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
}
|
|
|
399 |
@Override
|
|
|
400 |
protected void onPostExecute(JSONObject result) {
|
|
|
401 |
super.onPostExecute(result);
|
|
|
402 |
if(result==null){
|
|
|
403 |
finish();
|
|
|
404 |
}
|
|
|
405 |
try {
|
|
|
406 |
JSONArray objects = result.getJSONArray("settings");
|
|
|
407 |
if(objects.length()==0){
|
|
|
408 |
System.out.println("Null settings array");
|
|
|
409 |
}else {
|
|
|
410 |
for (int i = 0; i < objects.length(); i++) {
|
|
|
411 |
JSONObject jsonObject = objects.getJSONObject(i);
|
|
|
412 |
JSONObject j = jsonObject.getJSONObject("Mobileappsetting");
|
|
|
413 |
apiEditor.remove(j.getString("setting"));
|
|
|
414 |
apiEditor.commit();
|
|
|
415 |
apiEditor.putString(j.getString("setting"), j.getString("value"));
|
|
|
416 |
apiEditor.commit();
|
|
|
417 |
}
|
|
|
418 |
}
|
|
|
419 |
String timestamp=result.getString("t");
|
|
|
420 |
String failureCount=result.getString("failureCount");
|
|
|
421 |
apkDataEditor.putString("timestamp",timestamp);
|
|
|
422 |
apkDataEditor.commit();
|
| 22834 |
rajender |
423 |
getFirstTimeRun();
|
| 21480 |
rajender |
424 |
|
|
|
425 |
}catch (Exception e){
|
|
|
426 |
finish();
|
|
|
427 |
}
|
|
|
428 |
}
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
class pushApkData extends AsyncTask<String, Integer, String> {
|
|
|
432 |
|
|
|
433 |
@Override
|
|
|
434 |
protected void onPreExecute() {
|
|
|
435 |
super.onPreExecute();
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
@Override
|
|
|
439 |
protected String doInBackground(String... arg0) {
|
|
|
440 |
try {
|
|
|
441 |
HttpClient httpclient = new DefaultHttpClient();
|
| 22834 |
rajender |
442 |
HttpPost httppost = new HttpPost(apiData.getString("devices_info","http://api.profittill.com/devices/add"));
|
| 22133 |
rajender |
443 |
//HttpPost httppost = new HttpPost(ProfitTillConstants.Push_Url);
|
| 21480 |
rajender |
444 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
| 24857 |
tejbeer |
445 |
// HttpPost httppost = new HttpPost("http://192.168.120.52:8080/profitmandi-web/devices/add");
|
|
|
446 |
//httppost.setHeader("Auth-Token", userData.getString("token", ""));
|
| 21480 |
rajender |
447 |
httppost.setEntity(new UrlEncodedFormEntity(apkDataListValue));
|
|
|
448 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
449 |
HttpEntity entity = response.getEntity();
|
|
|
450 |
int status = response.getStatusLine().getStatusCode();
|
|
|
451 |
|
|
|
452 |
if(status == 200){
|
|
|
453 |
apkDataEditor.putString("checkId",userData.getString("id",""));
|
|
|
454 |
apkDataEditor.commit();
|
|
|
455 |
return "success";
|
|
|
456 |
} else {
|
|
|
457 |
return "failure";
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
} catch (Exception e) {
|
|
|
461 |
return null;
|
|
|
462 |
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
}
|
|
|
466 |
@Override
|
|
|
467 |
protected void onPostExecute(String result) {
|
|
|
468 |
super.onPostExecute(result);
|
| 22133 |
rajender |
469 |
}
|
| 21480 |
rajender |
470 |
}
|
|
|
471 |
|
|
|
472 |
|
|
|
473 |
public final boolean isInternetOn() {
|
|
|
474 |
|
|
|
475 |
ConnectivityManager connection =
|
|
|
476 |
(ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
477 |
|
|
|
478 |
if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
479 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
480 |
return true;
|
|
|
481 |
|
|
|
482 |
} else if (
|
|
|
483 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
484 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
485 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
486 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
487 |
return false;
|
|
|
488 |
}
|
|
|
489 |
return false;
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
ProgressDialog pDlg;
|
|
|
493 |
|
|
|
494 |
public void registerGCM() {
|
|
|
495 |
|
|
|
496 |
registerInBackground();
|
|
|
497 |
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
private void registerInBackground() {
|
|
|
501 |
new AsyncTask<Void, Void, String>() {
|
|
|
502 |
@Override
|
|
|
503 |
protected String doInBackground(Void... params) {
|
|
|
504 |
String msg = "";
|
|
|
505 |
if (fcm == null) {
|
|
|
506 |
regId = FirebaseInstanceId.getInstance().getToken();
|
|
|
507 |
msg = "Device registered";
|
|
|
508 |
}
|
|
|
509 |
return msg;
|
|
|
510 |
}
|
|
|
511 |
|
|
|
512 |
@Override
|
|
|
513 |
protected void onPostExecute(String msg) {
|
|
|
514 |
if(userData.getString("fcm_token_sent","false").equalsIgnoreCase("false")) {
|
|
|
515 |
new gcmPushData().execute(msg);
|
|
|
516 |
}
|
|
|
517 |
}
|
|
|
518 |
}.execute(null, null, null);
|
|
|
519 |
}
|
|
|
520 |
|
|
|
521 |
|
|
|
522 |
class gcmPushData extends AsyncTask<String, Integer, String> {
|
|
|
523 |
|
|
|
524 |
@Override
|
|
|
525 |
protected void onPreExecute() {
|
|
|
526 |
super.onPreExecute();
|
|
|
527 |
}
|
|
|
528 |
|
| 24857 |
tejbeer |
529 |
@SuppressLint("MissingPermission")
|
| 21480 |
rajender |
530 |
@Override
|
|
|
531 |
protected String doInBackground(String... arg0) {
|
|
|
532 |
String id = null;
|
|
|
533 |
try {
|
|
|
534 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
535 |
HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://api.profittill.com/gcm_users/add"));
|
| 22133 |
rajender |
536 |
//HttpPost httppost = new HttpPost(ProfitTillConstants.gcm_url);
|
| 21480 |
rajender |
537 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
538 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
539 |
nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
|
|
|
540 |
nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
|
|
|
541 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
|
|
|
542 |
nameValuePairsGcm.add(new BasicNameValuePair("device_message", arg0[0]));
|
|
|
543 |
nameValuePairsGcm.add(new BasicNameValuePair("notification_type","fcm"));
|
|
|
544 |
nameValuePairsGcm.add(new BasicNameValuePair("androidid", UtilityFunctions.androidId(SplashScreen.this)));
|
|
|
545 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
546 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
|
|
|
547 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
548 |
HttpEntity entity = response.getEntity();
|
|
|
549 |
int status = response.getStatusLine().getStatusCode();
|
|
|
550 |
|
|
|
551 |
if(status == 200){
|
|
|
552 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
553 |
userDataEditor.putString("fcm_token_sent", "true");
|
|
|
554 |
userDataEditor.commit();
|
|
|
555 |
} else {
|
|
|
556 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
nameValuePairsGcm.clear();
|
|
|
560 |
Log.e("pass 1", "connection success ");
|
|
|
561 |
} catch (Exception e) {
|
|
|
562 |
Log.e("Fail 1", e.toString());
|
|
|
563 |
|
|
|
564 |
}
|
|
|
565 |
return id;
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
|
|
|
569 |
@Override
|
|
|
570 |
protected void onPostExecute(String result) {
|
|
|
571 |
super.onPostExecute(result);
|
|
|
572 |
final String idCheck = userData.getString("id",null);
|
|
|
573 |
/* if(userData.getString("docsSubmitted","false").equalsIgnoreCase("true")){
|
|
|
574 |
Intent i = new Intent(SplashScreen.this, PendingActivity.class);
|
|
|
575 |
startActivity(i);
|
|
|
576 |
}
|
|
|
577 |
else if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
|
|
|
578 |
Intent startActivityIntent=new Intent(SplashScreen.this, BasicInformation.class);
|
|
|
579 |
Intent intent = getIntent();
|
|
|
580 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
581 |
Uri uri = intent.getData();
|
|
|
582 |
startActivityIntent.setAction("31");
|
|
|
583 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
584 |
}
|
|
|
585 |
startActivity(startActivityIntent);
|
|
|
586 |
//startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
|
|
|
587 |
}
|
|
|
588 |
else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
|
|
|
589 |
Intent startActivityIntent=new Intent(SplashScreen.this, MobileNumber.class);
|
|
|
590 |
Intent intent = getIntent();
|
|
|
591 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
592 |
Uri uri = intent.getData();
|
|
|
593 |
startActivityIntent.setAction("31");
|
|
|
594 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
595 |
}
|
|
|
596 |
startActivity(startActivityIntent);
|
|
|
597 |
//startActivity(new Intent(SplashScreen.this, MobileNumber.class));
|
|
|
598 |
} else*/
|
|
|
599 |
if (idCheck != null) {
|
|
|
600 |
Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
|
|
|
601 |
Intent intent = getIntent();
|
|
|
602 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
603 |
Uri uri = intent.getData();
|
|
|
604 |
startActivityIntent.setAction("31");
|
|
|
605 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
606 |
}
|
|
|
607 |
startActivity(startActivityIntent);
|
|
|
608 |
}
|
|
|
609 |
else {
|
|
|
610 |
Intent startActivityIntent=new Intent(SplashScreen.this, LoginActivity.class);
|
|
|
611 |
Intent intent = getIntent();
|
|
|
612 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
613 |
Uri uri = intent.getData();
|
|
|
614 |
startActivityIntent.setAction("31");
|
|
|
615 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
616 |
}
|
|
|
617 |
startActivity(startActivityIntent);
|
|
|
618 |
|
|
|
619 |
}
|
|
|
620 |
}
|
|
|
621 |
}
|
| 24857 |
tejbeer |
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 |
}}
|
| 21480 |
rajender |
699 |
}
|