Messaging: Remove setHost() logic

* This relies too much on call order and other things to go right
* We can use the activity just fine for it

Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8623
Change-Id: I048910258cedaa21e26fb88a57e5028ae1df9f83
This commit is contained in:
Michael W
2025-05-18 09:18:48 +00:00
parent 6161d0fca1
commit 8af12822f8
5 changed files with 25 additions and 94 deletions
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,25 +20,22 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentOnAttachListener;
import com.android.messaging.R;
public class ArchivedConversationListActivity extends AbstractConversationListActivity
implements FragmentOnAttachListener {
public class ArchivedConversationListActivity extends AbstractConversationListActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ConversationListFragment fragment =
mConversationListFragment =
ConversationListFragment.createArchivedConversationListFragment();
getSupportFragmentManager().addFragmentOnAttachListener(this);
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, mConversationListFragment)
.commit();
invalidateActionBar();
}
@@ -80,13 +77,4 @@ public class ArchivedConversationListActivity extends AbstractConversationListAc
public boolean isSwipeAnimatable() {
return false;
}
@Override
public void onAttachFragment(@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment) {
if (fragment instanceof ConversationListFragment) {
mConversationListFragment = (ConversationListFragment) fragment;
mConversationListFragment.setHost(this);
}
}
}
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,22 +24,23 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentOnAttachListener;
import com.android.messaging.R;
import com.android.messaging.ui.UIIntents;
import com.android.messaging.util.Trace;
public class ConversationListActivity extends AbstractConversationListActivity implements FragmentOnAttachListener {
public class ConversationListActivity extends AbstractConversationListActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
Trace.beginSection("ConversationListActivity.onCreate");
setTheme(R.style.BugleTheme_ConversationListActivity);
super.onCreate(savedInstanceState);
getSupportFragmentManager().addFragmentOnAttachListener(this);
setContentView(R.layout.conversation_list_activity);
mConversationListFragment = ConversationListFragment.createConversationListFragment(null);
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, mConversationListFragment)
.commit();
Trace.endSection();
invalidateActionBar();
}
@@ -131,22 +132,10 @@ public class ConversationListActivity extends AbstractConversationListActivity i
@Override
public void onWindowFocusChanged(final boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
final ConversationListFragment conversationListFragment =
(ConversationListFragment) getSupportFragmentManager().findFragmentById(
R.id.conversation_list_fragment);
// When the screen is turned on, the last used activity gets resumed, but it gets
// window focus only after the lock screen is unlocked.
if (hasFocus && conversationListFragment != null) {
conversationListFragment.setScrolledToNewestConversationIfNeeded();
}
}
@Override
public void onAttachFragment(@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment) {
if (fragment instanceof ConversationListFragment) {
mConversationListFragment = (ConversationListFragment) fragment;
mConversationListFragment.setHost(this);
if (hasFocus && mConversationListFragment != null) {
mConversationListFragment.setScrolledToNewestConversationIfNeeded();
}
}
}
@@ -52,7 +52,6 @@ import com.android.messaging.ui.ListEmptyView;
import com.android.messaging.ui.SnackBarInteraction;
import com.android.messaging.ui.UIIntents;
import com.android.messaging.util.AccessibilityUtil;
import com.android.messaging.util.Assert;
import com.android.messaging.util.ImeUtil;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.UiUtils;
@@ -110,9 +109,11 @@ public class ConversationListFragment extends Fragment implements ConversationLi
public static ConversationListFragment createConversationListFragment(String modeKeyName) {
final ConversationListFragment fragment = new ConversationListFragment();
final Bundle bundle = new Bundle();
bundle.putBoolean(modeKeyName, true);
fragment.setArguments(bundle);
if (modeKeyName != null) {
final Bundle bundle = new Bundle();
bundle.putBoolean(modeKeyName, true);
fragment.setArguments(bundle);
}
return fragment;
}
@@ -130,7 +131,7 @@ public class ConversationListFragment extends Fragment implements ConversationLi
public void onResume() {
super.onResume();
Assert.notNull(mHost);
mHost = (ConversationListFragmentHost) getActivity();
setScrolledToNewestConversationIfNeeded();
updateUi();
@@ -265,14 +266,6 @@ public class ConversationListFragment extends Fragment implements ConversationLi
mListBinding.getData().setScrolledToNewestConversation(false);
}
/**
* Call this immediately after attaching the fragment
*/
public void setHost(final ConversationListFragmentHost host) {
Assert.isNull(mHost);
mHost = host;
}
@Override
public void onConversationListCursorUpdated(final ConversationListData data,
final Cursor cursor) {
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +19,6 @@ package com.android.messaging.ui.conversationlist;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentOnAttachListener;
import com.android.messaging.datamodel.data.ConversationListData;
import com.android.messaging.datamodel.data.ConversationListItemData;
import com.android.messaging.datamodel.data.MessageData;
@@ -36,13 +31,12 @@ import com.android.messaging.ui.conversationlist.ConversationListFragment.Conver
* conversation list.
*/
public class ForwardMessageActivity extends BaseBugleActivity
implements ConversationListFragmentHost, FragmentOnAttachListener {
implements ConversationListFragmentHost {
private MessageData mDraftMessage;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportFragmentManager().addFragmentOnAttachListener(this);
final ConversationListFragment fragment =
ConversationListFragment.createForwardMessageConversationListFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
@@ -50,15 +44,6 @@ public class ForwardMessageActivity extends BaseBugleActivity
MessageData.class);
}
@Override
public void onAttachFragment(@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment) {
if (fragment instanceof ConversationListFragment) {
final ConversationListFragment clf = (ConversationListFragment) fragment;
clf.setHost(this);
}
}
@Override
public void onConversationClick(final ConversationListData listData,
final ConversationListItemData conversationListItemData,