Search in sources :

Example 1 with BaseWebActivityBundle

use of me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle in project Hentoid by avluis.

the class BaseWebActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    // NB : This doesn't restore the browsing history, but WebView.saveState/restoreState
    // doesn't work that well (bugged when using back/forward commands). A valid solution still has to be found
    BaseWebActivityBundle bundle = new BaseWebActivityBundle();
    bundle.setUrl(webView.getUrl());
    outState.putAll(bundle.toBundle());
}
Also used : BaseWebActivityBundle(me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle)

Example 2 with BaseWebActivityBundle

use of me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle in project Hentoid by avluis.

the class BaseWebActivity method onRestoreInstanceState.

@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    // NB : This doesn't restore the browsing history, but WebView.saveState/restoreState
    // doesn't work that well (bugged when using back/forward commands). A valid solution still has to be found
    String url = new BaseWebActivityBundle(savedInstanceState).getUrl();
    if (url != null && !url.isEmpty())
        webView.loadUrl(url);
}
Also used : BaseWebActivityBundle(me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle)

Example 3 with BaseWebActivityBundle

use of me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle in project Hentoid by avluis.

the class BaseWebActivity method getStartUrl.

/**
 * Determine the URL the browser will load at startup
 * - Either an URL specifically given to the activity (e.g. "view source" action)
 * - Or the last viewed page, if the option is enabled
 * - If neither of the previous cases, the default URL of the site
 *
 * @return URL to load at startup
 */
private String getStartUrl() {
    // Priority 1 : URL specifically given to the activity (e.g. "view source" action)
    if (getIntent().getExtras() != null) {
        BaseWebActivityBundle bundle = new BaseWebActivityBundle(getIntent().getExtras());
        String intentUrl = StringHelper.protect(bundle.getUrl());
        if (!intentUrl.isEmpty())
            return intentUrl;
    }
    // Priority 2 : Last viewed position, if option enabled
    if (Preferences.isBrowserResumeLast()) {
        SiteHistory siteHistory = dao.selectHistory(getStartSite());
        if (siteHistory != null && !siteHistory.getUrl().isEmpty())
            return siteHistory.getUrl();
    }
    // Priority 3 : Homepage, if manually set through bookmarks
    SiteBookmark welcomePage = dao.selectHomepage(getStartSite());
    if (welcomePage != null)
        return welcomePage.getUrl();
    // Default site URL
    return getStartSite().getUrl();
}
Also used : SiteBookmark(me.devsaki.hentoid.database.domains.SiteBookmark) BaseWebActivityBundle(me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle) SiteHistory(me.devsaki.hentoid.database.domains.SiteHistory)

Example 4 with BaseWebActivityBundle

use of me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle in project Hentoid by avluis.

the class ContentHelper method launchBrowserFor.

/**
 * Launch the web browser for the given site and URL
 *
 * @param context   COntext to be used
 * @param targetUrl Url to navigate to
 */
public static void launchBrowserFor(@NonNull final Context context, @NonNull final String targetUrl) {
    Site targetSite = Site.searchByUrl(targetUrl);
    if (null == targetSite || targetSite.equals(Site.NONE))
        return;
    Intent intent = new Intent(context, Content.getWebActivityClass(targetSite));
    BaseWebActivityBundle bundle = new BaseWebActivityBundle();
    bundle.setUrl(targetUrl);
    intent.putExtras(bundle.toBundle());
    context.startActivity(intent);
}
Also used : Site(me.devsaki.hentoid.enums.Site) BaseWebActivityBundle(me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle) Intent(android.content.Intent)

Example 5 with BaseWebActivityBundle

use of me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle in project Hentoid by avluis.

the class ContentHelper method viewContentGalleryPage.

/**
 * Open the app's web browser to view the given Content's gallery page
 *
 * @param context Context to use for the action
 * @param content Content to view
 * @param wrapPin True if the intent should be wrapped with PIN protection
 */
public static void viewContentGalleryPage(@NonNull final Context context, @NonNull Content content, boolean wrapPin) {
    if (content.getSite().equals(Site.NONE))
        return;
    Intent intent = new Intent(context, Content.getWebActivityClass(content.getSite()));
    BaseWebActivityBundle bundle = new BaseWebActivityBundle();
    bundle.setUrl(content.getGalleryUrl());
    intent.putExtras(bundle.toBundle());
    if (wrapPin)
        intent = UnlockActivity.wrapIntent(context, intent);
    context.startActivity(intent);
}
Also used : BaseWebActivityBundle(me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle) Intent(android.content.Intent)

Aggregations

BaseWebActivityBundle (me.devsaki.hentoid.activities.bundles.BaseWebActivityBundle)5 Intent (android.content.Intent)2 SiteBookmark (me.devsaki.hentoid.database.domains.SiteBookmark)1 SiteHistory (me.devsaki.hentoid.database.domains.SiteHistory)1 Site (me.devsaki.hentoid.enums.Site)1