diff --git a/app/src/main/java/com/ibnux/smsgateway/data/LogAdapter.java b/app/src/main/java/com/ibnux/smsgateway/data/LogAdapter.java index 4a1650e..5ab1e5e 100644 --- a/app/src/main/java/com/ibnux/smsgateway/data/LogAdapter.java +++ b/app/src/main/java/com/ibnux/smsgateway/data/LogAdapter.java @@ -14,12 +14,13 @@ public class LogAdapter extends RecyclerView.Adapter { private List datas; - long offset=0,limit=5; + long offset = 0, limit = 50; String search = ""; long smallTime = System.currentTimeMillis(), bigTime = 0; public static class MyViewHolder extends RecyclerView.ViewHolder { - TextView txtDate,txtMsg; + TextView txtDate, txtMsg; + public MyViewHolder(View v) { super(v); txtMsg = v.findViewById(R.id.txtMsg); @@ -27,57 +28,69 @@ public MyViewHolder(View v) { } } - public LogAdapter(){ - Fungsi.log("Data: "+ObjectBox.get().boxFor(LogLine.class).count()); + public LogAdapter() { + Fungsi.log("Data: " + ObjectBox.get().boxFor(LogLine.class).count()); } - public void reload(){ - if(search.length()>0) { - datas = ObjectBox.get().boxFor(LogLine.class).query().orderDesc(LogLine_.time).build().find(offset, limit); - }else{ + public void reload() { + smallTime = System.currentTimeMillis(); + bigTime = 0; + if (search.length() > 0) { + datas = ObjectBox.get().boxFor(LogLine.class).query().contains(LogLine_.message, search).orderDesc(LogLine_.time).build().find(offset, limit); + } else { datas = ObjectBox.get().boxFor(LogLine.class).query().orderDesc(LogLine_.time).build().find(offset, limit); } - for(int n=0;nbigTime){ + for (int n = 0; n < getItemCount(); n++) { + if (datas.get(n).time > bigTime) { bigTime = datas.get(n).time; } - if(smallTime>datas.get(n).time){ + if (smallTime > datas.get(n).time) { smallTime = datas.get(n).time; } } - Fungsi.log("reload "+datas.size()+" "+bigTime+" "+smallTime); + Fungsi.log("reload " + datas.size() + " " + bigTime + " " + smallTime); notifyDataSetChanged(); } - public void search(String search){ + public void search(String search) { this.search = search; reload(); } - public void getNewData(){ - List dts = ObjectBox.get().boxFor(LogLine.class).query().greater(LogLine_.time, bigTime).order(LogLine_.time).build().find(offset,limit); - for(int n=0;n dts; + if (search.length() > 0) { + dts = ObjectBox.get().boxFor(LogLine.class).query().contains(LogLine_.message, search).greater(LogLine_.time, bigTime).order(LogLine_.time).build().find(offset, limit); + } else { + dts = ObjectBox.get().boxFor(LogLine.class).query().greater(LogLine_.time, bigTime).order(LogLine_.time).build().find(offset, limit); + } + for (int n = 0; n < dts.size(); n++) { datas.add(0, dts.get(n)); - if(dts.get(n).time>bigTime){ + if (dts.get(n).time > bigTime) { bigTime = dts.get(n).time; } } - Fungsi.log("getNewData "+dts.size()+" "+bigTime); + Fungsi.log("getNewData " + dts.size() + " " + bigTime); notifyDataSetChanged(); - if(datas.size()>500){ + if (datas.size() > 500) { reload(); } } - public void nextData(){ - List dts = ObjectBox.get().boxFor(LogLine.class).query().less(LogLine_.time, smallTime).orderDesc(LogLine_.time).build().find(offset,limit); - for(int n=0;n dts; + if (search.length() > 0) { + dts = ObjectBox.get().boxFor(LogLine.class).query().contains(LogLine_.message, search).less(LogLine_.time, smallTime).orderDesc(LogLine_.time).build().find(offset, limit); + } else { + dts = ObjectBox.get().boxFor(LogLine.class).query().less(LogLine_.time, smallTime).orderDesc(LogLine_.time).build().find(offset, limit); + } + for (int n = 0; n < dts.size(); n++) { datas.add(dts.get(n)); - if(smallTime>dts.get(n).time){ + if (smallTime > dts.get(n).time) { smallTime = dts.get(n).time; } } - Fungsi.log("nextData "+dts.size()+" "+smallTime); + Fungsi.log("nextData " + dts.size() + " " + smallTime); notifyDataSetChanged(); } @@ -97,6 +110,6 @@ public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { @Override public int getItemCount() { - return (datas==null)?0:datas.size(); + return (datas == null) ? 0 : datas.size(); } }