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

Server chooser now works correctly.

parent 7f9736f8
......@@ -34,6 +34,8 @@
<string name="preferences_location_settings_sum">Změny nastavení polohy</string>
<string name="user_server_selection">Výběr serveru</string>
<string name="user_server_selected">Server nastaven</string>
<string name="preferences_user_server_selection">Vybrat server</string>
<string name="preferences_user_server_selection_auto">Automaticky vybrat nejlepší</string>
......
......@@ -36,6 +36,7 @@
<string name="preferences_location_settings_sum">Change location settings</string>
<string name="user_server_selection">Server selection</string>
<string name="user_server_selected">Server selected</string>
<string name="preferences_user_server_selection">Choose server</string>
<string name="preferences_user_server_selection_auto">Automatically choose the best</string>
......
......@@ -26,9 +26,9 @@ import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.util.Log;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;
import at.alladin.rmbt.android.main.FeatureConfig;
import at.alladin.rmbt.android.sync.RMBTSyncActivity;
......@@ -42,6 +42,7 @@ public class RMBTPreferenceActivity extends PreferenceActivity
{
protected static final int REQUEST_NDT_CHECK = 1;
protected static final int REQUEST_IC_CHECK = 2;
protected static final int REQUEST_SERVER_SELECT = 3;
protected Method mLoadHeaders = null;
protected Method mHasHeaders = null;
......@@ -110,7 +111,7 @@ public class RMBTPreferenceActivity extends PreferenceActivity
final ListView v = getListView();
v.setCacheColorHint(0);
final Preference ndtPref = (Preference) findPreference("ndt");
final Preference ndtPref = findPreference("ndt");
if (ndtPref != null)
{
ndtPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
......@@ -134,7 +135,7 @@ public class RMBTPreferenceActivity extends PreferenceActivity
});
}
final Preference icPref = (Preference) findPreference("information_commissioner");
final Preference icPref = findPreference("information_commissioner");
if (icPref != null)
{
if (FeatureConfig.TEST_USE_PERSONAL_DATA_FUZZING) {
......@@ -204,57 +205,49 @@ public class RMBTPreferenceActivity extends PreferenceActivity
//Enable Development options
addPreferencesFromResource(R.xml.preferences_dev);
refreshServerSelectionState(true);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_NDT_CHECK) {
((CheckBoxPreference) findPreference("ndt")).setChecked(ConfigHelper.isNDT(this));
}
else if (requestCode == REQUEST_IC_CHECK) {
((CheckBoxPreference) findPreference("information_commissioner")).setChecked(ConfigHelper.isInformationCommissioner(this));
}
else if (requestCode == REQUEST_SERVER_SELECT) {
refreshServerSelectionState(false);
}
}
private void refreshServerSelectionState(boolean setClickListener) {
final Preference serverSelectButton = findPreference("user_server_selection_button");
if(serverSelectButton == null) {
Log.i(getClass().getSimpleName(), "Cannot refresh select button state, the button is null!");
return;
}
Server server = ConfigHelper.getUserSelectedServer(this);
if(server != null) {
if (server != null) {
serverSelectButton.setSummary(server.toString());
}
else {
} else {
serverSelectButton.setSummary(getText(R.string.preferences_user_server_selection_auto));
}
if(serverSelectButton != null) {
if(setClickListener) {
serverSelectButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(getBaseContext(), RMBTServerSelectActivity.class));
return true;
startActivityForResult(new Intent(getBaseContext(), RMBTServerSelectActivity.class), REQUEST_SERVER_SELECT); //Start for request code and refresh on result
return true;
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_NDT_CHECK)
{
((CheckBoxPreference) findPreference("ndt")).setChecked(ConfigHelper.isNDT(this));
}
else if (requestCode == REQUEST_IC_CHECK) {
((CheckBoxPreference) findPreference("information_commissioner")).setChecked(ConfigHelper.isInformationCommissioner(this));
}
}
/*
* @Override public void onBuildHeaders(List<Header> aTarget) { try {
* mLoadHeaders.invoke(this,new Object[]{R.xml.pref_headers,aTarget}); }
* catch (IllegalArgumentException e) { } catch (IllegalAccessException e) {
* } catch (InvocationTargetException e) { } }
*
* @TargetApi(11) static public class PrefsFragment extends
* PreferenceFragment {
*
* @Override public void onCreate(Bundle aSavedState) {
* super.onCreate(aSavedState); Context anAct =
* getActivity().getApplicationContext(); int thePrefRes =
* anAct.getResources
* ().getIdentifier(getArguments().getString("pref-resource"),
* "xml",anAct.getPackageName()); addPreferencesFromResource(thePrefRes);
* //addPreferencesFromResource(R.xml.preferences);
* Log.i("test","Preferences Loaded"); } }
*/
}
}
\ No newline at end of file
package at.alladin.rmbt.android.preferences;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
......@@ -10,8 +11,6 @@ import at.alladin.rmbt.android.util.Server;
import cz.nic.netmetr.R;
public class RMBTServerSelectActivity extends Activity implements RMBTServerSelectFragment.OnServerSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -26,7 +25,9 @@ public class RMBTServerSelectActivity extends Activity implements RMBTServerSele
ConfigHelper.setUserSelectedServer(getBaseContext(), server);
}
((RMBTMainActivity)getParent()).checkSettings(true, null);
Toast.makeText(this, getText(R.string.user_server_selected), Toast.LENGTH_SHORT).show();
setResult(Activity.RESULT_OK);
finish();
}
}
......@@ -3,9 +3,7 @@ package at.alladin.rmbt.android.preferences;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -14,12 +12,10 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
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;
......@@ -35,7 +31,6 @@ public class RMBTServerSelectFragment extends Fragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.i(getClass().getSimpleName(), "Attached To: " + activity.getLocalClassName());
listener = (OnServerSelectedListener) activity;
}
......@@ -55,21 +50,6 @@ public class RMBTServerSelectFragment extends Fragment {
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);
listView.setAdapter(serverSelectItemAdapter);
......
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