AboutFrag.java
4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package etelligens.com.foodsafety.fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.NoConnectionError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import etelligens.com.foodsafety.activities.login.LoginChangeActivity;
import etelligens.com.foodsafety.utils.getVersionNameUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import etelligens.com.foodsafety.R;
import etelligens.com.foodsafety.utils.BaseFragment;
import static etelligens.com.foodsafety.utils.EndPoint.ETE_BASE_URL;
import static etelligens.com.foodsafety.utils.EndPoint.ETE_SETTINGS_ABOUT_US;
import static etelligens.com.foodsafety.utils.Keyword.MY_SOCKET_TIMEOUT;
import static org.jetbrains.anko.AnkoContextKt.setContentView;
public class AboutFrag extends BaseFragment implements View.OnClickListener {
TextView dashboardtxt, buildtxt, nametxt, coprytxt,versiontxt;
Bundle bundle;
String version;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_about, container, false);
getSavedData();
getselectedLanguage();
dashboardtxt = view.findViewById(R.id.dashboard_txt);
nametxt = view.findViewById(R.id.name_txt);
buildtxt = view.findViewById(R.id.build_txt);
coprytxt = view.findViewById(R.id.copy_right_txt);
dashboardtxt.setOnClickListener(this);
versiontxt=view.findViewById(R.id.version_txt);
bundle = this.getArguments();
version = bundle.getString("version");
versiontxt.setText("version: "+version);
aboutUs();
return view;
}
private void aboutUs() {
loaderShow(getActivity());
String url = null;
if (currentLang != null) {
url = ETE_SETTINGS_ABOUT_US + "?" + "language=" + currentLang;
} else {
url = ETE_SETTINGS_ABOUT_US;
}
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
response -> {
try {
JSONObject jsonObject = new JSONObject(response);
int status = jsonObject.getInt("status");
String msg = jsonObject.getString("msg");
if (status == 1) {
String typ = jsonObject.getString("type");
String title = jsonObject.getString("title");
String des = jsonObject.getString("description");
nametxt.setText(title);
buildtxt.setText(typ);
coprytxt.setText(des);
} else {
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
}
} catch (JSONException j) {
j.printStackTrace();
}
loaderHide(getActivity());
},
error -> {
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
Toast.makeText(getActivity(), getString(R.string.internet_connection_fail), Toast.LENGTH_SHORT).show();
}
loaderHide(getActivity());
}) {
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> header = new HashMap<String, String>();
header.put("Authorization", "Bearer " + loginToken);
return header;
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
final RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
requestQueue.add(stringRequest);
requestQueue.addRequestFinishedListener(request -> requestQueue.getCache().clear());
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.dashboard_txt: {
gotoDashboard(getActivity());
}
break;
}
}
}