Add board selecting to filterlayout

filtering
Floens 10 years ago
parent c98d3565d1
commit 810fd66e4e
  1. 17
      Clover/app/src/main/java/org/floens/chan/core/manager/FilterEngine.java
  2. 28
      Clover/app/src/main/java/org/floens/chan/core/model/Filter.java
  3. 7
      Clover/app/src/main/java/org/floens/chan/ui/controller/BoardEditController.java
  4. 7
      Clover/app/src/main/java/org/floens/chan/ui/controller/FiltersController.java
  5. 31
      Clover/app/src/main/java/org/floens/chan/ui/helper/BoardHelper.java
  6. 263
      Clover/app/src/main/java/org/floens/chan/ui/layout/BoardSelectLayout.java
  7. 117
      Clover/app/src/main/java/org/floens/chan/ui/layout/FilterLayout.java
  8. 141
      Clover/app/src/main/java/org/floens/chan/ui/layout/SearchLayout.java
  9. 83
      Clover/app/src/main/java/org/floens/chan/ui/toolbar/Toolbar.java
  10. 58
      Clover/app/src/main/res/layout/cell_board_select.xml
  11. 54
      Clover/app/src/main/res/layout/layout_board_select.xml
  12. 49
      Clover/app/src/main/res/layout/layout_filter.xml
  13. 4
      Clover/app/src/main/res/values/strings.xml

@ -1,3 +1,20 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.core.manager;
import org.floens.chan.core.model.Filter;

@ -1,3 +1,20 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.core.model;
public class Filter {
@ -9,7 +26,18 @@ public class Filter {
public String pattern;
public boolean allBoards = true;
public String boards;
public boolean hide = true;
public void apply(Filter filter) {
enabled = filter.enabled;
type = filter.type;
pattern = filter.pattern;
allBoards = filter.allBoards;
boards = filter.boards;
hide = filter.hide;
}
}

@ -45,12 +45,12 @@ import org.floens.chan.controller.Controller;
import org.floens.chan.core.manager.BoardManager;
import org.floens.chan.core.model.Board;
import org.floens.chan.ui.drawable.ThumbDrawable;
import org.floens.chan.ui.helper.BoardHelper;
import org.floens.chan.ui.helper.SwipeListener;
import org.floens.chan.ui.toolbar.ToolbarMenu;
import org.floens.chan.ui.toolbar.ToolbarMenuItem;
import org.floens.chan.ui.view.FloatingMenuItem;
import org.floens.chan.utils.AndroidUtils;
import org.jsoup.parser.Parser;
import java.util.ArrayList;
import java.util.Collections;
@ -396,9 +396,8 @@ public class BoardEditController extends Controller implements SwipeListener.Cal
} else {
BoardEditItem item = (BoardEditItem) holder;
Board board = boards.get(position - 1);
item.text.setText("/" + board.value + "/ " + board.key);
item.description.setText(board.description == null ? null : Parser.unescapeEntities(board.description, false));
item.text.setText(BoardHelper.getName(board));
item.description.setText(BoardHelper.getDescription(board));
}
}

@ -101,7 +101,7 @@ public class FiltersController extends Controller implements ToolbarMenuItem.Too
public void onSubMenuItemClicked(ToolbarMenuItem parent, FloatingMenuItem item) {
}
private void showFilterDialog(Filter filter) {
private void showFilterDialog(final Filter filter) {
final FilterLayout filterLayout = (FilterLayout) LayoutInflater.from(context).inflate(R.layout.layout_filter, null);
new AlertDialog.Builder(context)
@ -109,7 +109,10 @@ public class FiltersController extends Controller implements ToolbarMenuItem.Too
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
filterLayout.save();
Filter newFilter = filterLayout.getFilter();
newFilter.id = filter.id;
Chan.getDatabaseManager().addFilter(newFilter);
adapter.load();
}
})

@ -0,0 +1,31 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.helper;
import org.floens.chan.core.model.Board;
import org.jsoup.parser.Parser;
public class BoardHelper {
public static String getName(Board board) {
return "/" + board.value + "/ " + board.key;
}
public static String getDescription(Board board) {
return board.description == null ? null : Parser.unescapeEntities(board.description, false);
}
}

