Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'androidx.webkit:webkit:1.5.0'
}
repositories {
mavenCentral()
Expand Down
95 changes: 52 additions & 43 deletions app/src/main/java/de/eknoes/inofficialgolem/ArticleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewFragment;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;

import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -110,12 +114,17 @@ public void onSaveInstanceState(@NotNull Bundle outState) {
outState.putBoolean(NO_ARTICLE, noArticle);
}

@SuppressLint("SetJavaScriptEnabled")
@SuppressLint({"SetJavaScriptEnabled", "RequiresFeature"})
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

if(webView != null) {
if (webView != null) {
if (PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("force_dark_mode", false) &&
WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
WebSettingsCompat.setAlgorithmicDarkeningAllowed(webView.getSettings(), true);
}
webView.setWebViewClient(new GolemWebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Expand Down Expand Up @@ -146,8 +155,8 @@ public void onPageFinished(WebView view, String url) {
webView.getSettings().setJavaScriptEnabled(true);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptThirdPartyCookies(webView,true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptThirdPartyCookies(webView, true);
}
}

Expand Down Expand Up @@ -178,7 +187,7 @@ public void onResume() {
@Override
public void onDetach() {
super.onDetach();
if(mTask != null) {
if (mTask != null) {
mTask.cancel(false);
}
}
Expand All @@ -188,9 +197,9 @@ public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflat
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_webview, menu);

if(article == null || article.getCommentUrl() == null) {
if (article == null || article.getCommentUrl() == null) {
MenuItem item = menu.findItem(R.id.action_comments);
if(item != null) {
if (item != null) {
item.setVisible(false);
}
}
Expand Down Expand Up @@ -272,44 +281,44 @@ private class loadArticleTask extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(requireContext().getApplicationContext());

SQLiteDatabase db = dbHelper.getReadableDatabase();

if (url != null) {
String[] columns = {
FeedReaderContract.Article.COLUMN_NAME_ID,
FeedReaderContract.Article.COLUMN_NAME_TITLE,
FeedReaderContract.Article.COLUMN_NAME_SUBHEADING,
FeedReaderContract.Article.COLUMN_NAME_URL,
FeedReaderContract.Article.COLUMN_NAME_COMMENTNR,
FeedReaderContract.Article.COLUMN_NAME_COMMENTURL,
FeedReaderContract.Article.COLUMN_NAME_OFFLINE,
FeedReaderContract.Article.COLUMN_NAME_FULLTEXT,
};
Cursor cursor = db.query(
FeedReaderContract.Article.TABLE_NAME,
columns,
"url=\"" + url + "\"",
null,
null,
null,
null);
if (cursor.moveToFirst()) {
article = new Article();
article.setId(cursor.getInt(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_ID)));
article.setTitle(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_TITLE)));
article.setSubheadline(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_SUBHEADING)));
article.setUrl(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_URL)));
article.setCommentUrl(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_COMMENTURL)));
article.setCommentNr(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_COMMENTNR)));
article.setOffline(cursor.getInt(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_OFFLINE)) == 1);
article.setFulltext(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_FULLTEXT)));
}
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(requireContext().getApplicationContext());

SQLiteDatabase db = dbHelper.getReadableDatabase();

cursor.close();
if (url != null) {
String[] columns = {
FeedReaderContract.Article.COLUMN_NAME_ID,
FeedReaderContract.Article.COLUMN_NAME_TITLE,
FeedReaderContract.Article.COLUMN_NAME_SUBHEADING,
FeedReaderContract.Article.COLUMN_NAME_URL,
FeedReaderContract.Article.COLUMN_NAME_COMMENTNR,
FeedReaderContract.Article.COLUMN_NAME_COMMENTURL,
FeedReaderContract.Article.COLUMN_NAME_OFFLINE,
FeedReaderContract.Article.COLUMN_NAME_FULLTEXT,
};
Cursor cursor = db.query(
FeedReaderContract.Article.TABLE_NAME,
columns,
"url=\"" + url + "\"",
null,
null,
null,
null);
if (cursor.moveToFirst()) {
article = new Article();
article.setId(cursor.getInt(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_ID)));
article.setTitle(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_TITLE)));
article.setSubheadline(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_SUBHEADING)));
article.setUrl(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_URL)));
article.setCommentUrl(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_COMMENTURL)));
article.setCommentNr(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_COMMENTNR)));
article.setOffline(cursor.getInt(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_OFFLINE)) == 1);
article.setFulltext(cursor.getString(cursor.getColumnIndexOrThrow(FeedReaderContract.Article.COLUMN_NAME_FULLTEXT)));
}


cursor.close();
}
return null;
}

Expand Down Expand Up @@ -340,7 +349,7 @@ protected void onPostExecute(Void vVoid) {
String fulltext = article.getFulltext();

// Change CSS for Dark Mode
if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
if (fulltext != null) {
fulltext = fulltext.replace("</head>", "<style type=\"text/css\">#screen, body, html {\n" +
"color: white;\n" +
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@
<string name="action_imprint">Golem.de Kontakt</string>
<string name="synchronize_only_if_wi_fi_is_available">Synchronisiere nur mit WLAN</string>
<string name="if_enabled_articles_will_be_synchronized_only_when_wi_fi_is_available">Wenn aktiviert, werden Artikel beim Start nur synchronisiert, wenn WLAN verfügbar ist.</string>
<string name="force_dark_mode">Erzwinge Dark-Mode (experimentell)</string>
<string name="force_dark_mode_title">Erzwinge Dark-Mode</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@
<string name="action_imprint">Golem.de Contact</string>
<string name="synchronize_only_if_wi_fi_is_available">Synchronize with Wi-Fi only</string>
<string name="if_enabled_articles_will_be_synchronized_only_when_wi_fi_is_available">If enabled, articles will only be synchronized at startup when Wi-Fi is available.</string>
<string name="force_dark_mode">Force Dark-Mode (experimental)</string>
<string name="force_dark_mode_title">Force Dark-Mode</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
app:summary="@string/choose_layout_content"
android:icon="@drawable/ic_view">
</Preference>
<SwitchPreference
app:key="force_dark_mode"
app:title="@string/force_dark_mode_title"
app:summary="@string/force_dark_mode"
android:icon="@drawable/ic_darkmode">
</SwitchPreference>

</PreferenceCategory>
<PreferenceCategory
Expand Down