* Neutralize scene firstly * Remove StageLayout * Add nav graph * Rename .java to .kt * Convert BaseScene to kotlin * Add GalleryDetailScene to navgraph No need to check topfragment is callback target fragment, since these callback must be cancelled in fragment's lifecycle when DestroyView * Restore funcs * Restore preview * Revert "Convert BaseScene to kotlin" Should not do it here This reverts commit 5d2e3af6ad85fef7604d8df19ee58a957390cdb5. * Revert "Rename .java to .kt" This reverts commit 128c655bc98fc54528d58534651d61ff47b2284d. * Restore drawer * Remove all getScene usage * Remove all getStageActivity usage * Remove all getStageActivity usage * setupWithNavController * Refactor MainActivity with viewBinding * Add navdrawer corresponding navdestination * Migrate All normal fragment * Add anims * Fix statusbar flicker * Remove SceneApplication * Remove SceneFragment * Remove StageActivity * Drop scene totally * Dynamically set navgraph * Restore signin * Restore login via cookies * Restore login via webview * Add some TODOs * Fixup * Restore onProvideAssistContent * Restore checkClipboard * Restore intent handle * Fix handle intent * Remove unused EhUrlOpener * Let system handle that intent * Restore handle download intent * Restore AboveSnackerLayout * Fix the last navigation
87 lines
3.1 KiB
Java
87 lines
3.1 KiB
Java
/*
|
|
* Copyright 2016 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.
|
|
*/
|
|
|
|
package com.hippo.ehviewer;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.text.TextUtils;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.browser.customtabs.CustomTabsIntent;
|
|
|
|
import com.hippo.ehviewer.client.data.GalleryDetail;
|
|
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
|
|
|
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity;
|
|
|
|
public final class UrlOpener {
|
|
|
|
private UrlOpener() {
|
|
}
|
|
|
|
public static void openUrl(@NonNull Context context, String url, boolean ehUrl) {
|
|
openUrl(context, url, ehUrl, null);
|
|
}
|
|
|
|
public static void openUrl(@NonNull Context context, String url, boolean ehUrl, GalleryDetail galleryDetail) {
|
|
if (TextUtils.isEmpty(url)) {
|
|
return;
|
|
}
|
|
|
|
Intent intent;
|
|
Uri uri = Uri.parse(url);
|
|
|
|
if (ehUrl) {
|
|
if (galleryDetail != null) {
|
|
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(url);
|
|
if (result != null) {
|
|
if (result.gid == galleryDetail.getGid()) {
|
|
intent = new Intent(context, ReaderActivity.class);
|
|
intent.setAction(ReaderActivity.ACTION_EH);
|
|
intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, galleryDetail);
|
|
intent.putExtra(ReaderActivity.KEY_PAGE, result.page);
|
|
context.startActivity(intent);
|
|
return;
|
|
}
|
|
} else if (url.startsWith("#c")) {
|
|
try {
|
|
intent = new Intent(context, ReaderActivity.class);
|
|
intent.setAction(ReaderActivity.ACTION_EH);
|
|
intent.putExtra(ReaderActivity.KEY_GALLERY_INFO, galleryDetail);
|
|
intent.putExtra(ReaderActivity.KEY_PAGE, Integer.parseInt(url.replace("#c", "")) - 1);
|
|
context.startActivity(intent);
|
|
return;
|
|
} catch (NumberFormatException e) {
|
|
//
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
CustomTabsIntent.Builder customTabsIntent = new CustomTabsIntent.Builder();
|
|
customTabsIntent.setShowTitle(true);
|
|
try {
|
|
customTabsIntent.build().launchUrl(context, uri);
|
|
} catch (ActivityNotFoundException e) {
|
|
Toast.makeText(context, R.string.no_browser_installed, Toast.LENGTH_LONG).show();
|
|
}
|
|
}
|
|
}
|