Commit 818b2ef7 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add pre and post logout hooks. Should clear subscriptions prior to logging out...

Add pre and post logout hooks. Should clear subscriptions prior to logging out to avoid mislead flow of activities when reacting to an unknown empty session
parent 00c1d279
......@@ -142,22 +142,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
return false;
}
public void onLogout(String oldHost) {
onHostnameUpdated();
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
@Override
protected void onHostnameUpdated() {
......@@ -192,7 +176,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
publicSettingRepository
);
updateSidebarMainFragment();
presenter.bindView(this);
......@@ -326,6 +309,24 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
@DebugLog
public void onLogout() {
if (new RocketChatCache(getApplicationContext()).getSelectedServerHostname() == null) {
LaunchUtil.showMainActivity(this);
} else {
onHostnameUpdated();
}
}
@DebugLog
public void beforeLogoutCleanup() {
presenter.beforeLogout();
}
public void onFailedLogout() {
onHostnameUpdated();
}
//TODO: consider this class to define in layouthelper for more complicated operation.
private static class StatusTicker {
public static final int STATUS_DISMISS = 0;
......
......@@ -37,5 +37,7 @@ public interface MainContract {
void bindViewOnly(View view);
void loadSignedInServers(String hostname);
void beforeLogout();
}
}
......@@ -133,6 +133,11 @@ public class MainPresenter extends BasePresenter<MainContract.View>
addSubscription(subscription);
}
@Override
public void beforeLogout() {
clearSubscriptions();
}
private Pair<String, String> getLogoAndSiteNamePair(Pair<Optional<PublicSetting>, Optional<PublicSetting>> settingsPair) {
String logoUrl = "";
String siteName = "";
......
package chat.rocket.android.fragment.sidebar;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
......@@ -14,6 +15,12 @@ import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import java.util.ArrayList;
import java.util.List;
import bolts.Task;
import chat.rocket.android.BuildConfig;
import chat.rocket.android.R;
......@@ -43,15 +50,9 @@ import chat.rocket.persistence.realm.repositories.RealmServerInfoRepository;
import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightRepository;
import chat.rocket.persistence.realm.repositories.RealmUserRepository;
import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import java.util.ArrayList;
import java.util.List;
public class SidebarMainFragment extends AbstractFragment implements SidebarMainContract.View {
private SidebarMainContract.Presenter presenter;
private RoomListAdapter adapter;
......@@ -59,6 +60,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private TextView loadMoreResultsText;
private List<RoomSidebar> roomSidebarList;
private Disposable spotlightDisposable;
private RocketChatCache rocketChatCache;
private String hostname;
private static final String HOSTNAME = "hostname";
......@@ -91,11 +93,13 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
new SessionInteractor(new RealmSessionRepository(hostname))
);
rocketChatCache = new RocketChatCache(getContext().getApplicationContext());
presenter = new SidebarMainPresenter(
hostname,
new RoomInteractor(new RealmRoomRepository(hostname)),
userRepository,
new RocketChatCache(getContext()),
rocketChatCache,
absoluteUrlHelper,
new MethodCallHelper(getContext(), hostname),
new RealmSpotlightRepository(hostname)
......@@ -320,18 +324,24 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private void setupLogoutButton() {
rootView.findViewById(R.id.btn_logout).setOnClickListener(view -> {
final String oldHost = hostname;
closeUserActionContainer();
Activity mainActivity = getActivity();
if (mainActivity != null && mainActivity instanceof MainActivity) {
((MainActivity) mainActivity).beforeLogoutCleanup();
}
presenter.onLogout(task -> {
if (task.isFaulted()) {
if (mainActivity != null && mainActivity instanceof MainActivity) {
((MainActivity) mainActivity).onFailedLogout();
}
return Task.forError(task.getError());
}
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).onLogout(oldHost);
if (mainActivity != null && mainActivity instanceof MainActivity) {
((MainActivity) mainActivity).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