DSEViewFeedbackActivity.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. package com.cygnusa.hyperm;
  2. import android.annotation.SuppressLint;
  3. import android.content.Intent;
  4. import android.graphics.PorterDuff;
  5. import android.graphics.drawable.Drawable;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.ImageView;
  13. import android.widget.LinearLayout;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16. import androidx.appcompat.app.AppCompatActivity;
  17. import androidx.appcompat.widget.Toolbar;
  18. import androidx.fragment.app.FragmentManager;
  19. import androidx.fragment.app.FragmentTransaction;
  20. import com.bumptech.glide.Glide;
  21. import com.bumptech.glide.load.engine.DiskCacheStrategy;
  22. import com.bumptech.glide.request.RequestOptions;
  23. import com.google.gson.Gson;
  24. import com.google.gson.JsonElement;
  25. import com.google.gson.reflect.TypeToken;
  26. import com.cygnusa.hyperm.fragments.DSETrainerFeedback;
  27. import com.cygnusa.hyperm.fragments.DSETrainingFeedback;
  28. import com.cygnusa.hyperm.util.ApiService;
  29. import com.cygnusa.hyperm.util.GlobalData;
  30. import com.cygnusa.hyperm.util.MainApplication;
  31. import com.cygnusa.hyperm.wrappers.CommonResponse;
  32. import com.cygnusa.hyperm.wrappers.DSEFeedBackAnswer;
  33. import com.cygnusa.hyperm.wrappers.DSETrainingFeedbackData;
  34. import com.cygnusa.hyperm.wrappers.ErrorResponse;
  35. import com.cygnusa.hyperm.wrappers.GetAllDSETrainingFeedbackSummary;
  36. import com.cygnusa.hyperm.wrappers.SurveyAnswer;
  37. import java.text.ParseException;
  38. import java.text.SimpleDateFormat;
  39. import java.util.ArrayList;
  40. import java.util.Date;
  41. import java.util.HashMap;
  42. import java.util.Locale;
  43. import java.util.Objects;
  44. import retrofit2.Call;
  45. import retrofit2.Callback;
  46. import retrofit2.Response;
  47. public class DSEViewFeedbackActivity extends AppCompatActivity {
  48. private TextView txtTrainingName, txtTrainingStartDate, txtTrainingDuration, txtTrainingEndDate, txtTrainingVenue,
  49. txtTrainingTotalPArticipant, smpin, participantName, dealerName;
  50. LinearLayout llout_remaining;
  51. private ImageView imgAttendance;
  52. private Button trainingFeedback, trainersFeedback, btnsubmit, btncancel;
  53. FragmentManager manager;
  54. private EditText edtRemarks;
  55. ApiService restService;
  56. @Override
  57. protected void onCreate(Bundle savedInstanceState) {
  58. super.onCreate(savedInstanceState);
  59. setContentView(R.layout.activity_dse_feedback_view);
  60. initViews();
  61. }
  62. @Override
  63. public void onBackPressed() {
  64. super.onBackPressed();
  65. startActivity(new Intent(DSEViewFeedbackActivity.this, ClassRoomDSETainingActivity.class));
  66. finish();
  67. this.overridePendingTransition(R.anim.animation_f_enter,
  68. R.anim.animation_f_leave);
  69. }
  70. @Override
  71. public boolean onOptionsItemSelected(MenuItem item) {
  72. if (item.getItemId() == android.R.id.home) {
  73. startActivity(new Intent(DSEViewFeedbackActivity.this, ClassRoomDSETainingActivity.class));
  74. finish();
  75. }
  76. return super.onOptionsItemSelected(item);
  77. }
  78. private void initViews() {
  79. Toolbar toolbar = findViewById(R.id.toolbar);
  80. setSupportActionBar(toolbar);
  81. toolbar.setContentInsetStartWithNavigation(0);
  82. toolbar.setTitle("");
  83. Objects.requireNonNull(getSupportActionBar()).setTitle("");
  84. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  85. getSupportActionBar().setDisplayShowHomeEnabled(true);
  86. @SuppressLint("PrivateResource")
  87. Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
  88. backArrow.setColorFilter(getResources().getColor(R.color.btn_bg_color), PorterDuff.Mode.SRC_ATOP);
  89. getSupportActionBar().setHomeAsUpIndicator(backArrow);
  90. restService = ((MainApplication) getApplication()).getClient();
  91. txtTrainingName = findViewById(R.id.txtTrainingName);
  92. txtTrainingStartDate = findViewById(R.id.txtTrainingStartDate);
  93. txtTrainingDuration = findViewById(R.id.txtTrainingDuration);
  94. txtTrainingEndDate = findViewById(R.id.txtTrainingEndDate);
  95. txtTrainingVenue = findViewById(R.id.txtTrainingVenue);
  96. txtTrainingTotalPArticipant = findViewById(R.id.txtTrainingTotalPArticipant);
  97. llout_remaining = findViewById(R.id.lloutWholeLayout);
  98. llout_remaining.setVisibility(View.GONE);
  99. TextView txtShowmore = findViewById(R.id.txtShowmore);
  100. imgAttendance = findViewById(R.id.imgAttendance);
  101. edtRemarks = findViewById(R.id.edtRemarks);
  102. trainersFeedback = findViewById(R.id.trainers_feedback);
  103. trainingFeedback = findViewById(R.id.training_feedback);
  104. manager = getSupportFragmentManager();
  105. btnsubmit = findViewById(R.id.btnsubmit);
  106. btncancel = findViewById(R.id.btncancel);
  107. btncancel.setOnClickListener(new View.OnClickListener() {
  108. @Override
  109. public void onClick(View v) {
  110. onBackPressed();
  111. }
  112. });
  113. btnsubmit.setOnClickListener(new View.OnClickListener() {
  114. @Override
  115. public void onClick(View v) {
  116. if (validate()) {
  117. sendAllTrainingFeedbacktoServer();
  118. }
  119. }
  120. });
  121. GetAllDSETrainingDetails();
  122. trainersFeedback.setOnClickListener(new View.OnClickListener() {
  123. @Override
  124. public void onClick(View v) {
  125. FragmentTransaction transaction = manager.beginTransaction();
  126. trainingFeedback.setBackground(getResources().getDrawable(R.drawable.border_login_black));
  127. trainersFeedback.setBackground(getResources().getDrawable(R.drawable.border_login_white));
  128. transaction.replace(R.id.container, new DSETrainerFeedback());
  129. transaction.commit();
  130. }
  131. });
  132. trainingFeedback.setOnClickListener(new View.OnClickListener() {
  133. @Override
  134. public void onClick(View v) {
  135. FragmentTransaction transaction = manager.beginTransaction();
  136. trainersFeedback.setBackground(getResources().getDrawable(R.drawable.border_login_black));
  137. trainingFeedback.setBackground(getResources().getDrawable(R.drawable.border_login_white));
  138. transaction.replace(R.id.container, new DSETrainingFeedback());
  139. transaction.commit();
  140. }
  141. });
  142. smpin = findViewById(R.id.smpin);
  143. participantName = findViewById(R.id.txtParticipantName);
  144. dealerName = findViewById(R.id.txtDealerName);
  145. txtTrainingVenue.setSelected(true);
  146. dealerName.setSelected(true);
  147. txtShowmore.setOnClickListener(new View.OnClickListener() {
  148. @Override
  149. public void onClick(View v) {
  150. if (txtShowmore.getText().toString().equalsIgnoreCase("Show More")) {
  151. txtShowmore.setText(getResources().getText(R.string.showless));
  152. llout_remaining.setVisibility(View.VISIBLE);
  153. } else {
  154. txtShowmore.setText(getResources().getText(R.string.showmore));
  155. llout_remaining.setVisibility(View.GONE);
  156. }
  157. }
  158. });
  159. setAllData();
  160. }
  161. private void sendAllTrainingFeedbacktoServer() {
  162. HashMap<String, String> sendObj = new HashMap<>();
  163. sendObj.put("startdatetime", GlobalData.DSEFEEDBACKVIEW.getStartDate());
  164. sendObj.put("enddatetime", GlobalData.DSEFEEDBACKVIEW.getEndDate());
  165. sendObj.put("remarks", edtRemarks.getText().toString().trim());
  166. ArrayList<DSEFeedBackAnswer> answers = new ArrayList<>();
  167. DSEFeedBackAnswer answer = new DSEFeedBackAnswer();
  168. for (int i = 0; i < GlobalData.DSEFeedbackQuestions.getQuestions().size(); i++) {
  169. answer = new DSEFeedBackAnswer();
  170. answer.setAqid(GlobalData.DSEFeedbackQuestions.getQuestions().get(i).getAqid());
  171. answer.setQid(GlobalData.DSEFeedbackQuestions.getQuestions().get(i).getQid());
  172. ArrayList<String> strings = new ArrayList<>();
  173. strings.add(GlobalData.DSEFeedbackQuestions.getQuestions().get(i).getSelectedOption());
  174. answer.setOptions(strings);
  175. answers.add(answer);
  176. }
  177. Gson gson = new Gson();
  178. JsonElement jsonElement = gson.toJsonTree(
  179. answers, new TypeToken<ArrayList<SurveyAnswer>>() {
  180. }.getType());
  181. sendObj.put("ans_arr", jsonElement.toString());
  182. restService.dsePostSurvey(GlobalData.DSEFEEDBACKVIEW.getAssessmentid(), sendObj).enqueue(new Callback<CommonResponse>() {
  183. @Override
  184. public void onResponse(Call<CommonResponse> call, Response<CommonResponse> response) {
  185. if (response.body() != null) {
  186. if (response.body().getResponse().equalsIgnoreCase("Success")) {
  187. GlobalData.toast(getApplicationContext(), response.body().getMessage());
  188. startActivity(new Intent(DSEViewFeedbackActivity.this, ClassRoomDSETainingActivity.class));
  189. finish();
  190. } else {
  191. GlobalData.toast(getApplicationContext(), response.body().getResponseText());
  192. }
  193. } else if (response.body() != null && response.body().getStatus() == 401) {
  194. GlobalData.canLogout = true;
  195. finish();
  196. } else if (response.errorBody() != null) {
  197. Gson gson = new Gson();
  198. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  199. GlobalData.showToast(getApplicationContext(), message.getMessage(), Toast.LENGTH_SHORT).show();
  200. if (message.getStatus() == 401) {
  201. GlobalData.canLogout = true;
  202. finish();
  203. }
  204. }
  205. }
  206. @Override
  207. public void onFailure(Call<CommonResponse> call, Throwable t) {
  208. if (t.getMessage() != null) {
  209. Log.e("tmess", t.getMessage());
  210. }
  211. }
  212. });
  213. }
  214. private boolean validate() {
  215. if (edtRemarks.getText().toString().equalsIgnoreCase("")) {
  216. Toast.makeText(DSEViewFeedbackActivity.this, "Please Enter Remarks", Toast.LENGTH_SHORT).show();
  217. return false;
  218. }
  219. if (edtRemarks.getText().toString().length() < 60) {
  220. Toast.makeText(DSEViewFeedbackActivity.this, "Please Enter Remarks min 60 letters", Toast.LENGTH_SHORT).show();
  221. return false;
  222. }
  223. if (GlobalData.DSEFeedbackQuestions.getQuestions() != null && GlobalData.DSEFeedbackQuestions.getQuestions().size() > 0) {
  224. for (int j = 0; j < GlobalData.DSEFeedbackQuestions.getQuestions().size(); j++) {
  225. if (GlobalData.DSEFeedbackQuestions.getQuestions().get(j).getSelectedOption() == null) {
  226. Toast.makeText(DSEViewFeedbackActivity.this, "Please Choose mark for all questions", Toast.LENGTH_SHORT).show();
  227. return false;
  228. }
  229. }
  230. }
  231. return true;
  232. }
  233. private void GetAllDSETrainingDetails() {
  234. restService.getDSETrainingFeedback(GlobalData.DSEFEEDBACKVIEW.getAssessmentid()).enqueue(new Callback<GetAllDSETrainingFeedbackSummary>() {
  235. @Override
  236. public void onResponse(Call<GetAllDSETrainingFeedbackSummary> call, Response<GetAllDSETrainingFeedbackSummary> response) {
  237. if (response.body() != null) {
  238. if (response.body().getResponse().equalsIgnoreCase("Success")) {
  239. DSETrainingFeedbackData summaryData = response.body().getDseTrainingFeedbackData();
  240. if (summaryData.getQuestions() != null && summaryData.getQuestions().size() > 0) {
  241. GlobalData.DSEFeedbackQuestions = summaryData;
  242. FragmentTransaction transaction = manager.beginTransaction();
  243. trainersFeedback.setBackground(getResources().getDrawable(R.drawable.border_login_black));
  244. trainingFeedback.setBackground(getResources().getDrawable(R.drawable.border_login_white));
  245. transaction.replace(R.id.container, new DSETrainingFeedback());
  246. transaction.commit();
  247. } else {
  248. GlobalData.toast(getApplicationContext(), response.body().getMessage());
  249. }
  250. } else {
  251. GlobalData.toast(getApplicationContext(), response.body().getMessage());
  252. }
  253. } else if (response.body() != null && response.body().getStatus() == 401) {
  254. GlobalData.canLogout = true;
  255. finish();
  256. } else if (response.errorBody() != null) {
  257. Gson gson = new Gson();
  258. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  259. GlobalData.showToast(getApplicationContext(), message.getMessage(), Toast.LENGTH_SHORT).show();
  260. if (message.getStatus() == 401) {
  261. GlobalData.canLogout = true;
  262. finish();
  263. }
  264. }
  265. }
  266. @Override
  267. public void onFailure(Call<GetAllDSETrainingFeedbackSummary> call, Throwable t) {
  268. if (t.getMessage() != null) {
  269. Log.e("tmess", t.getMessage());
  270. }
  271. }
  272. });
  273. }
  274. private void setAllData() {
  275. if (GlobalData.DSEFEEDBACKVIEW != null) {
  276. txtTrainingName.setText(GlobalData.DSEFEEDBACKVIEW.getTitle());
  277. String endDate = GlobalData.DSEFEEDBACKVIEW.getEndDate();
  278. String startDate = GlobalData.DSEFEEDBACKVIEW.getStartDate();
  279. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
  280. String startDateString = "", endDateString = "";
  281. try {
  282. startDateString = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(Objects.requireNonNull(format.parse(startDate)));
  283. endDateString = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(Objects.requireNonNull(format.parse(endDate)));
  284. } catch (ParseException e) {
  285. e.printStackTrace();
  286. }
  287. String endTime = GlobalData.DSEFEEDBACKVIEW.getEndDate();
  288. String startTime = GlobalData.DSEFEEDBACKVIEW.getStartDate();
  289. SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
  290. String startTimeString = "", endTimeString = "";
  291. Date date1, date2;
  292. long difference = 0;
  293. try {
  294. date1 = timeFormat.parse(startTime);
  295. date2 = timeFormat.parse(endTime);
  296. startTimeString = new SimpleDateFormat("HH:mm", Locale.getDefault()).format(Objects.requireNonNull(timeFormat.parse(startTime)));
  297. endTimeString = new SimpleDateFormat("HH:mm", Locale.getDefault()).format(Objects.requireNonNull(timeFormat.parse(endTime)));
  298. difference = date1.getTime() - date2.getTime();
  299. } catch (ParseException e) {
  300. e.printStackTrace();
  301. }
  302. int days = (int) (difference / (1000 * 60 * 60 * 24));
  303. int hours = (int) ((difference - (1000 * 60 * 60 * 24 * days)) / (1000 * 60 * 60));
  304. int min = (int) (difference - (1000 * 60 * 60 * 24 * days) - (1000 * 60 * 60 * hours)) / (1000 * 60);
  305. min = (hours < 0 ? -min : min);
  306. Log.i("======= min", " :: " + min);
  307. txtTrainingStartDate.setText(startDateString);
  308. txtTrainingEndDate.setText(endDateString);
  309. txtTrainingTotalPArticipant.setText(GlobalData.DSEFEEDBACKVIEW.getTotal_participants());
  310. txtTrainingDuration.setText(GlobalData.DSEFEEDBACKVIEW.getOrganizer_name());
  311. txtTrainingVenue.setText(GlobalData.DSEFEEDBACKVIEW.getVenueAddress());
  312. if (GlobalData.user.getData().getSmpin() != null)
  313. smpin.setText(GlobalData.user.getData().getSmpin());
  314. participantName.setText(GlobalData.DSEFEEDBACKVIEW.getTraining_id());
  315. dealerName.setText(GlobalData.user.getData().getDealer().getName());
  316. Glide.with(DSEViewFeedbackActivity.this).load(GlobalData.DSEFEEDBACKRESPONSEGROUPIMAGE)
  317. .apply(new RequestOptions().fitCenter().diskCacheStrategy(DiskCacheStrategy.ALL)
  318. .placeholder(R.drawable.nodatafound)).into(imgAttendance);
  319. }
  320. }
  321. }