Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Add ability to set a custom server
Browse files Browse the repository at this point in the history
Resolves #6.
  • Loading branch information
hashworks committed Jun 22, 2020
1 parent 3f36ac9 commit 4a2a8df
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.DS_Store

build
.gradle

.idea


2 changes: 1 addition & 1 deletion CorrectorSoftcatala/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ android {

dependencies {
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:+'
implementation 'com.android.support.constraint:constraint-layout:1.+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
package org.softcatala.corrector;

import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;

import java.util.Date;

public class Configuration {
private static final String SoftcatalaServer = "https://lt.softcatala.org";

private static volatile Configuration instance = null;
private static String PREF_DIALECT = "corrector.softcatala.dialect";
private static String PREF_SERVER = "corrector.softcatala.server";
//private static String PREF_DIALECT = "corrector.softcatala.dialect";
private static int HttpConnections = 0;
private static Date LastConnection = null;
//public static SpellCheckerSettingsActivity SettingsActivity;
public static SpellCheckerSettingsActivity SettingsActivity;

public static synchronized Configuration getInstance() {
if (instance == null) {
Expand Down Expand Up @@ -59,6 +60,23 @@ public void setDialect(Boolean dialect)
spref.edit().putBoolean(PREF_DIALECT, dialect).commit();
}*/

public String getServer()
{
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
return spref.getString(PREF_SERVER, SoftcatalaServer);
}

public String setServer(String server)
{
if (server.isEmpty()) {
server = SoftcatalaServer;
}

SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(SettingsActivity);
spref.edit().putString(PREF_SERVER, server).apply();
return server;
}

public int getHttpConnections() {
return HttpConnections;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.io.BufferedReader;
Expand All @@ -30,12 +31,8 @@

import android.util.Log;

import javax.net.ssl.HttpsURLConnection;

public class LanguageToolRequest {

//private static final String SERVER_URL = "https://www.softcatala.org/languagetool/api/";
private static final String SERVER_URL = "https://lt.softcatala.org/v2/check";
private static final String ENCODING = "UTF-8";
private static final String TAG = LanguageToolRequest.class.getSimpleName();
private static final String m_sessionId = GetSessionID();
Expand Down Expand Up @@ -103,9 +100,10 @@ private String sendPost(String text) {
try {

String url = BuildURL();
Log.d("softcatala", "URL: " + url);

URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");

String urlParameters = GetFillPostFields(text);
Expand Down Expand Up @@ -158,11 +156,10 @@ public Suggestion[] Request(String text) {
}

private String BuildURL() {
StringBuilder sb = new StringBuilder();
sb.append(SERVER_URL);
/* Parameter to help to track requests from the same IP */
sb.append(AddQueryParameter("?", "sessionID", m_sessionId));
return sb.toString();
return Configuration.getInstance().getServer() +
"/v2/check" +
/* Parameter to help to track requests from the same IP */
AddQueryParameter("?", "sessionID", m_sessionId);
}

String AddQueryParameter(String separator, String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SpellCheckerSettingsActivity extends PreferenceActivity {
@Override
public Intent getIntent() {
final Intent modIntent = new Intent(super.getIntent());
//Configuration.SettingsActivity = this;
Configuration.SettingsActivity = this;
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, SpellCheckerSettingsFragment.class.getName());
modIntent.putExtra(EXTRA_NO_HEADERS, true);
return modIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.EditTextPreference;
import android.preference.PreferenceFragment;
import android.util.Log;

Expand All @@ -47,6 +48,7 @@ public void onCreate(final Bundle savedInstanceState) {

setHttpConnections();
setVersion();
setServer();
//setDialect();
}

Expand All @@ -65,6 +67,21 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
});*/
}

private void setServer() {
EditTextPreference server = ((EditTextPreference) findPreference("server"));
server.setSummary(Configuration.getInstance().getServer());

server.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String newServer = newValue.toString();
newServer = Configuration.getInstance().setServer(newServer);
EditTextPreference server = ((EditTextPreference) preference);
server.setSummary(newServer);
return true;
}
});
}

private void setVersion() {
Date buildDate = BuildConfig.buildTime;
Preference version = findPreference("version");
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-br/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Adlenner LanguageTool</string>
<string name="sample_settings">Perzhioù</string>
<string name="version">Stumm</string>
<string name="server">Servijer</string>
<string name="requests">Goulennoù savet da servijer an adlenner </string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (savet war %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Revisió de text LanguageTool</string>
<string name="sample_settings">Preferències</string>
<string name="version">Versió</string>
<string name="server">Servidor</string>
<string name="requests">Sol·licituds al servidor</string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (compilat el %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">LanguageTool Textprüfer</string>
<string name="sample_settings">Einstellungen</string>
<string name="version">Version</string>
<string name="server">Server</string>
<string name="requests">Anfragen an den Textprüfungs-Server</string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (gebaut am %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Kontrolilo Lingvoilo/LanguageTool</string>
<string name="sample_settings">Agordoj</string>
<string name="version">Versio</string>
<string name="server">Servilo</string>
<string name="requests">Petoj al la servilo de kontrolado</string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (kunmetita ĉe %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Correcteur LanguageTool</string>
<string name="sample_settings">Préférences</string>
<string name="version">Version</string>
<string name="server">Serveur</string>
<string name="requests">Requêtes au serveur de correction</string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (généré sur %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Revisor LanguageTool</string>
<string name="sample_settings">Configurações</string>
<string name="version">Versão</string>
<string name="server">Servidor</string>
<string name="requests">Pedidos ao servidor do revisor</string>
<string name="version_text" formatted="false">%s (feito em %s)</string>
<string name="connections" formatted="false">%d (último %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Корректор LanguageTool </string>
<string name="sample_settings">Настройки</string>
<string name="version">Версия</string>
<string name="server">Cерверу</string>
<string name="requests">Объём запросов к серверу проверки</string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (сборка от %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="spellchecker_name">Коректор LanguageTool</string>
<string name="sample_settings">Налаштування</string>
<string name="version">Версія</string>
<string name="server">Cервера</string>
<string name="requests">Запити до сервера коректора</string>
<!--%s is the version number and %s the date (e.g Sun Feb 28)-->
<string name="version_text" formatted="false">%s (побудовано на %s)</string>
Expand Down
1 change: 1 addition & 0 deletions CorrectorSoftcatala/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="subtype_generic" translatable="false">%s</string>
<string name="sample_settings">Preferences</string>
<string name="version">Version</string>
<string name="server">Server</string>
<string name="requests">Requests to the proofreader server</string>
<!-- %s is the version number and %s the date (e.g Sun Feb 28) -->
<string name="version_text" formatted="false">%s (built on %s)</string>
Expand Down
10 changes: 10 additions & 0 deletions CorrectorSoftcatala/src/main/res/xml/spell_checker_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@
android:key="version"
android:title="@string/version"
android:summary="" />

<EditTextPreference
android:selectable="true"
android:enabled="true"
android:selectAllOnFocus="true"
android:inputType="textUri"
android:singleLine="true"
android:key="server"
android:title="@string/server"
android:summary="" />
</PreferenceScreen>

0 comments on commit 4a2a8df

Please sign in to comment.