| 14792 |
manas |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
|
| 15356 |
manas |
4 |
import android.app.Fragment;
|
|
|
5 |
import android.app.FragmentManager;
|
| 14792 |
manas |
6 |
import android.content.Context;
|
|
|
7 |
import android.content.Intent;
|
|
|
8 |
import android.content.SharedPreferences;
|
| 15356 |
manas |
9 |
import android.content.res.Configuration;
|
|
|
10 |
import android.content.res.TypedArray;
|
| 14792 |
manas |
11 |
import android.graphics.Color;
|
|
|
12 |
import android.graphics.drawable.ColorDrawable;
|
|
|
13 |
import android.net.ConnectivityManager;
|
|
|
14 |
import android.os.AsyncTask;
|
| 15356 |
manas |
15 |
import android.os.Bundle;
|
| 14792 |
manas |
16 |
import android.os.PersistableBundle;
|
| 15356 |
manas |
17 |
import android.support.v4.app.ActionBarDrawerToggle;
|
|
|
18 |
import android.support.v4.widget.DrawerLayout;
|
| 14792 |
manas |
19 |
import android.support.v7.app.ActionBarActivity;
|
| 15356 |
manas |
20 |
import android.util.Log;
|
| 14792 |
manas |
21 |
import android.view.KeyEvent;
|
|
|
22 |
import android.view.Menu;
|
|
|
23 |
import android.view.MenuItem;
|
|
|
24 |
import android.view.View;
|
|
|
25 |
import android.view.ViewConfiguration;
|
|
|
26 |
import android.view.Window;
|
|
|
27 |
import android.widget.AdapterView;
|
|
|
28 |
import android.widget.ListView;
|
|
|
29 |
import android.widget.Toast;
|
| 15356 |
manas |
30 |
|
| 14792 |
manas |
31 |
import com.facebook.Session;
|
|
|
32 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
33 |
import com.google.android.gms.analytics.Tracker;
|
|
|
34 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
35 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
36 |
import com.google.android.gms.plus.Plus;
|
|
|
37 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
38 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
| 15356 |
manas |
39 |
import com.saholic.profittill.R;
|
|
|
40 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
| 14792 |
manas |
41 |
import com.saholic.profittill.navigationdrawer.NavDrawerItem;
|
|
|
42 |
import com.saholic.profittill.navigationdrawer.NavDrawerListAdapter;
|
|
|
43 |
import com.testin.agent.TestinAgent;
|
|
|
44 |
|
|
|
45 |
import org.apache.http.HttpEntity;
|
|
|
46 |
import org.apache.http.HttpResponse;
|
|
|
47 |
import org.apache.http.NameValuePair;
|
|
|
48 |
import org.apache.http.client.HttpClient;
|
|
|
49 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
50 |
import org.apache.http.client.methods.HttpPost;
|
|
|
51 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
52 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
53 |
import org.json.JSONException;
|
|
|
54 |
import org.json.JSONObject;
|
|
|
55 |
|
|
|
56 |
import java.lang.reflect.Field;
|
|
|
57 |
import java.lang.reflect.Method;
|
|
|
58 |
import java.text.SimpleDateFormat;
|
|
|
59 |
import java.util.ArrayList;
|
|
|
60 |
import java.util.Date;
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
public class MainActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
|
|
64 |
private DrawerLayout mDrawerLayout;
|
|
|
65 |
private ListView mDrawerList;
|
|
|
66 |
private ActionBarDrawerToggle mDrawerToggle;
|
|
|
67 |
public GoogleApiClient mGoogleApiClient;
|
|
|
68 |
SharedPreferences userData;
|
|
|
69 |
SharedPreferences apiData;
|
|
|
70 |
boolean glogout;
|
|
|
71 |
SharedPreferences.Editor userDataEditor;
|
|
|
72 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
73 |
SharedPreferences.Editor inviteDataEditor;
|
|
|
74 |
SharedPreferences inviteData;
|
|
|
75 |
private String[] navMenuTitles;
|
|
|
76 |
private TypedArray navMenuIcons;
|
|
|
77 |
String type1;
|
|
|
78 |
private ArrayList<NavDrawerItem> navDrawerItems;
|
|
|
79 |
private NavDrawerListAdapter adapter;
|
|
|
80 |
int flag;
|
|
|
81 |
boolean shouldGoInvisible;
|
|
|
82 |
int titleVisible;
|
|
|
83 |
StringBuilder subtag,sb;
|
|
|
84 |
String userIdAffliate;
|
|
|
85 |
Date dateAffliate;
|
|
|
86 |
String stringDateAffliate;
|
|
|
87 |
SimpleDateFormat dateFormatAffliate;
|
|
|
88 |
String redirectUrl;
|
|
|
89 |
MixpanelAPI mixpanel;
|
|
|
90 |
String notificationURL;
|
|
|
91 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
|
|
92 |
@Override
|
|
|
93 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
94 |
super.onCreate(savedInstanceState);
|
|
|
95 |
setContentView(R.layout.activity_main);
|
|
|
96 |
TestinAgent.init(this);
|
|
|
97 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
|
|
98 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
|
|
99 |
userDataEditor = userData.edit();
|
|
|
100 |
apiSettingsEditor = apiData.edit();
|
|
|
101 |
inviteData = getApplicationContext().getSharedPreferences("Invite_Data", Context.MODE_PRIVATE);
|
|
|
102 |
inviteDataEditor = inviteData.edit();
|
|
|
103 |
TestinAgent.setUserInfo(userData.getString("id",""));
|
|
|
104 |
mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
105 |
type1 = userData.getString("type",null);
|
|
|
106 |
|
|
|
107 |
if(getIntent().getAction()=="20"){
|
|
|
108 |
flag=20;
|
|
|
109 |
notificationURL = String.valueOf(getIntent().getData());
|
|
|
110 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
111 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id","")));
|
|
|
112 |
nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
|
| 15356 |
manas |
113 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
| 14792 |
manas |
114 |
nameValuePairsGcm.add(new BasicNameValuePair("result","opened"));
|
|
|
115 |
getIntent().getExtras().remove("cid");
|
|
|
116 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
117 |
}else if(getIntent().getAction()=="15"){
|
|
|
118 |
flag=15;
|
|
|
119 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
120 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id","")));
|
|
|
121 |
nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
|
| 15356 |
manas |
122 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp",UtilityFunctions.notificationDate()));
|
| 14792 |
manas |
123 |
nameValuePairsGcm.add(new BasicNameValuePair("result","opened"));
|
|
|
124 |
getIntent().getExtras().remove("cid");
|
|
|
125 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
126 |
}else if(getIntent().getAction()=="7"){
|
|
|
127 |
flag=7;
|
|
|
128 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
129 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id","")));
|
|
|
130 |
nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
|
| 15356 |
manas |
131 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp",UtilityFunctions.notificationDate()));
|
| 14792 |
manas |
132 |
nameValuePairsGcm.add(new BasicNameValuePair("result","opened"));
|
|
|
133 |
getIntent().getExtras().remove("cid");
|
|
|
134 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
135 |
}else if(getIntent().getAction()=="6"){
|
|
|
136 |
flag=6;
|
|
|
137 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
138 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id","")));
|
|
|
139 |
nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
|
| 15356 |
manas |
140 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp",UtilityFunctions.notificationDate()));
|
| 14792 |
manas |
141 |
nameValuePairsGcm.add(new BasicNameValuePair("result","opened"));
|
|
|
142 |
getIntent().getExtras().remove("cid");
|
|
|
143 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
144 |
}else {
|
|
|
145 |
Bundle i = getIntent().getExtras();
|
|
|
146 |
if (i != null) {
|
|
|
147 |
flag = Integer.parseInt(i.getString("displayView"));
|
|
|
148 |
if (flag == 31) {
|
|
|
149 |
redirectUrl = i.getString("redirectUrl");
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
|
|
|
157 |
getSupportActionBar().setIcon(R.drawable.logo_cirlce_1);
|
|
|
158 |
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
|
|
159 |
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
|
|
160 |
|
|
|
161 |
try {
|
|
|
162 |
ViewConfiguration config = ViewConfiguration.get(this);
|
|
|
163 |
Field menuKeyField = ViewConfiguration.class
|
|
|
164 |
.getDeclaredField("sHasPermanentMenuKey");
|
|
|
165 |
if (menuKeyField != null) {
|
|
|
166 |
menuKeyField.setAccessible(true);
|
|
|
167 |
menuKeyField.setBoolean(config, false);
|
|
|
168 |
}
|
|
|
169 |
} catch (Exception ex) {
|
|
|
170 |
Log.d("Exception","Message"+ex);
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
if(type1!=null && type1.equalsIgnoreCase("google")) {
|
|
|
174 |
mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
|
175 |
.addConnectionCallbacks(this)
|
|
|
176 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
177 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
178 |
mGoogleApiClient.connect();
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
/*mTitle = mDrawerTitle = getTitle();*/
|
|
|
182 |
// load slide menu items
|
|
|
183 |
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
|
|
|
184 |
|
|
|
185 |
// nav drawer icons from resources
|
|
|
186 |
navMenuIcons = getResources()
|
|
|
187 |
.obtainTypedArray(R.array.nav_drawer_icons);
|
|
|
188 |
|
|
|
189 |
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
190 |
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
|
|
|
191 |
mDrawerLayout.setBackgroundColor(getResources().getColor(R.color.White));
|
|
|
192 |
navDrawerItems = new ArrayList<NavDrawerItem>();
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
|
|
|
197 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, 0)));
|
|
|
198 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
|
|
|
199 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
|
|
|
200 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
|
|
|
201 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
|
|
|
202 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));
|
|
|
203 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(7, -1)));
|
|
|
204 |
navDrawerItems.add(new NavDrawerItem(navMenuTitles[8], navMenuIcons.getResourceId(8, -1)));
|
|
|
205 |
/* navDrawerItems.add(new NavDrawerItem(navMenuTitles[9], navMenuIcons.getResourceId(8, -1)));*/
|
|
|
206 |
navMenuIcons.recycle();
|
|
|
207 |
|
|
|
208 |
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
|
|
|
209 |
|
|
|
210 |
// setting the nav drawer list adapter
|
|
|
211 |
adapter = new NavDrawerListAdapter(getApplicationContext(),navDrawerItems);
|
|
|
212 |
mDrawerList.setAdapter(adapter);
|
|
|
213 |
|
|
|
214 |
// enabling action bar app icon and behaving it as toggle button
|
|
|
215 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
216 |
getSupportActionBar().setHomeButtonEnabled(true);
|
|
|
217 |
|
|
|
218 |
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
|
|
|
219 |
R.drawable.menubutton, //nav menu toggle icon
|
|
|
220 |
R.string.hello_world, // nav drawer open - description for accessibility
|
|
|
221 |
R.string.hello_world// nav drawer close - description for accessibility
|
|
|
222 |
) {
|
|
|
223 |
public void onDrawerClosed(View view) {
|
|
|
224 |
if(titleVisible!=0) {
|
|
|
225 |
if(titleVisible==1)
|
|
|
226 |
getSupportActionBar().setCustomView(R.layout.actionbarmyfavorites);
|
|
|
227 |
|
|
|
228 |
if(titleVisible==2)
|
|
|
229 |
getSupportActionBar().setCustomView(R.layout.actionbarprefernces);
|
|
|
230 |
|
|
|
231 |
if(titleVisible==3)
|
|
|
232 |
getSupportActionBar().setCustomView(R.layout.actionbarmywallet);
|
|
|
233 |
|
|
|
234 |
if(titleVisible==4)
|
|
|
235 |
getSupportActionBar().setCustomView(R.layout.actionbarmyorders);
|
|
|
236 |
|
|
|
237 |
if(titleVisible==5)
|
|
|
238 |
getSupportActionBar().setCustomView(R.layout.actionbarpendingcashback);
|
|
|
239 |
|
|
|
240 |
if(titleVisible==6)
|
|
|
241 |
getSupportActionBar().setCustomView(R.layout.actionbarmyprofile);
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
}
|
|
|
245 |
else{
|
|
|
246 |
if (getTitle().equals("Deals")) {
|
|
|
247 |
getSupportActionBar().setCustomView(R.layout.actionbardeals);
|
|
|
248 |
}
|
|
|
249 |
if (getTitle().equals("Saholic") || getTitle().equals("Flipkart") || getTitle().equals("Snapdeal") || getTitle().equals("Amazon")) {
|
|
|
250 |
getSupportActionBar().setCustomView(R.layout.actionbarprofittill);
|
|
|
251 |
}
|
|
|
252 |
if (getTitle().equals("FAQ")) {
|
|
|
253 |
getSupportActionBar().setCustomView(R.layout.actionbaraboutus);
|
|
|
254 |
}
|
|
|
255 |
if (getTitle().equals("Contact Us")) {
|
|
|
256 |
getSupportActionBar().setCustomView(R.layout.actionbarcontactus);
|
|
|
257 |
}
|
|
|
258 |
if (getTitle().equals("Search")) {
|
|
|
259 |
getSupportActionBar().setCustomView(R.layout.actionbarsearch);
|
|
|
260 |
}
|
|
|
261 |
if (getTitle().equals("How It Works")) {
|
|
|
262 |
getSupportActionBar().setCustomView(R.layout.actionbarhowitworks);
|
|
|
263 |
}
|
|
|
264 |
}
|
|
|
265 |
shouldGoInvisible = false;
|
|
|
266 |
invalidateOptionsMenu();
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
public void onDrawerOpened(View drawerView) {
|
|
|
270 |
getSupportActionBar().setCustomView(R.layout.actionbarprofittill);
|
|
|
271 |
shouldGoInvisible = true;
|
|
|
272 |
invalidateOptionsMenu();
|
|
|
273 |
}
|
|
|
274 |
@Override
|
|
|
275 |
public void onDrawerSlide(View drawerView, float slideOffset) {
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
};
|
|
|
281 |
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
|
|
282 |
|
|
|
283 |
if (savedInstanceState == null) {
|
|
|
284 |
|
|
|
285 |
if (flag == 7) {
|
|
|
286 |
getSupportActionBar().setCustomView(R.layout.actionbarhowitworks);
|
|
|
287 |
displayView(flag);
|
|
|
288 |
} else if (flag == 6) {
|
|
|
289 |
getSupportActionBar().setCustomView(R.layout.actionbarcontactus);
|
|
|
290 |
displayView(flag);
|
|
|
291 |
} else if (flag == 15) {
|
|
|
292 |
getSupportActionBar().setCustomView(R.layout.actionbarmyprofile);
|
|
|
293 |
MyProfile myProfile = new MyProfile();
|
|
|
294 |
this.getFragmentManager().beginTransaction()
|
|
|
295 |
.replace(R.id.frame_container, myProfile, "Mike")
|
|
|
296 |
.addToBackStack(null)
|
|
|
297 |
.commit();
|
|
|
298 |
}else if (flag == 20) {
|
|
|
299 |
getSupportActionBar().setCustomView(R.layout.actionbardeals);
|
|
|
300 |
JSONObject propsNotification = new JSONObject();
|
|
|
301 |
try {
|
|
|
302 |
mixpanel.identify(userData.getString("id",null));
|
|
|
303 |
propsNotification.put("Screen", "Notification Url opened");
|
|
|
304 |
mixpanel.track("Notification Opened", propsNotification);
|
|
|
305 |
} catch (JSONException e) {
|
|
|
306 |
e.printStackTrace();
|
|
|
307 |
}
|
|
|
308 |
Bundle args = new Bundle();
|
|
|
309 |
DealsHomeFragment notifcationFragment = new DealsHomeFragment();
|
|
|
310 |
args.putString("key", notificationURL);
|
|
|
311 |
this.getFragmentManager().beginTransaction()
|
|
|
312 |
.replace(R.id.frame_container, notifcationFragment, "Mike")
|
|
|
313 |
.addToBackStack(null)
|
|
|
314 |
.commit();
|
|
|
315 |
notifcationFragment.setArguments(args);
|
|
|
316 |
}else if (flag == 31) {
|
|
|
317 |
getSupportActionBar().setCustomView(R.layout.actionbardeals);
|
|
|
318 |
Bundle args = new Bundle();
|
|
|
319 |
DealsHomeFragment redirectUrlFragment = new DealsHomeFragment();
|
|
|
320 |
args.putString("key", redirectUrl);
|
|
|
321 |
this.getFragmentManager().beginTransaction()
|
|
|
322 |
.replace(R.id.frame_container, redirectUrlFragment, "Mike")
|
|
|
323 |
.addToBackStack(null)
|
|
|
324 |
.commit();
|
|
|
325 |
redirectUrlFragment.setArguments(args);
|
|
|
326 |
}else {
|
|
|
327 |
getSupportActionBar().setCustomView(R.layout.actionbardeals);
|
|
|
328 |
displayView(0);
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
}
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
/**
|
|
|
335 |
* Slide menu item click listener
|
|
|
336 |
* */
|
|
|
337 |
private class SlideMenuClickListener implements
|
|
|
338 |
ListView.OnItemClickListener {
|
|
|
339 |
@Override
|
|
|
340 |
public void onItemClick(AdapterView<?> parent, View view, int position,
|
|
|
341 |
long id) {
|
|
|
342 |
// display view for selected nav drawer item
|
|
|
343 |
displayView(position);
|
|
|
344 |
}
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
@Override
|
|
|
348 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
349 |
mainMenu=menu;
|
|
|
350 |
super.onCreateOptionsMenu(menu);
|
|
|
351 |
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
352 |
|
|
|
353 |
return true;
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
@Override
|
|
|
357 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
358 |
Fragment menuFragment= null;
|
|
|
359 |
JSONObject props = new JSONObject();
|
|
|
360 |
Bundle args = new Bundle();
|
|
|
361 |
String id = userData.getString("id",null);
|
|
|
362 |
if (mDrawerToggle.onOptionsItemSelected(item)) {
|
|
|
363 |
return true;
|
|
|
364 |
}
|
|
|
365 |
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
|
|
366 |
switch (item.getItemId()) {
|
|
|
367 |
case R.id.action_settings:
|
|
|
368 |
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
|
|
|
369 |
android.webkit.CookieSyncManager.createInstance(this);
|
|
|
370 |
cookieManager.removeAllCookie();
|
|
|
371 |
try {
|
|
|
372 |
mixpanel.identify(userData.getString("id",null));
|
|
|
373 |
props.put("Screen", "Signing Out");
|
|
|
374 |
mixpanel.track("Signing Out", props);
|
|
|
375 |
} catch (JSONException e) {
|
|
|
376 |
e.printStackTrace();
|
|
|
377 |
}
|
|
|
378 |
try{
|
|
|
379 |
if (mGoogleApiClient.isConnected()) {
|
|
|
380 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
381 |
mGoogleApiClient.disconnect();
|
|
|
382 |
mGoogleApiClient.connect();
|
|
|
383 |
userDataEditor.clear().commit();
|
|
|
384 |
inviteDataEditor.clear().commit();
|
|
|
385 |
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
|
|
386 |
}
|
|
|
387 |
else if(Session.getActiveSession() != null){
|
|
|
388 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
389 |
Session.setActiveSession(null);
|
|
|
390 |
userDataEditor.clear().commit();
|
|
|
391 |
inviteDataEditor.clear().commit();
|
|
|
392 |
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
|
|
393 |
}
|
|
|
394 |
else{
|
|
|
395 |
if(!mGoogleApiClient.isConnected() || Session.getActiveSession()==null){
|
|
|
396 |
userDataEditor.clear().commit();
|
|
|
397 |
inviteDataEditor.clear().commit();
|
|
|
398 |
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
/*Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
402 |
mGoogleApiClient.disconnect();
|
|
|
403 |
mGoogleApiClient.connect();*/
|
|
|
404 |
//userDataEditor.clear().commit();
|
|
|
405 |
}
|
|
|
406 |
/*if(type1.equalsIgnoreCase("facebook")) {
|
|
|
407 |
Log.d("fblogout","logout");
|
|
|
408 |
if (Session.getActiveSession() != null) {
|
|
|
409 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
410 |
|
|
|
411 |
}
|
|
|
412 |
Session.setActiveSession(null);
|
|
|
413 |
userDataEditor.remove("id");
|
|
|
414 |
userDataEditor.remove("type");
|
|
|
415 |
userDataEditor.remove("email");
|
|
|
416 |
userDataEditor.commit();
|
|
|
417 |
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
|
|
418 |
}
|
|
|
419 |
else{
|
|
|
420 |
signOutFromGplus();
|
|
|
421 |
if(glogout==true){
|
|
|
422 |
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
|
|
423 |
}
|
|
|
424 |
}*/
|
|
|
425 |
}catch (Exception e){
|
|
|
426 |
Log.d("Exception ","Exception");
|
|
|
427 |
/* if (Session.getActiveSession() != null) {
|
|
|
428 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
429 |
}else{
|
|
|
430 |
signOutFromGplus();
|
|
|
431 |
}*/
|
|
|
432 |
userDataEditor.clear().commit();
|
|
|
433 |
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
|
|
434 |
}
|
|
|
435 |
return true;
|
|
|
436 |
|
|
|
437 |
case R.id.my_wallet:
|
|
|
438 |
titleVisible=3;
|
|
|
439 |
getSupportActionBar().setCustomView(R.layout.actionbarmywallet);
|
|
|
440 |
try {
|
|
|
441 |
mixpanel.identify(userData.getString("id",null));
|
|
|
442 |
props.put("Screen", "My Wallet");
|
|
|
443 |
mixpanel.track("My Wallet", props);
|
|
|
444 |
} catch (JSONException e) {
|
|
|
445 |
e.printStackTrace();
|
|
|
446 |
}
|
|
|
447 |
MyWallet myWallet= new MyWallet();
|
|
|
448 |
this.getFragmentManager().beginTransaction()
|
|
|
449 |
.replace(R.id.frame_container, myWallet,"Mike")
|
|
|
450 |
.addToBackStack(null)
|
|
|
451 |
.commit();
|
|
|
452 |
return true;
|
|
|
453 |
case R.id.pending_cashback:
|
|
|
454 |
titleVisible=5;
|
|
|
455 |
getSupportActionBar().setCustomView(R.layout.actionbarpendingcashback);
|
|
|
456 |
try {
|
|
|
457 |
mixpanel.identify(userData.getString("id",null));
|
|
|
458 |
props.put("Screen", "Cashback Status");
|
|
|
459 |
mixpanel.track("Cashback Status", props);
|
|
|
460 |
} catch (JSONException e) {
|
|
|
461 |
e.printStackTrace();
|
|
|
462 |
}
|
|
|
463 |
PendingCashback pendingCashback= new PendingCashback();
|
|
|
464 |
this.getFragmentManager().beginTransaction()
|
|
|
465 |
.replace(R.id.frame_container, pendingCashback,"Mike")
|
|
|
466 |
.addToBackStack(null)
|
|
|
467 |
.commit();
|
|
|
468 |
return true;
|
|
|
469 |
case R.id.my_favorites:
|
|
|
470 |
titleVisible=1;
|
|
|
471 |
getSupportActionBar().setCustomView(R.layout.actionbarmyfavorites);
|
|
|
472 |
try {
|
|
|
473 |
mixpanel.identify(userData.getString("id",null));
|
|
|
474 |
props.put("Screen", "My Favorites");
|
|
|
475 |
mixpanel.track("My Favorites", props);
|
|
|
476 |
} catch (JSONException e) {
|
|
|
477 |
e.printStackTrace();
|
|
|
478 |
}
|
|
|
479 |
args.putString("key", apiData.getString("myfavourite.url",null)+"?user_id="+id);
|
|
|
480 |
DealsHomeFragment favoritesFragment= new DealsHomeFragment();
|
|
|
481 |
this.getFragmentManager().beginTransaction()
|
|
|
482 |
.replace(R.id.frame_container, favoritesFragment,"Mike")
|
|
|
483 |
.addToBackStack(null)
|
|
|
484 |
.commit();
|
|
|
485 |
favoritesFragment.setArguments(args);
|
|
|
486 |
return true;
|
|
|
487 |
case R.id.my_profile:
|
|
|
488 |
titleVisible=6;
|
|
|
489 |
getSupportActionBar().setCustomView(R.layout.actionbarmyprofile);
|
|
|
490 |
try {
|
|
|
491 |
mixpanel.identify(userData.getString("id",null));
|
|
|
492 |
props.put("Screen", "My Profile");
|
|
|
493 |
mixpanel.track("My profile", props);
|
|
|
494 |
} catch (JSONException e) {
|
|
|
495 |
e.printStackTrace();
|
|
|
496 |
}
|
|
|
497 |
MyProfile myProfile= new MyProfile();
|
|
|
498 |
this.getFragmentManager().beginTransaction()
|
|
|
499 |
.replace(R.id.frame_container, myProfile,"Mike")
|
|
|
500 |
.addToBackStack(null)
|
|
|
501 |
.commit();
|
|
|
502 |
return true;
|
|
|
503 |
case R.id.my_order:
|
|
|
504 |
titleVisible=4;
|
|
|
505 |
getSupportActionBar().setCustomView(R.layout.actionbarmyorders);
|
|
|
506 |
try {
|
|
|
507 |
mixpanel.identify(userData.getString("id",null));
|
|
|
508 |
props.put("Screen", "My Orders");
|
|
|
509 |
mixpanel.track("My Orders", props);
|
|
|
510 |
} catch (JSONException e) {
|
|
|
511 |
e.printStackTrace();
|
|
|
512 |
}
|
|
|
513 |
args.putString("key", apiData.getString("myorders.url",null)+"?user_id="+id);
|
|
|
514 |
DealsHomeFragment orderFragment= new DealsHomeFragment();
|
|
|
515 |
this.getFragmentManager().beginTransaction()
|
|
|
516 |
.replace(R.id.frame_container, orderFragment,"Mike")
|
|
|
517 |
.addToBackStack(null)
|
|
|
518 |
.commit();
|
|
|
519 |
orderFragment.setArguments(args);
|
|
|
520 |
|
|
|
521 |
return true;
|
|
|
522 |
case R.id.my_preferences:
|
|
|
523 |
titleVisible=2;
|
|
|
524 |
getSupportActionBar().setCustomView(R.layout.actionbarprefernces);
|
|
|
525 |
try {
|
|
|
526 |
mixpanel.identify(userData.getString("id",null));
|
|
|
527 |
props.put("Screen", "My Preferences");
|
|
|
528 |
mixpanel.track("My Preferences", props);
|
|
|
529 |
} catch (JSONException e) {
|
|
|
530 |
e.printStackTrace();
|
|
|
531 |
}
|
|
|
532 |
PreferencesFragment my_preferences = new PreferencesFragment();
|
|
|
533 |
this.getFragmentManager().beginTransaction()
|
|
|
534 |
.replace(R.id.frame_container, my_preferences,"Mike")
|
|
|
535 |
.addToBackStack(null)
|
|
|
536 |
.commit();
|
|
|
537 |
|
|
|
538 |
return true;
|
|
|
539 |
default:
|
|
|
540 |
return super.onOptionsItemSelected(item);
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
}
|
|
|
545 |
public void signOutFromGplus() {
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
if (mGoogleApiClient.isConnected()) {
|
|
|
549 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
550 |
mGoogleApiClient.disconnect();
|
|
|
551 |
mGoogleApiClient.connect();
|
|
|
552 |
glogout=true;
|
|
|
553 |
userDataEditor.remove("id");
|
|
|
554 |
userDataEditor.remove("type");
|
|
|
555 |
userDataEditor.remove("email");
|
|
|
556 |
userDataEditor.commit();
|
|
|
557 |
} else {
|
|
|
558 |
glogout=false;
|
|
|
559 |
}
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
@Override
|
|
|
563 |
public void onConnected(Bundle bundle) {
|
|
|
564 |
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
@Override
|
|
|
568 |
public void onConnectionSuspended(int i) {
|
|
|
569 |
|
|
|
570 |
}
|
|
|
571 |
|
|
|
572 |
@Override
|
|
|
573 |
public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
574 |
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
@Override
|
|
|
578 |
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
|
|
|
579 |
Toast.makeText(getApplicationContext(),"Toast in saved instance" + flag,Toast.LENGTH_SHORT).show();
|
|
|
580 |
super.onSaveInstanceState(outState, outPersistentState);
|
|
|
581 |
}
|
|
|
582 |
@Override
|
|
|
583 |
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
584 |
super.onRestoreInstanceState(savedInstanceState);
|
|
|
585 |
Intent i= new Intent(MainActivity.this,MainActivity.class);
|
|
|
586 |
i.putExtra("displayView","0");
|
|
|
587 |
startActivity(i);
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
@Override
|
|
|
591 |
public boolean onMenuOpened(int featureId, Menu menu)
|
|
|
592 |
{
|
|
|
593 |
if(featureId == Window.FEATURE_ACTION_BAR && menu != null){
|
|
|
594 |
if(menu.getClass().getSimpleName().equals("MenuBuilder")){
|
|
|
595 |
try{
|
|
|
596 |
Method m = menu.getClass().getDeclaredMethod(
|
|
|
597 |
"setOptionalIconsVisible", Boolean.TYPE);
|
|
|
598 |
m.setAccessible(true);
|
|
|
599 |
m.invoke(menu, true);
|
|
|
600 |
|
|
|
601 |
}
|
|
|
602 |
catch(Exception e){
|
|
|
603 |
throw new RuntimeException(e);
|
|
|
604 |
}
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
return super.onMenuOpened(featureId, menu);
|
|
|
608 |
}
|
|
|
609 |
|
|
|
610 |
private void displayView(int position) {
|
|
|
611 |
titleVisible=0;
|
|
|
612 |
Bundle args = new Bundle();
|
|
|
613 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
614 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
615 |
String id = userData.getString("id",null);
|
|
|
616 |
Fragment fragment = null;
|
|
|
617 |
switch (position) {
|
|
|
618 |
case 0:
|
|
|
619 |
JSONObject props = new JSONObject();
|
|
|
620 |
try {
|
|
|
621 |
mixpanel.getPeople().set( "$last_login",new Date());
|
|
|
622 |
mixpanel.identify(userData.getString("id",null));
|
|
|
623 |
props.put("Screen", "Deals Screen");
|
|
|
624 |
mixpanel.track("Deals", props);
|
|
|
625 |
} catch (JSONException e) {
|
|
|
626 |
e.printStackTrace();
|
|
|
627 |
}
|
|
|
628 |
|
|
|
629 |
t.send(new HitBuilders.EventBuilder()
|
|
|
630 |
.setCategory("Menu")
|
|
|
631 |
.setAction("Deals ")
|
|
|
632 |
.setLabel("Deals Clicked")
|
|
|
633 |
.build());
|
|
|
634 |
args.putString("key", apiData.getString("mobile.website.url","")+"?user_id="+id);
|
|
|
635 |
fragment = new DealsHomeFragment();
|
|
|
636 |
fragment.setArguments(args);
|
|
|
637 |
break;
|
|
|
638 |
case 1:
|
|
|
639 |
JSONObject props1 = new JSONObject();
|
|
|
640 |
try {
|
|
|
641 |
mixpanel.identify(userData.getString("id",null));
|
|
|
642 |
props1.put("Screen", "Search");
|
|
|
643 |
mixpanel.track("Search", props1);
|
|
|
644 |
} catch (JSONException e) {
|
|
|
645 |
e.printStackTrace();
|
|
|
646 |
}
|
|
|
647 |
t.send(new HitBuilders.EventBuilder()
|
|
|
648 |
.setCategory("Menu")
|
|
|
649 |
.setAction("Search ")
|
|
|
650 |
.setLabel("Search Clicked")
|
|
|
651 |
.build());
|
|
|
652 |
args.putString("key", apiData.getString("search.url",null)+"?user_id="+id);
|
|
|
653 |
fragment = new DealsHomeFragment();
|
|
|
654 |
fragment.setArguments(args);
|
|
|
655 |
break;
|
|
|
656 |
case 2:
|
|
|
657 |
JSONObject propsAmazon = new JSONObject();
|
|
|
658 |
try {
|
|
|
659 |
mixpanel.identify(userData.getString("id",null));
|
|
|
660 |
propsAmazon.put("Screen", "Amazon");
|
|
|
661 |
mixpanel.track("Amazon", propsAmazon);
|
|
|
662 |
} catch (JSONException e) {
|
|
|
663 |
e.printStackTrace();
|
|
|
664 |
}
|
|
|
665 |
t.send(new HitBuilders.EventBuilder()
|
|
|
666 |
.setCategory("Menu")
|
|
|
667 |
.setAction("Amazon ")
|
|
|
668 |
.setLabel("Amazon Clicked")
|
|
|
669 |
.build());
|
|
|
670 |
args.putString("key", apiData.getString("affiliate.url.redirect","")+"?user_id="+userData.getString("id","")+"&store_id="+apiData.getString("store.code.amazon",""));
|
|
|
671 |
fragment = new DealsHomeFragment();
|
|
|
672 |
fragment.setArguments(args);
|
|
|
673 |
break;
|
|
|
674 |
case 3:
|
|
|
675 |
JSONObject propsFlipkart = new JSONObject();
|
|
|
676 |
try {
|
|
|
677 |
mixpanel.identify(userData.getString("id",null));
|
|
|
678 |
propsFlipkart.put("Screen", "Flipkart");
|
|
|
679 |
mixpanel.track("Flipkart", propsFlipkart);
|
|
|
680 |
} catch (JSONException e) {
|
|
|
681 |
e.printStackTrace();
|
|
|
682 |
}
|
|
|
683 |
t.send(new HitBuilders.EventBuilder()
|
|
|
684 |
.setCategory("Menu")
|
|
|
685 |
.setAction("Flipkart ")
|
|
|
686 |
.setLabel("Flipkart Clicked")
|
|
|
687 |
.build());
|
|
|
688 |
args.putString("key", apiData.getString("affiliate.url.redirect","")+"?user_id="+userData.getString("id","")+"&store_id="+apiData.getString("store.code.flipkart",""));
|
|
|
689 |
fragment = new DealsHomeFragment();
|
|
|
690 |
fragment.setArguments(args);
|
|
|
691 |
break;
|
|
|
692 |
case 4:
|
|
|
693 |
JSONObject propsSaholic = new JSONObject();
|
|
|
694 |
try {
|
|
|
695 |
mixpanel.identify(userData.getString("id",null));
|
|
|
696 |
propsSaholic.put("Screen", "Saholic");
|
|
|
697 |
mixpanel.track("Saholic", propsSaholic);
|
|
|
698 |
} catch (JSONException e) {
|
|
|
699 |
e.printStackTrace();
|
|
|
700 |
}
|
|
|
701 |
t.send(new HitBuilders.EventBuilder()
|
|
|
702 |
.setCategory("Menu")
|
|
|
703 |
.setAction("Saholic ")
|
|
|
704 |
.setLabel("Saholic Clicked")
|
|
|
705 |
.build());
|
|
|
706 |
args.putString("key", apiData.getString("saholic.autologin.url","")+"?user_id="+userData.getString("id",""));
|
|
|
707 |
fragment = new DealsHomeFragment();
|
|
|
708 |
fragment.setArguments(args);
|
|
|
709 |
break;
|
|
|
710 |
case 5:
|
|
|
711 |
JSONObject propsSnapdeal = new JSONObject();
|
|
|
712 |
try {
|
|
|
713 |
mixpanel.identify(userData.getString("id",null));
|
|
|
714 |
propsSnapdeal.put("Screen", "Snapdeal");
|
|
|
715 |
mixpanel.track("Snapdeal", propsSnapdeal);
|
|
|
716 |
} catch (JSONException e) {
|
|
|
717 |
e.printStackTrace();
|
|
|
718 |
}
|
|
|
719 |
t.send(new HitBuilders.EventBuilder()
|
|
|
720 |
.setCategory("Menu")
|
|
|
721 |
.setAction("Snapdeal ")
|
|
|
722 |
.setLabel("Snapdeal Clicked")
|
|
|
723 |
.build());
|
|
|
724 |
args.putString("key", apiData.getString("affiliate.url.redirect","")+"?user_id="+userData.getString("id","")+"&store_id="+apiData.getString("store.code.snapdeal",""));
|
|
|
725 |
fragment = new DealsHomeFragment();
|
|
|
726 |
fragment.setArguments(args);
|
|
|
727 |
break;
|
|
|
728 |
case 6:
|
|
|
729 |
JSONObject propsContactUs = new JSONObject();
|
|
|
730 |
try {
|
|
|
731 |
mixpanel.identify(userData.getString("id",null));
|
|
|
732 |
propsContactUs.put("Screen", "Contact Us");
|
|
|
733 |
mixpanel.track("Contact Us", propsContactUs);
|
|
|
734 |
} catch (JSONException e) {
|
|
|
735 |
e.printStackTrace();
|
|
|
736 |
}
|
|
|
737 |
t.send(new HitBuilders.EventBuilder()
|
|
|
738 |
.setCategory("Menu")
|
|
|
739 |
.setAction("Contact Us ")
|
|
|
740 |
.setLabel("Contact us Clicked")
|
|
|
741 |
.build());
|
|
|
742 |
fragment = new ContactUsFragment();
|
|
|
743 |
break;
|
|
|
744 |
case 7:
|
|
|
745 |
JSONObject propsHowItWorks = new JSONObject();
|
|
|
746 |
try {
|
|
|
747 |
mixpanel.identify(userData.getString("id",null));
|
|
|
748 |
propsHowItWorks.put("Screen", "How it Works");
|
|
|
749 |
mixpanel.track("How it Works", propsHowItWorks);
|
|
|
750 |
} catch (JSONException e) {
|
|
|
751 |
e.printStackTrace();
|
|
|
752 |
}
|
|
|
753 |
t.send(new HitBuilders.EventBuilder()
|
|
|
754 |
.setCategory("Menu")
|
|
|
755 |
.setAction("Tutorials ")
|
|
|
756 |
.setLabel("Tutorials Clicked")
|
|
|
757 |
.build());
|
|
|
758 |
fragment = new HowItWorksFragment();
|
|
|
759 |
break;
|
|
|
760 |
case 8:
|
|
|
761 |
JSONObject propsAboutUs = new JSONObject();
|
|
|
762 |
try {
|
|
|
763 |
mixpanel.identify(userData.getString("id",null));
|
|
|
764 |
propsAboutUs.put("Screen", "About Us");
|
|
|
765 |
mixpanel.track("About Us", propsAboutUs);
|
|
|
766 |
} catch (JSONException e) {
|
|
|
767 |
e.printStackTrace();
|
|
|
768 |
}
|
|
|
769 |
t.send(new HitBuilders.EventBuilder()
|
|
|
770 |
.setCategory("Menu")
|
|
|
771 |
.setAction("About Us ")
|
|
|
772 |
.setLabel("About us Clicked")
|
|
|
773 |
.build());
|
|
|
774 |
fragment = new AboutUsFragment();
|
|
|
775 |
break;
|
|
|
776 |
default:
|
|
|
777 |
break;
|
|
|
778 |
}
|
|
|
779 |
if (fragment != null) {
|
|
|
780 |
FragmentManager fragmentManager = getFragmentManager();
|
|
|
781 |
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
|
|
|
782 |
mDrawerList.setItemChecked(position, true);
|
|
|
783 |
mDrawerList.setSelection(position);
|
|
|
784 |
setTitle(navMenuTitles[position]);
|
|
|
785 |
mDrawerLayout.closeDrawer(mDrawerList);
|
|
|
786 |
} else {
|
|
|
787 |
Log.e("MainActivity", "Error in creating fragment");
|
|
|
788 |
}
|
|
|
789 |
}
|
|
|
790 |
|
|
|
791 |
|
|
|
792 |
|
|
|
793 |
@Override
|
|
|
794 |
protected void onPostCreate(Bundle savedInstanceState) {
|
|
|
795 |
super.onPostCreate(savedInstanceState);
|
|
|
796 |
mDrawerToggle.syncState();
|
|
|
797 |
}
|
|
|
798 |
|
|
|
799 |
@Override
|
|
|
800 |
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
801 |
boolean drawerOpen = shouldGoInvisible;
|
|
|
802 |
hideMenuItems(menu, !drawerOpen);
|
|
|
803 |
return super.onPrepareOptionsMenu(menu);
|
|
|
804 |
}
|
|
|
805 |
private void hideMenuItems(Menu menu, boolean visible)
|
|
|
806 |
{
|
|
|
807 |
for(int i = 0; i < menu.size(); i++){
|
|
|
808 |
menu.getItem(i).setVisible(visible);
|
|
|
809 |
}
|
|
|
810 |
}
|
|
|
811 |
@Override
|
|
|
812 |
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
813 |
super.onConfigurationChanged(newConfig);
|
|
|
814 |
mDrawerToggle.onConfigurationChanged(newConfig);
|
|
|
815 |
}
|
|
|
816 |
@Override
|
|
|
817 |
public boolean onKeyUp(int keycode, KeyEvent e) {
|
|
|
818 |
switch(keycode) {
|
|
|
819 |
case KeyEvent.KEYCODE_MENU:
|
|
|
820 |
|
|
|
821 |
if (mainMenu !=null) {
|
|
|
822 |
mainMenu.performIdentifierAction(R.id.overflowMenu,0);
|
|
|
823 |
}
|
|
|
824 |
}
|
|
|
825 |
|
|
|
826 |
return super.onKeyUp(keycode, e);
|
|
|
827 |
}
|
|
|
828 |
@Override
|
|
|
829 |
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
830 |
|
|
|
831 |
switch(keyCode) {
|
|
|
832 |
case KeyEvent.KEYCODE_MENU:
|
|
|
833 |
if (mainMenu !=null) {
|
|
|
834 |
mainMenu.performIdentifierAction(R.id.overflowMenu,0);
|
|
|
835 |
}
|
|
|
836 |
}
|
|
|
837 |
return super.onKeyUp(keyCode, event);
|
|
|
838 |
}
|
|
|
839 |
private Menu mainMenu;
|
|
|
840 |
public final boolean isInternetOn() {
|
|
|
841 |
|
|
|
842 |
ConnectivityManager connec =
|
|
|
843 |
(ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
844 |
|
|
|
845 |
if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
846 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
847 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
848 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
849 |
|
|
|
850 |
Toast.makeText(this, " Connected ", Toast.LENGTH_LONG).show();
|
|
|
851 |
return true;
|
|
|
852 |
|
|
|
853 |
} else if (
|
|
|
854 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
855 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
856 |
|
|
|
857 |
Toast.makeText(this, " Not Connected ", Toast.LENGTH_LONG).show();
|
|
|
858 |
return false;
|
|
|
859 |
}
|
|
|
860 |
return false;
|
|
|
861 |
}
|
|
|
862 |
class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
|
|
863 |
|
|
|
864 |
@Override
|
|
|
865 |
protected void onPreExecute() {
|
|
|
866 |
super.onPreExecute();
|
|
|
867 |
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
@Override
|
|
|
871 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
|
|
872 |
|
|
|
873 |
try {
|
|
|
874 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
875 |
HttpPost httppost = new HttpPost(apiData.getString("notification.data.url","http://api.profittill.com/pushnotifications/add"));
|
|
|
876 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
877 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
878 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
879 |
HttpEntity entity = response.getEntity();
|
|
|
880 |
int status = response.getStatusLine().getStatusCode();
|
|
|
881 |
|
|
|
882 |
if(status == 200){
|
|
|
883 |
Log.d("Notification Opened","Notication opened and main activity page and sent successfully");
|
|
|
884 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
885 |
} else {
|
|
|
886 |
Log.d("ResponseCode GCM ",status+"");
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
nameValuePairsGcm.clear();
|
|
|
890 |
Log.e("pass 1", "connection success ");
|
|
|
891 |
} catch (Exception e) {
|
|
|
892 |
Log.e("Fail 1", e.toString());
|
|
|
893 |
|
|
|
894 |
}
|
|
|
895 |
return "success";
|
|
|
896 |
}
|
|
|
897 |
|
|
|
898 |
@Override
|
|
|
899 |
protected void onPostExecute(String result) {
|
|
|
900 |
super.onPostExecute(result);
|
|
|
901 |
Log.d("Notification Opened","Notication opened and main activity page");
|
|
|
902 |
}
|
|
|
903 |
}
|
|
|
904 |
}
|