Skip to content
Snippets Groups Projects
Verified Commit bd1f3fc2 authored by Torsten Grote's avatar Torsten Grote
Browse files

Make ContactSelectorFragment reusable

parent d25f4d1f
No related branches found
No related tags found
No related merge requests found
Showing
with 55 additions and 27 deletions
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_share_forum" android:id="@+id/action_contacts_selected"
android:icon="@drawable/ic_check_white" android:icon="@drawable/ic_check_white"
android:title="@string/forum_share_action" android:title="@string/contacts_selected"
app:showAsAction="always"/> app:showAsAction="always"/>
</menu> </menu>
\ No newline at end of file
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
<string name="forum_left_toast">Forum wurde verlassen</string> <string name="forum_left_toast">Forum wurde verlassen</string>
<!--Forum Sharing--> <!--Forum Sharing-->
<string name="forum_share_button">Forum teilen</string> <string name="forum_share_button">Forum teilen</string>
<string name="forum_share_action">Teile dieses Forum mit den gewählten Kontakten</string> <string name="contacts_selected">Teile dieses Forum mit den gewählten Kontakten</string>
<string name="activity_share_toolbar_header">Kontakte auswählen</string> <string name="activity_share_toolbar_header">Kontakte auswählen</string>
<string name="no_contacts_selector">Du scheinst hier neu zu sein und noch keine Kontakte zu haben.\n\nBitte komm zurück, wenn du deinen ersten Kontakt hinzugefügt hast.</string> <string name="no_contacts_selector">Du scheinst hier neu zu sein und noch keine Kontakte zu haben.\n\nBitte komm zurück, wenn du deinen ersten Kontakt hinzugefügt hast.</string>
<string name="forum_shared_snackbar">Forum mit gewählten Kontakten geteilt</string> <string name="forum_shared_snackbar">Forum mit gewählten Kontakten geteilt</string>
......
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
<string name="forum_left_toast">Foro abandonado</string> <string name="forum_left_toast">Foro abandonado</string>
<!--Forum Sharing--> <!--Forum Sharing-->
<string name="forum_share_button">Compartir foro</string> <string name="forum_share_button">Compartir foro</string>
<string name="forum_share_action">Compartir este foro con los contactos seleccionados</string> <string name="contacts_selected">Compartir este foro con los contactos seleccionados</string>
<string name="activity_share_toolbar_header">Elige contactos</string> <string name="activity_share_toolbar_header">Elige contactos</string>
<string name="no_contacts_selector">Parece que eres nuevo aquí y no tienes contactos aún.\n\nPor favor, vuelve cuando hayas añadido tu primer contacto.</string> <string name="no_contacts_selector">Parece que eres nuevo aquí y no tienes contactos aún.\n\nPor favor, vuelve cuando hayas añadido tu primer contacto.</string>
<string name="forum_shared_snackbar">Foro compartido con los contactos seleccionados</string> <string name="forum_shared_snackbar">Foro compartido con los contactos seleccionados</string>
......
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
<string name="forum_left_toast">Forum lasciato</string> <string name="forum_left_toast">Forum lasciato</string>
<!--Forum Sharing--> <!--Forum Sharing-->
<string name="forum_share_button">Condividi Forum</string> <string name="forum_share_button">Condividi Forum</string>
<string name="forum_share_action">Condividi questo forum con i contatti scelti</string> <string name="contacts_selected">Condividi questo forum con i contatti scelti</string>
<string name="activity_share_toolbar_header">Scegli Contatti</string> <string name="activity_share_toolbar_header">Scegli Contatti</string>
<string name="forum_shared_snackbar">Forum condiviso con i contatti scelti</string> <string name="forum_shared_snackbar">Forum condiviso con i contatti scelti</string>
<string name="forum_share_error">C\'è stato un errore nella condivisione di questo forum.</string> <string name="forum_share_error">C\'è stato un errore nella condivisione di questo forum.</string>
......
...@@ -171,7 +171,7 @@ Se sentido sozinho aqui? Compartilhe esse fórum com seus contatos!</string> ...@@ -171,7 +171,7 @@ Se sentido sozinho aqui? Compartilhe esse fórum com seus contatos!</string>
<string name="forum_left_toast">Saiu do fórum</string> <string name="forum_left_toast">Saiu do fórum</string>
<!--Forum Sharing--> <!--Forum Sharing-->
<string name="forum_share_button">Compartilhar fórum</string> <string name="forum_share_button">Compartilhar fórum</string>
<string name="forum_share_action">Compartilhar este fórum com os contatos escolhidos</string> <string name="contacts_selected">Compartilhar este fórum com os contatos escolhidos</string>
<string name="activity_share_toolbar_header">Escolher contatos</string> <string name="activity_share_toolbar_header">Escolher contatos</string>
<string name="no_contacts_selector">Parece que você é novo aqui e não tem nenhum contato ainda. <string name="no_contacts_selector">Parece que você é novo aqui e não tem nenhum contato ainda.
Por favor volte aqui depois de adicionar um contato.</string> Por favor volte aqui depois de adicionar um contato.</string>
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
<!-- Forum Sharing --> <!-- Forum Sharing -->
<string name="forum_share_button">Share Forum</string> <string name="forum_share_button">Share Forum</string>
<string name="forum_share_action">Share this forum with chosen contacts</string> <string name="contacts_selected">Contacts selected</string>
<string name="activity_share_toolbar_header">Choose Contacts</string> <string name="activity_share_toolbar_header">Choose Contacts</string>
<string name="no_contacts_selector">It seems that you are new here and have no contacts yet.\n\nPlease come back here after you added your first contact.</string> <string name="no_contacts_selector">It seems that you are new here and have no contacts yet.\n\nPlease come back here after you added your first contact.</string>
<string name="forum_shared_snackbar">Forum shared with chosen contacts</string> <string name="forum_shared_snackbar">Forum shared with chosen contacts</string>
......
...@@ -23,7 +23,6 @@ import org.briarproject.api.contact.Contact; ...@@ -23,7 +23,6 @@ import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.contact.ContactManager; import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.forum.ForumSharingManager;
import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
...@@ -48,7 +47,6 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -48,7 +47,6 @@ public class ContactSelectorFragment extends BaseFragment implements
public static final String TAG = ContactSelectorFragment.class.getName(); public static final String TAG = ContactSelectorFragment.class.getName();
private static final Logger LOG = Logger.getLogger(TAG); private static final Logger LOG = Logger.getLogger(TAG);
private ShareActivity shareActivity;
private Menu menu; private Menu menu;
private BriarRecyclerView list; private BriarRecyclerView list;
private ContactSelectorAdapter adapter; private ContactSelectorAdapter adapter;
...@@ -59,13 +57,11 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -59,13 +57,11 @@ public class ContactSelectorFragment extends BaseFragment implements
volatile ContactManager contactManager; volatile ContactManager contactManager;
@Inject @Inject
volatile IdentityManager identityManager; volatile IdentityManager identityManager;
@Inject
volatile ForumSharingManager forumSharingManager;
private volatile GroupId groupId; private volatile GroupId groupId;
private volatile ContactSelectorListener listener;
public static ContactSelectorFragment newInstance(GroupId groupId) { public static ContactSelectorFragment newInstance(GroupId groupId) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putByteArray(GROUP_ID, groupId.getBytes()); args.putByteArray(GROUP_ID, groupId.getBytes());
ContactSelectorFragment fragment = new ContactSelectorFragment(); ContactSelectorFragment fragment = new ContactSelectorFragment();
...@@ -81,7 +77,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -81,7 +77,7 @@ public class ContactSelectorFragment extends BaseFragment implements
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
shareActivity = (ShareActivity) context; listener = (ContactSelectorListener) context;
} }
@Override @Override
...@@ -139,6 +135,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -139,6 +135,7 @@ public class ContactSelectorFragment extends BaseFragment implements
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (adapter != null) { if (adapter != null) {
selectedContacts = adapter.getSelectedContactIds(); selectedContacts = adapter.getSelectedContactIds();
outState.putIntegerArrayList(CONTACTS, outState.putIntegerArrayList(CONTACTS,
...@@ -148,7 +145,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -148,7 +145,7 @@ public class ContactSelectorFragment extends BaseFragment implements
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.forum_share_actions, menu); inflater.inflate(R.menu.contact_selection_actions, menu);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
this.menu = menu; this.menu = menu;
// hide sharing action initially, if no contact is selected // hide sharing action initially, if no contact is selected
...@@ -160,11 +157,11 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -160,11 +157,11 @@ public class ContactSelectorFragment extends BaseFragment implements
// Handle presses on the action bar items // Handle presses on the action bar items
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
shareActivity.onBackPressed(); listener.onBackPressed();
return true; return true;
case R.id.action_share_forum: case R.id.action_contacts_selected:
selectedContacts = adapter.getSelectedContactIds(); selectedContacts = adapter.getSelectedContactIds();
shareActivity.showMessageScreen(groupId, selectedContacts); listener.contactsSelected(groupId, selectedContacts);
return true; return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
...@@ -185,7 +182,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -185,7 +182,7 @@ public class ContactSelectorFragment extends BaseFragment implements
} }
private void loadContacts(@Nullable final Collection<ContactId> selection) { private void loadContacts(@Nullable final Collection<ContactId> selection) {
shareActivity.runOnDbThread(new Runnable() { listener.runOnDbThread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
...@@ -199,7 +196,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -199,7 +196,7 @@ public class ContactSelectorFragment extends BaseFragment implements
boolean selected = selection != null && boolean selected = selection != null &&
selection.contains(c.getId()); selection.contains(c.getId());
// do we have already some sharing with that contact? // do we have already some sharing with that contact?
boolean disabled = shareActivity.isDisabled(groupId, c); boolean disabled = listener.isDisabled(groupId, c);
contacts.add(new SelectableContactListItem(c, contacts.add(new SelectableContactListItem(c,
localAuthor, groupId, selected, disabled)); localAuthor, groupId, selected, disabled));
} }
...@@ -216,7 +213,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -216,7 +213,7 @@ public class ContactSelectorFragment extends BaseFragment implements
} }
private void displayContacts(final List<ContactListItem> contacts) { private void displayContacts(final List<ContactListItem> contacts) {
shareActivity.runOnUiThreadUnlessDestroyed(new Runnable() { listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (contacts.isEmpty()) list.showData(); if (contacts.isEmpty()) list.showData();
...@@ -228,7 +225,7 @@ public class ContactSelectorFragment extends BaseFragment implements ...@@ -228,7 +225,7 @@ public class ContactSelectorFragment extends BaseFragment implements
private void updateMenuItem() { private void updateMenuItem() {
if (menu == null) return; if (menu == null) return;
MenuItem item = menu.findItem(R.id.action_share_forum); MenuItem item = menu.findItem(R.id.action_contacts_selected);
if (item == null) return; if (item == null) return;
selectedContacts = adapter.getSelectedContactIds(); selectedContacts = adapter.getSelectedContactIds();
......
package org.briarproject.android.sharing;
import android.support.annotation.UiThread;
import org.briarproject.android.DestroyableContext;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.sync.GroupId;
import java.util.Collection;
public interface ContactSelectorListener extends DestroyableContext {
void runOnDbThread(Runnable runnable);
boolean isDisabled(GroupId groupId, Contact c) throws DbException;
@UiThread
void contactsSelected(GroupId groupId, Collection<ContactId> contacts);
@UiThread
void onBackPressed();
}
...@@ -6,7 +6,7 @@ import android.view.View; ...@@ -6,7 +6,7 @@ import android.view.View;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
import org.briarproject.android.fragment.BaseFragment; import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
...@@ -17,7 +17,7 @@ import java.util.Collection; ...@@ -17,7 +17,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
public abstract class ShareActivity extends BriarActivity implements public abstract class ShareActivity extends BriarActivity implements
BaseFragment.BaseFragmentListener { BaseFragmentListener, ContactSelectorListener {
final static String CONTACTS = "contacts"; final static String CONTACTS = "contacts";
...@@ -44,9 +44,15 @@ public abstract class ShareActivity extends BriarActivity implements ...@@ -44,9 +44,15 @@ public abstract class ShareActivity extends BriarActivity implements
abstract ShareMessageFragment getMessageFragment(GroupId groupId, abstract ShareMessageFragment getMessageFragment(GroupId groupId,
Collection<ContactId> contacts); Collection<ContactId> contacts);
abstract boolean isDisabled(GroupId groupId, Contact c) throws DbException; /**
* This must only be called from a DbThread
*/
public abstract boolean isDisabled(GroupId groupId, Contact c)
throws DbException;
void showMessageScreen(GroupId groupId, Collection<ContactId> contacts) { @Override
public void contactsSelected(GroupId groupId,
Collection<ContactId> contacts) {
ShareMessageFragment messageFragment = ShareMessageFragment messageFragment =
getMessageFragment(groupId, contacts); getMessageFragment(groupId, contacts);
......
...@@ -29,7 +29,7 @@ public class ShareBlogActivity extends ShareActivity { ...@@ -29,7 +29,7 @@ public class ShareBlogActivity extends ShareActivity {
/** /**
* This must only be called from a DbThread * This must only be called from a DbThread
*/ */
boolean isDisabled(GroupId groupId, Contact c) throws DbException { public boolean isDisabled(GroupId groupId, Contact c) throws DbException {
return !blogSharingManager.canBeShared(groupId, c); return !blogSharingManager.canBeShared(groupId, c);
} }
} }
...@@ -28,7 +28,7 @@ public class ShareForumActivity extends ShareActivity { ...@@ -28,7 +28,7 @@ public class ShareForumActivity extends ShareActivity {
/** /**
* This must only be called from a DbThread * This must only be called from a DbThread
*/ */
boolean isDisabled(GroupId groupId, Contact c) throws DbException { public boolean isDisabled(GroupId groupId, Contact c) throws DbException {
return !forumSharingManager.canBeShared(groupId, c); return !forumSharingManager.canBeShared(groupId, c);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment