| Line 1... |
Line 1... |
| 1 |
package com.saholic.profittill.main;
|
1 |
package com.saholic.profittill.main;
|
| 2 |
|
2 |
|
| 3 |
import android.app.Activity;
|
3 |
import android.app.Fragment;
|
| 4 |
import android.app.AlertDialog;
|
- |
|
| 5 |
import android.app.ProgressDialog;
|
4 |
import android.app.ProgressDialog;
|
| 6 |
import android.content.Context;
|
5 |
import android.content.Context;
|
| 7 |
import android.content.DialogInterface;
|
- |
|
| 8 |
import android.content.Intent;
|
6 |
import android.content.Intent;
|
| 9 |
import android.content.SharedPreferences;
|
7 |
import android.content.SharedPreferences;
|
| 10 |
import android.graphics.Bitmap;
|
8 |
import android.graphics.Bitmap;
|
| 11 |
import android.net.ConnectivityManager;
|
9 |
import android.net.ConnectivityManager;
|
| 12 |
import android.net.Uri;
|
10 |
import android.net.Uri;
|
| 13 |
import android.os.AsyncTask;
|
11 |
import android.os.AsyncTask;
|
| 14 |
import android.os.Bundle;
|
12 |
import android.os.Bundle;
|
| 15 |
import android.app.Fragment;
|
- |
|
| 16 |
import android.util.Base64;
|
- |
|
| 17 |
import android.util.Log;
|
13 |
import android.util.Log;
|
| 18 |
import android.view.KeyEvent;
|
14 |
import android.view.KeyEvent;
|
| 19 |
import android.view.LayoutInflater;
|
15 |
import android.view.LayoutInflater;
|
| 20 |
import android.view.View;
|
16 |
import android.view.View;
|
| 21 |
import android.view.ViewGroup;
|
17 |
import android.view.ViewGroup;
|
| - |
|
18 |
import android.webkit.CookieManager;
|
| - |
|
19 |
import android.webkit.CookieSyncManager;
|
| 22 |
import android.webkit.HttpAuthHandler;
|
20 |
import android.webkit.HttpAuthHandler;
|
| 23 |
import android.webkit.JavascriptInterface;
|
- |
|
| 24 |
import android.webkit.WebView;
|
21 |
import android.webkit.WebView;
|
| 25 |
import android.webkit.WebViewClient;
|
22 |
import android.webkit.WebViewClient;
|
| 26 |
import android.widget.Toast;
|
- |
|
| 27 |
|
23 |
|
| 28 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
24 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
| 29 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
25 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
| 30 |
import com.saholic.profittill.R;
|
26 |
import com.saholic.profittill.R;
|
| 31 |
import com.testin.agent.TestinAgent;
|
27 |
import com.testin.agent.TestinAgent;
|
| 32 |
|
28 |
|
| 33 |
import org.apache.http.HttpEntity;
|
- |
|
| 34 |
import org.apache.http.HttpResponse;
|
29 |
import org.apache.http.HttpResponse;
|
| 35 |
import org.apache.http.NameValuePair;
|
30 |
import org.apache.http.NameValuePair;
|
| 36 |
import org.apache.http.client.ClientProtocolException;
|
31 |
import org.apache.http.client.ClientProtocolException;
|
| 37 |
import org.apache.http.client.HttpClient;
|
32 |
import org.apache.http.client.HttpClient;
|
| 38 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
33 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| Line 42... |
Line 37... |
| 42 |
import org.apache.http.message.BasicNameValuePair;
|
37 |
import org.apache.http.message.BasicNameValuePair;
|
| 43 |
import org.json.JSONArray;
|
38 |
import org.json.JSONArray;
|
| 44 |
import org.json.JSONException;
|
39 |
import org.json.JSONException;
|
| 45 |
import org.json.JSONObject;
|
40 |
import org.json.JSONObject;
|
| 46 |
|
41 |
|
| 47 |
import java.io.BufferedReader;
|
- |
|
| 48 |
import java.io.IOException;
|
42 |
import java.io.IOException;
|
| 49 |
import java.io.InputStream;
|
- |
|
| 50 |
import java.io.InputStreamReader;
|
- |
|
| 51 |
import java.text.SimpleDateFormat;
|
43 |
import java.text.SimpleDateFormat;
|
| 52 |
import java.util.ArrayList;
|
44 |
import java.util.ArrayList;
|
| 53 |
import java.util.Date;
|
45 |
import java.util.Date;
|
| 54 |
import java.util.StringTokenizer;
|
- |
|
| 55 |
|
46 |
|
| 56 |
public class PreferencesFragment extends Fragment {
|
47 |
public class PreferencesFragment extends Fragment {
|
| 57 |
WebView preferencesWebView;
|
48 |
WebView preferencesWebView;
|
| 58 |
SharedPreferences userData;
|
49 |
SharedPreferences userData;
|
| 59 |
SharedPreferences apiData;
|
50 |
SharedPreferences apiData;
|
| Line 68... |
Line 59... |
| 68 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
59 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
| 69 |
userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
60 |
userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
| 70 |
apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
61 |
apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
| 71 |
userDataEditor = userData.edit();
|
62 |
userDataEditor = userData.edit();
|
| 72 |
apiSettingsEditor = apiData.edit();
|
63 |
apiSettingsEditor = apiData.edit();
|
| 73 |
String url = apiData.getString("preferences.url",null);
|
64 |
String url=apiData.getString("preferences.url", null);;
|
| 74 |
String id = userData.getString("id",null);
|
65 |
String id = userData.getString("id", null);
|
| - |
|
66 |
String landingUrl;
|
| - |
|
67 |
if(userData.getString("preferences","false").equalsIgnoreCase("true")) {
|
| - |
|
68 |
landingUrl =url+"?user_id="+id+"&firsttime=1";
|
| - |
|
69 |
}else {
|
| - |
|
70 |
landingUrl=url+"?user_id="+id;
|
| - |
|
71 |
}
|
| 75 |
TestinAgent.setUserInfo(userData.getString("id", ""));
|
72 |
TestinAgent.setUserInfo(userData.getString("id", ""));
|
| 76 |
String landingUrl = url+"?user_id="+id;
|
- |
|
| 77 |
JSONObject props = new JSONObject();
|
73 |
JSONObject props = new JSONObject();
|
| 78 |
try {
|
74 |
try {
|
| 79 |
mixpanel.identify(userData.getString("id",null));
|
75 |
mixpanel.identify(userData.getString("id",null));
|
| 80 |
props.put("Screen", "My Preferences");
|
76 |
props.put("Screen", "My Preferences");
|
| 81 |
mixpanel.track("My Preferences", props);
|
77 |
mixpanel.track("My Preferences", props);
|
| Line 88... |
Line 84... |
| 88 |
preferencesWebView = (WebView)rootView.findViewById(R.id.preferencesWebView);
|
84 |
preferencesWebView = (WebView)rootView.findViewById(R.id.preferencesWebView);
|
| 89 |
preferencesWebView.setClickable(true);
|
85 |
preferencesWebView.setClickable(true);
|
| 90 |
preferencesWebView.setFocusableInTouchMode(true);
|
86 |
preferencesWebView.setFocusableInTouchMode(true);
|
| 91 |
preferencesWebView.getSettings().setJavaScriptEnabled(true);
|
87 |
preferencesWebView.getSettings().setJavaScriptEnabled(true);
|
| 92 |
preferencesWebView.getSettings().setBuiltInZoomControls(true);
|
88 |
preferencesWebView.getSettings().setBuiltInZoomControls(true);
|
| - |
|
89 |
if(Uri.parse(landingUrl).getHost().equalsIgnoreCase(ProfitTillConstants.DOMAIN)) {
|
| - |
|
90 |
CookieSyncManager.createInstance(getActivity());
|
| - |
|
91 |
CookieManager cookieManager1 = CookieManager.getInstance();
|
| - |
|
92 |
cookieManager1.setCookie(url, "token=" + userData.getString("token", ""));
|
| - |
|
93 |
cookieManager1.setCookie(url, "walletAuthentication=true");
|
| - |
|
94 |
cookieManager1.setCookie(url, "shopcluesActive=true");
|
| - |
|
95 |
}
|
| 93 |
preferencesWebView.loadUrl(url+"?user_id="+id);
|
96 |
preferencesWebView.loadUrl(landingUrl);
|
| 94 |
preferencesWebView.setWebViewClient(webViewClient);
|
97 |
preferencesWebView.setWebViewClient(webViewClient);
|
| 95 |
}
|
98 |
}
|
| 96 |
else{
|
99 |
else{
|
| 97 |
SearchFragment nextFrag= new SearchFragment();
|
100 |
SearchFragment nextFrag= new SearchFragment();
|
| 98 |
Bundle args = new Bundle();
|
101 |
Bundle args = new Bundle();
|
| Line 103... |
Line 106... |
| 103 |
.replace(R.id.frame_container, nextFrag)
|
106 |
.replace(R.id.frame_container, nextFrag)
|
| 104 |
.addToBackStack(null)
|
107 |
.addToBackStack(null)
|
| 105 |
.commit();
|
108 |
.commit();
|
| 106 |
}
|
109 |
}
|
| 107 |
|
110 |
|
| 108 |
|
- |
|
| 109 |
return rootView;
|
111 |
return rootView;
|
| 110 |
}
|
112 |
}
|
| 111 |
|
113 |
|
| 112 |
@Override
|
114 |
@Override
|
| 113 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
115 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
| Line 184... |
Line 186... |
| 184 |
HttpAuthHandler handler, String host, String realm) {
|
186 |
HttpAuthHandler handler, String host, String realm) {
|
| 185 |
|
187 |
|
| 186 |
handler.proceed("dtr", "dtr18Feb2015");
|
188 |
handler.proceed("dtr", "dtr18Feb2015");
|
| 187 |
|
189 |
|
| 188 |
}
|
190 |
}
|
| - |
|
191 |
|
| - |
|
192 |
@Override
|
| - |
|
193 |
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
| - |
|
194 |
super.shouldOverrideUrlLoading(view, url);
|
| - |
|
195 |
|
| - |
|
196 |
if(url.contains(apiData.getString("mobile.website.url",""))){
|
| - |
|
197 |
Intent i = new Intent(getActivity(),MainActivity.class);
|
| - |
|
198 |
i.putExtra("displayView","0");
|
| - |
|
199 |
startActivity(i);
|
| - |
|
200 |
}
|
| - |
|
201 |
|
| - |
|
202 |
return false;
|
| - |
|
203 |
}
|
| 189 |
}
|
204 |
}
|
| 190 |
@Override
|
205 |
@Override
|
| 191 |
public void onResume() {
|
206 |
public void onResume() {
|
| 192 |
super.onResume();
|
207 |
super.onResume();
|
| 193 |
getView().setFocusableInTouchMode(true);
|
208 |
getView().setFocusableInTouchMode(true);
|