Skip to content

Commit

Permalink
Nicer looking, more consistent form/instance lists (#2825)
Browse files Browse the repository at this point in the history
* Rename form lists for consistency

* Format form lists consistently for better future diffs

View this diff with '-w' flag or 'w=1' URL param.

* Rename form list items for consistency

* Format form list items consistently for better future diffs

View this diff with '-w' flag or 'w=1' URL param.

* Give form lists Material Design 8dp vertical padding

* Remove form 'visibility' icon; disable row and show toast

* Set 38% opacity for disabled form items

The text color itself may also be changing in an upcoming commit per
Material guidelines.

* Tweak theme colors to conform to Material specs

* Use Material text and padding for form_chooser_list_item

* Factor out form_chooser_list_item_text into separate file

* Remove redundant text alignment properties

So list item text doesn't overlap the image

* Display form_state_blank icon by default

Other states will be handled soon.

* Use form_chooser_list_item_text for multiple choice items as well

* Factor out form_chooser_list_item_icon into separate file

* Also display form_state_blank icon on multiple_choice item

By default; new states coming soon.

* Use Material text and padding for multiple choice list items

* Use form_chooser_list_item_multiple_choice for google drive too

* Add convenience links to Material spec for future maintainers

* Also set opacity on disabled image view

* Set item icon based on form status for View Sent

* Use InstanceListCursorAdapter for both 'sent' and 'saved'

* Add inset list_item_divider to every form list

* Factor out form_chooser_list_item_checkbox into separate file

* Use form_chooser_list_item_text for Send Finalized

* Remove Send Finalized CardView wrapper

* Remove Send Finalized dimen abstractions for clarity

They'll be changing in upcoming commits, easier to see them here.

* Use form_chooser_list_item_icon for Send Finalized

* Use Material Design layout for Send Finalized

`instance_uploader_list_item` now mirrors `form_chooser_list_item_multiple_choice`,
just with a few extra components.

* Simplify form lists using LinearLayout

* Use generic form_chooser_list_item_multiple_choice for Send Finalized

* Use the new icons for Send Finalized

* Use the new icons for Delete Saved Instances

* Make TwoItemMultipleChoiceView a LinearLayout

Gets rid of one extra layer of nesting

* Use Material Design 'cancel' icon for sending SMS

* Use srcCompat for lower API compatibility

* Use light/dark themed list item divider colors

* Shrink the 'cancel' icon down to a proper size

* Remove now-unnecessary list_item_checkbox layout

* Make 'finalized' icon indigo to differentiate it

* Rename form_state_{,submission_}failed for clarity

* Factor out setEnabled/Disabled methods

* Make views 'final' to appease checkstyle

* Remove useless gravity specifications for text

It was only on some of them anyway.

* Swap text2, text3 so they're in the right order

Only 2 screens use text3, and both use VersionHidingCursorAdapter.
They're the only ones that use VHCA.

The only additional change needed is to make sure text3 is made visible
in VHCA because text2 always used to be visible and now they're swapped.

* Rename text1 => form_title

* Rename text2 => form_subtitle

* Remove redundant text4 view

* Rename text3 => form_subtitle2

* Rename update_info => form_update_alert

* Disable clipToPadding for all lists

So the MD 8dp padding doesn't cover the actual list items.

* Add MD palette to colors.xml

* Overlay scrollbar for all lists

So MD padding top/bottom doesn't push the scrollbar down.

* Clean up GoogleDriveActivity setChecked logic

Checkbox is already checked by FileArrayAdapter.

* Remove unused divider dimens

Tap target not used on ListViews, just Dialogs.

* Rename divider => dividerCompat for clarity

* Default to dividerCompat and upgrade on newer devices

Fixes crash in API < 21.
  • Loading branch information
cooperka authored and grzesiek2010 committed Feb 20, 2019
1 parent 1ee4a1f commit b41b817
Show file tree
Hide file tree
Showing 58 changed files with 917 additions and 950 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.odk.collect.android.activities;

import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
Expand Down Expand Up @@ -127,6 +128,12 @@ public void setContentView(@LayoutRes int layoutResID) {
progressBar = findViewById(R.id.progressBar);
llParent = findViewById(R.id.llParent);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Use the nicer-looking drawable with Material Design insets.
listView.setDivider(getResources().getDrawable(R.drawable.list_item_divider, getTheme()));
listView.setDividerHeight(1);
}

setSupportActionBar(findViewById(R.id.toolbar));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void initToolbar() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.file_manager_layout);
setContentView(R.layout.file_manager_tabs);
initToolbar();

