Add download label scene
This commit is contained in:
1 parent
feb9bbadc6
commit
a55b5a84d5
19 files changed
+764
-12
No files matched your search
@@ -73,6 +73,7 @@ dependencies {
|
||||
compile 'com.android.support:appcompat-v7:23.2.0'
|
||||
compile 'com.android.support:customtabs:23.2.0'
|
||||
compile 'com.android.support:design:23.2.0'
|
||||
compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.6'
|
||||
compile 'de.greenrobot:greendao:2.0.0'
|
||||
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2016 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.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class EditTextDialogBuilder extends AlertDialog.Builder implements EditText.OnEditorActionListener {
|
||||
|
||||
private final TextInputLayout mTextInputLayout;
|
||||
private final EditText mEditText;
|
||||
private AlertDialog mDialog;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public EditTextDialogBuilder(Context context, String text, String hint) {
|
||||
super(context);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext_builder, null);
|
||||
setView(view);
|
||||
mTextInputLayout = (TextInputLayout) view;
|
||||
mEditText = (EditText) view.findViewById(R.id.edit_text);
|
||||
mEditText.setText(text);
|
||||
mEditText.setOnEditorActionListener(this);
|
||||
mTextInputLayout.setHint(hint);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return mEditText.getText().toString();
|
||||
}
|
||||
|
||||
public void setError(CharSequence error) {
|
||||
mTextInputLayout.setError(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog create() {
|
||||
mDialog = super.create();
|
||||
return mDialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (mDialog != null) {
|
||||
Button button = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
if (button != null) {
|
||||
button.performClick();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,4 +417,29 @@ public class EhDB {
|
||||
raw.setId(dao.insert(raw));
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static synchronized void moveDownloadLabel(int fromPosition, int toPosition) {
|
||||
if (fromPosition == toPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean reverse = fromPosition > toPosition;
|
||||
int offset = reverse ? toPosition : fromPosition;
|
||||
int limit = reverse ? fromPosition - toPosition + 1 : toPosition - fromPosition + 1;
|
||||
|
||||
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
|
||||
List<DownloadLabelRaw> list = dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time)
|
||||
.offset(offset).limit(limit).list();
|
||||
|
||||
int step = reverse ? 1 : -1;
|
||||
int start = reverse ? limit - 1 : 0;
|
||||
int end = reverse ? 0 : limit - 1;
|
||||
long toTime = list.get(end).getTime();
|
||||
for (int i = end; reverse ? i < start : i > start; i += step) {
|
||||
list.get(i).setTime(list.get(i + step).getTime());
|
||||
}
|
||||
list.get(start).setTime(toTime);
|
||||
|
||||
dao.updateInTx(list);
|
||||
}
|
||||
}
|
||||
@@ -594,6 +594,29 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void addLabel(String label) {
|
||||
if (label == null || containLabel(label)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mLabelList.add(EhDB.addDownloadLabel(label));
|
||||
mMap.put(label, new LinkedList<DownloadInfo>());
|
||||
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdateLabels();
|
||||
}
|
||||
}
|
||||
|
||||
public void moveLabel(int fromPosition, int toPosition) {
|
||||
final DownloadLabelRaw item = mLabelList.remove(fromPosition);
|
||||
mLabelList.add(toPosition, item);
|
||||
EhDB.moveDownloadLabel(fromPosition, toPosition);
|
||||
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdateLabels();
|
||||
}
|
||||
}
|
||||
|
||||
boolean isIdle() {
|
||||
return mCurrentTask == null && mWaitList.isEmpty();
|
||||
}
|
||||
@@ -901,10 +924,15 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
void onUpdateAll();
|
||||
|
||||
/**
|
||||
* Maybe all data is changed, maybe size is changed
|
||||
* Maybe all data is changed, maybe list is changed
|
||||
*/
|
||||
void onReload();
|
||||
|
||||
/**
|
||||
* The list is gone
|
||||
*/
|
||||
void onChange();
|
||||
|
||||
/**
|
||||
* Remove the special info from the special position
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* Copyright 2016 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 android.content.DialogInterface;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemAdapter;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemConstants;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAction;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
|
||||
import com.hippo.app.EditTextDialogBuilder;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.dao.DownloadLabelRaw;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.vector.VectorDrawable;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.SimpleImageView;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadLabelScene extends ToolbarScene {
|
||||
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
@Nullable
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
|
||||
@Nullable
|
||||
public List<DownloadLabelRaw> mList = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mList = EhApplication.getDownloadManager(getContext()).getLabelList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mList = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView2(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_download_label, container, false);
|
||||
|
||||
mRecyclerView = (EasyRecyclerView) view.findViewById(R.id.recycler_view);
|
||||
View tip = view.findViewById(R.id.tip);
|
||||
SimpleImageView tipImage = (SimpleImageView) tip.findViewById(R.id.tip_image);
|
||||
tipImage.setDrawable(VectorDrawable.create(getContext(), R.xml.sadpanda_head));
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
if (mRecyclerView != null) {
|
||||
// touch guard manager (this class is required to suppress scrolling while swipe-dismiss animation is running)
|
||||
RecyclerViewTouchActionGuardManager guardManager = new RecyclerViewTouchActionGuardManager();
|
||||
guardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
|
||||
guardManager.setEnabled(true);
|
||||
|
||||
// drag & drop manager
|
||||
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
|
||||
dragDropManager.setDraggingItemShadowDrawable(
|
||||
(NinePatchDrawable) getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
|
||||
// swipe manager
|
||||
RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
|
||||
|
||||
RecyclerView.Adapter adapter = new LabelAdapter();
|
||||
adapter.setHasStableIds(true);
|
||||
adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
|
||||
adapter = swipeManager.createWrappedAdapter(adapter); // wrap for swiping
|
||||
mAdapter = adapter;
|
||||
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.setItemAnimator(animator);
|
||||
|
||||
guardManager.attachRecyclerView(mRecyclerView);
|
||||
swipeManager.attachRecyclerView(mRecyclerView);
|
||||
dragDropManager.attachRecyclerView(mRecyclerView);
|
||||
}
|
||||
|
||||
updateView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
setTitle(R.string.label);
|
||||
setNavigationIcon(VectorDrawable.create(getContext(), R.xml.ic_arrow_left_dark_x24));
|
||||
|
||||
// Clear nav checked item
|
||||
setNavCheckedItem(0);
|
||||
|
||||
// Hide IME
|
||||
ActivityHelper.hideSoftInput(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNavigationClick() {
|
||||
onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMenuResId() {
|
||||
return R.menu.scene_download_label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_add: {
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(getContext(), null, getString(R.string.label));
|
||||
builder.setTitle(R.string.new_label_title);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
AlertDialog dialog = builder.show();
|
||||
new NewLabelDialogHelper(builder, dialog);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateView() {
|
||||
if (mViewTransition != null) {
|
||||
if (mList != null && mList.size() > 0) {
|
||||
mViewTransition.showView(0);
|
||||
} else {
|
||||
mViewTransition.showView(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class NewLabelDialogHelper implements View.OnClickListener {
|
||||
|
||||
private final EditTextDialogBuilder mBuilder;
|
||||
private final AlertDialog mDialog;
|
||||
|
||||
public NewLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog) {
|
||||
mBuilder = builder;
|
||||
mDialog = dialog;
|
||||
Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
if (button != null) {
|
||||
button.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String text = mBuilder.getText();
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_is_empty));
|
||||
} else if (getString(R.string.default_download_label_name).equals(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_is_invalid));
|
||||
} else if (EhApplication.getDownloadManager(getContext()).containLabel(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_exist));
|
||||
} else {
|
||||
mBuilder.setError(null);
|
||||
mDialog.dismiss();
|
||||
EhApplication.getDownloadManager(getContext()).addLabel(text);
|
||||
if (mAdapter != null && mList != null) {
|
||||
mAdapter.notifyItemInserted(mList.size() - 1);
|
||||
}
|
||||
if (mViewTransition != null) {
|
||||
if (mList != null && mList.size() > 0) {
|
||||
mViewTransition.showView(0);
|
||||
} else {
|
||||
mViewTransition.showView(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelHolder extends AbstractDraggableSwipeableItemViewHolder
|
||||
implements View.OnClickListener {
|
||||
|
||||
public final View swipeHandler;
|
||||
public final TextView label;
|
||||
public final View dragHandler;
|
||||
|
||||
public LabelHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
swipeHandler = itemView.findViewById(R.id.swipe_handler);
|
||||
label = (TextView) itemView.findViewById(R.id.label);
|
||||
dragHandler = itemView.findViewById(R.id.drag_handler);
|
||||
|
||||
label.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return swipeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelAdapter extends RecyclerView.Adapter<LabelHolder>
|
||||
implements DraggableItemAdapter<LabelHolder>,
|
||||
SwipeableItemAdapter<LabelHolder> {
|
||||
|
||||
|
||||
@Override
|
||||
public LabelHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new LabelHolder(getActivity().getLayoutInflater()
|
||||
.inflate(R.layout.item_download_label, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(LabelHolder holder, int position) {
|
||||
if (mList != null) {
|
||||
holder.label.setText(mList.get(position).getLabel());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mList != null ? mList.get(position).getId() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList != null ? mList.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCheckCanStartDrag(LabelHolder holder, int position, int x, int y) {
|
||||
return ViewUtils.isViewUnder(holder.dragHandler, x, y, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDraggableRange onGetItemDraggableRange(LabelHolder holder, int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoveItem(int fromPosition, int toPosition) {
|
||||
if (fromPosition == toPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
EhApplication.getDownloadManager(getContext()).moveLabel(fromPosition, toPosition);
|
||||
if (mAdapter != null && mList != null) {
|
||||
notifyItemMoved(fromPosition, toPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(LabelHolder holder, int position, int x, int y) {
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_BOTH_H;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(LabelHolder holder, int position, int type) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwipeResultAction onSwipeItem(LabelHolder holder, int position, int result) {
|
||||
switch (result) {
|
||||
// swipe right
|
||||
case SwipeableItemConstants.RESULT_SWIPED_RIGHT:
|
||||
case SwipeableItemConstants.RESULT_SWIPED_LEFT:
|
||||
return null;
|
||||
case SwipeableItemConstants.RESULT_CANCELED:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,6 +125,14 @@ public class DownloadScene extends ToolbarScene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mList = null;
|
||||
DownloadManager manager = EhApplication.getDownloadManager(getContext());
|
||||
manager.setDownloadInfoListener(null);
|
||||
}
|
||||
|
||||
private void updateForLabel() {
|
||||
DownloadManager manager = EhApplication.getDownloadManager(getContext());
|
||||
if (mLabel == null) {
|
||||
@@ -271,8 +279,6 @@ public class DownloadScene extends ToolbarScene
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
DownloadManager manager = EhApplication.getDownloadManager(getContext());
|
||||
manager.setDownloadInfoListener(null);
|
||||
mRecyclerView = null;
|
||||
mFabLayout = null;
|
||||
mViewTransition = null;
|
||||
@@ -293,7 +299,7 @@ public class DownloadScene extends ToolbarScene
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_settings:
|
||||
// TODO
|
||||
startScene(new Announcer(DownloadLabelScene.class));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -338,12 +344,6 @@ public class DownloadScene extends ToolbarScene
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mList = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
@@ -546,6 +546,19 @@ public class DownloadScene extends ToolbarScene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange() {
|
||||
mLabel = null;
|
||||
updateForLabel();
|
||||
if (mViewTransition != null) {
|
||||
if (mList == null || mList.size() == 0) {
|
||||
mViewTransition.showView(1);
|
||||
} else {
|
||||
mViewTransition.showView(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(@NonNull DownloadInfo info, @NonNull List<DownloadInfo> list, int position) {
|
||||
if (mList != list) {
|
||||
|
||||
@@ -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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewOutlineProvider;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
|
||||
public class ShadowLinearLayout extends LinearLayout {
|
||||
|
||||
private NinePatchDrawable mShadow;
|
||||
private final Rect mShadowPaddings = new Rect();
|
||||
|
||||
public ShadowLinearLayout(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ShadowLinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ShadowLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
// TODO not only 2dp
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
setOutlineProvider(ViewOutlineProvider.BOUNDS);
|
||||
setElevation(LayoutUtils.dp2pix(context, 2));
|
||||
} else {
|
||||
setShadow((NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_2dp)); // TODO draktheme
|
||||
}
|
||||
}
|
||||
|
||||
private void setShadow(NinePatchDrawable shadow) {
|
||||
mShadow = shadow;
|
||||
mShadow.getPadding(mShadowPaddings);
|
||||
updateShadowBounds();
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
|
||||
private void updateShadowBounds() {
|
||||
NinePatchDrawable shadow = mShadow;
|
||||
if (shadow == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
Rect paddings = mShadowPaddings;
|
||||
if (width != 0 && height != 0) {
|
||||
shadow.setBounds(-paddings.left, -paddings.top, width + paddings.right, height + paddings.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
updateShadowBounds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
if (mShadow != null) {
|
||||
mShadow.draw(canvas);
|
||||
}
|
||||
super.draw(canvas);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 124 B |
Binary file not shown.
|
After Width: | Height: | Size: 93 B |
Binary file not shown.
|
After Width: | Height: | Size: 97 B |
Binary file not shown.
|
After Width: | Height: | Size: 97 B |
Binary file not shown.
|
After Width: | Height: | Size: 258 B |
Binary file not shown.
|
After Width: | Height: | Size: 981 B |
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 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.
|
||||
-->
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="?attr/dialogPreferredPadding"
|
||||
android:paddingTop="@dimen/abc_dialog_padding_top_material"
|
||||
android:paddingRight="?attr/dialogPreferredPadding">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 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.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false">
|
||||
|
||||
<com.hippo.widget.ShadowLinearLayout
|
||||
android:id="@+id/swipe_handler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textSize="@dimen/text_little_small"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/drag_handler"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorAccent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider"/>
|
||||
|
||||
</com.hippo.widget.ShadowLinearLayout>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 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.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.hippo.easyrecyclerview.EasyRecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/keyline_margin"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tip"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.hippo.widget.SimpleImageView
|
||||
android:id="@+id/tip_image"
|
||||
android:layout_width="168dp"
|
||||
android:layout_height="168dp"
|
||||
android:layout_gravity="center_horizontal"/>
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.AppCompat.Medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:text="@string/no_download_label"/>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
@@ -48,7 +48,7 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
|
||||
<EditText
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -67,7 +67,7 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
|
||||
<EditText
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 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.
|
||||
-->
|
||||
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_add"
|
||||
android:icon="@drawable/ic_add_dark_x24"
|
||||
android:title="@string/add"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
||||
@@ -240,6 +240,14 @@
|
||||
<string name="download_move_dialog_title">Move</string>
|
||||
<string name="label">Label</string>
|
||||
|
||||
<!-- Download label -->
|
||||
<string name="no_download_label">No labels</string>
|
||||
<string name="add">Add</string>
|
||||
<string name="new_label_title">New label</string>
|
||||
<string name="label_text_is_empty">Label text is empty</string>
|
||||
<string name="label_text_is_invalid">\"Default\" is an invalid label</string>
|
||||
<string name="label_text_exist">Label text exists</string>
|
||||
|
||||
<!-- Gallery Activity -->
|
||||
<string name="page_menu_title">Page %d</string>
|
||||
<string name="page_menu_refresh">@string/refresh</string>
|
||||
|
||||
Reference in new issue
Block a user