Let user search for image

This commit is contained in:
RichyHBM 2017-11-26 15:34:54 +00:00
parent 91db03bc47
commit 85f1a86b5d
3 changed files with 54 additions and 9 deletions

View file

@ -32,6 +32,9 @@ import android.graphics.Bitmap;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -281,18 +284,43 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
int marginSmall = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_small); int marginSmall = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_small);
int marginMedium = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium); int marginMedium = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium);
final ThumbnailSelectionAdapter thumbnailAdapter = new ThumbnailSelectionAdapter(context);
final EditText input = new EditText(context);
input.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
input.setSingleLine();
input.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void afterTextChanged(Editable editable) {
thumbnailAdapter.filter(editable.toString());
}
});
GridView grid = new GridView(context); GridView grid = new GridView(context);
grid.setAdapter(new ThumbnailSelectionAdapter(context)); grid.setAdapter(thumbnailAdapter);
grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size)); grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size_small));
grid.setNumColumns(GridView.AUTO_FIT); grid.setNumColumns(GridView.AUTO_FIT);
grid.setVerticalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium)); grid.setVerticalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium));
grid.setHorizontalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium)); grid.setHorizontalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium));
grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH); grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layout.addView(input);
layout.addView(grid);
FrameLayout container = new FrameLayout(context); FrameLayout container = new FrameLayout(context);
container.setPaddingRelative(marginMedium, marginSmall, marginMedium, 0); container.setPaddingRelative(marginMedium, marginSmall, marginMedium, 0);
container.addView(grid); container.addView(layout);
final AlertDialog alert = builder.setTitle(R.string.menu_popup_change_image) final AlertDialog alert = builder.setTitle(R.string.menu_popup_change_image)
.setView(container) .setView(container)

View file

@ -15,36 +15,52 @@ import org.shadowice.flocke.andotp.R;
import org.shadowice.flocke.andotp.Utilities.EntryThumbnail; import org.shadowice.flocke.andotp.Utilities.EntryThumbnail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ThumbnailSelectionAdapter extends BaseAdapter { public class ThumbnailSelectionAdapter extends BaseAdapter {
private Context context; private Context context;
private List items;
ThumbnailSelectionAdapter(Context context) { ThumbnailSelectionAdapter(Context context) {
items = new ArrayList(EntryThumbnail.EntryThumbnails.values().length);
Collections.addAll(items, EntryThumbnail.EntryThumbnails.values());
this.context = context; this.context = context;
} }
void filter(String filter) {
items.clear();
for (EntryThumbnail.EntryThumbnails thumb : EntryThumbnail.EntryThumbnails.values()) {
if(thumb.name().toLowerCase().contains(filter.toLowerCase())) {
items.add(thumb);
}
}
notifyDataSetChanged();
}
@Override @Override
public int getCount() { public int getCount() {
return EntryThumbnail.EntryThumbnails.values().length; return items.size();
} }
@Override @Override
public Object getItem(int i) { public Object getItem(int i) {
if(i >= EntryThumbnail.EntryThumbnails.values().length) if(i < getCount())
return EntryThumbnail.EntryThumbnails.Default; return items.get(i);
else else
return EntryThumbnail.EntryThumbnails.values()[i]; return EntryThumbnail.EntryThumbnails.Default;
} }
@Override @Override
public long getItemId(int i) { public long getItemId(int i) {
return EntryThumbnail.EntryThumbnails.values()[i].ordinal(); return ((EntryThumbnail.EntryThumbnails) getItem(i)).ordinal();
} }
@NonNull @NonNull
@Override @Override
public View getView(int i, View view, @NonNull ViewGroup viewGroup) { public View getView(int i, View view, @NonNull ViewGroup viewGroup) {
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size); int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size_small);
ImageView imageView; ImageView imageView;
if (view == null) { if (view == null) {
imageView = new ImageView(context); imageView = new ImageView(context);

View file

@ -10,6 +10,7 @@
<dimen name="card_corner_radius">0dp</dimen> <dimen name="card_corner_radius">0dp</dimen>
<dimen name="card_thumbnail_size">64dp</dimen> <dimen name="card_thumbnail_size">64dp</dimen>
<dimen name="card_thumbnail_size_small">46dp</dimen>
<!-- The default letter tile text size --> <!-- The default letter tile text size -->
<dimen name="tile_letter_font_size">33sp</dimen> <dimen name="tile_letter_font_size">33sp</dimen>