@ -0,0 +1,263 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.floens.chan.Chan;
import org.floens.chan.R;
import org.floens.chan.core.manager.BoardManager;
import org.floens.chan.core.model.Board;
import org.floens.chan.ui.helper.BoardHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static org.floens.chan.utils.AndroidUtils.getAttrColor;
import static org.floens.chan.utils.AndroidUtils.getString;
public class BoardSelectLayout extends LinearLayout implements SearchLayout.SearchLayoutCallback, View.OnClickListener {
private SearchLayout searchLayout;
private RecyclerView recyclerView;
private Button checkAllButton;
private List<BoardChecked> boards = new ArrayList<>();
private BoardManager boardManager;
private BoardSelectAdapter adapter;
private boolean allChecked = false;
public BoardSelectLayout(Context context) {
super(context);
}
public BoardSelectLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BoardSelectLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onSearchEntered(String entered) {
adapter.search(entered);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
boardManager = Chan.getBoardManager();
List<Board> savedList = boardManager.getSavedBoards();
for (Board saved : savedList) {
boards.add(new BoardChecked(saved, false));
}
searchLayout = (SearchLayout) findViewById(R.id.search_layout);
searchLayout.setCallback(this);
searchLayout.setHint(getString(R.string.search_hint));
searchLayout.setTextColor(getAttrColor(getContext(), R.attr.text_color_primary));
searchLayout.setHintColor(getAttrColor(getContext(), R.attr.text_color_hint));
searchLayout.setClearButtonImage(R.drawable.ic_clear_black_24dp);
checkAllButton = (Button) findViewById(R.id.select_all);
checkAllButton.setOnClickListener(this);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new BoardSelectAdapter();
recyclerView.setAdapter(adapter);
adapter.load();
updateAllSelected();
}
@Override
public void onClick(View v) {
if (v == checkAllButton) {
for (BoardChecked item : boards) {
item.checked = !allChecked;
}
updateAllSelected();
recyclerView.getAdapter().notifyDataSetChanged();
}
}
public void setCheckedBoards(List<Board> checked) {
for (BoardChecked board : boards) {
for (Board check : checked) {
if (check.value.equals(board.board.value)) {
board.checked = true;
break;
}
}
}
recyclerView.getAdapter().notifyDataSetChanged();
}
public List<Board> getCheckedBoards() {
List<Board> list = new ArrayList<>();
for (int i = 0; i < boards.size(); i++) {
BoardSelectLayout.BoardChecked board = boards.get(i);
if (board.checked) {
list.add(board.board);
}
}
return list;
}
public boolean getAllChecked() {
return allChecked;
}
private void updateAllSelected() {
int checkedCount = 0;
for (BoardChecked item : boards) {
if (item.checked) {
checkedCount++;
}
}
allChecked = checkedCount == boards.size();
checkAllButton.setText(allChecked ? R.string.board_select_none : R.string.board_select_all);
}
private class BoardSelectAdapter extends RecyclerView.Adapter<BoardSelectViewHolder> {
private List<BoardChecked> sourceList = new ArrayList<>();
private List<BoardChecked> displayList = new ArrayList<>();
private String searchQuery;
public BoardSelectAdapter() {
setHasStableIds(true);
}
@Override
public BoardSelectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new BoardSelectViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_board_select, parent, false));
}
@Override
public void onBindViewHolder(BoardSelectViewHolder holder, int position) {
BoardChecked board = displayList.get(position);
holder.checkBox.setChecked(board.checked);
holder.text.setText(BoardHelper.getName(board.board));
holder.description.setText(BoardHelper.getDescription(board.board));
}
@Override
public int getItemCount() {
return displayList.size();
}
@Override
public long getItemId(int position) {
return displayList.get(position).board.id;
}
public void search(String query) {
this.searchQuery = query;
filter();
}
private void load() {
sourceList.clear();
sourceList.addAll(boards);
filter();
}
private void filter() {
displayList.clear();
if (!TextUtils.isEmpty(searchQuery)) {
String query = searchQuery.toLowerCase(Locale.ENGLISH);
for (BoardChecked boardChecked : sourceList) {
String description = boardChecked.board.description == null ? "" : boardChecked.board.description;
if (boardChecked.board.key.toLowerCase(Locale.ENGLISH).contains(query) ||
boardChecked.board.value.toLowerCase(Locale.ENGLISH).contains(query) ||
description.toLowerCase(Locale.ENGLISH).contains(query)) {
displayList.add(boardChecked);
}
}
} else {
displayList.addAll(sourceList);
}
notifyDataSetChanged();
}
}
private class BoardSelectViewHolder extends RecyclerView.ViewHolder implements CompoundButton.OnCheckedChangeListener, OnClickListener {
private CheckBox checkBox;
private TextView text;
private TextView description;
public BoardSelectViewHolder(View itemView) {
super(itemView);
checkBox = (CheckBox) itemView.findViewById(R.id.checkbox);
text = (TextView) itemView.findViewById(R.id.text);
description = (TextView) itemView.findViewById(R.id.description);
checkBox.setOnCheckedChangeListener(this);
itemView.setOnClickListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView == checkBox) {
BoardChecked board = adapter.displayList.get(getAdapterPosition());
board.checked = isChecked;
updateAllSelected();
}
}
@Override
public void onClick(View v) {
checkBox.toggle();
}
}
public static class BoardChecked {
public Board board;
public boolean checked;
public BoardChecked(Board board, boolean checked) {
this.board = board;
this.checked = checked;
}
}
}

