NotificationAdapter.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. package com.cygnusa.hyperm.adapter;
  2. import android.content.ContentValues;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.os.Handler;
  7. import android.util.Log;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.ImageView;
  12. import android.widget.LinearLayout;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15. import androidx.annotation.NonNull;
  16. import androidx.recyclerview.widget.RecyclerView;
  17. import com.google.gson.Gson;
  18. import com.google.gson.JsonElement;
  19. import com.google.gson.reflect.TypeToken;
  20. import com.cygnusa.hyperm.AMHomeActivity;
  21. import com.cygnusa.hyperm.ASMScheduleViewActivity;
  22. import com.cygnusa.hyperm.AcceptTrainingActivity;
  23. import com.cygnusa.hyperm.AssessmentActivity;
  24. import com.cygnusa.hyperm.AudioViewActivity;
  25. import com.cygnusa.hyperm.BulletinDetails;
  26. import com.cygnusa.hyperm.ClassRoomDSETainingActivity;
  27. import com.cygnusa.hyperm.ClassRoomTrainerTainingActivity;
  28. import com.cygnusa.hyperm.HomeActivity;
  29. import com.cygnusa.hyperm.MyEarnedPoints;
  30. import com.cygnusa.hyperm.NotificationViewActivity;
  31. import com.cygnusa.hyperm.PdfViewActivity;
  32. import com.cygnusa.hyperm.R;
  33. import com.cygnusa.hyperm.SurveyActivity;
  34. import com.cygnusa.hyperm.VideoViewActivity;
  35. import com.cygnusa.hyperm.screenpinview.AppLockActivity;
  36. import com.cygnusa.hyperm.training.activities.ScheduleListActivity;
  37. import com.cygnusa.hyperm.util.ApiService;
  38. import com.cygnusa.hyperm.util.GlobalData;
  39. import com.cygnusa.hyperm.util.MyCallback;
  40. import com.cygnusa.hyperm.util.PositionUpdateListener;
  41. import com.cygnusa.hyperm.util.TransparentProgressDialog;
  42. import com.cygnusa.hyperm.util.UtilService;
  43. import com.cygnusa.hyperm.wrappers.AssessmentList;
  44. import com.cygnusa.hyperm.wrappers.AssessmentStatusResponse;
  45. import com.cygnusa.hyperm.wrappers.Bulletin;
  46. import com.cygnusa.hyperm.wrappers.BulletinStatusResponse;
  47. import com.cygnusa.hyperm.wrappers.ContentDetailResponse;
  48. import com.cygnusa.hyperm.wrappers.ContentFile;
  49. import com.cygnusa.hyperm.wrappers.ErrorResponse;
  50. import com.cygnusa.hyperm.wrappers.MyContent;
  51. import com.cygnusa.hyperm.wrappers.Notification;
  52. import com.cygnusa.hyperm.wrappers.Survey;
  53. import com.cygnusa.hyperm.wrappers.SurveyStatusResponse;
  54. import com.cygnusa.hyperm.wrappers.ViewScheduleListResponse;
  55. import java.text.SimpleDateFormat;
  56. import java.util.ArrayList;
  57. import java.util.HashMap;
  58. import java.util.Objects;
  59. import retrofit2.Call;
  60. import retrofit2.Callback;
  61. import retrofit2.Response;
  62. public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapter.ViewHolder> {
  63. private ArrayList<Notification> NOTIFICATION_LIST;
  64. private Context context;
  65. private PositionUpdateListener listener;
  66. private ApiService restService;
  67. private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  68. private SimpleDateFormat format1 = new SimpleDateFormat("dd-MMM-yyyy");
  69. private AssessmentList ASSESSMENT_LIST = new AssessmentList();
  70. private Survey SURVEY_LIST = new Survey();
  71. private MyContent myCon = new MyContent();
  72. private Bulletin myBulletin = new Bulletin();
  73. private TransparentProgressDialog progressDialog;
  74. public NotificationAdapter(Context context, ArrayList<Notification> items,
  75. PositionUpdateListener l, ApiService restService) {
  76. this.NOTIFICATION_LIST = items;
  77. this.context = context;
  78. this.listener = l;
  79. this.restService = restService;
  80. }
  81. @NonNull
  82. @Override
  83. public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  84. View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notification_item, parent, false);
  85. return new ViewHolder(v);
  86. }
  87. @Override
  88. public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
  89. Notification item = NOTIFICATION_LIST.get(position);
  90. holder.view.setTag(position);
  91. // int color1 = ColorGenerator.MATERIAL.getColor(item);
  92. // String cha = String.valueOf(item.getNotificationtitle().trim().toUpperCase().charAt(0));
  93. // TextDrawable drawable = TextDrawable.builder()
  94. // .beginConfig()
  95. // .withBorder(4)
  96. // .endConfig()
  97. // .buildRound(cha, color1);
  98. // holder.imageView.setImageDrawable(drawable);
  99. holder.description.setText(item.getNotificationtext());
  100. holder.title.setText(item.getNotificationtitle());
  101. holder.title.setSelected(true);
  102. if (item.getStatus().trim().equalsIgnoreCase("0")) {
  103. holder.unreadStatus.setVisibility(View.VISIBLE);
  104. holder.notificationLayout.setAlpha(1f);
  105. } else {
  106. holder.unreadStatus.setVisibility(View.GONE);
  107. holder.notificationLayout.setAlpha(0.6f);
  108. }
  109. try {
  110. holder.publishedDate.setText(String.format("Published On: %s", format1.format(Objects.requireNonNull(format.parse(item.getCreated_on())))));
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. }
  114. holder.view.setOnClickListener(new View.OnClickListener() {
  115. @Override
  116. public void onClick(View v) {
  117. int position = (int) v.getTag();
  118. if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("2")) {
  119. //getBulletinList(NOTIFICATION_LIST.get(position).getNotificationdata().getAssessmentid());
  120. getAssessmentListByCategory(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
  121. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("1")) {
  122. getContentCategory(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
  123. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("4")) {
  124. getBulletinList(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
  125. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("3")) {
  126. getSurveyListByCategory(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
  127. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("6")) {
  128. context.startActivity(new Intent(context, MyEarnedPoints.class));
  129. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("7")) {
  130. context.startActivity(new Intent(context, AppLockActivity.class));
  131. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("9")) {
  132. context.startActivity(new Intent(context, ScheduleListActivity.class));
  133. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("10")) {
  134. getScheduledList(NOTIFICATION_LIST.get(position).getNotificationdata().getSchedule_id());
  135. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("11")) {
  136. getFeedbackList(NOTIFICATION_LIST.get(position).getNotificationtype(), NOTIFICATION_LIST.get(position).getNotificationdata().getSchedule_id());
  137. } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("12")) {
  138. getFeedbackList(NOTIFICATION_LIST.get(position).getNotificationtype(), NOTIFICATION_LIST.get(position).getNotificationdata().getSchedule_id());
  139. } else {
  140. NotificationViewActivity.NOTIFICATION = NOTIFICATION_LIST.get(position);
  141. context.startActivity(new Intent(context, NotificationViewActivity.class));
  142. }
  143. if (NOTIFICATION_LIST.get(position).getStatus().trim().equalsIgnoreCase("0")) {
  144. updateNotification(position);
  145. }
  146. if (listener != null) {
  147. listener.onPositionUpdate(position);
  148. }
  149. }
  150. });
  151. }
  152. private void getFeedbackList(String type, String scheduleId) {
  153. restService.getScheduledList(scheduleId).enqueue(new Callback<ViewScheduleListResponse>() {
  154. @Override
  155. public void onResponse(Call<ViewScheduleListResponse> call, Response<ViewScheduleListResponse> response) {
  156. if (response.body() != null) {
  157. if (response.body().getData() != null) {
  158. GlobalData.scheduledDataList = new ArrayList<>();
  159. GlobalData.scheduledDataList = response.body().getData();
  160. if (GlobalData.scheduledDataList != null && GlobalData.scheduledDataList.size() > 0) {
  161. if (GlobalData.user.getData().getRole().equalsIgnoreCase("5")) {
  162. Intent intent = new Intent(context, ClassRoomTrainerTainingActivity.class);
  163. intent.putExtra("type", type);
  164. context.startActivity(intent);
  165. } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("10")) {
  166. Intent i = new Intent(context, ClassRoomDSETainingActivity.class);
  167. i.putExtra("type", type);
  168. context.startActivity(i);
  169. // context.startActivity(new Intent(context, ASMScheduleViewActivity.class));
  170. }
  171. } else {
  172. GlobalData.showToast(context, "No Data Found.", Toast.LENGTH_SHORT).show();
  173. }
  174. } else if (response.body() != null) {
  175. GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
  176. }
  177. } else if (response.body() != null && response.body().getStatus() == 401) {
  178. GlobalData.canLogout = true;
  179. } else if (response.errorBody() != null) {
  180. Gson gson = new Gson();
  181. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  182. GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
  183. if (message.getStatus() == 401) {
  184. GlobalData.canLogout = true;
  185. }
  186. }
  187. }
  188. @Override
  189. public void onFailure(Call<ViewScheduleListResponse> call, Throwable t) {
  190. Log.e("rr", t.getMessage());
  191. }
  192. });
  193. }
  194. private void getScheduledList(String scheduleId) {
  195. restService.getScheduledList(scheduleId).enqueue(new Callback<ViewScheduleListResponse>() {
  196. @Override
  197. public void onResponse(Call<ViewScheduleListResponse> call, Response<ViewScheduleListResponse> response) {
  198. if (response.body() != null) {
  199. if (response.body().getData() != null) {
  200. GlobalData.scheduledDataList = new ArrayList<>();
  201. GlobalData.scheduledDataList = response.body().getData();
  202. if (GlobalData.scheduledDataList != null && GlobalData.scheduledDataList.size() > 0) {
  203. if (GlobalData.scheduledDataList.get(0).getParticipant() != null && GlobalData.scheduledDataList.get(0).getParticipant().size() > 0) {
  204. if (GlobalData.user.getData().getRole().equalsIgnoreCase("10")) {
  205. context.startActivity(new Intent(context, AcceptTrainingActivity.class));
  206. } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("7")) {
  207. Intent i = new Intent(context, ASMScheduleViewActivity.class);
  208. i.putExtra("SCHEDULE_ID", scheduleId);
  209. context.startActivity(i);
  210. // context.startActivity(new Intent(context, ASMScheduleViewActivity.class));
  211. }
  212. } else {
  213. GlobalData.showToast(context, "No Data Found.", Toast.LENGTH_SHORT).show();
  214. }
  215. } else {
  216. GlobalData.showToast(context, "No Data Found.", Toast.LENGTH_SHORT).show();
  217. }
  218. } else if (response.body() != null) {
  219. GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
  220. }
  221. } else if (response.body() != null && response.body().getStatus() == 401) {
  222. GlobalData.canLogout = true;
  223. } else if (response.errorBody() != null) {
  224. Gson gson = new Gson();
  225. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  226. GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
  227. if (message.getStatus() == 401) {
  228. GlobalData.canLogout = true;
  229. }
  230. }
  231. }
  232. @Override
  233. public void onFailure(Call<ViewScheduleListResponse> call, Throwable t) {
  234. Log.e("rr", t.getMessage());
  235. }
  236. });
  237. }
  238. private void getBulletinList(String id) {
  239. progressDialog = new TransparentProgressDialog(context);
  240. progressDialog.show();
  241. if (new UtilService().isNetworkAvailable(context)) {
  242. try {
  243. restService.getBulletinByPosition(id).enqueue(new Callback<BulletinStatusResponse>() {
  244. @Override
  245. public void onResponse(Call<BulletinStatusResponse> call, Response<BulletinStatusResponse> response) {
  246. if (progressDialog != null && progressDialog.isShowing()) {
  247. progressDialog.dismiss();
  248. }
  249. if (response.body() != null && response.body().getStatus() == 200) {
  250. myBulletin = response.body().getData();
  251. goToBulletinActivity();
  252. if (myCon == null) {
  253. myCon = new MyContent();
  254. }
  255. } else if (response.body() != null && response.body().getStatus() == 401) {
  256. GlobalData.canLogout = true;
  257. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  258. } else if (response.body() != null) {
  259. GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
  260. } else if (response.errorBody() != null) {
  261. Gson gson = new Gson();
  262. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  263. GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
  264. if (message.getStatus() == 401) {
  265. GlobalData.canLogout = true;
  266. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  267. }
  268. }
  269. }
  270. @Override
  271. public void onFailure(Call<BulletinStatusResponse> call, Throwable t) {
  272. if (progressDialog != null && progressDialog.isShowing()) {
  273. progressDialog.dismiss();
  274. }
  275. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  276. }
  277. });
  278. } catch (Exception e) {
  279. if (progressDialog != null && progressDialog.isShowing()) {
  280. progressDialog.dismiss();
  281. }
  282. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  283. }
  284. } else {
  285. }
  286. }
  287. private void getContentCategory(String id) {
  288. progressDialog = new TransparentProgressDialog(context);
  289. progressDialog.show();
  290. if (new UtilService().isNetworkAvailable(context)) {
  291. try {
  292. restService.getTopicContentsDetails(id).enqueue(new Callback<ContentDetailResponse>() {
  293. @Override
  294. public void onResponse(Call<ContentDetailResponse> call, Response<ContentDetailResponse> response) {
  295. if (progressDialog != null && progressDialog.isShowing()) {
  296. progressDialog.dismiss();
  297. }
  298. if (response.body() != null && response.body().getStatus() == 200) {
  299. myCon = response.body().getData();
  300. goToTopicActivity();
  301. if (myCon == null) {
  302. myCon = new MyContent();
  303. }
  304. } else if (response.body() != null && response.body().getStatus() == 401) {
  305. GlobalData.canLogout = true;
  306. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  307. } else if (response.body() != null) {
  308. GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
  309. } else if (response.errorBody() != null) {
  310. Gson gson = new Gson();
  311. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  312. GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
  313. if (message.getStatus() == 401) {
  314. GlobalData.canLogout = true;
  315. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  316. }
  317. }
  318. }
  319. @Override
  320. public void onFailure(Call<ContentDetailResponse> call, Throwable t) {
  321. if (progressDialog != null && progressDialog.isShowing()) {
  322. progressDialog.dismiss();
  323. }
  324. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  325. }
  326. });
  327. } catch (Exception e) {
  328. if (progressDialog != null && progressDialog.isShowing()) {
  329. progressDialog.dismiss();
  330. }
  331. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  332. }
  333. } else {
  334. }
  335. }
  336. private void getAssessmentListByCategory(String id) {
  337. progressDialog = new TransparentProgressDialog(context);
  338. progressDialog.show();
  339. if (new UtilService().isNetworkAvailable(context)) {
  340. try {
  341. restService.getAssessmentByPosition(id).enqueue(new Callback<AssessmentStatusResponse>() {
  342. @Override
  343. public void onResponse(Call<AssessmentStatusResponse> call, Response<AssessmentStatusResponse> response) {
  344. if (progressDialog != null && progressDialog.isShowing()) {
  345. progressDialog.dismiss();
  346. }
  347. if (response.body() != null && response.body().getStatus() == 200) {
  348. ASSESSMENT_LIST = response.body().getData();
  349. goToAssessmentActivity();
  350. if (ASSESSMENT_LIST == null) {
  351. ASSESSMENT_LIST = new AssessmentList();
  352. }
  353. } else if (response.body() != null && response.body().getStatus() == 401) {
  354. GlobalData.canLogout = true;
  355. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  356. } else if (response.body() != null) {
  357. GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
  358. } else if (response.errorBody() != null) {
  359. Gson gson = new Gson();
  360. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  361. GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
  362. if (message.getStatus() == 401) {
  363. GlobalData.canLogout = true;
  364. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  365. }
  366. }
  367. }
  368. @Override
  369. public void onFailure(Call<AssessmentStatusResponse> call, Throwable t) {
  370. if (progressDialog != null && progressDialog.isShowing()) {
  371. progressDialog.dismiss();
  372. }
  373. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  374. }
  375. });
  376. } catch (Exception e) {
  377. if (progressDialog != null && progressDialog.isShowing()) {
  378. progressDialog.dismiss();
  379. }
  380. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  381. }
  382. } else {
  383. }
  384. }
  385. private void getSurveyListByCategory(String id) {
  386. progressDialog = new TransparentProgressDialog(context);
  387. progressDialog.show();
  388. if (new UtilService().isNetworkAvailable(context)) {
  389. try {
  390. restService.getSurveyByPosition(id).enqueue(new Callback<SurveyStatusResponse>() {
  391. @Override
  392. public void onResponse(Call<SurveyStatusResponse> call, Response<SurveyStatusResponse> response) {
  393. if (progressDialog != null && progressDialog.isShowing()) {
  394. progressDialog.dismiss();
  395. }
  396. if (response.body() != null && response.body().getStatus() == 200) {
  397. SURVEY_LIST = response.body().getData();
  398. goToSurveyActivity();
  399. if (SURVEY_LIST == null) {
  400. SURVEY_LIST = new Survey();
  401. }
  402. } else if (response.body() != null && response.body().getStatus() == 401) {
  403. GlobalData.canLogout = true;
  404. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  405. } else if (response.body() != null) {
  406. GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
  407. } else if (response.errorBody() != null) {
  408. Gson gson = new Gson();
  409. ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
  410. GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
  411. if (message.getStatus() == 401) {
  412. GlobalData.canLogout = true;
  413. new Handler(HomeActivity.callback).sendEmptyMessage(0);
  414. }
  415. }
  416. }
  417. @Override
  418. public void onFailure(Call<SurveyStatusResponse> call, Throwable t) {
  419. if (progressDialog != null && progressDialog.isShowing()) {
  420. progressDialog.dismiss();
  421. }
  422. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  423. }
  424. });
  425. } catch (Exception e) {
  426. if (progressDialog != null && progressDialog.isShowing()) {
  427. progressDialog.dismiss();
  428. }
  429. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  430. }
  431. } else {
  432. }
  433. }
  434. private void goToSurveyActivity() {
  435. SurveyActivity.ASSESSMENT = SURVEY_LIST;
  436. if (listener != null) {
  437. // listener.onPositionUpdate(SURVEY_LIST.indexOf(SURVEY_LIST));
  438. }
  439. context.startActivity(new Intent(context, SurveyActivity.class));
  440. }
  441. private void goToBulletinActivity() {
  442. BulletinDetails.CONTENT = myBulletin;
  443. if (listener != null) {
  444. // listener.onPositionUpdate(SURVEY_LIST.indexOf(SURVEY_LIST));
  445. }
  446. context.startActivity(new Intent(context, BulletinDetails.class));
  447. }
  448. private void goToTopicActivity() {
  449. ContentFile file = getContentFile(myCon);
  450. assert file != null;
  451. if (file.getFiletypeid().trim().equalsIgnoreCase("1")) {
  452. PdfViewActivity.CONTENT = myCon;
  453. //PdfViewActivity.TOPIC = myCon.getTitle();
  454. Intent i = new Intent(context, PdfViewActivity.class);
  455. i.putExtra("type", "notification");
  456. context.startActivity(i);
  457. } else if (file.getFiletypeid().trim().equalsIgnoreCase("2")) {
  458. VideoViewActivity.CONTENT = myCon;
  459. Intent i = new Intent(context, VideoViewActivity.class);
  460. i.putExtra("type", "notification");
  461. context.startActivity(i);
  462. } else if (file.getFiletypeid().trim().equalsIgnoreCase("3")) {
  463. AudioViewActivity.CONTENT = myCon;
  464. // AudioViewActivity.TOPIC = TOPIC;
  465. context.startActivity(new Intent(context, AudioViewActivity.class));
  466. }
  467. }
  468. private ContentFile getContentFile(MyContent item) {
  469. if (item.getContent_files() == null) {
  470. return null;
  471. }
  472. String language = context.getSharedPreferences("LANGUAGE", Context.MODE_PRIVATE).getString("DEFAULT", "en_us");
  473. for (ContentFile file : item.getContent_files()) {
  474. if (file.getLanguage_code().trim().equalsIgnoreCase(language.trim())) {
  475. return file;
  476. }
  477. }
  478. return item.getContent_files().get(0);
  479. }
  480. private void goToAssessmentActivity() {
  481. if (Integer.parseInt(ASSESSMENT_LIST.getAttemptslimit().trim())
  482. > ASSESSMENT_LIST.getAttempt_time()) {
  483. if (ASSESSMENT_LIST.getIs_expired().trim().equalsIgnoreCase("0")) {
  484. AssessmentActivity.ASSESSMENT = ASSESSMENT_LIST;
  485. context.startActivity(new Intent(context, AssessmentActivity.class));
  486. } else {
  487. GlobalData.showToast(context,
  488. "Assessment expired", Toast.LENGTH_SHORT).show();
  489. }
  490. } else {
  491. GlobalData.showToast(context, "You have attempted this test "
  492. + ASSESSMENT_LIST.getAttempt_time() + " times. Please contact the admin for more details.", Toast.LENGTH_SHORT).show();
  493. }
  494. }
  495. private void updateNotification(int id) {
  496. Cursor cursor = GlobalData.sdb.rawQuery("select * from notification_readed", null);
  497. String ids;
  498. if (cursor.getCount() > 0) {
  499. cursor.moveToFirst();
  500. ids = cursor.getString(cursor.getColumnIndex("notification_readed"));
  501. ids = ids + "," + NOTIFICATION_LIST.get(id).getId().trim();
  502. } else {
  503. ids = NOTIFICATION_LIST.get(id).getId().trim();
  504. }
  505. NOTIFICATION_LIST.get(id).setStatus("1");
  506. notifyDataSetChanged();
  507. GlobalData.sdb.delete("notification_readed", null, null);
  508. ContentValues values1 = new ContentValues();
  509. values1.put("notification_readed", ids);
  510. GlobalData.sdb.insert("notification_readed", null, values1);
  511. GlobalData.sdb.delete("notifications", null, null);
  512. Gson gson = new Gson();
  513. JsonElement jsonElement = gson.toJsonTree(
  514. NOTIFICATION_LIST, new TypeToken<ArrayList<Notification>>() {
  515. }.getType());
  516. ContentValues values = new ContentValues();
  517. values.put("notifications", jsonElement.toString());
  518. GlobalData.sdb.insert("notifications", null, values);
  519. if (new UtilService().isNetworkAvailable(context)) {
  520. HashMap<String, String> map = new HashMap<>();
  521. map.put("notificationid", ids);
  522. restService.updateReadNotifications(map)
  523. .enqueue(new MyCallback<ErrorResponse>(ids) {
  524. @Override
  525. public void onResponse(Call<ErrorResponse> call, Response<ErrorResponse> response) {
  526. if (response.body() != null && response.body().getStatus() == 200) {
  527. GlobalData.sdb.delete("notification_readed", null, null);
  528. }
  529. try {
  530. new Handler(HomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
  531. new Handler(AMHomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535. }
  536. @Override
  537. public void onFailure(Call<ErrorResponse> call, Throwable t) {
  538. GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
  539. }
  540. });
  541. } else {
  542. try {
  543. new Handler(HomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
  544. new Handler(AMHomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
  545. } catch (Exception e) {
  546. e.printStackTrace();
  547. }
  548. }
  549. }
  550. @Override
  551. public int getItemCount() {
  552. return NOTIFICATION_LIST.size();
  553. }
  554. public void add(Notification item, int position) {
  555. NOTIFICATION_LIST.add(position, item);
  556. notifyItemInserted(position);
  557. }
  558. public void add(Notification item) {
  559. NOTIFICATION_LIST.add(item);
  560. notifyItemInserted(NOTIFICATION_LIST.size());
  561. }
  562. public void remove(int position) {
  563. NOTIFICATION_LIST.remove(position);
  564. notifyItemRemoved(position);
  565. }
  566. class ViewHolder extends RecyclerView.ViewHolder {
  567. TextView unreadStatus, publishedDate, title, description;
  568. View view;
  569. ImageView imageView;
  570. LinearLayout notificationLayout;
  571. private ViewHolder(View itemView) {
  572. super(itemView);
  573. view = itemView;
  574. unreadStatus = itemView.findViewById(R.id.unreadStatus);
  575. publishedDate = itemView.findViewById(R.id.publishedDate);
  576. title = itemView.findViewById(R.id.title);
  577. description = itemView.findViewById(R.id.description);
  578. imageView = itemView.findViewById(R.id.imageView);
  579. notificationLayout = itemView.findViewById(R.id.mainView);
  580. }
  581. }
  582. }