| 14792 |
manas |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.AlertDialog;
|
| 16278 |
manas |
4 |
import android.app.Fragment;
|
| 14792 |
manas |
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.Paint;
|
|
|
11 |
import android.net.Uri;
|
|
|
12 |
import android.os.AsyncTask;
|
|
|
13 |
import android.os.Bundle;
|
|
|
14 |
import android.text.TextUtils;
|
|
|
15 |
import android.view.KeyEvent;
|
|
|
16 |
import android.view.LayoutInflater;
|
|
|
17 |
import android.view.View;
|
|
|
18 |
import android.view.ViewGroup;
|
|
|
19 |
import android.widget.AdapterView;
|
|
|
20 |
import android.widget.ArrayAdapter;
|
|
|
21 |
import android.widget.Button;
|
|
|
22 |
import android.widget.EditText;
|
|
|
23 |
import android.widget.Spinner;
|
|
|
24 |
import android.widget.TextView;
|
|
|
25 |
import android.widget.Toast;
|
|
|
26 |
|
|
|
27 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
28 |
import com.saholic.profittill.R;
|
| 16278 |
manas |
29 |
import com.saholic.profittill.Utils.AnalyticsUtility;
|
|
|
30 |
import com.saholic.profittill.Volley.Analytics;
|
|
|
31 |
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
|
|
|
32 |
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
|
| 14792 |
manas |
33 |
import com.testin.agent.TestinAgent;
|
|
|
34 |
|
|
|
35 |
import org.apache.http.HttpEntity;
|
|
|
36 |
import org.apache.http.HttpResponse;
|
|
|
37 |
import org.apache.http.NameValuePair;
|
|
|
38 |
import org.apache.http.client.HttpClient;
|
|
|
39 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
40 |
import org.apache.http.client.methods.HttpPost;
|
|
|
41 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
42 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
43 |
|
|
|
44 |
import java.io.BufferedReader;
|
|
|
45 |
import java.io.InputStream;
|
|
|
46 |
import java.io.InputStreamReader;
|
|
|
47 |
import java.text.SimpleDateFormat;
|
|
|
48 |
import java.util.ArrayList;
|
|
|
49 |
import java.util.Calendar;
|
|
|
50 |
import java.util.StringTokenizer;
|
|
|
51 |
import java.util.regex.Matcher;
|
|
|
52 |
import java.util.regex.Pattern;
|
|
|
53 |
|
|
|
54 |
public class ContactUsFragment extends Fragment {
|
|
|
55 |
ArrayList<NameValuePair> contactusNameValuePair;
|
|
|
56 |
SharedPreferences userData;
|
|
|
57 |
SharedPreferences apiData;
|
|
|
58 |
SharedPreferences.Editor userDataEditor;
|
|
|
59 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
60 |
EditText emailId,content;
|
|
|
61 |
Button submit;
|
|
|
62 |
TextView contactUsNumber,tapToCall;
|
|
|
63 |
String subject="";
|
|
|
64 |
EditText otherContent;
|
|
|
65 |
@Override
|
|
|
66 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
67 |
Bundle savedInstanceState) {
|
|
|
68 |
|
|
|
69 |
View rootView = inflater.inflate(R.layout.fragment_contact_us, container, false);
|
|
|
70 |
TestinAgent.init(getActivity());
|
|
|
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 |
otherContent=(EditText) rootView.findViewById(R.id.otherSubjectContent);
|
|
|
77 |
emailId =(EditText) rootView.findViewById(R.id.contactUsEmailId);
|
|
|
78 |
emailId.setText(userData.getString("email","Email"));
|
|
|
79 |
emailId.setKeyListener(null);
|
|
|
80 |
final ArrayList<String> issueList = new ArrayList<String>();
|
|
|
81 |
String issues =apiData.getString("contactus.issues","");
|
|
|
82 |
StringTokenizer st2 = new StringTokenizer(issues, "|");
|
|
|
83 |
issueList.add("---Select Issue---");
|
|
|
84 |
while (st2.hasMoreElements()) {
|
|
|
85 |
issueList.add(st2.nextToken());
|
|
|
86 |
}
|
|
|
87 |
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
|
|
|
88 |
android.R.layout.simple_spinner_item, issueList);
|
|
|
89 |
|
|
|
90 |
final Spinner spinYear = (Spinner)rootView.findViewById(R.id.contactUsSubject);
|
|
|
91 |
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
|
|
|
92 |
spinYear.setAdapter(adapter);
|
|
|
93 |
content =(EditText) rootView.findViewById(R.id.contactUsContent);
|
|
|
94 |
submit = (Button) rootView.findViewById(R.id.contactUsButton);
|
|
|
95 |
contactUsNumber = (TextView) rootView.findViewById(R.id.contactUsNumber);
|
|
|
96 |
contactUsNumber.setText("Call Us at " +apiData.getString("contactus.number","") + " >");
|
|
|
97 |
contactUsNumber.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
|
| 16278 |
manas |
98 |
if(!(userData.getString("id", "").isEmpty())) {
|
|
|
99 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
100 |
AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Screen", "Contact Us", "Contact Us Screen"),
|
|
|
101 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
102 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
|
|
|
103 |
}
|
| 14792 |
manas |
104 |
spinYear.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
105 |
@Override
|
|
|
106 |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
107 |
subject=spinYear.getSelectedItem().toString();
|
|
|
108 |
|
|
|
109 |
if(position==(issueList.size()-1)){
|
|
|
110 |
otherContent.setVisibility(View.VISIBLE);
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
else{
|
|
|
114 |
otherContent.setVisibility(View.GONE);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
@Override
|
|
|
120 |
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
121 |
|
|
|
122 |
}
|
|
|
123 |
});
|
|
|
124 |
contactUsNumber.setOnClickListener(new View.OnClickListener() {
|
|
|
125 |
@Override
|
|
|
126 |
public void onClick(View v) {
|
| 16278 |
manas |
127 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
128 |
AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Clicks", "Contact Us", "Call for any query"),
|
|
|
129 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
130 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
|
|
|
131 |
|
| 14792 |
manas |
132 |
Calendar cal = Calendar.getInstance();
|
|
|
133 |
cal.getTime();
|
|
|
134 |
SimpleDateFormat sdf = new SimpleDateFormat("HH");
|
|
|
135 |
int currentHour = Integer.parseInt(sdf.format(cal.getTime()));
|
|
|
136 |
int timeFrom = Integer.parseInt(apiData.getString("contactus.time.from", "").split(" ")[0]);
|
|
|
137 |
int timeTo = Integer.parseInt(apiData.getString("contactus.time.to", "").split(" ")[0]);
|
|
|
138 |
if (currentHour > timeTo || currentHour < timeFrom) {
|
|
|
139 |
Toast.makeText(getActivity(),"Sorry not the correct time to contact us. Please contact us between "+apiData.getString("contactus.time.from", "") + " to "+ apiData.getString("contactus.time.to", "") ,Toast.LENGTH_SHORT).show();
|
|
|
140 |
} else {
|
|
|
141 |
new AlertDialog.Builder(getActivity())
|
|
|
142 |
.setTitle("Call us")
|
|
|
143 |
.setMessage("Our customer care people are available from " + apiData.getString("contactus.time.from","") + " to " + apiData.getString("contactus.time.to",""))
|
|
|
144 |
.setPositiveButton("Call", new DialogInterface.OnClickListener() {
|
|
|
145 |
@Override
|
|
|
146 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
147 |
Intent callIntent = new Intent(Intent.ACTION_CALL);
|
|
|
148 |
callIntent.setData(Uri.parse("tel:0" + apiData.getString("contactus.number", "")));
|
|
|
149 |
startActivity(callIntent);
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
})
|
|
|
153 |
.setNegativeButton("Cancel", null)
|
|
|
154 |
.show();
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
});
|
|
|
158 |
submit.setOnClickListener(new View.OnClickListener() {
|
|
|
159 |
@Override
|
|
|
160 |
public void onClick(View v) {
|
|
|
161 |
if(subject.contains("Other")) {
|
|
|
162 |
subject = otherContent.getText().toString();
|
|
|
163 |
}
|
|
|
164 |
if(TextUtils.isEmpty(emailId.getText().toString())){
|
|
|
165 |
Toast.makeText(getActivity(),"Please enter a email id.",Toast.LENGTH_SHORT).show();
|
|
|
166 |
}
|
|
|
167 |
else if(TextUtils.isEmpty(subject) || subject.contains("Select")){
|
|
|
168 |
Toast.makeText(getActivity(),"Please enter a subject.",Toast.LENGTH_SHORT).show();
|
|
|
169 |
}
|
|
|
170 |
else if(TextUtils.isEmpty(content.getText().toString())){
|
|
|
171 |
Toast.makeText(getActivity(),"Please enter the message details.",Toast.LENGTH_SHORT).show();
|
|
|
172 |
}
|
|
|
173 |
else{
|
|
|
174 |
Pattern pattern;
|
|
|
175 |
Matcher matcher;
|
|
|
176 |
pattern = Pattern.compile(ProfitTillConstants.EMAIL_PATTERN);
|
|
|
177 |
matcher = pattern.matcher(emailId.getText().toString());
|
|
|
178 |
if( matcher.matches()){
|
| 14991 |
manas |
179 |
showProgressDialog();
|
| 16278 |
manas |
180 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
181 |
AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Clicks", "Contact Us", "Submit Query"),
|
|
|
182 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
183 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
|
| 14792 |
manas |
184 |
contactusNameValuePair = new ArrayList<NameValuePair>();
|
|
|
185 |
contactusNameValuePair.add(new BasicNameValuePair("user_id",userData.getString("id","")));
|
|
|
186 |
contactusNameValuePair.add(new BasicNameValuePair("email",emailId.getText().toString()));
|
|
|
187 |
contactusNameValuePair.add(new BasicNameValuePair("subject",subject));
|
|
|
188 |
contactusNameValuePair.add(new BasicNameValuePair("message",content.getText().toString()));
|
|
|
189 |
new loadData().execute();
|
|
|
190 |
}
|
|
|
191 |
else{
|
|
|
192 |
Toast.makeText(getActivity(),"Please enter a valid email id",Toast.LENGTH_SHORT).show();
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
}
|
|
|
196 |
});
|
|
|
197 |
return rootView;
|
|
|
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 |
return false;
|
|
|
216 |
}
|
|
|
217 |
});
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
@Override
|
|
|
221 |
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
222 |
|
|
|
223 |
super.onViewCreated(view, savedInstanceState);
|
|
|
224 |
}
|
| 14991 |
manas |
225 |
ProgressDialog pDlg;
|
| 14792 |
manas |
226 |
class loadData extends AsyncTask<String, Integer, String> {
|
|
|
227 |
private StringBuilder sb;
|
|
|
228 |
private InputStream is;
|
|
|
229 |
|
|
|
230 |
@Override
|
|
|
231 |
protected void onPreExecute() {
|
|
|
232 |
super.onPreExecute();
|
| 16278 |
manas |
233 |
|
| 14792 |
manas |
234 |
}
|
|
|
235 |
|
|
|
236 |
@Override
|
|
|
237 |
protected String doInBackground(String... arg0) {
|
|
|
238 |
try {
|
|
|
239 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
240 |
HttpPost httppost = new HttpPost(apiData.getString("feedback.push.api",null));
|
|
|
241 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
242 |
httppost.setEntity(new UrlEncodedFormEntity(contactusNameValuePair));
|
|
|
243 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
244 |
HttpEntity entity = response.getEntity();
|
|
|
245 |
is = entity.getContent();
|
|
|
246 |
InputStreamReader ireader = new InputStreamReader(is);
|
|
|
247 |
BufferedReader bf = new BufferedReader(ireader);
|
|
|
248 |
sb = new StringBuilder();
|
|
|
249 |
String line = null;
|
|
|
250 |
while ((line = bf.readLine()) != null) {
|
|
|
251 |
sb.append(line);
|
|
|
252 |
}
|
|
|
253 |
} catch (Exception e) {
|
|
|
254 |
}
|
|
|
255 |
return "success";
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
@Override
|
|
|
259 |
protected void onPostExecute(String result) {
|
|
|
260 |
super.onPostExecute(result);
|
| 14991 |
manas |
261 |
if(pDlg!=null){
|
|
|
262 |
pDlg.dismiss();
|
|
|
263 |
}
|
| 16278 |
manas |
264 |
if(!(userData.getString("id", "").isEmpty())) {
|
|
|
265 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
266 |
AnalyticsUtility.getAnalyticsRequest(getActivity(), userData.getString("id", ""), "Click", "Contact Us", "Query Submitted"),
|
|
|
267 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
268 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getActivity());
|
|
|
269 |
}
|
| 14792 |
manas |
270 |
Intent i = new Intent(getActivity(),MainActivity.class);
|
|
|
271 |
i.putExtra("displayView","0");
|
|
|
272 |
startActivity(i);
|
|
|
273 |
|
|
|
274 |
}
|
|
|
275 |
}
|
| 14991 |
manas |
276 |
private void showProgressDialog()
|
|
|
277 |
{
|
|
|
278 |
pDlg = new ProgressDialog(getActivity());
|
|
|
279 |
pDlg.setMessage("Submitting your feedback");
|
|
|
280 |
pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
281 |
pDlg.setCancelable(false);
|
|
|
282 |
pDlg.show();
|
| 14792 |
manas |
283 |
|
| 14991 |
manas |
284 |
}
|
| 14792 |
manas |
285 |
}
|