Make custom server work when polling
[fonbot.git] / src / ro / ieval / fonbot / Utils.java
index d5e0f5bcf8de0d506748fedce0dbdaf143bf4e6d..117c528f6408d8cea153b5f665544009935329c0 100644 (file)
@@ -24,6 +24,8 @@ import static ro.ieval.fonbot.R.string.the_second_argument_to_wipe_must_be;
 import static ro.ieval.fonbot.R.string.unknown_command;
 import static ro.ieval.fonbot.R.string.wipetype_should_be_one_of;
 
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.Locale;
 
@@ -406,6 +408,21 @@ public final class Utils {
                context.startService(intent);
        }
 
+       /**
+        * Gets the server URL according to the user preferences.
+        *
+        * @param context Context instance
+        * @param path URL path
+        * @return the server URL
+        * @throws MalformedURLException if the user preferences create an invalid URL
+        */
+       public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
+               final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "ieval.ro");
+               final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777"));
+               final URL url=new URL("http", hostname, port, path);
+               return url;
+       }
+
        /**
         * Executes a given command
         *
This page took 0.010086 seconds and 4 git commands to generate.