| 14792 |
manas |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.Activity;
|
|
|
4 |
import android.app.AlertDialog;
|
|
|
5 |
import android.app.ProgressDialog;
|
|
|
6 |
import android.content.Context;
|
|
|
7 |
import android.content.DialogInterface;
|
|
|
8 |
import android.content.Intent;
|
|
|
9 |
import android.content.SharedPreferences;
|
|
|
10 |
import android.graphics.Bitmap;
|
|
|
11 |
import android.net.ConnectivityManager;
|
|
|
12 |
import android.net.Uri;
|
|
|
13 |
import android.os.AsyncTask;
|
|
|
14 |
import android.os.Bundle;
|
|
|
15 |
import android.app.Fragment;
|
|
|
16 |
import android.util.Log;
|
|
|
17 |
import android.view.KeyEvent;
|
|
|
18 |
import android.view.LayoutInflater;
|
|
|
19 |
import android.view.View;
|
|
|
20 |
import android.view.ViewGroup;
|
|
|
21 |
import android.webkit.CookieManager;
|
|
|
22 |
import android.webkit.HttpAuthHandler;
|
|
|
23 |
import android.webkit.WebView;
|
|
|
24 |
import android.webkit.WebViewClient;
|
|
|
25 |
|
|
|
26 |
import com.google.android.gms.analytics.GoogleAnalytics;
|
|
|
27 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
28 |
import com.google.android.gms.analytics.Tracker;
|
|
|
29 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
30 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
31 |
import com.saholic.profittill.R;
|
|
|
32 |
import com.testin.agent.TestinAgent;
|
|
|
33 |
|
|
|
34 |
import org.apache.http.HttpResponse;
|
|
|
35 |
import org.apache.http.NameValuePair;
|
|
|
36 |
import org.apache.http.client.ClientProtocolException;
|
|
|
37 |
import org.apache.http.client.HttpClient;
|
|
|
38 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
39 |
import org.apache.http.client.methods.HttpPost;
|
|
|
40 |
import org.apache.http.entity.StringEntity;
|
|
|
41 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
42 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
43 |
import org.json.JSONArray;
|
|
|
44 |
import org.json.JSONException;
|
|
|
45 |
import org.json.JSONObject;
|
|
|
46 |
|
|
|
47 |
import java.io.IOException;
|
|
|
48 |
import java.text.SimpleDateFormat;
|
|
|
49 |
import java.util.ArrayList;
|
|
|
50 |
import java.util.Date;
|
|
|
51 |
|
|
|
52 |
public class MyWallet extends Fragment {
|
|
|
53 |
WebView myWalletWebView;
|
|
|
54 |
SharedPreferences userData;
|
|
|
55 |
SharedPreferences apiData;
|
|
|
56 |
SharedPreferences.Editor userDataEditor;
|
|
|
57 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
58 |
|
|
|
59 |
public MyWallet() {
|
|
|
60 |
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
@Override
|
|
|
65 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
66 |
Bundle savedInstanceState) {
|
|
|
67 |
// Inflate the layout for this fragment
|
|
|
68 |
View rootView = inflater.inflate(R.layout.fragment_my_wallet, container, false);
|
|
|
69 |
TestinAgent.init(getActivity());
|
|
|
70 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
71 |
userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
72 |
apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
|
|
73 |
userDataEditor = userData.edit();
|
|
|
74 |
apiSettingsEditor = apiData.edit();
|
|
|
75 |
TestinAgent.setUserInfo(userData.getString("id", ""));
|
|
|
76 |
String url = apiData.getString("mywallet.url",null);
|
|
|
77 |
String id = userData.getString("id",null);
|
|
|
78 |
String landingUrl = url + "?user_id=" + id;
|
|
|
79 |
JSONObject props = new JSONObject();
|
|
|
80 |
try {
|
|
|
81 |
mixpanel.identify(userData.getString("id",null));
|
|
|
82 |
props.put("Screen", "My Wallet");
|
|
|
83 |
mixpanel.track("My Wallet", props);
|
|
|
84 |
} catch (JSONException e) {
|
|
|
85 |
e.printStackTrace();
|
|
|
86 |
}
|
|
|
87 |
if(isInternetOn()) {
|
|
|
88 |
WebClientClass webViewClient = new WebClientClass();
|
|
|
89 |
myWalletWebView = (WebView) rootView.findViewById(R.id.myWalletWebView);
|
|
|
90 |
myWalletWebView.setClickable(true);
|
|
|
91 |
myWalletWebView.setFocusableInTouchMode(true);
|
|
|
92 |
myWalletWebView.getSettings().setDomStorageEnabled(true);
|
|
|
93 |
myWalletWebView.getSettings().setJavaScriptEnabled(true);
|
|
|
94 |
myWalletWebView.loadUrl(landingUrl);
|
|
|
95 |
//myWalletWebView.reload();
|
|
|
96 |
|
|
|
97 |
myWalletWebView.setWebViewClient(webViewClient);
|
|
|
98 |
}else{
|
|
|
99 |
SearchFragment nextFrag= new SearchFragment();
|
|
|
100 |
Bundle args = new Bundle();
|
|
|
101 |
args.putString("finishingurl", landingUrl);
|
|
|
102 |
args.putString("fragmentNumber", "17");
|
|
|
103 |
nextFrag.setArguments(args);
|
|
|
104 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
105 |
.replace(R.id.frame_container, nextFrag)
|
|
|
106 |
.addToBackStack(null)
|
|
|
107 |
.commit();
|
|
|
108 |
}
|
|
|
109 |
return rootView;
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
@Override
|
|
|
114 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
115 |
super.onViewCreated(view, savedInstanceState);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
JSONObject obj;
|
|
|
119 |
public class WebClientClass extends WebViewClient {
|
|
|
120 |
ProgressDialog pd = null;
|
|
|
121 |
|
|
|
122 |
@Override
|
|
|
123 |
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
124 |
super.onPageStarted(view, url, favicon);
|
|
|
125 |
obj = new JSONObject();
|
|
|
126 |
/*CookieManager cookieManager = CookieManager.getInstance();
|
|
|
127 |
String cookiestring = cookieManager.getCookie(url);
|
|
|
128 |
Log.d("Cookies setting ","Cookies " + cookiestring);*/
|
|
|
129 |
//cookieManager.removeAllCookie();
|
|
|
130 |
try {
|
|
|
131 |
JSONObject j = new JSONObject();
|
|
|
132 |
JSONArray jsArray = new JSONArray();
|
|
|
133 |
j.put("url",url);
|
|
|
134 |
j.put("user_id",userData.getString("id",null));
|
|
|
135 |
j.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
136 |
jsArray.put(j);
|
|
|
137 |
obj.put("pushdata",jsArray);
|
|
|
138 |
} catch (JSONException e) {
|
|
|
139 |
e.printStackTrace();
|
|
|
140 |
}
|
|
|
141 |
new pushData().execute();
|
|
|
142 |
|
|
|
143 |
}
|
|
|
144 |
@Override
|
|
|
145 |
public void onPageFinished(WebView view, String url) {
|
|
|
146 |
view.setOnKeyListener(new View.OnKeyListener()
|
|
|
147 |
{
|
|
|
148 |
@Override
|
|
|
149 |
public boolean onKey(View v, int keyCode, KeyEvent event)
|
|
|
150 |
{
|
|
|
151 |
if(event.getAction() == KeyEvent.ACTION_DOWN)
|
|
|
152 |
{
|
|
|
153 |
WebView webView = (WebView) v;
|
|
|
154 |
|
|
|
155 |
switch(keyCode)
|
|
|
156 |
{
|
|
|
157 |
case KeyEvent.KEYCODE_BACK:
|
|
|
158 |
if(webView.canGoBack())
|
|
|
159 |
{
|
|
|
160 |
webView.goBack();
|
|
|
161 |
return true;
|
|
|
162 |
}
|
|
|
163 |
else{
|
|
|
164 |
Intent i = new Intent(getActivity(),MainActivity.class);
|
|
|
165 |
i.putExtra("displayView","0");
|
|
|
166 |
startActivity(i);
|
|
|
167 |
}
|
|
|
168 |
break;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
return false;
|
|
|
173 |
}
|
|
|
174 |
});
|
|
|
175 |
super.onPageFinished(view, url);
|
|
|
176 |
}
|
|
|
177 |
@Override
|
|
|
178 |
public void onReceivedHttpAuthRequest(WebView view,
|
|
|
179 |
HttpAuthHandler handler, String host, String realm) {
|
|
|
180 |
|
|
|
181 |
handler.proceed("dtr", "dtr18Feb2015");
|
|
|
182 |
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
@Override
|
|
|
186 |
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
|
|
187 |
super.onReceivedError(view, errorCode, description, failingUrl);
|
|
|
188 |
SearchFragment nextFrag= new SearchFragment();
|
|
|
189 |
Bundle args = new Bundle();
|
|
|
190 |
args.putString("finishingurl",failingUrl);
|
|
|
191 |
nextFrag.setArguments(args);
|
|
|
192 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
193 |
.replace(R.id.frame_container, nextFrag)
|
|
|
194 |
.addToBackStack(null)
|
|
|
195 |
.commit();
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
@Override
|
|
|
201 |
public void onResume() {
|
|
|
202 |
super.onResume();
|
|
|
203 |
getView().setFocusableInTouchMode(true);
|
|
|
204 |
getView().requestFocus();
|
|
|
205 |
getView().setOnKeyListener(new View.OnKeyListener() {
|
|
|
206 |
@Override
|
|
|
207 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
208 |
|
|
|
209 |
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
|
|
|
210 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
211 |
i.putExtra("displayView", "0");
|
|
|
212 |
startActivity(i);
|
|
|
213 |
return true;
|
|
|
214 |
|
|
|
215 |
}
|
|
|
216 |
return false;
|
|
|
217 |
}
|
|
|
218 |
});
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
class pushData extends AsyncTask<String, Integer, String> {
|
|
|
223 |
|
|
|
224 |
@Override
|
|
|
225 |
protected void onPreExecute() {
|
|
|
226 |
super.onPreExecute();
|
|
|
227 |
Log.e("Push Service", "Pre execute");
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
@Override
|
|
|
231 |
protected String doInBackground(String... arg0) {
|
|
|
232 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
233 |
try {
|
|
|
234 |
|
|
|
235 |
ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
|
|
|
236 |
nameValuePairs.add(new BasicNameValuePair("pushdata",obj.toString()));
|
|
|
237 |
HttpPost httppost = new HttpPost(apiData.getString("url.push.api",null));
|
|
|
238 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
239 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
240 |
System.out.println(obj.toString());
|
|
|
241 |
StringEntity se = new StringEntity(obj.toString());
|
|
|
242 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
243 |
int status = response.getStatusLine().getStatusCode();
|
|
|
244 |
|
|
|
245 |
if(status == 200){
|
|
|
246 |
System.out.println("ResponseCode of record: "+ status + " is " + status);
|
|
|
247 |
return "success";
|
|
|
248 |
} else {
|
|
|
249 |
Log.d("ResponseCode",status+"");
|
|
|
250 |
System.out.println(" NOT Transfered");
|
|
|
251 |
return "failure";
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
} catch (ClientProtocolException e) {
|
|
|
255 |
return "failure";
|
|
|
256 |
} catch (IOException e) {
|
|
|
257 |
return "failure";
|
|
|
258 |
}
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
@Override
|
|
|
262 |
protected void onPostExecute(String result) {
|
|
|
263 |
super.onPostExecute(result);
|
|
|
264 |
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
public final boolean isInternetOn() {
|
|
|
269 |
ConnectivityManager connec =
|
|
|
270 |
(ConnectivityManager)getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
271 |
|
|
|
272 |
if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
273 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
274 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
275 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
276 |
|
|
|
277 |
return true;
|
|
|
278 |
|
|
|
279 |
} else if (
|
|
|
280 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
281 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
282 |
return false;
|
|
|
283 |
}
|
|
|
284 |
return false;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
}
|