Update
This commit is contained in:
1 parent
4ca95f0b7c
commit
523ff94f71
33 files changed
+962
-114
No files matched your search
@@ -28,6 +28,7 @@ public final class Constants {
|
||||
public static final int MESSENGER_ID_JPN_TITLE;
|
||||
public static final int MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION;
|
||||
public static final int MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION;
|
||||
public static final int MESSENGER_ID_UPDATE_QUICK_SEARCH;
|
||||
|
||||
static {
|
||||
Messenger messenger = Messenger.getInstance();
|
||||
@@ -39,5 +40,6 @@ public final class Constants {
|
||||
MESSENGER_ID_JPN_TITLE = messenger.newId();
|
||||
MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION = messenger.newId();
|
||||
MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION = messenger.newId();
|
||||
MESSENGER_ID_UPDATE_QUICK_SEARCH = messenger.newId();
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,15 @@ public class ListUrlBuilder {
|
||||
mMinRating = glub.mMinRating;
|
||||
}
|
||||
|
||||
public void set(QuickSearch quickSearch) {
|
||||
mMode = quickSearch.mode;
|
||||
mPageIndex = 0;
|
||||
mCategory = quickSearch.category;
|
||||
mKeyword = quickSearch.keyword;
|
||||
mAdvanceSearch = quickSearch.advancedSearch;
|
||||
mMinRating = quickSearch.minRating;
|
||||
}
|
||||
|
||||
public String build(int source) throws UnsupportedSearchException {
|
||||
switch (mMode) {
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.client.data;
|
||||
|
||||
import com.hippo.ehviewer.dao.QuickSearchObj;
|
||||
|
||||
public class QuickSearch {
|
||||
|
||||
public long id;
|
||||
public String name;
|
||||
public int mode;
|
||||
public int category;
|
||||
public String keyword;
|
||||
public int advancedSearch;
|
||||
public int minRating;
|
||||
|
||||
public static QuickSearch fromQuickSearchObj(QuickSearchObj quickSearchObj) {
|
||||
QuickSearch quickSearch = new QuickSearch();
|
||||
quickSearch.id = quickSearchObj.getId();
|
||||
quickSearch.name = quickSearchObj.getName();
|
||||
quickSearch.mode = quickSearchObj.getMode();
|
||||
quickSearch.category = quickSearchObj.getCategory();
|
||||
quickSearch.keyword = quickSearchObj.getKeyword();
|
||||
quickSearch.advancedSearch = quickSearchObj.getAdvancedSearch();
|
||||
quickSearch.minRating = quickSearchObj.getMinRating();
|
||||
return quickSearch;
|
||||
}
|
||||
}
|
||||
@@ -28,14 +28,17 @@ import android.widget.AdapterView;
|
||||
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.scene.DrawerProvider;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
import com.hippo.ehviewer.ui.scene.MainSettingsScene;
|
||||
import com.hippo.ehviewer.ui.scene.SignInScene;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.ehviewer.widget.DrawerLeftPanel;
|
||||
import com.hippo.ehviewer.widget.DrawerRightPanel;
|
||||
import com.hippo.ehviewer.widget.FitStageLayout;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.OffsetCurtain;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.SceneManager;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.scene.StageLayout;
|
||||
@@ -61,6 +64,7 @@ public final class ContentActivity extends StageActivity
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private FitStageLayout mFitStageLayout;
|
||||
private DrawerLeftPanel mDrawerLeftPanel;
|
||||
private DrawerRightPanel mDrawerRightPanel;
|
||||
private DrawerListView mDrawerListView;
|
||||
|
||||
private AdapterView.OnItemClickListener mDrawerListListener = new AdapterView.OnItemClickListener() {
|
||||
@@ -98,33 +102,65 @@ public final class ContentActivity extends StageActivity
|
||||
|
||||
private SceneManager.SceneStateListener mSceneStateListener = new SceneManager.SceneStateListener() {
|
||||
@Override
|
||||
public void onCreate(Class clazz) {
|
||||
if (clazz.equals(GalleryListScene.class)) {
|
||||
unlockDrawer();
|
||||
public void onInit(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRebirth(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Scene scene) {
|
||||
if (scene instanceof DrawerProvider) {
|
||||
DrawerProvider drawerProvider = (DrawerProvider) scene;
|
||||
mDrawerLayout.setDrawerLockMode(drawerProvider.showLeftDrawer() ?
|
||||
DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
|
||||
drawerProvider.bindRightDrawer(ContentActivity.this);
|
||||
} else {
|
||||
lockDrawer();
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
|
||||
clearRightDrawerView();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(Class clazz) {
|
||||
public void onBind(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(Class clazz) {
|
||||
public void onRestore(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(Class clazz) {
|
||||
if (clazz.equals(GalleryListScene.class)) {
|
||||
unlockDrawer();
|
||||
public void onDestroy(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDie(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(Scene scene) {
|
||||
if (scene instanceof DrawerProvider) {
|
||||
DrawerProvider drawerProvider = (DrawerProvider) scene;
|
||||
mDrawerLayout.setDrawerLockMode(drawerProvider.showLeftDrawer() ?
|
||||
DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
|
||||
drawerProvider.bindRightDrawer(ContentActivity.this);
|
||||
} else {
|
||||
lockDrawer();
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
|
||||
clearRightDrawerView();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRebirth(Class clazz) {
|
||||
public void onOpen(Scene scene) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Scene scene) {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -142,11 +178,13 @@ public final class ContentActivity extends StageActivity
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
mFitStageLayout = (FitStageLayout) mDrawerLayout.getChildAt(0);
|
||||
mDrawerLeftPanel = (DrawerLeftPanel) mDrawerLayout.getChildAt(1);
|
||||
mDrawerRightPanel = (DrawerRightPanel) mDrawerLayout.getChildAt(2);
|
||||
mDrawerListView = mDrawerLeftPanel.getDrawerListView();
|
||||
|
||||
mFitStageLayout.setOnFitPaddingBottomListener(this);
|
||||
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
|
||||
|
||||
mDrawerLeftPanel.setHelper(this);
|
||||
|
||||
@@ -188,6 +226,16 @@ public final class ContentActivity extends StageActivity
|
||||
return mFitStageLayout;
|
||||
}
|
||||
|
||||
public void setRightDrawerView(View view) {
|
||||
mDrawerRightPanel.setData(view);
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
|
||||
}
|
||||
|
||||
public void clearRightDrawerView() {
|
||||
mDrawerRightPanel.clearData();
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(VectorContext.wrapContext(newBase));
|
||||
@@ -216,12 +264,8 @@ public final class ContentActivity extends StageActivity
|
||||
}
|
||||
}
|
||||
|
||||
public void lockDrawer() {
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||
}
|
||||
|
||||
public void unlockDrawer() {
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||
public void closeDrawers() {
|
||||
mDrawerLayout.closeDrawers();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -23,9 +24,11 @@ import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
import android.util.SparseArray;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.hippo.app.StatsActivity;
|
||||
import com.hippo.conaco.BitmapPool;
|
||||
@@ -50,6 +53,7 @@ import com.hippo.ehviewer.gallery.ui.GalleryPanel;
|
||||
import com.hippo.ehviewer.gallery.ui.GalleryView;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.vectorold.content.VectorContext;
|
||||
import com.hippo.yorozuya.PriorityThreadFactory;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
@@ -284,6 +288,43 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (Settings.getVolumePage()) {
|
||||
mGalleryView.scrollToPrevious();
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (Settings.getVolumePage()) {
|
||||
mGalleryView.scrollToNext();
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
case KeyEvent.KEYCODE_PAGE_UP:
|
||||
mGalleryView.scrollToPrevious();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_PAGE_DOWN:
|
||||
mGalleryView.scrollToNext();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
mGalleryView.scrollToLeft();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
mGalleryView.scrollToRight();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_SPACE:
|
||||
case KeyEvent.KEYCODE_MENU:
|
||||
mGalleryPanel.setShown(!mGalleryPanel.isShown(), true);
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mGalleryPanel.isShown()) {
|
||||
@@ -293,6 +334,11 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(VectorContext.wrapContext(newBase));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFreeBitmap(TiledTexture tiledTexture, Bitmap bitmap) {
|
||||
if (tiledTexture instanceof GifTexture) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import com.hippo.scene.Scene;
|
||||
|
||||
public class DownloadScene extends Scene {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
|
||||
public interface DrawerProvider {
|
||||
|
||||
boolean showLeftDrawer();
|
||||
|
||||
void bindRightDrawer(ContentActivity activity);
|
||||
}
|
||||
@@ -169,8 +169,6 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
|
||||
mEhConfig = EhApplication.getEhHttpClient(getStageActivity()).getEhConfigClone();
|
||||
mSource = Settings.getEhSource();
|
||||
|
||||
((ContentActivity) getStageActivity()).setDrawerListActivatedPosition(ContentActivity.DRAWER_LIST_NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,6 +176,8 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
super.onCreate(rebirth);
|
||||
setContentView(R.layout.scene_gallery_detail);
|
||||
|
||||
((ContentActivity) getStageActivity()).setDrawerListActivatedPosition(ContentActivity.DRAWER_LIST_NONE);
|
||||
|
||||
ViewGroup main = (ViewGroup) findViewById(R.id.main);
|
||||
mRecyclerView = (RecyclerView) main.getChildAt(0);
|
||||
mMainProgressView = main.getChildAt(1);
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -33,6 +34,7 @@ import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -51,45 +53,51 @@ import com.hippo.ehviewer.client.GalleryListParser;
|
||||
import com.hippo.ehviewer.client.PopularParser;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.data.QuickSearch;
|
||||
import com.hippo.ehviewer.client.data.UnsupportedSearchException;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.util.DBUtils;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.ehviewer.widget.ContentLayout;
|
||||
import com.hippo.ehviewer.widget.ListSearchBar;
|
||||
import com.hippo.ehviewer.widget.LoadImageView;
|
||||
import com.hippo.ehviewer.widget.OffsetLayout;
|
||||
import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.ehviewer.widget.SearchDatabase;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.Curtain;
|
||||
import com.hippo.scene.ElementsSharedCurtain;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.scene.ElementsSharedCurtain;
|
||||
import com.hippo.util.AnimationUtils;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.FloatingActionButton;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
import com.hippo.widget.recyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO remeber the data in ContentHelper after screen dirction change
|
||||
// TODO Must refresh when change source
|
||||
// TODO disable click action when animating
|
||||
// TODO Dim when expand search list
|
||||
public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
public final class GalleryListScene extends Scene implements ListSearchBar.Helper,
|
||||
View.OnClickListener, FabLayout.OnCancelListener,
|
||||
SearchLayout.SearhLayoutHelper, EasyRecyclerView.OnItemClickListener,
|
||||
Messenger.Receiver {
|
||||
Messenger.Receiver, DrawerProvider {
|
||||
|
||||
public static final String KEY_MODE = "mode";
|
||||
|
||||
private static final String KEY_STATE = "state";
|
||||
|
||||
public static final int MODE_HOMEPAGE = 0;
|
||||
public static final int MODE_POPULAR = 1;
|
||||
|
||||
@@ -112,7 +120,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
private Resources mResources;
|
||||
private SearchDatabase mSearchDatabase;
|
||||
|
||||
private SearchBar mSearchBar;
|
||||
private ListSearchBar mSearchBar;
|
||||
private ContentLayout mContentLayout;
|
||||
private EasyRecyclerView mContentRecyclerView;
|
||||
private SearchLayout mSearchLayout;
|
||||
@@ -142,6 +150,12 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
|
||||
private boolean mJpnTitle;
|
||||
|
||||
|
||||
private FrameLayout mRightDrawerView;
|
||||
private EasyRecyclerView mQuickSearchView;
|
||||
private QuickSearchAdapter mQuickSearchAdapter;
|
||||
private List<QuickSearch> mQuickSearches;
|
||||
|
||||
private SimpleDialog.OnCreateCustomViewListener mGoToCreateCustomViewListener =
|
||||
new SimpleDialog.OnCreateCustomViewListener() {
|
||||
@Override
|
||||
@@ -261,7 +275,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
mResources = mActivity.getResources();
|
||||
mSearchDatabase = SearchDatabase.getInstance(getStageActivity());
|
||||
|
||||
mSearchBar = (SearchBar) findViewById(R.id.search_bar);
|
||||
mSearchBar = (ListSearchBar) findViewById(R.id.search_bar);
|
||||
mContentLayout = (ContentLayout) findViewById(R.id.content_layout);
|
||||
mContentRecyclerView = mContentLayout.getRecyclerView();
|
||||
mSearchLayout = (SearchLayout) findViewById(R.id.search_layout);
|
||||
@@ -318,16 +332,45 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
mSearchDrawable = mResources.getDrawable(R.drawable.ic_search_dark);
|
||||
mCornerFab.setDrawable(mAddDeleteDrawable);
|
||||
|
||||
//
|
||||
mRightDrawerView = (FrameLayout) getStageActivity().getLayoutInflater().inflate(R.layout.drawer_right_gallery_list, null);
|
||||
mQuickSearchView = (EasyRecyclerView) mRightDrawerView.getChildAt(0);
|
||||
mQuickSearches = DBUtils.getAllQuickSearch();
|
||||
mQuickSearchAdapter = new QuickSearchAdapter();
|
||||
mQuickSearchView.setAdapter(mQuickSearchAdapter);
|
||||
mQuickSearchView.setLayoutManager(new LinearLayoutManager(getStageActivity()));
|
||||
mQuickSearchView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mQuickSearchView.setDrawSelectorOnTop(true);
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL,
|
||||
mResources.getColor(R.color.divider_light),
|
||||
LayoutUtils.dp2pix(getStageActivity(), 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
mQuickSearchView.addItemDecoration(decoration);
|
||||
mQuickSearchView.setOnItemClickListener(new QuickSearchClickListener());
|
||||
|
||||
// When scene start
|
||||
if (!rebirth) {
|
||||
handleAnnouncer(getAnnouncer());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestore() {
|
||||
super.onRestore();
|
||||
|
||||
int state = mState;
|
||||
// Reset state for set state
|
||||
mState = STATE_NORMAL;
|
||||
mFabState = FAB_STATE_NORMAL;
|
||||
setState(state, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
mJpnTitle = Settings.getJpnTitle();
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_JPN_TITLE, this);
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_UPDATE_QUICK_SEARCH, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,6 +378,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
super.onDie();
|
||||
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_JPN_TITLE, this);
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_UPDATE_QUICK_SEARCH, this);
|
||||
|
||||
// Avoid memory leak
|
||||
if (mGalleryListHelper.mListener != null) {
|
||||
@@ -359,6 +403,16 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
mFabLayout.setPadding(mFabLayout.getPaddingLeft(), mFabLayout.getPaddingTop(), mFabLayout.getPaddingRight(), mCornerFabOriginalBottom + b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showLeftDrawer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindRightDrawer(ContentActivity activity) {
|
||||
activity.setRightDrawerView(mRightDrawerView);
|
||||
}
|
||||
|
||||
private void setFabState(int fabState, boolean animation) {
|
||||
if (mFabState != fabState) {
|
||||
mFabState = fabState;
|
||||
@@ -588,8 +642,6 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onApplySearch(String query) {
|
||||
// TODO check is source and search vaild
|
||||
@@ -740,6 +792,60 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
}
|
||||
}
|
||||
|
||||
private class AddToQuickSearchHelper implements SimpleDialog.OnCreateCustomViewListener,
|
||||
SimpleDialog.OnClickListener {
|
||||
|
||||
private EditText mEditText;
|
||||
private ListUrlBuilder mBuilder;
|
||||
|
||||
public AddToQuickSearchHelper(ListUrlBuilder builder) {
|
||||
mBuilder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateCustomView(final SimpleDialog dialog, View view) {
|
||||
mEditText = (EditText) view.findViewById(R.id.edit_text);
|
||||
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
|
||||
dialog.pressPositiveButton();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(SimpleDialog dialog, int which) {
|
||||
if (which == SimpleDialog.POSITIVE) {
|
||||
String displayname = mEditText.getText().toString();
|
||||
if (!TextUtils.isEmpty(displayname)) {
|
||||
DBUtils.addQuickSearch(displayname, mBuilder);
|
||||
return true;
|
||||
} else {
|
||||
Toast.makeText(getStageActivity(), "Empty displayname", Toast.LENGTH_SHORT).show(); // TODO
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdd(ListUrlBuilder builder) {
|
||||
// Set keyword from search bar
|
||||
builder.setKeyword(mSearchBar.getText());
|
||||
AddToQuickSearchHelper helper = new AddToQuickSearchHelper(builder);
|
||||
new SimpleDialog.Builder(getStageActivity()).setTitle("Add to quick search")
|
||||
.setCustomView(R.layout.dialog_add_to_quick_search, helper)
|
||||
.setPositiveButton(android.R.string.ok)
|
||||
.setOnButtonClickListener(helper).show(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeSearchMode() {
|
||||
showSearchBar(true);
|
||||
@@ -782,6 +888,9 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
public void onReceive(int id, Object obj) {
|
||||
if (Constants.MESSENGER_ID_JPN_TITLE == id) {
|
||||
mJpnTitle = (Boolean) obj;
|
||||
} else if (Constants.MESSENGER_ID_UPDATE_QUICK_SEARCH == id) {
|
||||
mQuickSearches = DBUtils.getAllQuickSearch();
|
||||
mQuickSearchAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1096,4 +1205,67 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
private interface GalleryListHelperSettable {
|
||||
void setGalleryListHelper(GalleryListHelper helper);
|
||||
}
|
||||
|
||||
private class SimpleHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public SimpleHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int TYPE_SETTINGS = 0;
|
||||
private static final int TYPE_TEXT = 1;
|
||||
|
||||
private class QuickSearchAdapter extends RecyclerView.Adapter<SimpleHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position == 0 ? TYPE_SETTINGS : TYPE_TEXT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
switch (viewType) {
|
||||
case TYPE_SETTINGS:
|
||||
return new SimpleHolder(getStageActivity().getLayoutInflater().inflate(
|
||||
R.layout.item_quick_search_setting, parent, false));
|
||||
case TYPE_TEXT:
|
||||
return new SimpleHolder(getStageActivity().getLayoutInflater().inflate(
|
||||
R.layout.item_quick_search, parent, false));
|
||||
default:
|
||||
throw new IllegalStateException("Unknown view type");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(SimpleHolder holder, int position) {
|
||||
if (getItemViewType(position) == TYPE_TEXT) {
|
||||
((TextView) holder.itemView).setText(mQuickSearches.get(position - 1).name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mQuickSearches.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private class QuickSearchClickListener implements EasyRecyclerView.OnItemClickListener {
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
switch (parent.getAdapter().getItemViewType(position)) {
|
||||
case TYPE_SETTINGS:
|
||||
// TODO
|
||||
return true;
|
||||
case TYPE_TEXT:
|
||||
setState(STATE_NORMAL);
|
||||
mListUrlBuilder.set(mQuickSearches.get(position - 1));
|
||||
mGalleryListHelper.refresh();
|
||||
((ContentActivity) getStageActivity()).closeDrawers();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,10 +63,15 @@ public class ReadingSettingsScene extends PreferenceScene implements ListPrefere
|
||||
hideNavbarPreference.setEnable(false);
|
||||
}
|
||||
|
||||
SwitchPreference volumePagePreference = new SwitchPreference(Settings.KEY_VOLUME_PAGE,
|
||||
resources.getString(R.string.settings_volume_page), null);
|
||||
volumePagePreference.setDefaultValue(Settings.DEFAULT_VOLUME_PAGE);
|
||||
|
||||
PreferenceSet preferenceSet = new PreferenceSet();
|
||||
preferenceSet.setPreferenceList(new Preference[] {
|
||||
directionPreference,
|
||||
hideNavbarPreference
|
||||
hideNavbarPreference,
|
||||
volumePagePreference
|
||||
});
|
||||
|
||||
return new PreferenceSet[] {
|
||||
|
||||
@@ -18,14 +18,24 @@ package com.hippo.ehviewer.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.client.data.GalleryBase;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.data.QuickSearch;
|
||||
import com.hippo.ehviewer.dao.DaoMaster;
|
||||
import com.hippo.ehviewer.dao.DaoSession;
|
||||
import com.hippo.ehviewer.dao.DirnameObj;
|
||||
import com.hippo.ehviewer.dao.DirnameObjDao;
|
||||
import com.hippo.ehviewer.dao.GalleryBaseObj;
|
||||
import com.hippo.ehviewer.dao.GalleryBaseObjDao;
|
||||
import com.hippo.ehviewer.dao.QuickSearchObj;
|
||||
import com.hippo.ehviewer.dao.QuickSearchObjDao;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DBUtils {
|
||||
|
||||
@@ -107,4 +117,39 @@ public class DBUtils {
|
||||
dirnameObjDao.update(dirnameObj);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addQuickSearch(String name, ListUrlBuilder builder) {
|
||||
if (TextUtils.isEmpty(name) ||
|
||||
(builder.getMode() != ListUrlBuilder.MODE_NORMAL &&
|
||||
builder.getMode() != ListUrlBuilder.MODE_UPLOADER &&
|
||||
builder.getMode() != ListUrlBuilder.MODE_TAG)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QuickSearchObj quickSearchObj = new QuickSearchObj();
|
||||
quickSearchObj.setName(name);
|
||||
quickSearchObj.setMode(builder.getMode());
|
||||
quickSearchObj.setCategory(builder.getCategory());
|
||||
quickSearchObj.setKeyword(builder.getKeyword());
|
||||
quickSearchObj.setAdvancedSearch(builder.getAdvanceSearch());
|
||||
quickSearchObj.setMinRating(builder.getMinRating());
|
||||
quickSearchObj.setTime(System.currentTimeMillis());
|
||||
sDaoSession.getQuickSearchObjDao().insert(quickSearchObj);
|
||||
|
||||
Messenger.getInstance().notify(Constants.MESSENGER_ID_UPDATE_QUICK_SEARCH, null);
|
||||
}
|
||||
|
||||
public static void removeQuickSearch(QuickSearch quickSearch) {
|
||||
sDaoSession.getQuickSearchObjDao().deleteByKey(quickSearch.id);
|
||||
}
|
||||
|
||||
public static List<QuickSearch> getAllQuickSearch() {
|
||||
QuickSearchObjDao quickSearchObjDao = sDaoSession.getQuickSearchObjDao();
|
||||
List<QuickSearchObj> list = quickSearchObjDao.queryBuilder().orderAsc(QuickSearchObjDao.Properties.Time).list();
|
||||
List<QuickSearch> result = new ArrayList<>(list.size());
|
||||
for (QuickSearchObj quickSearchObj : list) {
|
||||
result.add(QuickSearch.fromQuickSearchObj(quickSearchObj));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,8 @@ public final class Settings {
|
||||
public static final int DEFAULT_READING_DIRECTION = 1;
|
||||
public static final String KEY_READING_HIDE_NAV_BAR = "reading_hide_nav_bar";
|
||||
public static final boolean DEFAULT_READING_HIDE_NAV_BAR = true;
|
||||
public static final String KEY_VOLUME_PAGE = "volume_page";
|
||||
public static final boolean DEFAULT_VOLUME_PAGE = true;
|
||||
|
||||
public static void putReadingDirection(int value) {
|
||||
putInt(KEY_READING_DIRECTION, value);
|
||||
@@ -158,6 +160,14 @@ public final class Settings {
|
||||
return getBoolean(KEY_READING_HIDE_NAV_BAR, DEFAULT_READING_HIDE_NAV_BAR);
|
||||
}
|
||||
|
||||
public static void putVolumePage(boolean value) {
|
||||
putBoolean(KEY_VOLUME_PAGE, value);
|
||||
}
|
||||
|
||||
public static boolean getVolumePage() {
|
||||
return getBoolean(KEY_VOLUME_PAGE, DEFAULT_VOLUME_PAGE);
|
||||
}
|
||||
|
||||
|
||||
/****** EH ******/
|
||||
public static final String KEY_EH_SOURCE = "eh_source";
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
public class DownloadSearchBar {
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.widget.DrawerLayout;
|
||||
import com.hippo.widget.FitPaddingImpl;
|
||||
|
||||
public class DrawerRightPanel extends ViewGroup implements FitPaddingImpl {
|
||||
|
||||
private static final int[] MAX_ATTRS = {android.R.attr.maxWidth};
|
||||
|
||||
private int mMaxWidth = -1;
|
||||
|
||||
public DrawerRightPanel(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
public DrawerRightPanel(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs, MAX_ATTRS);
|
||||
mMaxWidth = a.getDimensionPixelSize(0, -1);
|
||||
a.recycle();
|
||||
|
||||
clearData();
|
||||
}
|
||||
|
||||
public void setData(View child) {
|
||||
removeAllViews();
|
||||
addView(child, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
public void clearData() {
|
||||
removeAllViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
|
||||
if (mMaxWidth > 0) {
|
||||
widthSpecSize = Math.min(mMaxWidth, widthSpecSize);
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSpecSize,
|
||||
MeasureSpec.EXACTLY);
|
||||
}
|
||||
|
||||
for (int i = 0, n = getChildCount(); i < n; i++) {
|
||||
measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
int left = getPaddingLeft();
|
||||
int top = getPaddingTop();
|
||||
|
||||
for (int i = 0, n = getChildCount(); i < n; i++) {
|
||||
final View view = getChildAt(i);
|
||||
view.layout(left, top, left + view.getMeasuredWidth(), top + view.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFitPadding(int left, int top, int right, int bottom) {
|
||||
DrawerLayout.LayoutParams lp = (DrawerLayout.LayoutParams) getLayoutParams();
|
||||
lp.topMargin = top;
|
||||
setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
|
||||
public class ListSearchBar extends SearchBar implements Messenger.Receiver {
|
||||
|
||||
private int mSource = -1;
|
||||
|
||||
public ListSearchBar(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ListSearchBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public ListSearchBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setSource(Settings.getEhSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_EH_SOURCE, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_EH_SOURCE, this);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"deprecation", "ConstantConditions"})
|
||||
public void setSource(int source) {
|
||||
if (mSource != source) {
|
||||
Resources resources = getContext().getResources();
|
||||
Drawable searchImage = resources.getDrawable(R.drawable.ic_search);
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
|
||||
ssb.append(String.format(resources.getString(R.string.search_bar_hint),
|
||||
EhUrl.getReadableHost(source)));
|
||||
int textSize = (int) (getEditTextTextSize() * 1.25);
|
||||
searchImage.setBounds(0, 0, textSize, textSize);
|
||||
ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
setEditTextHint(ssb);
|
||||
|
||||
mSource = source;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(int id, Object obj) {
|
||||
if (id == Constants.MESSENGER_ID_EH_SOURCE) {
|
||||
if (obj instanceof Integer) {
|
||||
int source = (Integer) obj;
|
||||
setSource(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -19,19 +19,14 @@ package com.hippo.ehviewer.widget;
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Editable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -49,11 +44,7 @@ import com.hippo.cardsalon.CardView;
|
||||
import com.hippo.drawable.AddDeleteDrawable;
|
||||
import com.hippo.drawable.DrawerArrowDrawable;
|
||||
import com.hippo.effect.ViewTransition;
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
import com.hippo.widget.SimpleImageView;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -64,7 +55,7 @@ import java.util.List;
|
||||
|
||||
public class SearchBar extends CardView implements View.OnClickListener,
|
||||
TextView.OnEditorActionListener, TextWatcher,
|
||||
SearchEditText.SearchEditTextListener, Messenger.Receiver {
|
||||
SearchEditText.SearchEditTextListener {
|
||||
|
||||
private static final String STATE_KEY_SUPER = "super";
|
||||
private static final String STATE_KEY_STATE = "state";
|
||||
@@ -102,8 +93,6 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
|
||||
private boolean mInAnimation = false;
|
||||
|
||||
private int mSource = -1;
|
||||
|
||||
public SearchBar(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
@@ -160,20 +149,6 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
mEditText.setSelection(suggestion.length());
|
||||
}
|
||||
});
|
||||
|
||||
setSource(Settings.getEhSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_EH_SOURCE, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_EH_SOURCE, this);
|
||||
}
|
||||
|
||||
private void updateSuggestions() {
|
||||
@@ -184,21 +159,12 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
mSuggestionAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"deprecation", "ConstantConditions"})
|
||||
public void setSource(int source) {
|
||||
if (mSource != source) {
|
||||
Resources resources = getContext().getResources();
|
||||
Drawable searchImage = resources.getDrawable(R.drawable.ic_search);
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
|
||||
ssb.append(String.format(resources.getString(R.string.search_bar_hint),
|
||||
EhUrl.getReadableHost(source)));
|
||||
int textSize = (int) (mEditText.getTextSize() * 1.25);
|
||||
searchImage.setBounds(0, 0, textSize, textSize);
|
||||
ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
mEditText.setHint(ssb);
|
||||
public float getEditTextTextSize() {
|
||||
return mEditText.getTextSize();
|
||||
}
|
||||
|
||||
mSource = source;
|
||||
}
|
||||
public void setEditTextHint(CharSequence hint) {
|
||||
mEditText.setHint(hint);
|
||||
}
|
||||
|
||||
public void setHelper(Helper helper) {
|
||||
@@ -415,16 +381,6 @@ public class SearchBar extends CardView implements View.OnClickListener,
|
||||
mHelper.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(int id, Object obj) {
|
||||
if (id == Constants.MESSENGER_ID_EH_SOURCE) {
|
||||
if (obj instanceof Integer) {
|
||||
int source = (Integer) obj;
|
||||
setSource(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
final Bundle state = new Bundle();
|
||||
|
||||
@@ -308,6 +308,11 @@ public class SearchLayout extends MonoRecyclerView implements CompoundButton.OnC
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mAction1) {
|
||||
if (mSearchMode == SEARCH_MODE_NORMAL) {
|
||||
ListUrlBuilder builder = new ListUrlBuilder();
|
||||
formatListUrlBuilder(builder);
|
||||
mHelper.onAdd(builder);
|
||||
}
|
||||
// TODO add quick search
|
||||
} else if (v == mAction2) {
|
||||
toggleSearchMode();
|
||||
@@ -412,6 +417,8 @@ public class SearchLayout extends MonoRecyclerView implements CompoundButton.OnC
|
||||
}
|
||||
|
||||
public interface SearhLayoutHelper {
|
||||
void onAdd(ListUrlBuilder builder);
|
||||
|
||||
void onChangeSearchMode();
|
||||
|
||||
void onRequestSelectImage();
|
||||
|
||||
@@ -478,10 +478,18 @@ public abstract class Scene {
|
||||
return "scene:" + mId;
|
||||
}
|
||||
|
||||
private String getPersonalStateKey() {
|
||||
return "scene:personal:" + mId;
|
||||
}
|
||||
|
||||
void saveInstanceState(Bundle outState) {
|
||||
SparseArray<Parcelable> states = new SparseArray<>();
|
||||
onSaveInstanceState(states);
|
||||
outState.putSparseParcelableArray(getStateKey(), states);
|
||||
Parcelable personalState = onSavePersonalState();
|
||||
if (personalState != null) {
|
||||
outState.putParcelable(getPersonalStateKey(), personalState);
|
||||
}
|
||||
}
|
||||
|
||||
void restoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||
@@ -492,6 +500,17 @@ public abstract class Scene {
|
||||
onRestoreInstanceState(savedStates);
|
||||
}
|
||||
}
|
||||
Parcelable personalState = savedInstanceState.getParcelable(getPersonalStateKey());
|
||||
if (personalState != null) {
|
||||
onRestorePersonalState(personalState);
|
||||
}
|
||||
}
|
||||
|
||||
protected Parcelable onSavePersonalState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onRestorePersonalState(@NonNull Parcelable saved) {
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState(@NonNull SparseArray<Parcelable> outState) {
|
||||
|
||||
@@ -80,33 +80,70 @@ public class SceneManager {
|
||||
mSceneStateListenerList.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyCreate(Class clazz) {
|
||||
|
||||
private void notifyInit(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onCreate(clazz);
|
||||
l.onInit(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyDestroy(Class clazz) {
|
||||
private void notifyRebirth(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onDestroy(clazz);
|
||||
l.onRebirth(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyPause(Class clazz) {
|
||||
private void notifyCreate(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onPause(clazz);
|
||||
l.onCreate(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyResume(Class clazz) {
|
||||
private void notifyBind(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onResume(clazz);
|
||||
l.onBind(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyRebirth(Class clazz) {
|
||||
private void notifyRestore(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onRebirth(clazz);
|
||||
l.onRestore(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyDestroy(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onDestroy(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyDie(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onDie(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyPause(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onPause(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyResume(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onResume(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyOpen(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onOpen(scene);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyClose(Scene scene) {
|
||||
for (SceneStateListener l : mSceneStateListenerList) {
|
||||
l.onClose(scene);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,23 +231,27 @@ public class SceneManager {
|
||||
}
|
||||
|
||||
private void startScene(Scene scene, Curtain curtain) {
|
||||
Scene previousState = getTopScene();
|
||||
Scene previousScene = getTopScene();
|
||||
mSceneStack.push(scene);
|
||||
|
||||
if (curtain != null) {
|
||||
curtain.setPreviousScene(previousState);
|
||||
curtain.setPreviousScene(previousScene);
|
||||
}
|
||||
|
||||
if (previousState != null) {
|
||||
previousState.endCurtainAnimation();
|
||||
previousState.pause();
|
||||
previousState.setState(Scene.SCENE_STATE_PAUSE);
|
||||
if (previousScene != null) {
|
||||
previousScene.endCurtainAnimation();
|
||||
previousScene.pause();
|
||||
notifyPause(previousScene);
|
||||
previousScene.setState(Scene.SCENE_STATE_PAUSE);
|
||||
}
|
||||
|
||||
scene.init();
|
||||
notifyInit(scene);
|
||||
scene.setState(Scene.SCENE_STATE_PREPARE);
|
||||
scene.create(false);
|
||||
notifyCreate(scene);
|
||||
scene.bind();
|
||||
notifyBind(scene);
|
||||
|
||||
// Update fit padding
|
||||
int fitPaddingBottom = getStageActivity().getFitPaddingBottom();
|
||||
@@ -221,12 +262,12 @@ public class SceneManager {
|
||||
scene.setState(Scene.SCENE_STATE_RUN);
|
||||
if (!checkPrepareToDie(scene)) {
|
||||
// No finish called. Go on
|
||||
if (curtain != null && previousState != null) {
|
||||
if (curtain != null && previousScene != null) {
|
||||
scene.setState(Scene.SCENE_STATE_OPEN);
|
||||
curtain.open(scene, previousState);
|
||||
curtain.open(scene, previousScene);
|
||||
} else {
|
||||
// No curtain, set visiblity for previousState here
|
||||
if (previousState != null) {
|
||||
if (previousScene != null) {
|
||||
updateSceneVisibility();
|
||||
}
|
||||
}
|
||||
@@ -275,8 +316,10 @@ public class SceneManager {
|
||||
// It is not the first or it is the last scene
|
||||
mSceneStack.remove(index);
|
||||
scene.destroy(true);
|
||||
notifyDestroy(scene);
|
||||
scene.setState(Scene.SCENE_STATE_DESTROY);
|
||||
scene.die(index == 0);
|
||||
notifyDie(scene);
|
||||
scene.setState(Scene.SCENE_STATE_DIE);
|
||||
|
||||
if (index == 0) {
|
||||
@@ -291,9 +334,11 @@ public class SceneManager {
|
||||
Scene previousScene = mSceneStack.get(index - 1);
|
||||
|
||||
previousScene.resume();
|
||||
notifyResume(previousScene);
|
||||
previousScene.setState(Scene.SCENE_STATE_RUN);
|
||||
|
||||
scene.destroy(true);
|
||||
notifyDestroy(scene);
|
||||
|
||||
// Update scene visibility
|
||||
updateSceneVisibility();
|
||||
@@ -309,6 +354,7 @@ public class SceneManager {
|
||||
} else {
|
||||
scene.setState(Scene.SCENE_STATE_DESTROY);
|
||||
scene.die(false);
|
||||
notifyDie(scene);
|
||||
scene.setState(Scene.SCENE_STATE_DIE);
|
||||
|
||||
previousScene.setHide(false);
|
||||
@@ -327,6 +373,7 @@ public class SceneManager {
|
||||
void openScene(Scene scene) {
|
||||
checkSceneState(scene, Scene.SCENE_STATE_OPEN);
|
||||
scene.open();
|
||||
notifyOpen(scene);
|
||||
scene.setState(Scene.SCENE_STATE_RUN);
|
||||
checkPrepareToDie(scene);
|
||||
updateSceneVisibility();
|
||||
@@ -335,8 +382,10 @@ public class SceneManager {
|
||||
void closeScene(Scene scene) {
|
||||
checkSceneState(scene, Scene.SCENE_STATE_CLOSE);
|
||||
scene.close();
|
||||
notifyClose(scene);
|
||||
scene.setState(Scene.SCENE_STATE_DESTROY);
|
||||
scene.die(false);
|
||||
notifyDie(scene);
|
||||
scene.setState(Scene.SCENE_STATE_DIE);
|
||||
|
||||
// remove the scene from legacy set
|
||||
@@ -391,21 +440,42 @@ public class SceneManager {
|
||||
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||
for (Scene scene : mSceneStack) {
|
||||
scene.destroy(false);
|
||||
notifyDestroy(scene);
|
||||
scene.setState(Scene.SCENE_STATE_REBIRTH);
|
||||
scene.rebirth();
|
||||
notifyRebirth(scene);
|
||||
scene.setState(Scene.SCENE_STATE_PREPARE);
|
||||
scene.create(true);
|
||||
notifyCreate(scene);
|
||||
scene.restore();
|
||||
notifyRestore(scene);
|
||||
scene.setState(Scene.SCENE_STATE_RUN);
|
||||
scene.restoreInstanceState(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
||||
public interface SceneStateListener {
|
||||
void onCreate(Class clazz);
|
||||
void onDestroy(Class clazz);
|
||||
void onPause(Class clazz);
|
||||
void onResume(Class clazz);
|
||||
void onRebirth(Class clazz);
|
||||
|
||||
void onInit(Scene scene);
|
||||
|
||||
void onRebirth(Scene scene);
|
||||
|
||||
void onCreate(Scene scene);
|
||||
|
||||
void onBind(Scene scene);
|
||||
|
||||
void onRestore(Scene scene);
|
||||
|
||||
void onDestroy(Scene scene);
|
||||
|
||||
void onDie(Scene scene);
|
||||
|
||||
void onPause(Scene scene);
|
||||
|
||||
void onResume(Scene scene);
|
||||
|
||||
void onOpen(Scene scene);
|
||||
|
||||
void onClose(Scene scene);
|
||||
}
|
||||
}
|
||||
@@ -687,6 +687,7 @@ public class DrawerLayout extends ViewGroup {
|
||||
@Override
|
||||
protected boolean fitSystemWindows(@NonNull Rect insets) {
|
||||
int fitPaddingTop = insets.top;
|
||||
int fitPaddingRight = insets.right;
|
||||
int fitPaddingBottom = insets.bottom;
|
||||
|
||||
int count = getChildCount();
|
||||
@@ -699,6 +700,14 @@ public class DrawerLayout extends ViewGroup {
|
||||
|
||||
insets.top = 0;
|
||||
insets.bottom = 0;
|
||||
insets.right = 0;
|
||||
|
||||
// TODO padding right make it weird
|
||||
ViewParent parent = getParent();
|
||||
if (parent instanceof ViewGroup) {
|
||||
ViewGroup viewGroup = (ViewGroup) parent;
|
||||
viewGroup.setPadding(0, 0, fitPaddingRight, 0);
|
||||
}
|
||||
|
||||
return super.fitSystemWindows(insets);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,12 @@ public class LinearDividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
int itemCount = parent.getAdapter().getItemCount();
|
||||
RecyclerView.Adapter adapter = parent.getAdapter();
|
||||
if (adapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int itemCount = adapter.getItemCount();
|
||||
|
||||
if (mOrientation == VERTICAL) {
|
||||
final boolean isRtl = ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
|
||||
Reference in new issue
Block a user