Upgrade FlexibleAdapter

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-03-06 12:54:15 +01:00
parent 015fefb9ac
commit 9c6a06776b
12 changed files with 165 additions and 155 deletions

View file

@ -123,7 +123,7 @@ dependencies {
implementation 'com.github.HITGIF:TextFieldBoxes:1.4.1' implementation 'com.github.HITGIF:TextFieldBoxes:1.4.1'
implementation 'eu.davidea:flexible-adapter:5.0.0-rc4' implementation 'eu.davidea:flexible-adapter:5.0.0'
implementation 'eu.davidea:flexible-adapter-ui:1.0.0-b2' implementation 'eu.davidea:flexible-adapter-ui:1.0.0-b2'
implementation 'com.github.bumptech.glide:glide:4.3.0' implementation 'com.github.bumptech.glide:glide:4.3.0'

View file

@ -54,7 +54,8 @@ import eu.davidea.flexibleadapter.utils.FlexibleUtils;
import eu.davidea.flipview.FlipView; import eu.davidea.flipview.FlipView;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.UserItemViewHolder> implements IFilterable { public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.UserItemViewHolder> implements
IFilterable<String> {
private Participant participant; private Participant participant;
private UserEntity userEntity; private UserEntity userEntity;
@ -110,8 +111,9 @@ public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.User
@Override @Override
public void bindViewHolder(FlexibleAdapter adapter, UserItemViewHolder holder, int position, List payloads) { public void bindViewHolder(FlexibleAdapter adapter, UserItemViewHolder holder, int position, List payloads) {
if (adapter.hasSearchText()) { if (adapter.hasFilter()) {
FlexibleUtils.highlightText(holder.contactDisplayName, participant.getName(), adapter.getSearchText()); FlexibleUtils.highlightText(holder.contactDisplayName, participant.getName(),
String.valueOf(adapter.getFilter(String.class)));
} else { } else {
holder.contactDisplayName.setText(participant.getName()); holder.contactDisplayName.setText(participant.getName());
} }

View file

@ -38,6 +38,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem; import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
public class AppItem extends AbstractFlexibleItem<AppItem.AppItemViewHolder> { public class AppItem extends AbstractFlexibleItem<AppItem.AppItemViewHolder> {
@ -83,12 +84,7 @@ public class AppItem extends AbstractFlexibleItem<AppItem.AppItemViewHolder> {
} }
@Override @Override
public AppItem.AppItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) { public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, AppItemViewHolder holder, int position, List<Object> payloads) {
return new AppItemViewHolder(view, adapter);
}
@Override
public void bindViewHolder(FlexibleAdapter adapter, AppItem.AppItemViewHolder holder, int position, List<Object> payloads) {
if (drawable != null) { if (drawable != null) {
holder.iconImageView.setVisibility(View.VISIBLE); holder.iconImageView.setVisibility(View.VISIBLE);
holder.iconImageView.setImageDrawable(drawable); holder.iconImageView.setImageDrawable(drawable);
@ -108,6 +104,11 @@ public class AppItem extends AbstractFlexibleItem<AppItem.AppItemViewHolder> {
} }
} }
@Override
public AppItem.AppItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
return new AppItemViewHolder(view, adapter);
}
static class AppItemViewHolder extends FlexibleViewHolder { static class AppItemViewHolder extends FlexibleViewHolder {
@BindView(R.id.icon_image_view) @BindView(R.id.icon_image_view)
public ImageView iconImageView; public ImageView iconImageView;

View file

@ -54,7 +54,7 @@ import eu.davidea.flexibleadapter.utils.FlexibleUtils;
import eu.davidea.flipview.FlipView; import eu.davidea.flipview.FlipView;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
public class CallItem extends AbstractFlexibleItem<CallItem.RoomItemViewHolder> implements IFilterable { public class CallItem extends AbstractFlexibleItem<CallItem.RoomItemViewHolder> implements IFilterable<String> {
private Room room; private Room room;
private UserEntity userEntity; private UserEntity userEntity;
@ -102,8 +102,9 @@ public class CallItem extends AbstractFlexibleItem<CallItem.RoomItemViewHolder>
@Override @Override
public void bindViewHolder(final FlexibleAdapter adapter, RoomItemViewHolder holder, int position, List payloads) { public void bindViewHolder(final FlexibleAdapter adapter, RoomItemViewHolder holder, int position, List payloads) {
if (adapter.hasSearchText()) { if (adapter.hasFilter()) {
FlexibleUtils.highlightText(holder.roomDisplayName, room.getDisplayName(), adapter.getSearchText()); FlexibleUtils.highlightText(holder.roomDisplayName, room.getDisplayName(),
String.valueOf(adapter.getFilter(String.class)));
} else { } else {
holder.roomDisplayName.setText(room.getDisplayName()); holder.roomDisplayName.setText(room.getDisplayName());
} }

View file

@ -28,6 +28,7 @@ import java.util.List;
import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem; import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
public class EmptyFooterItem extends AbstractFlexibleItem<EmptyFooterItem.EmptyFooterItemViewHolder> { public class EmptyFooterItem extends AbstractFlexibleItem<EmptyFooterItem.EmptyFooterItemViewHolder> {
@ -57,13 +58,14 @@ public class EmptyFooterItem extends AbstractFlexibleItem<EmptyFooterItem.EmptyF
} }
@Override @Override
public EmptyFooterItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) { public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, EmptyFooterItemViewHolder holder,
return new EmptyFooterItemViewHolder(view, adapter); int position, List<Object> payloads) {
} }
@Override @Override
public void bindViewHolder(FlexibleAdapter adapter, EmptyFooterItemViewHolder holder, int position, List<Object> payloads) { public EmptyFooterItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
return new EmptyFooterItemViewHolder(view, adapter);
} }
static class EmptyFooterItemViewHolder extends FlexibleViewHolder { static class EmptyFooterItemViewHolder extends FlexibleViewHolder {

View file

@ -31,6 +31,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractHeaderItem; import eu.davidea.flexibleadapter.items.AbstractHeaderItem;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.flexibleadapter.items.IHeader; import eu.davidea.flexibleadapter.items.IHeader;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
@ -55,13 +56,7 @@ public class NewCallHeaderItem extends AbstractHeaderItem<NewCallHeaderItem.Head
} }
@Override @Override
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) { public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, HeaderViewHolder holder, int position, List<Object> payloads) {
headerViewHolder = new HeaderViewHolder(view, adapter);
return headerViewHolder;
}
@Override
public void bindViewHolder(FlexibleAdapter adapter, HeaderViewHolder holder, int position, List<Object> payloads) {
headerViewHolder = holder; headerViewHolder = holder;
if (holder.secondaryRelativeLayout.getVisibility() == View.GONE && adapter.isSelected(position)) { if (holder.secondaryRelativeLayout.getVisibility() == View.GONE && adapter.isSelected(position)) {
@ -71,6 +66,12 @@ public class NewCallHeaderItem extends AbstractHeaderItem<NewCallHeaderItem.Head
} }
} }
@Override
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
headerViewHolder = new HeaderViewHolder(view, adapter);
return headerViewHolder;
}
public void togglePublicCall(boolean showDescription) { public void togglePublicCall(boolean showDescription) {
if (!showDescription) { if (!showDescription) {
headerViewHolder.secondaryRelativeLayout.setVisibility(View.GONE); headerViewHolder.secondaryRelativeLayout.setVisibility(View.GONE);

View file

@ -35,9 +35,10 @@ import butterknife.ButterKnife;
import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractHeaderItem; import eu.davidea.flexibleadapter.items.AbstractHeaderItem;
import eu.davidea.flexibleadapter.items.IFilterable; import eu.davidea.flexibleadapter.items.IFilterable;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
public class UserHeaderItem extends AbstractHeaderItem<UserHeaderItem.HeaderViewHolder> implements IFilterable { public class UserHeaderItem extends AbstractHeaderItem<UserHeaderItem.HeaderViewHolder> implements IFilterable<String> {
private static final String TAG = "UserHeaderItem"; private static final String TAG = "UserHeaderItem";
private String title; private String title;
@ -73,17 +74,18 @@ public class UserHeaderItem extends AbstractHeaderItem<UserHeaderItem.HeaderView
} }
@Override @Override
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) { public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, HeaderViewHolder holder, int position, List<Object> payloads) {
return new HeaderViewHolder(view, adapter);
}
@Override
public void bindViewHolder(FlexibleAdapter adapter, HeaderViewHolder holder, int position, List<Object> payloads) {
if (payloads.size() > 0) { if (payloads.size() > 0) {
Log.d(TAG, "We have payloads, so ignoring!"); Log.d(TAG, "We have payloads, so ignoring!");
} else { } else {
holder.titleTextView.setText(title); holder.titleTextView.setText(title);
} }
}
@Override
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
return new HeaderViewHolder(view, adapter);
} }
static class HeaderViewHolder extends FlexibleViewHolder { static class HeaderViewHolder extends FlexibleViewHolder {

View file

@ -50,7 +50,7 @@ import eu.davidea.flipview.FlipView;
import eu.davidea.viewholders.FlexibleViewHolder; import eu.davidea.viewholders.FlexibleViewHolder;
public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder> implements public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder> implements
ISectionable<UserItem.UserItemViewHolder, UserHeaderItem>, IFilterable { ISectionable<UserItem.UserItemViewHolder, UserHeaderItem>, IFilterable<String> {
private Participant participant; private Participant participant;
private UserEntity userEntity; private UserEntity userEntity;
@ -114,8 +114,9 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
flipItemSelection(); flipItemSelection();
} }
if (adapter.hasSearchText()) { if (adapter.hasFilter()) {
FlexibleUtils.highlightText(holder.contactDisplayName, participant.getName(), adapter.getSearchText()); FlexibleUtils.highlightText(holder.contactDisplayName, participant.getName(),
String.valueOf(adapter.getFilter(String.class)));
} else { } else {
holder.contactDisplayName.setText(participant.getName()); holder.contactDisplayName.setText(participant.getName());
} }

View file

@ -257,9 +257,9 @@ public class CallsListController extends BaseController implements SearchView.On
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
searchItem.setVisible(callItems.size() > 0); searchItem.setVisible(callItems.size() > 0);
if (adapter.hasSearchText()) { if (adapter.hasFilter()) {
searchItem.expandActionView(); searchItem.expandActionView();
searchView.setQuery(adapter.getSearchText(), false); searchView.setQuery(adapter.getFilter(String.class), false);
} }
} }
@ -394,20 +394,20 @@ public class CallsListController extends BaseController implements SearchView.On
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (adapter.hasNewSearchText(newText) || !TextUtils.isEmpty(searchQuery)) { if (adapter.hasNewFilter(newText) || !TextUtils.isEmpty(searchQuery)) {
if (!TextUtils.isEmpty(searchQuery)) { if (!TextUtils.isEmpty(searchQuery)) {
adapter.setSearchText(searchQuery); adapter.setFilter(searchQuery);
searchQuery = ""; searchQuery = "";
adapter.filterItems(); adapter.filterItems();
} else { } else {
adapter.setSearchText(newText); adapter.setFilter(newText);
adapter.filterItems(300); adapter.filterItems(300);
} }
} }
if (swipeRefreshLayout != null) { if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(!adapter.hasSearchText()); swipeRefreshLayout.setEnabled(!adapter.hasFilter());
} }
return true; return true;
@ -473,7 +473,17 @@ public class CallsListController extends BaseController implements SearchView.On
@Override @Override
public boolean onItemClick(int position) { protected String getTitle() {
return getResources().getString(R.string.nc_app_name);
}
@Override
public void onFastScrollerStateChange(boolean scrolling) {
swipeRefreshLayout.setEnabled(!scrolling);
}
@Override
public boolean onItemClick(View view, int position) {
CallItem callItem = adapter.getItem(position); CallItem callItem = adapter.getItem(position);
if (callItem != null && getActivity() != null) { if (callItem != null && getActivity() != null) {
Room room = callItem.getModel(); Room room = callItem.getModel();
@ -496,14 +506,4 @@ public class CallsListController extends BaseController implements SearchView.On
return true; return true;
} }
@Override
protected String getTitle() {
return getResources().getString(R.string.nc_app_name);
}
@Override
public void onFastScrollerStateChange(boolean scrolling) {
swipeRefreshLayout.setEnabled(!scrolling);
}
} }

View file

@ -397,9 +397,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
searchItem.setVisible(contactItems.size() > 0); searchItem.setVisible(contactItems.size() > 0);
if (adapter.hasSearchText()) { if (adapter.hasFilter()) {
searchItem.expandActionView(); searchItem.expandActionView();
searchView.setQuery(adapter.getSearchText(), false); searchView.setQuery((CharSequence) adapter.getFilter(String.class), false);
} }
} }
@ -592,20 +592,20 @@ public class ContactsController extends BaseController implements SearchView.OnQ
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (adapter.hasNewSearchText(newText) || !TextUtils.isEmpty(searchQuery)) { if (adapter.hasNewFilter(newText) || !TextUtils.isEmpty(searchQuery)) {
if (!TextUtils.isEmpty(searchQuery)) { if (!TextUtils.isEmpty(searchQuery)) {
adapter.setSearchText(searchQuery); adapter.setFilter(searchQuery);
searchQuery = ""; searchQuery = "";
adapter.filterItems(); adapter.filterItems();
} else { } else {
adapter.setSearchText(newText); adapter.setFilter(newText);
adapter.filterItems(300); adapter.filterItems(300);
} }
} }
if (swipeRefreshLayout != null) { if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(!adapter.hasSearchText()); swipeRefreshLayout.setEnabled(!adapter.hasFilter());
} }
return true; return true;
@ -616,66 +616,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ
return onQueryTextChange(query); return onQueryTextChange(query);
} }
@Override
public boolean onItemClick(int position) {
if (adapter.getItem(position) instanceof UserItem) {
if (!isNewConversationView) {
UserItem userItem = (UserItem) adapter.getItem(position);
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), "1",
userItem.getModel().getUserId(), null);
ncApi.createRoom(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()),
retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RoomOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(RoomOverall roomOverall) {
if (getActivity() != null) {
Intent callIntent = new Intent(getActivity(), CallActivity.class);
Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity));
callIntent.putExtras(bundle);
if (getActivity() != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
}
startActivity(callIntent);
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
((UserItem) adapter.getItem(position)).flipItemSelection();
adapter.toggleSelection(position);
checkAndHandleBottomButtons();
}
} else if (adapter.getItem(position) instanceof NewCallHeaderItem) {
adapter.toggleSelection(position);
isPublicCall = adapter.isSelected(position);
((NewCallHeaderItem) adapter.getItem(position)).togglePublicCall(isPublicCall);
checkAndHandleBottomButtons();
}
return true;
}
private void checkAndHandleBottomButtons() { private void checkAndHandleBottomButtons() {
if (adapter != null && bottomButtonsLinearLayout != null && clearButton != null) { if (adapter != null && bottomButtonsLinearLayout != null && clearButton != null) {
if (adapter.getSelectedItemCount() > 0 || isPublicCall) { if (adapter.getSelectedItemCount() > 0 || isPublicCall) {
@ -773,4 +713,63 @@ public class ContactsController extends BaseController implements SearchView.OnQ
eventBus.unregister(this); eventBus.unregister(this);
} }
@Override
public boolean onItemClick(View view, int position) {
if (adapter.getItem(position) instanceof UserItem) {
if (!isNewConversationView) {
UserItem userItem = (UserItem) adapter.getItem(position);
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), "1",
userItem.getModel().getUserId(), null);
ncApi.createRoom(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()),
retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RoomOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(RoomOverall roomOverall) {
if (getActivity() != null) {
Intent callIntent = new Intent(getActivity(), CallActivity.class);
Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity));
callIntent.putExtras(bundle);
if (getActivity() != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
}
startActivity(callIntent);
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
((UserItem) adapter.getItem(position)).flipItemSelection();
adapter.toggleSelection(position);
checkAndHandleBottomButtons();
}
} else if (adapter.getItem(position) instanceof NewCallHeaderItem) {
adapter.toggleSelection(position);
isPublicCall = adapter.isSelected(position);
((NewCallHeaderItem) adapter.getItem(position)).togglePublicCall(isPublicCall);
checkAndHandleBottomButtons();
}
return true;
}
} }

