Kaydet (Commit) 79f79ab0 authored tarafından Artur Dryomov's avatar Artur Dryomov

Add saving the current tab between application launches.

Mimic the Contacts app behaviour basically.

Change-Id: Ib0579d26c105629cfe59620f996689a949bad073
üst 38a3eba7
......@@ -25,6 +25,7 @@ import org.libreoffice.impressremote.util.BluetoothOperator;
import org.libreoffice.impressremote.util.FragmentOperator;
import org.libreoffice.impressremote.util.Intents;
import org.libreoffice.impressremote.R;
import org.libreoffice.impressremote.util.Preferences;
public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
private static final class TabsIndices {
......@@ -72,6 +73,8 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
setUpTabs();
setUpComputersPager();
setUpSavedTab();
}
private void setUpTabs() {
......@@ -137,6 +140,14 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
public void onPageScrollStateChanged(int aPosition) {
}
private void setUpSavedTab() {
getSupportActionBar().setSelectedNavigationItem(loadTabIndex());
}
private int loadTabIndex() {
return Preferences.getApplicationStatesInstance(this).getInt("saved_tab");
}
private void setUpComputersList() {
Fragment aComputersFragment = ComputersFragment.newInstance(ComputersFragment.Type.WIFI);
......@@ -189,6 +200,19 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
Intent aIntent = Intents.buildLicensesIntent(this);
startActivity(aIntent);
}
@Override
protected void onStop() {
super.onStop();
saveTabIndex();
}
private void saveTabIndex() {
int aTabIndex = getSupportActionBar().getSelectedNavigationIndex();
Preferences.getApplicationStatesInstance(this).setInt("saved_tab", aTabIndex);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -46,11 +46,11 @@ final class PairingProvider {
}
private String getSavedPin(Server aServer) {
return mAuthorizedServersPreferences.get(aServer.getAddress());
return mAuthorizedServersPreferences.getString(aServer.getAddress());
}
private void savePin(Server aServer, String aPin) {
mAuthorizedServersPreferences.set(aServer.getAddress(), aPin);
mAuthorizedServersPreferences.setString(aServer.getAddress(), aPin);
}
public static String getPairingDeviceName(Context aContext) {
......
......@@ -101,7 +101,7 @@ class ServersManager implements Comparator<Server> {
}
public void addTcpServer(String aAddress, String aName) {
mSavedServersPreferences.set(aAddress, aName);
mSavedServersPreferences.setString(aAddress, aName);
}
public void removeServer(Server aServer) {
......
......@@ -20,6 +20,7 @@ public final class Preferences {
public static final String AUTHORIZED_SERVERS = "authorized_servers";
public static final String SAVED_SERVERS = "saved_servers";
public static final String APPLICATION_STATES = "application_states";
}
private final SharedPreferences mPreferences;
......@@ -40,18 +41,30 @@ public final class Preferences {
return new Preferences(aContext, Locations.SAVED_SERVERS);
}
public static Preferences getApplicationStatesInstance(Context aContext) {
return new Preferences(aContext, Locations.APPLICATION_STATES);
}
public Map<String, ?> getAll() {
return mPreferences.getAll();
}
public String get(String aKey) {
public String getString(String aKey) {
return mPreferences.getString(aKey, null);
}
public void set(String aKey, String aValue) {
public int getInt(String aKey) {
return mPreferences.getInt(aKey, 0);
}
public void setString(String aKey, String aValue) {
mPreferences.edit().putString(aKey, aValue).commit();
}
public void setInt(String aKey, int aValue) {
mPreferences.edit().putInt(aKey, aValue).commit();
}
public void remove(String aKey) {
mPreferences.edit().remove(aKey).commit();
}
......
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