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
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ android {

buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
minifyEnabled !rootProject.ext.ci
useProguard false
}
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />

<permission android:name="io.github.hidroh.materialistic.permission.SYNC_ITEM"
<permission android:name="${applicationId}.permission.SYNC_ITEM"
android:protectionLevel="signature" />
<permission android:name="io.github.hidroh.materialistic.permission.AUTHENTICATE_ACCOUNTS"
<permission android:name="${applicationId}.permission.AUTHENTICATE_ACCOUNTS"
android:protectionLevel="signature" />
<uses-permission android:name="io.github.hidroh.materialistic.permission.SYNC_ITEM" />
<uses-permission android:name="io.github.hidroh.materialistic.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="${applicationId}.permission.SYNC_ITEM" />
<uses-permission android:name="${applicationId}.permission.AUTHENTICATE_ACCOUNTS" />

<uses-sdk tools:overrideLibrary="androidx.browser" />

Expand Down Expand Up @@ -271,15 +271,15 @@
android:name=".data.WebCacheService"
android:exported="false" />
<provider
android:authorities="io.github.hidroh.materialistic.syncprovider"
android:authorities="${applicationId}.syncprovider"
android:name=".data.SyncContentProvider"
android:exported="false" />
<provider
android:authorities="io.github.hidroh.materialistic.recentprovider"
android:authorities="${applicationId}.recentprovider"
android:name=".data.SearchRecentSuggestionsProvider"
android:exported="false" />
<provider
android:authorities="io.github.hidroh.materialistic.fileprovider"
android:authorities="${applicationId}.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.hidroh.materialistic

import android.content.Context
import java.net.InetSocketAddress
import java.net.Proxy

