Skip to content

Commit

Permalink
add setting
Browse files Browse the repository at this point in the history
  • Loading branch information
x-falcon committed Sep 2, 2019
1 parent 2f16506 commit 74adaea
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 158 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ captures/
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
Expand Down Expand Up @@ -106,7 +105,6 @@ captures/
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
Expand Down Expand Up @@ -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/
117 changes: 0 additions & 117 deletions app/.gitignore

This file was deleted.

5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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'
Expand Down
40 changes: 40 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;

/**
Expand Down
66 changes: 53 additions & 13 deletions app/src/main/java/com/github/xfalcon/vhosts/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/com/github/xfalcon/vhosts/VhostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 74adaea

Please sign in to comment.