Commit d9b3ee7f authored by Torsten Grote's avatar Torsten Grote

Merge branch '1707-fragment-listeners' into 'master'

Don't overwrite listener references with null during fragment changes

Closes #1707, #1706, #1704, and #1697

See merge request !1227
parents 62ef64db c206b46e
Pipeline #4148 passed with stage
in 10 minutes and 16 seconds
......@@ -9,7 +9,6 @@ import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
import java.util.Collection;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
@NotNullByDefault
......@@ -18,7 +17,10 @@ public interface BlogController extends BaseController {
void setGroupId(GroupId g);
@UiThread
void setBlogSharingListener(@Nullable BlogSharingListener listener);
void setBlogSharingListener(BlogSharingListener listener);
@UiThread
void unsetBlogSharingListener(BlogSharingListener listener);
void loadBlogPosts(
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler);
......
......@@ -96,10 +96,15 @@ class BlogControllerImpl extends BaseControllerImpl
}
@Override
public void setBlogSharingListener(@Nullable BlogSharingListener listener) {
public void setBlogSharingListener(BlogSharingListener listener) {
this.listener = listener;
}
@Override
public void unsetBlogSharingListener(BlogSharingListener listener) {
if (this.listener == listener) this.listener = null;
}
@Override
public void eventOccurred(Event e) {
if (groupId == null || listener == null)
......
......@@ -141,7 +141,8 @@ public class BlogFragment extends BaseFragment
@Override
public void onDestroy() {
super.onDestroy();
blogController.setBlogSharingListener(null);
blogController.unsetBlogSharingListener(this);
sharingController.unsetSharingListener(this);
}
@Override
......
......@@ -7,7 +7,6 @@ import org.briarproject.briar.api.blog.Blog;
import java.util.Collection;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
@NotNullByDefault
......@@ -19,7 +18,10 @@ public interface FeedController extends BaseController {
void loadPersonalBlog(ResultExceptionHandler<Blog, DbException> handler);
@UiThread
void setFeedListener(@Nullable FeedListener listener);
void setFeedListener(FeedListener listener);
@UiThread
void unsetFeedListener(FeedListener listener);
@NotNullByDefault
interface FeedListener extends BlogListener {
......
......@@ -69,10 +69,15 @@ class FeedControllerImpl extends BaseControllerImpl implements FeedController {
}
@Override
public void setFeedListener(@Nullable FeedListener listener) {
public void setFeedListener(FeedListener listener) {
this.listener = listener;
}
@Override
public void unsetFeedListener(FeedListener listener) {
if (this.listener == listener) this.listener = null;
}
@Override
public void eventOccurred(Event e) {
if (listener == null) throw new IllegalStateException();
......
......@@ -134,7 +134,7 @@ public class FeedFragment extends BaseFragment implements
@Override
public void onDestroy() {
super.onDestroy();
feedController.setFeedListener(null);
feedController.unsetFeedListener(this);
}
@Override
......
......@@ -16,6 +16,12 @@ public interface SharingController {
@UiThread
void setSharingListener(SharingListener listener);
/**
* Unsets the listener.
*/
@UiThread
void unsetSharingListener(SharingListener listener);
/**
* Call this when your lifecycle starts,
* so the listener will be called when information changes.
......
......@@ -43,6 +43,11 @@ public class SharingControllerImpl implements SharingController, EventListener {
this.listener = listener;
}
@Override
public void unsetSharingListener(SharingListener listener) {
if (this.listener == listener) this.listener = null;
}
@Override
public void onStart() {
eventBus.addListener(this);
......
......@@ -10,8 +10,6 @@ import org.briarproject.briar.api.privategroup.GroupMessageHeader;
import java.util.Collection;
import javax.annotation.Nullable;
import androidx.annotation.UiThread;
@NotNullByDefault
......@@ -21,7 +19,10 @@ interface GroupListController extends DbController {
* The listener must be set right after the controller was injected
*/
@UiThread
void setGroupListListener(@Nullable GroupListListener listener);
void setGroupListListener(GroupListListener listener);
@UiThread
void unsetGroupListListener(GroupListListener listener);
@UiThread
void onStart();
......
......@@ -80,10 +80,15 @@ class GroupListControllerImpl extends DbControllerImpl
}
@Override
public void setGroupListListener(@Nullable GroupListListener listener) {
public void setGroupListListener(GroupListListener listener) {
this.listener = listener;
}
@Override
public void unsetGroupListListener(GroupListListener listener) {
if (this.listener == listener) this.listener = null;
}
@Override
@CallSuper
public void onStart() {
......
......@@ -112,7 +112,7 @@ public class GroupListFragment extends BaseFragment implements
@Override
public void onDestroy() {
super.onDestroy();
controller.setGroupListListener(null);
controller.unsetGroupListListener(this);
}
@Override
......
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