Change landscape layout
This commit is contained in:
parent
2aa354dab2
commit
8b523ea9c2
3 changed files with 208 additions and 108 deletions
|
@ -7,9 +7,12 @@
|
||||||
android:descendantFocusability="blocksDescendants"
|
android:descendantFocusability="blocksDescendants"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include layout="@layout/list_item_divider"/>
|
<include
|
||||||
|
android:id="@+id/top_divider"
|
||||||
|
layout="@layout/list_item_divider"/>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/background_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/bg_color">
|
android:background="?attr/bg_color">
|
||||||
|
|
|
@ -117,11 +117,12 @@ public class NotesFragment extends OsmAndListFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||||
List<Object> items = createItemsList();
|
List<Object> items = createItemsList();
|
||||||
ListView listView = getListView();
|
ListView listView = getListView();
|
||||||
listView.setDivider(null);
|
listView.setDivider(null);
|
||||||
listView.setEmptyView(emptyView);
|
listView.setEmptyView(emptyView);
|
||||||
if (items.size() > 0 && footerView == null) {
|
if (items.size() > 0 && footerView == null && portrait) {
|
||||||
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false);
|
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false);
|
||||||
listView.addFooterView(footerView);
|
listView.addFooterView(footerView);
|
||||||
listView.setHeaderDividersEnabled(false);
|
listView.setHeaderDividersEnabled(false);
|
||||||
|
@ -131,6 +132,7 @@ public class NotesFragment extends OsmAndListFragment {
|
||||||
listAdapter.setSelectionMode(selectionMode);
|
listAdapter.setSelectionMode(selectionMode);
|
||||||
listAdapter.setSelected(selected);
|
listAdapter.setSelected(selected);
|
||||||
listAdapter.setListener(createAdapterListener());
|
listAdapter.setListener(createAdapterListener());
|
||||||
|
listAdapter.setPortrait(portrait);
|
||||||
listView.setAdapter(listAdapter);
|
listView.setAdapter(listAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +296,7 @@ public class NotesFragment extends OsmAndListFragment {
|
||||||
|
|
||||||
private void selectAll(int type) {
|
private void selectAll(int type) {
|
||||||
if (type == NotesAdapter.TYPE_DATE_HEADER) {
|
if (type == NotesAdapter.TYPE_DATE_HEADER) {
|
||||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
for (int i = 0; i < listAdapter.getItemsCount(); i++) {
|
||||||
Object item = listAdapter.getItem(i);
|
Object item = listAdapter.getItem(i);
|
||||||
if (item instanceof Recording) {
|
if (item instanceof Recording) {
|
||||||
selected.add((Recording) item);
|
selected.add((Recording) item);
|
||||||
|
|
|
@ -2,13 +2,16 @@ package net.osmand.plus.audionotes.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -30,10 +33,13 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private NotesAdapterListener listener;
|
private NotesAdapterListener listener;
|
||||||
|
private List<Object> items;
|
||||||
|
|
||||||
private boolean selectionMode;
|
private boolean selectionMode;
|
||||||
private Set<Recording> selected;
|
private Set<Recording> selected;
|
||||||
|
|
||||||
|
private boolean portrait;
|
||||||
|
|
||||||
public void setListener(NotesAdapterListener listener) {
|
public void setListener(NotesAdapterListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
@ -46,127 +52,88 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPortrait(boolean portrait) {
|
||||||
|
this.portrait = portrait;
|
||||||
|
}
|
||||||
|
|
||||||
public NotesAdapter(OsmandApplication app, List<Object> items) {
|
public NotesAdapter(OsmandApplication app, List<Object> items) {
|
||||||
super(app, R.layout.note, items);
|
super(app, R.layout.note, items);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View row, @NonNull ViewGroup parent) {
|
public View getView(final int position, View row, @NonNull ViewGroup parent) {
|
||||||
final int type = getItemViewType(position);
|
if (portrait) {
|
||||||
boolean header = type == TYPE_DATE_HEADER
|
final int type = getItemViewType(position);
|
||||||
|| type == TYPE_AUDIO_HEADER
|
boolean header = type == TYPE_DATE_HEADER
|
||||||
|| type == TYPE_PHOTO_HEADER
|
|| type == TYPE_AUDIO_HEADER
|
||||||
|| type == TYPE_VIDEO_HEADER;
|
|| type == TYPE_PHOTO_HEADER
|
||||||
|
|| type == TYPE_VIDEO_HEADER;
|
||||||
|
|
||||||
|
if (row == null) {
|
||||||
|
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
if (header) {
|
||||||
|
row = inflater.inflate(R.layout.list_item_header, parent, false);
|
||||||
|
HeaderViewHolder hHolder = new HeaderViewHolder(row);
|
||||||
|
row.setTag(hHolder);
|
||||||
|
} else {
|
||||||
|
row = inflater.inflate(R.layout.note_list_item, parent, false);
|
||||||
|
ItemViewHolder iHolder = new ItemViewHolder(row);
|
||||||
|
row.setTag(iHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (row == null) {
|
|
||||||
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
if (header) {
|
if (header) {
|
||||||
row = inflater.inflate(R.layout.list_item_header, parent, false);
|
setupHeader(type, (HeaderViewHolder) row.getTag());
|
||||||
HeaderViewHolder hHolder = new HeaderViewHolder(row);
|
|
||||||
row.setTag(hHolder);
|
|
||||||
} else {
|
} else {
|
||||||
row = inflater.inflate(R.layout.note_list_item, parent, false);
|
final Object item = getItem(position);
|
||||||
ItemViewHolder iHolder = new ItemViewHolder(row);
|
if (item instanceof Recording) {
|
||||||
row.setTag(iHolder);
|
setupItem(position, (Recording) item, (ItemViewHolder) row.getTag());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (header) {
|
return row;
|
||||||
final HeaderViewHolder holder = (HeaderViewHolder) row.getTag();
|
|
||||||
holder.checkBox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
|
|
||||||
holder.headerRow.setEnabled(selectionMode);
|
|
||||||
if (selectionMode) {
|
|
||||||
holder.checkBox.setChecked(isSelectAllChecked(type));
|
|
||||||
holder.checkBox.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onHeaderClick(type, holder.checkBox.isChecked());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
holder.headerRow.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
holder.checkBox.performClick();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
holder.view.setOnClickListener(null);
|
|
||||||
}
|
|
||||||
int titleId;
|
|
||||||
if (type == TYPE_DATE_HEADER) {
|
|
||||||
titleId = R.string.notes_by_date;
|
|
||||||
} else if (type == TYPE_AUDIO_HEADER) {
|
|
||||||
titleId = R.string.shared_string_audio;
|
|
||||||
} else if (type == TYPE_PHOTO_HEADER) {
|
|
||||||
titleId = R.string.shared_string_photo;
|
|
||||||
} else {
|
|
||||||
titleId = R.string.shared_string_video;
|
|
||||||
}
|
|
||||||
holder.title.setText(titleId);
|
|
||||||
} else {
|
} else {
|
||||||
final Object item = getItem(position);
|
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
if (item instanceof Recording) {
|
boolean lastCard = getHeadersCount() == position + 1;
|
||||||
final Recording recording = (Recording) item;
|
int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
final ItemViewHolder holder = (ItemViewHolder) row.getTag();
|
int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10;
|
||||||
|
|
||||||
if (recording == NotesFragment.SHARE_LOCATION_FILE) {
|
FrameLayout fl = new FrameLayout(getContext());
|
||||||
holder.title.setText(R.string.av_locations);
|
LinearLayout ll = new LinearLayout(getContext());
|
||||||
holder.description.setText(R.string.av_locations_descr);
|
fl.addView(ll);
|
||||||
|
ll.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
ll.setBackgroundResource(app.getSettings().isLightContent() ? R.drawable.bg_card_light : R.drawable.bg_card_dark);
|
||||||
|
((FrameLayout.LayoutParams) ll.getLayoutParams()).setMargins(sideMargin, margin, sideMargin, lastCard ? margin : 0);
|
||||||
|
|
||||||
|
int headerInd = getHeaderIndex(position);
|
||||||
|
HeaderViewHolder headerVH = new HeaderViewHolder(inflater.inflate(R.layout.list_item_header, parent, false));
|
||||||
|
setupHeader((int) items.get(headerInd), headerVH);
|
||||||
|
ll.addView(headerVH.view);
|
||||||
|
|
||||||
|
for (int i = headerInd + 1; i < items.size(); i++) {
|
||||||
|
Object item = items.get(i);
|
||||||
|
if (item instanceof Recording) {
|
||||||
|
ItemViewHolder itemVH = new ItemViewHolder(inflater.inflate(R.layout.note_list_item, parent, false));
|
||||||
|
setupItem(i, (Recording) item, itemVH);
|
||||||
|
ll.addView(itemVH.view);
|
||||||
} else {
|
} else {
|
||||||
holder.title.setText(recording.getName(app, true));
|
break;
|
||||||
holder.description.setText(recording.getNewSmallDescription(app));
|
|
||||||
int iconRes = recording.isAudio() ? R.drawable.ic_type_audio
|
|
||||||
: (recording.isVideo() ? R.drawable.ic_type_video : R.drawable.ic_type_img);
|
|
||||||
int colorRes = app.getSettings().isLightContent() ? R.color.icon_color : R.color.ctx_menu_info_text_dark;
|
|
||||||
holder.icon.setImageDrawable(app.getIconsCache().getIcon(iconRes, colorRes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.bottomDivider.setVisibility(hideBottomDivider(position) ? View.GONE : View.VISIBLE);
|
|
||||||
holder.icon.setVisibility(selectionMode ? View.GONE : View.VISIBLE);
|
|
||||||
holder.checkBox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
|
|
||||||
holder.options.setVisibility(selectionMode ? View.GONE : View.VISIBLE);
|
|
||||||
if (selectionMode) {
|
|
||||||
holder.checkBox.setChecked(selected.contains(recording));
|
|
||||||
holder.checkBox.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onCheckBoxClick(recording, holder.checkBox.isChecked());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
holder.options.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
|
||||||
holder.options.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onOptionsClick(recording);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.view.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (selectionMode) {
|
|
||||||
holder.checkBox.performClick();
|
|
||||||
} else {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onItemClick(recording);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return row;
|
return fl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
if (portrait) {
|
||||||
|
return super.getCount();
|
||||||
|
}
|
||||||
|
return getHeadersCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,13 +150,137 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
||||||
return TYPE_COUNT;
|
return TYPE_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupHeader(final int type, final HeaderViewHolder holder) {
|
||||||
|
setupBackground(holder.backgroundView);
|
||||||
|
holder.topDivider.setVisibility(portrait ? View.VISIBLE : View.GONE);
|
||||||
|
holder.checkBox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
|
||||||
|
holder.headerRow.setEnabled(selectionMode);
|
||||||
|
if (selectionMode) {
|
||||||
|
holder.checkBox.setChecked(isSelectAllChecked(type));
|
||||||
|
holder.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onHeaderClick(type, holder.checkBox.isChecked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
holder.headerRow.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
holder.checkBox.performClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
holder.view.setOnClickListener(null);
|
||||||
|
}
|
||||||
|
holder.title.setText(getHeaderTitleRes(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getHeaderTitleRes(int type) {
|
||||||
|
if (type == TYPE_DATE_HEADER) {
|
||||||
|
return R.string.notes_by_date;
|
||||||
|
} else if (type == TYPE_AUDIO_HEADER) {
|
||||||
|
return R.string.shared_string_audio;
|
||||||
|
} else if (type == TYPE_PHOTO_HEADER) {
|
||||||
|
return R.string.shared_string_photo;
|
||||||
|
}
|
||||||
|
return R.string.shared_string_video;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupItem(int position, final Recording recording, final ItemViewHolder holder) {
|
||||||
|
setupBackground(holder.view);
|
||||||
|
if (recording == NotesFragment.SHARE_LOCATION_FILE) {
|
||||||
|
holder.title.setText(R.string.av_locations);
|
||||||
|
holder.description.setText(R.string.av_locations_descr);
|
||||||
|
} else {
|
||||||
|
holder.title.setText(recording.getName(app, true));
|
||||||
|
holder.description.setText(recording.getNewSmallDescription(app));
|
||||||
|
int iconRes = recording.isAudio() ? R.drawable.ic_type_audio
|
||||||
|
: (recording.isVideo() ? R.drawable.ic_type_video : R.drawable.ic_type_img);
|
||||||
|
int colorRes = app.getSettings().isLightContent() ? R.color.icon_color : R.color.ctx_menu_info_text_dark;
|
||||||
|
holder.icon.setImageDrawable(app.getIconsCache().getIcon(iconRes, colorRes));
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.bottomDivider.setVisibility(hideBottomDivider(position) ? View.GONE : View.VISIBLE);
|
||||||
|
holder.icon.setVisibility(selectionMode ? View.GONE : View.VISIBLE);
|
||||||
|
holder.checkBox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
|
||||||
|
holder.options.setVisibility(selectionMode ? View.GONE : View.VISIBLE);
|
||||||
|
if (selectionMode) {
|
||||||
|
holder.checkBox.setChecked(selected.contains(recording));
|
||||||
|
holder.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onCheckBoxClick(recording, holder.checkBox.isChecked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
holder.options.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||||
|
holder.options.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onOptionsClick(recording);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.view.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (selectionMode) {
|
||||||
|
holder.checkBox.performClick();
|
||||||
|
} else {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onItemClick(recording);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupBackground(View view) {
|
||||||
|
if (!portrait) {
|
||||||
|
view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.color_transparent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getItemsCount() {
|
||||||
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getHeadersCount() {
|
||||||
|
int res = 0;
|
||||||
|
for (Object item : items) {
|
||||||
|
if (item instanceof Integer) {
|
||||||
|
res++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getHeaderIndex(int position) {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
if (items.get(i) instanceof Integer) {
|
||||||
|
if (count == position) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hideBottomDivider(int pos) {
|
private boolean hideBottomDivider(int pos) {
|
||||||
return pos == getCount() - 1 || !(getItem(pos + 1) instanceof Recording);
|
return pos == items.size() - 1 || !(getItem(pos + 1) instanceof Recording);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSelectAllChecked(int type) {
|
private boolean isSelectAllChecked(int type) {
|
||||||
for (int i = 0; i < getCount(); i++) {
|
for (Object item : items) {
|
||||||
Object item = getItem(i);
|
|
||||||
if (item instanceof Recording) {
|
if (item instanceof Recording) {
|
||||||
if (type != TYPE_DATE_HEADER && !isAppropriate((Recording) item, type)) {
|
if (type != TYPE_DATE_HEADER && !isAppropriate((Recording) item, type)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -214,12 +305,16 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
||||||
private class HeaderViewHolder {
|
private class HeaderViewHolder {
|
||||||
|
|
||||||
final View view;
|
final View view;
|
||||||
|
final View topDivider;
|
||||||
|
final View backgroundView;
|
||||||
final View headerRow;
|
final View headerRow;
|
||||||
final CheckBox checkBox;
|
final CheckBox checkBox;
|
||||||
final TextView title;
|
final TextView title;
|
||||||
|
|
||||||
HeaderViewHolder(View view) {
|
HeaderViewHolder(View view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
topDivider = view.findViewById(R.id.top_divider);
|
||||||
|
backgroundView = view.findViewById(R.id.background_view);
|
||||||
headerRow = view.findViewById(R.id.header_row);
|
headerRow = view.findViewById(R.id.header_row);
|
||||||
checkBox = (CheckBox) view.findViewById(R.id.check_box);
|
checkBox = (CheckBox) view.findViewById(R.id.check_box);
|
||||||
title = (TextView) view.findViewById(R.id.title_text_view);
|
title = (TextView) view.findViewById(R.id.title_text_view);
|
||||||
|
|
Loading…
Reference in a new issue