Skip to content

Commit

Permalink
ChatFragment: Fix a crash with invalid server UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
MCMrARM committed Dec 2, 2017
1 parent a7b5b4b commit 8442f1e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/io/mrarm/irc/chat/ChatFragment.java
Expand Up @@ -30,6 +30,8 @@
import io.mrarm.irc.R;
import io.mrarm.irc.ServerConnectionInfo;
import io.mrarm.irc.ServerConnectionManager;
import io.mrarm.irc.config.ServerConfigData;
import io.mrarm.irc.config.ServerConfigManager;
import io.mrarm.irc.config.SettingsHelper;

public class ChatFragment extends Fragment implements
Expand Down Expand Up @@ -71,6 +73,11 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
mConnectionInfo = ServerConnectionManager.getInstance(getContext()).getConnection(connectionUUID);
String requestedChannel = getArguments().getString(ARG_CHANNEL_NAME);

if (mConnectionInfo == null) {
((MainActivity) getActivity()).openManageServers();
return null;
}

mAppBar = rootView.findViewById(R.id.appbar);

Toolbar toolbar = rootView.findViewById(R.id.toolbar);
Expand Down Expand Up @@ -247,6 +254,9 @@ public void setTabsHidden(boolean hidden) {

@Override
public void onDestroyView() {
super.onDestroyView();
if (mConnectionInfo == null)
return;
mConnectionInfo.removeOnChannelListChangeListener(this);
mConnectionInfo.removeOnChannelInfoChangeListener(this);
mConnectionInfo.getNotificationManager().removeUnreadMessageCountCallback(this);
Expand All @@ -256,13 +266,13 @@ public void onDestroyView() {
s.removePreferenceChangeListener(SettingsHelper.PREF_CHAT_FONT, this);
s.removePreferenceChangeListener(SettingsHelper.PREF_NICK_AUTOCOMPLETE_SHOW_BUTTON, this);
s.removePreferenceChangeListener(SettingsHelper.PREF_NICK_AUTOCOMPLETE_DOUBLE_TAP, this);
super.onDestroyView();
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mSectionsPagerAdapter.onSaveInstanceState(outState);
if (mSectionsPagerAdapter != null)
mSectionsPagerAdapter.onSaveInstanceState(outState);
}

public ServerConnectionInfo getConnectionInfo() {
Expand Down

0 comments on commit 8442f1e

Please sign in to comment.