@ -1,8 +1,29 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
@ -10,7 +31,9 @@ import android.widget.TextView;
import org.floens.chan.Chan;
import org.floens.chan.R;
import org.floens.chan.core.manager.BoardManager;
import org.floens.chan.core.manager.FilterEngine;
import org.floens.chan.core.model.Board;
import org.floens.chan.core.model.Filter;
import org.floens.chan.ui.drawable.DropdownArrowDrawable;
import org.floens.chan.ui.view.FloatingMenu;
@ -25,11 +48,16 @@ import static org.floens.chan.utils.AndroidUtils.getString;
public class FilterLayout extends LinearLayout implements View.OnClickListener, FloatingMenu.FloatingMenuCallback {
private TextView typeText;
private TextView boards;
private TextView boardsSelector;
private TextView pattern;
private CheckBox enabled;
private CheckBox hide;
private Filter filter;
private BoardManager boardManager;
private Filter filter = new Filter();
private List<Board> appliedBoards = new ArrayList<>();
public FilterLayout(Context context) {
super(context);
@ -47,30 +75,55 @@ public class FilterLayout extends LinearLayout implements View.OnClickListener,
protected void onFinishInflate() {
super.onFinishInflate();
boardManager = Chan.getBoardManager();
typeText = (TextView) findViewById(R.id.type);
boards = (TextView) findViewById(R.id.boards);
boardsSelector = (TextView) findViewById(R.id.boards);
pattern = (TextView) findViewById(R.id.pattern);
enabled = (CheckBox) findViewById(R.id.enabled);
hide = (CheckBox) findViewById(R.id.hide);
typeText.setOnClickListener(this);
typeText.setCompoundDrawablesWithIntrinsicBounds(null, null, new DropdownArrowDrawable(dp(12), dp(12), true,
getAttrColor(getContext(), R.attr.dropdown_dark_color), getAttrColor(getContext(), R.attr.dropdown_dark_pressed_color)), null);
boardsSelector.setOnClickListener(this);
boardsSelector.setCompoundDrawablesWithIntrinsicBounds(null, null, new DropdownArrowDrawable(dp(12), dp(12), true,
getAttrColor(getContext(), R.attr.dropdown_dark_color), getAttrColor(getContext(), R.attr.dropdown_dark_pressed_color)), null);
update();
}
public void setFilter(Filter filter) {
this.filter = filter;
pattern.setText(filter.pattern);
boards.setText(filter.boards);
hide.setChecked(filter.hide);
typeText.setText(filterTypeName(FilterEngine.FilterType.forId(filter.type)));
this.filter.apply(filter);
appliedBoards.clear();
if (filter.allBoards) {
appliedBoards.addAll(boardManager.getSavedBoards());
} else if (!TextUtils.isEmpty(filter.boards)) {
for (String value : filter.boards.split(",")) {
Board boardByValue = boardManager.getBoardByValue(value);
if (boardByValue != null) {
appliedBoards.add(boardByValue);
}
}
}
update();
}
public void save() {
public Filter getFilter() {
filter.pattern = pattern.getText().toString();
filter.boards = boards.getText().toString();
filter.hide = hide.isChecked();
filter.enabled = enabled.isChecked();
filter.boards = "";
for (int i = 0; i < appliedBoards.size(); i++) {
Board board = appliedBoards.get(i);
filter.boards += board.value;
if (i < appliedBoards.size() - 1) {
filter.boards += ",";
}
}
Chan.getDatabaseManager().addFilter(filter);
return filter;
}
@Override
@ -88,20 +141,58 @@ public class FilterLayout extends LinearLayout implements View.OnClickListener,
menu.setCallback(this);
menu.setItems(menuItems);
menu.show();
} else if (v == boardsSelector) {
final BoardSelectLayout boardSelectLayout = (BoardSelectLayout) LayoutInflater.from(getContext()).inflate(R.layout.layout_board_select, null);
boardSelectLayout.setCheckedBoards(appliedBoards);
new AlertDialog.Builder(getContext())
.setView(boardSelectLayout)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setCheckedBoards(boardSelectLayout.getCheckedBoards(), boardSelectLayout.getAllChecked());
update();
}
})
.show();
}
}
@Override
public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) {
FilterEngine.FilterType type = (FilterEngine.FilterType) item.getId();
typeText.setText(filterTypeName(type));
filter.type = type.id;
update();
}
@Override
public void onFloatingMenuDismissed(FloatingMenu menu) {
}
private void update() {
pattern.setText(filter.pattern);
hide.setChecked(filter.hide);
enabled.setChecked(filter.enabled);
typeText.setText(filterTypeName(FilterEngine.FilterType.forId(filter.type)));
String text = getString(R.string.filter_boards) + " (";
if (filter.allBoards) {
text += getString(R.string.filter_boards_all);
} else {
text += String.valueOf(appliedBoards.size());
}
text += ")";
boardsSelector.setText(text);
}
private void setCheckedBoards(List<Board> checkedBoards, boolean allChecked) {
appliedBoards.clear();
appliedBoards.addAll(checkedBoards);
filter.allBoards = allChecked;
}
private String filterTypeName(FilterEngine.FilterType type) {
switch (type) {
case TRIPCODE:

@ -0,0 +1,141 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.floens.chan.R;
import org.floens.chan.utils.AndroidUtils;
import static org.floens.chan.utils.AndroidUtils.dp;
public class SearchLayout extends LinearLayout {
private EditText searchView;
private ImageView clearButton;
public SearchLayout(Context context) {
super(context);
}
public SearchLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SearchLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setCallback(final SearchLayoutCallback callback) {
searchView = new EditText(getContext());
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_DONE);
searchView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
searchView.setHintTextColor(0x88ffffff);
searchView.setTextColor(0xffffffff);
searchView.setSingleLine(true);
searchView.setBackgroundResource(0);
searchView.setPadding(0, 0, 0, 0);
clearButton = new ImageView(getContext());
searchView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
clearButton.setAlpha(s.length() == 0 ? 0.6f : 1.0f);
callback.onSearchEntered(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
searchView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
AndroidUtils.hideKeyboard(searchView);
callback.onSearchEntered(searchView.getText().toString());
return true;
}
return false;
}
});
LinearLayout.LayoutParams searchViewParams = new LinearLayout.LayoutParams(0, dp(36), 1);
searchViewParams.gravity = Gravity.CENTER_VERTICAL;
addView(searchView, searchViewParams);
clearButton.setAlpha(0.6f);
clearButton.setImageResource(R.drawable.ic_clear_white_24dp);
clearButton.setScaleType(ImageView.ScaleType.CENTER);
clearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
searchView.setText("");
AndroidUtils.requestKeyboardFocus(searchView);
}
});
addView(clearButton, dp(48), LayoutParams.MATCH_PARENT);
}
public void setHintColor(int color) {
searchView.setHintTextColor(color);
}
public void setTextColor(int color) {
searchView.setTextColor(color);
}
public void setClearButtonImage(int image) {
clearButton.setImageResource(image);
}
public void setText(String text) {
searchView.setText(text);
}
public void setHint(String hint) {
searchView.setHint(hint);
}
public void openKeyboard() {
searchView.postDelayed(new Runnable() {
@Override
public void run() {
searchView.requestFocus();
AndroidUtils.requestKeyboardFocus(searchView);
}
}, 100);
}
public interface SearchLayoutCallback {
void onSearchEntered(String entered);
}
}

