添加历史过滤

This commit is contained in:
seven332 committed 2014-11-02 19:47:18 +08:00
1 parent 61992ed2a2
commit 52b62cefee
20 files changed
+186 -62

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 433 B

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 B

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 536 B

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 B

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 927 B

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

+8 -16
View File
@@ -26,22 +26,20 @@
<CheckBox
android:id="@+id/tag_group_reclass"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="reclass"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
<CheckBox
android:id="@+id/tag_group_language"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="language"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
</TableRow>
@@ -51,22 +49,20 @@
<CheckBox
android:id="@+id/tag_group_parody"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="parody"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
<CheckBox
android:id="@+id/tag_group_character"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="character"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
</TableRow>
@@ -76,22 +72,20 @@
<CheckBox
android:id="@+id/tag_group_group"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="group"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
<CheckBox
android:id="@+id/tag_group_artist"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="artist"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
</TableRow>
@@ -101,22 +95,20 @@
<CheckBox
android:id="@+id/tag_group_male"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="male"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
<CheckBox
android:id="@+id/tag_group_female"
style="@style/DialogMessage"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="female"
android:button="@drawable/btn_check_dialog_material"
tools:ignore="HardcodedText" />
</TableRow>
+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/just_browse"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/just_browse" />
<CheckBox
android:id="@+id/have_read"
style="@style/Dialog.CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/have_read" />
</TableRow>
</TableLayout>
+9 -1
View File
@@ -14,9 +14,17 @@
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_filter"
android:title="@string/filter"
android:icon="@drawable/ic_action_filter"
android:showAsAction="ifRoom" />
<item
android:id="@+id/action_clear"
android:title="@string/clear"
android:icon="@drawable/ic_action_clear"
android:showAsAction="always" />
android:showAsAction="ifRoom" />
</menu>
+3
View File
@@ -171,6 +171,8 @@
<!-- History -->
<string name="clear_history_message">所有历史记录将被清除</string>
<string name="just_browse">仅浏览过</string>
<string name="have_read">已阅读过</string>
<!-- Settings -->
<string name="display_settings_title">显示</string>
@@ -343,6 +345,7 @@
<string name="rating0">…</string>
<!-- Utils -->
<string name="filter">过滤</string>
<string name="clear">清除</string>
<string name="history">历史</string>
<string name="warning">警告</string>
+8
View File
@@ -246,4 +246,12 @@
<style name="DropDownItem.Spinner">
</style>
<!-- Dialog -->
<style name="Dialog" parent="DialogMessage">
</style>
<style name="Dialog.CheckBox">
<item name="android:button">@drawable/btn_check_dialog_material</item>
</style>
</resources>
+1
View File
@@ -34,6 +34,7 @@
<!-- spinner -->
<item name="@android:spinnerDropDownItemStyle">@style/DropDownItem.Spinner</item>
<item name="@android:spinnerItemStyle">@style/DropDownItem.Spinner</item>
</style>
<style name="AppTheme.Normal">
+23 -18
View File
@@ -17,7 +17,6 @@
package com.hippo.ehviewer.data;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import android.content.ContentValues;
@@ -85,7 +84,6 @@ public class Data {
private List<Tag> mTags;
private List<GalleryInfo> mLocalFavourites;
private List<DownloadInfo> mDownloads;
private List<HistoryItem> mHistory;
private final Context mContext;
@@ -112,7 +110,6 @@ public class Data {
getTags();
getLocalFavourites();
getDownloads();
getHistory();
}
@Override
@@ -620,22 +617,40 @@ public class Data {
public static final int BROWSE = 0x1;
public static final int READ = 0x2;
private synchronized void getHistory() {
mHistory = new LinkedList<HistoryItem>();
Cursor cursor = mDatabase.rawQuery("select * from " + TABLE_HISTORY
+ " order by " + COLUMN_DATE + " desc", null);
public synchronized List<HistoryItem> getHistory(int mode, boolean desc) {
List<HistoryItem> history = new ArrayList<HistoryItem>();
StringBuilder sb = new StringBuilder();
sb.append("select * from ").append(TABLE_HISTORY);
boolean first = true;
if (mode != 0) {
sb.append(" where " + COLUMN_MODE + " in (");
for (int b = 1; b <= READ; b <<= 1) {
if ((mode & b) != 0) {
sb.append(first ? "" : ", ").append(b);
first = false;
}
}
sb.append(")");
}
sb.append(" order by ").append(COLUMN_DATE).append(desc ? " desc" : " asc");
Log.d(TAG, sb.toString());
Cursor cursor = mDatabase.rawQuery(sb.toString(), null);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
int gid = cursor.getInt(0);
GalleryInfo gi = getGallery(mDatabase, gid);
if (gi != null) {
mHistory.add(new HistoryItem(gi, cursor.getInt(1), cursor.getLong(2)));
history.add(new HistoryItem(gi, cursor.getInt(1), cursor.getLong(2)));
}
cursor.moveToNext();
}
}
cursor.close();
return history;
}
public synchronized int containsHistory(int gid) {
@@ -670,7 +685,6 @@ public class Data {
mDatabase.insert(TABLE_HISTORY, null, values);
addGallery(gi);
mHistory.add(0, new HistoryItem(gi, mode, curDate));
truncateHistory(Config.getMaxHistoryCount());
} else {
// Update record
@@ -679,16 +693,11 @@ public class Data {
mDatabase.update(TABLE_HISTORY, values,
COLUMN_GID + "=?", new String[]{String.valueOf(gi.gid)});
updateGallery(gi);
HistoryItem item = new HistoryItem(gi, mode, curDate);
mHistory.remove(item);
mHistory.add(0, item);
}
}
public void clearHistory() {
truncateHistory(0);
mHistory.clear();
}
protected synchronized void truncateHistory(int maxEntries) {
@@ -706,10 +715,6 @@ public class Data {
}
}
public synchronized List<HistoryItem> getAllHistory() {
return mHistory;
}
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
+92 -27
View File
@@ -19,10 +19,10 @@ package com.hippo.ehviewer.ui;
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.content.Context;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -33,6 +33,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
@@ -43,7 +44,6 @@ import com.hippo.ehviewer.app.MaterialAlertDialog;
import com.hippo.ehviewer.cardview.CardViewSalon;
import com.hippo.ehviewer.data.Data;
import com.hippo.ehviewer.data.GalleryInfo;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
@@ -53,21 +53,89 @@ import com.hippo.ehviewer.widget.RatingView;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public class HistoryActivity extends AbsGalleryActivity
implements AdapterView.OnItemClickListener {
implements AdapterView.OnItemClickListener, MaterialAlertDialog.OnClickListener {
private static final String TAG = HistoryActivity.class.getSimpleName();
private Context mContext;
private Data mData;
private Resources mResources;
private EhClient mClient;
private PullViewGroup mPullViewGroup;
private ListView mList;
private BaseAdapter mAdapter;
private int mFilterMode;
private Dialog mFilterDialog;
private CheckBox mJustBrowse;
private CheckBox mHaveRead;
private Dialog mClearDialog;
private static final String HISTORY_URL = "ehviewer://history";
private static final String KEY_HISTORY_FILTER = "history_filter";
private void setFilterDialogMode(int filterMode) {
if ((filterMode & Data.BROWSE) == 0)
mJustBrowse.setChecked(false);
else
mJustBrowse.setChecked(true);
if ((filterMode & Data.READ) == 0)
mHaveRead.setChecked(false);
else
mHaveRead.setChecked(true);
}
private int getFilterDialogMode() {
int filterMode = 0;
filterMode |= mJustBrowse.isChecked() ? Data.BROWSE : 0;
filterMode |= mHaveRead.isChecked() ? Data.READ : 0;
return filterMode;
}
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
if (dialog == mFilterDialog) {
switch (which) {
case MaterialAlertDialog.POSITIVE:
int newFilterMode = getFilterDialogMode();
if (newFilterMode != mFilterMode) {
mFilterMode = newFilterMode;
Config.setInt(KEY_HISTORY_FILTER, mFilterMode);
refresh();
}
}
return true;
} else if (dialog == mClearDialog) {
switch (which) {
case MaterialAlertDialog.POSITIVE:
Data.getInstance().clearHistory();
refresh();
}
return true;
}
return true;
}
@SuppressLint("InflateParams")
private void createFilterDialog() {
View view = LayoutInflater.from(this).inflate(R.layout.history_filter, null);
mJustBrowse = (CheckBox) view.findViewById(R.id.just_browse);
mHaveRead = (CheckBox) view.findViewById(R.id.have_read);
mFilterDialog = new MaterialAlertDialog.Builder(this).setTitle(R.string.filter)
.setView(view, true)
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
.setButtonListener(this).create();
}
private void createClearDialog() {
mClearDialog = new MaterialAlertDialog.Builder(this).setTitle(R.string.attention)
.setMessage(R.string.clear_history_message)
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
.setButtonListener(this).create();
}
@Override
public void onOrientationChanged(int paddingTop, int paddingBottom) {
@@ -91,10 +159,9 @@ public class HistoryActivity extends AbsGalleryActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getApplication();
mData = Data.getInstance();
mResources =getResources();
mClient = EhClient.getInstance();
mFilterMode = Config.getInt(KEY_HISTORY_FILTER, Data.BROWSE | Data.READ);
// Just avoid error
setBehindContentView(new View(this));
@@ -122,7 +189,8 @@ public class HistoryActivity extends AbsGalleryActivity
mList.setDivider(null);
mList.setOnItemClickListener(this);
refresh();
createFilterDialog();
createClearDialog();
}
@Override
@@ -137,22 +205,19 @@ public class HistoryActivity extends AbsGalleryActivity
case android.R.id.home:
finish();
return true;
case R.id.action_clear:
new MaterialAlertDialog.Builder(this).setTitle(R.string.attention)
.setMessage(R.string.clear_history_message)
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
switch (which) {
case MaterialAlertDialog.POSITIVE:
Data.getInstance().clearHistory();
refresh();
}
return true;
}
}).show();
case R.id.action_filter:
if (!mFilterDialog.isShowing()) {
setFilterDialogMode(mFilterMode);
mFilterDialog.show();
}
return true;
case R.id.action_clear:
if (!mClearDialog.isShowing())
mClearDialog.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
@@ -167,7 +232,7 @@ public class HistoryActivity extends AbsGalleryActivity
protected void doGetGallerys(String url, long taskStamp,
OnGetListListener listener) {
if (url.equals(HISTORY_URL)) {
List<GalleryInfo> giList = new ArrayList<GalleryInfo>(mData.getAllHistory());
List<GalleryInfo> giList = new ArrayList<GalleryInfo>(mData.getHistory(mFilterMode, true));
if (giList == null || giList.size() == 0)
listener.onSuccess(mAdapter, taskStamp, giList, 0);
else