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:orientation="vertical">
|
||||
|
||||
<include layout="@layout/list_item_divider"/>
|
||||
<include
|
||||
android:id="@+id/top_divider"
|
||||
layout="@layout/list_item_divider"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/background_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/bg_color">
|
||||
|
|
|
@ -117,11 +117,12 @@ public class NotesFragment extends OsmAndListFragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||
List<Object> items = createItemsList();
|
||||
ListView listView = getListView();
|
||||
listView.setDivider(null);
|
||||
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);
|
||||
listView.addFooterView(footerView);
|
||||
listView.setHeaderDividersEnabled(false);
|
||||
|
@ -131,6 +132,7 @@ public class NotesFragment extends OsmAndListFragment {
|
|||
listAdapter.setSelectionMode(selectionMode);
|
||||
listAdapter.setSelected(selected);
|
||||
listAdapter.setListener(createAdapterListener());
|
||||
listAdapter.setPortrait(portrait);
|
||||
listView.setAdapter(listAdapter);
|
||||
}
|
||||
|
||||
|
@ -294,7 +296,7 @@ public class NotesFragment extends OsmAndListFragment {
|
|||
|
||||
private void selectAll(int type) {
|
||||
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);
|
||||
if (item instanceof Recording) {
|
||||
selected.add((Recording) item);
|
||||
|
|
|
@ -2,13 +2,16 @@ package net.osmand.plus.audionotes.adapters;
|
|||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -30,10 +33,13 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
|||
|
||||
private OsmandApplication app;
|
||||
private NotesAdapterListener listener;
|
||||
private List<Object> items;
|
||||
|
||||
private boolean selectionMode;
|
||||
private Set<Recording> selected;
|
||||
|
||||
private boolean portrait;
|
||||
|
||||
public void setListener(NotesAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
@ -46,14 +52,20 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
|||
this.selected = selected;
|
||||
}
|
||||
|
||||
public void setPortrait(boolean portrait) {
|
||||
this.portrait = portrait;
|
||||
}
|
||||
|
||||
public NotesAdapter(OsmandApplication app, List<Object> items) {
|
||||
super(app, R.layout.note, items);
|
||||
this.app = app;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View row, @NonNull ViewGroup parent) {
|
||||
if (portrait) {
|
||||
final int type = getItemViewType(position);
|
||||
boolean header = type == TYPE_DATE_HEADER
|
||||
|| type == TYPE_AUDIO_HEADER
|
||||
|
@ -74,7 +86,73 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
|||
}
|
||||
|
||||
if (header) {
|
||||
final HeaderViewHolder holder = (HeaderViewHolder) row.getTag();
|
||||
setupHeader(type, (HeaderViewHolder) row.getTag());
|
||||
} else {
|
||||
final Object item = getItem(position);
|
||||
if (item instanceof Recording) {
|
||||
setupItem(position, (Recording) item, (ItemViewHolder) row.getTag());
|
||||
}
|
||||
}
|
||||
|
||||
return row;
|
||||
} else {
|
||||
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
boolean lastCard = getHeadersCount() == position + 1;
|
||||
int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||
int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10;
|
||||
|
||||
FrameLayout fl = new FrameLayout(getContext());
|
||||
LinearLayout ll = new LinearLayout(getContext());
|
||||
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 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return fl;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (portrait) {
|
||||
return super.getCount();
|
||||
}
|
||||
return getHeadersCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Object item = getItem(position);
|
||||
if (item instanceof Recording) {
|
||||
return TYPE_ITEM;
|
||||
}
|
||||
return (int) item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
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) {
|
||||
|
@ -96,23 +174,22 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
|||
} 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(getHeaderTitleRes(type));
|
||||
}
|
||||
holder.title.setText(titleId);
|
||||
} else {
|
||||
final Object item = getItem(position);
|
||||
if (item instanceof Recording) {
|
||||
final Recording recording = (Recording) item;
|
||||
final ItemViewHolder holder = (ItemViewHolder) row.getTag();
|
||||
|
||||
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);
|
||||
|
@ -164,32 +241,46 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupBackground(View view) {
|
||||
if (!portrait) {
|
||||
view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.color_transparent));
|
||||
}
|
||||
}
|
||||
|
||||
return row;
|
||||
public int getItemsCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Object item = getItem(position);
|
||||
if (item instanceof Recording) {
|
||||
return TYPE_ITEM;
|
||||
private int getHeadersCount() {
|
||||
int res = 0;
|
||||
for (Object item : items) {
|
||||
if (item instanceof Integer) {
|
||||
res++;
|
||||
}
|
||||
return (int) item;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return TYPE_COUNT;
|
||||
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) {
|
||||
return pos == getCount() - 1 || !(getItem(pos + 1) instanceof Recording);
|
||||
return pos == items.size() - 1 || !(getItem(pos + 1) instanceof Recording);
|
||||
}
|
||||
|
||||
private boolean isSelectAllChecked(int type) {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
Object item = getItem(i);
|
||||
for (Object item : items) {
|
||||
if (item instanceof Recording) {
|
||||
if (type != TYPE_DATE_HEADER && !isAppropriate((Recording) item, type)) {
|
||||
continue;
|
||||
|
@ -214,12 +305,16 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|
|||
private class HeaderViewHolder {
|
||||
|
||||
final View view;
|
||||
final View topDivider;
|
||||
final View backgroundView;
|
||||
final View headerRow;
|
||||
final CheckBox checkBox;
|
||||
final TextView title;
|
||||
|
||||
HeaderViewHolder(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);
|
||||
checkBox = (CheckBox) view.findViewById(R.id.check_box);
|
||||
title = (TextView) view.findViewById(R.id.title_text_view);
|
||||
|
|
Loading…
Reference in a new issue