2016-12-18 18:41:30 +01:00
|
|
|
/*
|
|
|
|
This file is part of Subsonic.
|
2018-03-24 20:25:12 +01:00
|
|
|
Subsonic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
Subsonic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
Copyright 2015 (C) Scott Jackson
|
2016-12-18 18:41:30 +01:00
|
|
|
*/
|
|
|
|
|
2017-01-09 08:01:12 +01:00
|
|
|
package net.nullsum.audinaut.adapter;
|
2016-12-18 18:41:30 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.support.v7.view.ActionMode;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
|
2017-01-09 08:01:12 +01:00
|
|
|
import net.nullsum.audinaut.R;
|
|
|
|
import net.nullsum.audinaut.activity.SubsonicFragmentActivity;
|
|
|
|
import net.nullsum.audinaut.util.Constants;
|
|
|
|
import net.nullsum.audinaut.util.MenuUtil;
|
|
|
|
import net.nullsum.audinaut.util.Util;
|
|
|
|
import net.nullsum.audinaut.view.BasicHeaderView;
|
|
|
|
import net.nullsum.audinaut.view.UpdateView;
|
|
|
|
import net.nullsum.audinaut.view.UpdateView.UpdateViewHolder;
|
2016-12-18 18:41:30 +01:00
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-12-18 18:41:30 +01:00
|
|
|
public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewHolder<T>> {
|
2018-03-25 03:28:28 +02:00
|
|
|
public static final int VIEW_TYPE_HEADER = 0;
|
|
|
|
private static final String TAG = SectionAdapter.class.getSimpleName();
|
|
|
|
private static String[] ignoredArticles;
|
|
|
|
private final List<T> selected = new ArrayList<>();
|
|
|
|
private final List<UpdateView> selectedViews = new ArrayList<>();
|
|
|
|
Context context;
|
|
|
|
List<String> headers;
|
|
|
|
List<List<T>> sections;
|
|
|
|
boolean singleSectionHeader;
|
|
|
|
OnItemClickedListener<T> onItemClickedListener;
|
|
|
|
boolean checkable = false;
|
|
|
|
private ActionMode currentActionMode;
|
|
|
|
|
|
|
|
SectionAdapter() {
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
|
|
|
SectionAdapter(Context context, List<T> section) {
|
2018-03-24 20:25:12 +01:00
|
|
|
this.context = context;
|
2018-03-25 03:28:28 +02:00
|
|
|
this.headers = Collections.singletonList("Section");
|
2018-03-24 20:25:12 +01:00
|
|
|
this.sections = new ArrayList<>();
|
|
|
|
this.sections.add(section);
|
2018-03-25 03:28:28 +02:00
|
|
|
this.singleSectionHeader = false;
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
SectionAdapter(Context context, List<String> headers, List<List<T>> sections) {
|
|
|
|
this.context = context;
|
2018-03-24 20:25:12 +01:00
|
|
|
this.headers = headers;
|
|
|
|
this.sections = sections;
|
2018-03-25 03:28:28 +02:00
|
|
|
this.singleSectionHeader = true;
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2018-03-25 03:28:28 +02:00
|
|
|
if (viewType == VIEW_TYPE_HEADER) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return onCreateHeaderHolder(parent);
|
|
|
|
} else {
|
2018-03-25 03:28:28 +02:00
|
|
|
final UpdateViewHolder<T> holder = onCreateSectionViewHolder(viewType);
|
2018-03-24 20:25:12 +01:00
|
|
|
final UpdateView updateView = holder.getUpdateView();
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
if (updateView != null) {
|
|
|
|
updateView.getChildAt(0).setOnClickListener(v -> {
|
|
|
|
T item = holder.getItem();
|
|
|
|
if (currentActionMode != null) {
|
|
|
|
if (updateView.isCheckable()) {
|
|
|
|
if (selected.contains(item)) {
|
|
|
|
selected.remove(item);
|
|
|
|
selectedViews.remove(updateView);
|
|
|
|
setChecked(updateView, false);
|
|
|
|
} else {
|
|
|
|
selected.add(item);
|
|
|
|
selectedViews.add(updateView);
|
|
|
|
setChecked(updateView, true);
|
|
|
|
}
|
2018-03-24 20:25:12 +01:00
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
if (selected.isEmpty()) {
|
|
|
|
currentActionMode.finish();
|
|
|
|
} else {
|
|
|
|
currentActionMode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
} else if (onItemClickedListener != null) {
|
|
|
|
onItemClickedListener.onItemClicked(updateView, item);
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
View moreButton = updateView.findViewById(R.id.item_more);
|
|
|
|
if (moreButton != null) {
|
2018-03-25 03:28:28 +02:00
|
|
|
moreButton.setOnClickListener(v -> {
|
|
|
|
try {
|
|
|
|
final T item = holder.getItem();
|
|
|
|
if (onItemClickedListener != null) {
|
|
|
|
PopupMenu popup = new PopupMenu(context, v);
|
|
|
|
onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item);
|
|
|
|
|
|
|
|
popup.setOnMenuItemClickListener(menuItem -> onItemClickedListener.onContextItemSelected(menuItem, updateView, item));
|
|
|
|
popup.show();
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(TAG, "Failed to show popup", e);
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
if (checkable) {
|
|
|
|
updateView.getChildAt(0).setOnLongClickListener(v -> {
|
|
|
|
if (updateView.isCheckable()) {
|
|
|
|
if (currentActionMode == null) {
|
|
|
|
startActionMode(holder);
|
|
|
|
} else {
|
|
|
|
updateView.getChildAt(0).performClick();
|
2018-03-24 20:25:12 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
return true;
|
2018-03-24 20:25:12 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(UpdateViewHolder holder, int position) {
|
|
|
|
UpdateView updateView = holder.getUpdateView();
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
if (sections.size() == 1 && !singleSectionHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
T item = sections.get(0).get(position);
|
|
|
|
onBindViewHolder(holder, item, getItemViewType(position));
|
|
|
|
postBindView(updateView, item);
|
|
|
|
holder.setItem(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int subPosition = 0;
|
|
|
|
int subHeader = 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
for (List<T> section : sections) {
|
2018-03-24 20:25:12 +01:00
|
|
|
boolean validHeader = headers.get(subHeader) != null;
|
2018-03-25 03:28:28 +02:00
|
|
|
if (position == subPosition && validHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
onBindHeaderHolder(holder, headers.get(subHeader), subHeader);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int headerOffset = validHeader ? 1 : 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
if (position < (subPosition + section.size() + headerOffset)) {
|
2018-03-24 20:25:12 +01:00
|
|
|
T item = section.get(position - subPosition - headerOffset);
|
|
|
|
onBindViewHolder(holder, item, getItemViewType(item));
|
|
|
|
|
|
|
|
postBindView(updateView, item);
|
|
|
|
holder.setItem(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
subPosition += section.size();
|
2018-03-25 03:28:28 +02:00
|
|
|
if (validHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
subPosition += 1;
|
|
|
|
}
|
|
|
|
subHeader++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void postBindView(UpdateView updateView, T item) {
|
2018-03-25 03:28:28 +02:00
|
|
|
if (updateView.isCheckable()) {
|
2018-03-24 20:25:12 +01:00
|
|
|
setChecked(updateView, selected.contains(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
View moreButton = updateView.findViewById(R.id.item_more);
|
2018-03-25 03:28:28 +02:00
|
|
|
if (moreButton != null) {
|
|
|
|
if (onItemClickedListener != null) {
|
2018-03-24 20:25:12 +01:00
|
|
|
PopupMenu popup = new PopupMenu(context, moreButton);
|
|
|
|
Menu menu = popup.getMenu();
|
|
|
|
onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item);
|
|
|
|
if (menu.size() == 0) {
|
|
|
|
moreButton.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
moreButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
moreButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2018-03-25 03:28:28 +02:00
|
|
|
if (sections.size() == 1 && !singleSectionHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return sections.get(0).size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
for (String header : headers) {
|
|
|
|
if (header != null) {
|
2018-03-24 20:25:12 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
for (List<T> section : sections) {
|
2018-03-24 20:25:12 +01:00
|
|
|
count += section.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2018-03-25 03:28:28 +02:00
|
|
|
if (sections.size() == 1 && !singleSectionHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return getItemViewType(sections.get(0).get(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
int subPosition = 0;
|
|
|
|
int subHeader = 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
for (List<T> section : sections) {
|
2018-03-24 20:25:12 +01:00
|
|
|
boolean validHeader = headers.get(subHeader) != null;
|
2018-03-25 03:28:28 +02:00
|
|
|
if (position == subPosition && validHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return VIEW_TYPE_HEADER;
|
|
|
|
}
|
|
|
|
|
|
|
|
int headerOffset = validHeader ? 1 : 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
if (position < (subPosition + section.size() + headerOffset)) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return getItemViewType(section.get(position - subPosition - headerOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
subPosition += section.size();
|
2018-03-25 03:28:28 +02:00
|
|
|
if (validHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
subPosition += 1;
|
|
|
|
}
|
|
|
|
subHeader++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return new UpdateViewHolder(new BasicHeaderView(context));
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
|
|
|
void onBindHeaderHolder(UpdateViewHolder holder, String header, int sectionIndex) {
|
2018-03-24 20:25:12 +01:00
|
|
|
UpdateView view = holder.getUpdateView();
|
2018-03-25 03:28:28 +02:00
|
|
|
if (view != null) {
|
2018-03-24 20:25:12 +01:00
|
|
|
view.setObject(header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
T getItemForPosition(int position) {
|
|
|
|
if (sections.size() == 1 && !singleSectionHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return sections.get(0).get(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
int subPosition = 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
for (List<T> section : sections) {
|
|
|
|
if (position == subPosition) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
if (position <= (subPosition + section.size())) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return section.get(position - subPosition - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
subPosition += section.size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
2018-03-24 20:25:12 +01:00
|
|
|
public int getItemPosition(T item) {
|
2018-03-25 03:28:28 +02:00
|
|
|
if (sections.size() == 1 && !singleSectionHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return sections.get(0).indexOf(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int subPosition = 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
for (List<T> section : sections) {
|
2018-03-24 20:25:12 +01:00
|
|
|
subPosition += section.size() + 1;
|
|
|
|
|
|
|
|
int position = section.indexOf(item);
|
2018-03-25 03:28:28 +02:00
|
|
|
if (position != -1) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return position + subPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnItemClickedListener(OnItemClickedListener<T> onItemClickedListener) {
|
|
|
|
this.onItemClickedListener = onItemClickedListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addSelected(T item) {
|
|
|
|
selected.add(item);
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
2018-03-24 20:25:12 +01:00
|
|
|
public List<T> getSelected() {
|
|
|
|
List<T> selected = new ArrayList<>();
|
|
|
|
selected.addAll(this.selected);
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearSelected() {
|
|
|
|
selected.clear();
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
for (UpdateView updateView : selectedViews) {
|
2018-03-24 20:25:12 +01:00
|
|
|
updateView.setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void moveItem(int from, int to) {
|
|
|
|
List<T> section = sections.get(0);
|
|
|
|
int max = section.size();
|
2018-03-25 03:28:28 +02:00
|
|
|
if (to >= max) {
|
2018-03-24 20:25:12 +01:00
|
|
|
to = max - 1;
|
2018-03-25 03:28:28 +02:00
|
|
|
} else if (to < 0) {
|
2018-03-24 20:25:12 +01:00
|
|
|
to = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
T moved = section.remove(from);
|
|
|
|
section.add(to, moved);
|
|
|
|
|
|
|
|
notifyItemMoved(from, to);
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
2018-03-24 20:25:12 +01:00
|
|
|
public void removeItem(T item) {
|
|
|
|
int subPosition = 0;
|
2018-03-25 03:28:28 +02:00
|
|
|
for (List<T> section : sections) {
|
|
|
|
if (sections.size() > 1 || singleSectionHeader) {
|
2018-03-24 20:25:12 +01:00
|
|
|
subPosition++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = section.indexOf(item);
|
|
|
|
if (index != -1) {
|
|
|
|
section.remove(item);
|
|
|
|
notifyItemRemoved(subPosition + index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
subPosition += section.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
protected abstract UpdateView.UpdateViewHolder onCreateSectionViewHolder(int viewType);
|
|
|
|
|
|
|
|
protected abstract void onBindViewHolder(UpdateViewHolder holder, T item, int viewType);
|
|
|
|
|
|
|
|
protected abstract int getItemViewType(T item);
|
|
|
|
|
|
|
|
private void setChecked(UpdateView updateView, boolean checked) {
|
2018-03-24 20:25:12 +01:00
|
|
|
updateView.setChecked(checked);
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
|
|
|
void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
|
|
|
|
}
|
2018-03-24 20:25:12 +01:00
|
|
|
|
|
|
|
private void startActionMode(final UpdateView.UpdateViewHolder<T> holder) {
|
|
|
|
final UpdateView<T> updateView = holder.getUpdateView();
|
|
|
|
if (context instanceof SubsonicFragmentActivity && currentActionMode == null) {
|
|
|
|
final SubsonicFragmentActivity fragmentActivity = (SubsonicFragmentActivity) context;
|
|
|
|
fragmentActivity.startSupportActionMode(new ActionMode.Callback() {
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
currentActionMode = mode;
|
|
|
|
|
|
|
|
T item = holder.getItem();
|
|
|
|
selected.add(item);
|
|
|
|
selectedViews.add(updateView);
|
|
|
|
setChecked(updateView, true);
|
|
|
|
|
|
|
|
onCreateActionModeMenu(menu, mode.getMenuInflater());
|
|
|
|
MenuUtil.hideMenuItems(context, menu, updateView);
|
|
|
|
|
|
|
|
mode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
|
|
|
|
TypedValue typedValue = new TypedValue();
|
|
|
|
Resources.Theme theme = context.getTheme();
|
|
|
|
theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
|
|
|
|
int colorPrimaryDark = typedValue.data;
|
|
|
|
|
|
|
|
Window window = ((SubsonicFragmentActivity) context).getWindow();
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
|
window.setStatusBarColor(colorPrimaryDark);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
if (fragmentActivity.onOptionsItemSelected(item)) {
|
|
|
|
currentActionMode.finish();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
currentActionMode = null;
|
|
|
|
selected.clear();
|
|
|
|
for (UpdateView<T> updateView : selectedViews) {
|
|
|
|
updateView.setChecked(false);
|
|
|
|
}
|
|
|
|
selectedViews.clear();
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
|
|
|
|
Window window = ((SubsonicFragmentActivity) context).getWindow();
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
2018-03-24 20:25:12 +01:00
|
|
|
public void stopActionMode() {
|
2018-03-25 03:28:28 +02:00
|
|
|
if (currentActionMode != null) {
|
2018-03-24 20:25:12 +01:00
|
|
|
currentActionMode.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
String getNameIndex(String name) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return getNameIndex(name, false);
|
|
|
|
}
|
2018-03-25 03:28:28 +02:00
|
|
|
|
|
|
|
String getNameIndex(String name, boolean removeIgnoredArticles) {
|
|
|
|
if (name == null) {
|
2018-03-24 20:25:12 +01:00
|
|
|
return "*";
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:28:28 +02:00
|
|
|
if (removeIgnoredArticles) {
|
2018-03-24 20:25:12 +01:00
|
|
|
if (ignoredArticles == null) {
|
|
|
|
SharedPreferences prefs = Util.getPreferences(context);
|
|
|
|
String ignoredArticlesString = prefs.getString(Constants.CACHE_KEY_IGNORE, "The El La Los Las Le Les");
|
|
|
|
ignoredArticles = ignoredArticlesString.split(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
name = name.toLowerCase();
|
|
|
|
for (String article : ignoredArticles) {
|
|
|
|
int index = name.indexOf(article.toLowerCase() + " ");
|
|
|
|
if (index == 0) {
|
|
|
|
name = name.substring(article.length() + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String index = name.substring(0, 1).toUpperCase();
|
|
|
|
if (!Character.isLetter(index.charAt(0))) {
|
|
|
|
index = "#";
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnItemClickedListener<T> {
|
|
|
|
void onItemClicked(UpdateView<T> updateView, T item);
|
2018-03-25 03:28:28 +02:00
|
|
|
|
2018-03-24 20:25:12 +01:00
|
|
|
void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<T> updateView, T item);
|
2018-03-25 03:28:28 +02:00
|
|
|
|
2018-03-24 20:25:12 +01:00
|
|
|
boolean onContextItemSelected(MenuItem menuItem, UpdateView<T> updateView, T item);
|
|
|
|
}
|
2016-12-18 18:41:30 +01:00
|
|
|
}
|