diff --git a/.gitignore b/.gitignore
index 288c884..49c34cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,7 +49,6 @@ captures/
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
-google-services.json
# Freeline
freeline.py
@@ -106,7 +105,6 @@ captures/
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
-google-services.json
# Freeline
freeline.py
@@ -164,11 +162,11 @@ captures/
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
-# Google Services (e.g. APIs or Firebase)
-google-services.json
+
# Freeline
freeline.py
freeline/
freeline_project_description.json
+libs/
diff --git a/app/.gitignore b/app/.gitignore
deleted file mode 100644
index d75ebc1..0000000
--- a/app/.gitignore
+++ /dev/null
@@ -1,117 +0,0 @@
-/build
-### Android template
-# Built application files
-*.apk
-*.ap_
-
-# Files for the ART/Dalvik VM
-*.dex
-
-# Java class files
-*.class
-
-# Generated files
-bin/
-gen/
-out/
-
-# Gradle files
-.gradle/
-build/
-
-# Local configuration file (sdk path, etc)
-local.properties
-
-# Proguard folder generated by Eclipse
-proguard/
-
-# Log Files
-*.log
-
-# Android Studio Navigation editor temp files
-.navigation/
-
-# Android Studio captures folder
-captures/
-
-# Intellij
-*.iml
-.idea/workspace.xml
-.idea/tasks.xml
-.idea/gradle.xml
-.idea/dictionaries
-.idea/libraries
-
-# Keystore files
-# Uncomment the following line if you do not want to check your keystore files in.
-#*.jks
-
-# External native build folder generated in Android Studio 2.2 and later
-.externalNativeBuild
-
-# Google Services (e.g. APIs or Firebase)
-google-services.json
-
-# Freeline
-freeline.py
-freeline/
-freeline_project_description.json
-
-### Android template
-# Built application files
-*.apk
-*.ap_
-
-# Files for the ART/Dalvik VM
-*.dex
-
-# Java class files
-*.class
-
-# Generated files
-bin/
-gen/
-out/
-
-# Gradle files
-.gradle/
-build/
-
-# Local configuration file (sdk path, etc)
-local.properties
-
-# Proguard folder generated by Eclipse
-proguard/
-
-# Log Files
-*.log
-
-# Android Studio Navigation editor temp files
-.navigation/
-
-# Android Studio captures folder
-captures/
-
-# IntelliJ
-*.iml
-.idea/workspace.xml
-.idea/tasks.xml
-.idea/gradle.xml
-.idea/dictionaries
-.idea/libraries
-
-# Keystore files
-# Uncomment the following line if you do not want to check your keystore files in.
-#*.jks
-
-# External native build folder generated in Android Studio 2.2 and later
-.externalNativeBuild
-
-# Google Services (e.g. APIs or Firebase)
-google-services.json
-
-# Freeline
-freeline.py
-freeline/
-freeline_project_description.json
-
diff --git a/app/build.gradle b/app/build.gradle
index f39b316..c4799c5 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,8 +7,8 @@ android {
applicationId "com.github.xfalcon.vhosts"
minSdkVersion 19
targetSdkVersion 28
- versionCode 36
- versionName "2.0.7"
+ versionCode 37
+ versionName "2.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
@@ -50,7 +50,6 @@ dependencies {
implementation 'com.android.support:cardview-v7:28.0.0'
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation 'com.android.support:preference-v7:28.0.0'
-// implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
implementation 'com.github.clans:fab:1.6.4'
testImplementation 'junit:junit:4.12'
diff --git a/app/google-services.json b/app/google-services.json
new file mode 100644
index 0000000..78d4291
--- /dev/null
+++ b/app/google-services.json
@@ -0,0 +1,40 @@
+{
+ "project_info": {
+ "project_number": "1050109021929",
+ "firebase_url": "https://api-5874083157835505386-758464.firebaseio.com",
+ "project_id": "api-5874083157835505386-758464",
+ "storage_bucket": "api-5874083157835505386-758464.appspot.com"
+ },
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:1050109021929:android:c1dc6c6b163e1bae",
+ "android_client_info": {
+ "package_name": "com.github.xfalcon.vhosts"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "1050109021929-qklglsvs6k4gj10isuh3ipklopkoen69.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyAkDG6T5t2EtA6oXquofFoT5FTWQLoMe88"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "1050109021929-qklglsvs6k4gj10isuh3ipklopkoen69.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "configuration_version": "1"
+}
\ No newline at end of file
diff --git a/app/src/androidTest/java/com/github/xfalcon/vhosts/PressureTest.java b/app/src/androidTest/java/com/github/xfalcon/vhosts/PressureTest.java
index 7fb139d..c8f3a7b 100644
--- a/app/src/androidTest/java/com/github/xfalcon/vhosts/PressureTest.java
+++ b/app/src/androidTest/java/com/github/xfalcon/vhosts/PressureTest.java
@@ -18,14 +18,13 @@
package com.github.xfalcon.vhosts;
-import static android.support.test.espresso.Espresso.onView;
import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.rule.ActivityTestRule;
-import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.rule.ActivityTestRule;
+import androidx.test.runner.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,8 +39,9 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.*;
/**
diff --git a/app/src/main/java/com/github/xfalcon/vhosts/SettingsFragment.java b/app/src/main/java/com/github/xfalcon/vhosts/SettingsFragment.java
index c24560e..33c3081 100644
--- a/app/src/main/java/com/github/xfalcon/vhosts/SettingsFragment.java
+++ b/app/src/main/java/com/github/xfalcon/vhosts/SettingsFragment.java
@@ -25,10 +25,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
-import android.view.Gravity;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.WindowManager;
+import android.view.*;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -70,35 +67,67 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Preference urlCustomPref = findPreference(HOSTS_URL);
Preference dnsCustomPref = findPreference(IPV4_DNS);
- dnsCustomPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ dnsCustomPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceClick(Preference preference) {
- String ipv4_dns = sharedPreferences.getString(IPV4_DNS, "");
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String ipv4_dns = (String)newValue;
try {
Address.getByAddress(ipv4_dns);
return true;
} catch (Exception e) {
LogUtils.e(TAG, e.getMessage(), e);
- Toast.makeText(preference.getContext(), getString(R.string.url_error), Toast.LENGTH_LONG).show();
+ Toast.makeText(preference.getContext(), getString(R.string.dns4_error), Toast.LENGTH_LONG).show();
}
return false;
}
});
- urlCustomPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference preference) {
- String url = sharedPreferences.getString(HOSTS_URL, "");
+// dnsCustomPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+//
+// public boolean onPreferenceClick(Preference preference) {
+// String ipv4_dns = sharedPreferences.getString(IPV4_DNS, "");
+// try {
+// Address.getByAddress(ipv4_dns);
+// return true;
+// } catch (Exception e) {
+// LogUtils.e(TAG, e.getMessage(), e);
+// Toast.makeText(preference.getContext(), getString(R.string.url_error), Toast.LENGTH_LONG).show();
+// }
+// return false;
+// }
+// });
+
+ urlCustomPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String url = (String)newValue;
if (isUrl(url)) {
setProgressDialog(preference.getContext(), url);
return true;
} else {
- Toast.makeText(preference.getContext(), getString(R.string.dns4_error), Toast.LENGTH_LONG).show();
+ Toast.makeText(preference.getContext(), getString(R.string.url_error), Toast.LENGTH_LONG).show();
return false;
}
-
}
});
+
+// urlCustomPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+//
+// public boolean onPreferenceClick(Preference preference) {
+// String url = sharedPreferences.getString(HOSTS_URL, "");
+// if (isUrl(url)) {
+// setProgressDialog(preference.getContext(), url);
+// return true;
+// } else {
+// Toast.makeText(preference.getContext(), getString(R.string.url_error), Toast.LENGTH_LONG).show();
+// return false;
+// }
+//
+// }
+// });
}
public void setProgressDialog(final Context context, final String url) {
@@ -225,6 +254,17 @@ public void onCreate(Bundle savedInstanceState) {
.registerOnSharedPreferenceChangeListener(this);
}
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ // create ContextThemeWrapper from the original Activity Context with the custom theme
+
+ // clone the inflater using the ContextThemeWrapper
+ inflater.getContext().setTheme(R.style.AppPreferenceSettingsFragmentTheme);
+
+ // inflate the layout using the cloned inflater, not default inflater
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
@Override
public void onResume() {
super.onResume();
diff --git a/app/src/main/java/com/github/xfalcon/vhosts/VhostsActivity.java b/app/src/main/java/com/github/xfalcon/vhosts/VhostsActivity.java
index 17546c4..758f90f 100644
--- a/app/src/main/java/com/github/xfalcon/vhosts/VhostsActivity.java
+++ b/app/src/main/java/com/github/xfalcon/vhosts/VhostsActivity.java
@@ -219,13 +219,22 @@ private void setUriByPREFS(Intent intent) {
getContentResolver().takePersistableUriPermission(uri, takeFlags);
editor.putString(SettingsFragment.HOSTS_URI, uri.toString());
editor.apply();
- if (checkHostUri() == 1) {
- setButton(true);
- setButton(false);
- } else {
- Toast.makeText(this, R.string.permission_error, Toast.LENGTH_LONG).show();
+ switch (checkHostUri()){
+ case 1:{
+ setButton(true);
+ setButton(false);
+ break;
+ }case -1:{
+ Toast.makeText(this, R.string.permission_error, Toast.LENGTH_LONG).show();
+ break;
+ }case 2:{
+ break;
+ }case -2:{
+ break;
+ }
}
+
} catch (Exception e) {
LogUtils.e(TAG, "permission error", e);
}
diff --git a/app/src/main/java/com/github/xfalcon/vhosts/vservice/VhostsService.java b/app/src/main/java/com/github/xfalcon/vhosts/vservice/VhostsService.java
index 3249f1b..99e33f1 100644
--- a/app/src/main/java/com/github/xfalcon/vhosts/vservice/VhostsService.java
+++ b/app/src/main/java/com/github/xfalcon/vhosts/vservice/VhostsService.java
@@ -27,7 +27,9 @@
import android.net.Uri;
import android.net.VpnService;
import android.os.Build;
+import android.os.Looper;
import android.os.ParcelFileDescriptor;
+import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.github.xfalcon.vhosts.NetworkReceiver;
import com.github.xfalcon.vhosts.R;
@@ -94,7 +96,7 @@ public void onCreate() {
.build();
startForeground(1, notification);
}
- isOAndBoot=false;
+ isOAndBoot = false;
}
setupHostFile();
setupVPN();
@@ -131,8 +133,8 @@ public void onCreate() {
private void setupHostFile() {
- SharedPreferences settings = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this);
- boolean is_net = settings.getBoolean(SettingsFragment.IS_NET, false);
+ SharedPreferences settings = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this);
+ final boolean is_net = settings.getBoolean(SettingsFragment.IS_NET, false);
String uri_path = settings.getString(SettingsFragment.HOSTS_URI, null);
try {
final InputStream inputStream;
@@ -142,11 +144,24 @@ private void setupHostFile() {
inputStream = getContentResolver().openInputStream(Uri.parse(uri_path));
new Thread() {
public void run() {
- DnsChange.handle_hosts(inputStream);
+ if (DnsChange.handle_hosts(inputStream) == 0) {
+ Looper.prepare();
+ if(is_net){
+ Toast.makeText(getApplicationContext(), R.string.no_net_record, Toast.LENGTH_LONG).show();
+ }else{
+ Toast.makeText(getApplicationContext(), R.string.no_local_record, Toast.LENGTH_LONG).show();
+ }
+ Looper.loop();
+ }
}
}.start();
} catch (Exception e) {
+ if(is_net){
+ Toast.makeText(getApplicationContext(), R.string.no_net_record, Toast.LENGTH_LONG).show();
+ }else{
+ Toast.makeText(getApplicationContext(), R.string.no_local_record, Toast.LENGTH_LONG).show();
+ }
LogUtils.e(TAG, "error setup host file service", e);
}
}
@@ -158,16 +173,16 @@ private void setupVPN() {
builder.addAddress(VPN_ADDRESS6, 128);
- SharedPreferences settings = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this);
+ SharedPreferences settings = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this);
String VPN_DNS4_DEFAULT = getString(R.string.dns_server);
- boolean is_cus_dns = settings.getBoolean(SettingsFragment.IS_CUS_DNS,false);
- String VPN_DNS4=VPN_DNS4_DEFAULT;
- if(is_cus_dns){
+ boolean is_cus_dns = settings.getBoolean(SettingsFragment.IS_CUS_DNS, false);
+ String VPN_DNS4 = VPN_DNS4_DEFAULT;
+ if (is_cus_dns) {
VPN_DNS4 = settings.getString(SettingsFragment.IPV4_DNS, VPN_DNS4_DEFAULT);
try {
Address.getByAddress(VPN_DNS4);
} catch (Exception e) {
- VPN_DNS4=VPN_DNS4_DEFAULT;
+ VPN_DNS4 = VPN_DNS4_DEFAULT;
LogUtils.e(TAG, e.getMessage(), e);
}
}
diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml
index 02aadd4..f3392f7 100644
--- a/app/src/main/res/values-vi/strings.xml
+++ b/app/src/main/res/values-vi/strings.xml
@@ -57,4 +57,7 @@
Cài đặt
Nhập DNS không đúng.
Đang tải xuống tập tin ...
+
+ cảnh báo! tệp lưu trữ mạng không có bản ghi dns, vui lòng kiểm tra
+ cảnh báo! tệp máy chủ cục bộ không có bản ghi dns, vui lòng kiểm tra
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 83e5dc8..b01bee8 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -54,4 +54,6 @@
使用遠程Hosts文件
DNS 輸入不正確
正在下載文件...
+ 提示! 網絡文件不存在DNS記錄,請檢查
+ 提示! 本地文件不存在DNS記錄,請檢查
\ No newline at end of file
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 8c8f36b..ce6f503 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -53,4 +53,7 @@
使用远程Hosts文件
DNS 输入不正确
正在下载文件...
+
+ 提示! 网络文件不存在DNS记录,请检查
+ 提示! 本地文件不存在DNS记录,请检查
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 01afb27..bb64124 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -58,4 +58,7 @@
use custom dns
Downloading File...
+ warning! net hosts file no dns record, please check
+ warning! local hosts file no dns record, please check
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 68f834d..9872909 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -15,7 +15,12 @@
+