| Line 1... |
Line 1... |
| 1 |
package com.saholic.profittill.main;
|
1 |
package com.saholic.profittill.main;
|
| - |
|
2 |
import android.app.AlarmManager;
|
| 2 |
import android.app.Fragment;
|
3 |
import android.app.Fragment;
|
| 3 |
import android.app.FragmentManager;
|
4 |
import android.app.FragmentManager;
|
| - |
|
5 |
import android.app.PendingIntent;
|
| 4 |
import android.content.Context;
|
6 |
import android.content.Context;
|
| 5 |
import android.content.Intent;
|
7 |
import android.content.Intent;
|
| 6 |
import android.content.SharedPreferences;
|
8 |
import android.content.SharedPreferences;
|
| 7 |
import android.content.res.Configuration;
|
9 |
import android.content.res.Configuration;
|
| 8 |
import android.graphics.Color;
|
10 |
import android.graphics.Color;
|
| Line 10... |
Line 12... |
| 10 |
import android.net.ConnectivityManager;
|
12 |
import android.net.ConnectivityManager;
|
| 11 |
import android.net.Uri;
|
13 |
import android.net.Uri;
|
| 12 |
import android.os.AsyncTask;
|
14 |
import android.os.AsyncTask;
|
| 13 |
import android.os.Bundle;
|
15 |
import android.os.Bundle;
|
| 14 |
import android.os.PersistableBundle;
|
16 |
import android.os.PersistableBundle;
|
| - |
|
17 |
import android.os.SystemClock;
|
| 15 |
import android.support.v4.app.ActionBarDrawerToggle;
|
18 |
import android.support.v4.app.ActionBarDrawerToggle;
|
| 16 |
import android.support.v4.widget.DrawerLayout;
|
19 |
import android.support.v4.widget.DrawerLayout;
|
| 17 |
import android.support.v7.app.ActionBarActivity;
|
20 |
import android.support.v7.app.ActionBarActivity;
|
| 18 |
import android.util.Log;
|
21 |
import android.util.Log;
|
| 19 |
import android.view.KeyEvent;
|
22 |
import android.view.KeyEvent;
|
| Line 23... |
Line 26... |
| 23 |
import android.view.ViewConfiguration;
|
26 |
import android.view.ViewConfiguration;
|
| 24 |
import android.view.Window;
|
27 |
import android.view.Window;
|
| 25 |
import android.webkit.CookieManager;
|
28 |
import android.webkit.CookieManager;
|
| 26 |
import android.webkit.CookieSyncManager;
|
29 |
import android.webkit.CookieSyncManager;
|
| 27 |
import android.widget.ExpandableListView;
|
30 |
import android.widget.ExpandableListView;
|
| - |
|
31 |
import android.widget.ImageView;
|
| 28 |
import android.widget.LinearLayout;
|
32 |
import android.widget.LinearLayout;
|
| - |
|
33 |
import android.widget.RelativeLayout;
|
| - |
|
34 |
import android.widget.TextView;
|
| - |
|
35 |
|
| 29 |
import com.facebook.Session;
|
36 |
import com.facebook.Session;
|
| 30 |
import com.google.android.gms.analytics.HitBuilders;
|
37 |
import com.google.android.gms.analytics.HitBuilders;
|
| 31 |
import com.google.android.gms.analytics.Tracker;
|
38 |
import com.google.android.gms.analytics.Tracker;
|
| 32 |
import com.google.android.gms.common.ConnectionResult;
|
39 |
import com.google.android.gms.common.ConnectionResult;
|
| 33 |
import com.google.android.gms.common.api.GoogleApiClient;
|
40 |
import com.google.android.gms.common.api.GoogleApiClient;
|
| 34 |
import com.google.android.gms.plus.Plus;
|
41 |
import com.google.android.gms.plus.Plus;
|
| 35 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
42 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
| 36 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
43 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
| - |
|
44 |
import com.saholic.profittill.Network.NotificationCount;
|
| 37 |
import com.saholic.profittill.R;
|
45 |
import com.saholic.profittill.R;
|
| - |
|
46 |
import com.saholic.profittill.Services.PollingService;
|
| 38 |
import com.saholic.profittill.Utils.AnalyticsUtility;
|
47 |
import com.saholic.profittill.Utils.AnalyticsUtility;
|
| 39 |
import com.saholic.profittill.Utils.DESEncrypter;
|
48 |
import com.saholic.profittill.Utils.DESEncrypter;
|
| 40 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
49 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
| 41 |
import com.saholic.profittill.Volley.Analytics;
|
50 |
import com.saholic.profittill.Volley.Analytics;
|
| 42 |
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
|
51 |
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
|
| Line 580... |
Line 589... |
| 580 |
@Override
|
589 |
@Override
|
| 581 |
public boolean onCreateOptionsMenu(Menu menu) {
|
590 |
public boolean onCreateOptionsMenu(Menu menu) {
|
| 582 |
mainMenu=menu;
|
591 |
mainMenu=menu;
|
| 583 |
super.onCreateOptionsMenu(menu);
|
592 |
super.onCreateOptionsMenu(menu);
|
| 584 |
getMenuInflater().inflate(R.menu.menu_main, menu);
|
593 |
getMenuInflater().inflate(R.menu.menu_main, menu);
|
| - |
|
594 |
RelativeLayout badgeLayout = (RelativeLayout) mainMenu.findItem(R.id.action_notifications).getActionView();
|
| - |
|
595 |
ImageView k = (ImageView) badgeLayout.findViewById(R.id.inAppNotificationImage);
|
| - |
|
596 |
TextView notifciationCount = (TextView) badgeLayout.findViewById(R.id.inAppNotificationText);
|
| - |
|
597 |
k.setOnClickListener(new View.OnClickListener() {
|
| - |
|
598 |
@Override
|
| - |
|
599 |
public void onClick(View v) {
|
| - |
|
600 |
Bundle args = new Bundle();
|
| - |
|
601 |
args.putString("key", apiData.getString("notification.page.url", "http://api.profittill.com/users/usernotification") + "?user_id=" + userData.getString("id", "") + "&android_id=" + UtilityFunctions.androidId(MainActivity.this));
|
| - |
|
602 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
| - |
|
603 |
AnalyticsUtility.getAnalyticsRequest(MainActivity.this,userData.getString("id",""),"Notification","Notification Icon","Notification Icon Clicked"),
|
| - |
|
604 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
| - |
|
605 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(MainActivity.this);
|
| - |
|
606 |
|
| - |
|
607 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
| - |
|
608 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
| - |
|
609 |
t.send(new HitBuilders.EventBuilder()
|
| - |
|
610 |
.setCategory("Menu")
|
| - |
|
611 |
.setAction("Search ")
|
| - |
|
612 |
.setLabel("Search Clicked")
|
| - |
|
613 |
.build());
|
| - |
|
614 |
DealsHomeFragment notificationFragment = new DealsHomeFragment();
|
| - |
|
615 |
getFragmentManager().beginTransaction()
|
| - |
|
616 |
.replace(R.id.frame_container, notificationFragment, "Mike")
|
| - |
|
617 |
.addToBackStack(null)
|
| - |
|
618 |
.commit();
|
| - |
|
619 |
notificationFragment.setArguments(args);
|
| - |
|
620 |
}
|
| - |
|
621 |
});
|
| 585 |
|
622 |
|
| - |
|
623 |
if(userData.getInt("notification_count",0)!=0) {
|
| - |
|
624 |
notifciationCount.setVisibility(View.VISIBLE);
|
| - |
|
625 |
notifciationCount.setText(userData.getInt("notification_count",0)+"");
|
| - |
|
626 |
}else{
|
| - |
|
627 |
notifciationCount.setVisibility(View.GONE);
|
| - |
|
628 |
}
|
| 586 |
return true;
|
629 |
return true;
|
| 587 |
}
|
630 |
}
|
| 588 |
|
631 |
|
| 589 |
@Override
|
632 |
@Override
|
| 590 |
public boolean onOptionsItemSelected(MenuItem item) {
|
633 |
public boolean onOptionsItemSelected(MenuItem item) {
|
| Line 596... |
Line 639... |
| 596 |
return true;
|
639 |
return true;
|
| 597 |
}
|
640 |
}
|
| 598 |
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
641 |
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
| 599 |
switch (item.getItemId()) {
|
642 |
switch (item.getItemId()) {
|
| 600 |
case R.id.action_settings:
|
643 |
case R.id.action_settings:
|
| - |
|
644 |
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
|
| - |
|
645 |
Intent i = new Intent(this, PollingService.class);
|
| - |
|
646 |
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
|
| - |
|
647 |
am.cancel(pi);
|
| - |
|
648 |
userDataEditor.putString("alarm_set","false").commit();
|
| 601 |
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
|
649 |
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
|
| 602 |
android.webkit.CookieSyncManager.createInstance(this);
|
650 |
android.webkit.CookieSyncManager.createInstance(this);
|
| 603 |
cookieManager.removeAllCookie();
|
651 |
cookieManager.removeAllCookie();
|
| 604 |
try {
|
652 |
try {
|
| 605 |
mixpanel.identify(userData.getString("id",null));
|
653 |
mixpanel.identify(userData.getString("id",null));
|
| Line 778... |
Line 826... |
| 778 |
}
|
826 |
}
|
| 779 |
|
827 |
|
| 780 |
|
828 |
|
| 781 |
}
|
829 |
}
|
| 782 |
public void signOutFromGplus() {
|
830 |
public void signOutFromGplus() {
|
| 783 |
|
- |
|
| 784 |
|
- |
|
| 785 |
if (mGoogleApiClient.isConnected()) {
|
831 |
if (mGoogleApiClient.isConnected()) {
|
| 786 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
832 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
| 787 |
mGoogleApiClient.disconnect();
|
833 |
mGoogleApiClient.disconnect();
|
| 788 |
mGoogleApiClient.connect();
|
834 |
mGoogleApiClient.connect();
|
| 789 |
glogout=true;
|
835 |
glogout=true;
|
| Line 975... |
Line 1021... |
| 975 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
1021 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
| 976 |
AnalyticsUtility.getAnalyticsRequest(MainActivity.this,userData.getString("id",""),"Menu","HomeShop18","HomeShop18 Clicked"),
|
1022 |
AnalyticsUtility.getAnalyticsRequest(MainActivity.this,userData.getString("id",""),"Menu","HomeShop18","HomeShop18 Clicked"),
|
| 977 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
1023 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
| 978 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(MainActivity.this);
|
1024 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(MainActivity.this);
|
| 979 |
args.putString("key", apiData.getString("affiliate.url.redirect","")+"?user_id="+userData.getString("id","")+"&store_id="+UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code","amazon=1,flipkart=2,snapdeal=3,spice=4,shopclues=5,paytm=6,homeshop18=7,")),ProfitTillConstants.HOMESHOP18));
|
1025 |
args.putString("key", apiData.getString("affiliate.url.redirect","")+"?user_id="+userData.getString("id","")+"&store_id="+UtilityFunctions.getNewStoreId(UtilityFunctions.generateStoreMap(apiData.getString("stores.code","amazon=1,flipkart=2,snapdeal=3,spice=4,shopclues=5,paytm=6,homeshop18=7,")),ProfitTillConstants.HOMESHOP18));
|
| 980 |
//args.putString("key","https://paytm.com");
|
- |
|
| 981 |
fragment = new DealsHomeFragment();
|
1026 |
fragment = new DealsHomeFragment();
|
| 982 |
fragment.setArguments(args);
|
1027 |
fragment.setArguments(args);
|
| 983 |
break;
|
1028 |
break;
|
| 984 |
case 3:
|
1029 |
case 3:
|
| 985 |
t.send(new HitBuilders.EventBuilder()
|
1030 |
t.send(new HitBuilders.EventBuilder()
|
| Line 1172... |
Line 1217... |
| 1172 |
class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
1217 |
class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
| 1173 |
|
1218 |
|
| 1174 |
@Override
|
1219 |
@Override
|
| 1175 |
protected void onPreExecute() {
|
1220 |
protected void onPreExecute() {
|
| 1176 |
super.onPreExecute();
|
1221 |
super.onPreExecute();
|
| 1177 |
|
- |
|
| 1178 |
}
|
1222 |
}
|
| 1179 |
|
1223 |
|
| 1180 |
@Override
|
1224 |
@Override
|
| 1181 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
1225 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
| 1182 |
|
1226 |
|
| Line 1199... |
Line 1243... |
| 1199 |
@Override
|
1243 |
@Override
|
| 1200 |
protected void onPostExecute(String result) {
|
1244 |
protected void onPostExecute(String result) {
|
| 1201 |
super.onPostExecute(result);
|
1245 |
super.onPostExecute(result);
|
| 1202 |
}
|
1246 |
}
|
| 1203 |
}
|
1247 |
}
|
| - |
|
1248 |
@Override
|
| - |
|
1249 |
protected void onResume() {
|
| - |
|
1250 |
super.onResume();
|
| - |
|
1251 |
String userId = userData.getString("id","");
|
| - |
|
1252 |
String androidId=UtilityFunctions.androidId(MainActivity.this);
|
| - |
|
1253 |
if(!userId.isEmpty() && !androidId.isEmpty()) {
|
| - |
|
1254 |
String notificationUrl = apiData.getString("notification.count", "http://45.33.50.227:3001/getNotificationCount") + "?user_id=" + userId + "&android_id=" + androidId;
|
| - |
|
1255 |
new NotificationCount().getCount(MainActivity.this, null, notificationUrl);
|
| - |
|
1256 |
}
|
| - |
|
1257 |
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
|
| - |
|
1258 |
Intent i = new Intent(this, PollingService.class);
|
| - |
|
1259 |
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
|
| - |
|
1260 |
am.cancel(pi);
|
| - |
|
1261 |
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 1000, 30 * 60 * 1000, pi);
|
| - |
|
1262 |
invalidateOptionsMenu();
|
| - |
|
1263 |
}
|
| 1204 |
}
|
1264 |
}
|
| 1205 |
|
1265 |
|