| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- package com.cygnusa.hyperm.adapter;
- import android.content.ContentValues;
- import android.content.Context;
- import android.content.Intent;
- import android.database.Cursor;
- import android.os.Handler;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import androidx.annotation.NonNull;
- import androidx.recyclerview.widget.RecyclerView;
- import com.google.gson.Gson;
- import com.google.gson.JsonElement;
- import com.google.gson.reflect.TypeToken;
- import com.cygnusa.hyperm.AMHomeActivity;
- import com.cygnusa.hyperm.ASMScheduleViewActivity;
- import com.cygnusa.hyperm.AcceptTrainingActivity;
- import com.cygnusa.hyperm.AssessmentActivity;
- import com.cygnusa.hyperm.AudioViewActivity;
- import com.cygnusa.hyperm.BulletinDetails;
- import com.cygnusa.hyperm.ClassRoomDSETainingActivity;
- import com.cygnusa.hyperm.ClassRoomTrainerTainingActivity;
- import com.cygnusa.hyperm.HomeActivity;
- import com.cygnusa.hyperm.MyEarnedPoints;
- import com.cygnusa.hyperm.NotificationViewActivity;
- import com.cygnusa.hyperm.PdfViewActivity;
- import com.cygnusa.hyperm.R;
- import com.cygnusa.hyperm.SurveyActivity;
- import com.cygnusa.hyperm.VideoViewActivity;
- import com.cygnusa.hyperm.screenpinview.AppLockActivity;
- import com.cygnusa.hyperm.training.activities.ScheduleListActivity;
- import com.cygnusa.hyperm.util.ApiService;
- import com.cygnusa.hyperm.util.GlobalData;
- import com.cygnusa.hyperm.util.MyCallback;
- import com.cygnusa.hyperm.util.PositionUpdateListener;
- import com.cygnusa.hyperm.util.TransparentProgressDialog;
- import com.cygnusa.hyperm.util.UtilService;
- import com.cygnusa.hyperm.wrappers.AssessmentList;
- import com.cygnusa.hyperm.wrappers.AssessmentStatusResponse;
- import com.cygnusa.hyperm.wrappers.Bulletin;
- import com.cygnusa.hyperm.wrappers.BulletinStatusResponse;
- import com.cygnusa.hyperm.wrappers.ContentDetailResponse;
- import com.cygnusa.hyperm.wrappers.ContentFile;
- import com.cygnusa.hyperm.wrappers.ErrorResponse;
- import com.cygnusa.hyperm.wrappers.MyContent;
- import com.cygnusa.hyperm.wrappers.Notification;
- import com.cygnusa.hyperm.wrappers.Survey;
- import com.cygnusa.hyperm.wrappers.SurveyStatusResponse;
- import com.cygnusa.hyperm.wrappers.ViewScheduleListResponse;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Objects;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapter.ViewHolder> {
- private ArrayList<Notification> NOTIFICATION_LIST;
- private Context context;
- private PositionUpdateListener listener;
- private ApiService restService;
- private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- private SimpleDateFormat format1 = new SimpleDateFormat("dd-MMM-yyyy");
- private AssessmentList ASSESSMENT_LIST = new AssessmentList();
- private Survey SURVEY_LIST = new Survey();
- private MyContent myCon = new MyContent();
- private Bulletin myBulletin = new Bulletin();
- private TransparentProgressDialog progressDialog;
- public NotificationAdapter(Context context, ArrayList<Notification> items,
- PositionUpdateListener l, ApiService restService) {
- this.NOTIFICATION_LIST = items;
- this.context = context;
- this.listener = l;
- this.restService = restService;
- }
- @NonNull
- @Override
- public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notification_item, parent, false);
- return new ViewHolder(v);
- }
- @Override
- public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
- Notification item = NOTIFICATION_LIST.get(position);
- holder.view.setTag(position);
- // int color1 = ColorGenerator.MATERIAL.getColor(item);
- // String cha = String.valueOf(item.getNotificationtitle().trim().toUpperCase().charAt(0));
- // TextDrawable drawable = TextDrawable.builder()
- // .beginConfig()
- // .withBorder(4)
- // .endConfig()
- // .buildRound(cha, color1);
- // holder.imageView.setImageDrawable(drawable);
- holder.description.setText(item.getNotificationtext());
- holder.title.setText(item.getNotificationtitle());
- holder.title.setSelected(true);
- if (item.getStatus().trim().equalsIgnoreCase("0")) {
- holder.unreadStatus.setVisibility(View.VISIBLE);
- holder.notificationLayout.setAlpha(1f);
- } else {
- holder.unreadStatus.setVisibility(View.GONE);
- holder.notificationLayout.setAlpha(0.6f);
- }
- try {
- holder.publishedDate.setText(String.format("Published On: %s", format1.format(Objects.requireNonNull(format.parse(item.getCreated_on())))));
- } catch (Exception e) {
- e.printStackTrace();
- }
- holder.view.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int position = (int) v.getTag();
- if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("2")) {
- //getBulletinList(NOTIFICATION_LIST.get(position).getNotificationdata().getAssessmentid());
- getAssessmentListByCategory(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("1")) {
- getContentCategory(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("4")) {
- getBulletinList(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("3")) {
- getSurveyListByCategory(NOTIFICATION_LIST.get(position).getNotificationdata().getId());
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("6")) {
- context.startActivity(new Intent(context, MyEarnedPoints.class));
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("7")) {
- context.startActivity(new Intent(context, AppLockActivity.class));
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("9")) {
- context.startActivity(new Intent(context, ScheduleListActivity.class));
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("10")) {
- getScheduledList(NOTIFICATION_LIST.get(position).getNotificationdata().getSchedule_id());
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("11")) {
- getFeedbackList(NOTIFICATION_LIST.get(position).getNotificationtype(), NOTIFICATION_LIST.get(position).getNotificationdata().getSchedule_id());
- } else if (NOTIFICATION_LIST.get(position).getNotificationtype().equalsIgnoreCase("12")) {
- getFeedbackList(NOTIFICATION_LIST.get(position).getNotificationtype(), NOTIFICATION_LIST.get(position).getNotificationdata().getSchedule_id());
- } else {
- NotificationViewActivity.NOTIFICATION = NOTIFICATION_LIST.get(position);
- context.startActivity(new Intent(context, NotificationViewActivity.class));
- }
- if (NOTIFICATION_LIST.get(position).getStatus().trim().equalsIgnoreCase("0")) {
- updateNotification(position);
- }
- if (listener != null) {
- listener.onPositionUpdate(position);
- }
- }
- });
- }
- private void getFeedbackList(String type, String scheduleId) {
- restService.getScheduledList(scheduleId).enqueue(new Callback<ViewScheduleListResponse>() {
- @Override
- public void onResponse(Call<ViewScheduleListResponse> call, Response<ViewScheduleListResponse> response) {
- if (response.body() != null) {
- if (response.body().getData() != null) {
- GlobalData.scheduledDataList = new ArrayList<>();
- GlobalData.scheduledDataList = response.body().getData();
- if (GlobalData.scheduledDataList != null && GlobalData.scheduledDataList.size() > 0) {
- if (GlobalData.user.getData().getRole().equalsIgnoreCase("5")) {
- Intent intent = new Intent(context, ClassRoomTrainerTainingActivity.class);
- intent.putExtra("type", type);
- context.startActivity(intent);
- } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("10")) {
- Intent i = new Intent(context, ClassRoomDSETainingActivity.class);
- i.putExtra("type", type);
- context.startActivity(i);
- // context.startActivity(new Intent(context, ASMScheduleViewActivity.class));
- }
- } else {
- GlobalData.showToast(context, "No Data Found.", Toast.LENGTH_SHORT).show();
- }
- } else if (response.body() != null) {
- GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
- }
- } else if (response.body() != null && response.body().getStatus() == 401) {
- GlobalData.canLogout = true;
- } else if (response.errorBody() != null) {
- Gson gson = new Gson();
- ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
- GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
- if (message.getStatus() == 401) {
- GlobalData.canLogout = true;
- }
- }
- }
- @Override
- public void onFailure(Call<ViewScheduleListResponse> call, Throwable t) {
- Log.e("rr", t.getMessage());
- }
- });
- }
- private void getScheduledList(String scheduleId) {
- restService.getScheduledList(scheduleId).enqueue(new Callback<ViewScheduleListResponse>() {
- @Override
- public void onResponse(Call<ViewScheduleListResponse> call, Response<ViewScheduleListResponse> response) {
- if (response.body() != null) {
- if (response.body().getData() != null) {
- GlobalData.scheduledDataList = new ArrayList<>();
- GlobalData.scheduledDataList = response.body().getData();
- if (GlobalData.scheduledDataList != null && GlobalData.scheduledDataList.size() > 0) {
- if (GlobalData.scheduledDataList.get(0).getParticipant() != null && GlobalData.scheduledDataList.get(0).getParticipant().size() > 0) {
- if (GlobalData.user.getData().getRole().equalsIgnoreCase("10")) {
- context.startActivity(new Intent(context, AcceptTrainingActivity.class));
- } else if (GlobalData.user.getData().getRole().equalsIgnoreCase("7")) {
- Intent i = new Intent(context, ASMScheduleViewActivity.class);
- i.putExtra("SCHEDULE_ID", scheduleId);
- context.startActivity(i);
- // context.startActivity(new Intent(context, ASMScheduleViewActivity.class));
- }
- } else {
- GlobalData.showToast(context, "No Data Found.", Toast.LENGTH_SHORT).show();
- }
- } else {
- GlobalData.showToast(context, "No Data Found.", Toast.LENGTH_SHORT).show();
- }
- } else if (response.body() != null) {
- GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
- }
- } else if (response.body() != null && response.body().getStatus() == 401) {
- GlobalData.canLogout = true;
- } else if (response.errorBody() != null) {
- Gson gson = new Gson();
- ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
- GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
- if (message.getStatus() == 401) {
- GlobalData.canLogout = true;
- }
- }
- }
- @Override
- public void onFailure(Call<ViewScheduleListResponse> call, Throwable t) {
- Log.e("rr", t.getMessage());
- }
- });
- }
- private void getBulletinList(String id) {
- progressDialog = new TransparentProgressDialog(context);
- progressDialog.show();
- if (new UtilService().isNetworkAvailable(context)) {
- try {
- restService.getBulletinByPosition(id).enqueue(new Callback<BulletinStatusResponse>() {
- @Override
- public void onResponse(Call<BulletinStatusResponse> call, Response<BulletinStatusResponse> response) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- if (response.body() != null && response.body().getStatus() == 200) {
- myBulletin = response.body().getData();
- goToBulletinActivity();
- if (myCon == null) {
- myCon = new MyContent();
- }
- } else if (response.body() != null && response.body().getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- } else if (response.body() != null) {
- GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
- } else if (response.errorBody() != null) {
- Gson gson = new Gson();
- ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
- GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
- if (message.getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- }
- }
- }
- @Override
- public void onFailure(Call<BulletinStatusResponse> call, Throwable t) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- });
- } catch (Exception e) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- } else {
- }
- }
- private void getContentCategory(String id) {
- progressDialog = new TransparentProgressDialog(context);
- progressDialog.show();
- if (new UtilService().isNetworkAvailable(context)) {
- try {
- restService.getTopicContentsDetails(id).enqueue(new Callback<ContentDetailResponse>() {
- @Override
- public void onResponse(Call<ContentDetailResponse> call, Response<ContentDetailResponse> response) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- if (response.body() != null && response.body().getStatus() == 200) {
- myCon = response.body().getData();
- goToTopicActivity();
- if (myCon == null) {
- myCon = new MyContent();
- }
- } else if (response.body() != null && response.body().getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- } else if (response.body() != null) {
- GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
- } else if (response.errorBody() != null) {
- Gson gson = new Gson();
- ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
- GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
- if (message.getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- }
- }
- }
- @Override
- public void onFailure(Call<ContentDetailResponse> call, Throwable t) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- });
- } catch (Exception e) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- } else {
- }
- }
- private void getAssessmentListByCategory(String id) {
- progressDialog = new TransparentProgressDialog(context);
- progressDialog.show();
- if (new UtilService().isNetworkAvailable(context)) {
- try {
- restService.getAssessmentByPosition(id).enqueue(new Callback<AssessmentStatusResponse>() {
- @Override
- public void onResponse(Call<AssessmentStatusResponse> call, Response<AssessmentStatusResponse> response) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- if (response.body() != null && response.body().getStatus() == 200) {
- ASSESSMENT_LIST = response.body().getData();
- goToAssessmentActivity();
- if (ASSESSMENT_LIST == null) {
- ASSESSMENT_LIST = new AssessmentList();
- }
- } else if (response.body() != null && response.body().getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- } else if (response.body() != null) {
- GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
- } else if (response.errorBody() != null) {
- Gson gson = new Gson();
- ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
- GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
- if (message.getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- }
- }
- }
- @Override
- public void onFailure(Call<AssessmentStatusResponse> call, Throwable t) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- });
- } catch (Exception e) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- } else {
- }
- }
- private void getSurveyListByCategory(String id) {
- progressDialog = new TransparentProgressDialog(context);
- progressDialog.show();
- if (new UtilService().isNetworkAvailable(context)) {
- try {
- restService.getSurveyByPosition(id).enqueue(new Callback<SurveyStatusResponse>() {
- @Override
- public void onResponse(Call<SurveyStatusResponse> call, Response<SurveyStatusResponse> response) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- if (response.body() != null && response.body().getStatus() == 200) {
- SURVEY_LIST = response.body().getData();
- goToSurveyActivity();
- if (SURVEY_LIST == null) {
- SURVEY_LIST = new Survey();
- }
- } else if (response.body() != null && response.body().getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- } else if (response.body() != null) {
- GlobalData.showToast(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
- } else if (response.errorBody() != null) {
- Gson gson = new Gson();
- ErrorResponse message = gson.fromJson(response.errorBody().charStream(), ErrorResponse.class);
- GlobalData.showToast(context, message.getMessage(), Toast.LENGTH_SHORT).show();
- if (message.getStatus() == 401) {
- GlobalData.canLogout = true;
- new Handler(HomeActivity.callback).sendEmptyMessage(0);
- }
- }
- }
- @Override
- public void onFailure(Call<SurveyStatusResponse> call, Throwable t) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- });
- } catch (Exception e) {
- if (progressDialog != null && progressDialog.isShowing()) {
- progressDialog.dismiss();
- }
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- } else {
- }
- }
- private void goToSurveyActivity() {
- SurveyActivity.ASSESSMENT = SURVEY_LIST;
- if (listener != null) {
- // listener.onPositionUpdate(SURVEY_LIST.indexOf(SURVEY_LIST));
- }
- context.startActivity(new Intent(context, SurveyActivity.class));
- }
- private void goToBulletinActivity() {
- BulletinDetails.CONTENT = myBulletin;
- if (listener != null) {
- // listener.onPositionUpdate(SURVEY_LIST.indexOf(SURVEY_LIST));
- }
- context.startActivity(new Intent(context, BulletinDetails.class));
- }
- private void goToTopicActivity() {
- ContentFile file = getContentFile(myCon);
- assert file != null;
- if (file.getFiletypeid().trim().equalsIgnoreCase("1")) {
- PdfViewActivity.CONTENT = myCon;
- //PdfViewActivity.TOPIC = myCon.getTitle();
- Intent i = new Intent(context, PdfViewActivity.class);
- i.putExtra("type", "notification");
- context.startActivity(i);
- } else if (file.getFiletypeid().trim().equalsIgnoreCase("2")) {
- VideoViewActivity.CONTENT = myCon;
- Intent i = new Intent(context, VideoViewActivity.class);
- i.putExtra("type", "notification");
- context.startActivity(i);
- } else if (file.getFiletypeid().trim().equalsIgnoreCase("3")) {
- AudioViewActivity.CONTENT = myCon;
- // AudioViewActivity.TOPIC = TOPIC;
- context.startActivity(new Intent(context, AudioViewActivity.class));
- }
- }
- private ContentFile getContentFile(MyContent item) {
- if (item.getContent_files() == null) {
- return null;
- }
- String language = context.getSharedPreferences("LANGUAGE", Context.MODE_PRIVATE).getString("DEFAULT", "en_us");
- for (ContentFile file : item.getContent_files()) {
- if (file.getLanguage_code().trim().equalsIgnoreCase(language.trim())) {
- return file;
- }
- }
- return item.getContent_files().get(0);
- }
- private void goToAssessmentActivity() {
- if (Integer.parseInt(ASSESSMENT_LIST.getAttemptslimit().trim())
- > ASSESSMENT_LIST.getAttempt_time()) {
- if (ASSESSMENT_LIST.getIs_expired().trim().equalsIgnoreCase("0")) {
- AssessmentActivity.ASSESSMENT = ASSESSMENT_LIST;
- context.startActivity(new Intent(context, AssessmentActivity.class));
- } else {
- GlobalData.showToast(context,
- "Assessment expired", Toast.LENGTH_SHORT).show();
- }
- } else {
- GlobalData.showToast(context, "You have attempted this test "
- + ASSESSMENT_LIST.getAttempt_time() + " times. Please contact the admin for more details.", Toast.LENGTH_SHORT).show();
- }
- }
- private void updateNotification(int id) {
- Cursor cursor = GlobalData.sdb.rawQuery("select * from notification_readed", null);
- String ids;
- if (cursor.getCount() > 0) {
- cursor.moveToFirst();
- ids = cursor.getString(cursor.getColumnIndex("notification_readed"));
- ids = ids + "," + NOTIFICATION_LIST.get(id).getId().trim();
- } else {
- ids = NOTIFICATION_LIST.get(id).getId().trim();
- }
- NOTIFICATION_LIST.get(id).setStatus("1");
- notifyDataSetChanged();
- GlobalData.sdb.delete("notification_readed", null, null);
- ContentValues values1 = new ContentValues();
- values1.put("notification_readed", ids);
- GlobalData.sdb.insert("notification_readed", null, values1);
- GlobalData.sdb.delete("notifications", null, null);
- Gson gson = new Gson();
- JsonElement jsonElement = gson.toJsonTree(
- NOTIFICATION_LIST, new TypeToken<ArrayList<Notification>>() {
- }.getType());
- ContentValues values = new ContentValues();
- values.put("notifications", jsonElement.toString());
- GlobalData.sdb.insert("notifications", null, values);
- if (new UtilService().isNetworkAvailable(context)) {
- HashMap<String, String> map = new HashMap<>();
- map.put("notificationid", ids);
- restService.updateReadNotifications(map)
- .enqueue(new MyCallback<ErrorResponse>(ids) {
- @Override
- public void onResponse(Call<ErrorResponse> call, Response<ErrorResponse> response) {
- if (response.body() != null && response.body().getStatus() == 200) {
- GlobalData.sdb.delete("notification_readed", null, null);
- }
- try {
- new Handler(HomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
- new Handler(AMHomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onFailure(Call<ErrorResponse> call, Throwable t) {
- GlobalData.showToast(context, "Connection Failure, try again!", Toast.LENGTH_SHORT).show();
- }
- });
- } else {
- try {
- new Handler(HomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
- new Handler(AMHomeActivity.badgeUpdateCallback).sendEmptyMessage(0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- @Override
- public int getItemCount() {
- return NOTIFICATION_LIST.size();
- }
- public void add(Notification item, int position) {
- NOTIFICATION_LIST.add(position, item);
- notifyItemInserted(position);
- }
- public void add(Notification item) {
- NOTIFICATION_LIST.add(item);
- notifyItemInserted(NOTIFICATION_LIST.size());
- }
- public void remove(int position) {
- NOTIFICATION_LIST.remove(position);
- notifyItemRemoved(position);
- }
- class ViewHolder extends RecyclerView.ViewHolder {
- TextView unreadStatus, publishedDate, title, description;
- View view;
- ImageView imageView;
- LinearLayout notificationLayout;
- private ViewHolder(View itemView) {
- super(itemView);
- view = itemView;
- unreadStatus = itemView.findViewById(R.id.unreadStatus);
- publishedDate = itemView.findViewById(R.id.publishedDate);
- title = itemView.findViewById(R.id.title);
- description = itemView.findViewById(R.id.description);
- imageView = itemView.findViewById(R.id.imageView);
- notificationLayout = itemView.findViewById(R.id.mainView);
- }
- }
- }
|