Beispiel #1
0
  private void getData() {
    try {
      noticeData = new ArrayList<>();
      DatabaseHandler handler = new DatabaseHandler(MainActivity.this);
      Cursor noticeCursor = handler.getNotice();
      noticeCursor.moveToFirst();
      do {
        NoticeData2 nd = new NoticeData2();
        nd.isNew = noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("isNew"));
        //    nd.alertTransId =
        // noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("alertTransId"));
        nd.sender_name = noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("sender_name"));
        nd.sender_round_photo =
            noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("sender_round_photo"));
        nd.sender_designation =
            noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("sender_designation"));
        nd.sent_date = noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("sent_date"));
        //   nd.alertText = noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("alertText"));
        nd.attachmentCount =
            noticeCursor.getInt(noticeCursor.getColumnIndexOrThrow("attachmentCount"));
        nd.attachments = noticeCursor.getString(noticeCursor.getColumnIndexOrThrow("attachments"));

        noticeData.add(nd);

      } while (noticeCursor.moveToNext());

      handler.close();
    } catch (Exception e) {
      Log.e("#Exc in getdata()", e.toString());
    }
  }
  private void fetchNoticeData(String type) {
    try {
      DatabaseHandler handler = new DatabaseHandler(DetailedDisplayActivity.this);
      handler.openDataBase();

      // Fetching NOTICE
      Cursor noticeCusrosr = handler.getNoticeByType(type);
      noticeCusrosr.moveToFirst();
      noticeData = new ArrayList<>();
      if (noticeCusrosr != null) {
        do {
          NoticeData2 notice = new NoticeData2();
          notice.noticeTransactId =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("noticeTransactId"));
          notice.noticeType =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("noticeType"));
          notice.sender_name =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sender_name"));
          notice.sender_round_photo =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sender_round_photo"));

          notice.sender_designation =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sender_designation"));
          notice.sent_date =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sent_date"));
          notice.subject = noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("subject"));
          notice.description =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("description"));
          notice.attachmentCount =
              noticeCusrosr.getInt(noticeCusrosr.getColumnIndexOrThrow("attachmentCount"));
          notice.isNew = noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("isNew"));
          String tempAttachment =
              noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("attachments"));
          notice.staffId = noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("staffID"));
          notice.attachments = tempAttachment;

          noticeData.add(notice);
        } while (noticeCusrosr.moveToNext());
      }

      handler.close();

    } catch (Exception e) {

      Log.e("%%% Exc", e.toString());
    }

    dat = new ArrayList<>();
    fragmentdat2 = new ArrayList<>();

    if (noticeData == null) {
      try {
        DatabaseHandler handler = new DatabaseHandler(DetailedDisplayActivity.this);
        handler.openDataBase();
        // Fetching NOTICE
        Cursor noticeCusrosr = handler.getNotice();
        noticeCusrosr.moveToFirst();
        noticeData = new ArrayList<>();
        if (noticeCusrosr != null) {
          do {
            NoticeData2 notice = new NoticeData2();
            notice.noticeTransactId =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("noticeTransactId"));
            notice.noticeType =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("noticeType"));
            notice.sender_name =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sender_name"));
            notice.sender_round_photo =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sender_round_photo"));

            notice.sender_designation =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sender_designation"));
            notice.sent_date =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("sent_date"));
            notice.subject =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("subject"));
            notice.description =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("description"));
            notice.attachmentCount =
                noticeCusrosr.getInt(noticeCusrosr.getColumnIndexOrThrow("attachmentCount"));
            notice.isNew = noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("isNew"));
            String tempAttachment =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("attachments"));
            notice.staffId =
                noticeCusrosr.getString(noticeCusrosr.getColumnIndexOrThrow("staffID"));

            notice.attachments = tempAttachment;

            noticeData.add(notice);
          } while (noticeCusrosr.moveToNext());
        }

        handler.close();
        for (int i = 0; i < noticeData.size(); i++) {
          InstituteData fr2 = new InstituteData();
          fr2.setNotice(noticeData.get(i));
          fr2.setType(1);
          dat.add(fr2);

          InstituteData2 InstituteData2 = new InstituteData2();
          InstituteData2.setType(1);
          InstituteData2.setData(
              noticeData.get(i).staffId,
              "",
              "",
              "",
              noticeData.get(i).noticeTransactId,
              noticeData.get(i).noticeType,
              noticeData.get(i).sender_name,
              noticeData.get(i).sender_round_photo,
              noticeData.get(i).sender_designation,
              noticeData.get(i).sent_date,
              noticeData.get(i).subject,
              noticeData.get(i).description,
              noticeData.get(i).attachmentCount,
              noticeData.get(i).attachments,
              noticeData.get(i).isNew,
              "",
              "");

          fragmentdat2.add(InstituteData2);
        }

        handler.close();
      } catch (Exception e) {
      }
    } else {
      for (int i = 0; i < noticeData.size(); i++) {
        InstituteData fr2 = new InstituteData();
        fr2.setNotice(noticeData.get(i));
        fr2.setType(1);
        dat.add(fr2);

        InstituteData2 InstituteData2 = new InstituteData2();
        InstituteData2.setType(1);
        InstituteData2.setData(
            noticeData.get(i).staffId,
            "",
            "",
            "",
            noticeData.get(i).noticeTransactId,
            noticeData.get(i).noticeType,
            noticeData.get(i).sender_name,
            noticeData.get(i).sender_round_photo,
            noticeData.get(i).sender_designation,
            noticeData.get(i).sent_date,
            noticeData.get(i).subject,
            noticeData.get(i).description,
            noticeData.get(i).attachmentCount,
            noticeData.get(i).attachments,
            noticeData.get(i).isNew,
            "",
            "");

        fragmentdat2.add(InstituteData2);
      }
    }
  }