Skip to content

Commit

Permalink
overlay logger can filter by log priority now (minimum log level filter)
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Mar 1, 2017
1 parent f035098 commit d8f5ed4
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class OverlayLoggingSetup
private int mTextSizeInDp = 12;
private int mOverlayHeightInDp = 150;
private boolean mStartExpanded = true;
private int mLogPriorityForErrorFilter = Log.ERROR;
private boolean mStartWithShowErrorsOnly = false;
private int mDefaultMinVisibleLogPriority = Log.VERBOSE;

private int mPermissionRequestCode = 200;
private String mNotificationTitle = "Overlay logger";
Expand Down Expand Up @@ -165,26 +164,14 @@ public OverlayLoggingSetup withStartExpanded(boolean startExpanded)
}

/**
* only show logs of the defined level or higher in overlay logger if error filter is on
* DEFAULT: Log.ERRROR
* default value for miimimum visible log priority, by default all logs are visible
* DEFAULT: Log.VERBOSE
*
* @param logPriority define the minimum log level that is visible in the overlay logger if error filter is on
* @param logPriority define the minimum log level that is visible in the overlay logger
*/
public OverlayLoggingSetup withMinimumLogPriority(int logPriority)
public OverlayLoggingSetup withDefaultMinimumVisibleLogPriority(int logPriority)
{
mLogPriorityForErrorFilter = logPriority;
return this;
}

/**
* start the overlay logger with active error filter
* DEFAULT: false
*
* @param startWithShowErrorsOnly true to start the overlay logger with active error filter
*/
public OverlayLoggingSetup withStartWithShowErrorsOnly(boolean startWithShowErrorsOnly)
{
mStartWithShowErrorsOnly = startWithShowErrorsOnly;
mDefaultMinVisibleLogPriority = logPriority;
return this;
}

Expand Down Expand Up @@ -247,14 +234,9 @@ public boolean getWithStartExpanded()
return mStartExpanded;
}

public int getLogPriorityForErrorFilter()
{
return mLogPriorityForErrorFilter;
}

public boolean getStartWithShowErrorsOnly()
public int getDefaultMinVisibleLogPriority()
{
return mStartWithShowErrorsOnly;
return mDefaultMinVisibleLogPriority;
}

public String getNotificationTitle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,46 @@

public class LogAdapter extends RecyclerView.Adapter<LogAdapter.ViewHolder>
{
private boolean mIsFiltered;
private int mMinimumVisiblePriority;

private int mFilterLogLevel;
private List<OverlayLoggingTree.LogEntry> mItems;
private List<OverlayLoggingTree.LogEntry> mFilteredItems;

public LogAdapter(int filterLogLevel, boolean isFiltered)
public LogAdapter(int mimimumVisiblePriority)
{
mFilterLogLevel = filterLogLevel;
mIsFiltered = isFiltered;
mMinimumVisiblePriority = mimimumVisiblePriority;
mItems = new ArrayList<>();
mFilteredItems = new ArrayList<>();
}

public void setFiltered(boolean isFiltered)
public void setFiltered(int mimimumVisiblePriority)
{
if (mIsFiltered != isFiltered)
if (mMinimumVisiblePriority != mimimumVisiblePriority)
{
mIsFiltered = isFiltered;
mMinimumVisiblePriority = mimimumVisiblePriority;
calcFilteredItems();
notifyDataSetChanged();
}
}

private void calcFilteredItems()
{
mFilteredItems.clear();
for (OverlayLoggingTree.LogEntry item : mItems)
{
if (item.getPriority() >= mMinimumVisiblePriority)
mFilteredItems.add(item);
}
}

public boolean add(OverlayLoggingTree.LogEntry item)
{
mItems.add(item);
if (item.getPriority() >= mFilterLogLevel)
if (item.getPriority() >= mMinimumVisiblePriority)
{
mFilteredItems.add(item);
if (mIsFiltered && item.getPriority() >= mFilterLogLevel)
notifyItemInserted(mFilteredItems.size() - 1);
else if (!mIsFiltered)
notifyItemInserted(mItems.size() - 1);
}
else
return false;
return true;
Expand All @@ -67,7 +75,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
@Override
public void onBindViewHolder(ViewHolder holder, int position)
{
OverlayLoggingTree.LogEntry item = mIsFiltered ? mFilteredItems.get(position) : mItems.get(position);
OverlayLoggingTree.LogEntry item = mFilteredItems.get(position);
holder.text.setText(item.getMessage());
holder.text.setTextColor(item.getColor());
holder.text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, item.getTextSizeInDp());
Expand All @@ -76,7 +84,7 @@ public void onBindViewHolder(ViewHolder holder, int position)
@Override
public int getItemCount()
{
return mIsFiltered ? mFilteredItems.size() : mItems.size();
return mFilteredItems.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public void run() {
};
private boolean mPaused = false;

private boolean mErrorFilterActive;
private int mMinimumVisibleLogPriority;

public void setSetup(OverlayLoggingSetup setup)
{
mSetup = setup;
mErrorFilterActive = mSetup.getStartWithShowErrorsOnly();
mMinimumVisibleLogPriority = mSetup.getDefaultMinVisibleLogPriority();
}

@Override
Expand Down Expand Up @@ -120,23 +120,21 @@ private void createView()
if (mView != null)
return;

mView = new OverlayView(getApplicationContext(), mSetup, mErrorFilterActive);
mView.getCloseButton().setOnClickListener(new View.OnClickListener()
mView = new OverlayView(getApplicationContext(), mSetup, mMinimumVisibleLogPriority, new OverlayView.IFilterChangedListener()
{
@Override
public void onClick(View v)
public void onFilterChanged(int priority)
{
destroyView();
stopSelf();
mMinimumVisibleLogPriority = priority;
}
});
mView.getErrorButton().setOnClickListener(new View.OnClickListener()
mView.getCloseButton().setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
mErrorFilterActive = !mErrorFilterActive;
mView.updateErrorFilter(mErrorFilterActive);
destroyView();
stopSelf();
}
});
mView.getPauseButton().setOnClickListener(new View.OnClickListener()
Expand Down
Loading

0 comments on commit d8f5ed4

Please sign in to comment.