Improve search
This commit is contained in:
1 parent
903373a625
commit
16e4a41fbe
5 files changed
+95
-14
No files matched your search
@@ -19,12 +19,12 @@ import com.hippo.util.Messenger;
|
||||
|
||||
public final class Constants {
|
||||
|
||||
public static final int MESSENGER_ID_SOURCE;
|
||||
public static final int MESSENGER_ID_EH_SOURCE;
|
||||
public static final int MESSENGER_ID_SHOW_APP_STATUS;
|
||||
|
||||
static {
|
||||
Messenger messenger = Messenger.getInstance();
|
||||
MESSENGER_ID_SOURCE = messenger.newId();
|
||||
MESSENGER_ID_EH_SOURCE = messenger.newId();
|
||||
MESSENGER_ID_SHOW_APP_STATUS = messenger.newId();
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.data.UnsupportedSearchException;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.widget.ContentLayout;
|
||||
import com.hippo.ehviewer.widget.OffsetLayout;
|
||||
@@ -64,7 +65,6 @@ import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.util.AnimationUtils;
|
||||
import com.hippo.util.AppHandler;
|
||||
import com.hippo.util.AssertUtils;
|
||||
import com.hippo.util.Log;
|
||||
import com.hippo.util.MathUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.FabLayout;
|
||||
@@ -440,15 +440,33 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
|
||||
@Override
|
||||
public void onApplySearch(String query) {
|
||||
// TODO Query may be "", should not do search if it is
|
||||
Log.d("onApplySearch " + query);
|
||||
// TODO check is source and search vaild
|
||||
if (TextUtils.isEmpty(query) && (mViewTransition.getShownViewIndex() == 0
|
||||
|| mSearchLayout.isSpecifyTag())) {
|
||||
// Invaild search
|
||||
return;
|
||||
}
|
||||
|
||||
mSearchDatabase.addQuery(query);
|
||||
|
||||
if (mViewTransition.getShownViewIndex() == 0) {
|
||||
mListUrlBuilder.reset();
|
||||
mListUrlBuilder.setKeyword(query);
|
||||
} else {
|
||||
mSearchLayout.formatListUrlBuilder(mListUrlBuilder);
|
||||
if (mSearchLayout.isSpecifyTAuthor()) {
|
||||
query = "uploader:" + query;
|
||||
}
|
||||
mListUrlBuilder.setKeyword(query);
|
||||
}
|
||||
|
||||
mState = STATE_NORMAL;
|
||||
mViewTransition.showView(0);
|
||||
mSearchBar.setState(SearchBar.STATE_NORMAL);
|
||||
returnSearchBarPosition();
|
||||
setFabState(FAB_STATE_NORMAL);
|
||||
|
||||
mGalleryListHelper.refresh();
|
||||
}
|
||||
|
||||
private RecyclerView getVaildRecyclerView() {
|
||||
@@ -668,12 +686,12 @@ public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
@Override
|
||||
protected void getPageData(int taskId, int type, int page) {
|
||||
try {
|
||||
int source = Config.getEhSource();
|
||||
mListUrlBuilder.setPageIndex(page);
|
||||
String url = mListUrlBuilder.build(EhClient.SOURCE_LOFI);
|
||||
String url = mListUrlBuilder.build(source);
|
||||
GalleryListListener listener = new GalleryListListener(taskId, type,
|
||||
page, EhClient.SOURCE_LOFI);
|
||||
EhClient.getInstance().getGalleryList(EhClient.SOURCE_LOFI,
|
||||
url, listener);
|
||||
page, source);
|
||||
EhClient.getInstance().getGalleryList(source, url, listener);
|
||||
} catch (UnsupportedSearchException e) {
|
||||
onGetPageData(taskId, e);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.hippo.ehviewer.BuildConfig;
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.util.Messenger;
|
||||
|
||||
public final class Config {
|
||||
|
||||
@@ -72,6 +75,28 @@ public final class Config {
|
||||
sConfigPre.edit().putString(key, value).apply();
|
||||
}
|
||||
|
||||
/****** ******/
|
||||
|
||||
private static final String KEY_EH_SOURCE = "eh_source";
|
||||
private static final int DEFAULT_EH_SOURCE = BuildConfig.DEBUG ?
|
||||
EhClient.SOURCE_LOFI : EhClient.SOURCE_G;
|
||||
|
||||
public static int getEhSource() {
|
||||
int value = getInt(KEY_EH_SOURCE, DEFAULT_EH_SOURCE);
|
||||
if (value < EhClient.SOURCE_G || value > EhClient.SOURCE_LOFI) {
|
||||
value = DEFAULT_EH_SOURCE;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void putEhSource(int value) {
|
||||
if (value < EhClient.SOURCE_G || value > EhClient.SOURCE_LOFI) {
|
||||
value = DEFAULT_EH_SOURCE;
|
||||
}
|
||||
putInt(KEY_EH_SOURCE, value);
|
||||
Messenger.getInstance().notify(Constants.MESSENGER_ID_EH_SOURCE, value);
|
||||
}
|
||||
|
||||
/****** Advance ******/
|
||||
|
||||
private static final String KEY_SHOW_APPLICATION_STATS = "show_application_stats";
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
@@ -51,6 +52,7 @@ import com.hippo.effect.ViewTransition;
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.util.MathUtils;
|
||||
import com.hippo.util.Messenger;
|
||||
import com.hippo.util.UiUtils;
|
||||
@@ -152,25 +154,33 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
mBaseHeight = getMeasuredHeight();
|
||||
|
||||
mSuggestionList = new ArrayList<>();
|
||||
// TODO
|
||||
// TODO Use custom view
|
||||
mSuggestionAdapter = new ArrayAdapter<>(getContext(),
|
||||
android.R.layout.simple_list_item_1, mSuggestionList);
|
||||
mList.setAdapter(mSuggestionAdapter);
|
||||
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String suggestion = mSuggestionList.get(position);
|
||||
mEditText.setText(suggestion);
|
||||
mEditText.setSelection(suggestion.length());
|
||||
}
|
||||
});
|
||||
|
||||
// TODO get source from config
|
||||
setSource(EhClient.SOURCE_EX);
|
||||
setSource(Config.getEhSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_SOURCE, this);
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_EH_SOURCE, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_SOURCE, this);
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_EH_SOURCE, this);
|
||||
}
|
||||
|
||||
private void updateSuggestions() {
|
||||
@@ -414,7 +424,7 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
|
||||
@Override
|
||||
public void onReceive(int id, Object obj) {
|
||||
if (id == Constants.MESSENGER_ID_SOURCE) {
|
||||
if (id == Constants.MESSENGER_ID_EH_SOURCE) {
|
||||
if (obj instanceof Integer) {
|
||||
int source = (Integer) obj;
|
||||
setSource(source);
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.hippo.effect.ripple.RippleSalon;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
@@ -181,6 +182,33 @@ public class SearchLayout extends MonoRecyclerView implements CompoundButton.OnC
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
public boolean isSpecifyTag() {
|
||||
return mCheckSpecifyTag.isChecked();
|
||||
}
|
||||
|
||||
public boolean isSpecifyTAuthor() {
|
||||
return mCheckSpecifyTag.isChecked();
|
||||
}
|
||||
|
||||
// TODO image search
|
||||
public void formatListUrlBuilder(ListUrlBuilder listUrlBuilder) {
|
||||
listUrlBuilder.reset();
|
||||
if (mCheckSpecifyTag.isChecked()) {
|
||||
listUrlBuilder.setMode(ListUrlBuilder.MODE_TAG);
|
||||
} else {
|
||||
if (mCheckSpecifyAuthor.isChecked()) {
|
||||
listUrlBuilder.setMode(ListUrlBuilder.MODE_UPLOADER);
|
||||
} else {
|
||||
listUrlBuilder.setMode(ListUrlBuilder.MODE_NORMAL);
|
||||
}
|
||||
listUrlBuilder.setCategory(mTableCategory.getCategory());
|
||||
if (mEnableAdvance) {
|
||||
listUrlBuilder.setAdvanceSearch(mTableAdvanceSearch.getAdvanceSearch());
|
||||
listUrlBuilder.setMinRating(mTableAdvanceSearch.getMinRating());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollSearchContainerToTop() {
|
||||
mLayoutManager.scrollToPositionWithOffset(0, 0);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user