1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-25 13:52:08 +01:00

- Added AMOLED mode

- Use opoc/AdBlock
- Improve NavDrawer
This commit is contained in:
Gregor Santner 2017-06-08 02:33:00 +02:00
parent 544e86073a
commit 2d7d898bfe
No known key found for this signature in database
GPG key ID: 7E83A7834AECB009
16 changed files with 2621 additions and 24 deletions

View file

@ -1,5 +1,8 @@
### v0.2.9 ### v0.2.9
- Use opoc/Helpers - Use opoc/Helpers
- Use opoc/AdBlock
- Added AMOLED mode
- Improve NavDrawer
### v0.2.7 (2017-05-26) ### v0.2.7 (2017-05-26)
- Small improvements - Small improvements

View file

@ -34,6 +34,8 @@ import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings; import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import io.github.gsantner.opoc.util.AdBlock;
public class App extends Application { public class App extends Application {
private volatile static App app; private volatile static App app;
private AppSettings appSettings; private AppSettings appSettings;
@ -69,6 +71,7 @@ public class App extends Application {
} }
cookieManager.setAcceptCookie(true); cookieManager.setAcceptCookie(true);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
AdBlock.getInstance().loadHostsFromRawAssetsAsync(this);
} }
public void resetPodData(@Nullable WebView webView) { public void resetPodData(@Nullable WebView webView) {

View file

@ -25,6 +25,8 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -424,6 +426,14 @@ public class MainActivity extends ThemedActivity
navheaderImage.setImageResource(R.drawable.ic_launcher_test); navheaderImage.setImageResource(R.drawable.ic_launcher_test);
} }
updateNavigationViewEntryVisibilities(); updateNavigationViewEntryVisibilities();
if (appSettings.isAmoledColorMode()) {
navView.setItemTextColor(ColorStateList.valueOf(Color.LTGRAY));
navView.setItemIconTintList(ColorStateList.valueOf(Color.LTGRAY));
navView.setBackgroundColor(Color.BLACK);
navheaderTitle.setTextColor(Color.LTGRAY);
navheaderDescription.setTextColor(Color.GRAY);
}
} }
protected void updateNavigationViewEntryVisibilities() { protected void updateNavigationViewEntryVisibilities() {

View file

@ -22,6 +22,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
@ -176,10 +177,18 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
listedPodsList.add(pod.getPodUrl().getHost()); listedPodsList.add(pod.getPodUrl().getHost());
} }
listViewPodAdapter = new ArrayAdapter<>( listViewPodAdapter = new ArrayAdapter<String>(
getContext(), getContext(),
android.R.layout.simple_list_item_1, android.R.layout.simple_list_item_1,
listedPodsList); listedPodsList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTextColor(Color.BLACK);
return view;
}
};
// save index and top position // save index and top position
int index = listViewPod.getFirstVisiblePosition(); int index = listViewPod.getFirstVisiblePosition();

View file

