Commit 1cc4c338 authored by Drahomír Karchňák's avatar Drahomír Karchňák

WIP Server picker. Fixed Registratiou resource in control server.

parent f1843d5b
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="match_parent"> android:orientation="vertical"
android:visibility="visible">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="44dp"
android:text="TextView"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="24sp"
tools:text="[TEST] Vyber server [Test]" />
<ListView <ListView
android:id="@+id/server_select_list" android:id="@+id/server_select_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="fill_parent"
android:layout_above="@+id/server_select_auto_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="@+id/server_select_auto_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/action_bar_background"
android:text="@string/preferences_user_server_selection_auto"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout> </RelativeLayout>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="6dip"
android:padding="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip">
> <ImageView
android:id="@+id/serverSelectedIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/linearLayout"
android:layout_alignRight="@+id/linearLayout"
android:layout_centerVertical="true"
android:adjustViewBounds="false"
android:scaleType="fitEnd"
android:src="@drawable/traffic_lights_green"
android:visibility="gone" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"> android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:orientation="vertical"
android:id="@+id/linearLayout">
<TextView <TextView
android:id="@+id/serverName" android:id="@+id/serverName"
...@@ -27,5 +42,7 @@ ...@@ -27,5 +42,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@android:string/unknownName" android:text="@android:string/unknownName"
android:textColor="@color/gray" /> android:textColor="@color/gray" />
</LinearLayout> </LinearLayout>
</FrameLayout>
\ No newline at end of file </RelativeLayout>
\ No newline at end of file
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<string name="user_server_selection">Výběr serveru</string> <string name="user_server_selection">Výběr serveru</string>
<string name="preferences_user_server_selection">Vybrat server</string> <string name="preferences_user_server_selection">Vybrat server</string>
<string name="preferences_user_server_selection_sub">Automaticky vybrat nejlepší</string> <string name="preferences_user_server_selection_auto">Automaticky vybrat nejlepší</string>
<string name="preferences_no_gps">Bez GPS</string> <string name="preferences_no_gps">Bez GPS</string>
<string name="preferences_no_gps_sum">Nepoužívat GPS během testu</string> <string name="preferences_no_gps_sum">Nepoužívat GPS během testu</string>
......
...@@ -36,8 +36,9 @@ ...@@ -36,8 +36,9 @@
<string name="preferences_location_settings_sum">Change location settings</string> <string name="preferences_location_settings_sum">Change location settings</string>
<string name="user_server_selection">Server selection</string> <string name="user_server_selection">Server selection</string>
<string name="preferences_user_server_selection">Choose server</string> <string name="preferences_user_server_selection">Choose server</string>
<string name="preferences_user_server_selection_sum">Automatically choose the best</string> <string name="preferences_user_server_selection_auto">Automatically choose the best</string>
<string name="preferences_no_gps">No GPS</string> <string name="preferences_no_gps">No GPS</string>
<string name="preferences_no_gps_sum">Do not use GPS during test</string> <string name="preferences_no_gps_sum">Do not use GPS during test</string>
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<Preference <Preference
android:key="user_server_selection_button" android:key="user_server_selection_button"
android:title="@string/preferences_user_server_selection" android:title="@string/preferences_user_server_selection"
android:summary="@string/preferences_user_server_selection_sum"
android:layout="@layout/preferences_item" /> android:layout="@layout/preferences_item" />
<EditTextPreference <EditTextPreference
......
...@@ -35,6 +35,7 @@ import at.alladin.rmbt.android.sync.RMBTSyncActivity; ...@@ -35,6 +35,7 @@ import at.alladin.rmbt.android.sync.RMBTSyncActivity;
import at.alladin.rmbt.android.terms.RMBTCheckFragment.CheckType; import at.alladin.rmbt.android.terms.RMBTCheckFragment.CheckType;
import at.alladin.rmbt.android.terms.RMBTTermsActivity; import at.alladin.rmbt.android.terms.RMBTTermsActivity;
import at.alladin.rmbt.android.util.ConfigHelper; import at.alladin.rmbt.android.util.ConfigHelper;
import at.alladin.rmbt.android.util.Server;
import cz.nic.netmetr.R; import cz.nic.netmetr.R;
public class RMBTPreferenceActivity extends PreferenceActivity public class RMBTPreferenceActivity extends PreferenceActivity
...@@ -200,17 +201,25 @@ public class RMBTPreferenceActivity extends PreferenceActivity ...@@ -200,17 +201,25 @@ public class RMBTPreferenceActivity extends PreferenceActivity
}); });
} }
//Enable Development options
addPreferencesFromResource(R.xml.preferences_dev); addPreferencesFromResource(R.xml.preferences_dev);
final Preference serverSelectButton = findPreference("user_server_selection_button"); final Preference serverSelectButton = findPreference("user_server_selection_button");
Server server = ConfigHelper.getUserSelectedServer(this);
if(server != null) {
serverSelectButton.setSummary(server.toString());
}
else {
serverSelectButton.setSummary(getText(R.string.preferences_user_server_selection_auto));
}
if(serverSelectButton != null) { if(serverSelectButton != null) {
serverSelectButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { serverSelectButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
System.out.println("Preference clicked!"); startActivity(new Intent(getBaseContext(), RMBTServerSelectActivity.class));
startActivity(new Intent(getBaseContext(), RMBTServerSelectActivity.class)); return true;
return true;
} }
}); });
} }
......
...@@ -2,14 +2,31 @@ package at.alladin.rmbt.android.preferences; ...@@ -2,14 +2,31 @@ package at.alladin.rmbt.android.preferences;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;
import at.alladin.rmbt.android.main.RMBTMainActivity;
import at.alladin.rmbt.android.util.ConfigHelper;
import at.alladin.rmbt.android.util.Server;
import cz.nic.netmetr.R; import cz.nic.netmetr.R;
public class RMBTServerSelectActivity extends Activity{ public class RMBTServerSelectActivity extends Activity implements RMBTServerSelectFragment.OnServerSelectedListener {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
System.out.println("Activity on create");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server_select); setContentView(R.layout.activity_server_select);
} }
@Override
public void onServerSelected(Server server) {
if(server == null) {
ConfigHelper.removeUserSelectedServer(getBaseContext());
} else {
ConfigHelper.setUserSelectedServer(getBaseContext(), server);
}
((RMBTMainActivity)getParent()).checkSettings(true, null);
finish();
}
} }
package at.alladin.rmbt.android.preferences; package at.alladin.rmbt.android.preferences;
import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import at.alladin.rmbt.android.main.RMBTMainActivity;
import at.alladin.rmbt.android.util.ConfigHelper; import at.alladin.rmbt.android.util.ConfigHelper;
import at.alladin.rmbt.android.util.Server; import at.alladin.rmbt.android.util.Server;
import cz.nic.netmetr.R; import cz.nic.netmetr.R;
public class RMBTServerSelectFragment extends Fragment { public class RMBTServerSelectFragment extends Fragment {
public interface OnServerSelectedListener {
void onServerSelected(Server server);
}
private OnServerSelectedListener listener;
private Server selectedServer;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.i(getClass().getSimpleName(), "Attached To: " + activity.getLocalClassName());
listener = (OnServerSelectedListener) activity;
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...@@ -33,9 +53,34 @@ public class RMBTServerSelectFragment extends Fragment { ...@@ -33,9 +53,34 @@ public class RMBTServerSelectFragment extends Fragment {
servers.add(Server.decodeFromString(serverString)); servers.add(Server.decodeFromString(serverString));
} }
this.selectedServer = ConfigHelper.getUserSelectedServer(getActivity());
servers.add(new Server("ToJeJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeJeasJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeJasdedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJasdedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJaaeJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeasdJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeJasdedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJaeJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeJhgedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJsdeJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeJefdno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJfdgeJedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
servers.add(new Server("ToJeJhgedno", "Testovaci Server", "Mesto", "Nejaka krasna zeme"));
ServerSelectItemAdapter serverSelectItemAdapter = new ServerSelectItemAdapter(this.getActivity(), servers); ServerSelectItemAdapter serverSelectItemAdapter = new ServerSelectItemAdapter(this.getActivity(), servers);
listView.setAdapter(serverSelectItemAdapter); listView.setAdapter(serverSelectItemAdapter);
Button autoButton = (Button) view.findViewById(R.id.server_select_auto_button);
autoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(listener != null) listener.onServerSelected(null);
}
});
return view; return view;
} }
...@@ -47,7 +92,7 @@ public class RMBTServerSelectFragment extends Fragment { ...@@ -47,7 +92,7 @@ public class RMBTServerSelectFragment extends Fragment {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
Server server = getItem(position); final Server server = getItem(position);
if(convertView == null) { if(convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.server_select_item, parent, false); convertView = LayoutInflater.from(getContext()).inflate(R.layout.server_select_item, parent, false);
...@@ -59,6 +104,18 @@ public class RMBTServerSelectFragment extends Fragment { ...@@ -59,6 +104,18 @@ public class RMBTServerSelectFragment extends Fragment {
serverName.setText(server.getName()); serverName.setText(server.getName());
serverLocation.setText(server.getFormattedLocation()); serverLocation.setText(server.getFormattedLocation());
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(listener != null) listener.onServerSelected(server);
}
});
if(selectedServer != null && selectedServer.equals(server)) {
ImageView selectedIcon = (ImageView) convertView.findViewById(R.id.serverSelectedIcon);
selectedIcon.setVisibility(View.VISIBLE);
}
return convertView; return convertView;
} }
} }
......
...@@ -244,7 +244,7 @@ public class CheckSettingsTask extends AsyncTask<Void, Void, JSONArray> ...@@ -244,7 +244,7 @@ public class CheckSettingsTask extends AsyncTask<Void, Void, JSONArray>
final String serverCity = serverObj.getString("city"); final String serverCity = serverObj.getString("city");
final String serverCountry = serverObj.getString("country"); final String serverCountry = serverObj.getString("country");
final Server server = new Server(serverName, serverUuid, serverCity, serverCountry); final Server server = new Server(serverUuid, serverName, serverCity, serverCountry);
serverSet.add(server.encodeToString()); serverSet.add(server.encodeToString());
...@@ -252,7 +252,6 @@ public class CheckSettingsTask extends AsyncTask<Void, Void, JSONArray> ...@@ -252,7 +252,6 @@ public class CheckSettingsTask extends AsyncTask<Void, Void, JSONArray>
} }
} }
ConfigHelper.setServers(activity, serverSet); ConfigHelper.setServers(activity, serverSet);
} }
catch (final JSONException e) catch (final JSONException e)
{ {
......
...@@ -595,16 +595,24 @@ public final class ConfigHelper ...@@ -595,16 +595,24 @@ public final class ConfigHelper
return PackageManager.SIGNATURE_MATCH == ctx.getPackageManager().checkSignatures(ctx.getPackageName(), at.alladin.rmbt.android.util.Config.RMBT_DEV_UNLOCK_PACKAGE_NAME); return PackageManager.SIGNATURE_MATCH == ctx.getPackageManager().checkSignatures(ctx.getPackageName(), at.alladin.rmbt.android.util.Config.RMBT_DEV_UNLOCK_PACKAGE_NAME);
} }
public static boolean isUserServerSelectionActive(final Context ctx) { //Last user selected server
return getSharedPreferences(ctx).getBoolean("user_server_selection", false); public static void removeUserSelectedServer(final Context ctx) {
getSharedPreferences(ctx).edit().remove("user_selected_server").apply();
} }
public static void setServerSelectionState(final Context ctx, final boolean isEnabled) { public static void setUserSelectedServer(final Context ctx, Server server) {
getSharedPreferences(ctx).edit().putBoolean("user_server_selection", isEnabled).apply(); getSharedPreferences(ctx).edit().putString("user_selected_server", server.encodeToString()).apply();
} }
public static Set<String> getServers(final Context context) public static Server getUserSelectedServer(final Context ctx) {
{ String encodedServer = getSharedPreferences(ctx).getString("user_selected_server", null);
if(encodedServer == null) return null;
return Server.decodeFromString(encodedServer);
}
//Cached list of servers
public static Set<String> getServers(final Context context) {
return getSharedPreferences(context).getStringSet("servers", null); return getSharedPreferences(context).getStringSet("servers", null);
} }
......
...@@ -536,7 +536,7 @@ public class ControlServerConnection ...@@ -536,7 +536,7 @@ public class ControlServerConnection
public JSONArray requestSettings() public JSONArray requestSettings()
{ {
hasError = false; hasError = false;
Long time = requestTime(); Long time = requestTime();
...@@ -580,7 +580,8 @@ public class ControlServerConnection ...@@ -580,7 +580,8 @@ public class ControlServerConnection
requestData.put("version_code", clientVersionCode); requestData.put("version_code", clientVersionCode);
requestData.put("time", time); requestData.put("time", time);
requestData.put("client_secret", ClientSecretHelper.prepareClientSecret(getUUID(), clientName, clientVersionName, clientVersionCode, time, BuildConfig.CLIENT_SECRET)); requestData.put("client_secret", ClientSecretHelper.prepareClientSecret(getUUID(), clientName, clientVersionName, clientVersionCode, time, BuildConfig.CLIENT_SECRET));
requestData.put("user_server_selection", true); //TODO
requestData.put("user_server_selection", true); //TODO - Is Developer Options Enabled
final int tcAcceptedVersion = ConfigHelper.getTCAcceptedVersion(context); final int tcAcceptedVersion = ConfigHelper.getTCAcceptedVersion(context);
requestData.put("terms_and_conditions_accepted_version", tcAcceptedVersion); requestData.put("terms_and_conditions_accepted_version", tcAcceptedVersion);
......
...@@ -383,8 +383,7 @@ public class InformationCollector ...@@ -383,8 +383,7 @@ public class InformationCollector
public static JSONObject fillBasicInfo(JSONObject object, Context ctx) throws JSONException public static JSONObject fillBasicInfo(JSONObject object, Context ctx) throws JSONException
{ {
object.put("plattform", PLATTFORM_NAME); object.put("plattform", PLATTFORM_NAME);
object.put("os_version", android.os.Build.VERSION.RELEASE + "(" + android.os.Build.VERSION.INCREMENTAL object.put("os_version", android.os.Build.VERSION.RELEASE + "(" + android.os.Build.VERSION.INCREMENTAL + ")");
+ ")");
object.put("api_level", String.valueOf(android.os.Build.VERSION.SDK_INT)); object.put("api_level", String.valueOf(android.os.Build.VERSION.SDK_INT));
object.put("device", android.os.Build.DEVICE); object.put("device", android.os.Build.DEVICE);
object.put("model", android.os.Build.MODEL); object.put("model", android.os.Build.MODEL);
...@@ -400,7 +399,9 @@ public class InformationCollector ...@@ -400,7 +399,9 @@ public class InformationCollector
object.put("softwareVersionName", pInfo.versionName); object.put("softwareVersionName", pInfo.versionName);
} }
object.put("type", at.alladin.rmbt.android.util.Config.RMBT_CLIENT_TYPE); object.put("type", at.alladin.rmbt.android.util.Config.RMBT_CLIENT_TYPE);
addClientFeatures(object, ctx);
if (BASIC_INFORMATION_INCLUDE_LOCATION) { if (BASIC_INFORMATION_INCLUDE_LOCATION) {
Location loc = GeoLocation.getLastKnownLocation(ctx); Location loc = GeoLocation.getLastKnownLocation(ctx);
if (loc != null) { if (loc != null) {
...@@ -475,7 +476,16 @@ public class InformationCollector ...@@ -475,7 +476,16 @@ public class InformationCollector
private void getTestTypeId() { private void getTestTypeId() {
fullInfo.setProperty("TEST_TYPE_ID", ConfigHelper.isSignalOnly(context) ? "2" : "1"); fullInfo.setProperty("TEST_TYPE_ID", ConfigHelper.isSignalOnly(context) ? "2" : "1");
} }
private static void addClientFeatures(JSONObject object, Context ctx) throws JSONException {
Server server;
if((server = ConfigHelper.getUserSelectedServer(ctx)) != null) {
object.put("user_server_selection", true);
object.put("prefer_server", server);
}
}
private void getWiFiInfo() private void getWiFiInfo()
{ {
initNetwork(); initNetwork();
......
...@@ -59,16 +59,15 @@ public class Server { ...@@ -59,16 +59,15 @@ public class Server {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + ((city == null) ? 0 : city.hashCode()); result = prime * result + ((city == null) ? 0 : city.hashCode());
result = prime * result + ((country == null) ? 0 : country.hashCode()); result = prime * result + ((country == null) ? 0 : country.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
...@@ -96,6 +95,6 @@ public class Server { ...@@ -96,6 +95,6 @@ public class Server {
@Override @Override
public String toString() { public String toString() {
return "Server: " + name + "(" + uuid + ")"; return name + " " + getFormattedLocation();
} }
} }
\ No newline at end of file
...@@ -256,12 +256,12 @@ public class RegistrationResource extends ServerResource ...@@ -256,12 +256,12 @@ public class RegistrationResource extends ServerResource
ipv6 = null; ipv6 = null;
TestServer server = null; TestServer server = null;
final Boolean userServerSelection = request.optBoolean("user_server_selection"); final Boolean userServerSelection = request.optBoolean("user_server_selection");
if(userServerSelection) { if(userServerSelection) {
final String preferServer = request.optString("prefer_server", null); final String preferServer = request.optString("prefer_server", null);
if(!Strings.isNullOrEmpty(preferServer)); { if(!Strings.isNullOrEmpty(preferServer)) {
server = getPreferredServer(preferServer, testServerEncryption, ipv6); server = getPreferredServer(preferServer, testServerEncryption, ipv6);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment