Search in sources :

Example 6 with GalleryInfo

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();
    }
}
Also used : DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel) AlertDialog(androidx.appcompat.app.AlertDialog) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ListCheckBoxDialogBuilder(com.hippo.app.ListCheckBoxDialogBuilder) IOUtils(com.hippo.yorozuya.IOUtils) PackageInfo(android.content.pm.PackageInfo) Html(com.hippo.text.Html) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Response(okhttp3.Response) Log(android.util.Log) DialogInterface(android.content.DialogInterface) FileUtils(com.hippo.yorozuya.FileUtils) Request(okhttp3.Request) AsyncTask(android.os.AsyncTask) UrlOpener(com.hippo.ehviewer.UrlOpener) DownloadManager(com.hippo.ehviewer.download.DownloadManager) EhDB(com.hippo.ehviewer.EhDB) IOException(java.io.IOException) R(com.hippo.ehviewer.R) IoThreadPoolExecutor(com.hippo.util.IoThreadPoolExecutor) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) Settings(com.hippo.ehviewer.Settings) DownloadService(com.hippo.ehviewer.download.DownloadService) UniFile(com.hippo.unifile.UniFile) EhClient(com.hippo.ehviewer.client.EhClient) LongList(com.hippo.yorozuya.collect.LongList) EhApplication(com.hippo.ehviewer.EhApplication) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) BaseScene(com.hippo.ehviewer.ui.scene.BaseScene) Activity(android.app.Activity) Collections(java.util.Collections) EhRequest(com.hippo.ehviewer.client.EhRequest) ExceptionUtils(com.hippo.util.ExceptionUtils) InputStream(java.io.InputStream) ListCheckBoxDialogBuilder(com.hippo.app.ListCheckBoxDialogBuilder)

