mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Add a controller for contact selection lists
This commit is contained in:
@@ -2,29 +2,22 @@ package org.briarproject.android.sharing;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.contactselection.ContactSelectorActivity;
|
||||
import org.briarproject.android.contactselection.ContactSelectorFragment;
|
||||
import org.briarproject.android.contactselection.SelectableContactItem;
|
||||
import org.briarproject.android.sharing.BaseMessageFragment.MessageFragmentListener;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public abstract class ShareActivity extends ContactSelectorActivity implements
|
||||
MessageFragmentListener {
|
||||
|
||||
private final static Logger LOG =
|
||||
Logger.getLogger(ShareActivity.class.getName());
|
||||
public abstract class ShareActivity
|
||||
extends ContactSelectorActivity<SelectableContactItem>
|
||||
implements MessageFragmentListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
@@ -46,9 +39,8 @@ public abstract class ShareActivity extends ContactSelectorActivity implements
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void contactsSelected(GroupId groupId,
|
||||
Collection<ContactId> contacts) {
|
||||
super.contactsSelected(groupId, contacts);
|
||||
public void contactsSelected(Collection<ContactId> contacts) {
|
||||
super.contactsSelected(contacts);
|
||||
|
||||
BaseMessageFragment messageFragment = getMessageFragment();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
@@ -67,45 +59,12 @@ public abstract class ShareActivity extends ContactSelectorActivity implements
|
||||
@UiThread
|
||||
@Override
|
||||
public boolean onButtonClick(@NotNull String message) {
|
||||
share(groupId, contacts, message);
|
||||
share(contacts, message);
|
||||
setResult(RESULT_OK);
|
||||
supportFinishAfterTransition();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void share(final GroupId g, final Collection<ContactId> contacts,
|
||||
final String msg) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (ContactId c : contacts) {
|
||||
share(g, c, msg);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
// TODO proper error handling
|
||||
sharingError();
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
protected abstract void share(GroupId g, ContactId c, String msg)
|
||||
throws DbException;
|
||||
|
||||
private void sharingError() {
|
||||
runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int res = getSharingError();
|
||||
Toast.makeText(ShareActivity.this, res, LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract @StringRes int getSharingError();
|
||||
abstract void share(Collection<ContactId> contacts, String msg);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user