Overhaul notifications to fix various bugs.

Fixes #539, #564 and #568.
This commit is contained in:
akwizgran
2016-08-02 16:48:16 +01:00
parent 98337a16ec
commit dbdf567d4e
9 changed files with 344 additions and 101 deletions

View File

@@ -2,6 +2,7 @@ package org.briarproject.android.blogs;
import android.app.Activity;
import org.briarproject.android.api.AndroidNotificationManager;
import org.briarproject.android.controller.DbControllerImpl;
import org.briarproject.android.controller.handler.ResultExceptionHandler;
import org.briarproject.api.blogs.Blog;
@@ -38,6 +39,8 @@ public class BlogControllerImpl extends DbControllerImpl
protected Activity activity;
@Inject
protected EventBus eventBus;
@Inject
protected AndroidNotificationManager notificationManager;
@Inject
protected volatile BlogManager blogManager;
@@ -69,11 +72,14 @@ public class BlogControllerImpl extends DbControllerImpl
@Override
public void onActivityResume() {
notificationManager.blockNotification(groupId);
notificationManager.clearBlogPostNotification(groupId);
eventBus.addListener(this);
}
@Override
public void onActivityPause() {
notificationManager.unblockNotification(groupId);
eventBus.removeListener(this);
}

View File

@@ -121,6 +121,7 @@ public class BlogFragment extends BaseFragment implements BlogPostListener {
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
blogController.setGroupId(groupId);
}
@Override

View File

@@ -33,12 +33,13 @@ public class FeedControllerImpl extends DbControllerImpl
@SuppressWarnings("WeakerAccess")
@Inject
AndroidNotificationManager notificationManager;
@Inject
protected EventBus eventBus;
@Inject
protected volatile BlogManager blogManager;
@Inject
protected volatile IdentityManager identityManager;
@Inject
protected volatile EventBus eventBus;
private volatile OnBlogPostAddedListener listener;
@@ -48,14 +49,14 @@ public class FeedControllerImpl extends DbControllerImpl
@Override
public void onResume() {
notificationManager.blockBlogNotification();
notificationManager.clearBlogPostNotification();
notificationManager.blockAllBlogPostNotifications();
notificationManager.clearAllBlogPostNotifications();
eventBus.addListener(this);
}
@Override
public void onPause() {
notificationManager.unblockBlogNotification();
notificationManager.unblockAllBlogPostNotifications();
eventBus.removeListener(this);
}

View File

@@ -18,6 +18,7 @@ import android.widget.TextView.OnEditorActionListener;
import org.briarproject.R;
import org.briarproject.android.ActivityComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.api.AndroidNotificationManager;
import org.briarproject.api.FormatException;
import org.briarproject.api.blogs.BlogManager;
import org.briarproject.api.blogs.BlogPost;
@@ -47,6 +48,9 @@ public class WriteBlogPostActivity extends BriarActivity
Logger.getLogger(WriteBlogPostActivity.class.getName());
private static final String contentType = "text/plain";
@Inject
protected AndroidNotificationManager notificationManager;
private TextInputEditText titleInput;
private EditText bodyInput;
private Button publishButton;
@@ -69,13 +73,8 @@ public class WriteBlogPostActivity extends BriarActivity
byte[] b = i.getByteArrayExtra(GROUP_ID);
if (b == null) throw new IllegalStateException("No Group in intent.");
groupId = new GroupId(b);
// String blogName = i.getStringExtra(BLOG_NAME);
// if (blogName != null) setTitle(blogName);
setContentView(R.layout.activity_write_blog_post);
// String title =
// getTitle() + ": " + getString(R.string.blogs_write_blog_post);
// setTitle(title);
TextInputLayout titleLayout =
(TextInputLayout) findViewById(R.id.titleLayout);
@@ -116,6 +115,18 @@ public class WriteBlogPostActivity extends BriarActivity
progressBar = (ProgressBar) findViewById(R.id.progressBar);
}
@Override
public void onPause() {
super.onPause();
notificationManager.unblockNotification(groupId);
}
@Override
public void onResume() {
super.onResume();
notificationManager.blockNotification(groupId);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {