From 867d4a2c1e65ff990a54682608ec3f41f9ac13e6 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 18 May 2020 00:08:11 +0300 Subject: [PATCH] Display zoomed WebView images when clicked --- app/build.gradle | 5 +- app/proguard-rules.pro | 8 + app/src/main/assets/apache_libraries.html | 3 + app/src/main/assets/mit_libraries.html | 2 +- app/src/main/assets/other_libraries.html | 146 ++++++++++++++++++ .../mthmmy/activities/AboutActivity.java | 4 + .../main/recent/RecentFragment.java | 1 - .../main/unread/UnreadFragment.java | 1 - .../latestPosts/LatestPostsAdapter.java | 9 +- .../latestPosts/LatestPostsFragment.java | 3 +- .../mthmmy/activities/topic/TopicAdapter.java | 2 + .../topic/tasks/PrepareForEditTask.java | 1 - .../topic/tasks/PrepareForReplyTask.java | 1 - .../gr/thmmy/mthmmy/base/BaseActivity.java | 2 +- .../gr/thmmy/mthmmy/base/BaseApplication.java | 22 ++- .../thmmy/mthmmy/session/SessionManager.java | 1 - .../gr/thmmy/mthmmy/utils/NetworkTask.java | 1 - .../utils/WebViewOnTouchClickListener.java | 79 ++++++++++ .../mthmmy/utils/parsing/ParseHelpers.java | 4 - app/src/main/res/layout/activity_about.xml | 13 +- app/src/main/res/values/strings.xml | 1 + 21 files changed, 288 insertions(+), 21 deletions(-) create mode 100644 app/src/main/assets/other_libraries.html create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/WebViewOnTouchClickListener.java diff --git a/app/build.gradle b/app/build.gradle index 60fbf711..981f79dd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -98,14 +98,17 @@ dependencies { implementation 'com.mikepenz:materialdrawer:6.1.1' implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar' - implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! + implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'ru.noties:markwon:2.0.2' implementation 'net.gotev:uploadservice:3.5.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2' //TODO: Warning: v.3.5 depends on okhttp 3.13! implementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.5' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler + implementation 'com.github.bumptech.glide:glide:4.11.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' testImplementation 'junit:junit:4.12' testImplementation 'org.powermock:powermock-core:2.0.2' testImplementation 'org.powermock:powermock-module-junit4:2.0.2' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 9cde3150..e7c4ece2 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -32,6 +32,14 @@ # Picasso -dontwarn com.squareup.okhttp.** +#Glide +-keep public class * implements com.bumptech.glide.module.GlideModule +-keep public class * extends com.bumptech.glide.module.AppGlideModule +-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { + **[] $VALUES; + public *; +} + # Android-Iconics (fontawesome-typeface) -keep class .R -keep class **.R$* { diff --git a/app/src/main/assets/apache_libraries.html b/app/src/main/assets/apache_libraries.html index a75e08f3..c0c2e987 100644 --- a/app/src/main/assets/apache_libraries.html +++ b/app/src/main/assets/apache_libraries.html @@ -52,6 +52,9 @@
  • MaterialDrawer v6.1.1 (Copyright ©2018 Mike Penz)
  • +
  • +
    PhotoView v2.3.0 (Copyright ©2018 Chris Banes)
    +
  • Android-Iconics v2.9.5 (Copyright ©2016 Mike Penz)
  • diff --git a/app/src/main/assets/mit_libraries.html b/app/src/main/assets/mit_libraries.html index b3cdee88..a1cce5c6 100644 --- a/app/src/main/assets/mit_libraries.html +++ b/app/src/main/assets/mit_libraries.html @@ -41,7 +41,7 @@
    jsoup v1.10.3 (Copyright ©2009-2017, Jonathan Hedley <jonathan@hedley.net>)
  • -
    android-gif-drawable v1.2.12 (Copyright ©2013 -2018 Karol Wrótniak, Droids on Roids)
    +
    android-gif-drawable v1.2.19 (Copyright ©2013 -2020 Karol Wrótniak, Droids on Roids)
  • Expandable RecyclerView v3.0.0-RC1 (Copyright ©2015, Big Nerd Ranch)
    diff --git a/app/src/main/assets/other_libraries.html b/app/src/main/assets/other_libraries.html new file mode 100644 index 00000000..53edb44c --- /dev/null +++ b/app/src/main/assets/other_libraries.html @@ -0,0 +1,146 @@ + + + + + + + + + +
    +

    Glide License

    +
    +License for everything not in third_party and not otherwise marked:
    +
    +Copyright 2014 Google, Inc. All rights reserved.
    +
    +Redistribution and use in source and binary forms, with or without modification, are
    +permitted provided that the following conditions are met:
    +
    +   1. Redistributions of source code must retain the above copyright notice, this list of
    +         conditions and the following disclaimer.
    +
    +   2. Redistributions in binary form must reproduce the above copyright notice, this list
    +         of conditions and the following disclaimer in the documentation and/or other materials
    +         provided with the distribution.
    +
    +THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED
    +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE, INC. OR
    +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    +
    +The views and conclusions contained in the software and documentation are those of the
    +authors and should not be interpreted as representing official policies, either expressed
    +or implied, of Google, Inc.
    +---------------------------------------------------------------------------------------------
    +License for third_party/disklrucache:
    +
    +Copyright 2012 Jake Wharton
    +Copyright 2011 The Android Open Source Project
    +
    +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.
    +---------------------------------------------------------------------------------------------
    +License for third_party/gif_decoder:
    +
    +Copyright (c) 2013 Xcellent Creations, Inc.
    +
    +Permission is hereby granted, free of charge, to any person obtaining
    +a copy of this software and associated documentation files (the
    +"Software"), to deal in the Software without restriction, including
    +without limitation the rights to use, copy, modify, merge, publish,
    +distribute, sublicense, and/or sell copies of the Software, and to
    +permit persons to whom the Software is furnished to do so, subject to
    +the following conditions:
    +
    +The above copyright notice and this permission notice shall be
    +included in all copies or substantial portions of the Software.
    +
    +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    +---------------------------------------------------------------------------------------------
    +License for third_party/gif_encoder/AnimatedGifEncoder.java and
    +third_party/gif_encoder/LZWEncoder.java:
    +
    +No copyright asserted on the source code of this class. May be used for any
    +purpose, however, refer to the Unisys LZW patent for restrictions on use of
    +the associated LZWEncoder class. Please forward any corrections to
    +kweiner@fmsware.com.
    +
    +-----------------------------------------------------------------------------
    +License for third_party/gif_encoder/NeuQuant.java
    +
    +Copyright (c) 1994 Anthony Dekker
    +
    +NEUQUANT Neural-Net quantization algorithm by Anthony Dekker, 1994. See
    +"Kohonen neural networks for optimal colour quantization" in "Network:
    +Computation in Neural Systems" Vol. 5 (1994) pp 351-367. for a discussion of
    +the algorithm.
    +
    +Any party obtaining a copy of these files from the author, directly or
    +indirectly, is granted, free of charge, a full and unrestricted irrevocable,
    +world-wide, paid up, royalty-free, nonexclusive right and license to deal in
    +this software and documentation files (the "Software"), including without
    +limitation the rights to use, copy, modify, merge, publish, distribute,
    +sublicense, and/or sell copies of the Software, and to permit persons who
    +receive copies from any such party to do so, with the only requirement being
    +that this copyright notice remain intact.
    +
    + + + diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index 0f3e9981..1919608f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -151,6 +151,10 @@ public class AboutActivity extends BaseActivity { title=getString(R.string.epl_libraries); fileUrl="file:///android_asset/epl_libraries.html"; break; + case "OTHER": + title=getString(R.string.other_libraries); + fileUrl="file:///android_asset/other_libraries.html"; + break; default: break; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 6eff1d27..9435fecc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -1,7 +1,6 @@ package gr.thmmy.mthmmy.activities.main.recent; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index 53b7d20b..8b11cc3e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java @@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.main.unread; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index d2a4d1cb..5b401f01 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.profile.latestPosts; +import android.annotation.SuppressLint; +import android.content.Context; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; @@ -16,6 +18,7 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.TopicSummary; +import gr.thmmy.mthmmy.utils.WebViewOnTouchClickListener; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; /** @@ -26,11 +29,13 @@ class LatestPostsAdapter extends RecyclerView.Adapter { private static final int VIEW_TYPE_EMPTY = -1; private static final int VIEW_TYPE_ITEM = 0; private static final int VIEW_TYPE_LOADING = 1; + private final Context context; private final LatestPostsFragment.LatestPostsFragmentInteractionListener interactionListener; private final ArrayList parsedTopicSummaries; - LatestPostsAdapter(BaseFragment.FragmentInteractionListener interactionListener, + LatestPostsAdapter(Context context, BaseFragment.FragmentInteractionListener interactionListener, ArrayList parsedTopicSummaries) { + this.context = context; this.interactionListener = (LatestPostsFragment.LatestPostsFragmentInteractionListener) interactionListener; this.parsedTopicSummaries = parsedTopicSummaries; } @@ -64,6 +69,7 @@ class LatestPostsAdapter extends RecyclerView.Adapter { return null; } + @SuppressLint("ClickableViewAccessibility") @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { if (holder instanceof LatestPostViewHolder) { @@ -75,6 +81,7 @@ class LatestPostsAdapter extends RecyclerView.Adapter { latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" , topic.getPost(), "text/html", "UTF-8", null); + latestPostViewHolder.post.setOnTouchListener(new WebViewOnTouchClickListener(context)); latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { if (interactionListener != null) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 11a1cb7c..b23cc601 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -6,7 +6,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; -import android.widget.Toast; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; @@ -86,7 +85,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_latest_posts, container, false); - latestPostsAdapter = new LatestPostsAdapter(fragmentInteractionListener, parsedTopicSummaries); + latestPostsAdapter = new LatestPostsAdapter(this.getContext(), fragmentInteractionListener, parsedTopicSummaries); RecyclerView mainContent = rootView.findViewById(R.id.profile_latest_posts_recycler); mainContent.setAdapter(latestPostsAdapter); final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 0e885cc3..327fe44d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -73,6 +73,7 @@ import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.TopicItem; import gr.thmmy.mthmmy.utils.CircleTransform; +import gr.thmmy.mthmmy.utils.WebViewOnTouchClickListener; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ThmmyParser; import gr.thmmy.mthmmy.viewmodel.TopicViewModel; @@ -362,6 +363,7 @@ class TopicAdapter extends RecyclerView.Adapter { //Post's WebView parameters holder.post.setClickable(true); holder.post.setWebViewClient(new LinkLauncher()); + holder.post.setOnTouchListener(new WebViewOnTouchClickListener(context)); //noinspection ConstantConditions loadAvatar(currentPost.getThumbnailURL(), holder.thumbnail); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java index 6c971d33..5438132e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java @@ -10,7 +10,6 @@ import org.jsoup.select.Selector; import java.io.IOException; import gr.thmmy.mthmmy.base.BaseApplication; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReplyTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReplyTask.java index 4f1f160c..b45bf50c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReplyTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReplyTask.java @@ -10,7 +10,6 @@ import org.jsoup.select.Selector; import java.io.IOException; import gr.thmmy.mthmmy.base.BaseApplication; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 22357d76..bd21f61b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -390,7 +390,7 @@ public abstract class BaseActivity extends AppCompatActivity { DrawerBuilder drawerBuilder = new DrawerBuilder() .withActivity(this) .withToolbar(toolbar) - .withDrawerWidthDp((int) BaseApplication.getInstance().getDpWidth() / 2) + .withDrawerWidthDp((int) BaseApplication.getInstance().getWidthInDp() / 2) .withSliderBackgroundColor(ContextCompat.getColor(this, R.color.primary_light)) .withAccountHeader(accountHeader) .withOnDrawerItemClickListener((view, position, drawerItem) -> { diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 64ad4996..c52a8c98 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -68,7 +68,9 @@ public class BaseApplication extends Application { private static final String SHARED_PREFS = "ThmmySharedPrefs"; //Display Metrics - private static float dpWidth; + private static float widthDp; + private static int widthPxl, heightPxl; + public static BaseApplication getInstance() { return baseApplication; } @@ -175,7 +177,11 @@ public class BaseApplication extends Application { }); DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics(); - dpWidth = displayMetrics.widthPixels / displayMetrics.density; + + widthPxl = displayMetrics.widthPixels; + widthDp = widthPxl / displayMetrics.density; + + heightPxl = displayMetrics.heightPixels; displayRelativeTime = settingsSharedPrefs.getBoolean(DISPLAY_RELATIVE_TIME, false); } @@ -193,8 +199,16 @@ public class BaseApplication extends Application { return sessionManager; } - public float getDpWidth() { - return dpWidth; + public float getWidthInDp() { + return widthDp; + } + + public int getWidthInPixels() { + return widthPxl; + } + + public int getHeightInPixels() { + return heightPxl; } public boolean isDisplayRelativeTimeEnabled() { diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java index a907e057..36def1de 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -19,7 +19,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import gr.thmmy.mthmmy.utils.parsing.ParseException; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.Cookie; import okhttp3.FormBody; import okhttp3.HttpUrl; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java index 950d9934..9ae5a309 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java @@ -11,7 +11,6 @@ import java.io.IOException; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.parsing.ParseException; -import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/WebViewOnTouchClickListener.java b/app/src/main/java/gr/thmmy/mthmmy/utils/WebViewOnTouchClickListener.java new file mode 100644 index 00000000..43a5b40e --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/WebViewOnTouchClickListener.java @@ -0,0 +1,79 @@ +package gr.thmmy.mthmmy.utils; + +import android.annotation.SuppressLint; +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.ColorDrawable; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.view.Window; +import android.webkit.WebView; + +import com.bumptech.glide.Glide; +import com.github.chrisbanes.photoview.PhotoView; + +import gr.thmmy.mthmmy.base.BaseApplication; + +/** + * Workaround for WebView's inability to send onClick events (sends only onLongClickEvents) + * If an image is find when clicking it will be inflated as a zoomed/zoomable/pinchable PhotoView + */ +public class WebViewOnTouchClickListener implements View.OnTouchListener { + private final static int screenWidth = BaseApplication.getInstance().getWidthInPixels(); + private final static int screenHeight = BaseApplication.getInstance().getHeightInPixels(); + + private final static long MAX_TOUCH_DURATION = 100; + private final Context context; + private long downTime; + + public WebViewOnTouchClickListener(Context context){ + this.context = context; + } + + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + downTime = event.getEventTime(); + break; + case MotionEvent.ACTION_UP: + if(event.getEventTime() - downTime <= MAX_TOUCH_DURATION) + onClick((WebView) v); + break; + default: + break; + } + return false; + } + + private void onClick(WebView webView){ + WebView.HitTestResult result = webView.getHitTestResult(); + if(result.getType() == WebView.HitTestResult.IMAGE_TYPE){ + String imageURL = result.getExtra(); + showImage(imageURL); + } + webView.performClick(); + } + + private void showImage(String url) { + Dialog builder = new Dialog(context); + builder.requestWindowFeature(Window.FEATURE_NO_TITLE); + builder.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + builder.getWindow().setBackgroundDrawable( + new ColorDrawable(android.graphics.Color.TRANSPARENT)); + + PhotoView photoView = new PhotoView(context); + photoView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + photoView.getLayoutParams().width = screenWidth; + photoView.getLayoutParams().height = screenHeight; + + Glide.with(context).load(url).fitCenter().into(photoView); + builder.addContentView(photoView, new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + builder.show(); + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index f5198410..50ca9870 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -1,9 +1,7 @@ package gr.thmmy.mthmmy.utils.parsing; -import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; -import org.jsoup.nodes.TextNode; import org.jsoup.select.Elements; import java.util.ArrayList; @@ -11,8 +9,6 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import timber.log.Timber; - /** * This class consists exclusively of static classes (enums) and methods (excluding methods of inner * classes). It can be used to resolve a page's language and state or fix embedded videos html code diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index f41fe45f..87d99723 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -142,11 +142,22 @@ android:textColor="@color/accent" /> + + Apache v2.0 License libraries The MIT License libraries Eclipse Public License v1.0 libraries + Other libraries Contact Do not hesitate to contact us for any matter either by email at thmmynolife@gmail.com, or by joining our discord server at https://discord.gg/CVt3yrn. Open Source