Fix layout on small screens / long titles, add ability to define resolver for self-check

This commit is contained in:
Marvin W 2016-01-26 23:32:17 +01:00
parent b2f08accd9
commit d7210d466a
3 changed files with 66 additions and 33 deletions

View File

@ -17,6 +17,7 @@
package org.microg.tools.selfcheck;
import android.content.Context;
import android.support.v4.app.Fragment;
public interface SelfCheckGroup {
String getGroupName(Context context);
@ -25,6 +26,12 @@ public interface SelfCheckGroup {
interface ResultCollector {
void addResult(String name, Result value, String resolution);
void addResult(String name, Result value, String resolution, CheckResolver resolver);
}
interface CheckResolver {
void tryResolve(Fragment fragment);
}
enum Result {

View File

@ -41,16 +41,24 @@ import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Unknown;
public abstract class AbstractSelfCheckFragment extends Fragment {
private static final String TAG = "SelfCheck";
protected abstract void prepareSelfCheckList(List<SelfCheckGroup> checks);
private ViewGroup root;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View scrollRoot = inflater.inflate(R.layout.self_check, container, false);
root = (ViewGroup) scrollRoot.findViewById(R.id.self_check_root);
reset(inflater);
return scrollRoot;
}
protected abstract void prepareSelfCheckList(List<SelfCheckGroup> checks);
protected void reset(LayoutInflater inflater) {
List<SelfCheckGroup> selfCheckGroupList = new ArrayList<SelfCheckGroup>();
prepareSelfCheckList(selfCheckGroupList);
ViewGroup root = (ViewGroup) scrollRoot.findViewById(R.id.self_check_root);
root.removeAllViews();
for (SelfCheckGroup group : selfCheckGroupList) {
View groupView = inflater.inflate(R.layout.self_check_group, root, false);
((TextView) groupView.findViewById(android.R.id.title)).setText(group.getGroupName(getContext()));
@ -64,7 +72,6 @@ public abstract class AbstractSelfCheckFragment extends Fragment {
}
root.addView(groupView);
}
return scrollRoot;
}
private class GroupResultCollector implements SelfCheckGroup.ResultCollector {
@ -76,6 +83,12 @@ public abstract class AbstractSelfCheckFragment extends Fragment {
@Override
public void addResult(final String name, final SelfCheckGroup.Result result, final String resolution) {
addResult(name, result, resolution, null);
}
@Override
public void addResult(final String name, final SelfCheckGroup.Result result, final String resolution,
final SelfCheckGroup.CheckResolver resolver) {
if (result == null || getActivity() == null) return;
getActivity().runOnUiThread(new Runnable() {
@Override
@ -96,11 +109,19 @@ public abstract class AbstractSelfCheckFragment extends Fragment {
if (result == Unknown) {
resultEntry.findViewById(R.id.self_check_result).setVisibility(INVISIBLE);
}
if (resolver != null) {
resultEntry.setClickable(true);
resultEntry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resolver.tryResolve(AbstractSelfCheckFragment.this);
}
});
}
}
viewGroup.addView(resultEntry);
}
});
}
}
}

View File

@ -15,39 +15,44 @@
~ limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingBottom="5dp"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
<TextView
android:paddingTop="5dp"
android:id="@+id/self_check_name"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItem"
android:textColor="?android:textColorPrimary"/>
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/self_check_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItem"
android:textColor="?android:textColorPrimary"/>
<TextView
android:id="@+id/self_check_resolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary"/>
</LinearLayout>
<CheckBox
android:id="@+id/self_check_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"/>
<TextView
android:id="@+id/self_check_resolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/self_check_name"
android:layout_below="@id/self_check_name"
android:layout_toLeftOf="@id/self_check_result"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary"/>
</RelativeLayout>
android:focusable="false"
android:gravity="right|center_vertical"
android:paddingTop="5dp"/>
</LinearLayout>