Commit 5c217510 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Remove all view before adding a new server to the list of signed in hosts

parent 4b84a8c8
...@@ -140,9 +140,20 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -140,9 +140,20 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
return false; return false;
} }
public void onLogout() { public void onLogout(String oldHost) {
onHostnameUpdated(); onHostnameUpdated();
onRoomIdUpdated(); SlidingPaneLayout subPane = (SlidingPaneLayout) findViewById(R.id.sub_sliding_pane);
if (subPane != null) {
LinearLayout serverListContainer = subPane.findViewById(R.id.server_list_bar);
serverListContainer.post(() -> {
View row = serverListContainer.findViewWithTag(oldHost);
if (row != null) {
serverListContainer.setLayoutTransition(null);
serverListContainer.removeView(row);
}
});
}
} }
@DebugLog @DebugLog
...@@ -257,6 +268,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -257,6 +268,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
LinearLayout serverListContainer = subPane.findViewById(R.id.server_list_bar); LinearLayout serverListContainer = subPane.findViewById(R.id.server_list_bar);
View addServerButton = subPane.findViewById(R.id.btn_add_server); View addServerButton = subPane.findViewById(R.id.btn_add_server);
addServerButton.setOnClickListener(view -> showAddServerActivity()); addServerButton.setOnClickListener(view -> showAddServerActivity());
serverListContainer.removeAllViews();
for (Pair<String, Pair<String, String>> server : serverList) { for (Pair<String, Pair<String, String>> server : serverList) {
String serverHostname = server.first; String serverHostname = server.first;
Pair<String, String> serverInfoPair = server.second; Pair<String, String> serverInfoPair = server.second;
...@@ -264,27 +276,30 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -264,27 +276,30 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
String siteName = serverInfoPair.second; String siteName = serverInfoPair.second;
View serverView = serverListContainer.findViewWithTag(serverHostname); View serverView = serverListContainer.findViewWithTag(serverHostname);
if (serverView == null) { if (serverView == null) {
int serverCount = serverListContainer.getChildCount(); View newServerView = LayoutInflater.from(this).inflate(R.layout.server_row, serverListContainer, false);
SimpleDraweeView serverButton = newServerView.findViewById(R.id.drawee_server_button);
TextView hostnameLabel = newServerView.findViewById(R.id.text_view_server_label);
TextView siteNameLabel = newServerView.findViewById(R.id.text_view_site_name_label);
ImageView dotView = newServerView.findViewById(R.id.selected_server_dot);
View serverRow = LayoutInflater.from(this).inflate(R.layout.server_row, serverListContainer, false); newServerView.setTag(serverHostname);
SimpleDraweeView serverButton = serverRow.findViewById(R.id.drawee_server_button);
TextView hostnameLabel = serverRow.findViewById(R.id.text_view_server_label);
TextView siteNameLabel = serverRow.findViewById(R.id.text_view_site_name_label);
ImageView dotView = serverRow.findViewById(R.id.selected_server_dot);
serverRow.setTag(serverHostname);
hostnameLabel.setText(serverHostname); hostnameLabel.setText(serverHostname);
siteNameLabel.setText(siteName); siteNameLabel.setText(siteName);
// Currently selected server // Currently selected server
serverRow.setSelected(true); if (hostname.equalsIgnoreCase(serverHostname)) {
newServerView.setSelected(true);
dotView.setVisibility(View.VISIBLE); dotView.setVisibility(View.VISIBLE);
} else {
newServerView.setSelected(false);
dotView.setVisibility(View.GONE);
}
serverRow.setOnClickListener(view -> changeServerIfNeeded(serverHostname)); newServerView.setOnClickListener(view -> changeServerIfNeeded(serverHostname));
FrescoHelper.INSTANCE.loadImage(serverButton, logoUrl, ContextCompat.getDrawable(this, R.mipmap.ic_launcher)); FrescoHelper.INSTANCE.loadImage(serverButton, logoUrl, ContextCompat.getDrawable(this, R.mipmap.ic_launcher));
serverListContainer.addView(serverRow, serverCount - 1); serverListContainer.addView(newServerView);
} else { } else {
View dotView = serverView.findViewById(R.id.selected_server_dot); View dotView = serverView.findViewById(R.id.selected_server_dot);
if (hostname.equalsIgnoreCase(serverHostname)) { if (hostname.equalsIgnoreCase(serverHostname)) {
...@@ -296,6 +311,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -296,6 +311,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
} }
} }
} }
serverListContainer.addView(addServerButton);
} }
} }
......
...@@ -304,13 +304,14 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -304,13 +304,14 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private void setupLogoutButton() { private void setupLogoutButton() {
rootView.findViewById(R.id.btn_logout).setOnClickListener(view -> { rootView.findViewById(R.id.btn_logout).setOnClickListener(view -> {
final String oldHost = hostname;
presenter.onLogout(task -> { presenter.onLogout(task -> {
if (task.isFaulted()) { if (task.isFaulted()) {
return Task.forError(task.getError()); return Task.forError(task.getError());
} }
// destroy Activity on logout to be able to recreate most of the environment
if (getActivity() instanceof MainActivity) { if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).onLogout(); ((MainActivity) getActivity()).onLogout(oldHost);
} }
return null; return null;
}); });
......
...@@ -139,7 +139,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -139,7 +139,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
Logger.report(task.getError()); Logger.report(task.getError());
return Task.forError(task.getError()); return Task.forError(task.getError());
} }
return task.continueWith(continuation); return task.onSuccess(continuation);
}); });
} }
......
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