| 22131 |
rajender |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.Manifest;
|
| 24857 |
tejbeer |
4 |
import android.annotation.SuppressLint;
|
| 22131 |
rajender |
5 |
import android.app.AlertDialog;
|
| 22831 |
rajender |
6 |
import android.app.FragmentManager;
|
| 22131 |
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.IntentSender;
|
|
|
12 |
import android.content.SharedPreferences;
|
|
|
13 |
import android.content.pm.PackageManager;
|
|
|
14 |
import android.content.res.Configuration;
|
|
|
15 |
import android.net.ConnectivityManager;
|
|
|
16 |
import android.net.Uri;
|
|
|
17 |
import android.os.AsyncTask;
|
|
|
18 |
import android.os.Build;
|
|
|
19 |
import android.os.Bundle;
|
|
|
20 |
import android.support.v4.app.ActivityCompat;
|
|
|
21 |
import android.support.v4.content.ContextCompat;
|
| 24857 |
tejbeer |
22 |
|
|
|
23 |
import android.support.v7.app.AppCompatActivity;
|
| 22131 |
rajender |
24 |
import android.telephony.TelephonyManager;
|
|
|
25 |
import android.text.TextUtils;
|
|
|
26 |
import android.util.Log;
|
|
|
27 |
import android.view.Menu;
|
|
|
28 |
import android.view.MenuItem;
|
|
|
29 |
import android.view.View;
|
|
|
30 |
import android.widget.ImageButton;
|
|
|
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.auth.GoogleAuthException;
|
|
|
36 |
import com.google.android.gms.auth.GoogleAuthUtil;
|
|
|
37 |
import com.google.android.gms.auth.UserRecoverableAuthException;
|
|
|
38 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
39 |
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
|
40 |
import com.google.android.gms.common.Scopes;
|
|
|
41 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
42 |
import com.google.android.gms.common.api.ResultCallback;
|
|
|
43 |
import com.google.android.gms.common.api.Status;
|
|
|
44 |
import com.google.android.gms.plus.Plus;
|
|
|
45 |
import com.google.firebase.iid.FirebaseInstanceId;
|
|
|
46 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
47 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
48 |
import com.saholic.profittill.R;
|
|
|
49 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
|
|
50 |
import com.testin.agent.TestinAgent;
|
|
|
51 |
|
|
|
52 |
import org.apache.http.HttpEntity;
|
|
|
53 |
import org.apache.http.HttpResponse;
|
|
|
54 |
import org.apache.http.NameValuePair;
|
|
|
55 |
import org.apache.http.client.HttpClient;
|
|
|
56 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
57 |
import org.apache.http.client.methods.HttpGet;
|
|
|
58 |
import org.apache.http.client.methods.HttpPost;
|
|
|
59 |
import org.apache.http.entity.StringEntity;
|
|
|
60 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
61 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
62 |
import org.apache.http.util.EntityUtils;
|
|
|
63 |
import org.json.JSONException;
|
|
|
64 |
import org.json.JSONObject;
|
|
|
65 |
|
|
|
66 |
import java.io.IOException;
|
|
|
67 |
import java.io.UnsupportedEncodingException;
|
| 22831 |
rajender |
68 |
import java.net.URL;
|
| 22131 |
rajender |
69 |
import java.util.ArrayList;
|
|
|
70 |
import java.util.Date;
|
|
|
71 |
|
| 24857 |
tejbeer |
72 |
public class LoginActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
|
| 22131 |
rajender |
73 |
public GoogleApiClient mGoogleApiClient;
|
|
|
74 |
String scope = "oauth2:" + Scopes.PLUS_LOGIN +" " +Scopes.PLUS_ME + " " + Scopes.EMAIL;
|
|
|
75 |
private boolean mIntentInProgress;
|
|
|
76 |
private boolean mSignInClicked;
|
|
|
77 |
private ConnectionResult mConnectionResult;
|
|
|
78 |
private static final int RC_SIGN_IN = 0;
|
|
|
79 |
public static final int REQUEST_CODE_TOKEN_AUTH =1;
|
| 24857 |
tejbeer |
80 |
|
| 22131 |
rajender |
81 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
|
|
82 |
SharedPreferences userData;
|
|
|
83 |
SharedPreferences apiData;
|
|
|
84 |
SharedPreferences.Editor inviteDataEditor;
|
|
|
85 |
SharedPreferences inviteData;
|
|
|
86 |
boolean FLAG=false;
|
|
|
87 |
SharedPreferences.Editor userDataEditor;
|
|
|
88 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
89 |
SharedPreferences inviteD;
|
|
|
90 |
SharedPreferences.Editor inviteDEditor;
|
|
|
91 |
ImageButton googlelogin;
|
|
|
92 |
String mobile;
|
|
|
93 |
MixpanelAPI mixpanel;
|
|
|
94 |
FirebaseInstanceId fcm;
|
|
|
95 |
Context context;
|
|
|
96 |
String regId;
|
|
|
97 |
String msg = "";
|
|
|
98 |
public static final int READ_Token_PERMISSION=101;
|
|
|
99 |
static final String TAG = "Register Activity";
|
|
|
100 |
private boolean PermissionIngranted=false;
|
|
|
101 |
@Override
|
|
|
102 |
|
|
|
103 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
104 |
|
|
|
105 |
context = getApplicationContext();
|
|
|
106 |
mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
107 |
super.onCreate(savedInstanceState);
|
|
|
108 |
setContentView(R.layout.activity_login);
|
|
|
109 |
TestinAgent.init(this);
|
|
|
110 |
getSupportActionBar().hide();
|
|
|
111 |
requestToken();
|
|
|
112 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
|
|
113 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
|
|
114 |
userDataEditor = userData.edit();
|
|
|
115 |
apiSettingsEditor = apiData.edit();
|
|
|
116 |
inviteData = context.getSharedPreferences("Invite_Data", Context.MODE_PRIVATE);
|
|
|
117 |
inviteDataEditor = inviteData.edit();
|
|
|
118 |
inviteD = getApplicationContext().getSharedPreferences("Invite", MODE_PRIVATE);
|
|
|
119 |
inviteDEditor = inviteD.edit();
|
|
|
120 |
googlelogin =(ImageButton)findViewById(R.id.google_login_button);
|
|
|
121 |
if(getIntent().getAction()=="Login"){
|
|
|
122 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
123 |
nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
|
|
|
124 |
nameValuePairsGcm.add(new BasicNameValuePair("result","login"));
|
|
|
125 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp",UtilityFunctions.notificationDate()));
|
|
|
126 |
getIntent().getExtras().remove("cid");
|
|
|
127 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
else if(getIntent().getAction()=="31"){
|
|
|
131 |
String emailURL = String.valueOf(getIntent().getData());
|
|
|
132 |
Uri url = Uri.parse(emailURL);
|
|
|
133 |
String campaignId = url.getQueryParameter("campaign");
|
|
|
134 |
if(url.getQueryParameter("intent_type").equalsIgnoreCase("url")) {
|
|
|
135 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
136 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
137 |
t.send(new HitBuilders.EventBuilder()
|
|
|
138 |
.setCategory("Message/Email")
|
|
|
139 |
.setAction("Message/Email Opened For User Id " + UtilityFunctions.campaignUserId(url))
|
|
|
140 |
.setLabel("Campaign Id " + campaignId)
|
|
|
141 |
.build());
|
|
|
142 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
143 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", UtilityFunctions.campaignUserId(url)));
|
|
|
144 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
|
|
|
145 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
146 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_login"));
|
|
|
147 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
148 |
}
|
|
|
149 |
else{
|
|
|
150 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
151 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id","")));
|
|
|
152 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
|
|
|
153 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
154 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_login"));
|
|
|
155 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
159 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
160 |
t.setScreenName("Login Screen");
|
|
|
161 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
162 |
|
|
|
163 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
164 |
JSONObject props = new JSONObject();
|
|
|
165 |
try {
|
|
|
166 |
props.put("Screen", "Login Screen");
|
|
|
167 |
mixpanel.track("Login Page", props);
|
|
|
168 |
} catch (JSONException e) {
|
|
|
169 |
e.printStackTrace();
|
|
|
170 |
}
|
|
|
171 |
googlelogin.setOnClickListener(new View.OnClickListener() {
|
|
|
172 |
@Override
|
|
|
173 |
public void onClick(View v) {
|
|
|
174 |
if(isInternetOn()) {
|
|
|
175 |
if (TextUtils.isEmpty(regId)) {
|
|
|
176 |
regId = registerGCM();
|
|
|
177 |
Log.d("RegisterActivity", "GCM RegId: " + regId);
|
|
|
178 |
} else {
|
|
|
179 |
}
|
|
|
180 |
signInWithGplus();
|
|
|
181 |
}
|
|
|
182 |
else{
|
|
|
183 |
Toast.makeText(getApplicationContext(),"Sorry your internet is not working. Please check again",Toast.LENGTH_SHORT).show();
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
});
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
|
190 |
.addConnectionCallbacks(this)
|
|
|
191 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
192 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
193 |
}
|
|
|
194 |
public void requestToken(){
|
|
|
195 |
try{
|
|
|
196 |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
|
|
197 |
if (ContextCompat.checkSelfPermission(this,
|
|
|
198 |
Manifest.permission.GET_ACCOUNTS)
|
|
|
199 |
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
200 |
ActivityCompat.requestPermissions(LoginActivity.this,
|
|
|
201 |
new String[]{Manifest.permission.GET_ACCOUNTS},
|
|
|
202 |
READ_Token_PERMISSION);
|
|
|
203 |
} else {
|
|
|
204 |
PermissionIngranted = true;
|
|
|
205 |
}
|
|
|
206 |
} else {
|
|
|
207 |
PermissionIngranted = true;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
}
|
|
|
211 |
catch (Exception e){
|
|
|
212 |
e.printStackTrace();
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
private void signInWithGplus() {
|
|
|
217 |
if (!mGoogleApiClient.isConnecting()) {
|
|
|
218 |
mSignInClicked = true;
|
|
|
219 |
resolveSignInError();
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
@Override
|
|
|
224 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
225 |
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
226 |
getMenuInflater().inflate(R.menu.menu_login, menu);
|
|
|
227 |
return true;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
@Override
|
|
|
231 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
232 |
// Handle action bar item clicks here. The action bar will
|
|
|
233 |
// automatically handle clicks on the Home/Up button, so long
|
|
|
234 |
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
235 |
int id = item.getItemId();
|
|
|
236 |
|
|
|
237 |
//noinspection SimplifiableIfStatement
|
|
|
238 |
if (id == R.id.action_settings) {
|
|
|
239 |
return true;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
return super.onOptionsItemSelected(item);
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
/**
|
|
|
246 |
* Method to resolve any signin errors
|
|
|
247 |
* */
|
|
|
248 |
private void resolveSignInError() {
|
| 23185 |
rajender |
249 |
if (mConnectionResult != null) {
|
| 22131 |
rajender |
250 |
if (mConnectionResult.hasResolution()) {
|
|
|
251 |
try {
|
|
|
252 |
mIntentInProgress = true;
|
|
|
253 |
mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
|
| 22831 |
rajender |
254 |
}
|
|
|
255 |
catch (IntentSender.SendIntentException e) {
|
| 22131 |
rajender |
256 |
e.printStackTrace();
|
|
|
257 |
TestinAgent.uploadException(this,"Exception in Resolve sign in error", new Exception());
|
|
|
258 |
mIntentInProgress = false;
|
| 22831 |
rajender |
259 |
mGoogleApiClient.connect();
|
| 22131 |
rajender |
260 |
revokeGplusAccess();
|
|
|
261 |
}
|
|
|
262 |
}
|
| 23185 |
rajender |
263 |
}}
|
| 22131 |
rajender |
264 |
|
|
|
265 |
/**
|
|
|
266 |
* Revoking access from google
|
|
|
267 |
* */
|
|
|
268 |
private void revokeGplusAccess() {
|
|
|
269 |
if (mGoogleApiClient.isConnected()) {
|
|
|
270 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
271 |
Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient)
|
|
|
272 |
.setResultCallback(new ResultCallback<Status>() {
|
|
|
273 |
@Override
|
|
|
274 |
public void onResult(Status arg0) {
|
|
|
275 |
Log.e(TAG, "User access revoked!");
|
|
|
276 |
mGoogleApiClient.connect();
|
|
|
277 |
//updateUI(false);
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
});
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
@Override
|
|
|
285 |
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
286 |
super.onConfigurationChanged(newConfig);
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
protected void onStart() {
|
|
|
290 |
super.onStart();
|
|
|
291 |
mGoogleApiClient.connect();
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
protected void onStop() {
|
|
|
295 |
super.onStop();
|
|
|
296 |
if (mGoogleApiClient.isConnected()) {
|
|
|
297 |
mGoogleApiClient.disconnect();
|
|
|
298 |
|
|
|
299 |
}
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
@Override
|
|
|
303 |
public void onConnectionFailed(ConnectionResult result) {
|
|
|
304 |
if (!result.hasResolution()) {
|
|
|
305 |
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,0).show();
|
|
|
306 |
return;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
if (!mIntentInProgress) {
|
|
|
310 |
mConnectionResult = result;
|
|
|
311 |
if (mSignInClicked) {
|
|
|
312 |
resolveSignInError();
|
|
|
313 |
}
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
@Override
|
|
|
318 |
protected void onActivityResult(int requestCode, int responseCode,
|
|
|
319 |
Intent intent) {
|
|
|
320 |
if (requestCode == RC_SIGN_IN) {
|
|
|
321 |
if (responseCode != RESULT_OK) {
|
|
|
322 |
mSignInClicked = false;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
mIntentInProgress = false;
|
|
|
326 |
|
|
|
327 |
if (!mGoogleApiClient.isConnecting()) {
|
|
|
328 |
mGoogleApiClient.connect();
|
|
|
329 |
}
|
|
|
330 |
}
|
|
|
331 |
else if (requestCode==REQUEST_CODE_TOKEN_AUTH &&responseCode==RESULT_OK){
|
|
|
332 |
getAccessToken();
|
|
|
333 |
}
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
private void getAccessToken() {
|
|
|
337 |
new getToken().execute();
|
|
|
338 |
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
@Override
|
|
|
342 |
public void onConnectionSuspended(int arg0) {
|
|
|
343 |
mGoogleApiClient.connect();
|
|
|
344 |
}
|
|
|
345 |
@Override
|
|
|
346 |
public void onConnected(Bundle arg0) {
|
|
|
347 |
mSignInClicked=false;
|
|
|
348 |
getAccessToken();
|
|
|
349 |
}
|
|
|
350 |
private void showProgressDialog()
|
|
|
351 |
{
|
|
|
352 |
pDlg = new ProgressDialog(LoginActivity.this);
|
|
|
353 |
pDlg.setMessage("Logging In");
|
|
|
354 |
pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
355 |
pDlg.setCancelable(false);
|
|
|
356 |
pDlg.show();
|
|
|
357 |
|
|
|
358 |
}
|
|
|
359 |
private ProgressDialog pDlg = null;
|
|
|
360 |
class getToken extends AsyncTask<String, Integer, String> {
|
|
|
361 |
|
|
|
362 |
@Override
|
|
|
363 |
protected void onPreExecute() {
|
|
|
364 |
showProgressDialog();
|
|
|
365 |
}
|
|
|
366 |
@Override
|
|
|
367 |
protected String doInBackground(String... params) {
|
|
|
368 |
String registered=null;
|
|
|
369 |
String googletoken = null;
|
|
|
370 |
Bundle appActivities = new Bundle();
|
| 24857 |
tejbeer |
371 |
// appActivities.putString(GoogleAuthUtil.,"MainActivity");
|
| 22131 |
rajender |
372 |
try {
|
|
|
373 |
googletoken = GoogleAuthUtil.getToken(
|
|
|
374 |
LoginActivity.this,
|
|
|
375 |
Plus.AccountApi.getAccountName(mGoogleApiClient),
|
|
|
376 |
scope,appActivities);
|
|
|
377 |
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
|
|
|
378 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
379 |
String json = "";
|
|
|
380 |
JSONObject jsonObject = new JSONObject();
|
|
|
381 |
jsonObject.put("type", "GOOGLE");
|
|
|
382 |
jsonObject.put("token", googletoken);
|
|
|
383 |
json = jsonObject.toString();
|
| 22831 |
rajender |
384 |
HttpPost httppost = new HttpPost(apiData.getString("Web_Api_Login","http://app.profitmandi.com/apis/user/googleLogin"));
|
| 24857 |
tejbeer |
385 |
|
|
|
386 |
// HttpPost httppost = new HttpPost("http://192.168.120.52:8080/profitmandi-web/user/googleLogin");
|
| 22131 |
rajender |
387 |
StringEntity se = new StringEntity(json);
|
|
|
388 |
httppost.setEntity(se);
|
|
|
389 |
httppost.setHeader("Content-type", "application/json");
|
|
|
390 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
391 |
HttpEntity entity = response.getEntity();
|
|
|
392 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
393 |
JSONObject jobj= jObjGmail.getJSONObject("response");
|
|
|
394 |
registered=jobj.getString("registered");
|
|
|
395 |
if(!registered.equalsIgnoreCase(null)) {
|
|
|
396 |
String token = jobj.getString("token");
|
|
|
397 |
Log.d("token",token);
|
|
|
398 |
userDataEditor.putString("token", token);
|
| 22381 |
rajender |
399 |
userDataEditor.putString("email", Plus.AccountApi.getAccountName(mGoogleApiClient));
|
| 22131 |
rajender |
400 |
userDataEditor.putString("registered", registered);
|
|
|
401 |
userDataEditor.putString("type", "google");
|
|
|
402 |
userDataEditor.commit();
|
|
|
403 |
}
|
|
|
404 |
else{
|
|
|
405 |
|
|
|
406 |
}
|
|
|
407 |
}
|
|
|
408 |
else{
|
|
|
409 |
return "failure";
|
|
|
410 |
}
|
|
|
411 |
}
|
|
|
412 |
catch (IOException transientEx) {
|
|
|
413 |
Log.e("InputOutput", transientEx.toString());
|
|
|
414 |
|
|
|
415 |
}
|
|
|
416 |
catch (UserRecoverableAuthException e) {
|
|
|
417 |
Log.d("Here","Here " + e.getMessage());
|
|
|
418 |
Intent recover = e.getIntent();
|
|
|
419 |
startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
|
|
|
420 |
}
|
|
|
421 |
catch (GoogleAuthException authEx) {
|
|
|
422 |
Log.e("AuthEX", authEx.toString());
|
|
|
423 |
}
|
|
|
424 |
catch (Exception e) {
|
|
|
425 |
Log.e("Exception main", e.toString());
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
return registered;
|
|
|
429 |
}
|
|
|
430 |
@Override
|
|
|
431 |
protected void onPostExecute(String result){
|
|
|
432 |
super.onPostExecute(result);
|
|
|
433 |
|
|
|
434 |
try {
|
|
|
435 |
if (userData.getString("registered",null) == null) {
|
|
|
436 |
if(mGoogleApiClient.isConnected()) {
|
|
|
437 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
438 |
mGoogleApiClient.disconnect();
|
|
|
439 |
userDataEditor.clear().commit();
|
|
|
440 |
}
|
|
|
441 |
else{
|
|
|
442 |
userDataEditor.clear().commit();
|
|
|
443 |
}
|
|
|
444 |
if(pDlg!=null){
|
|
|
445 |
pDlg.dismiss();
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
else{
|
|
|
449 |
new AuthTokenChange().execute();
|
|
|
450 |
}
|
|
|
451 |
}
|
|
|
452 |
catch (Exception e){
|
|
|
453 |
e.printStackTrace();
|
|
|
454 |
}
|
|
|
455 |
}}
|
| 22381 |
rajender |
456 |
class AuthTokenChange extends AsyncTask<String, Integer, String> {
|
| 22131 |
rajender |
457 |
|
|
|
458 |
@Override
|
|
|
459 |
protected void onPreExecute() {
|
|
|
460 |
|
|
|
461 |
super.onPreExecute();
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
@Override
|
|
|
465 |
protected String doInBackground(String... params) {
|
|
|
466 |
try {
|
|
|
467 |
HttpClient httpclient = new DefaultHttpClient();
|
| 22831 |
rajender |
468 |
HttpGet httpget = new HttpGet(apiData.getString("Web_Api_Tokendetail","http://app.profitmandi.com/apis/user/detail/token"));
|
| 24857 |
tejbeer |
469 |
//HttpGet httpget = new HttpGet("http://192.168.120.52:8080/profitmandi-web/user/detail/token");
|
| 22131 |
rajender |
470 |
httpget.setHeader("Auth-Token", userData.getString("token", ""));
|
|
|
471 |
HttpResponse response = httpclient.execute(httpget);
|
|
|
472 |
HttpEntity entity = response.getEntity();
|
|
|
473 |
int status = response.getStatusLine().getStatusCode();
|
|
|
474 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
475 |
Log.d("Json",String.valueOf(jObjGmail));
|
|
|
476 |
return String.valueOf(jObjGmail);
|
|
|
477 |
|
|
|
478 |
} catch (UnsupportedEncodingException e) {
|
|
|
479 |
e.printStackTrace();
|
|
|
480 |
} catch (IOException e) {
|
|
|
481 |
e.printStackTrace();
|
|
|
482 |
} catch (JSONException e) {
|
|
|
483 |
e.printStackTrace();
|
|
|
484 |
}
|
|
|
485 |
return null;
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
@Override
|
|
|
489 |
protected void onPostExecute(String result) {
|
|
|
490 |
super.onPostExecute(result);
|
|
|
491 |
try {
|
|
|
492 |
JSONObject jsonObject = new JSONObject(result);
|
|
|
493 |
JSONObject jobj=jsonObject.getJSONObject("response");
|
|
|
494 |
String userStatus=jobj.getString("userStatus");
|
|
|
495 |
userDataEditor.putString("userStatus",userStatus);
|
|
|
496 |
userDataEditor.commit();
|
|
|
497 |
if(!(userData.getString("userStatus","").equals("notRegistered"))) {
|
|
|
498 |
String user_id = jobj.getString("userId");
|
|
|
499 |
userDataEditor.putString("id", user_id);
|
|
|
500 |
userDataEditor.commit();
|
|
|
501 |
if(!(userData.getString("id", "").equals(""))){
|
|
|
502 |
UtilityFunctions utf = new UtilityFunctions();
|
|
|
503 |
new pushApkData().execute(utf.getDeviceInformation(getApplicationContext()));
|
| 22831 |
rajender |
504 |
Intent i = new Intent(LoginActivity.this,MainActivity.class);
|
|
|
505 |
i.putExtra("displayView","0");
|
|
|
506 |
startActivity(i);
|
| 22131 |
rajender |
507 |
}
|
|
|
508 |
else{
|
|
|
509 |
Intent i = new Intent(LoginActivity.this,MainActivity.class);
|
|
|
510 |
i.putExtra("displayView","0");
|
|
|
511 |
startActivity(i);
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
else{
|
|
|
515 |
Intent i = new Intent(LoginActivity.this,MainActivity.class);
|
|
|
516 |
i.putExtra("displayView","0");
|
|
|
517 |
startActivity(i);
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
}
|
|
|
521 |
catch (JSONException e) {
|
|
|
522 |
e.printStackTrace();
|
|
|
523 |
}
|
|
|
524 |
}
|
|
|
525 |
}
|
|
|
526 |
boolean doubleBackToExitPressedOnce = false;
|
|
|
527 |
@Override
|
|
|
528 |
public void onBackPressed() {
|
|
|
529 |
new AlertDialog.Builder(this)
|
| 24857 |
tejbeer |
530 |
.setIcon(R.drawable.exitsymbol)
|
| 22131 |
rajender |
531 |
.setTitle("Exit!")
|
|
|
532 |
.setMessage("Are you sure you want to close?")
|
|
|
533 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
|
|
|
534 |
{
|
|
|
535 |
@Override
|
|
|
536 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
537 |
Intent startMain = new Intent(Intent.ACTION_MAIN);
|
|
|
538 |
startMain.addCategory(Intent.CATEGORY_HOME);
|
|
|
539 |
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
540 |
startActivity(startMain);
|
|
|
541 |
}
|
|
|
542 |
})
|
|
|
543 |
.setNegativeButton("No", null)
|
|
|
544 |
.show();
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
private void registerInBackground() {
|
|
|
548 |
new AsyncTask<Void, Void, String>() {
|
|
|
549 |
@Override
|
|
|
550 |
protected String doInBackground(Void... params) {
|
|
|
551 |
|
|
|
552 |
if (fcm == null) {
|
|
|
553 |
regId =FirebaseInstanceId.getInstance().getToken();
|
|
|
554 |
Log.d("RegisterActivity", "registerInBackground - regId: "
|
|
|
555 |
+ regId);
|
|
|
556 |
msg = "Device registered";
|
|
|
557 |
}
|
|
|
558 |
Log.d("RegisterActivity", "AsyncTask completed: " + msg);
|
|
|
559 |
return msg;
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
@Override
|
|
|
563 |
protected void onPostExecute(String msg) {
|
|
|
564 |
}
|
|
|
565 |
}.execute(null, null, null);
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
public String registerGCM() {
|
|
|
569 |
regId = getRegistrationId(context);
|
|
|
570 |
registerInBackground();
|
|
|
571 |
return regId;
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
private String getRegistrationId(Context context) {
|
|
|
575 |
|
|
|
576 |
String registrationId = userData.getString("gcm_regid", "");
|
|
|
577 |
if (registrationId.isEmpty()) {
|
|
|
578 |
Log.i(TAG, "Registration not found.");
|
|
|
579 |
return "";
|
|
|
580 |
}
|
|
|
581 |
return registrationId;
|
|
|
582 |
}
|
|
|
583 |
|
|
|
584 |
class gcmPushData extends AsyncTask<String, Integer, String> {
|
|
|
585 |
|
|
|
586 |
@Override
|
|
|
587 |
protected void onPreExecute() {
|
|
|
588 |
super.onPreExecute();
|
|
|
589 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
590 |
MixpanelAPI.People people = mixpanel.getPeople();
|
|
|
591 |
JSONObject props = new JSONObject();
|
|
|
592 |
try {
|
|
|
593 |
mixpanel.identify(userData.getString("id",null));
|
|
|
594 |
people.identify(userData.getString("id",null));
|
|
|
595 |
props.put("Screen", "Logged In");
|
|
|
596 |
people.set("$last_login",new Date());
|
|
|
597 |
people.set("user_id" , userData.getString("id",null));
|
|
|
598 |
mixpanel.track("Successfully Logged In", props);
|
|
|
599 |
} catch (JSONException e) {
|
|
|
600 |
e.printStackTrace();
|
|
|
601 |
}
|
|
|
602 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
603 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
604 |
t.set("&uid",userData.getString("id",null));
|
|
|
605 |
t.send(new HitBuilders.EventBuilder()
|
|
|
606 |
.setCategory("Login ")
|
|
|
607 |
.setAction("Login Successful")
|
|
|
608 |
.setLabel("Successful for User" +userData.getString("id",null))
|
|
|
609 |
.build());
|
|
|
610 |
}
|
|
|
611 |
|
| 24857 |
tejbeer |
612 |
@SuppressLint("MissingPermission")
|
| 22131 |
rajender |
613 |
@Override
|
|
|
614 |
protected String doInBackground(String... arg0) {
|
|
|
615 |
String id=null;
|
|
|
616 |
try {
|
|
|
617 |
HttpClient httpclient = new DefaultHttpClient();
|
| 22831 |
rajender |
618 |
HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url","http://api.profittill.com/gcm_users/add"));
|
| 22131 |
rajender |
619 |
//HttpPost httppost = new HttpPost(ProfitTillConstants.gcm_url);
|
|
|
620 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
621 |
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
622 |
nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid",regId));
|
|
|
623 |
nameValuePairsGcm.add(new BasicNameValuePair("imeinumber",telephonyManager.getDeviceId()));
|
|
|
624 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id", null)));
|
|
|
625 |
nameValuePairsGcm.add(new BasicNameValuePair("notification_type","fcm"));
|
|
|
626 |
nameValuePairsGcm.add(new BasicNameValuePair("device_message",arg0[0]));
|
|
|
627 |
nameValuePairsGcm.add(new BasicNameValuePair("androidid",UtilityFunctions.androidId(LoginActivity.this)));
|
|
|
628 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
629 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
|
|
|
630 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
631 |
HttpEntity entity = response.getEntity();
|
|
|
632 |
int status = response.getStatusLine().getStatusCode();
|
|
|
633 |
|
|
|
634 |
if(status == 200){
|
|
|
635 |
Log.d("ResponseCode GCM",status+"");
|
|
|
636 |
userDataEditor.putString("fcm_token_sent", "true");
|
|
|
637 |
userDataEditor.commit();
|
|
|
638 |
} else {
|
|
|
639 |
Log.d("ResponseCode GCM",status+"");
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
nameValuePairsGcm.clear();
|
|
|
643 |
Log.e("pass 1", "connection success ");
|
|
|
644 |
} catch (Exception e) {
|
|
|
645 |
Log.e("Fail 1", e.toString());
|
|
|
646 |
|
|
|
647 |
}
|
|
|
648 |
return id;
|
|
|
649 |
}
|
|
|
650 |
|
|
|
651 |
@Override
|
|
|
652 |
protected void onPostExecute(String result) {
|
|
|
653 |
super.onPostExecute(result);
|
|
|
654 |
if(pDlg!=null){
|
|
|
655 |
pDlg.dismiss();
|
|
|
656 |
}
|
|
|
657 |
userDataEditor.putString("gcm_regid", regId);
|
|
|
658 |
userDataEditor.commit();
|
|
|
659 |
|
|
|
660 |
String check = userData.getString("message","");
|
|
|
661 |
/* if(userData.getString("docsSubmitted","").equalsIgnoreCase("true")){
|
|
|
662 |
// Intent i = new Intent(LoginActivity.this, PendingActivity.class);
|
|
|
663 |
// startActivity(i);
|
|
|
664 |
}
|
|
|
665 |
else if(userData.getString("referralCodeRequired","").equalsIgnoreCase("true")){
|
|
|
666 |
Log.d("In if","in if" +inviteD.getString("referrerCode","").equalsIgnoreCase("") + inviteD .getString("referrerCode","") );
|
|
|
667 |
//Intent i = new Intent(LoginActivity.this, BasicInformation.class);
|
|
|
668 |
//startActivity(i);
|
|
|
669 |
}
|
|
|
670 |
else if(check.equalsIgnoreCase("true")){
|
|
|
671 |
Log.d("In if","in else");
|
|
|
672 |
//Intent i = new Intent(LoginActivity.this, MobileNumber.class);
|
|
|
673 |
// i.putExtra("displayView", "7");
|
|
|
674 |
// startActivity(i);
|
|
|
675 |
}
|
|
|
676 |
else{*/
|
| 22831 |
rajender |
677 |
|
| 22131 |
rajender |
678 |
}
|
|
|
679 |
}
|
|
|
680 |
|
|
|
681 |
|
|
|
682 |
public final boolean isInternetOn() {
|
|
|
683 |
|
|
|
684 |
ConnectivityManager connection =
|
|
|
685 |
(ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
686 |
|
|
|
687 |
if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
688 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
689 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
690 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
691 |
|
|
|
692 |
return true;
|
|
|
693 |
|
|
|
694 |
} else if (
|
|
|
695 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
696 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
697 |
|
|
|
698 |
return false;
|
|
|
699 |
}
|
|
|
700 |
return false;
|
|
|
701 |
}
|
|
|
702 |
class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
|
|
703 |
|
|
|
704 |
@Override
|
|
|
705 |
protected void onPreExecute() {
|
|
|
706 |
super.onPreExecute();
|
|
|
707 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
708 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
709 |
t.send(new HitBuilders.EventBuilder()
|
|
|
710 |
.setCategory("Notification")
|
|
|
711 |
.setAction("Notification Opened Login")
|
|
|
712 |
.setLabel("For User Id " + userData.getString("id","0"))
|
|
|
713 |
.build());
|
|
|
714 |
}
|
|
|
715 |
|
|
|
716 |
@Override
|
|
|
717 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
|
|
718 |
|
|
|
719 |
try {
|
|
|
720 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
721 |
HttpPost httppost = new HttpPost(apiData.getString("notication.data.url","http://api.profittill.com/pushnotifications/add"));
|
|
|
722 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
723 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
724 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
725 |
HttpEntity entity = response.getEntity();
|
|
|
726 |
int status = response.getStatusLine().getStatusCode();
|
|
|
727 |
|
|
|
728 |
if(status == 200){
|
|
|
729 |
Log.d("Notification Opened","Notication opened and sent to server");
|
|
|
730 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
731 |
} else {
|
|
|
732 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
nameValuePairsGcm.clear();
|
|
|
736 |
Log.e("pass 1", "connection success ");
|
|
|
737 |
} catch (Exception e) {
|
|
|
738 |
Log.e("Fail 1", e.toString());
|
|
|
739 |
|
|
|
740 |
}
|
|
|
741 |
return "success";
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
@Override
|
|
|
745 |
protected void onPostExecute(String result) {
|
|
|
746 |
super.onPostExecute(result);
|
|
|
747 |
Log.d("Notification Opened","Notication opened and login page");
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
|
|
|
751 |
class pushApkData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
|
|
752 |
|
|
|
753 |
@Override
|
|
|
754 |
protected void onPreExecute() {
|
|
|
755 |
super.onPreExecute();
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
@Override
|
|
|
759 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
|
|
760 |
try {
|
|
|
761 |
HttpClient httpclient = new DefaultHttpClient();
|
| 22831 |
rajender |
762 |
HttpPost httppost = new HttpPost(apiData.getString("devices_info","http://api.profittill.com/devices/add"));
|
| 24857 |
tejbeer |
763 |
// HttpPost httppost = new HttpPost("http://192.168.120.52:8080/profitmandi-web/devices/add");
|
| 22131 |
rajender |
764 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
765 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
766 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
767 |
HttpEntity entity = response.getEntity();
|
|
|
768 |
int status = response.getStatusLine().getStatusCode();
|
|
|
769 |
if(status == 200){
|
|
|
770 |
return "success";
|
|
|
771 |
} else {
|
|
|
772 |
return "failure";
|
|
|
773 |
}
|
|
|
774 |
}
|
|
|
775 |
catch (Exception e) {
|
|
|
776 |
e.printStackTrace();
|
|
|
777 |
return null;
|
|
|
778 |
}
|
|
|
779 |
}
|
|
|
780 |
@Override
|
|
|
781 |
protected void onPostExecute(String result) {
|
|
|
782 |
super.onPostExecute(result);
|
|
|
783 |
if(userData.getString("fcm_token_sent","false").equalsIgnoreCase("false")){
|
|
|
784 |
new gcmPushData().execute(msg);
|
|
|
785 |
}
|
|
|
786 |
|
|
|
787 |
}
|
|
|
788 |
}
|
|
|
789 |
}
|
|
|
790 |
|