Commit 036eaba6 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fixed multiple instatiation of the SidebarMainFragment and its

presenter. Subscribing to each room change on different connected
servers.
parent 611fe792
......@@ -205,4 +205,18 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
)
);
}
protected void subscribeToNewConfigChanges() {
compositeDisposable.add(
rocketChatCache.getSelectedRoomIdPublisher()
.map(Optional::get)
.distinctUntilChanged()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
this::updateRoomIdIfNeeded,
Logger::report
)
);
}
}
......@@ -75,10 +75,22 @@ abstract class AbstractFragmentActivity extends RxAppCompatActivity {
.commit();
}
protected void showFragmentWithTag(Fragment fragment, String tag) {
getSupportFragmentManager().beginTransaction()
.replace(getLayoutContainerForFragment(), fragment, tag)
.addToBackStack(null)
.commit();
}
protected void showFragmentWithBackStack(Fragment fragment) {
getSupportFragmentManager().beginTransaction()
.replace(getLayoutContainerForFragment(), fragment)
.addToBackStack(null)
.commit();
}
@Nullable
protected Fragment findFragmentByTag(String tag) {
return getSupportFragmentManager().findFragmentByTag(tag);
}
}
......@@ -197,9 +197,17 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
private void updateSidebarMainFragment() {
closeSidebarIfNeeded();
String selectedServerHostname = new RocketChatCache(this).getSelectedServerHostname();
Fragment sidebarFragment = findFragmentByTag(selectedServerHostname);
if (sidebarFragment == null) {
sidebarFragment = SidebarMainFragment.create(selectedServerHostname);
}
subscribeToNewConfigChanges();
getSupportFragmentManager().beginTransaction()
.replace(R.id.sidebar_fragment_container, SidebarMainFragment.create(hostname))
.replace(R.id.sidebar_fragment_container, sidebarFragment, selectedServerHostname)
.addToBackStack(null)
.commit();
getSupportFragmentManager().executePendingTransactions();
}
@Override
......@@ -220,7 +228,11 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override
public void showRoom(String hostname, String roomId) {
showFragment(RoomFragment.create(hostname, roomId));
Fragment roomFragment = findFragmentByTag(roomId);
if (roomFragment == null) {
roomFragment = RoomFragment.create(hostname, roomId);
}
showFragmentWithTag(roomFragment, roomId);
closeSidebarIfNeeded();
KeyboardHelper.hideSoftKeyboard(this);
}
......@@ -311,7 +323,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
if (!hostname.equalsIgnoreCase(serverHostname)) {
RocketChatCache rocketChatCache = new RocketChatCache(getApplicationContext());
rocketChatCache.setSelectedServerHostname(serverHostname);
onHostnameUpdated();
}
}
......
......@@ -8,7 +8,9 @@ import android.support.v4.app.DialogFragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;
......@@ -100,15 +102,29 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
presenter.bindView(this);
return view;
}
@Override
public void onDestroyView() {
presenter.release();
super.onDestroyView();
}
@Override
public void onResume() {
super.onResume();
presenter.bindView(this);
}
@Override
public void onPause() {
presenter.release();
super.onPause();
}
......@@ -287,7 +303,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
));
roomListHeaders.add(new LivechatRoomListHeader(
getString(R.string.fragment_sidebar_main_livechat_title)
getString(R.string.fragment_sidebar_main_livechat_title)
));
roomListHeaders.add(new ChannelRoomListHeader(
......
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