title: Android have seen list
body: <p>Im trying to have a checked button where where the user click it will set the hasSeen boolean to true. The problem is when the user refresh, it will fetch new data from the server and overrides the value. Im trying to cache it but it seems like im stuck. </p>
  
  <pre><code>public class CaseFragment extends BaseFragment implements View.OnClickListener {
  
      private CaseAdapter caseAdapter;
  
      private RecyclerView caseRecycler;
  
      private ArrayList&lt;Rfq&gt; caseList,ca;
      private ArrayList&lt;DealerCase&gt; caseDetails;
  
  
      private DealerCase carDetails;
      private RequestQueue rq;
  
      private TextView textUpdatedTime,test2;
      private SwipeRefreshLayout swipeRefreshLayout;
  
      public CaseFragment(){
          caseList = new ArrayList&lt;&gt;();
  
      }
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater,  ViewGroup container, Bundle savedInstanceState) {
          view = inflater.inflate(R.layout.tab_cases, null);
  
          caseRecycler = (RecyclerView)view.findViewById(R.id.recycler_view_case);
          textUpdatedTime = (TextView)view.findViewById(R.id.textView8);
          LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
          caseRecycler.setLayoutManager(linearLayoutManager);
          caseAdapter = new CaseAdapter();
          caseAdapter.setData(caseList);
          caseRecycler.setAdapter(caseAdapter);
          caseRecycler.setFocusable(false);
  
          rq = Volley.newRequestQueue(getContext());
          lastUpdated();
  
          swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
          // swipe refresh layout
          swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
                  //loadCase();
                  requestNewCase();
                  lastUpdated();
                  swipeRefreshLayout.setRefreshing(false);
  
              }
          });
  
  
  
  
          caseAdapter.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(int position) {
                  String uid = caseList.get(position).getUid();
                  caseList.get(position).setIsSeen(true);
                  requestNewCase();
                  caseAdapter.notifyDataSetChanged();
                  getCaseDetails(uid,KeyConfig.NEW);
              }
          });
  
  
          return view;
      }
  
      private void loadFromCache() {
  
  
          String uri = String.format(UriManager.getDealerCase(),
                  GlobalConstant.NEW);
          ApiManager.getInstance().authUrlRequest(getActivity(), KeyConfig.CACHE_NEW, true, true, StringRequest.Method.GET, uri, new OnResponseListener() {
              @Override
              public void onResponse(String response, boolean fromCache) {
                  if(response != null) {
                      caseList.clear();
  
                      String newList = CacheManager.getInstance().getCache().get(KeyConfig.CACHE_NEW);
                      Gson gson = new Gson();
  
                      DealerCase caseModel = gson.fromJson(newList, DealerCase.class);
  
                      if(caseModel.getData().getRfqs() != null){
  
                          int b = caseModel.getData().getRfqs().size();
  
                          //Toast.makeText(getContext(), String.valueOf(ca.size())+" - " + String.valueOf(caseModel.getData().getRfqs().size()),Toast.LENGTH_LONG).show();
  
                          for(int i=0;i&lt;b;i++){
  
                              if(caseModel.getData().getRfqs().get(i).getIsSeen() == null){
                                  caseModel.getData().getRfqs().get(i).setIsSeen(false);
                              }
  
                              if(caseModel.getData().getRfqs().get(i).getIsSeen()){
                                  caseModel.getData().getRfqs().get(i).setIsSeen(false);
                              }
  
                              caseList.add(i,caseModel.getData().getRfqs().get(i));
  
                          }
  
  
  
  
  
                      }
  
                  }
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
              }
          });
      }
  
      private void lastUpdated() {
          Long tsLong = System.currentTimeMillis()/1000;
          String ts = tsLong.toString();
          System.out.print(ts);
  
          long unixSeconds = Long.valueOf(ts);
          Date date = new Date(unixSeconds*1000L); // *1000 is to convert seconds to milliseconds
          SimpleDateFormat sdf = new SimpleDateFormat("E hh:mma"); // the format of your date
          //get gmt
          Calendar mCalendar = new GregorianCalendar();
          TimeZone mTimeZone = mCalendar.getTimeZone();
          String formattedDate = sdf.format(date);
  
          String updated = String.format(getString(R.string.last_updated), formattedDate);
          textUpdatedTime.setText(updated);
          textUpdatedTime.setVisibility(View.VISIBLE);
          textUpdatedTime.setTextColor(Color.RED);
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ca = new ArrayList&lt;&gt;();
          loadFromCache();
  
          // view update observer
          ViewUpdateObserver.getInstance().addObserver(new Observer() {
              @Override
              public void update(Observable observable, Object data) {
                  loadFromCache();
              }
          });
  
  
  
  
  
  
      }
  
      private void loadCase() {
  
          RequestQueue rq = Volley.newRequestQueue(getActivity());
          String uri = String.format(UriManager.getDealerCase(),
                  GlobalConstant.NEW);
          final ProgressDialog loading = ProgressDialog.show(getContext(), "Refreshing...", "Please wait...", false, false);
          CustomAuthObjectRequest caseRequest = new CustomAuthObjectRequest(getContext(), StringRequest.Method.GET, uri, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  caseList.clear();
  
                  Gson gson = new Gson();
  
                  DealerCase caseModel = gson.fromJson(response, DealerCase.class);
  
                  if(caseModel.getData().getRfqs() != null){
  
                      int b = caseModel.getData().getRfqs().size();
                      ArrayList&lt;Rfq&gt; ca = new ArrayList&lt;&gt;();
  
                      for(int i=0;i&lt;b;i++){
  
  //                        if(caseList.get(i).getIsSeen()){
  //                            caseModel.getData().getRfqs().get(i).setIsSeen(true);
  //                        }else {
  //                            caseModel.getData().getRfqs().get(i).setIsSeen(false);
  //                        }
                          caseModel.getData().getRfqs().get(i).setIsSeen(false);
                          ca.add(i,caseModel.getData().getRfqs().get(i));
  //                        caseList.add(i,caseModel.getData().getRfqs().get(i));
  
                      }
  
  
                      caseAdapter.setData(ca);
                      caseAdapter.notifyDataSetChanged();
                      //Toast.makeText(getContext(), String.valueOf(b), Toast.LENGTH_SHORT).show();
  
                  }
  
  
                  loading.dismiss();
  
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  loading.dismiss();
                  errorHandling(error);
  
  
              }
          }){
              @Override
              protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                  Map&lt;String, String&gt; param = super.getParams();
                  param.put(GlobalConstant.TAB,GlobalConstant.NEW);
                  return  param;
              }
          };
  
          rq.add(caseRequest);
  
  
  
      }
  
      public void requestNewCase(){
  
          final ProgressDialog loading = ProgressDialog.show(getContext(), "Refreshing...", "Please wait...", false, false);
          String uri = String.format(UriManager.getDealerCase(),
                  GlobalConstant.NEW);
          ApiManager.getInstance().authUrlRequest(getActivity(), KeyConfig.CACHE_NEW, false, false, StringRequest.Method.GET, uri, new OnResponseListener() {
              @Override
              public void onResponse(String response, boolean fromCache) {
                  if(response != null &amp;&amp; !fromCache &amp;&amp; response.length() &gt; 0) {
  
                      Gson gson = new Gson();
  
                      DealerCase caseModel = gson.fromJson(response, DealerCase.class);
  
                      String newList = CacheManager.getInstance().getCache().get("test_cache");
  
                      if(caseModel.getData().getRfqs() != null) {
  
                          int b = caseModel.getData().getRfqs().size();
  
                          //Toast.makeText(getContext(), String.valueOf(ca.size())+" - " + String.valueOf(b),Toast.LENGTH_LONG).show();
                          for (int i = 0; i &lt; b; i++) {
                              for(int n=0 ; n&lt; caseList.size(); n++){
  
  
                                  if(caseList.get(n).getUid().equals(caseModel.getData().getRfqs().get(i).getUid())){
                                      caseModel.getData().getRfqs().get(i).setIsSeen(true);
                                      if(caseList.get(n).getIsSeen() == null){
                                          caseModel.getData().getRfqs().get(i).setIsSeen(false);
                                      }else {
                                          if(caseList.get(n).getIsSeen()){
                                              caseModel.getData().getRfqs().get(i).setIsSeen(true);
                                          }else
                                              caseModel.getData().getRfqs().get(i).setIsSeen(false);
  
                                      }
                                      //Toast.makeText(getContext(), String.valueOf(n)  +" __ " + String.valueOf(ca.get(n).getIsSeen())+" - " + String.valueOf(caseModel.getData().getRfqs().get(i).getIsSeen()),Toast.LENGTH_LONG).show();
                                  }
  
                              }
                              caseList.add(i,caseModel.getData().getRfqs().get(i));
                          }
  
  
  
                          caseAdapter.setData(caseList);
                          caseAdapter.notifyDataSetChanged();
  
                      }
  
                      CacheManager.getInstance().getCache().put(KeyConfig.CACHE_NEW, gson.toJson(caseModel));
                      Toast.makeText(getContext(),String.valueOf(caseModel.getData().getRfqs().get(0).getIsSeen()),Toast.LENGTH_LONG).show();
                      ViewUpdateObserver.getInstance().notifySubscribers();
                  }
                  loadFromCache();
                  loading.dismiss();
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  loading.dismiss();
              }
          });
      }
  
  
      @Override
      public void onClick(View v) {
  
      }
  
      @Override
      public void onResume() {
          super.onResume();
          requestNewCase();
  
  
      }
  }
  </code></pre>