mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 03:54:18 -04:00
Merge pull request #1645 from kiwix/feature/macgills/344-mixed-rendering
#344 Broken rendering, mixing content beetween different (TED) ZIM fi…
This commit is contained in:
commit
e2d4bc7e4c
@ -23,7 +23,9 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build.VERSION
|
||||
import android.os.Build.VERSION_CODES
|
||||
import android.util.TypedValue
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.AttrRes
|
||||
import org.kiwix.kiwixmobile.core.base.BaseBroadcastReceiver
|
||||
import java.util.Locale
|
||||
|
||||
@ -54,3 +56,10 @@ val Context.locale: Locale
|
||||
get() =
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.N) resources.configuration.locales.get(0)
|
||||
else resources.configuration.locale
|
||||
|
||||
fun Context.getColorAttribute(@AttrRes attributeRes: Int) = with(TypedValue()) {
|
||||
if (theme.resolveAttribute(attributeRes, this, true))
|
||||
data
|
||||
else
|
||||
throw RuntimeException("invalid attribute $attributeRes")
|
||||
}
|
||||
|
@ -18,7 +18,10 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.core.extensions
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.widget.ImageViewCompat
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.Base64String
|
||||
|
||||
fun ImageView.setBitmap(base64String: Base64String) {
|
||||
@ -36,3 +39,7 @@ fun ImageView.setBitmap(base64String: Base64String) {
|
||||
fun ImageView.setBitmapFromString(string: String?) {
|
||||
setBitmap(Base64String(string))
|
||||
}
|
||||
|
||||
fun ImageView.tint(@ColorInt colorId: Int) {
|
||||
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(colorId))
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
@ -356,7 +355,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
||||
bookOnDiskItem -> {
|
||||
open(bookOnDiskItem);
|
||||
getCurrentWebView().activateNightMode();
|
||||
updateNightMode();
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
null,
|
||||
@ -769,7 +768,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
webViewList.add(webView);
|
||||
selectTab(webViewList.size() - 1);
|
||||
tabsAdapter.notifyDataSetChanged();
|
||||
setUpWebView();
|
||||
setUpWebViewWithTextToSpeech();
|
||||
documentParser.initInterface(webView);
|
||||
return webView;
|
||||
}
|
||||
@ -778,7 +777,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
KiwixWebView webView = getWebView(url);
|
||||
webViewList.add(webView);
|
||||
tabsAdapter.notifyDataSetChanged();
|
||||
setUpWebView();
|
||||
setUpWebViewWithTextToSpeech();
|
||||
documentParser.initInterface(webView);
|
||||
}
|
||||
|
||||
@ -791,7 +790,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
.setAction(R.string.undo, v -> {
|
||||
webViewList.add(index, tempForUndo);
|
||||
tabsAdapter.notifyItemInserted(index);
|
||||
setUpWebView();
|
||||
setUpWebViewWithTextToSpeech();
|
||||
})
|
||||
.show();
|
||||
openHomeScreen();
|
||||
@ -1090,8 +1089,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
openZimFile(file);
|
||||
}
|
||||
scanStorageForZims();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Snackbar.make(snackbarRoot, R.string.request_storage, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.menu_settings, view -> {
|
||||
Intent intent = new Intent();
|
||||
@ -1192,7 +1190,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
webViewList.set(i, getWebView(webViewList.get(i).getUrl()));
|
||||
}
|
||||
selectTab(currentWebViewIndex);
|
||||
setUpWebView();
|
||||
setUpWebViewWithTextToSpeech();
|
||||
}
|
||||
presenter.loadCurrentZimBookmarksUrl();
|
||||
|
||||
@ -1324,22 +1322,7 @@ public abstract class CoreMainActivity extends BaseActivity
|
||||
openArticle(articleUrl);
|
||||
}
|
||||
|
||||
private void setUpWebView() {
|
||||
getCurrentWebView().getSettings().setJavaScriptEnabled(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
WebView.setWebContentsDebuggingEnabled(true);
|
||||
}
|
||||
|
||||
// webView.getSettings().setLoadsImagesAutomatically(false);
|
||||
// Does not make much sense to cache data from zim files.(Not clear whether
|
||||
// this actually has any effect)
|
||||
getCurrentWebView().getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
|
||||
// Should basically resemble the behavior when setWebClient not done
|
||||
// (i.p. internal urls load in webView, external urls in browser)
|
||||
// as currently no custom setWebViewClient required it is commented
|
||||
// However, it must notify the bookmark system when a page is finished loading
|
||||
// so that it can refresh the menu.
|
||||
private void setUpWebViewWithTextToSpeech() {
|
||||
tts.initWebView(getCurrentWebView());
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.core.main;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
@ -41,6 +42,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.inject.Inject;
|
||||
import org.kiwix.kiwixmobile.core.BuildConfig;
|
||||
import org.kiwix.kiwixmobile.core.CoreApp;
|
||||
import org.kiwix.kiwixmobile.core.R;
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
|
||||
@ -66,15 +68,21 @@ public class KiwixWebView extends VideoEnabledWebView {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public KiwixWebView(Context context, WebViewCallback callback, AttributeSet attrs,
|
||||
ViewGroup nonVideoView, ViewGroup videoView, CoreWebViewClient webViewClient) {
|
||||
super(context, attrs);
|
||||
if (BuildConfig.DEBUG == true && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
setWebContentsDebuggingEnabled(true);
|
||||
}
|
||||
this.callback = callback;
|
||||
CoreApp.getCoreComponent().inject(this);
|
||||
// Set the user agent to the current locale so it can be read with navigator.userAgent
|
||||
final WebSettings settings = getSettings();
|
||||
settings.setUserAgentString(LanguageUtils.getCurrentLocale(context).toString());
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setJavaScriptEnabled(true);
|
||||
clearCache(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
settings.setAllowUniversalAccessFromFileURLs(true);
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.List;
|
||||
import org.kiwix.kiwixmobile.core.R;
|
||||
import org.kiwix.kiwixmobile.core.extensions.ContextExtensionsKt;
|
||||
import org.kiwix.kiwixmobile.core.extensions.ImageViewExtensionsKt;
|
||||
|
||||
import static org.kiwix.kiwixmobile.core.utils.DimenUtils.getToolbarHeight;
|
||||
import static org.kiwix.kiwixmobile.core.utils.DimenUtils.getWindowHeight;
|
||||
@ -67,6 +69,8 @@ public class TabsAdapter extends RecyclerView.Adapter<TabsAdapter.ViewHolder> {
|
||||
ImageView close = new ImageView(context);
|
||||
close.setId(2);
|
||||
close.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_clear_white_24dp));
|
||||
ImageViewExtensionsKt.tint(close,
|
||||
ContextExtensionsKt.getColorAttribute(context, R.attr.colorOnSurface));
|
||||
|
||||
CardView cardView = new CardView(context);
|
||||
cardView.setId(3);
|
||||
@ -90,7 +94,6 @@ public class TabsAdapter extends RecyclerView.Adapter<TabsAdapter.ViewHolder> {
|
||||
textView.setId(4);
|
||||
textView.setMaxLines(1);
|
||||
textView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
textView.setTextColor(activity.getResources().getColor(R.color.white));
|
||||
constraintLayout.addView(textView,
|
||||
new ConstraintLayout.LayoutParams(0, ConstraintLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user