use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.
the class CommonOperations method addToFavorites.
public static void addToFavorites(final Activity activity, final GalleryInfo galleryInfo, final EhClient.Callback<Void> listener) {
int slot = Settings.getDefaultFavSlot();
String[] items = new String[11];
items[0] = activity.getString(R.string.local_favorites);
String[] favCat = Settings.getFavCat();
System.arraycopy(favCat, 0, items, 1, 10);
if (slot >= -1 && slot <= 9) {
String newFavoriteName = slot >= 0 ? items[slot + 1] : null;
doAddToFavorites(activity, galleryInfo, slot, new DelegateFavoriteCallback(listener, galleryInfo, newFavoriteName, slot));
} else {
new ListCheckBoxDialogBuilder(activity, items, (builder, dialog, position) -> {
int slot1 = position - 1;
String newFavoriteName = (slot1 >= 0 && slot1 <= 9) ? items[slot1 + 1] : null;
doAddToFavorites(activity, galleryInfo, slot1, new DelegateFavoriteCallback(listener, galleryInfo, newFavoriteName, slot1));
if (builder.isChecked()) {
Settings.putDefaultFavSlot(slot1);
} else {
Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT);
}
}, activity.getString(R.string.remember_favorite_collection), false).setTitle(R.string.add_favorites_dialog_title).setOnCancelListener(dialog -> listener.onCancel()).show();
}
}
use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.
the class GalleryListScene method onItemLongClick.
@Override
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
final Context context = getContext2();
final MainActivity activity = getActivity2();
if (null == context || null == activity || null == mHelper) {
return false;
}
final GalleryInfo gi = mHelper.getDataAtEx(position);
if (gi == null) {
return true;
}
boolean downloaded = mDownloadManager.getDownloadState(gi.gid) != DownloadInfo.STATE_INVALID;
boolean favourited = gi.favoriteSlot != -2;
CharSequence[] items = new CharSequence[] { context.getString(R.string.read), context.getString(downloaded ? R.string.delete_downloads : R.string.download), context.getString(favourited ? R.string.remove_from_favourites : R.string.add_to_favourites) };
int[] icons = new int[] { R.drawable.v_book_open_x24, downloaded ? R.drawable.v_delete_x24 : R.drawable.v_download_x24, favourited ? R.drawable.v_heart_broken_x24 : R.drawable.v_heart_x24 };
new AlertDialog.Builder(context).setTitle(EhUtils.getSuitableTitle(gi)).setAdapter(new SelectItemWithIconAdapter(context, items, icons), (dialog, which) -> {
switch(which) {
case // Read
0:
Intent intent = new Intent(activity, GalleryActivity.class);
intent.setAction(GalleryActivity.ACTION_EH);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, gi);
startActivity(intent);
break;
case // Download
1:
if (downloaded) {
new AlertDialog.Builder(context).setTitle(R.string.download_remove_dialog_title).setMessage(getString(R.string.download_remove_dialog_message, gi.title)).setPositiveButton(android.R.string.ok, (dialog1, which1) -> mDownloadManager.deleteDownload(gi.gid)).show();
} else {
CommonOperations.startDownload(activity, gi, false);
}
break;
case // Favorites
2:
if (favourited) {
CommonOperations.removeFromFavorites(activity, gi, new RemoveFromFavoriteListener(context, activity.getStageId(), getTag()));
} else {
CommonOperations.addToFavorites(activity, gi, new AddToFavoriteListener(context, activity.getStageId(), getTag()));
}
break;
}
}).show();
return true;
}
use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.
the class GalleryInfoContentHelper method restoreInstanceState.
@Override
protected Parcelable restoreInstanceState(Parcelable state) {
Bundle bundle = (Bundle) state;
int id = bundle.getInt(KEY_DATA_MAP, IntIdGenerator.INVALID_ID);
if (id != IntIdGenerator.INVALID_ID) {
FavouriteStatusRouter router = EhApplication.getFavouriteStatusRouter();
Map<Long, GalleryInfo> map = router.restoreDataMap(id);
if (map != null) {
this.map = map;
}
}
return super.restoreInstanceState(state);
}
use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.
the class DownloadManager method resetAllReadingProgress.
@SuppressLint("StaticFieldLeak")
public void resetAllReadingProgress() {
LinkedList<DownloadInfo> list = new LinkedList<>(mAllInfoList);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
GalleryInfo galleryInfo = new GalleryInfo();
for (DownloadInfo downloadInfo : list) {
galleryInfo.gid = downloadInfo.gid;
galleryInfo.token = downloadInfo.token;
galleryInfo.title = downloadInfo.title;
galleryInfo.thumb = downloadInfo.thumb;
galleryInfo.category = downloadInfo.category;
galleryInfo.posted = downloadInfo.posted;
galleryInfo.uploader = downloadInfo.uploader;
galleryInfo.rating = downloadInfo.rating;
UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo);
if (downloadDir == null) {
continue;
}
UniFile file = downloadDir.findFile(".ehviewer");
if (file == null) {
continue;
}
SpiderInfo spiderInfo = SpiderInfo.read(file);
if (spiderInfo == null) {
continue;
}
spiderInfo.startPage = 0;
try {
spiderInfo.write(file.openOutputStream());
} catch (IOException e) {
Log.e(TAG, "Can't write SpiderInfo", e);
}
}
return null;
}
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
}
use of com.hippo.ehviewer.client.data.GalleryInfo in project EhViewer by seven332.
the class EhDB method getAllLocalFavorites.
public static synchronized List<GalleryInfo> getAllLocalFavorites() {
LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
List<LocalFavoriteInfo> list = dao.queryBuilder().orderDesc(LocalFavoritesDao.Properties.Time).list();
List<GalleryInfo> result = new ArrayList<>();
result.addAll(list);
return result;
}
Aggregations