String[] tabNames = {getString(R.string.data), getString(R.string.forms)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class FormChooserList extends FormListActivity implements
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chooser_list_layout);
setContentView(R.layout.form_chooser_list);

setTitle(getString(R.string.enter_data));

Expand Down Expand Up @@ -171,13 +171,13 @@ public void syncComplete(@NonNull String result) {

private void setupAdapter() {
String[] data = new String[]{
FormsColumns.DISPLAY_NAME, FormsColumns.DISPLAY_SUBTEXT, FormsColumns.JR_VERSION
FormsColumns.DISPLAY_NAME, FormsColumns.JR_VERSION, FormsColumns.DISPLAY_SUBTEXT
};
int[] view = new int[]{
R.id.text1, R.id.text2, R.id.text3
R.id.form_title, R.id.form_subtitle, R.id.form_subtitle2
};

listAdapter = new VersionHidingCursorAdapter(FormsColumns.JR_VERSION, this, R.layout.two_item, null, data, view);
listAdapter = new VersionHidingCursorAdapter(FormsColumns.JR_VERSION, this, R.layout.form_chooser_list_item, null, data, view);
listView.setAdapter(listAdapter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public class FormDownloadList extends FormListActivity implements FormListDownlo
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.remote_file_manage_list);
setContentView(R.layout.form_download_list);
getComponent().inject(this);
setTitle(getString(R.string.get_forms));

Expand Down Expand Up @@ -925,4 +925,4 @@ private void cleanUpWebCredentials() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void initToolbar() {
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.drive_layout);
setContentView(R.layout.google_drive_list);

setProgressBarVisibility(true);
initToolbar();
Expand Down Expand Up @@ -578,10 +578,10 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
} else {
// file clicked, download the file, mark checkbox.
CheckBox cb = view.findViewById(R.id.checkbox);
cb.setChecked(!cb.isChecked());
item.setSelected(cb.isChecked());
boolean isNowSelected = cb.isChecked();
item.setSelected(isNowSelected);

if (toDownload.contains(item) && !cb.isChecked()) {
if (!isNowSelected) {
toDownload.remove(item);
} else {
toDownload.add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import android.support.v4.content.Loader;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import android.widget.Toast;
import org.odk.collect.android.R;
import org.odk.collect.android.adapters.ViewSentListAdapter;
import org.odk.collect.android.adapters.InstanceListCursorAdapter;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.dao.InstancesDao;
import org.odk.collect.android.listeners.DiskSyncListener;
Expand Down Expand Up @@ -67,7 +67,7 @@ public class InstanceChooserList extends InstanceListActivity implements
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chooser_list_layout);
setContentView(R.layout.form_chooser_list);

String formMode = getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE);
if (formMode == null || ApplicationConstants.FormModes.EDIT_SAVED.equalsIgnoreCase(formMode)) {
Expand Down Expand Up @@ -130,7 +130,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
ContentUris.withAppendedId(InstanceColumns.CONTENT_URI,
c.getLong(c.getColumnIndex(InstanceColumns._ID)));

if (view.findViewById(R.id.visible_off).getVisibility() != View.VISIBLE) {
if (view.isEnabled()) {
String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action)) {
// caller is waiting on a picked form
Expand Down Expand Up @@ -162,6 +162,9 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
startActivity(intent);
}
finish();
} else {
TextView disabledCause = view.findViewById(R.id.form_subtitle2);
Toast.makeText(this, disabledCause.getText(), Toast.LENGTH_SHORT).show();
}
}
}
Expand Down Expand Up @@ -197,14 +200,12 @@ private void setupAdapter() {
InstanceColumns.DISPLAY_NAME, InstanceColumns.DISPLAY_SUBTEXT, InstanceColumns.DELETED_DATE
};
int[] view = new int[]{
R.id.text1, R.id.text2, R.id.text4
R.id.form_title, R.id.form_subtitle, R.id.form_subtitle2
};

