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; package org.microg.tools.selfcheck;
import android.content.Context; import android.content.Context;
import android.support.v4.app.Fragment;
public interface SelfCheckGroup { public interface SelfCheckGroup {
String getGroupName(Context context); String getGroupName(Context context);
@ -25,6 +26,12 @@ public interface SelfCheckGroup {
interface ResultCollector { interface ResultCollector {
void addResult(String name, Result value, String resolution); 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 { enum Result {

View File

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

View File

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