code cleanup, null check not necessary when using instance of

This commit is contained in:
Daniel Gultsch 2018-10-24 20:00:25 +02:00
parent bb6ddae76b
commit d6f604a8e4

View file

@ -221,7 +221,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
return; return;
} }
final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment); final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (fragment != null && fragment instanceof ConversationsOverviewFragment) { if (fragment instanceof ConversationsOverviewFragment) {
if (ExceptionHelper.checkForCrash(this)) { if (ExceptionHelper.checkForCrash(this)) {
return; return;
} }
@ -273,14 +273,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
private void notifyFragmentOfBackendConnected(@IdRes int id) { private void notifyFragmentOfBackendConnected(@IdRes int id) {
final Fragment fragment = getFragmentManager().findFragmentById(id); final Fragment fragment = getFragmentManager().findFragmentById(id);
if (fragment != null && fragment instanceof OnBackendConnected) { if (fragment instanceof OnBackendConnected) {
((OnBackendConnected) fragment).onBackendConnected(); ((OnBackendConnected) fragment).onBackendConnected();
} }
} }
private void refreshFragment(@IdRes int id) { private void refreshFragment(@IdRes int id) {
final Fragment fragment = getFragmentManager().findFragmentById(id); final Fragment fragment = getFragmentManager().findFragmentById(id);
if (fragment != null && fragment instanceof XmppFragment) { if (fragment instanceof XmppFragment) {
((XmppFragment) fragment).refresh(); ((XmppFragment) fragment).refresh();
} }
} }
@ -462,7 +462,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
if (conversationFragment == null) { if (conversationFragment == null) {
mainNeedsRefresh = false; mainNeedsRefresh = false;
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment); Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (mainFragment != null && mainFragment instanceof ConversationFragment) { if (mainFragment instanceof ConversationFragment) {
conversationFragment = (ConversationFragment) mainFragment; conversationFragment = (ConversationFragment) mainFragment;
} else { } else {
conversationFragment = new ConversationFragment(); conversationFragment = new ConversationFragment();
@ -586,7 +586,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
return; return;
} }
} else { } else {
if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) { if (secondaryFragment instanceof ConversationFragment) {
transaction.remove(secondaryFragment); transaction.remove(secondaryFragment);
transaction.commit(); transaction.commit();
getFragmentManager().executePendingTransactions(); getFragmentManager().executePendingTransactions();
@ -610,7 +610,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
final ActionBar actionBar = getSupportActionBar(); final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment); Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (mainFragment != null && mainFragment instanceof ConversationFragment) { if (mainFragment instanceof ConversationFragment) {
final Conversation conversation = ((ConversationFragment) mainFragment).getConversation(); final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
if (conversation != null) { if (conversation != null) {
actionBar.setTitle(EmojiWrapper.transform(conversation.getName())); actionBar.setTitle(EmojiWrapper.transform(conversation.getName()));
@ -629,7 +629,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
return; return;
} }
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment); Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (mainFragment != null && mainFragment instanceof ConversationFragment) { if (mainFragment instanceof ConversationFragment) {
try { try {
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
@ -639,7 +639,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
return; return;
} }
Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment); Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) { if (secondaryFragment instanceof ConversationFragment) {
if (((ConversationFragment) secondaryFragment).getConversation() == conversation) { if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation); Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
if (suggestion != null) { if (suggestion != null) {
@ -652,7 +652,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
@Override @Override
public void onConversationsListItemUpdated() { public void onConversationsListItemUpdated() {
Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment); Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (fragment != null && fragment instanceof ConversationsOverviewFragment) { if (fragment instanceof ConversationsOverviewFragment) {
((ConversationsOverviewFragment) fragment).refresh(); ((ConversationsOverviewFragment) fragment).refresh();
} }
} }