@ -17,6 +17,7 @@ package com.github.dfa.diaspora_android.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.BuildConfig; import com.github.dfa.diaspora_android.BuildConfig;
@ -394,9 +395,13 @@ public class AppSettings extends AppSettingsBase {
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public int getPrimaryColor() { public int getPrimaryColor() {
if (isAmoledColorMode()) {
return Color.BLACK;
} else {
return getInt(prefApp, R.string.pref_key__primary_color_shade, rcolor( return getInt(prefApp, R.string.pref_key__primary_color_shade, rcolor(
BuildConfig.IS_TEST_BUILD ? R.color.md_brown_800 : R.color.primary)); BuildConfig.IS_TEST_BUILD ? R.color.md_brown_800 : R.color.primary));
} }
}
public void setAccentColorSettings(int base, int shade) { public void setAccentColorSettings(int base, int shade) {
setInt(prefApp, R.string.pref_key__accent_color_base, base); setInt(prefApp, R.string.pref_key__accent_color_base, base);
@ -417,4 +422,12 @@ public class AppSettings extends AppSettingsBase {
public boolean isExtendedNotificationsActivated() { public boolean isExtendedNotificationsActivated() {
return getBool(prefApp, R.string.pref_key__extended_notifications, false); return getBool(prefApp, R.string.pref_key__extended_notifications, false);
} }
public boolean isAmoledColorMode() {
return getBool(prefApp, R.string.pref_key__primary_color__amoled_mode, false);
}
public boolean isAdBlockEnabled() {
return getBool(prefApp, R.string.pref_key__adblock_enable, true);
}
} }

View file

@ -18,9 +18,13 @@
*/ */
package com.github.dfa.diaspora_android.web; package com.github.dfa.diaspora_android.web;
import android.annotation.TargetApi;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.WebResourceResponse;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
@ -29,12 +33,16 @@ import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.data.DiasporaPodList; import com.github.dfa.diaspora_android.data.DiasporaPodList;
import com.github.dfa.diaspora_android.util.AppSettings; import com.github.dfa.diaspora_android.util.AppSettings;
import io.github.gsantner.opoc.util.AdBlock;
public class CustomWebViewClient extends WebViewClient { public class CustomWebViewClient extends WebViewClient {
private final App app; private final App app;
private String lastLoadUrl = ""; private String lastLoadUrl = "";
private boolean isAdBlockEnabled = false;
public CustomWebViewClient(App app, WebView webView) { public CustomWebViewClient(App app, WebView webView) {
this.app = app; this.app = app;
isAdBlockEnabled = AppSettings.get().isAdBlockEnabled();
} }
//Open non-diaspora links in customtab/external browser //Open non-diaspora links in customtab/external browser
@ -77,4 +85,15 @@ public class CustomWebViewClient extends WebViewClient {
} }
} }
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (isAdBlockEnabled && AdBlock.getInstance().isAdHost(url)) {
return AdBlock.createEmptyResponse();
}
return super.shouldInterceptRequest(view, url);
}
} }

View file