View file

@ -81,19 +81,21 @@ public class SwitchAccountController extends BaseController {
private boolean isAccountImport = false; private boolean isAccountImport = false;
private FlexibleAdapter.OnItemClickListener onImportItemClickListener = position -> { private FlexibleAdapter.OnItemClickListener onImportItemClickListener = new FlexibleAdapter.OnItemClickListener() {
@Override
public boolean onItemClick(View view, int position) {
if (userItems.size() > position) { if (userItems.size() > position) {
Account account = ((AdvancedUserItem) userItems.get(position)).getAccount(); Account account = ((AdvancedUserItem) userItems.get(position)).getAccount();
verifyAccount(account); verifyAccount(account);
} }
return true; return true;
}
}; };
private FlexibleAdapter.OnItemClickListener onSwitchItemClickListener = private FlexibleAdapter.OnItemClickListener onSwitchItemClickListener = new FlexibleAdapter.OnItemClickListener() {
new FlexibleAdapter.OnItemClickListener() {
@Override @Override
public boolean onItemClick(int position) { public boolean onItemClick(View view, int position) {
if (userItems.size() > position) { if (userItems.size() > position) {
UserEntity userEntity = ((AdvancedUserItem) userItems.get(position)).getEntity(); UserEntity userEntity = ((AdvancedUserItem) userItems.get(position)).getEntity();
userUtils.createOrUpdateUser(null, userUtils.createOrUpdateUser(null,

View file

@ -179,7 +179,7 @@ public class CallMenuController extends BaseController implements FlexibleAdapte
} }
@Override @Override
public boolean onItemClick(int position) { public boolean onItemClick(View view, int position) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room)); bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
@ -254,7 +254,6 @@ public class CallMenuController extends BaseController implements FlexibleAdapte
} }
} }
return true; return true;
} }