添加列表默认分类显示

This commit is contained in:
seven332 committed 2014-07-23 17:26:24 +08:00
1 parent eaae310f05
commit 2ed2c08183
7 files changed
+276 -272

No files matched your search

+82 -123
View File
@@ -17,20 +17,24 @@
package com.hippo.ehviewer;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Util;
public class ListUrls {
public static final boolean NUM_CATEGORY = false;
// Mode
public static final int NORMAL = 0x0;
public static final int UPLOADER = 0x1;
public static final int TAG = 0x2;
public static final int POPULAR = 0x3;
// Search type
// Category
public static final int NONE = -1; // Use it for homepage
public static final int MISC = 0x1;
public static final int DOUJINSHI = 0x2;
public static final int MANGA = 0x4;
@@ -43,10 +47,10 @@ public class ListUrls {
public static final int WESTERN = 0x200;
public static final int UNKNOWN = 0x400;
public static final int ALL_TYPE = UNKNOWN - 1;
public static final int ALL_CATEGORT = UNKNOWN - 1;
//DOUJINSHI|MANGA|ARTIST_CG|GAME_CG|WESTERN|NON_H|IMAGE_SET|COSPLAY|ASIAN_PORN|MISC;
// advance search type
// advance search
public static final int SNAME = 0x1;
public static final int STAGS = 0x2;
public static final int SDESC = 0x4;
@@ -62,7 +66,7 @@ public class ListUrls {
private int mMode = NORMAL;
private int page = 0;
private int type = ALL_TYPE;
private int category = NONE;
private int advsearchType = -1;
private int minRating = -1;
@@ -73,33 +77,32 @@ public class ListUrls {
public ListUrls() {}
public ListUrls(int t) {
type = t;
page = 0;
public ListUrls(int category) {
this.category = category;
}
public ListUrls(int t, int p) {
type = t;
page = p;
public ListUrls(int category, int page) {
this.category = category;
this.page = page;
}
public ListUrls(int t, String s) {
type = t;
search = s;
public ListUrls(int category, String search) {
this.category = category;
this.search = search;
}
public ListUrls(int t, String s, int p) {
type = t;
search = s;
page = p;
public ListUrls(int category, String search, int page) {
this.category = category;
this.search = search;
this.page = page;
}
public void setType(int type) {
this.type = type;
public void setCategory(int category) {
this.category = category;
}
public int getType() {
return type;
public int getCategory() {
return category;
}
public String getSearch() {
@@ -170,130 +173,86 @@ public class ListUrls {
public String getUrl(int mode) {
StringBuilder url = new StringBuilder(EhClient.getUrlHeader(mode));
if (mMode == TAG) {
switch (mMode) {
case TAG:
// Add tag
url.append("tag/");
if (mTag != null) {
String[] searchItems = mTag.split("\\s+");
boolean firstItem = true;
for (String searcheItem : searchItems) {
try {
searcheItem = java.net.URLEncoder.encode(searcheItem, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (firstItem)
firstItem = false;
else
url.append('+');
url.append(searcheItem);
}
String[] tag = mTag.split("\\s+");
try {
for (int i = 0; i < tag.length; i++)
tag[i] = URLEncoder.encode(tag[i], "UTF-8");
} catch (UnsupportedEncodingException e) {}
url.append(Util.join(tag, '+'));
// Add page
url.append("/").append(page);
} else
url.append(page);
} else if (mMode == POPULAR) {
} else {
// Add type
if (NUM_CATEGORY) {
url.append(type);
url.append("?");
} else {
url.append("?");
if((type & DOUJINSHI) == 0)
url.append("f_doujinshi=0&");
else
url.append("f_doujinshi=1&");
if((type & MANGA) == 0)
url.append("f_manga=0&");
else
url.append("f_manga=1&");
if((type & ARTIST_CG) == 0)
url.append("f_artistcg=0&");
else
url.append("f_artistcg=1&");
if((type & GAME_CG) == 0)
url.append("f_gamecg=0&");
else
url.append("f_gamecg=1&");
if((type & WESTERN) == 0)
url.append("f_western=0&");
else
url.append("f_western=1&");
if((type & NON_H) == 0)
url.append("f_non-h=0&");
else
url.append("f_non-h=1&");
if((type & IMAGE_SET) == 0)
url.append("f_imageset=0&");
else
url.append("f_imageset=1&");
if((type & COSPLAY) == 0)
url.append("f_cosplay=0&");
else
url.append("f_cosplay=1&");
if((type & ASIAN_PORN) == 0)
url.append("f_asianporn=0&");
else
url.append("f_asianporn=1&");
if((type & MISC) == 0)
url.append("f_misc=0&");
else
url.append("f_misc=1&");
url.append(page);
}
break;
case POPULAR:
break;
case NORMAL:
case UPLOADER:
default:
boolean isNeedFooter = false;
// Add category
if (category != NONE) {
isNeedFooter = true;
if (NUM_CATEGORY) {
url.append(category).append('?');
} else {
url.append("?");
if ((category & DOUJINSHI) == 0) url.append("f_doujinshi=0&"); else url.append("f_doujinshi=1&");
if ((category & MANGA) == 0) url.append("f_manga=0&"); else url.append("f_manga=1&");
if ((category & ARTIST_CG) == 0) url.append("f_artistcg=0&"); else url.append("f_artistcg=1&");
if ((category & GAME_CG) == 0) url.append("f_gamecg=0&"); else url.append("f_gamecg=1&");
if ((category & WESTERN) == 0) url.append("f_western=0&"); else url.append("f_western=1&");
if ((category & NON_H) == 0) url.append("f_non-h=0&"); else url.append("f_non-h=1&");
if ((category & IMAGE_SET) == 0) url.append("f_imageset=0&"); else url.append("f_imageset=1&");
if ((category & COSPLAY) == 0) url.append("f_cosplay=0&"); else url.append("f_cosplay=1&");
if ((category & ASIAN_PORN) == 0) url.append("f_asianporn=0&"); else url.append("f_asianporn=1&");
if ((category & MISC) == 0) url.append("f_misc=0&"); else url.append("f_misc=1&");
}
} else {
url.append('?');
}
// Add search
// Add search item
if (search != null) {
isNeedFooter = true;
url.append("f_search=");
String[] searchItems = search.split("\\s+");
boolean firstItem = true;
for (String searcheItem : searchItems) {
try {
searcheItem = java.net.URLEncoder.encode(searcheItem, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (firstItem)
firstItem = false;
else
url.append('+');
url.append(searcheItem);
}
url.append("&");
String[] tag = mTag.split("\\s+");
try {
for (int i = 0; i < tag.length; i++)
tag[i] = URLEncoder.encode(tag[i], "UTF-8");
} catch (UnsupportedEncodingException e) {}
url.append(Util.join(tag, '+')).append("&");
}
// Add page
url.append("page=").append(page).append("&");
// Add foot
url.append("f_apply=Apply+Filter");
if (isNeedFooter) url.append("f_apply=Apply+Filter");
// Is advance search
// Add advance search
if (isAdvance()) {
url.append("&advsearch=1");
if((advsearchType & SNAME) != 0)
url.append("&f_sname=on");
if((advsearchType & STAGS) != 0)
url.append("&f_stags=on");
if((advsearchType & SDESC) != 0)
url.append("&f_sdesc=on");
if((advsearchType & STORR) != 0)
url.append("&f_storr=on");
if((advsearchType & STO) != 0)
url.append("&f_sto=on");
if((advsearchType & STD1) != 0)
url.append("&f_sdt1=on");
if((advsearchType & STD2) != 0)
url.append("&f_sdt2=on");
if((advsearchType & SH) != 0)
url.append("&f_sh=on");
if((advsearchType & SNAME) != 0) url.append("&f_sname=on");
if((advsearchType & STAGS) != 0) url.append("&f_stags=on");
if((advsearchType & SDESC) != 0) url.append("&f_sdesc=on");
if((advsearchType & STORR) != 0) url.append("&f_storr=on");
if((advsearchType & STO) != 0) url.append("&f_sto=on");
if((advsearchType & STD1) != 0) url.append("&f_sdt1=on");
if((advsearchType & STD2) != 0) url.append("&f_sdt2=on");
if((advsearchType & SH) != 0) url.append("&f_sh=on");
// Set min star
if (isMinRating())
url.append("&f_sr=on&f_srdd=").append(minRating);
if (isMinRating()) url.append("&f_sr=on&f_srdd=").append(minRating);
}
}
+105 -107
View File
@@ -17,11 +17,7 @@
package com.hippo.ehviewer.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.hippo.ehviewer.Analytics;
import android.content.ContentValues;
import android.content.Context;
@@ -31,23 +27,25 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.util.SparseArray;
import com.hippo.ehviewer.Analytics;
/**
* @author Hippo
*
*
*/
public class Data {
private static final String TAG = "Data";
private static final int mVersion = 1;
private static final String DB_NAME = "data";
private static final String TABLE_GALLERY = "gallery";
private static final String TABLE_READ = "read";
private static final String TABLE_LOCAL_FAVOURITE = "local_favourite";
private static final String TABLE_TAG = "tag";
private static final String TABLE_DOWNLOAD = "download";
private static final String COLUMN_GID = "gid";
private static final String COLUMN_TOKEN = "token";
private static final String COLUMN_TITLE = "title";
@@ -57,7 +55,7 @@ public class Data {
private static final String COLUMN_UPLOADER = "uploader";
private static final String COLUMN_RATING = "rating";
private static final String COLUMN_REFERENCE = "reference";
private static final String COLUMN_ID = "id";
private static final String COLUMN_NAME = "name";
private static final String COLUMN_MODE = "mode";
@@ -65,49 +63,49 @@ public class Data {
private static final String COLUMN_ADVANCE = "advance";
private static final String COLUMN_MIN_RATING = "min_rating";
private static final String COLUMN_TAG = "tag";
private static final String COLUMN_STATE = "state";
private static final String COLUMN_PAGES = "pages";
private static final String COLUMN_DETAIL = "detail";
private static final String COLUMN_START_PAGE = "start_page";
private SparseArray<GalleryInfo> mGallerys;
private final SparseArray<GalleryInfo> mGallerys;
private long mTagRowNum;
private List<Tag> mTags;
private List<GalleryInfo> mLocalFavourites;
private List<GalleryInfo> mReads;
private long mDownloadRowNum;
private List<DownloadInfo> mDownloads;
private Context mContext;
private DBHelper mDBHelper;
private SQLiteDatabase mDatabase;
private final Context mContext;
private final DBHelper mDBHelper;
private final SQLiteDatabase mDatabase;
public Data(Context context) {
mContext = context;
mDBHelper = new DBHelper(mContext);
mDatabase = mDBHelper.getWritableDatabase();
mGallerys = new SparseArray<GalleryInfo>();
getTags();
getReads();
getLocalFavourites();
getDownloads();
}
@Override
public void finalize() {
mDBHelper.close();
}
/****** gallery ******/
/**
* Get galleryInfo in table, if do not exits return null
*
*
* @param gid
* @return
*/
@@ -126,7 +124,7 @@ public class Data {
galleryInfo.thumb = cursor.getString(5);
galleryInfo.uploader = cursor.getString(6);
galleryInfo.rating = cursor.getFloat(7);
// add to map
mGallerys.put(gid, galleryInfo);
}
@@ -134,7 +132,7 @@ public class Data {
}
return galleryInfo;
}
@SuppressWarnings("unused")
private synchronized boolean containsGallery(int gid) {
boolean re = false;
@@ -146,7 +144,7 @@ public class Data {
cursor.close();
return re;
}
/**
* If do not contain the gallery return -1;
* @param gid
@@ -163,12 +161,12 @@ public class Data {
cursor.close();
return reference;
}
/**
*
*
* If exits same gid, add the reference by 1.
* If exits no same gid, add it to table reference is 1
*
*
* @param galleryInfo
*/
private void addGallery(GalleryInfo galleryInfo) {
@@ -176,7 +174,7 @@ public class Data {
int gid = galleryInfo.gid;
// add to map
mGallerys.put(gid, galleryInfo);
// add to sql or update and add reference by 1
int reference;
if ((reference = getGalleryReference(gid)) != -1) {
@@ -187,7 +185,7 @@ public class Data {
isInsert = true;
reference = 1;
}
ContentValues values = new ContentValues();
values.put(COLUMN_GID, gid);
values.put(COLUMN_TOKEN, galleryInfo.token);
@@ -198,17 +196,17 @@ public class Data {
values.put(COLUMN_UPLOADER, galleryInfo.uploader);
values.put(COLUMN_RATING, galleryInfo.rating);
values.put(COLUMN_REFERENCE, reference);
if (isInsert) { // Set
mDatabase.insert(TABLE_GALLERY, null, values);
} else { // Update
mDatabase.update(TABLE_GALLERY, values, COLUMN_GID + "=?", new String[]{String.valueOf(gid)});
}
}
/**
* True if update
*
*
* @param gid
* @return
*/
@@ -222,11 +220,11 @@ public class Data {
values.put(COLUMN_THUMB, galleryInfo.thumb);
values.put(COLUMN_UPLOADER, galleryInfo.uploader);
values.put(COLUMN_RATING, galleryInfo.rating);
return mDatabase.update(TABLE_GALLERY, values,
COLUMN_GID + "=?", new String[]{String.valueOf(galleryInfo.gid)}) != 0;
}
/**
* decrease reference by 1, only delete when reference is 0
* @param gid
@@ -250,12 +248,12 @@ public class Data {
}
return true;
}
/****** download ******/
private synchronized void getDownloads() {
mDownloads = new ArrayList<DownloadInfo>();
mDownloadRowNum = 0;
Cursor cursor = mDatabase.rawQuery("select * from " + TABLE_DOWNLOAD
+ " order by " + COLUMN_ID + " asc", null);
if (cursor.moveToFirst()) {
@@ -269,17 +267,17 @@ public class Data {
DownloadInfo downloadInfo = new DownloadInfo(
galleryInfo, state, pages, detail, startPage);
mDownloads.add(downloadInfo);
cursor.moveToNext();
mDownloadRowNum++;
}
}
cursor.close();
}
/**
* True if contain this item
*
*
* @param gid
* @return
*/
@@ -293,7 +291,7 @@ public class Data {
cursor.close();
return re;
}
public synchronized boolean addDownload(DownloadInfo downloadInfo) {
GalleryInfo galleryInfo = downloadInfo.getGalleryInfo();
int gid = galleryInfo.gid;
@@ -305,7 +303,7 @@ public class Data {
return false;
} else {
addGallery(galleryInfo);
// add to sql
ContentValues values = new ContentValues();
values.put(COLUMN_ID, mDownloadRowNum);
@@ -324,19 +322,19 @@ public class Data {
}
}
}
public synchronized boolean deleteDownload(int id) {
int deleteNum = mDatabase.delete(TABLE_DOWNLOAD, COLUMN_ID + "=?", new String[]{String.valueOf(id)});
if (deleteNum > 1)
Log.e(TAG, "WTF? more than one id is " + id);
if (deleteNum == 0)
return false;
if (id < 0 || id >= mDownloads.size()) {
Log.e(TAG, "id is out of bounds, id is " + id + ", mDownloads.size() is " + mDownloads.size());
return false;
}
// delete from sql
ContentValues values = new ContentValues();
for (int i = id + 1; i < mDownloadRowNum; i++) {
@@ -344,35 +342,35 @@ public class Data {
mDatabase.update(TABLE_DOWNLOAD, values, COLUMN_ID + "=?", new String[]{String.valueOf(i)});
}
mDownloadRowNum -= deleteNum;
// delete from list
DownloadInfo downloadInfo = mDownloads.remove(id);
// sub reference
if (downloadInfo != null) {
deleteGallery(downloadInfo.getGalleryInfo().gid);
} else {
Log.e(TAG, id + " of mDownloads is null");
}
return true;
}
public synchronized List<DownloadInfo> getAllDownloads() {
return mDownloads;
}
public synchronized DownloadInfo getDownload(int location) {
return mDownloads.get(location);
}
public synchronized void setDownload(int location, DownloadInfo downloadInfo) {
if (location == mDownloadRowNum) {
addDownload(downloadInfo);
} else {
// Update list
mDownloads.set(location, downloadInfo);
// Update sql
GalleryInfo galleryInfo = downloadInfo.getGalleryInfo();
ContentValues values = new ContentValues();
@@ -382,24 +380,24 @@ public class Data {
values.put(COLUMN_DETAIL, downloadInfo.getDetail());
values.put(COLUMN_START_PAGE, downloadInfo.getStartPage());
mDatabase.update(TABLE_DOWNLOAD, values, COLUMN_ID + "=?", new String[]{String.valueOf(location)});
// Update gallery
updateGallery(galleryInfo);
}
}
public synchronized void notifyDownloadChange(int location) {
setDownload(location, mDownloads.get(location));
}
public synchronized boolean swapDownload(int indexOne, int indexTwo) {
if (indexOne < 0 || indexOne > mDownloadRowNum
|| indexTwo < 0 || indexTwo > mDownloadRowNum)
return false;
if (indexOne == indexTwo)
return true;
// Update list
DownloadInfo temp = mDownloads.get(indexOne);
mDownloads.set(indexOne, mDownloads.get(indexTwo));
@@ -414,13 +412,13 @@ public class Data {
mDatabase.update(TABLE_DOWNLOAD, values, COLUMN_ID + "=?", new String[]{String.valueOf(-1)});
return true;
}
/****** read ******/
private synchronized void getReads() {
mReads = new ArrayList<GalleryInfo>();
Cursor cursor = mDatabase.rawQuery("select * from "
+ TABLE_READ, null);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
int gid = cursor.getInt(0);
@@ -431,11 +429,11 @@ public class Data {
}
cursor.close();
}
public synchronized List<GalleryInfo> getAllReads() {
return mReads;
}
public synchronized boolean containsRead(int gid) {
boolean re = false;
Cursor cursor = mDatabase.rawQuery("select * from "
@@ -446,13 +444,13 @@ public class Data {
cursor.close();
return re;
}
public synchronized void addRead(GalleryInfo galleryInfo) {
int gid = galleryInfo.gid;
// Do not add to read if it in download
if (containsDownload(gid))
return;
if (containsRead(gid)) {
updateGallery(galleryInfo);
} else {
@@ -465,7 +463,7 @@ public class Data {
mReads.add(galleryInfo);
}
}
public synchronized void deleteRead(int gid) {
// delete from list
for (GalleryInfo galleryInfo : mReads) {
@@ -474,16 +472,16 @@ public class Data {
break;
}
}
// delete from sql
mDatabase.delete(TABLE_READ, COLUMN_GID + "=?", new String[]{String.valueOf(gid)});
deleteGallery(gid);
}
public synchronized void deleteAllReads() {
// delete from list
mReads.clear();
// delete from sql
Cursor cursor = mDatabase.rawQuery("select * from "
+ TABLE_READ, null);
@@ -497,13 +495,13 @@ public class Data {
cursor.close();
mDatabase.delete(TABLE_READ, null, null);
}
/****** local favourite ******/
private synchronized void getLocalFavourites() {
mLocalFavourites = new ArrayList<GalleryInfo>();
Cursor cursor = mDatabase.rawQuery("select * from "
+ TABLE_LOCAL_FAVOURITE, null);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
int gid = cursor.getInt(0);
@@ -514,7 +512,7 @@ public class Data {
}
cursor.close();
}
public synchronized boolean containsLocalFavourite(int gid) {
boolean re = false;
Cursor cursor = mDatabase.rawQuery("select * from "
@@ -525,14 +523,14 @@ public class Data {
cursor.close();
return re;
}
/**
* galleryInfo can't be null
* @param galleryInfo
*/
public synchronized void addLocalFavourite(GalleryInfo galleryInfo) {
int gid = galleryInfo.gid;
if (containsLocalFavourite(gid)) {
updateGallery(galleryInfo);
} else {
@@ -543,12 +541,12 @@ public class Data {
mDatabase.insert(TABLE_LOCAL_FAVOURITE, null, values);
// add to list
mLocalFavourites.add(galleryInfo);
// Analytics
Analytics.addToFavoriteGallery(mContext, gid, galleryInfo.token);
}
}
public synchronized void deleteLocalFavourite(int gid) {
// delete from list
for (GalleryInfo galleryInfo : mLocalFavourites) {
@@ -557,16 +555,16 @@ public class Data {
break;
}
}
// delete from sql
mDatabase.delete(TABLE_LOCAL_FAVOURITE, COLUMN_GID + "=?", new String[]{String.valueOf(gid)});
deleteGallery(gid);
}
public synchronized List<GalleryInfo> getAllLocalFavourites() {
return mLocalFavourites;
}
/****** tag ******/
private synchronized void getTags() {
mTags = new ArrayList<Tag>();
@@ -575,7 +573,7 @@ public class Data {
+ " order by " + COLUMN_ID + " asc", null);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
String name = cursor.getString(1);
int mode = cursor.getInt(2);
int category = cursor.getInt(3);
@@ -583,32 +581,32 @@ public class Data {
int advance = cursor.getInt(5);
int min_rating = cursor.getInt(6);
String tagStr = cursor.getString(7);
Tag tag = new Tag(name, category, search);
tag.setAdvance(advance, min_rating);
tag.setTag(tagStr);
tag.setMode(mode);
mTags.add(tag);
cursor.moveToNext();
mTagRowNum++;
}
}
cursor.close();
}
public synchronized boolean addTag(Tag tag) {
ContentValues values = new ContentValues();
values.put(COLUMN_ID, mTagRowNum);
values.put(COLUMN_NAME, tag.getName());
values.put(COLUMN_MODE, tag.getMode());
values.put(COLUMN_CATEGORY, tag.getType());
values.put(COLUMN_CATEGORY, tag.getCategory());
values.put(COLUMN_SEARCH, tag.getSearch());
values.put(COLUMN_ADVANCE, tag.getAdvanceType());
values.put(COLUMN_MIN_RATING, tag.getMinRating());
values.put(COLUMN_TAG, tag.getTag());
boolean ok = mDatabase.insert(
TABLE_TAG, null, values) != -1;
if (ok) {
@@ -617,19 +615,19 @@ public class Data {
}
return ok;
}
public synchronized boolean deleteTag(int id) {
int deleteNum = mDatabase.delete(TABLE_TAG, COLUMN_ID + "=?", new String[]{String.valueOf(id)});
if (deleteNum > 1)
Log.e(TAG, "WTF? more than one id is " + id);
if (deleteNum == 0)
return false;
if (id < 0 || id >= mTags.size()) {
Log.e(TAG, "id is out of bounds, id is " + id + ", mTags.size() is " + mTags.size());
return false;
}
// Update sql
ContentValues values = new ContentValues();
for (int i = id + 1; i < mTagRowNum; i++) {
@@ -637,28 +635,28 @@ public class Data {
mDatabase.update(TABLE_TAG, values, COLUMN_ID + "=?", new String[]{String.valueOf(i)});
}
mTagRowNum -= deleteNum;
// Update list
mTags.remove(id);
return true;
}
public synchronized List<Tag> getAllTags() {
return mTags;
}
public synchronized Tag getTag(int location) {
return mTags.get(location);
}
public synchronized List<String> getAllTagNames() {
List<String> names = new ArrayList<String>();
for (Tag tag : mTags)
names.add(tag.getName());
return names;
}
/**
* location >= 0 && location <= tagRowNum please
* @param location
@@ -670,26 +668,26 @@ public class Data {
} else {
// Update list
mTags.set(location, tag);
// Update sql
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, tag.getName());
values.put(COLUMN_CATEGORY, tag.getType());
values.put(COLUMN_CATEGORY, tag.getCategory());
values.put(COLUMN_SEARCH, tag.getSearch());
values.put(COLUMN_ADVANCE, tag.getAdvanceType());
values.put(COLUMN_MIN_RATING, tag.getMinRating());
mDatabase.update(TABLE_TAG, values, COLUMN_ID + "=?", new String[]{String.valueOf(location)});
}
}
public synchronized boolean swapTag(int indexOne, int indexTwo) {
if (indexOne < 0 || indexOne > mTagRowNum
|| indexTwo < 0 || indexTwo > mTagRowNum)
return false;
if (indexOne == indexTwo)
return true;
// Update list
Tag temp = mTags.get(indexOne);
mTags.set(indexOne, mTags.get(indexTwo));
@@ -704,7 +702,7 @@ public class Data {
mDatabase.update(TABLE_TAG, values, COLUMN_ID + "=?", new String[]{String.valueOf(-1)});
return true;
}
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
@@ -725,21 +723,21 @@ public class Data {
+ COLUMN_RATING + " float,"
+ COLUMN_REFERENCE + " integer);";
db.execSQL(CreateGallery);
// read
String CreateRead = "create table "
+ TABLE_READ + "("
+ COLUMN_GID + " integer primary key,"
+ "foreign key(" + COLUMN_GID + ") references " + TABLE_GALLERY + "(" + COLUMN_GID + "));";
db.execSQL(CreateRead);
// local favourite
String CreateLocalFavourite = "create table "
+ TABLE_LOCAL_FAVOURITE + "("
+ COLUMN_GID + " integer primary key,"
+ "foreign key(" + COLUMN_GID + ") references " + TABLE_GALLERY + "(" + COLUMN_GID + "));";
db.execSQL(CreateLocalFavourite);
// tag
String CreateTag = "create table "
+ TABLE_TAG + "("
@@ -752,7 +750,7 @@ public class Data {
+ COLUMN_MIN_RATING + " integer,"
+ COLUMN_TAG + " text);";
db.execSQL(CreateTag);
// download
String CreateDownload = "create table "
+ TABLE_DOWNLOAD + "("
@@ -765,7 +763,7 @@ public class Data {
+ "foreign key(" + COLUMN_GID + ") references " + TABLE_GALLERY + "(" + COLUMN_GID + "));";
db.execSQL(CreateDownload);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists " + TABLE_GALLERY);
+5 -5
View File
@@ -20,23 +20,23 @@ import com.hippo.ehviewer.ListUrls;
public class Tag extends ListUrls {
private String mName;
public Tag(String name, int category, String search) {
super(category, search);
mName = name;
}
public Tag(String name, ListUrls lus) {
this(name, lus.getType(), lus.getSearch());
this(name, lus.getCategory(), lus.getSearch());
setAdvance(lus.getAdvanceType(), lus.getMinRating());
setTag(lus.getTag());
setMode(lus.getMode());
}
public void setName(String name) {
mName = name;
}
public String getName() {
return mName;
}
@@ -676,7 +676,7 @@ public class MangaListActivity extends AbstractGalleryActivity
searchNormal.setVisibility(View.VISIBLE);
searchTag.setVisibility(View.GONE);
int category = listUrls.getType();
int category = listUrls.getCategory();
CategoryTable ct = (CategoryTable) view
.findViewById(R.id.category_table);
ct.setCategory(category);
@@ -795,7 +795,7 @@ public class MangaListActivity extends AbstractGalleryActivity
case ListUrls.UPLOADER:
String uploader = "uploader:" + intent.getStringExtra(KEY_UPLOADER);
lus = new ListUrls(ListUrls.ALL_TYPE, uploader);
lus = new ListUrls(ListUrls.NONE, uploader);
lus.setMode(ListUrls.UPLOADER);
mTitle = uploader;
setTitle(mTitle);
@@ -979,7 +979,7 @@ public class MangaListActivity extends AbstractGalleryActivity
switch (position) {
case 0: // Home page
ListUrls backup = lus;
lus = new ListUrls(ListUrls.ALL_TYPE, null, 0);
lus = new ListUrls(ListUrls.NONE, null, 0);
if (refresh(false)) {
mTitle = mResources.getString(R.string.homepage);
setTitle(mTitle);
@@ -1194,7 +1194,7 @@ public class MangaListActivity extends AbstractGalleryActivity
t = query;
ListUrls backup = lus;
lus = new ListUrls(ListUrls.ALL_TYPE, query);
lus = new ListUrls(ListUrls.NONE, query);
if (refresh(false)) {
mTitle = t;
setTitle(mTitle);
@@ -61,6 +61,7 @@ import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.Util;
import com.hippo.ehviewer.widget.AlertButton;
import com.hippo.ehviewer.widget.CategoryTable;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.FileExplorerView;
import com.hippo.ehviewer.widget.SuperDialogUtil;
@@ -370,8 +371,30 @@ public class SettingsActivity extends AbstractPreferenceActivity {
public boolean onPreferenceClick(Preference preference) {
final String key = preference.getKey();
if (KEY_LIST_DEFAULT_CATEGORY.equals(key)) {
DialogBuilder dialogBuilder = new DialogBuilder(mActivity)
.setTitle("");
int defaultCat = Config.getDefaultCat();
final CategoryTable ct = new CategoryTable(mActivity);
ct.setCategory(defaultCat);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
int margin = Ui.dp2pix(12);
lp.leftMargin = margin;
lp.topMargin = margin;
lp.rightMargin = margin;
lp.bottomMargin = margin;
new DialogBuilder(mActivity)
.setTitle(R.string.list_default_category)
.setView(ct, lp).setSimpleNegativeButton()
.setPositiveButton(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
((AlertButton)v).dialog.dismiss();
int defaultCat = ct.getCategory();
Config.setDefaultCat(defaultCat);
EhInfo.getInstance(mActivity).setDefaultCat(defaultCat);
}
}).create().show();
}
return true;
}
+6 -1
View File
@@ -22,6 +22,7 @@ import android.content.pm.ActivityInfo;
import android.os.Environment;
import android.preference.PreferenceManager;
import com.hippo.ehviewer.ListUrls;
import com.hippo.ehviewer.ehclient.EhClient;
public class Config {
@@ -331,7 +332,7 @@ public class Config {
/****** For Eh Config ******/
private static final String KEY_DEFAULT_CAT = "default_cat";
private static final int DEFAULT_DEFAULT_CAT = 0;
private static final int DEFAULT_DEFAULT_CAT = ListUrls.ALL_CATEGORT;
// m for normal, l for large
public static final String KEY_PREVIEW_MODE = "preview_mode";
@@ -381,6 +382,10 @@ public class Config {
return mConfigPre.getInt(KEY_DEFAULT_CAT, DEFAULT_DEFAULT_CAT);
}
public static void setDefaultCat(int defaultCat) {
mConfigPre.edit().putInt(KEY_DEFAULT_CAT, defaultCat).apply();
}
public static String getPreviewMode() {
return mConfigPre.getString(KEY_PREVIEW_MODE, DEFAULT_PREVIEW_MODE);
}
+49 -30
View File
@@ -37,23 +37,23 @@ import android.view.View;
public class Util {
@SuppressWarnings("unused")
private static String TAG = "Util";
/**
* Put InputStream to File, default bufferSize is 512 * 1024
*
*
* @param is
* @param file
* @throws IOException
* @throws IOException
*/
public static void inputStream2File(InputStream is, File file) throws IOException {
OutputStream os = new FileOutputStream(file);
copy(is, os);
}
public static void copy(InputStream is, OutputStream os) throws IOException {
copy(is, os, 512 * 1024);
}
public static void copy(InputStream is, OutputStream os, int size) throws IOException {
byte[] buffer = new byte[size];
int bytesRead;
@@ -64,10 +64,10 @@ public class Util {
os.close();
buffer = null;
}
public static final int BITMAP = 0x0;
public static final int MOVIE = 0x1;
public static int getResourcesType(String url) {
int type = BITMAP;
int index = url.lastIndexOf('.');
@@ -75,7 +75,7 @@ public class Util {
type = MOVIE;
return type;
}
public static String getExtension(String url) {
int index = url.lastIndexOf('.');
if (index != -1)
@@ -83,7 +83,7 @@ public class Util {
else
return "png";
}
public static String getName(String fileName) {
int index = fileName.lastIndexOf('.');
if (index != -1)
@@ -91,7 +91,7 @@ public class Util {
else
return "png";
}
public static boolean isNumber(String str) {
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
@@ -100,7 +100,7 @@ public class Util {
}
return true;
}
public static String byteArrayToHexString(byte[] b) {
StringBuilder sb = new StringBuilder(b.length * 2);
for (byte element : b) {
@@ -122,10 +122,10 @@ public class Util {
}
return data;
}
/**
* Convernt context in stream to string
*
*
* @param is
* @param charset
* @return
@@ -143,7 +143,7 @@ public class Util {
}
return str;
}
public static String getFileForUrl(String url) {
String file = null;
int index = url.lastIndexOf("/");
@@ -152,14 +152,14 @@ public class Util {
else
return url.substring(index + 1);
}
public static String[] getStrings(SharedPreferences shaper, String key) {
String str = shaper.getString(key, null);
if (str == null || str.length() == 0)
return null;
return new String(Util.hexStringToByteArray(str)).split("\n");
}
public static void putStrings(SharedPreferences shaper, String key, List<String> strs) {
StringBuffer sb = new StringBuffer();
for (String item : strs) {
@@ -171,7 +171,7 @@ public class Util {
sb.delete(length - 1, length);
shaper.edit().putString(key, byteArrayToHexString(sb.toString().getBytes())).apply();
}
public static void closeStreamQuietly (Closeable is) {
try {
if (is != null)
@@ -179,10 +179,10 @@ public class Util {
} catch (IOException e) {
}
}
/**
* Delete dir and it child file and dir
*
*
* @param dir
* The dir to deleted
* @throws IOException
@@ -201,7 +201,7 @@ public class Util {
}
}
}
@SuppressLint("SimpleDateFormat")
public static int getDate() {
int time = 0;
@@ -210,14 +210,14 @@ public class Util {
} catch (NumberFormatException e) {}
return time;
}
private static String[] SIZE_UNIT = {"%.2f B", "%.2f KB", "%.2f MB", "%.2f GB"};
public static String sizeToString(long size) {
int length = SIZE_UNIT.length;
float sizeFloat = (float)size;
float sizeFloat = size;
for (int i = 0; i < length; i++) {
if (sizeFloat < 1024 || i == length - 1) {
return String.format(SIZE_UNIT[i], sizeFloat);
@@ -226,10 +226,10 @@ public class Util {
}
return null;
}
/**
* Execute an {@link AsyncTask} on a thread pool
*
*
* @param forceSerial True to force the task to run in serial order
* @param task Task to execute
* @param args Optional arguments to pass to
@@ -249,7 +249,7 @@ public class Util {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
}
}
/**
* Method that removes the support for HardwareAcceleration from a {@link View}.<br/>
* <br/>
@@ -268,7 +268,7 @@ public class Util {
v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
/**
* Mostly title and url need it
* @param str
@@ -281,7 +281,7 @@ public class Util {
.replace("&quot;", "\"")
.replace("&#039;", "'");
}
/**
* Make file name valid by removing invalid character and set max length
* @param name
@@ -291,4 +291,23 @@ public class Util {
name = name.replaceAll("[\\\\|/|:|*|?|\"|<|>|\\|]", "");
return name.length() > 255 ? name.substring(0, 255) : name;
}
/**
* Joins the elements of the provided array into a single String
* containing the provided list of elements.
*
* @param array
* @param separator
* @return
*/
public static String join(final String[] array,
final Object separator) {
final StringBuilder sb = new StringBuilder(array.length * 16);
for (int i = 0; i < array.length; i++) {
if (i != 0)
sb.append(separator);
sb.append(array[i]);
}
return sb.toString();
}
}