Example 7 with GalleryInfo

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;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) EhException(com.hippo.ehviewer.client.exception.EhException) ContentLayout(com.hippo.widget.ContentLayout) Bundle(android.os.Bundle) AnimationUtils(com.hippo.yorozuya.AnimationUtils) NonNull(androidx.annotation.NonNull) SearchBar(com.hippo.ehviewer.widget.SearchBar) Spannable(android.text.Spannable) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) SelectItemWithIconAdapter(com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter) ColorDrawable(android.graphics.drawable.ColorDrawable) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) ViewConfiguration(android.view.ViewConfiguration) EditTextDialogBuilder(com.hippo.app.EditTextDialogBuilder) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder) AddDeleteDrawable(com.hippo.drawable.AddDeleteDrawable) DrawerLayout(com.hippo.drawerlayout.DrawerLayout) Display(android.view.Display) View(android.view.View) RefreshLayout(com.hippo.refreshlayout.RefreshLayout) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) AssertUtils(com.hippo.yorozuya.AssertUtils) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) QuickSearch(com.hippo.ehviewer.dao.QuickSearch) GalleryDetailUrlParser(com.hippo.ehviewer.client.parser.GalleryDetailUrlParser) FastScroller(com.hippo.easyrecyclerview.FastScroller) InputType(android.text.InputType) ViewGroup(android.view.ViewGroup) Ripple(com.hippo.ripple.Ripple) MathUtils(com.hippo.yorozuya.MathUtils) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) GalleryPageUrlParser(com.hippo.ehviewer.client.parser.GalleryPageUrlParser) EhClient(com.hippo.ehviewer.client.EhClient) Toolbar(androidx.appcompat.widget.Toolbar) ListView(android.widget.ListView) EhApplication(com.hippo.ehviewer.EhApplication) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) EhRequest(com.hippo.ehviewer.client.EhRequest) DrawableManager(com.hippo.util.DrawableManager) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) ImageSpan(android.text.style.ImageSpan) Intent(android.content.Intent) IntDef(androidx.annotation.IntDef) SimpleShowcaseEventListener(com.github.amlcurran.showcaseview.SimpleShowcaseEventListener) MenuItem(android.view.MenuItem) MainActivity(com.hippo.ehviewer.ui.MainActivity) FabLayout(com.hippo.widget.FabLayout) Retention(java.lang.annotation.Retention) FavouriteStatusRouter(com.hippo.ehviewer.FavouriteStatusRouter) SceneFragment(com.hippo.scene.SceneFragment) ViewTransition(com.hippo.view.ViewTransition) SpannableStringBuilder(android.text.SpannableStringBuilder) SearchBarMover(com.hippo.widget.SearchBarMover) ViewUtils(com.hippo.yorozuya.ViewUtils) SimpleAnimatorListener(com.hippo.yorozuya.SimpleAnimatorListener) DrawerArrowDrawable(com.hippo.drawable.DrawerArrowDrawable) DialogInterface(android.content.DialogInterface) GalleryInfoContentHelper(com.hippo.ehviewer.widget.GalleryInfoContentHelper) SearchLayout(com.hippo.ehviewer.widget.SearchLayout) LayoutInflater(android.view.LayoutInflater) DownloadManager(com.hippo.ehviewer.download.DownloadManager) StringUtils(com.hippo.yorozuya.StringUtils) PointTarget(com.github.amlcurran.showcaseview.targets.PointTarget) EhDB(com.hippo.ehviewer.EhDB) Point(android.graphics.Point) TextUtils(android.text.TextUtils) EhUtils(com.hippo.ehviewer.client.EhUtils) CommonOperations(com.hippo.ehviewer.ui.CommonOperations) AppHelper(com.hippo.util.AppHelper) File(java.io.File) R(com.hippo.ehviewer.R) Color(android.graphics.Color) Gravity(android.view.Gravity) ArrayAdapter(android.widget.ArrayAdapter) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) GalleryListParser(com.hippo.ehviewer.client.parser.GalleryListParser) Settings(com.hippo.ehviewer.Settings) AttrResources(com.hippo.android.resource.AttrResources) EhUrl(com.hippo.ehviewer.client.EhUrl) Announcer(com.hippo.scene.Announcer) Activity(android.app.Activity) Collections(java.util.Collections) Resources(android.content.res.Resources) RetentionPolicy(java.lang.annotation.RetentionPolicy) SelectItemWithIconAdapter(com.hippo.ehviewer.ui.dialog.SelectItemWithIconAdapter) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) Intent(android.content.Intent) MainActivity(com.hippo.ehviewer.ui.MainActivity) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity)

Example 8 with GalleryInfo

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);
}
Also used : Bundle(android.os.Bundle) FavouriteStatusRouter(com.hippo.ehviewer.FavouriteStatusRouter) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) SuppressLint(android.annotation.SuppressLint)

Example 9 with GalleryInfo

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());
}
Also used : UniFile(com.hippo.unifile.UniFile) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) IOException(java.io.IOException) LinkedList(java.util.LinkedList) SpiderInfo(com.hippo.ehviewer.spider.SpiderInfo) SuppressLint(android.annotation.SuppressLint)

Example 10 with GalleryInfo

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;
}
Also used : LocalFavoriteInfo(com.hippo.ehviewer.dao.LocalFavoriteInfo) LocalFavoritesDao(com.hippo.ehviewer.dao.LocalFavoritesDao) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) ArrayList(java.util.ArrayList)

Aggregations

GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)25 ArrayList (java.util.ArrayList)7 AlertDialog (androidx.appcompat.app.AlertDialog)6 SuppressLint (android.annotation.SuppressLint)5 Bundle (android.os.Bundle)5 View (android.view.View)5 TextView (android.widget.TextView)5 Activity (android.app.Activity)4 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)4 MainActivity (com.hippo.ehviewer.ui.MainActivity)4 Point (android.graphics.Point)3 Drawable (android.graphics.drawable.Drawable)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 EhApplication (com.hippo.ehviewer.EhApplication)3 EhDB (com.hippo.ehviewer.EhDB)3