|
|
@ -22,7 +22,6 @@ import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.res.TypedArray; |
|
|
|
import android.content.res.TypedArray; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
import android.util.AttributeSet; |
|
|
|
import android.util.AttributeSet; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
@ -35,6 +34,7 @@ import android.widget.ImageView; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.ListView; |
|
|
|
import android.widget.ListView; |
|
|
|
import android.widget.RelativeLayout; |
|
|
|
import android.widget.RelativeLayout; |
|
|
|
|
|
|
|
import android.widget.SearchView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
import com.android.volley.NetworkError; |
|
|
|
import com.android.volley.NetworkError; |
|
|
@ -52,6 +52,7 @@ import org.floens.chan.ui.activity.BaseActivity; |
|
|
|
import org.floens.chan.ui.activity.ImageViewActivity; |
|
|
|
import org.floens.chan.ui.activity.ImageViewActivity; |
|
|
|
import org.floens.chan.ui.adapter.PostAdapter; |
|
|
|
import org.floens.chan.ui.adapter.PostAdapter; |
|
|
|
import org.floens.chan.ui.view.LoadView; |
|
|
|
import org.floens.chan.ui.view.LoadView; |
|
|
|
|
|
|
|
import org.floens.chan.utils.ThemeHelper; |
|
|
|
import org.floens.chan.utils.Utils; |
|
|
|
import org.floens.chan.utils.Utils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -70,7 +71,6 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
private SkipLogic skipLogic; |
|
|
|
private SkipLogic skipLogic; |
|
|
|
private int highlightedPost = -1; |
|
|
|
private int highlightedPost = -1; |
|
|
|
private ThreadManager.ViewMode viewMode = ThreadManager.ViewMode.LIST; |
|
|
|
private ThreadManager.ViewMode viewMode = ThreadManager.ViewMode.LIST; |
|
|
|
private String lastFilter = ""; |
|
|
|
|
|
|
|
private boolean isFiltering = false; |
|
|
|
private boolean isFiltering = false; |
|
|
|
|
|
|
|
|
|
|
|
public static ThreadFragment newInstance(BaseActivity activity) { |
|
|
|
public static ThreadFragment newInstance(BaseActivity activity) { |
|
|
@ -120,10 +120,11 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
return threadManager.getLoader(); |
|
|
|
return threadManager.getLoader(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setFilter(String filter) { |
|
|
|
public void startFiltering() { |
|
|
|
if (!filter.equals(lastFilter) && postAdapter != null) { |
|
|
|
if (filterView != null) { |
|
|
|
lastFilter = filter; |
|
|
|
isFiltering = true; |
|
|
|
postAdapter.setFilter(filter); |
|
|
|
filterView.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
filterView.focusSearch(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -166,8 +167,8 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
public void onPostClicked(Post post) { |
|
|
|
public void onPostClicked(Post post) { |
|
|
|
if (loadable.isBoardMode() || loadable.isCatalogMode()) { |
|
|
|
if (loadable.isBoardMode() || loadable.isCatalogMode()) { |
|
|
|
baseActivity.onOPClicked(post); |
|
|
|
baseActivity.onOPClicked(post); |
|
|
|
} else if (loadable.isThreadMode() && !TextUtils.isEmpty(lastFilter)) { |
|
|
|
} else if (loadable.isThreadMode() && isFiltering) { |
|
|
|
baseActivity.onSetFilter(""); |
|
|
|
filterView.clearSearch(); |
|
|
|
postAdapter.scrollToPost(post.no); |
|
|
|
postAdapter.scrollToPost(post.no); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -211,6 +212,54 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onThreadLoaded(List posts, boolean append) { |
|
|
|
public void onThreadLoaded(List posts, boolean append) { |
|
|
|
if (postAdapter == null) { |
|
|
|
if (postAdapter == null) { |
|
|
|
|
|
|
|
if (container != null) { |
|
|
|
|
|
|
|
container.setView(createView()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postAdapter.setStatusMessage(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (append) { |
|
|
|
|
|
|
|
postAdapter.appendList(posts); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
postAdapter.setList(posts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (highlightedPost >= 0) { |
|
|
|
|
|
|
|
threadManager.highlightPost(highlightedPost); |
|
|
|
|
|
|
|
postAdapter.scrollToPost(highlightedPost); |
|
|
|
|
|
|
|
highlightedPost = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseActivity.onThreadLoaded(loadable, posts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onThreadLoadError(VolleyError error) { |
|
|
|
|
|
|
|
if (error instanceof EndOfLineException) { |
|
|
|
|
|
|
|
postAdapter.setEndOfLine(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (postAdapter == null) { |
|
|
|
|
|
|
|
if (container != null) { |
|
|
|
|
|
|
|
container.setView(getLoadErrorTextView(error)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
postAdapter.setStatusMessage(getLoadErrorText(error)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
highlightedPost = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onFilterResults(String filter, int count, boolean all) { |
|
|
|
|
|
|
|
isFiltering = !all; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filterView != null) { |
|
|
|
|
|
|
|
filterView.setText(filter, count, all); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RelativeLayout createView() { |
|
|
|
RelativeLayout compound = new RelativeLayout(baseActivity); |
|
|
|
RelativeLayout compound = new RelativeLayout(baseActivity); |
|
|
|
|
|
|
|
|
|
|
|
LinearLayout listViewContainer = new LinearLayout(baseActivity); |
|
|
|
LinearLayout listViewContainer = new LinearLayout(baseActivity); |
|
|
@ -290,56 +339,7 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
skipLogic = new SkipLogic(skip, listView); |
|
|
|
skipLogic = new SkipLogic(skip, listView); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (container != null) { |
|
|
|
return compound; |
|
|
|
container.setView(compound); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postAdapter.setStatusMessage(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (append) { |
|
|
|
|
|
|
|
postAdapter.appendList(posts); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
postAdapter.setList(posts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (highlightedPost >= 0) { |
|
|
|
|
|
|
|
threadManager.highlightPost(highlightedPost); |
|
|
|
|
|
|
|
postAdapter.scrollToPost(highlightedPost); |
|
|
|
|
|
|
|
highlightedPost = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseActivity.onThreadLoaded(loadable, posts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onThreadLoadError(VolleyError error) { |
|
|
|
|
|
|
|
if (error instanceof EndOfLineException) { |
|
|
|
|
|
|
|
postAdapter.setEndOfLine(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (postAdapter == null) { |
|
|
|
|
|
|
|
if (container != null) { |
|
|
|
|
|
|
|
container.setView(getLoadErrorTextView(error)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
postAdapter.setStatusMessage(getLoadErrorText(error)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
highlightedPost = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onFilterResults(String filter, int count, boolean all) { |
|
|
|
|
|
|
|
isFiltering = !all; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filterView != null) { |
|
|
|
|
|
|
|
if (all) { |
|
|
|
|
|
|
|
filterView.setVisibility(View.GONE); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
filterView.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
filterView.setText(filter, count); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setEmpty() { |
|
|
|
private void setEmpty() { |
|
|
@ -356,6 +356,13 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
|
|
|
|
|
|
|
|
skip = null; |
|
|
|
skip = null; |
|
|
|
skipLogic = null; |
|
|
|
skipLogic = null; |
|
|
|
|
|
|
|
filterView = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doFilter(String filter) { |
|
|
|
|
|
|
|
if (postAdapter != null) { |
|
|
|
|
|
|
|
postAdapter.setFilter(filter); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -452,6 +459,7 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class FilterView extends LinearLayout { |
|
|
|
public class FilterView extends LinearLayout { |
|
|
|
|
|
|
|
private SearchView searchView; |
|
|
|
private TextView textView; |
|
|
|
private TextView textView; |
|
|
|
|
|
|
|
|
|
|
|
public FilterView(Context activity) { |
|
|
|
public FilterView(Context activity) { |
|
|
@ -469,16 +477,79 @@ public class ThreadFragment extends Fragment implements ThreadManager.ThreadMana |
|
|
|
init(); |
|
|
|
init(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void focusSearch() { |
|
|
|
|
|
|
|
searchView.requestFocus(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void clearSearch() { |
|
|
|
|
|
|
|
searchView.setQuery("", false); |
|
|
|
|
|
|
|
doFilter(""); |
|
|
|
|
|
|
|
setVisibility(View.GONE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void init() { |
|
|
|
private void init() { |
|
|
|
|
|
|
|
setOrientation(LinearLayout.VERTICAL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LinearLayout searchViewContainer = new LinearLayout(getContext()); |
|
|
|
|
|
|
|
searchViewContainer.setOrientation(LinearLayout.HORIZONTAL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchView = new SearchView(getContext()); |
|
|
|
|
|
|
|
searchView.setIconifiedByDefault(false); |
|
|
|
|
|
|
|
searchViewContainer.addView(searchView); |
|
|
|
|
|
|
|
LinearLayout.LayoutParams searchViewParams = (LinearLayout.LayoutParams) searchView.getLayoutParams(); |
|
|
|
|
|
|
|
searchViewParams.weight = 1f; |
|
|
|
|
|
|
|
searchViewParams.width = 0; |
|
|
|
|
|
|
|
searchViewParams.height = LayoutParams.MATCH_PARENT; |
|
|
|
|
|
|
|
searchView.setLayoutParams(searchViewParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImageView closeButton = new ImageView(getContext()); |
|
|
|
|
|
|
|
searchViewContainer.addView(closeButton); |
|
|
|
|
|
|
|
closeButton.setImageResource(ThemeHelper.getInstance().getTheme().isLightTheme ? R.drawable.ic_action_cancel : R.drawable.ic_action_cancel_dark); |
|
|
|
|
|
|
|
LinearLayout.LayoutParams closeButtonParams = (LinearLayout.LayoutParams) closeButton.getLayoutParams(); |
|
|
|
|
|
|
|
searchViewParams.width = Utils.dp(48); |
|
|
|
|
|
|
|
searchViewParams.height = LayoutParams.MATCH_PARENT; |
|
|
|
|
|
|
|
closeButton.setLayoutParams(closeButtonParams); |
|
|
|
|
|
|
|
Utils.setPressedDrawable(closeButton); |
|
|
|
|
|
|
|
int padding = Utils.dp(8); |
|
|
|
|
|
|
|
closeButton.setPadding(padding, padding, padding, padding); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closeButton.setOnClickListener(new OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
clearSearch(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addView(searchViewContainer, new LayoutParams(LayoutParams.MATCH_PARENT, Utils.dp(48))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchView.setQueryHint(getString(R.string.search_hint)); |
|
|
|
|
|
|
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onQueryTextSubmit(String query) { |
|
|
|
|
|
|
|
doFilter(query); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onQueryTextChange(String newText) { |
|
|
|
|
|
|
|
doFilter(newText); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
textView = new TextView(getContext()); |
|
|
|
textView = new TextView(getContext()); |
|
|
|
textView.setGravity(Gravity.CENTER); |
|
|
|
textView.setGravity(Gravity.CENTER); |
|
|
|
addView(textView, new LayoutParams(LayoutParams.MATCH_PARENT, Utils.dp(48))); |
|
|
|
addView(textView, new LayoutParams(LayoutParams.MATCH_PARENT, Utils.dp(48))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setText(String filter, int count) { |
|
|
|
private void setText(String filter, int count, boolean all) { |
|
|
|
|
|
|
|
if (all) { |
|
|
|
|
|
|
|
textView.setText(""); |
|
|
|
|
|
|
|
} else { |
|
|
|
String posts = getContext().getString(count == 1 ? R.string.one_post : R.string.multiple_posts); |
|
|
|
String posts = getContext().getString(count == 1 ? R.string.one_post : R.string.multiple_posts); |
|
|
|
String text = getContext().getString(R.string.search_results, Integer.toString(count), posts, filter); |
|
|
|
String text = getContext().getString(R.string.search_results, Integer.toString(count), posts, filter); |
|
|
|
textView.setText(text); |
|
|
|
textView.setText(text); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|