Skip to content

Commit

Permalink
Fixed Logview related bugs and added uid in logview
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanth committed Aug 1, 2016
1 parent e0888de commit 5556a57
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 35 deletions.
65 changes: 46 additions & 19 deletions aFWall/src/main/java/dev/ukanth/ufirewall/activity/LogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<LogData> getLogData() {
return SQLite.select()
.from(LogData.class)
//.orderBy(LogData_Table.timestamp, true)
.queryList();
}


private class CollectLog extends AsyncTask<Void, Void, List<LogData>> {
private Context context = null;
MaterialDialog loadDialog = null;
boolean hasRoot = false;

public CollectLog() {
}
//private boolean suAvailable = false;

public CollectLog setContext(Context context) {
Expand All @@ -113,16 +139,18 @@ protected void onPreExecute() {

@Override
protected List<LogData> doInBackground(Void... params) {
// Let's do some SU stuff
List<LogData> 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> 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
Expand All @@ -141,24 +169,23 @@ protected void onPostExecute(List<LogData> 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<LogData> updateMap(List<LogData> logDataList) {
HashMap<String, LogData> logMap = new HashMap<>();
HashMap<String, Integer> count = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.ocpsoft.prettytime.PrettyTime;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -30,9 +31,15 @@ public class LogRecyclerViewAdapter extends RecyclerView.Adapter<LogRecyclerVie
private PrettyTime prettyTime;
private int uid;

public LogRecyclerViewAdapter(final Context context,List<LogData> logData ){
public LogRecyclerViewAdapter(final Context context){
this.context = context;
this.logData = logData;
logData = new ArrayList<>();
}

public void updateData(List<LogData> logDataList) {
logData.clear();
logData.addAll(logDataList);
this.notifyDataSetChanged();
}

@Override
Expand Down Expand Up @@ -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)) ;
Expand Down
26 changes: 13 additions & 13 deletions aFWall/src/main/res/layout/log_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />

<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>

<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
Expand All @@ -34,4 +21,17 @@
android:text="@string/no_data_available"
android:visibility="gone" />

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>


</LinearLayout>

0 comments on commit 5556a57

Please sign in to comment.