Commit 4b84a8c8 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Updating environment instead of recreating the MainActivity since now

that the flag FLAG_ACTIVITY_SINGLE_TOP is set to MainActivity when
launching we keep always a single instance of it avoiding it to leak
parent 5f7b0d5a
......@@ -17,7 +17,7 @@ public class LaunchUtil {
*/
public static void showMainActivity(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
......
......@@ -61,6 +61,8 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
if (intent.hasExtra(PushConstants.ROOM_ID)) {
rocketChatCache.setSelectedRoomId(intent.getStringExtra(PushConstants.ROOM_ID));
}
} else {
updateHostnameIfNeeded(rocketChatCache.getSelectedServerHostname());
}
if (intent.hasExtra(PushConstants.NOT_ID)) {
......
......@@ -140,6 +140,11 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
return false;
}
public void onLogout() {
onHostnameUpdated();
onRoomIdUpdated();
}
@DebugLog
@Override
protected void onHostnameUpdated() {
......@@ -257,7 +262,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
Pair<String, String> serverInfoPair = server.second;
String logoUrl = serverInfoPair.first;
String siteName = serverInfoPair.second;
if (serverListContainer.findViewWithTag(serverHostname) == null) {
View serverView = serverListContainer.findViewWithTag(serverHostname);
if (serverView == null) {
int serverCount = serverListContainer.getChildCount();
View serverRow = LayoutInflater.from(this).inflate(R.layout.server_row, serverListContainer, false);
......@@ -266,23 +272,28 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
TextView siteNameLabel = serverRow.findViewById(R.id.text_view_site_name_label);
ImageView dotView = serverRow.findViewById(R.id.selected_server_dot);
serverButton.setTag(serverHostname);
serverRow.setTag(serverHostname);
hostnameLabel.setText(serverHostname);
siteNameLabel.setText(siteName);
// Currently selected server
if (serverHostname.equalsIgnoreCase(hostname)) {
serverRow.setSelected(true);
dotView.setVisibility(View.VISIBLE);
} else {
dotView.setVisibility(View.GONE);
}
serverRow.setSelected(true);
dotView.setVisibility(View.VISIBLE);
serverRow.setOnClickListener(view -> changeServerIfNeeded(serverHostname));
FrescoHelper.INSTANCE.loadImage(serverButton, logoUrl, ContextCompat.getDrawable(this, R.mipmap.ic_launcher));
serverListContainer.addView(serverRow, serverCount - 1);
} else {
View dotView = serverView.findViewById(R.id.selected_server_dot);
if (hostname.equalsIgnoreCase(serverHostname)) {
serverView.setSelected(true);
dotView.setVisibility(View.VISIBLE);
} else {
serverView.setSelected(false);
dotView.setVisibility(View.GONE);
}
}
}
}
......@@ -292,7 +303,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
if (!hostname.equalsIgnoreCase(serverHostname)) {
RocketChatCache rocketChatCache = new RocketChatCache(getApplicationContext());
rocketChatCache.setSelectedServerHostname(serverHostname);
recreate();
onHostnameUpdated();
}
}
......
......@@ -16,6 +16,7 @@ import bolts.Task;
import chat.rocket.android.BuildConfig;
import chat.rocket.android.R;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.activity.MainActivity;
import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment;
......@@ -308,7 +309,9 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
return Task.forError(task.getError());
}
// destroy Activity on logout to be able to recreate most of the environment
this.getActivity().recreate();
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).onLogout();
}
return null;
});
closeUserActionContainer();
......
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