@ -26,19 +26,13 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -47,6 +41,7 @@ import android.widget.TextView;
import org.floens.chan.R;
import org.floens.chan.ui.drawable.ArrowMenuDrawable;
import org.floens.chan.ui.drawable.DropdownArrowDrawable;
import org.floens.chan.ui.layout.SearchLayout;
import org.floens.chan.ui.view.LoadView;
import org.floens.chan.utils.AndroidUtils;
@ -286,76 +281,30 @@ public class Toolbar extends LinearLayout implements View.OnClickListener, LoadV
private LinearLayout createNavigationItemView(final NavigationItem item) {
if (item.search) {
LinearLayout searchViewWrapper = new LinearLayout(getContext());
final EditText searchView = new EditText(getContext());
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_DONE);
searchView.setHint(callback.getSearchHint());
if (item.searchText != null) {
searchView.setText(item.searchText);
}
searchView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
searchView.setHintTextColor(0x88ffffff);
searchView.setTextColor(0xffffffff);
searchView.setSingleLine(true);
searchView.setBackgroundResource(0);
searchView.setPadding(0, 0, 0, 0);
final ImageView clearButton = new ImageView(getContext());
searchView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
item.searchText = s.toString();
callback.onSearchEntered(s.toString());
clearButton.setAlpha(s.length() == 0 ? 0.6f : 1.0f);
}
SearchLayout searchLayout = new SearchLayout(getContext());
searchLayout.setCallback(new SearchLayout.SearchLayoutCallback() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
searchView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
AndroidUtils.hideKeyboard(searchView);
callback.onSearchEntered(searchView.getText().toString());
return true;
}
return false;
}
});
LinearLayout.LayoutParams searchViewParams = new LinearLayout.LayoutParams(0, dp(36), 1);
searchViewParams.gravity = Gravity.CENTER_VERTICAL;
searchViewWrapper.addView(searchView, searchViewParams);
clearButton.setImageResource(R.drawable.ic_clear_white_24dp);
clearButton.setAlpha(searchView.length() == 0 ? 0.6f : 1.0f);
clearButton.setScaleType(ImageView.ScaleType.CENTER);
clearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
searchView.setText("");
AndroidUtils.requestKeyboardFocus(searchView);
public void onSearchEntered(String entered) {
item.searchText = entered;
callback.onSearchEntered(entered);
}
});
searchViewWrapper.addView(clearButton, dp(48), LayoutParams.MATCH_PARENT);
searchViewWrapper.setPadding(dp(16), 0, 0, 0);
if (item.searchText != null) {
searchLayout.setText(item.searchText);
}
searchLayout.setHint(callback.getSearchHint());
if (openKeyboardAfterSearchViewCreated) {
openKeyboardAfterSearchViewCreated = false;
searchView.postDelayed(new Runnable() {
@Override
public void run() {
searchView.requestFocus();
AndroidUtils.requestKeyboardFocus(searchView);
}
}, 100);
searchLayout.openKeyboard();
}
return searchViewWrapper;
searchLayout.setPadding(dp(16), searchLayout.getPaddingTop(), searchLayout.getPaddingRight(), searchLayout.getPaddingBottom());
return searchLayout;
} else {
@SuppressLint("InflateParams")
LinearLayout menu = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.toolbar_menu, null);

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="8dp">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingTop="8dp"
android:singleLine="true"
android:textColor="?text_color_primary"
android:textSize="14sp" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingBottom="8dp"
android:textColor="?text_color_secondary"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-->
<org.floens.chan.ui.layout.BoardSelectLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<org.floens.chan.ui.layout.SearchLayout
android:id="@+id/search_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="8dp"
android:paddingTop="8dp" />
<Button
android:id="@+id/select_all"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" />
</org.floens.chan.ui.layout.BoardSelectLayout>

