add support for hierarchical log entries

This commit is contained in:
Vincent Breitmoser 2014-10-05 10:09:50 +02:00
parent 0b9308753d
commit 7fedde2638
3 changed files with 103 additions and 10 deletions

View File

@ -106,7 +106,7 @@ public abstract class OperationResult implements Parcelable {
mType = type;
mParameters = parameters;
mIndent = indent;
Log.v(Constants.TAG, "log: " + this.toString());
Log.v(Constants.TAG, "log: " + this);
}
public LogEntryParcel(Parcel source) {
@ -122,6 +122,7 @@ public abstract class OperationResult implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(0);
dest.writeInt(mType.ordinal());
dest.writeSerializable(mParameters);
dest.writeInt(mIndent);
@ -129,7 +130,12 @@ public abstract class OperationResult implements Parcelable {
public static final Creator<LogEntryParcel> CREATOR = new Creator<LogEntryParcel>() {
public LogEntryParcel createFromParcel(final Parcel source) {
return new LogEntryParcel(source);
// Actually create LogEntryParcel or SubLogEntryParcel depending on type indicator
if (source.readInt() == 0) {
return new LogEntryParcel(source);
} else {
return new SubLogEntryParcel(source);
}
}
public LogEntryParcel[] newArray(final int size) {
@ -139,7 +145,7 @@ public abstract class OperationResult implements Parcelable {
@Override
public String toString() {
return "LogEntryParcel{" +
return getClass().getSimpleName() + "{" +
"mLevel=" + mType.mLevel +
", mType=" + mType +
", mParameters=" + Arrays.toString(mParameters) +
@ -148,6 +154,42 @@ public abstract class OperationResult implements Parcelable {
}
}
public static class SubLogEntryParcel extends LogEntryParcel {
OperationResult mSubResult;
public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) {
super(type, indent, parameters);
mSubResult = subResult;
Log.v(Constants.TAG, "log: " + this);
}
public SubLogEntryParcel(Parcel source) {
super(source);
mSubResult = source.readParcelable(SubLogEntryParcel.class.getClassLoader());
}
public OperationResult getSubResult() {
return mSubResult;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(1);
dest.writeInt(mType.ordinal());
dest.writeSerializable(mParameters);
dest.writeInt(mIndent);
dest.writeParcelable(mSubResult, 0);
}
}
public SuperCardToast createNotify(final Activity activity) {
int color;
@ -597,6 +639,15 @@ public abstract class OperationResult implements Parcelable {
mParcels.add(new OperationResult.LogEntryParcel(type, indent, (Object[]) null));
}
public void add(OperationResult subResult, int indent) {
OperationLog subLog = subResult.getLog();
mParcels.add(new SubLogEntryParcel(subResult, subLog.getLast().mType, indent, subLog.getLast().mParameters));
}
public void clear() {
mParcels.clear();
}
public boolean containsType(LogType type) {
for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(mParcels.iterator())) {
if (entry.mType == type) {

View File

@ -31,6 +31,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
@ -40,11 +42,12 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.service.results.OperationResult;
import org.sufficientlysecure.keychain.service.results.OperationResult.LogEntryParcel;
import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel;
import org.sufficientlysecure.keychain.service.results.OperationResult.SubLogEntryParcel;
import org.sufficientlysecure.keychain.util.Log;
import java.util.HashMap;
public class LogDisplayFragment extends ListFragment implements OnTouchListener {
public class LogDisplayFragment extends ListFragment implements OnTouchListener, OnItemClickListener {
HashMap<LogLevel,LogAdapter> mAdapters = new HashMap<LogLevel, LogAdapter>();
LogAdapter mAdapter;
@ -89,6 +92,8 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener
}
});
getListView().setOnItemClickListener(this);
getListView().setFastScrollEnabled(true);
getListView().setDividerHeight(0);
getListView().setOnTouchListener(this);
@ -126,6 +131,18 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LogEntryParcel parcel = mAdapter.getItem(position);
if ( ! (parcel instanceof SubLogEntryParcel)) {
return;
}
Intent intent = new Intent(
getActivity(), LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ((SubLogEntryParcel) parcel).getSubResult());
startActivity(intent);
}
private class LogAdapter extends ArrayAdapter<LogEntryParcel> {
private LayoutInflater mInflater;
@ -147,10 +164,11 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener
private class ItemHolder {
final TextView mText;
final ImageView mImg;
public ItemHolder(TextView text, ImageView image) {
final ImageView mImg, mSub;
public ItemHolder(TextView text, ImageView image, ImageView sub) {
mText = text;
mImg = image;
mSub = sub;
}
}
@ -162,13 +180,22 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener
convertView = mInflater.inflate(R.layout.log_display_item, parent, false);
ih = new ItemHolder(
(TextView) convertView.findViewById(R.id.log_text),
(ImageView) convertView.findViewById(R.id.log_img)
(ImageView) convertView.findViewById(R.id.log_img),
(ImageView) convertView.findViewById(R.id.log_sub)
);
convertView.setTag(ih);
} else {
ih = (ItemHolder) convertView.getTag();
}
if (entry instanceof SubLogEntryParcel) {
ih.mSub.setVisibility(View.VISIBLE);
convertView.setClickable(false);
} else {
ih.mSub.setVisibility(View.GONE);
convertView.setClickable(true);
}
// special case: first parameter may be a quantity
if (entry.mParameters != null && entry.mParameters.length > 0
&& entry.mParameters[0] instanceof Integer) {

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
@ -12,11 +12,26 @@
android:background="@color/bg_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Log Entry Text"
android:id="@+id/log_text"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp" />
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/log_sub"
android:minWidth="10dp"
android:background="@drawable/ic_action_view_as_list"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical" />
</LinearLayout>