| 21478 |
rajender |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.Fragment;
|
|
|
4 |
import android.content.Context;
|
|
|
5 |
import android.content.Intent;
|
|
|
6 |
import android.content.SharedPreferences;
|
|
|
7 |
import android.net.ConnectivityManager;
|
|
|
8 |
import android.os.Bundle;
|
|
|
9 |
import android.text.TextUtils;
|
|
|
10 |
import android.util.Log;
|
|
|
11 |
import android.view.KeyEvent;
|
|
|
12 |
import android.view.LayoutInflater;
|
|
|
13 |
import android.view.View;
|
|
|
14 |
import android.view.ViewGroup;
|
|
|
15 |
import android.webkit.WebView;
|
|
|
16 |
import android.widget.Button;
|
|
|
17 |
import android.widget.Toast;
|
|
|
18 |
|
|
|
19 |
import com.saholic.profittill.R;
|
|
|
20 |
|
|
|
21 |
import java.util.ArrayList;
|
|
|
22 |
import java.util.List;
|
|
|
23 |
import java.util.StringTokenizer;
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
public class SearchFragment extends Fragment {
|
|
|
27 |
Button retry;
|
|
|
28 |
SharedPreferences userData;
|
|
|
29 |
SharedPreferences apiData;
|
|
|
30 |
SharedPreferences.Editor userDataEditor;
|
|
|
31 |
String finalURL;
|
|
|
32 |
String fragmentNumber;
|
|
|
33 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
34 |
@Override
|
|
|
35 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
36 |
Bundle savedInstanceState) {
|
|
|
37 |
|
|
|
38 |
View rootView = inflater.inflate(R.layout.fragment_search, container, false);
|
|
|
39 |
|
|
|
40 |
userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
41 |
apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
|
|
42 |
userDataEditor = userData.edit();
|
|
|
43 |
apiSettingsEditor = apiData.edit();
|
|
|
44 |
retry = (Button)rootView.findViewById(R.id.checkInternet);
|
|
|
45 |
finalURL=getArguments().getString("finishingurl");
|
|
|
46 |
Log.d("Finish Url","Finish Url" + finalURL);
|
|
|
47 |
List<String> snapdealExceptionUrls = new ArrayList<>();
|
|
|
48 |
StringTokenizer st = new StringTokenizer(apiData.getString("exception.urls.redirect",""),"|");
|
|
|
49 |
while(st.hasMoreTokens()){
|
|
|
50 |
snapdealExceptionUrls.add( st.nextToken());
|
|
|
51 |
}
|
|
|
52 |
for(String s:snapdealExceptionUrls){
|
|
|
53 |
if(finalURL.contains(s)){
|
|
|
54 |
Toast.makeText(getActivity(),apiData.getString("redirect.exception.message","Redirecting to deals"),Toast.LENGTH_SHORT).show();
|
|
|
55 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
56 |
i.putExtra("displayView", "0");
|
|
|
57 |
startActivity(i);
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
fragmentNumber=getArguments().getString("fragmentNumber");
|
|
|
62 |
retry.setOnClickListener(new View.OnClickListener() {
|
|
|
63 |
@Override
|
|
|
64 |
public void onClick(View v) {
|
|
|
65 |
if(isInternetOn()){
|
|
|
66 |
try {
|
|
|
67 |
if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("10")) {
|
|
|
68 |
MyProfile myProfile = new MyProfile();
|
|
|
69 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
70 |
.replace(R.id.frame_container, myProfile, "Mike")
|
|
|
71 |
.addToBackStack(null)
|
|
|
72 |
.commit();
|
|
|
73 |
} else if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("1")) {
|
|
|
74 |
DealsHomeFragment nextFrag = new DealsHomeFragment();
|
|
|
75 |
Bundle args = new Bundle();
|
|
|
76 |
args.putString("key", finalURL);
|
|
|
77 |
nextFrag.setArguments(args);
|
|
|
78 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
79 |
.replace(R.id.frame_container, nextFrag)
|
|
|
80 |
.addToBackStack(null)
|
|
|
81 |
.commit();
|
|
|
82 |
} /*else if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("11")) {
|
|
|
83 |
MyOrdersFragment ordersFragment = new MyOrdersFragment();
|
|
|
84 |
Bundle args = new Bundle();
|
|
|
85 |
args.putString("key", finalURL);
|
|
|
86 |
ordersFragment.setArguments(args);
|
|
|
87 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
88 |
.replace(R.id.frame_container, ordersFragment)
|
|
|
89 |
.addToBackStack(null)
|
|
|
90 |
.commit();
|
|
|
91 |
} */else if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("12")) {
|
|
|
92 |
PreferencesFragment preferencesFragment = new PreferencesFragment();
|
|
|
93 |
Bundle args = new Bundle();
|
|
|
94 |
args.putString("key", finalURL);
|
|
|
95 |
preferencesFragment.setArguments(args);
|
|
|
96 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
97 |
.replace(R.id.frame_container, preferencesFragment)
|
|
|
98 |
.addToBackStack(null)
|
|
|
99 |
.commit();
|
|
|
100 |
} else if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("14")) {
|
|
|
101 |
PendingCashback pendingCashback = new PendingCashback();
|
|
|
102 |
Bundle args = new Bundle();
|
|
|
103 |
args.putString("key", finalURL);
|
|
|
104 |
pendingCashback.setArguments(args);
|
|
|
105 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
106 |
.replace(R.id.frame_container, pendingCashback)
|
|
|
107 |
.addToBackStack(null)
|
|
|
108 |
.commit();
|
|
|
109 |
}else if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("17")) {
|
|
|
110 |
MyWallet myWallet = new MyWallet();
|
|
|
111 |
/* Bundle args = new Bundle();
|
|
|
112 |
args.putString("key", finalURL);
|
|
|
113 |
myWallet.setArguments(args);*/
|
|
|
114 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
115 |
.replace(R.id.frame_container, myWallet)
|
|
|
116 |
.addToBackStack(null)
|
|
|
117 |
.commit();
|
|
|
118 |
}
|
|
|
119 |
else if ((!TextUtils.isEmpty(finalURL) || finalURL != null) && fragmentNumber.equalsIgnoreCase("16")) {
|
|
|
120 |
AboutUsFragment aboutUs = new AboutUsFragment();
|
|
|
121 |
/* Bundle args = new Bundle();
|
|
|
122 |
args.putString("key", finalURL);
|
|
|
123 |
myWallet.setArguments(args);*/
|
|
|
124 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
125 |
.replace(R.id.frame_container, aboutUs)
|
|
|
126 |
.addToBackStack(null)
|
|
|
127 |
.commit();
|
|
|
128 |
}
|
|
|
129 |
else {
|
|
|
130 |
|
|
|
131 |
}
|
|
|
132 |
}catch (Exception e){
|
|
|
133 |
DealsHomeFragment nextFrag = new DealsHomeFragment();
|
|
|
134 |
Bundle args = new Bundle();
|
|
|
135 |
args.putString("key", finalURL);
|
|
|
136 |
nextFrag.setArguments(args);
|
|
|
137 |
getActivity().getFragmentManager().beginTransaction()
|
|
|
138 |
.replace(R.id.frame_container, nextFrag)
|
|
|
139 |
.addToBackStack(null)
|
|
|
140 |
.commit();
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
else{
|
|
|
144 |
Toast.makeText(getActivity(),"No Internet Connection. Please try again after some time.",Toast.LENGTH_SHORT).show();
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
});
|
|
|
148 |
|
|
|
149 |
rootView.setOnKeyListener(new View.OnKeyListener() {
|
|
|
150 |
@Override
|
|
|
151 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
152 |
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
153 |
WebView webView = (WebView) v;
|
|
|
154 |
switch (keyCode) {
|
|
|
155 |
case KeyEvent.KEYCODE_BACK:
|
|
|
156 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
157 |
i.putExtra("displayView", "0");
|
|
|
158 |
startActivity(i);
|
|
|
159 |
return true;
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
return false;
|
|
|
164 |
}
|
|
|
165 |
});
|
|
|
166 |
|
|
|
167 |
return rootView;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
@Override
|
|
|
171 |
public void onResume() {
|
|
|
172 |
super.onResume();
|
|
|
173 |
if(isInternetOn()) {
|
|
|
174 |
getView().setFocusableInTouchMode(true);
|
|
|
175 |
getView().requestFocus();
|
|
|
176 |
getView().setOnKeyListener(new View.OnKeyListener() {
|
|
|
177 |
@Override
|
|
|
178 |
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
179 |
|
|
|
180 |
if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
181 |
try {
|
|
|
182 |
|
|
|
183 |
Intent i = new Intent(getActivity(), MainActivity.class);
|
|
|
184 |
i.putExtra("displayView", "0");
|
|
|
185 |
startActivity(i);
|
|
|
186 |
|
|
|
187 |
} catch (Exception e) {
|
|
|
188 |
e.printStackTrace();
|
|
|
189 |
return false;
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
return false;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
});
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public final boolean isInternetOn() {
|
|
|
200 |
|
|
|
201 |
// get Connectivity Manager object to check connection
|
|
|
202 |
ConnectivityManager connec =
|
|
|
203 |
(ConnectivityManager)getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
204 |
|
|
|
205 |
// Check for network connections
|
|
|
206 |
if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
207 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
208 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
209 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
210 |
return true;
|
|
|
211 |
|
|
|
212 |
} else if (
|
|
|
213 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
214 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
215 |
return false;
|
|
|
216 |
}
|
|
|
217 |
return false;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
@Override
|
|
|
221 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
222 |
super.onViewCreated(view, savedInstanceState);
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
}
|