class DelegatingProxy : Proxy(Type.SOCKS, InetSocketAddress.createUnresolved("127.0.0.1", 1)) {
override fun type() = activeProxy.type()
override fun address() = activeProxy.address()

companion object {
var activeProxy: Proxy = NO_PROXY

@JvmStatic
fun updateFromPreferences(context: Context) {
activeProxy = Preferences.getProxy(context)
}
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/io/github/hidroh/materialistic/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.pm.PackageManager;
import android.text.TextUtils;

import java.net.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
Expand Down Expand Up @@ -304,13 +305,39 @@ public static SwipeAction[] getListSwipePreferences(Context context) {
return new SwipeAction[]{parseSwipeAction(left), parseSwipeAction(right)};
}

public static Proxy getProxy(Context context) {
boolean isEnabled = get(context, R.string.pref_proxy_enabled, false);
if (!isEnabled)
return Proxy.NO_PROXY;
Proxy.Type type = getProxyType(context);
String host = get(context, R.string.pref_proxy_host, R.string.pref_proxy_host_default);
int port = Integer.parseInt(get(context, R.string.pref_proxy_port, R.string.pref_proxy_port_default));
try {
return new Proxy(type, new InetSocketAddress(InetAddress.getByName(host), port));
} catch (UnknownHostException e) {
e.printStackTrace();
return Proxy.NO_PROXY;
}
}

public static void reset(Context context) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.clear()
.apply();
}

private static Proxy.Type getProxyType(Context context) {
String protocolStr = get(context, R.string.pref_proxy_protocol, R.string.pref_proxy_protocol_socks);
if (context.getResources().getString(R.string.pref_proxy_protocol_value_socks).equals(protocolStr)) {
return Proxy.Type.SOCKS;
} else if (context.getResources().getString(R.string.pref_proxy_protocol_value_http).equals(protocolStr)) {
return Proxy.Type.HTTP;
} else {
throw new IllegalArgumentException("Invalid proxy protocol: " + protocolStr);
}
}

private static SwipeAction parseSwipeAction(String value) {
try {
return SwipeAction.valueOf(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override
protected void onDestroy() {
super.onDestroy();
DelegatingProxy.updateFromPreferences(this);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(new Intent(SettingsActivity.this, PreferencesActivity.class)
.putExtra(PreferencesActivity.EXTRA_TITLE, R.string.readability)
.putExtra(PreferencesActivity.EXTRA_PREFERENCES, R.xml.preferences_readability)));
findViewById(R.id.menu_proxy).setOnClickListener(v ->
startActivity(new Intent(SettingsActivity.this, PreferencesActivity.class)
.putExtra(PreferencesActivity.EXTRA_TITLE, R.string.proxy)
.putExtra(PreferencesActivity.EXTRA_PREFERENCES, R.xml.preferences_proxy)));
findViewById(R.id.drawer_about).setOnClickListener(v ->
startActivity(new Intent(SettingsActivity.this, AboutActivity.class)));
findViewById(R.id.drawer_release).setOnClickListener(v ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTaskTitle(getTitle());
mMenuTintDelegate.onActivityCreated(this);

// Maybe not the right place to do this but this needs to run
// after the app starts and ThemedActivity is a common base
// class for activities
DelegatingProxy.updateFromPreferences(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

import javax.inject.Inject;

import okhttp3.Call;
import io.github.hidroh.materialistic.*;
import okhttp3.*;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
Expand Down Expand Up @@ -72,6 +73,10 @@ public <T> T create(String baseUrl, Class<T> clazz, Executor callbackExecutor) {
builder.callFactory(mCallFactory)
.callbackExecutor(callbackExecutor != null ?
callbackExecutor : new MainThreadExecutor());
OkHttpClient httpClient = new OkHttpClient.Builder()
.proxy(new DelegatingProxy())
.build();
builder.client(httpClient);
return builder.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build()
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_baseline_language_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@
android:layout_width="match_parent"
android:layout_height="@dimen/divider" />

<io.github.hidroh.materialistic.widget.TintableTextView
android:id="@id/menu_proxy"
android:text="@string/title_activity_proxy"
app:iconStart="@drawable/ic_baseline_language_24"
style="@style/DrawerTextStyle"/>

<View
android:background="@color/blackT12"
android:layout_width="match_parent"
android:layout_height="@dimen/divider" />

<io.github.hidroh.materialistic.widget.TintableTextView
android:id="@id/drawer_about"
android:text="@string/title_activity_about"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
<string name="pref_story_display_value_article" translatable="false">article</string>
<string name="pref_story_display_value_readability" translatable="false">readability</string>

<!-- Proxy -->
<string-array name="pref_proxy_protocol_options">
<item>@string/pref_proxy_protocol_socks</item>
<item>@string/pref_proxy_protocol_http</item>
</string-array>
<string-array name="pref_proxy_protocol_values">
<item>@string/pref_proxy_protocol_value_socks</item>
<item>@string/pref_proxy_protocol_value_http</item>
</string-array>
<string name="pref_proxy_protocol_value_socks" translatable="false">socks</string>
<string name="pref_proxy_protocol_value_http" translatable="false">http</string>

<!-- Comment max lines -->
<string-array name="comment_max_lines_options">
<item>@string/comment_max_lines_3</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<item type="id" name="drawer_display" />
<item type="id" name="drawer_offline" />
<item type="id" name="drawer_more" />
<item type="id" name="menu_proxy" />

<!-- menu -->
<item type="id" name="menu_share" />
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/non_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,7 @@
]]>
</string>
<string name="fab_scrolling_view_behavior" translatable="false">io.github.hidroh.materialistic.FabAwareScrollBehavior</string>
<string name="pref_proxy_host_default" translatable="false">127.0.0.1</string>
<string name="pref_proxy_port_default" translatable="false">9050</string>

</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@
<string translatable="false" name="pref_username">pref_username</string>
<string translatable="false" name="pref_volume">pref_volume</string>
<string translatable="false" name="pref_volume_help">pref_volume_help</string>
<string translatable="false" name="pref_proxy">pref_proxy</string>
<string translatable="false" name="pref_proxy_enabled">pref_proxy_enabled</string>
<string translatable="false" name="pref_proxy_protocol">pref_proxy_protocol</string>
<string translatable="false" name="pref_proxy_host">pref_proxy_host</string>
<string translatable="false" name="pref_proxy_port">pref_proxy_port</string>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="title_activity_best">Best Stories</string>
<string name="title_activity_item">Comments</string>
<string name="title_activity_release">What\'s New</string>
<string name="title_activity_proxy">Proxy</string>
<string name="filter_title_item">Materialistic</string>
<string name="open_drawer">Open drawer</string>
<string name="close_drawer">Close drawer</string>
Expand Down Expand Up @@ -110,6 +111,13 @@
<string name="pref_smooth_scroll_summary">Disable to improve scroll accuracy</string>
<string name="pref_list_swipe_left_title">Swipe left to</string>
<string name="pref_list_swipe_right_title">Swipe right to</string>
<string name="pref_proxy_enabled_title">Use proxy</string>
<string name="pref_proxy_enabled_summary">Use a proxy server for all network requests not made via an external browser</string>
<string name="pref_proxy_protocol_title">Proxy protocol</string>
<string name="pref_proxy_protocol_socks">SOCKS</string>
<string name="pref_proxy_protocol_http">HTTP</string>
<string name="pref_proxy_host_title">Proxy server host</string>
<string name="pref_proxy_port_title">Proxy server port</string>

<string name="connection_error">Unable to connect to Hacker News. Check your connection or try again.</string>
<string name="select_story">Select a story to view</string>
Expand Down Expand Up @@ -321,5 +329,6 @@
<string name="share_file">Share file</string>
<string name="privacy_policy">Privacy Policy</string>
<string name="notification_channel_downloads">Downloads</string>
<string name="proxy">Proxy</string>

</resources>
51 changes: 51 additions & 0 deletions app/src/main/res/xml/preferences_proxy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ha Duy Trung
~
~ 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.
-->

<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.preference.SwitchPreferenceCompat
app:iconSpaceReserved="false"
android:key="@string/pref_proxy_enabled"
android:title="@string/pref_proxy_enabled_title"
android:summary="@string/pref_proxy_enabled_summary"
android:defaultValue="false"/>

<io.github.hidroh.materialistic.preference.SimpleSpinnerPreference
android:key="@string/pref_proxy_protocol"
android:dependency="@string/pref_proxy_enabled"
android:title="@string/pref_proxy_protocol_title"
app:entries="@array/pref_proxy_protocol_options"
app:entryValues="@array/pref_proxy_protocol_values"
android:defaultValue="@string/pref_proxy_protocol_value_socks"/>

<EditTextPreference
android:key="@string/pref_proxy_host"
android:dependency="@string/pref_proxy_enabled"
android:title="@string/pref_proxy_host_title"
android:defaultValue="@string/pref_proxy_host_default"
app:iconSpaceReserved="false"/>

<EditTextPreference
android:key="@string/pref_proxy_port"
android:dependency="@string/pref_proxy_enabled"
android:title="@string/pref_proxy_port_title"
android:defaultValue="@string/pref_proxy_port_default"
app:iconSpaceReserved="false"/>

</androidx.preference.PreferenceScreen>