@ -0,0 +1,171 @@
/*
* ---------------------------------------------------------------------------- *
* Gregor Santner <gsantner.github.io> wrote this file. You can do whatever
* you want with this stuff. If we meet some day, and you think this stuff is
* worth it, you can buy me a coke in return. Provided as is without any kind
* of warranty. No attribution required. - Gregor Santner
*
* License: Creative Commons Zero (CC0 1.0)
* http://creativecommons.org/publicdomain/zero/1.0/
* ----------------------------------------------------------------------------
*/
/*
* Place adblock hosts file in raw: src/main/res/raw/adblock_domains__xyz.txt
* Always blocks both, www and non www
* Load hosts (call e.g. via Application-Object)
AdBlock.getInstance().loadHostsFromRawAssetsAsync(context);
* Override inside a WebViewClient:
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
return AdBlock.getInstance().isAdHost(url)
? AdBlock.createEmptyResponse()
: super.shouldInterceptRequest(view, url);
}
*/
package io.github.gsantner.opoc.util;
import android.content.Context;
import android.util.Log;
import android.webkit.WebResourceResponse;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.github.dfa.diaspora_android.R;
/**
* Simple Host-Based AdBlocker
*/
public class AdBlock {
private static final AdBlock instance = new AdBlock();
public static AdBlock getInstance() {
return instance;
}
//########################
//##
//## Members
//##
//########################
private final Set<String> adblockHostsFromRaw = new HashSet<>();
private final Set<String> adblockHosts = new HashSet<>();
private boolean isLoaded;
//########################
//##
//## Methods
//##
//########################
private AdBlock() {
}
public boolean isAdHost(String urlS) {
if (urlS != null && !urlS.isEmpty() && urlS.startsWith("http")) {
try {
URI url = new URI(urlS);
String host = url.getHost().trim();
if (host.startsWith("www.") && host.length() >= 4) {
host = host.substring(4);
}
return adblockHosts.contains(host) || adblockHosts.contains("www." + host);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
return false;
}
public AdBlock reset() {
adblockHosts.clear();
adblockHosts.addAll(adblockHostsFromRaw);
return this;
}
public static WebResourceResponse createEmptyResponse() {
return new WebResourceResponse("text/plain", "utf-8", new ByteArrayInputStream("".getBytes()));
}
public void addBlockedHosts(String... hosts) {
for (String host : hosts) {
if (host != null) {
host = host.trim();
if (host.startsWith("www.") && host.length() >= 4) {
host = host.substring(4);
}
if (!host.startsWith("#") && !host.startsWith("\"")) {
adblockHosts.add(host);
}
}
}
}
public void loadHostsFromRawAssetsAsync(final Context context) {
new Thread(new Runnable() {
@Override
public void run() {
try {
loadHostsFromRawAssets(context);
isLoaded = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
private void loadHostsFromRawAssets(Context context) throws IOException {
BufferedReader br = null;
String host;
adblockHosts.clear();
for (int rawId : getAdblockIdsInRaw()) {
try {
br = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(rawId)));
while ((host = br.readLine()) != null) {
addBlockedHosts(host);
}
} catch (Exception e) {
Log.d(AdBlock.class.getName(), "Error: Cannot read adblock res " + rawId);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ignored) {
}
}
}
}
adblockHostsFromRaw.clear();
adblockHostsFromRaw.addAll(adblockHosts);
}
private List<Integer> getAdblockIdsInRaw() {
ArrayList<Integer> adblockResIds = new ArrayList<>();
Field[] fields = R.raw.class.getFields();
for (Field field : fields) {
try {
int resId = field.getInt(field);
String resFilename = field.getName();
if (resFilename.startsWith("adblock_domains__")) {
adblockResIds.add(resId);
}
} catch (IllegalAccessException ignored) {
}
}
return adblockResIds;
}
}

View file

@ -6,7 +6,8 @@
android:layout_height="110dp" android:layout_height="110dp"
android:gravity="bottom" android:gravity="bottom"
android:orientation="vertical" android:orientation="vertical"
android:theme="@style/ThemeOverlay.AppCompat.Dark"> android:theme="@style/ThemeOverlay.AppCompat.Dark"
tools:background="@color/primary">
<!-- <!--
<ImageView <ImageView
@ -57,7 +58,8 @@
android:text="@string/app_name" android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="16sp" /> android:textSize="16sp"
android:textStyle="bold" />
<TextView <TextView
android:id="@+id/podselection__podupti_notice" android:id="@+id/podselection__podupti_notice"

View file

@ -70,8 +70,7 @@
android:visible="false" /> android:visible="false" />
</group> </group>
<item android:title="@string/nav_menu_more"> <group android:checkableBehavior="none">
<menu>
<item <item
android:id="@+id/nav_toggle_desktop_page" android:id="@+id/nav_toggle_desktop_page"
android:icon="@drawable/ic_sync_white_48px" android:icon="@drawable/ic_sync_white_48px"
@ -86,7 +85,6 @@
android:id="@+id/nav_about" android:id="@+id/nav_about"
android:icon="@drawable/ic_info_black_48px" android:icon="@drawable/ic_info_black_48px"
android:title="@string/nav_help_license" /> android:title="@string/nav_help_license" />
</menu> </group>
</item>
</menu> </menu>

File diff suppressed because it is too large Load diff

View file

@ -28,6 +28,8 @@
<string name="pref_desc__primary_color">Färbung der Werkzeugleisten</string> <string name="pref_desc__primary_color">Färbung der Werkzeugleisten</string>
<string name="pref_title__accent_color">Akzentfarbe</string> <string name="pref_title__accent_color">Akzentfarbe</string>
<string name="pref_desc__accent_color">Färbung der Details</string> <string name="pref_desc__accent_color">Färbung der Details</string>
<string name="pref_title__primary_color__amoled_mode">AMOLED Modus</string>
<string name="pref_desc__primary_color__amoled_mode">Farben mit AMOLED-Display freundlichen Farben an vielen Orten der App überschreiben. Ein Neustart ist erforderlich um diese Einstellung zu ändern. Du kannst in deinen persönlichen diaspora* Einstellungen das dunkle Thema aktivieren, damit wird auch der Inhalt dunkler.</string>
<!-- Notifications dropdown --> <!-- Notifications dropdown -->
<string name="pref_title__extended_notifications">Erweiterte Benachrichtigungen</string> <string name="pref_title__extended_notifications">Erweiterte Benachrichtigungen</string>
<string name="pref_desc__extended_notifications">Erweitere die Benachrichtigungsglocke um ein Ausklappmenü mit verschiedenen Benachrichtigungskategorien</string> <string name="pref_desc__extended_notifications">Erweitere die Benachrichtigungsglocke um ein Ausklappmenü mit verschiedenen Benachrichtigungskategorien</string>
@ -85,4 +87,6 @@
<string name="dialog_content__wipe_settings">Dies wird alle geänderten Einstellungen der Anwendung auf die Standardwerte zurücksetzen und alle Konten abmelden. Deine heruntergeladenen Medien bleiben unberührt. Bist du sicher, dass du fortfahren willst?</string> <string name="dialog_content__wipe_settings">Dies wird alle geänderten Einstellungen der Anwendung auf die Standardwerte zurücksetzen und alle Konten abmelden. Deine heruntergeladenen Medien bleiben unberührt. Bist du sicher, dass du fortfahren willst?</string>
<!-- Recently added - Please move to right section--> <!-- Recently added - Please move to right section-->
<!-- Sorry --> <!-- Sorry -->
<string name="pref_desc__adblock_enable">Einfachen Werbeblocker aktivieren. Werbung könnte z.B. in eingebetteten Anzeigen enthalten sein</string>
<string name="pref_title__adblock_enable">Werbung blockieren</string>
</resources> </resources>

View file

@ -19,6 +19,7 @@
<string name="pref_key__app_first_start_current_version" translatable="false">pref_key__app_first_start_current_version</string> <string name="pref_key__app_first_start_current_version" translatable="false">pref_key__app_first_start_current_version</string>
<!-- Themes --> <!-- Themes -->
<string name="pref_key__primary_color__amoled_mode" translatable="false">pref_key__primary_color__amoled_mode</string>
<string name="pref_key__primary_color__preference_click" translatable="false">@string/pref_key__primary_color_shade</string> <string name="pref_key__primary_color__preference_click" translatable="false">@string/pref_key__primary_color_shade</string>
<string name="pref_key__primary_color_base" translatable="false">pref_key_primary_color_base</string> <string name="pref_key__primary_color_base" translatable="false">pref_key_primary_color_base</string>
<string name="pref_key__primary_color_shade" translatable="false">pref_key_primary_color_shade</string> <string name="pref_key__primary_color_shade" translatable="false">pref_key_primary_color_shade</string>
@ -92,6 +93,8 @@
<string name="pref_desc__primary_color">Color of the toolbars</string> <string name="pref_desc__primary_color">Color of the toolbars</string>
<string name="pref_title__accent_color">Accent Color</string> <string name="pref_title__accent_color">Accent Color</string>
<string name="pref_desc__accent_color">Color of the progressbar</string> <string name="pref_desc__accent_color">Color of the progressbar</string>
<string name="pref_title__primary_color__amoled_mode">AMOLED Mode</string>
<string name="pref_desc__primary_color__amoled_mode">Override colors with AMOLED display friendly black at many parts of the app. You need to restart to toggle this setting. To browse diaspora* in dark you also need to activate the Dark theme, which can be found in your personal diaspora* account settings.</string>
<!-- Notifications dropdown --> <!-- Notifications dropdown -->
<string name="pref_title__extended_notifications">Extended Notifications</string> <string name="pref_title__extended_notifications">Extended Notifications</string>
@ -213,8 +216,13 @@
<string name="pref_key__title__proxy" translatable="false">pref_key__title__proxy</string> <string name="pref_key__title__proxy" translatable="false">pref_key__title__proxy</string>
<string name="pref_key__title__themes" translatable="false">pref_key__title__themes</string> <string name="pref_key__title__themes" translatable="false">pref_key__title__themes</string>
<string name="pref_key__cat_themes" translatable="false">pref_key__cat_themes</string> <string name="pref_key__cat_themes" translatable="false">pref_key__cat_themes</string>
<string name="pref_key__cat_nav_slider" translatable="false">pref_key__cat_nav_slider</string> <string name="pref_key__cat_nav_slider" translatable="false">pref_key__cat_nav_slider</string>
<string name="pref_key__cat_proxy" translatable="false">pref_key__cat_proxy</string> <string name="pref_key__cat_proxy" translatable="false">pref_key__cat_proxy</string>
<string name="pref_key__cat_debugging" translatable="false">pref_key__cat_debugging</string> <string name="pref_key__cat_debugging" translatable="false">pref_key__cat_debugging</string>
<string name="pref_key__adblock_enable" translatable="false">pref_key__adblock_enable</string>
<string name="pref_desc__adblock_enable">Enable basic AdBlocker. Ads may be included e.g. in embedded views</string>
<string name="pref_title__adblock_enable">Block advertisements</string>
</resources> </resources>

View file

@ -4,7 +4,7 @@
<string name="diaspora" translatable="false">diaspora*</string> <string name="diaspora" translatable="false">diaspora*</string>
<string name="diaspora_for_android" translatable="false">Diaspora for Android</string> <string name="diaspora_for_android" translatable="false">Diaspora for Android</string>
<string name="app_hashtag" translatable="false">#dandelion</string> <string name="app_hashtag" translatable="false">#dandelion</string>
<string name="app_subtitle" translatable="false">The community-run distributed social network</string> <string name="app_subtitle" translatable="false">Your companion app for browsing diaspora*</string>
<string name="shared_via_app" translatable="false"> <string name="shared_via_app" translatable="false">
\n\n\n_________________________\n \n\n\n_________________________\n
*via [dandelion*](/people?q=dandelion00%40diasp.org) client / #dandelíon*</string> *via [dandelion*](/people?q=dandelion00%40diasp.org) client / #dandelíon*</string>

View file

@ -128,6 +128,13 @@
android:summary="@string/pref_desc__load_images" android:summary="@string/pref_desc__load_images"
android:title="@string/pref_title__load_images"/> android:title="@string/pref_title__load_images"/>
<com.github.dfa.diaspora_android.ui.theme.ThemedCheckBoxPreference
android:defaultValue="true"
android:icon="@drawable/ic_file_download_black_24px"
android:key="@string/pref_key__adblock_enable"
android:summary="@string/pref_desc__adblock_enable"
android:title="@string/pref_title__adblock_enable"/>
<Preference <Preference
android:icon="@drawable/ic_clear_black_24px" android:icon="@drawable/ic_clear_black_24px"
android:key="@string/pref_key__clear_cache" android:key="@string/pref_key__clear_cache"

View file

@ -49,7 +49,7 @@
android:title="@string/pref_cat__visibility_nav_items__general"> android:title="@string/pref_cat__visibility_nav_items__general">
<com.github.dfa.diaspora_android.ui.theme.ThemedVisibilityPreference <com.github.dfa.diaspora_android.ui.theme.ThemedVisibilityPreference
android:defaultValue="false" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__exit" android:key="@string/pref_key__visibility_nav__exit"
android:title="@string/action_exit_app"/> android:title="@string/action_exit_app"/>
<com.github.dfa.diaspora_android.ui.theme.ThemedVisibilityPreference <com.github.dfa.diaspora_android.ui.theme.ThemedVisibilityPreference

View file

@ -14,5 +14,12 @@
android:summary="@string/pref_desc__accent_color" android:summary="@string/pref_desc__accent_color"
android:title="@string/pref_title__accent_color" android:title="@string/pref_title__accent_color"
android:icon="@drawable/circle" /> android:icon="@drawable/circle" />
<com.github.dfa.diaspora_android.ui.theme.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__primary_color__amoled_mode"
android:summary="@string/pref_desc__primary_color__amoled_mode"
android:title="@string/pref_title__primary_color__amoled_mode"
android:icon="@drawable/ic_color_lens_black_24px" />
</com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory> </com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory>
</PreferenceScreen> </PreferenceScreen>