| 14792 |
manas |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
| 21170 |
rajender |
3 |
import android.Manifest;
|
|
|
4 |
import android.annotation.TargetApi;
|
|
|
5 |
import android.app.Activity;
|
| 14792 |
manas |
6 |
import android.app.AlertDialog;
|
|
|
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.PackageInfo;
|
|
|
14 |
import android.content.pm.PackageManager;
|
|
|
15 |
import android.content.res.Configuration;
|
| 15356 |
manas |
16 |
import android.net.ConnectivityManager;
|
| 18082 |
manas |
17 |
import android.net.Uri;
|
| 15356 |
manas |
18 |
import android.os.AsyncTask;
|
| 21170 |
rajender |
19 |
import android.os.Build;
|
| 15356 |
manas |
20 |
import android.os.Bundle;
|
| 21170 |
rajender |
21 |
import android.support.annotation.NonNull;
|
|
|
22 |
import android.support.v4.app.ActivityCompat;
|
|
|
23 |
import android.support.v4.content.ContextCompat;
|
| 14792 |
manas |
24 |
import android.support.v7.app.ActionBarActivity;
|
| 21170 |
rajender |
25 |
import android.support.v7.app.AppCompatActivity;
|
| 14792 |
manas |
26 |
import android.telephony.TelephonyManager;
|
|
|
27 |
import android.text.TextUtils;
|
|
|
28 |
import android.util.Log;
|
|
|
29 |
import android.view.Menu;
|
|
|
30 |
import android.view.MenuItem;
|
|
|
31 |
import android.view.View;
|
|
|
32 |
import android.widget.EditText;
|
|
|
33 |
import android.widget.ImageButton;
|
|
|
34 |
import android.widget.Toast;
|
|
|
35 |
|
|
|
36 |
import com.facebook.Request;
|
|
|
37 |
import com.facebook.RequestAsyncTask;
|
|
|
38 |
import com.facebook.Response;
|
|
|
39 |
import com.facebook.Session;
|
|
|
40 |
import com.facebook.SessionState;
|
| 21170 |
rajender |
41 |
import com.facebook.Settings;
|
| 14792 |
manas |
42 |
import com.facebook.UiLifecycleHelper;
|
|
|
43 |
import com.facebook.model.GraphUser;
|
|
|
44 |
import com.facebook.widget.LoginButton;
|
|
|
45 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
46 |
import com.google.android.gms.analytics.Tracker;
|
|
|
47 |
import com.google.android.gms.auth.GoogleAuthException;
|
|
|
48 |
import com.google.android.gms.auth.GoogleAuthUtil;
|
|
|
49 |
import com.google.android.gms.auth.UserRecoverableAuthException;
|
|
|
50 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
51 |
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
|
52 |
import com.google.android.gms.common.Scopes;
|
|
|
53 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
54 |
import com.google.android.gms.common.api.ResultCallback;
|
|
|
55 |
import com.google.android.gms.common.api.Status;
|
|
|
56 |
import com.google.android.gms.plus.Plus;
|
|
|
57 |
import com.google.android.gms.plus.model.people.Person;
|
| 21170 |
rajender |
58 |
import com.google.firebase.iid.FirebaseInstanceId;
|
| 14792 |
manas |
59 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
60 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
61 |
import com.saholic.profittill.R;
|
| 14991 |
manas |
62 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
| 14792 |
manas |
63 |
import com.testin.agent.TestinAgent;
|
|
|
64 |
|
|
|
65 |
import org.apache.http.HttpEntity;
|
|
|
66 |
import org.apache.http.HttpResponse;
|
|
|
67 |
import org.apache.http.NameValuePair;
|
|
|
68 |
import org.apache.http.client.HttpClient;
|
|
|
69 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
70 |
import org.apache.http.client.methods.HttpPost;
|
|
|
71 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
72 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
73 |
import org.apache.http.util.EntityUtils;
|
|
|
74 |
import org.json.JSONException;
|
|
|
75 |
import org.json.JSONObject;
|
|
|
76 |
|
|
|
77 |
import java.io.IOException;
|
|
|
78 |
import java.util.ArrayList;
|
|
|
79 |
import java.util.Arrays;
|
|
|
80 |
import java.util.Date;
|
|
|
81 |
import java.util.regex.Matcher;
|
|
|
82 |
import java.util.regex.Pattern;
|
|
|
83 |
|
|
|
84 |
public class LoginActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
|
|
|
85 |
public GoogleApiClient mGoogleApiClient;
|
|
|
86 |
String scope = "oauth2:" + Scopes.PLUS_LOGIN;
|
|
|
87 |
private UiLifecycleHelper uiHelper;
|
|
|
88 |
private boolean mIntentInProgress;
|
|
|
89 |
private boolean mSignInClicked;
|
|
|
90 |
private ConnectionResult mConnectionResult;
|
|
|
91 |
private static final int RC_SIGN_IN = 0;
|
|
|
92 |
public static final int REQUEST_CODE_TOKEN_AUTH =1;
|
|
|
93 |
ArrayList<NameValuePair> nameValuePairs;
|
|
|
94 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
|
|
95 |
SharedPreferences userData;
|
|
|
96 |
SharedPreferences apiData;
|
|
|
97 |
SharedPreferences.Editor inviteDataEditor;
|
|
|
98 |
SharedPreferences inviteData;
|
|
|
99 |
boolean FLAG=false;
|
|
|
100 |
SharedPreferences.Editor userDataEditor;
|
|
|
101 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
102 |
SharedPreferences inviteD;
|
|
|
103 |
SharedPreferences.Editor inviteDEditor;
|
|
|
104 |
LoginButton fb_button;
|
|
|
105 |
ImageButton facebookLogin,googlelogin;
|
|
|
106 |
String mobile;
|
|
|
107 |
MixpanelAPI mixpanel;
|
| 21170 |
rajender |
108 |
FirebaseInstanceId fcm;
|
| 14792 |
manas |
109 |
Context context;
|
|
|
110 |
String regId;
|
| 15588 |
manas |
111 |
String msg = "";
|
| 21170 |
rajender |
112 |
public static final int READ_Token_PERMISSION=101;
|
| 14792 |
manas |
113 |
public static final String REG_ID = "regId";
|
|
|
114 |
private static final String APP_VERSION = "appVersion";
|
|
|
115 |
static final String TAG = "Register Activity";
|
| 21170 |
rajender |
116 |
private boolean PermissionIngranted=false;
|
| 14792 |
manas |
117 |
@Override
|
|
|
118 |
|
|
|
119 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
120 |
|
|
|
121 |
context = getApplicationContext();
|
|
|
122 |
mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
123 |
super.onCreate(savedInstanceState);
|
|
|
124 |
uiHelper = new UiLifecycleHelper(this, statusCallback);
|
|
|
125 |
uiHelper.onCreate(savedInstanceState);
|
|
|
126 |
setContentView(R.layout.activity_login);
|
|
|
127 |
TestinAgent.init(this);
|
|
|
128 |
getSupportActionBar().hide();
|
| 21170 |
rajender |
129 |
Settings.sdkInitialize(getApplicationContext());
|
|
|
130 |
requestToken();
|
| 14792 |
manas |
131 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
|
|
132 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
|
|
133 |
userDataEditor = userData.edit();
|
|
|
134 |
apiSettingsEditor = apiData.edit();
|
|
|
135 |
inviteData = context.getSharedPreferences("Invite_Data", Context.MODE_PRIVATE);
|
|
|
136 |
inviteDataEditor = inviteData.edit();
|
|
|
137 |
inviteD = getApplicationContext().getSharedPreferences("Invite", MODE_PRIVATE);
|
|
|
138 |
inviteDEditor = inviteD.edit();
|
|
|
139 |
facebookLogin =(ImageButton)findViewById(R.id.facebook_login_button);
|
|
|
140 |
googlelogin =(ImageButton)findViewById(R.id.google_login_button);
|
|
|
141 |
if(getIntent().getAction()=="Login"){
|
|
|
142 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
143 |
nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
|
|
|
144 |
nameValuePairsGcm.add(new BasicNameValuePair("result","login"));
|
| 15356 |
manas |
145 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp",UtilityFunctions.notificationDate()));
|
| 14792 |
manas |
146 |
getIntent().getExtras().remove("cid");
|
|
|
147 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
| 18082 |
manas |
148 |
}else if(getIntent().getAction()=="31"){
|
|
|
149 |
String emailURL = String.valueOf(getIntent().getData());
|
|
|
150 |
Uri url = Uri.parse(emailURL);
|
|
|
151 |
String campaignId = url.getQueryParameter("campaign");
|
|
|
152 |
if(url.getQueryParameter("intent_type").equalsIgnoreCase("url")) {
|
|
|
153 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
154 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
155 |
t.send(new HitBuilders.EventBuilder()
|
|
|
156 |
.setCategory("Message/Email")
|
|
|
157 |
.setAction("Message/Email Opened For User Id " + UtilityFunctions.campaignUserId(url))
|
|
|
158 |
.setLabel("Campaign Id " + campaignId)
|
|
|
159 |
.build());
|
|
|
160 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
161 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", UtilityFunctions.campaignUserId(url)));
|
|
|
162 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
|
|
|
163 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
164 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_login"));
|
|
|
165 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
166 |
}else{
|
|
|
167 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
168 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id","")));
|
|
|
169 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
|
|
|
170 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
171 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_login"));
|
|
|
172 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
173 |
}
|
| 14792 |
manas |
174 |
}
|
|
|
175 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
176 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
177 |
t.setScreenName("Login Screen");
|
|
|
178 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
179 |
|
|
|
180 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
181 |
JSONObject props = new JSONObject();
|
|
|
182 |
try {
|
|
|
183 |
props.put("Screen", "Login Screen");
|
|
|
184 |
mixpanel.track("Login Page", props);
|
|
|
185 |
} catch (JSONException e) {
|
|
|
186 |
e.printStackTrace();
|
|
|
187 |
}
|
|
|
188 |
if (Session.getActiveSession() != null) {
|
|
|
189 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
Session.setActiveSession(null);
|
|
|
194 |
|
|
|
195 |
fb_button=(LoginButton)findViewById(R.id.facebook_class_login_button);
|
|
|
196 |
|
|
|
197 |
fb_button.setReadPermissions(Arrays.asList("email"));
|
|
|
198 |
|
|
|
199 |
facebookLogin.setOnClickListener(new View.OnClickListener() {
|
|
|
200 |
@Override
|
|
|
201 |
public void onClick(View v) {
|
|
|
202 |
if(isInternetOn()) {
|
|
|
203 |
if (TextUtils.isEmpty(regId)) {
|
|
|
204 |
regId = registerGCM();
|
|
|
205 |
} else {
|
|
|
206 |
|
|
|
207 |
}
|
|
|
208 |
fb_button.performClick();
|
| 21170 |
rajender |
209 |
|
|
|
210 |
|
| 14792 |
manas |
211 |
/*if(!(inviteData.getBoolean("inviteCodeRequired",true))) {
|
|
|
212 |
fb_button.performClick();
|
|
|
213 |
}else {
|
|
|
214 |
if (apiData.getString("profitmandi.invitation", "false").equalsIgnoreCase("true")) {
|
|
|
215 |
if (inviteD.getString("invite_added", "").equalsIgnoreCase("added")) {
|
|
|
216 |
fb_button.performClick();
|
|
|
217 |
} else {
|
|
|
218 |
String referalCode1 = referralCode.getText().toString();
|
|
|
219 |
if (referalCode1.isEmpty()) {
|
|
|
220 |
if (Session.getActiveSession() != null) {
|
|
|
221 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
222 |
}
|
|
|
223 |
Session.setActiveSession(null);
|
|
|
224 |
inviteError.setVisibility(View.VISIBLE);
|
|
|
225 |
inviteError.setText(apiData.getString("invite.message", ""));
|
|
|
226 |
|
|
|
227 |
} else {
|
|
|
228 |
for (String s : invitationCodeList) {
|
|
|
229 |
if (referalCode1.equalsIgnoreCase(s)) {
|
|
|
230 |
FLAG = true;
|
|
|
231 |
break;
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
if (FLAG) {
|
|
|
235 |
if (Session.getActiveSession() != null) {
|
|
|
236 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
237 |
}
|
|
|
238 |
Session.setActiveSession(null);
|
|
|
239 |
fb_button.performClick();
|
|
|
240 |
} else {
|
|
|
241 |
if (Session.getActiveSession() != null) {
|
|
|
242 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
243 |
}
|
|
|
244 |
Session.setActiveSession(null);
|
|
|
245 |
inviteError.setVisibility(View.VISIBLE);
|
|
|
246 |
inviteError.setText(apiData.getString("invite.error.message", ""));
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
} else if (apiData.getString("profitmandi.invitation", "").equalsIgnoreCase("false")) {
|
|
|
251 |
fb_button.performClick();
|
|
|
252 |
} else {
|
|
|
253 |
}
|
|
|
254 |
}*/
|
|
|
255 |
}
|
|
|
256 |
else{
|
|
|
257 |
Toast.makeText(getApplicationContext(),"Sorry your internet is not working. Please check again",Toast.LENGTH_SHORT).show();
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
}
|
|
|
261 |
});
|
|
|
262 |
googlelogin.setOnClickListener(new View.OnClickListener() {
|
|
|
263 |
@Override
|
|
|
264 |
public void onClick(View v) {
|
|
|
265 |
if(isInternetOn()) {
|
|
|
266 |
if (TextUtils.isEmpty(regId)) {
|
|
|
267 |
regId = registerGCM();
|
|
|
268 |
Log.d("RegisterActivity", "GCM RegId: " + regId);
|
|
|
269 |
} else {
|
|
|
270 |
}
|
|
|
271 |
signInWithGplus();
|
|
|
272 |
/*if(!(inviteData.getBoolean("inviteCodeRequired",true))) {
|
|
|
273 |
signInWithGplus();
|
|
|
274 |
}else {
|
|
|
275 |
if (apiData.getString("profitmandi.invitation", "false").equalsIgnoreCase("true")) {
|
|
|
276 |
if (inviteD.getString("invite_added", "").equalsIgnoreCase("added")) {
|
|
|
277 |
signInWithGplus();
|
|
|
278 |
} else {
|
|
|
279 |
String referalCode1 = referralCode.getText().toString();
|
|
|
280 |
if (referalCode1.isEmpty()) {
|
|
|
281 |
inviteError.setVisibility(View.VISIBLE);
|
|
|
282 |
inviteError.setText(apiData.getString("invite.error.message", ""));
|
|
|
283 |
} else {
|
|
|
284 |
for (String s : invitationCodeList) {
|
|
|
285 |
if (referalCode1.equalsIgnoreCase(s)) {
|
|
|
286 |
FLAG = true;
|
|
|
287 |
break;
|
|
|
288 |
}
|
|
|
289 |
}
|
|
|
290 |
if (FLAG) {
|
|
|
291 |
signInWithGplus();
|
|
|
292 |
} else {
|
|
|
293 |
inviteError.setVisibility(View.VISIBLE);
|
|
|
294 |
inviteError.setText(apiData.getString("invite.error.message", ""));
|
|
|
295 |
|
|
|
296 |
}
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
} else if (apiData.getString("profitmandi.invitation", "").equalsIgnoreCase("false")) {
|
|
|
300 |
signInWithGplus();
|
|
|
301 |
}
|
|
|
302 |
}*/
|
|
|
303 |
}
|
|
|
304 |
else{
|
|
|
305 |
Toast.makeText(getApplicationContext(),"Sorry your internet is not working. Please check again",Toast.LENGTH_SHORT).show();
|
|
|
306 |
}
|
|
|
307 |
}
|
|
|
308 |
});
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
|
312 |
.addConnectionCallbacks(this)
|
|
|
313 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
314 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
| 21170 |
rajender |
315 |
|
| 14792 |
manas |
316 |
}
|
| 21170 |
rajender |
317 |
|
|
|
318 |
|
|
|
319 |
public void requestToken(){
|
|
|
320 |
try{
|
|
|
321 |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
|
|
322 |
if (ContextCompat.checkSelfPermission(this,
|
|
|
323 |
Manifest.permission.GET_ACCOUNTS)
|
|
|
324 |
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
325 |
ActivityCompat.requestPermissions(LoginActivity.this,
|
|
|
326 |
new String[]{Manifest.permission.GET_ACCOUNTS},
|
|
|
327 |
READ_Token_PERMISSION);
|
|
|
328 |
} else {
|
|
|
329 |
PermissionIngranted = true;
|
|
|
330 |
}
|
|
|
331 |
} else {
|
|
|
332 |
PermissionIngranted = true;
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
}catch (Exception e){
|
|
|
336 |
e.printStackTrace();
|
|
|
337 |
}
|
|
|
338 |
}
|
|
|
339 |
|
| 14792 |
manas |
340 |
private void signInWithGplus() {
|
|
|
341 |
if (!mGoogleApiClient.isConnecting()) {
|
|
|
342 |
mSignInClicked = true;
|
|
|
343 |
resolveSignInError();
|
|
|
344 |
}
|
|
|
345 |
}
|
|
|
346 |
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
|
|
|
347 |
@Override
|
|
|
348 |
public void call(final Session session, SessionState state,
|
|
|
349 |
Exception exception) {
|
|
|
350 |
if (state.isOpened()) {
|
|
|
351 |
nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
352 |
nameValuePairs.add(new BasicNameValuePair("type","facebook"));
|
|
|
353 |
nameValuePairs.add(new BasicNameValuePair("token",session.getAccessToken()+""));
|
|
|
354 |
Request mRequest = Request.newMeRequest(session,new Request.GraphUserCallback() {
|
|
|
355 |
@Override
|
|
|
356 |
public void onCompleted(GraphUser graphUser, Response response) {
|
|
|
357 |
if(response.getError()==null)
|
|
|
358 |
{
|
|
|
359 |
nameValuePairs.add(new BasicNameValuePair("id",graphUser.getId()));
|
|
|
360 |
nameValuePairs.add(new BasicNameValuePair("name",graphUser.getName()));
|
|
|
361 |
//nameValuePairs.add(new BasicNameValuePair("mobile_number",mobile));
|
|
|
362 |
// nameValuePairs.add(new BasicNameValuePair("referrer",referalCode.getText().toString()));
|
|
|
363 |
Log.d("Invite Code Boolean","Boolean" +inviteData.getBoolean("inviteCodeRequired",true));
|
|
|
364 |
if(!(inviteData.getBoolean("inviteCodeRequired",true))) {
|
|
|
365 |
nameValuePairs.add(new BasicNameValuePair("utm_source",inviteData.getString("utm_source","")));
|
|
|
366 |
nameValuePairs.add(new BasicNameValuePair("utm_medium",inviteData.getString("utm_medium","")));
|
|
|
367 |
nameValuePairs.add(new BasicNameValuePair("utm_content",inviteData.getString("utm_content","")));
|
|
|
368 |
nameValuePairs.add(new BasicNameValuePair("utm_term",inviteData.getString("utm_term","")));
|
|
|
369 |
nameValuePairs.add(new BasicNameValuePair("utm_campaign",inviteData.getString("utm_campaign","")));
|
|
|
370 |
|
|
|
371 |
}/*else{
|
|
|
372 |
if (inviteD.getString("invite_added", "").equalsIgnoreCase("added")) {
|
|
|
373 |
nameValuePairs.add(new BasicNameValuePair("referrer",inviteD.getString("ref","")));
|
|
|
374 |
}else {
|
|
|
375 |
nameValuePairs.add(new BasicNameValuePair("referrer", referralCode.getText().toString()));
|
|
|
376 |
inviteDEditor.putString("ref", referralCode.getText().toString());
|
|
|
377 |
inviteDEditor.commit();
|
|
|
378 |
}
|
|
|
379 |
}*/
|
|
|
380 |
nameValuePairs.add(new BasicNameValuePair("profile_pic","http://graph.facebook.com/"+graphUser.getId()+"/picture"));
|
|
|
381 |
|
|
|
382 |
try{
|
|
|
383 |
if(graphUser.getProperty("email").toString()==null){
|
|
|
384 |
//Toast.makeText(getApplicationContext(),"In if",Toast.LENGTH_SHORT).show();
|
|
|
385 |
//Toast.makeText(getApplicationContext(),"User Name " + graphUser.toString(),Toast.LENGTH_SHORT).show();
|
|
|
386 |
}
|
|
|
387 |
else{
|
|
|
388 |
nameValuePairs.add(new BasicNameValuePair("email",graphUser.getProperty("email").toString()));
|
|
|
389 |
nameValuePairs.add(new BasicNameValuePair("gender",graphUser.getProperty("gender").toString()));
|
|
|
390 |
userDataEditor.putString("email",graphUser.getProperty("email").toString());
|
|
|
391 |
userDataEditor.commit();
|
|
|
392 |
// Toast.makeText(getApplicationContext(),"User Name " + graphUser.getName(),Toast.LENGTH_SHORT).show();
|
|
|
393 |
// Toast.makeText(getApplicationContext(),"Email " + graphUser.getProperty("email").toString(),Toast.LENGTH_SHORT).show();
|
|
|
394 |
new loadData().execute();
|
|
|
395 |
}
|
|
|
396 |
}
|
|
|
397 |
catch (Exception e){
|
|
|
398 |
AlertDialog.Builder alert = new AlertDialog.Builder(LoginActivity.this);
|
|
|
399 |
alert.setMessage("Enter Email Id to complete registration: ");
|
|
|
400 |
final EditText input = new EditText(LoginActivity.this);
|
|
|
401 |
alert.setView(input);
|
|
|
402 |
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
403 |
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
404 |
String value = input.getText().toString();
|
|
|
405 |
Pattern pattern;
|
|
|
406 |
Matcher matcher;
|
|
|
407 |
pattern = Pattern.compile(ProfitTillConstants.EMAIL_PATTERN);
|
|
|
408 |
matcher = pattern.matcher(value);
|
|
|
409 |
if( matcher.matches()){
|
|
|
410 |
nameValuePairs.add(new BasicNameValuePair("email",value.toString()));
|
|
|
411 |
userDataEditor.putString("email",value.toString());
|
|
|
412 |
userDataEditor.commit();
|
|
|
413 |
new loadData().execute();
|
|
|
414 |
}
|
|
|
415 |
else{
|
|
|
416 |
Toast.makeText(getApplicationContext(),"Please enter a valid Email id",Toast.LENGTH_SHORT ).show();
|
|
|
417 |
if (Session.getActiveSession() != null) {
|
|
|
418 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
419 |
}
|
|
|
420 |
Session.setActiveSession(null);
|
|
|
421 |
}
|
|
|
422 |
}
|
|
|
423 |
});
|
|
|
424 |
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
425 |
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
426 |
// Canceled.
|
|
|
427 |
if (Session.getActiveSession() != null) {
|
|
|
428 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
429 |
}
|
|
|
430 |
Session.setActiveSession(null);
|
|
|
431 |
}
|
|
|
432 |
});
|
|
|
433 |
|
|
|
434 |
alert.show();
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
|
|
|
438 |
}
|
|
|
439 |
else{
|
|
|
440 |
Log.e("Login Activity Facebook",response.getError()+"");
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
});
|
|
|
444 |
RequestAsyncTask asyncTask=mRequest.executeAsync();
|
|
|
445 |
} else if (state.isClosed()) {
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
};
|
|
|
449 |
@Override
|
|
|
450 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
451 |
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
452 |
getMenuInflater().inflate(R.menu.menu_login, menu);
|
|
|
453 |
return true;
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
@Override
|
|
|
457 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
458 |
// Handle action bar item clicks here. The action bar will
|
|
|
459 |
// automatically handle clicks on the Home/Up button, so long
|
|
|
460 |
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
461 |
int id = item.getItemId();
|
|
|
462 |
|
|
|
463 |
//noinspection SimplifiableIfStatement
|
|
|
464 |
if (id == R.id.action_settings) {
|
|
|
465 |
return true;
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
return super.onOptionsItemSelected(item);
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
/**
|
|
|
472 |
* Method to resolve any signin errors
|
|
|
473 |
* */
|
|
|
474 |
private void resolveSignInError() {
|
|
|
475 |
if (mConnectionResult.hasResolution()) {
|
|
|
476 |
try {
|
|
|
477 |
mIntentInProgress = true;
|
|
|
478 |
mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
|
|
|
479 |
} catch (IntentSender.SendIntentException e) {
|
|
|
480 |
e.printStackTrace();
|
|
|
481 |
TestinAgent.uploadException(this,"Exception in Resolve sign in error", new Exception());
|
|
|
482 |
mIntentInProgress = false;
|
|
|
483 |
//mGoogleApiClient.connect();
|
|
|
484 |
revokeGplusAccess();
|
|
|
485 |
}
|
|
|
486 |
}
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
/**
|
|
|
490 |
* Revoking access from google
|
|
|
491 |
* */
|
|
|
492 |
private void revokeGplusAccess() {
|
|
|
493 |
if (mGoogleApiClient.isConnected()) {
|
|
|
494 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
495 |
Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient)
|
|
|
496 |
.setResultCallback(new ResultCallback<Status>() {
|
|
|
497 |
@Override
|
|
|
498 |
public void onResult(Status arg0) {
|
|
|
499 |
Log.e(TAG, "User access revoked!");
|
|
|
500 |
mGoogleApiClient.connect();
|
|
|
501 |
//updateUI(false);
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
});
|
|
|
505 |
}
|
|
|
506 |
}
|
|
|
507 |
|
|
|
508 |
@Override
|
|
|
509 |
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
510 |
super.onConfigurationChanged(newConfig);
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
protected void onStart() {
|
|
|
514 |
super.onStart();
|
|
|
515 |
mGoogleApiClient.connect();
|
|
|
516 |
}
|
|
|
517 |
|
|
|
518 |
protected void onStop() {
|
|
|
519 |
super.onStop();
|
|
|
520 |
if (mGoogleApiClient.isConnected()) {
|
|
|
521 |
mGoogleApiClient.disconnect();
|
| 21170 |
rajender |
522 |
|
| 14792 |
manas |
523 |
}
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
@Override
|
|
|
527 |
public void onConnectionFailed(ConnectionResult result) {
|
|
|
528 |
if (!result.hasResolution()) {
|
|
|
529 |
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,0).show();
|
|
|
530 |
return;
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
if (!mIntentInProgress) {
|
|
|
534 |
mConnectionResult = result;
|
|
|
535 |
if (mSignInClicked) {
|
|
|
536 |
resolveSignInError();
|
|
|
537 |
}
|
|
|
538 |
}
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
@Override
|
|
|
542 |
protected void onActivityResult(int requestCode, int responseCode,
|
|
|
543 |
Intent intent) {
|
|
|
544 |
if (requestCode == RC_SIGN_IN) {
|
|
|
545 |
if (responseCode != RESULT_OK) {
|
|
|
546 |
mSignInClicked = false;
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
mIntentInProgress = false;
|
|
|
550 |
|
|
|
551 |
if (!mGoogleApiClient.isConnecting()) {
|
|
|
552 |
mGoogleApiClient.connect();
|
|
|
553 |
}
|
|
|
554 |
}
|
|
|
555 |
else if (requestCode==REQUEST_CODE_TOKEN_AUTH &&responseCode==RESULT_OK){
|
|
|
556 |
getAccessToken();
|
|
|
557 |
}
|
|
|
558 |
uiHelper.onActivityResult(requestCode, responseCode, intent);
|
|
|
559 |
}
|
|
|
560 |
|
|
|
561 |
private void getAccessToken() {
|
| 21170 |
rajender |
562 |
new getToken().execute();
|
| 14792 |
manas |
563 |
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
@Override
|
|
|
567 |
public void onConnectionSuspended(int arg0) {
|
|
|
568 |
mGoogleApiClient.connect();
|
|
|
569 |
}
|
|
|
570 |
@Override
|
|
|
571 |
public void onConnected(Bundle arg0) {
|
| 21170 |
rajender |
572 |
mSignInClicked=false;
|
| 14792 |
manas |
573 |
getAccessToken();
|
|
|
574 |
}
|
|
|
575 |
private void showProgressDialog()
|
|
|
576 |
{
|
|
|
577 |
pDlg = new ProgressDialog(LoginActivity.this);
|
|
|
578 |
pDlg.setMessage("Logging In");
|
|
|
579 |
pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
580 |
pDlg.setCancelable(false);
|
|
|
581 |
pDlg.show();
|
|
|
582 |
|
|
|
583 |
}
|
|
|
584 |
private ProgressDialog pDlg = null;
|
|
|
585 |
class getToken extends AsyncTask<String,Integer,String> {
|
|
|
586 |
|
|
|
587 |
@Override
|
|
|
588 |
protected void onPreExecute() {
|
|
|
589 |
showProgressDialog();
|
|
|
590 |
}
|
| 21170 |
rajender |
591 |
@Override
|
| 14792 |
manas |
592 |
protected String doInBackground(String... params) {
|
|
|
593 |
String id=null;
|
|
|
594 |
String token = null;
|
|
|
595 |
Bundle appActivities = new Bundle();
|
|
|
596 |
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,"MainActivity");
|
|
|
597 |
try {
|
|
|
598 |
token = GoogleAuthUtil.getToken(
|
|
|
599 |
LoginActivity.this,
|
|
|
600 |
Plus.AccountApi.getAccountName(mGoogleApiClient),
|
|
|
601 |
scope,appActivities);
|
|
|
602 |
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
|
|
|
603 |
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
|
|
|
604 |
String imageUrl = currentPerson.getImage().getUrl();
|
|
|
605 |
int i = currentPerson.getGender();
|
|
|
606 |
String gender;
|
|
|
607 |
if(i==0){
|
|
|
608 |
gender="male";
|
|
|
609 |
}
|
|
|
610 |
else if (i==1){
|
|
|
611 |
gender="female";
|
|
|
612 |
}
|
|
|
613 |
else if(i==2) {
|
|
|
614 |
gender = "otherwise";
|
|
|
615 |
}
|
|
|
616 |
else {
|
|
|
617 |
gender = "not available";
|
|
|
618 |
}
|
|
|
619 |
nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
620 |
nameValuePairs.add(new BasicNameValuePair("type","google"));
|
|
|
621 |
nameValuePairs.add(new BasicNameValuePair("id",currentPerson.getId()));
|
|
|
622 |
nameValuePairs.add(new BasicNameValuePair("name",currentPerson.getDisplayName()));
|
|
|
623 |
nameValuePairs.add(new BasicNameValuePair("email",Plus.AccountApi.getAccountName(mGoogleApiClient)));
|
|
|
624 |
userDataEditor.putString("email",Plus.AccountApi.getAccountName(mGoogleApiClient));
|
|
|
625 |
userDataEditor.commit();
|
|
|
626 |
nameValuePairs.add(new BasicNameValuePair("gender",gender));
|
|
|
627 |
nameValuePairs.add(new BasicNameValuePair("token",token));
|
|
|
628 |
Log.d("Invite Code Boolean","Boolean" +inviteData.getBoolean("inviteCodeRequired",true));
|
|
|
629 |
if(!(inviteData.getBoolean("inviteCodeRequired",true))) {
|
|
|
630 |
nameValuePairs.add(new BasicNameValuePair("utm_source",inviteData.getString("utm_source","")));
|
|
|
631 |
nameValuePairs.add(new BasicNameValuePair("utm_medium",inviteData.getString("utm_medium","")));
|
|
|
632 |
nameValuePairs.add(new BasicNameValuePair("utm_content",inviteData.getString("utm_content","")));
|
|
|
633 |
nameValuePairs.add(new BasicNameValuePair("utm_term",inviteData.getString("utm_term","")));
|
|
|
634 |
nameValuePairs.add(new BasicNameValuePair("utm_campaign",inviteData.getString("utm_campaign","")));
|
|
|
635 |
|
| 14991 |
manas |
636 |
}
|
| 14792 |
manas |
637 |
|
|
|
638 |
nameValuePairs.add(new BasicNameValuePair("profile_pic",currentPerson.getImage().getUrl()));
|
|
|
639 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
640 |
HttpPost httppost = new HttpPost(apiData.getString("user.registration.api",null));
|
|
|
641 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
642 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
643 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
644 |
HttpEntity entity = response.getEntity();
|
|
|
645 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
646 |
System.out.println("JSON object in Login " + jObjGmail.toString());
|
|
|
647 |
String success = jObjGmail.getString("success");
|
|
|
648 |
if(success.equalsIgnoreCase("true")){
|
| 14991 |
manas |
649 |
userDataEditor.putString("token",token);
|
| 14792 |
manas |
650 |
userDataEditor.putString("referralCodeRequired",jObjGmail.getString("referrerRequired"));
|
| 21170 |
rajender |
651 |
userDataEditor.putString("docsSubmitted",jObjGmail.getString("docsSubmitted"));
|
| 14792 |
manas |
652 |
userDataEditor.putString("message",jObjGmail.getString("mobileRequired"));
|
|
|
653 |
userDataEditor.putString("type","google");
|
|
|
654 |
id= jObjGmail.getString("id");
|
|
|
655 |
userDataEditor.putString("id",id);
|
|
|
656 |
}
|
|
|
657 |
else{
|
|
|
658 |
|
|
|
659 |
}
|
|
|
660 |
}
|
|
|
661 |
else{
|
|
|
662 |
return "failure";
|
|
|
663 |
}
|
|
|
664 |
|
|
|
665 |
} catch (IOException transientEx) {
|
|
|
666 |
Log.e("InputOutput", transientEx.toString());
|
|
|
667 |
|
|
|
668 |
} catch (UserRecoverableAuthException e) {
|
|
|
669 |
Log.d("Here","Here " + e.getMessage());
|
|
|
670 |
Intent recover = e.getIntent();
|
|
|
671 |
startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
|
|
|
672 |
} catch (GoogleAuthException authEx) {
|
|
|
673 |
//resolveSignInError();
|
|
|
674 |
//revokeGplusAccess();
|
|
|
675 |
Log.e("AuthEX", authEx.toString());
|
|
|
676 |
}catch (Exception e) {
|
|
|
677 |
Log.e("Exception main", e.toString());
|
|
|
678 |
}
|
|
|
679 |
return id;
|
|
|
680 |
}
|
|
|
681 |
@Override
|
|
|
682 |
protected void onPostExecute(String result){
|
|
|
683 |
super.onPostExecute(result);
|
|
|
684 |
userDataEditor.commit();
|
| 18497 |
manas |
685 |
|
| 14792 |
manas |
686 |
try {
|
|
|
687 |
if (userData.getString("id", null) == null) {
|
|
|
688 |
if(mGoogleApiClient.isConnected()) {
|
|
|
689 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
690 |
mGoogleApiClient.disconnect();
|
|
|
691 |
userDataEditor.clear().commit();
|
|
|
692 |
}
|
|
|
693 |
else{
|
|
|
694 |
userDataEditor.clear().commit();
|
|
|
695 |
}
|
| 18497 |
manas |
696 |
if(pDlg!=null){
|
|
|
697 |
pDlg.dismiss();
|
|
|
698 |
}
|
| 14792 |
manas |
699 |
} else {
|
| 14991 |
manas |
700 |
UtilityFunctions utf = new UtilityFunctions();
|
|
|
701 |
new pushApkData().execute(utf.getDeviceInformation(getApplicationContext()));
|
|
|
702 |
//new gcmPushData().execute();
|
| 14792 |
manas |
703 |
}
|
|
|
704 |
}catch (Exception e){
|
|
|
705 |
e.printStackTrace();
|
|
|
706 |
}
|
|
|
707 |
}
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
|
|
|
711 |
@Override
|
|
|
712 |
public void onResume() {
|
|
|
713 |
super.onResume();
|
|
|
714 |
uiHelper.onResume();
|
|
|
715 |
}
|
|
|
716 |
|
|
|
717 |
@Override
|
|
|
718 |
public void onPause() {
|
|
|
719 |
super.onPause();
|
|
|
720 |
uiHelper.onPause();
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
@Override
|
|
|
724 |
public void onDestroy() {
|
|
|
725 |
super.onDestroy();
|
|
|
726 |
uiHelper.onDestroy();
|
|
|
727 |
mixpanel.flush();
|
|
|
728 |
}
|
| 14991 |
manas |
729 |
|
|
|
730 |
|
| 14792 |
manas |
731 |
@Override
|
|
|
732 |
public void onSaveInstanceState(Bundle savedState) {
|
|
|
733 |
super.onSaveInstanceState(savedState);
|
|
|
734 |
uiHelper.onSaveInstanceState(savedState);
|
|
|
735 |
}
|
|
|
736 |
class loadData extends AsyncTask<String, Integer, String> {
|
|
|
737 |
|
|
|
738 |
@Override
|
|
|
739 |
protected void onPreExecute() {
|
|
|
740 |
super.onPreExecute();
|
| 17463 |
manas |
741 |
showProgressDialog();
|
| 14792 |
manas |
742 |
}
|
|
|
743 |
|
|
|
744 |
@Override
|
|
|
745 |
protected String doInBackground(String... arg0) {
|
|
|
746 |
String id=null;
|
|
|
747 |
try {
|
|
|
748 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
749 |
HttpPost httppost = new HttpPost(apiData.getString("user.registration.api",null));
|
|
|
750 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
751 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
752 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
753 |
HttpEntity entity = response.getEntity();
|
|
|
754 |
int status = response.getStatusLine().getStatusCode();
|
|
|
755 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
756 |
String success = jObjGmail.getString("success");
|
|
|
757 |
if(success.equalsIgnoreCase("true")){
|
|
|
758 |
id = jObjGmail.getString("id");
|
|
|
759 |
userDataEditor.putString("type","facebook");
|
|
|
760 |
userDataEditor.putString("id",id);
|
| 14991 |
manas |
761 |
userDataEditor.putString("token",Session.getActiveSession().getAccessToken());
|
| 21170 |
rajender |
762 |
userDataEditor.putString("docsSubmitted",jObjGmail.getString("docsSubmitted"));
|
| 14792 |
manas |
763 |
userDataEditor.putString("referralCodeRequired",jObjGmail.getString("referrerRequired"));
|
|
|
764 |
userDataEditor.putString("message",jObjGmail.getString("mobileRequired"));
|
|
|
765 |
}
|
|
|
766 |
else{
|
|
|
767 |
}
|
|
|
768 |
nameValuePairs.clear();
|
|
|
769 |
} catch (Exception e) {
|
|
|
770 |
Log.e("Fail 1", e.toString());
|
|
|
771 |
}
|
|
|
772 |
return id;
|
|
|
773 |
}
|
|
|
774 |
|
|
|
775 |
@Override
|
|
|
776 |
protected void onPostExecute(String result) {
|
|
|
777 |
super.onPostExecute(result);
|
|
|
778 |
JSONObject props = new JSONObject();
|
|
|
779 |
try {
|
|
|
780 |
props.put("ID ", result);
|
|
|
781 |
} catch (JSONException e) {
|
|
|
782 |
e.printStackTrace();
|
|
|
783 |
}
|
|
|
784 |
mixpanel.track("Facebook",props);
|
|
|
785 |
userDataEditor.commit();
|
|
|
786 |
if(userData.getString("id",null)==null){
|
|
|
787 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
788 |
Session.setActiveSession(null);
|
|
|
789 |
userDataEditor.clear().commit();
|
| 18497 |
manas |
790 |
if(pDlg!=null){
|
|
|
791 |
pDlg.dismiss();
|
|
|
792 |
}
|
| 14792 |
manas |
793 |
}else {
|
| 15588 |
manas |
794 |
new pushApkData().execute(new UtilityFunctions().getDeviceInformation(getApplicationContext()));
|
| 14991 |
manas |
795 |
/* new gcmPushData().execute();*/
|
| 14792 |
manas |
796 |
}
|
|
|
797 |
}
|
|
|
798 |
}
|
|
|
799 |
|
|
|
800 |
@Override
|
|
|
801 |
public void onBackPressed() {
|
|
|
802 |
new AlertDialog.Builder(this)
|
|
|
803 |
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
804 |
.setTitle("Exit!")
|
|
|
805 |
.setMessage("Are you sure you want to close?")
|
|
|
806 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
|
|
|
807 |
{
|
|
|
808 |
@Override
|
|
|
809 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
810 |
Intent startMain = new Intent(Intent.ACTION_MAIN);
|
|
|
811 |
startMain.addCategory(Intent.CATEGORY_HOME);
|
|
|
812 |
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
813 |
startActivity(startMain);
|
|
|
814 |
}
|
|
|
815 |
})
|
|
|
816 |
.setNegativeButton("No", null)
|
|
|
817 |
.show();
|
|
|
818 |
}
|
|
|
819 |
|
|
|
820 |
private static int getAppVersion(Context context) {
|
|
|
821 |
try {
|
|
|
822 |
PackageInfo packageInfo = context.getPackageManager()
|
|
|
823 |
.getPackageInfo(context.getPackageName(), 0);
|
|
|
824 |
return packageInfo.versionCode;
|
|
|
825 |
} catch (PackageManager.NameNotFoundException e) {
|
|
|
826 |
throw new RuntimeException(e);
|
|
|
827 |
}
|
|
|
828 |
}
|
|
|
829 |
|
|
|
830 |
private void registerInBackground() {
|
|
|
831 |
new AsyncTask<Void, Void, String>() {
|
|
|
832 |
@Override
|
|
|
833 |
protected String doInBackground(Void... params) {
|
| 15588 |
manas |
834 |
|
| 21170 |
rajender |
835 |
if (fcm == null) {
|
|
|
836 |
regId =FirebaseInstanceId.getInstance().getToken();
|
| 14792 |
manas |
837 |
Log.d("RegisterActivity", "registerInBackground - regId: "
|
|
|
838 |
+ regId);
|
| 15588 |
manas |
839 |
msg = "Device registered";
|
| 14792 |
manas |
840 |
}
|
|
|
841 |
Log.d("RegisterActivity", "AsyncTask completed: " + msg);
|
|
|
842 |
return msg;
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
@Override
|
|
|
846 |
protected void onPostExecute(String msg) {
|
|
|
847 |
/*Toast.makeText(getApplicationContext(),
|
|
|
848 |
"Registered with GCM Server." + msg, Toast.LENGTH_LONG)
|
| 15588 |
manas |
849 |
.show();
|
|
|
850 |
*/
|
| 14792 |
manas |
851 |
}
|
|
|
852 |
}.execute(null, null, null);
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
/*private void storeRegistrationId(Context context, String regId) {
|
|
|
856 |
final SharedPreferences prefs = getSharedPreferences(
|
|
|
857 |
MainActivity.class.getSimpleName(), Context.MODE_PRIVATE);
|
|
|
858 |
int appVersion = getAppVersion(context);
|
|
|
859 |
Log.i(TAG, "Saving regId on app version " + appVersion);
|
|
|
860 |
SharedPreferences.Editor editor = prefs.edit();
|
|
|
861 |
editor.putString(REG_ID, regId);
|
|
|
862 |
editor.putInt(APP_VERSION, appVersion);
|
|
|
863 |
editor.commit();
|
|
|
864 |
}*/
|
|
|
865 |
public String registerGCM() {
|
|
|
866 |
|
| 21170 |
rajender |
867 |
// gcm = GoogleCloudMessaging.getInstance(this);
|
| 14792 |
manas |
868 |
regId = getRegistrationId(context);
|
| 15588 |
manas |
869 |
registerInBackground();
|
| 14792 |
manas |
870 |
return regId;
|
|
|
871 |
}
|
|
|
872 |
|
|
|
873 |
private String getRegistrationId(Context context) {
|
|
|
874 |
|
|
|
875 |
String registrationId = userData.getString("gcm_regid", "");
|
|
|
876 |
if (registrationId.isEmpty()) {
|
|
|
877 |
Log.i(TAG, "Registration not found.");
|
|
|
878 |
return "";
|
|
|
879 |
}
|
|
|
880 |
return registrationId;
|
|
|
881 |
}
|
|
|
882 |
|
|
|
883 |
class gcmPushData extends AsyncTask<String, Integer, String> {
|
|
|
884 |
|
|
|
885 |
@Override
|
|
|
886 |
protected void onPreExecute() {
|
|
|
887 |
super.onPreExecute();
|
|
|
888 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
889 |
MixpanelAPI.People people = mixpanel.getPeople();
|
|
|
890 |
JSONObject props = new JSONObject();
|
|
|
891 |
try {
|
|
|
892 |
mixpanel.identify(userData.getString("id",null));
|
|
|
893 |
people.identify(userData.getString("id",null));
|
|
|
894 |
props.put("Screen", "Logged In");
|
|
|
895 |
people.set("$last_login",new Date());
|
|
|
896 |
people.set("user_id" , userData.getString("id",null));
|
|
|
897 |
mixpanel.track("Successfully Logged In", props);
|
|
|
898 |
} catch (JSONException e) {
|
|
|
899 |
e.printStackTrace();
|
|
|
900 |
}
|
|
|
901 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
902 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
903 |
t.set("&uid",userData.getString("id",null));
|
|
|
904 |
t.send(new HitBuilders.EventBuilder()
|
|
|
905 |
.setCategory("Login ")
|
|
|
906 |
.setAction("Login Successful")
|
|
|
907 |
.setLabel("Successful for User" +userData.getString("id",null))
|
|
|
908 |
.build());
|
|
|
909 |
}
|
|
|
910 |
|
|
|
911 |
@Override
|
|
|
912 |
protected String doInBackground(String... arg0) {
|
|
|
913 |
String id=null;
|
|
|
914 |
try {
|
|
|
915 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
916 |
HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url",null));
|
|
|
917 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
918 |
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
919 |
nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid",regId));
|
|
|
920 |
nameValuePairsGcm.add(new BasicNameValuePair("imeinumber",telephonyManager.getDeviceId()));
|
| 19653 |
manas |
921 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id", null)));
|
| 21170 |
rajender |
922 |
nameValuePairsGcm.add(new BasicNameValuePair("notification_type","fcm"));
|
| 15588 |
manas |
923 |
nameValuePairsGcm.add(new BasicNameValuePair("device_message",arg0[0]));
|
| 19653 |
manas |
924 |
nameValuePairsGcm.add(new BasicNameValuePair("androidid",UtilityFunctions.androidId(LoginActivity.this)));
|
| 14792 |
manas |
925 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
926 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
|
|
|
927 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
928 |
HttpEntity entity = response.getEntity();
|
|
|
929 |
int status = response.getStatusLine().getStatusCode();
|
|
|
930 |
|
|
|
931 |
if(status == 200){
|
|
|
932 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
933 |
} else {
|
|
|
934 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
935 |
}
|
|
|
936 |
|
|
|
937 |
nameValuePairsGcm.clear();
|
|
|
938 |
Log.e("pass 1", "connection success ");
|
|
|
939 |
} catch (Exception e) {
|
|
|
940 |
Log.e("Fail 1", e.toString());
|
|
|
941 |
|
|
|
942 |
}
|
|
|
943 |
return id;
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
@Override
|
|
|
947 |
protected void onPostExecute(String result) {
|
|
|
948 |
super.onPostExecute(result);
|
| 14991 |
manas |
949 |
if(pDlg!=null){
|
|
|
950 |
pDlg.dismiss();
|
|
|
951 |
}
|
| 14792 |
manas |
952 |
userDataEditor.putString("gcm_regid", regId);
|
|
|
953 |
userDataEditor.commit();
|
| 21170 |
rajender |
954 |
|
| 14792 |
manas |
955 |
String check = userData.getString("message","");
|
| 21170 |
rajender |
956 |
if(userData.getString("docsSubmitted","").equalsIgnoreCase("true")){
|
|
|
957 |
Intent i = new Intent(LoginActivity.this, PendingActivity.class);
|
| 14792 |
manas |
958 |
startActivity(i);
|
|
|
959 |
}
|
| 21170 |
rajender |
960 |
else if(userData.getString("referralCodeRequired","").equalsIgnoreCase("true")){
|
|
|
961 |
Log.d("In if","in if" +inviteD.getString("referrerCode","").equalsIgnoreCase("") + inviteD .getString("referrerCode","") );
|
|
|
962 |
Intent i = new Intent(LoginActivity.this, BasicInformation.class);
|
|
|
963 |
startActivity(i);
|
|
|
964 |
}
|
| 14792 |
manas |
965 |
else if(check.equalsIgnoreCase("true")){
|
|
|
966 |
Log.d("In if","in else");
|
|
|
967 |
Intent i = new Intent(LoginActivity.this, MobileNumber.class);
|
|
|
968 |
i.putExtra("displayView", "7");
|
|
|
969 |
startActivity(i);
|
|
|
970 |
}
|
|
|
971 |
else{
|
|
|
972 |
Intent i = new Intent(LoginActivity.this,MainActivity.class);
|
|
|
973 |
i.putExtra("displayView","0");
|
|
|
974 |
startActivity(i);
|
|
|
975 |
}
|
|
|
976 |
}
|
|
|
977 |
|
|
|
978 |
|
|
|
979 |
}
|
|
|
980 |
public final boolean isInternetOn() {
|
|
|
981 |
|
|
|
982 |
ConnectivityManager connection =
|
|
|
983 |
(ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
984 |
|
|
|
985 |
if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
986 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
987 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
988 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
989 |
|
|
|
990 |
return true;
|
|
|
991 |
|
|
|
992 |
} else if (
|
|
|
993 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
994 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
995 |
|
|
|
996 |
return false;
|
|
|
997 |
}
|
|
|
998 |
return false;
|
|
|
999 |
}
|
|
|
1000 |
class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
|
|
1001 |
|
|
|
1002 |
@Override
|
|
|
1003 |
protected void onPreExecute() {
|
|
|
1004 |
super.onPreExecute();
|
| 15588 |
manas |
1005 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
1006 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
1007 |
t.send(new HitBuilders.EventBuilder()
|
|
|
1008 |
.setCategory("Notification")
|
|
|
1009 |
.setAction("Notification Opened Login")
|
|
|
1010 |
.setLabel("For User Id " + userData.getString("id","0"))
|
|
|
1011 |
.build());
|
| 14792 |
manas |
1012 |
}
|
|
|
1013 |
|
|
|
1014 |
@Override
|
|
|
1015 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
|
|
1016 |
|
|
|
1017 |
try {
|
|
|
1018 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1019 |
HttpPost httppost = new HttpPost(apiData.getString("notication.data.url","http://api.profittill.com/pushnotifications/add"));
|
|
|
1020 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1021 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
1022 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1023 |
HttpEntity entity = response.getEntity();
|
|
|
1024 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1025 |
|
|
|
1026 |
if(status == 200){
|
|
|
1027 |
Log.d("Notification Opened","Notication opened and sent to server");
|
|
|
1028 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
1029 |
} else {
|
|
|
1030 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
1031 |
}
|
|
|
1032 |
|
|
|
1033 |
nameValuePairsGcm.clear();
|
|
|
1034 |
Log.e("pass 1", "connection success ");
|
|
|
1035 |
} catch (Exception e) {
|
|
|
1036 |
Log.e("Fail 1", e.toString());
|
|
|
1037 |
|
|
|
1038 |
}
|
|
|
1039 |
return "success";
|
|
|
1040 |
}
|
|
|
1041 |
|
|
|
1042 |
@Override
|
|
|
1043 |
protected void onPostExecute(String result) {
|
|
|
1044 |
super.onPostExecute(result);
|
|
|
1045 |
Log.d("Notification Opened","Notication opened and login page");
|
|
|
1046 |
}
|
|
|
1047 |
}
|
| 14991 |
manas |
1048 |
|
|
|
1049 |
class pushApkData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
|
|
1050 |
|
|
|
1051 |
@Override
|
|
|
1052 |
protected void onPreExecute() {
|
|
|
1053 |
super.onPreExecute();
|
|
|
1054 |
}
|
|
|
1055 |
|
|
|
1056 |
@Override
|
|
|
1057 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
|
|
1058 |
try {
|
|
|
1059 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
1060 |
HttpPost httppost = new HttpPost("http://api.profittill.com/devices/add");
|
|
|
1061 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
1062 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
1063 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
1064 |
HttpEntity entity = response.getEntity();
|
|
|
1065 |
int status = response.getStatusLine().getStatusCode();
|
|
|
1066 |
if(status == 200){
|
|
|
1067 |
return "success";
|
|
|
1068 |
} else {
|
|
|
1069 |
return "failure";
|
|
|
1070 |
}
|
|
|
1071 |
} catch (Exception e) {
|
|
|
1072 |
return null;
|
|
|
1073 |
}
|
|
|
1074 |
}
|
|
|
1075 |
@Override
|
|
|
1076 |
protected void onPostExecute(String result) {
|
|
|
1077 |
super.onPostExecute(result);
|
| 15588 |
manas |
1078 |
new gcmPushData().execute(msg);
|
| 14991 |
manas |
1079 |
}
|
|
|
1080 |
}
|
| 14792 |
manas |
1081 |
}
|