@ -1,4 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-->
<org.floens.chan.ui.layout.FilterLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -19,22 +35,33 @@
android:paddingLeft="4dp"
android:paddingTop="4dp" />
<EditText
<TextView
android:id="@+id/boards"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_weight="1"
android:hint="@string/filter_boards"
android:textSize="14sp" />
android:drawablePadding="8dp" />
</LinearLayout>
<CheckBox
android:id="@+id/hide"
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter_hide" />
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter_enabled" />
<CheckBox
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter_hide" />
</LinearLayout>
<EditText
android:id="@+id/pattern"
@ -43,4 +70,4 @@
android:hint="@string/filter_pattern"
android:textSize="14sp" />
</org.floens.chan.ui.layout.FilterLayout>
</org.floens.chan.ui.layout.FilterLayout>

@ -120,6 +120,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="filter_enabled">Enabled</string>
<string name="filter_pattern">Pattern</string>
<string name="filter_boards">Boards</string>
<string name="filter_boards_all">all</string>
<string name="filter_hide">Hide</string>
<string name="filter_tripcode">Tripcode</string>
@ -129,6 +130,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="filter_subject">Subject</string>
<string name="filter_filename">Filename</string>
<string name="board_select_all">Select all</string>
<string name="board_select_none">Select none</string>
<string name="history_clear">Clear history</string>
<string name="history_clear_confirm">Clear history?</string>
<string name="history_clear_confirm_button">Clear</string>

Loading…
Cancel
Save