diff --git a/aFWall/src/main/java/dev/ukanth/ufirewall/activity/LogActivity.java b/aFWall/src/main/java/dev/ukanth/ufirewall/activity/LogActivity.java index d7353f313..70e715971 100644 --- a/aFWall/src/main/java/dev/ukanth/ufirewall/activity/LogActivity.java +++ b/aFWall/src/main/java/dev/ukanth/ufirewall/activity/LogActivity.java @@ -44,11 +44,13 @@ import java.util.List; import java.util.Map; +import dev.ukanth.ufirewall.Api; import dev.ukanth.ufirewall.R; +import dev.ukanth.ufirewall.log.Log; import dev.ukanth.ufirewall.log.LogData; -import dev.ukanth.ufirewall.log.LogData_Table; import dev.ukanth.ufirewall.log.LogRecyclerViewAdapter; import dev.ukanth.ufirewall.util.DateComparator; +import dev.ukanth.ufirewall.util.G; public class LogActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { @@ -88,15 +90,39 @@ public void onClick(View v) { recyclerView = (RecyclerView) findViewById(R.id.recyclerview); emptyView = (TextView) findViewById(R.id.empty_view); - (new CollectLog()).setContext(this).execute(); + initializeRecyclerView(); + + if(G.enableLogService()) { + (new CollectLog()).setContext(this).execute(); + } else { + recyclerView.setVisibility(View.GONE); + mSwipeLayout.setVisibility(View.GONE); + emptyView.setVisibility(View.VISIBLE); + } + } + + private void initializeRecyclerView() { + recyclerView.hasFixedSize(); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + recyclerViewAdapter = new LogRecyclerViewAdapter(getApplicationContext()); + recyclerView.setAdapter(recyclerViewAdapter); + } + + private List getLogData() { + return SQLite.select() + .from(LogData.class) + //.orderBy(LogData_Table.timestamp, true) + .queryList(); } private class CollectLog extends AsyncTask> { private Context context = null; MaterialDialog loadDialog = null; - boolean hasRoot = false; + + public CollectLog() { + } //private boolean suAvailable = false; public CollectLog setContext(Context context) { @@ -113,16 +139,18 @@ protected void onPreExecute() { @Override protected List doInBackground(Void... params) { - // Let's do some SU stuff - List logData = SQLite.select() - .from(LogData.class) - .orderBy(LogData_Table.timestamp, true) - .queryList(); - if(logData != null && logData.size() > 0) { - logData = updateMap(logData); - Collections.sort(logData, new DateComparator()); + List logData = getLogData(); + try { + if(logData != null && logData.size() > 0) { + logData = updateMap(logData); + Collections.sort(logData, new DateComparator()); + } + return logData; + } catch(Exception e) { + Log.e(Api.TAG,"Exception while retrieving data" + e.getLocalizedMessage()); + return null; } - return logData; + } @Override @@ -141,24 +169,23 @@ protected void onPostExecute(List logData) { } mSwipeLayout.setRefreshing(false); + if (logData == null || logData.isEmpty()) { + mSwipeLayout.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); } else { + recyclerViewAdapter.updateData(logData); recyclerView.setVisibility(View.VISIBLE); + mSwipeLayout.setVisibility(View.VISIBLE); emptyView.setVisibility(View.GONE); } - - recyclerViewAdapter = new LogRecyclerViewAdapter(context, logData); - recyclerView.hasFixedSize(); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(recyclerViewAdapter); - - } } + + private List updateMap(List logDataList) { HashMap logMap = new HashMap<>(); HashMap count = new HashMap<>(); diff --git a/aFWall/src/main/java/dev/ukanth/ufirewall/log/LogRecyclerViewAdapter.java b/aFWall/src/main/java/dev/ukanth/ufirewall/log/LogRecyclerViewAdapter.java index d7d099fac..25df5d726 100644 --- a/aFWall/src/main/java/dev/ukanth/ufirewall/log/LogRecyclerViewAdapter.java +++ b/aFWall/src/main/java/dev/ukanth/ufirewall/log/LogRecyclerViewAdapter.java @@ -12,6 +12,7 @@ import org.ocpsoft.prettytime.PrettyTime; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -30,9 +31,15 @@ public class LogRecyclerViewAdapter extends RecyclerView.Adapter logData ){ + public LogRecyclerViewAdapter(final Context context){ this.context = context; - this.logData = logData; + logData = new ArrayList<>(); + } + + public void updateData(List logDataList) { + logData.clear(); + logData.addAll(logDataList); + this.notifyDataSetChanged(); } @Override @@ -65,7 +72,7 @@ public void onBindViewHolder(ViewHolder holder, int position) { } } catch (Exception e) { } - holder.appname.setText(data.getAppName() != null ? data.getAppName(): context.getString(R.string.log_deletedapp)); + holder.appname.setText(data.getAppName() != null ? data.getAppName() + "(" + data.getUid() + ")" : context.getString(R.string.log_deletedapp)); if(data.getCount() > 1) { holder.dataDenied.setText(context.getString(R.string.log_denied) + " " + data.getCount() + " " + context.getString(R.string.log_times)) ; diff --git a/aFWall/src/main/res/layout/log_view.xml b/aFWall/src/main/res/layout/log_view.xml index f8f3151a5..19269a62f 100644 --- a/aFWall/src/main/res/layout/log_view.xml +++ b/aFWall/src/main/res/layout/log_view.xml @@ -13,19 +13,6 @@ android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" /> - - - - - + + + + + + \ No newline at end of file