Add download label view

This commit is contained in:
seven332 committed 2016-02-27 01:07:37 +08:00
1 parent d9ee9631a6
commit 271dddb389
17 files changed
+324 -39

No files matched your search

+15 -12
View File
@@ -44,7 +44,6 @@ import com.hippo.ehviewer.dao.QuickSearchDao;
import com.hippo.ehviewer.dao.QuickSearchRaw;
import com.hippo.ehviewer.download.DownloadInfo;
import java.util.ArrayList;
import java.util.List;
import de.greenrobot.dao.query.LazyList;
@@ -329,17 +328,6 @@ public class EhDB {
}
}
@NonNull
public static synchronized List<String> getAllDownloadLabelList() {
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
List<DownloadLabelRaw> list = dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time).list();
List<String> result = new ArrayList<>(list.size());
for (int i = 0, n = list.size(); i < n; i++) {
result.add(list.get(i).getLabel());
}
return result;
}
public static synchronized LazyList<DownloadInfoRaw> getDownloadInfoLazyList() {
return sDaoSession.getDownloadInfoDao().queryBuilder()
.orderAsc(DownloadInfoDao.Properties.Date).listLazy();
@@ -414,4 +402,19 @@ public class EhDB {
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
dao.deleteByKey((long) gid);
}
@NonNull
public static synchronized List<DownloadLabelRaw> getAllDownloadLabelList() {
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
return dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time).list();
}
public static synchronized DownloadLabelRaw addDownloadLabel(String label) {
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
DownloadLabelRaw raw = new DownloadLabelRaw();
raw.setLabel(label);
raw.setTime(System.currentTimeMillis());
raw.setId(dao.insert(raw));
return raw;
}
}
@@ -25,6 +25,7 @@ import android.util.SparseArray;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.dao.DownloadInfoRaw;
import com.hippo.ehviewer.dao.DownloadLabelRaw;
import com.hippo.ehviewer.spider.SpiderQueen;
import com.hippo.image.Image;
import com.hippo.yorozuya.ConcurrentPool;
@@ -49,7 +50,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
private final Map<String, LinkedList<DownloadInfo>> mMap;
// All labels without default label
@NonNull
private final List<String> mLabelList;
private final List<DownloadLabelRaw> mLabelList;
// Store download info with default label
@NonNull
private final LinkedList<DownloadInfo> mDefaultInfoList;
@@ -75,14 +76,14 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
public DownloadManager(Context context) {
mContext = context;
List<String> labels = EhDB.getAllDownloadLabelList();
List<DownloadLabelRaw> labels = EhDB.getAllDownloadLabelList();
mLabelList = labels;
// Create list for each label
HashMap<String, LinkedList<DownloadInfo>> map = new HashMap<>();
mMap = map;
for (String label : labels) {
map.put(label, new LinkedList<DownloadInfo>());
for (DownloadLabelRaw label : labels) {
map.put(label.getLabel(), new LinkedList<DownloadInfo>());
}
// Create default for non tag
mDefaultInfoList = new LinkedList<>();
@@ -106,8 +107,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
if (list == null) {
list = new LinkedList<>();
map.put(info.label, list);
if (!labels.contains(info.label)) {
labels.add(info.label);
if (!containLabel(info.label)) {
// Add label to DB and list
labels.add(EhDB.addDownloadLabel(info.label));
}
}
list.add(info);
@@ -151,11 +153,21 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
public boolean containLabel(String label) {
return mLabelList.contains(label);
if (label == null) {
return false;
}
for (DownloadLabelRaw raw: mLabelList) {
if (label.equals(raw.getLabel())) {
return true;
}
}
return false;
}
@NonNull
public List<String> getLabelList() {
public List<DownloadLabelRaw> getLabelList() {
return mLabelList;
}
@@ -211,6 +211,12 @@ public final class MainActivity extends StageActivity
}
}
public void closeDrawer(int drawerGravity) {
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(drawerGravity);
}
}
public void toggleDrawer(int drawerGravity) {
if (mDrawerLayout != null) {
if (mDrawerLayout.isDrawerOpen(drawerGravity)) {
@@ -38,6 +38,13 @@ public class BaseScene extends SceneFragment {
}
}
public void closeDrawer(int drawerGravity) {
FragmentActivity activity = getActivity();
if (activity instanceof MainActivity) {
((MainActivity) activity).closeDrawer(drawerGravity);
}
}
public void toggleDrawer(int drawerGravity) {
FragmentActivity activity = getActivity();
if (activity instanceof MainActivity) {
@@ -30,11 +30,16 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.transition.TransitionInflater;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -47,6 +52,7 @@ import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.dao.DownloadLabelRaw;
import com.hippo.ehviewer.download.DownloadInfo;
import com.hippo.ehviewer.download.DownloadManager;
import com.hippo.ehviewer.download.DownloadService;
@@ -64,7 +70,9 @@ import com.hippo.view.ViewTransition;
import com.hippo.widget.LoadImageView;
import com.hippo.widget.SimpleImageView;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
public class DownloadScene extends ToolbarScene
@@ -106,8 +114,7 @@ public class DownloadScene extends ToolbarScene
}
}
private void onInit() {
mLabel = Settings.getRecentDownloadLabel();
private void updateForLabel() {
DownloadManager manager = EhApplication.getDownloadManager(getContext());
if (mLabel == null) {
mList = manager.getDefaultDownloadInfoList();
@@ -118,20 +125,19 @@ public class DownloadScene extends ToolbarScene
mList = manager.getDefaultDownloadInfoList();
}
}
setTitle(getString(R.string.scene_download_title,
mLabel != null ? mLabel : getString(R.string.default_download_label_name)));
Settings.putRecentDownloadLabel(mLabel);
}
private void onInit() {
mLabel = Settings.getRecentDownloadLabel();
updateForLabel();
}
private void onRestore(@NonNull Bundle savedInstanceState) {
mLabel = savedInstanceState.getString(KEY_LABEL);
DownloadManager manager = EhApplication.getDownloadManager(getContext());
if (mLabel == null) {
mList = manager.getDefaultDownloadInfoList();
} else {
mList = manager.getLabelDownloadInfoList(mLabel);
if (mList == null) {
mLabel = null;
mList = manager.getDefaultDownloadInfoList();
}
}
updateForLabel();
}
@Override
@@ -177,7 +183,6 @@ public class DownloadScene extends ToolbarScene
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setTitle(R.string.download);
setNavigationIcon(VectorDrawable.create(getContext(), R.xml.ic_arrow_left_dark_x24));
// Clear nav checked item
@@ -228,6 +233,65 @@ public class DownloadScene extends ToolbarScene
mAdapter = null;
}
@Override
public View onCreateDrawerView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.drawer_download, container, false);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.drawer_download_label_title);
toolbar.inflateMenu(R.menu.drawer_download);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_settings:
// TODO
return true;
}
return false;
}
});
List<DownloadLabelRaw> list = EhApplication.getDownloadManager(getContext()).getLabelList();
final List<String> labels = new ArrayList<>(list.size() + 1);
// Add default label name
labels.add(getString(R.string.default_download_label_name));
for (DownloadLabelRaw raw: list) {
labels.add(raw.getLabel());
}
// TODO handle download label items update
ListView listView = (ListView) view.findViewById(R.id.list_view);
listView.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_simple_list, labels));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String label;
if (position == 0) {
label = null;
} else {
label = labels.get(position);
}
if (!ObjectUtils.equal(label, mLabel)) {
mLabel = label;
updateForLabel();
if (mViewTransition != null) {
if (mList == null || mList.size() == 0) {
mViewTransition.showView(1);
} else {
mViewTransition.showView(0);
}
}
closeDrawer(Gravity.RIGHT);
}
}
});
return view;
}
@Override
public void onDestroy() {
super.onDestroy();
@@ -33,8 +33,11 @@ import com.hippo.ehviewer.R;
public abstract class ToolbarScene extends BaseScene {
@Nullable
private Toolbar mToolbar;
private CharSequence mTempTitle;
@Nullable
public View onCreateView2(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -69,6 +72,11 @@ public abstract class ToolbarScene extends BaseScene {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (mToolbar != null) {
if (mTempTitle != null) {
mToolbar.setTitle(mTempTitle);
mTempTitle = null;
}
int menuResId = getMenuResId();
if (menuResId != 0) {
mToolbar.inflateMenu(menuResId);
@@ -78,6 +86,7 @@ public abstract class ToolbarScene extends BaseScene {
return ToolbarScene.this.onMenuItemClick(item);
}
});
onMenuCreated(mToolbar.getMenu());
}
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
@@ -85,7 +94,6 @@ public abstract class ToolbarScene extends BaseScene {
onNavigationClick();
}
});
onMenuCreated(mToolbar.getMenu());
}
}
@@ -116,14 +124,14 @@ public abstract class ToolbarScene extends BaseScene {
}
public void setTitle(@StringRes int resId) {
if (mToolbar != null) {
mToolbar.setTitle(resId);
}
setTitle(getString(resId));
}
public void setTitle(CharSequence title) {
if (mToolbar != null) {
mToolbar.setTitle(title);
} else {
mTempTitle = title;
}
}
}
@@ -0,0 +1,74 @@
/*
* 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.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import com.hippo.yorozuya.LayoutUtils;
public class DrawView extends FrameLayout {
private static final int DEFAULT_MAX_WIDTH = 280;
private static final int[] SIZE_ATTRS = new int[] {
android.R.attr.maxWidth
};
private int mMaxWidth;
public DrawView(Context context) {
super(context);
init(context, null);
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public DrawView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, SIZE_ATTRS);
mMaxWidth = a.getDimensionPixelOffset(0, LayoutUtils.dp2pix(context, DEFAULT_MAX_WIDTH));
a.recycle();
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
switch (MeasureSpec.getMode(widthSpec)) {
case MeasureSpec.EXACTLY:
// Nothing to do
break;
case MeasureSpec.AT_MOST:
widthSpec = MeasureSpec.makeMeasureSpec(
Math.min(MeasureSpec.getSize(widthSpec), mMaxWidth), MeasureSpec.EXACTLY);
break;
case MeasureSpec.UNSPECIFIED:
widthSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, MeasureSpec.EXACTLY);
break;
}
// Let super sort out the height
super.onMeasure(widthSpec, heightSpec);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

+4 -2
View File
@@ -38,11 +38,13 @@
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/nav_drawer_main"/>
<FrameLayout
<com.hippo.widget.DrawView
android:id="@+id/right_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:minWidth="320dp"/>
android:maxWidth="280dp"
android:background="@color/background_light"
android:clickable="true"/>
</android.support.v4.widget.DrawerLayout>
@@ -0,0 +1,48 @@
<?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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:saveEnabled="false"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/shadow_bottom"/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout>
@@ -0,0 +1,27 @@
<?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.
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:minHeight="?attr/listPreferredItemHeightSmall" />
+28
View File
@@ -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_settings"
android:icon="@drawable/ic_settings_dark_x24"
android:title="@string/settings"
app:showAsAction="ifRoom"/>
</menu>
@@ -173,6 +173,7 @@
<string name="go_to">跳页</string>
<!-- Download -->
<string name="scene_download_title">下载 - %s</string>
<string name="no_download_info">无下载项目</string>
<string name="download_state_none">未启动</string>
<string name="download_state_wait">等待中</string>
@@ -191,6 +192,8 @@
<string name="download_remove_dialog_message">从下载列表移除 %s ?</string>
<string name="download_remove_dialog_check_text">删除图片文件</string>
<string name="stat_download_action_stop_all">全部停止</string>
<string name="drawer_download_label_title">标签</string>
<string name="default_download_label_name">默认</string>
<!-- Gallery Activity -->
<string name="page_menu_title">第 %d 页</string>
+3
View File
@@ -213,6 +213,7 @@
<string name="go_to">Go to</string>
<!-- Download -->
<string name="scene_download_title">Download - %s</string>
<string name="no_download_info">No download items</string>
<string name="download_state_none">Idle</string>
<string name="download_state_wait">Waiting</string>
@@ -231,6 +232,8 @@
<string name="download_remove_dialog_message">Remove %s from download list ?</string>
<string name="download_remove_dialog_check_text">Delete image files</string>
<string name="stat_download_action_stop_all">Stop All</string>
<string name="drawer_download_label_title">Label</string>
<string name="default_download_label_name">Default</string>
<!-- Gallery Activity -->
<string name="page_menu_title">Page %d</string>