if (editMode) {
listAdapter = new SimpleCursorAdapter(this, R.layout.two_item, null, data, view);
} else {
listAdapter = new ViewSentListAdapter(this, R.layout.two_item, null, data, view);
}
boolean shouldCheckDisabled = !editMode;
listAdapter = new InstanceListCursorAdapter(
this, R.layout.form_chooser_list_item, null, data, view, shouldCheckDisabled);
listView.setAdapter(listAdapter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ public class FileArrayAdapter extends ArrayAdapter<DriveListItem> {
private final List<DriveListItem> items;

public FileArrayAdapter(Context context, List<DriveListItem> filteredDriveList) {
super(context, R.layout.two_item_image, filteredDriveList);
super(context, R.layout.form_chooser_list_item_multiple_choice, filteredDriveList);
items = filteredDriveList;
}

private class ViewHolder {
ImageView imageView;
TextView text1;
TextView text2;
TextView formTitle;
TextView formSubtitle;
CheckBox checkBox;

ViewHolder(View view) {
imageView = view.findViewById(R.id.image);
text1 = view.findViewById(R.id.text1);
text2 = view.findViewById(R.id.text2);
formTitle = view.findViewById(R.id.form_title);
formSubtitle = view.findViewById(R.id.form_subtitle);
checkBox = view.findViewById(R.id.checkbox);
}

Expand All @@ -76,8 +76,8 @@ void onBind(DriveListItem item) {
checkBox.setVisibility(View.GONE);
}

text1.setText(item.getName());
text2.setText(dateModified);
formTitle.setText(item.getName());
formSubtitle.setText(dateModified);
checkBox.setChecked(item.isSelected());
}
}
Expand All @@ -87,7 +87,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
final ViewHolder holder;
View view;
if (convertView == null) {
view = LayoutInflater.from(getContext()).inflate(R.layout.two_item_image, parent, false);
view = LayoutInflater.from(getContext()).inflate(R.layout.form_chooser_list_item_multiple_choice, parent, false);
holder = new ViewHolder(view);
view.setTag(holder);
} else {
Expand All @@ -97,4 +97,4 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
holder.onBind(items.get(position));
return view;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FormDownloadListAdapter extends ArrayAdapter {

public FormDownloadListAdapter(Context context, ArrayList<HashMap<String, String>> filteredFormList,
HashMap<String, FormDetails> formIdsToDetails) {
super(context, R.layout.two_item_multiple_choice, filteredFormList);
super(context, R.layout.form_chooser_list_item_multiple_choice, filteredFormList);
this.filteredFormList = filteredFormList;
this.formIdsToDetails = formIdsToDetails;
}
Expand All @@ -51,9 +51,9 @@ public void setFromIdsToDetails(HashMap<String, FormDetails> formIdsToDetails) {
}

private static class ViewHolder {
TextView text1;
TextView text2;
TextView updateInfo;
TextView formTitle;
TextView formSubtitle;
TextView formUpdateAlert;
}

public View getView(int position, View convertView, @NonNull ViewGroup parent) {
Expand All @@ -62,11 +62,11 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
if (row == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.two_item_multiple_choice, parent, false);
row = inflater.inflate(R.layout.form_chooser_list_item_multiple_choice, parent, false);

holder.text1 = row.findViewById(R.id.text1);
holder.text2 = row.findViewById(R.id.text2);
holder.updateInfo = row.findViewById(R.id.update_info);
holder.formTitle = row.findViewById(R.id.form_title);
holder.formSubtitle = row.findViewById(R.id.form_subtitle);
holder.formUpdateAlert = row.findViewById(R.id.form_update_alert);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
Expand All @@ -75,17 +75,17 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
final HashMap<String, String> formAtPosition = filteredFormList.get(position);
final String formIDAtPosition = formAtPosition.get(FORM_ID_KEY);

holder.text1.setText(formAtPosition.get(FORMNAME));
holder.text2.setText(formAtPosition.get(FORMID_DISPLAY));
holder.formTitle.setText(formAtPosition.get(FORMNAME));
holder.formSubtitle.setText(formAtPosition.get(FORMID_DISPLAY));

if (formIdsToDetails.get(formIDAtPosition) != null
&& (formIdsToDetails.get(formIDAtPosition).isNewerFormVersionAvailable()
|| formIdsToDetails.get(formIDAtPosition).areNewerMediaFilesAvailable())) {
holder.updateInfo.setVisibility(View.VISIBLE);
holder.formUpdateAlert.setVisibility(View.VISIBLE);
} else {
holder.updateInfo.setVisibility(View.GONE);
holder.formUpdateAlert.setVisibility(View.GONE);
}

return row;
}
}
}
Loading

0 comments on commit b41b817

Please sign in to comment.