Skip to content

Commit

Permalink
Search Log
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnux committed Aug 31, 2021
1 parent c498e34 commit 57e591d
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions app/src/main/java/com/ibnux/smsgateway/data/LogAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,70 +14,83 @@

public class LogAdapter extends RecyclerView.Adapter<LogAdapter.MyViewHolder> {
private List<LogLine> 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);
txtDate = v.findViewById(R.id.txtDate);
}
}

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;n<getItemCount();n++){
if(datas.get(n).time>bigTime){
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<LogLine> 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++){
public void getNewData() {
List<LogLine> 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<LogLine> 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++){
public void nextData() {
List<LogLine> 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();
}

Expand All @@ -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();
}
}

0 comments on commit 57e591d

Please sign in to comment.