55import android .content .res .TypedArray ;
66import android .net .Uri ;
77import android .os .Build ;
8- import androidx .annotation .NonNull ;
9- import androidx .annotation .Nullable ;
108import android .util .AttributeSet ;
119import android .view .MotionEvent ;
1210import android .view .View ;
1614import android .webkit .WebView ;
1715import android .webkit .WebViewClient ;
1816
17+ import androidx .annotation .NonNull ;
18+ import androidx .annotation .Nullable ;
19+
1920import com .fastaccess .R ;
2021import com .fastaccess .helper .AppHelper ;
2122import com .fastaccess .helper .InputHelper ;
@@ -56,18 +57,22 @@ public PrettifyWebView(Context context, AttributeSet attrs, int defStyleAttr) {
5657 initView (attrs );
5758 }
5859
59- @ Override public boolean onInterceptTouchEvent (MotionEvent p ) {
60+ @ Override
61+ public boolean onInterceptTouchEvent (MotionEvent p ) {
6062 return true ;
6163 }
6264
63- @ SuppressLint ("ClickableViewAccessibility" ) @ Override public boolean onTouchEvent (MotionEvent event ) {
65+ @ SuppressLint ("ClickableViewAccessibility" )
66+ @ Override
67+ public boolean onTouchEvent (MotionEvent event ) {
6468 if (getParent () != null ) {
6569 getParent ().requestDisallowInterceptTouchEvent (interceptTouch );
6670 }
6771 return super .onTouchEvent (event );
6872 }
6973
70- @ SuppressLint ("SetJavaScriptEnabled" ) private void initView (@ Nullable AttributeSet attrs ) {
74+ @ SuppressLint ("SetJavaScriptEnabled" )
75+ private void initView (@ Nullable AttributeSet attrs ) {
7176 if (isInEditMode ()) return ;
7277 if (attrs != null ) {
7378 TypedArray tp = getContext ().obtainStyledAttributes (attrs , R .styleable .PrettifyWebView );
@@ -102,14 +107,16 @@ public PrettifyWebView(Context context, AttributeSet attrs, int defStyleAttr) {
102107 });
103108 }
104109
105- @ Override protected void onScrollChanged (int l , int t , int oldl , int oldt ) {
110+ @ Override
111+ protected void onScrollChanged (int l , int t , int oldl , int oldt ) {
106112 super .onScrollChanged (l , t , oldl , oldt );
107113 if (onContentChangedListener != null ) {
108114 onContentChangedListener .onScrollChanged (t == 0 , t );
109115 }
110116 }
111117
112- @ Override protected void onDetachedFromWindow () {
118+ @ Override
119+ protected void onDetachedFromWindow () {
113120 onContentChangedListener = null ;
114121 super .onDetachedFromWindow ();
115122 }
@@ -171,7 +178,8 @@ public static String[] getLineNo(@Nullable String url) {
171178 if (lineNumber != null ) {
172179 lineNo = lineNumber .replaceAll ("L" , "" ).split ("-" );
173180 }
174- } catch (Exception ignored ) {}
181+ } catch (Exception ignored ) {
182+ }
175183 }
176184 return lineNo ;
177185 }
@@ -195,7 +203,8 @@ public void setWikiContent(@NonNull String source, @Nullable String baseUrl) {
195203 }
196204
197205 public void setGithubContent (@ NonNull String source , @ Nullable String baseUrl , boolean toggleNestScrolling , boolean enableBridge ) {
198- if (enableBridge ) addJavascriptInterface (new MarkDownInterceptorInterface (this , toggleNestScrolling ), "Android" );
206+ if (enableBridge )
207+ addJavascriptInterface (new MarkDownInterceptorInterface (this , toggleNestScrolling ), "Android" );
199208 String page = GithubHelper .generateContent (getContext (), source , baseUrl , AppHelper .isNightMode (getResources ()),
200209 AppHelper .isNightMode (getResources ()), false );
201210 post (() -> loadDataWithBaseURL ("file:///android_asset/md/" , page , "text/html" , "utf-8" , null ));
@@ -233,7 +242,12 @@ public void setEnableNestedScrolling(boolean enableNestedScrolling) {
233242 private void startActivity (@ Nullable Uri url ) {
234243 if (url == null ) return ;
235244 if (MarkDownProvider .isImage (url .toString ())) {
236- CodeViewerActivity .startActivity (getContext (), url .toString (), url .toString ());
245+ if (MarkDownProvider .isGithubBlobImage (url )) {
246+ String minifiedUrl = MarkDownProvider .minifyGithubImageUri (url );
247+ launchCodeViewerActivity (minifiedUrl );
248+ } else {
249+ launchCodeViewerActivity (url .toString ());
250+ }
237251 } else {
238252 String lastSegment = url .getEncodedFragment ();
239253 if (lastSegment != null || url .toString ().startsWith ("#" ) || url .toString ().indexOf ('#' ) != -1 ) {
@@ -243,8 +257,13 @@ private void startActivity(@Nullable Uri url) {
243257 }
244258 }
245259
260+ private void launchCodeViewerActivity (String url ) {
261+ CodeViewerActivity .startActivity (getContext (), url , url );
262+ }
263+
246264 private class ChromeClient extends WebChromeClient {
247- @ Override public void onProgressChanged (WebView view , int progress ) {
265+ @ Override
266+ public void onProgressChanged (WebView view , int progress ) {
248267 super .onProgressChanged (view , progress );
249268 if (onContentChangedListener != null ) {
250269 onContentChangedListener .onContentChanged (progress );
@@ -253,14 +272,17 @@ private class ChromeClient extends WebChromeClient {
253272 }
254273
255274 private class WebClient extends WebViewClient {
256- @ Override public boolean shouldOverrideUrlLoading (WebView view , WebResourceRequest request ) {
275+ @ Override
276+ public boolean shouldOverrideUrlLoading (WebView view , WebResourceRequest request ) {
257277 startActivity (request .getUrl ());
258278 return true ;
259279 }
260280 }
261281
262282 private class WebClientCompat extends WebViewClient {
263- @ SuppressWarnings ("deprecation" ) @ Override public boolean shouldOverrideUrlLoading (WebView view , String url ) {
283+ @ SuppressWarnings ("deprecation" )
284+ @ Override
285+ public boolean shouldOverrideUrlLoading (WebView view , String url ) {
264286 startActivity (Uri .parse (url ));
265287 return true ;
266288 }
0 commit comments