Skip to content

Commit

Permalink
* [Issue #18] The date/time formatting is not consistent across all v…
Browse files Browse the repository at this point in the history
…iews.

Corrected the date/time format in the details view (e.g. 19:00 would get displayed as '7:00').
Changed the detail view to not show the host name field in case the host name is not known.
  • Loading branch information
amaa-99 committed Sep 22, 2023
1 parent 8ec08d6 commit 0df2b5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ protected Boolean doInBackground(Void... params) {
return false;
}
} catch (Exception e) {
Log.e(Api.TAG, "Exception while retrieving data" + e.getLocalizedMessage());
Log.e(Api.TAG, "Exception while retrieving data" + e.getLocalizedMessage());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import dev.ukanth.ufirewall.R;
Expand Down Expand Up @@ -47,32 +48,38 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(ViewHolder holder, int position) {
data = logData.get(position);
if (data != null) {
holder.bind(logData.get(position), recyclerItemClickListener);
if(data.getOut() != null) {
holder.deniedTime.setText(pretty(data.getTimestamp()) + "(" + data.getOut() + ")");
if((data.getOut().contains("lan") || data.getOut().startsWith("eth") || data.getOut().startsWith("ra") || data.getOut().startsWith("bnep"))) {
holder.bind(data, recyclerItemClickListener);
if (data.getOut() != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(data.getTimestamp());
java.text.DateFormat dateFormat = java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.SHORT, java.text.DateFormat.SHORT);
String dateTime = dateFormat.format(calendar.getTime());
holder.deniedTime.setText(dateTime + " (" + data.getOut() + ")");
if ((data.getOut().contains("lan") || data.getOut().startsWith("eth") || data.getOut().startsWith("ra") || data.getOut().startsWith("bnep"))) {
holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_wifi));
} else{
} else {
holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_mobiledata));
}
}

holder.dataDest.setText(context.getResources().getString(R.string.log_dst) + data.getDst() + ":" + data.getDpt());
holder.dataSrc.setText(context.getResources().getString(R.string.log_src) + data.getSrc() + ":" + data.getSpt());
holder.dataProto.setText(context.getResources().getString(R.string.log_proto) + data.getProto());
holder.dataHost.setText(context.getResources().getString(R.string.host) + data.getHostname());
}
}

public static String pretty(Long timestamp) {
return android.text.format.DateFormat.format("dd-MM-yyyy hh:mm:ss", new java.util.Date(timestamp)).toString();
String hostName = data.getHostname();
if (!hostName.isEmpty()) {
holder.dataHost.setText(context.getResources().getString(R.string.host) + hostName);
} else {
holder.dataHost.setVisibility(View.GONE);
}
}
}

@Override
public int getItemCount() {
return logData.size();
}


public static class ViewHolder extends RecyclerView.ViewHolder {

final ImageView icon;
Expand Down

0 comments on commit 0df2b5c

Please sign in to comment.