mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch 'nav-drawer-instance-restore-fix' into 'master'
Fixing fragment instance restore Alas, it turns out that my neat way of integrating the Fragments into the dependency graph was not without problems. Me and @grote discovered that this presented us with a lot of problems on orientation changes as the Activity is re-created, and therefore parts of the dependency graph. The simplest solution was simply to abandon the idea, i.e. with this branch Fragments are no longer part of the dependency graph. See merge request !215
This commit is contained in:
@@ -2,25 +2,29 @@ package org.briarproject.android;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.briarproject.android.blogs.MyBlogsFragment;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.contact.ConversationActivity;
|
||||
import org.briarproject.android.forum.AvailableForumsActivity;
|
||||
import org.briarproject.android.forum.ContactSelectorFragment;
|
||||
import org.briarproject.android.forum.CreateForumActivity;
|
||||
import org.briarproject.android.forum.ForumActivity;
|
||||
import org.briarproject.android.forum.ForumListFragment;
|
||||
import org.briarproject.android.forum.ForumSharingStatusActivity;
|
||||
import org.briarproject.android.forum.ShareForumActivity;
|
||||
import org.briarproject.android.forum.ShareForumMessageFragment;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.identity.CreateIdentityActivity;
|
||||
import org.briarproject.android.introduction.ContactChooserFragment;
|
||||
import org.briarproject.android.introduction.IntroductionActivity;
|
||||
import org.briarproject.android.introduction.IntroductionMessageFragment;
|
||||
import org.briarproject.android.invitation.AddContactActivity;
|
||||
import org.briarproject.android.keyagreement.ChooseIdentityFragment;
|
||||
import org.briarproject.android.keyagreement.KeyAgreementActivity;
|
||||
import org.briarproject.android.keyagreement.ShowQrCodeFragment;
|
||||
import org.briarproject.android.panic.PanicPreferencesActivity;
|
||||
import org.briarproject.android.panic.PanicResponderActivity;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@ActivityScope
|
||||
@@ -66,33 +70,16 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(IntroductionActivity activity);
|
||||
|
||||
@Named("ContactListFragment")
|
||||
BaseFragment newContactListFragment();
|
||||
// Fragments
|
||||
void inject(ContactListFragment fragment);
|
||||
void inject(ForumListFragment fragment);
|
||||
void inject(BaseFragment fragment);
|
||||
void inject(MyBlogsFragment fragment);
|
||||
void inject(ChooseIdentityFragment fragment);
|
||||
void inject(ShowQrCodeFragment fragment);
|
||||
void inject(ContactChooserFragment fragment);
|
||||
void inject(ContactSelectorFragment fragment);
|
||||
void inject(ShareForumMessageFragment fragment);
|
||||
void inject(IntroductionMessageFragment fragment);
|
||||
|
||||
@Named("ForumListFragment")
|
||||
BaseFragment newForumListFragment();
|
||||
|
||||
@Named("BlogsFragment")
|
||||
BaseFragment newBlogsFragment();
|
||||
|
||||
@Named("MyBlogsFragment")
|
||||
BaseFragment newMyBlogsFragment();
|
||||
|
||||
@Named("ChooseIdentityFragment")
|
||||
BaseFragment newChooseIdentityFragment();
|
||||
|
||||
@Named("ShowQrCodeFragment")
|
||||
BaseFragment newShowQrCodeFragment();
|
||||
|
||||
@Named("ContactChooserFragment")
|
||||
BaseFragment newContactChooserFragment();
|
||||
|
||||
@Named("ContactSelectorFragment")
|
||||
ContactSelectorFragment newContactSelectorFragment();
|
||||
|
||||
@Named("ShareForumMessageFragment")
|
||||
ShareForumMessageFragment newShareForumMessageFragment();
|
||||
|
||||
@Named("IntroductionMessageFragment")
|
||||
IntroductionMessageFragment newIntroductionMessageFragment();
|
||||
}
|
||||
|
||||
@@ -3,19 +3,13 @@ package org.briarproject.android;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.briarproject.android.blogs.BlogsFragment;
|
||||
import org.briarproject.android.blogs.MyBlogsFragment;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.controller.BriarController;
|
||||
import org.briarproject.android.controller.BriarControllerImpl;
|
||||
import org.briarproject.android.controller.ConfigController;
|
||||
import org.briarproject.android.controller.ConfigControllerImpl;
|
||||
import org.briarproject.android.controller.DbController;
|
||||
import org.briarproject.android.controller.DbControllerImpl;
|
||||
import org.briarproject.android.forum.ForumController;
|
||||
import org.briarproject.android.forum.ForumControllerImpl;
|
||||
import org.briarproject.android.controller.NavDrawerController;
|
||||
import org.briarproject.android.controller.NavDrawerControllerImpl;
|
||||
import org.briarproject.android.controller.PasswordController;
|
||||
@@ -23,15 +17,9 @@ import org.briarproject.android.controller.PasswordControllerImpl;
|
||||
import org.briarproject.android.controller.SetupController;
|
||||
import org.briarproject.android.controller.SetupControllerImpl;
|
||||
import org.briarproject.android.controller.TransportStateListener;
|
||||
import org.briarproject.android.forum.ContactSelectorFragment;
|
||||
import org.briarproject.android.forum.ForumListFragment;
|
||||
import org.briarproject.android.forum.ForumController;
|
||||
import org.briarproject.android.forum.ForumControllerImpl;
|
||||
import org.briarproject.android.forum.ForumTestControllerImpl;
|
||||
import org.briarproject.android.forum.ShareForumMessageFragment;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.introduction.ContactChooserFragment;
|
||||
import org.briarproject.android.introduction.IntroductionMessageFragment;
|
||||
import org.briarproject.android.keyagreement.ChooseIdentityFragment;
|
||||
import org.briarproject.android.keyagreement.ShowQrCodeFragment;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
@@ -137,78 +125,4 @@ public class ActivityModule {
|
||||
return new BriarServiceConnection();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ForumListFragment")
|
||||
BaseFragment provideForumListFragment(ForumListFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ContactListFragment")
|
||||
BaseFragment provideContactListFragment(ContactListFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("BlogsFragment")
|
||||
BaseFragment provideBlogsFragment(BlogsFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("MyBlogsFragment")
|
||||
BaseFragment provideMyBlogsFragment(MyBlogsFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ChooseIdentityFragment")
|
||||
BaseFragment provideChooseIdentityFragment(
|
||||
ChooseIdentityFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ShowQrCodeFragment")
|
||||
BaseFragment provideShowQrCodeFragment(ShowQrCodeFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ContactChooserFragment")
|
||||
BaseFragment provideContactChooserFragment(
|
||||
ContactChooserFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ContactSelectorFragment")
|
||||
ContactSelectorFragment provideContactSelectorFragment(
|
||||
ContactSelectorFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("ShareForumMessageFragment")
|
||||
ShareForumMessageFragment provideShareForumMessageFragment(
|
||||
ShareForumMessageFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("IntroductionMessageFragment")
|
||||
IntroductionMessageFragment provideIntroductionMessageFragment(
|
||||
IntroductionMessageFragment fragment) {
|
||||
fragment.setArguments(new Bundle());
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public ActivityComponent getActivityComponent() {
|
||||
return activityComponent;
|
||||
}
|
||||
|
||||
// This exists to make test overrides easier
|
||||
protected ActivityModule getActivityModule() {
|
||||
return new ActivityModule(this);
|
||||
|
||||
@@ -52,13 +52,17 @@ public abstract class BriarFragmentActivity extends BriarActivity {
|
||||
exiting. This models the typical Google navigation behaviour such
|
||||
as in Gmail/Inbox.
|
||||
*/
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
startFragment(ContactListFragment.newInstance());
|
||||
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFragmentCreated(String tag) {
|
||||
updateToolbarTitle(tag);
|
||||
}
|
||||
|
||||
protected void startFragment(BaseFragment fragment) {
|
||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
|
||||
startFragment(fragment, false);
|
||||
@@ -94,6 +98,5 @@ public abstract class BriarFragmentActivity extends BriarActivity {
|
||||
trans.addToBackStack(fragment.getUniqueTag());
|
||||
}
|
||||
trans.commit();
|
||||
updateToolbarTitle(fragment.getUniqueTag());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,12 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.blogs.BlogsFragment;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.controller.NavDrawerController;
|
||||
import org.briarproject.android.controller.TransportStateListener;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.android.forum.ForumListFragment;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.util.CustomAnimations;
|
||||
import org.briarproject.api.TransportId;
|
||||
@@ -49,8 +52,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
public static final String INTENT_CONTACTS = "intent_contacts";
|
||||
public static final String INTENT_FORUMS = "intent_forums";
|
||||
|
||||
private static final String KEY_CURRENT_FRAGMENT_ID = "key_current_id";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(NavDrawerActivity.class.getName());
|
||||
|
||||
@@ -66,7 +67,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
private List<Transport> transports;
|
||||
private BaseAdapter transportsAdapter;
|
||||
private int currentFragmentId = R.id.nav_btn_contacts;
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
@@ -74,10 +74,12 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
exitIfStartupFailed(intent);
|
||||
checkAuthorHandle(intent);
|
||||
clearBackStack();
|
||||
if (intent.getBooleanExtra(INTENT_FORUMS, false))
|
||||
startFragment(activityComponent.newForumListFragment());
|
||||
else if (intent.getBooleanExtra(INTENT_CONTACTS, false))
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
if (intent.getBooleanExtra(INTENT_FORUMS, false)) {
|
||||
startFragment(ForumListFragment.newInstance());
|
||||
}
|
||||
else if (intent.getBooleanExtra(INTENT_CONTACTS, false)) {
|
||||
startFragment(ContactListFragment.newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,22 +111,17 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
R.string.nav_drawer_close_description);
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
navigation.setNavigationItemSelectedListener(this);
|
||||
if (state == null) {
|
||||
navigation.setCheckedItem(R.id.nav_btn_contacts);
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
}
|
||||
checkAuthorHandle(getIntent());
|
||||
|
||||
initializeTransports(getLayoutInflater());
|
||||
transportsView.setAdapter(transportsAdapter);
|
||||
|
||||
welcomeMessageCheck();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(KEY_CURRENT_FRAGMENT_ID, currentFragmentId);
|
||||
if (state == null) {
|
||||
navigation.setCheckedItem(R.id.nav_btn_contacts);
|
||||
startFragment(ContactListFragment.newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
private void welcomeMessageCheck() {
|
||||
@@ -171,16 +168,17 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
});
|
||||
}
|
||||
|
||||
private void loadCurrentFragment() {
|
||||
switch (currentFragmentId) {
|
||||
private void loadFragment(int fragmentId) {
|
||||
// TODO re-use fragments from the manager when possible
|
||||
switch (fragmentId) {
|
||||
case R.id.nav_btn_contacts:
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
startFragment(ContactListFragment.newInstance());
|
||||
break;
|
||||
case R.id.nav_btn_forums:
|
||||
startFragment(activityComponent.newForumListFragment());
|
||||
startFragment(ForumListFragment.newInstance());
|
||||
break;
|
||||
case R.id.nav_btn_blogs:
|
||||
startFragment(activityComponent.newBlogsFragment());
|
||||
startFragment(BlogsFragment.newInstance());
|
||||
break;
|
||||
case R.id.nav_btn_settings:
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
@@ -195,8 +193,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
clearBackStack();
|
||||
currentFragmentId = item.getItemId();
|
||||
loadCurrentFragment();
|
||||
loadFragment(item.getItemId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,25 +12,25 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class BlogsFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = BlogsFragment.class.getName();
|
||||
|
||||
// TODO add your first fragment here
|
||||
//@Inject
|
||||
//Lazy<MyBlogsFragment> myBlogsFragment;
|
||||
|
||||
private static final String SELECTED_TAB = "selectedTab";
|
||||
private TabLayout tabLayout;
|
||||
|
||||
@Inject
|
||||
public BlogsFragment() {
|
||||
public static BlogsFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
BlogsFragment fragment = new BlogsFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -72,6 +72,11 @@ public class BlogsFragment extends BaseFragment {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
|
||||
private static class TabAdapter extends FragmentStatePagerAdapter {
|
||||
private String[] titles;
|
||||
|
||||
@@ -8,10 +8,9 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class MyBlogsFragment extends BaseFragment {
|
||||
@@ -52,4 +51,9 @@ public class MyBlogsFragment extends BaseFragment {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.keyagreement.KeyAgreementActivity;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
@@ -84,9 +85,13 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
@Inject
|
||||
public ContactListFragment() {
|
||||
|
||||
public static ContactListFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ContactListFragment fragment = new ContactListFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +99,11 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -154,7 +164,6 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
return contentView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.contact.BaseContactListAdapter;
|
||||
import org.briarproject.android.contact.ContactListItem;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
@@ -64,15 +65,18 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
|
||||
protected volatile GroupId groupId;
|
||||
|
||||
public void initBundle(GroupId groupId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
setArguments(bundle);
|
||||
public static ContactSelectorFragment newInstance(GroupId groupId) {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
ContactSelectorFragment fragment = new ContactSelectorFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ContactSelectorFragment() {
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseEventFragment;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -59,9 +60,13 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
@Inject protected volatile ForumManager forumManager;
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
@Inject
|
||||
public ForumListFragment() {
|
||||
public static ForumListFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ForumListFragment fragment = new ForumListFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -96,6 +101,11 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
// TODO extend the BriarFragmentActivity ?
|
||||
public class ShareForumActivity extends BriarActivity implements
|
||||
BaseFragment.BaseFragmentListener {
|
||||
|
||||
@@ -33,8 +34,7 @@ public class ShareForumActivity extends BriarActivity implements
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
ContactSelectorFragment contactSelectorFragment =
|
||||
activityComponent.newContactSelectorFragment();
|
||||
contactSelectorFragment.initBundle(groupId);
|
||||
ContactSelectorFragment.newInstance(groupId);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.shareForumContainer, contactSelectorFragment)
|
||||
.commit();
|
||||
@@ -50,8 +50,7 @@ public class ShareForumActivity extends BriarActivity implements
|
||||
Collection<ContactId> contacts) {
|
||||
|
||||
ShareForumMessageFragment messageFragment =
|
||||
activityComponent.newShareForumMessageFragment();
|
||||
messageFragment.initBundle(groupId, contacts);
|
||||
ShareForumMessageFragment.newInstance(groupId, contacts);
|
||||
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.setCustomAnimations(android.R.anim.fade_in,
|
||||
@@ -86,7 +85,7 @@ public class ShareForumActivity extends BriarActivity implements
|
||||
|
||||
// turn contact integers from a bundle back to ContactIds
|
||||
List<ContactId> contacts = new ArrayList<>(intContacts.size());
|
||||
for(Integer c : intContacts) {
|
||||
for (Integer c : intContacts) {
|
||||
contacts.add(new ContactId(c));
|
||||
}
|
||||
return contacts;
|
||||
@@ -102,4 +101,9 @@ public class ShareForumActivity extends BriarActivity implements
|
||||
// this is handled by the recycler view in ContactSelectorFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentCreated(String tag) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -46,16 +47,13 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
private volatile GroupId groupId;
|
||||
private volatile Collection<ContactId> contacts;
|
||||
|
||||
public void initBundle(GroupId groupId, Collection<ContactId> contacts) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
bundle.putIntegerArrayList(CONTACTS, getContactsFromIds(contacts));
|
||||
setArguments(bundle);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ShareForumMessageFragment() {
|
||||
|
||||
public static ShareForumMessageFragment newInstance(GroupId groupId, Collection<ContactId> contacts) {
|
||||
Bundle args = new Bundle();
|
||||
args.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
args.putIntegerArrayList(CONTACTS, getContactsFromIds(contacts));
|
||||
ShareForumMessageFragment fragment = new ShareForumMessageFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,6 +117,11 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
public void onButtonClick() {
|
||||
// disable button to prevent accidental double invitations
|
||||
ui.button.setEnabled(false);
|
||||
|
||||
@@ -2,14 +2,19 @@ package org.briarproject.android.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
|
||||
protected BaseFragmentListener listener;
|
||||
|
||||
public abstract String getUniqueTag();
|
||||
|
||||
public abstract void injectFragment(ActivityComponent component);
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -26,6 +31,14 @@ public abstract class BaseFragment extends Fragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
this.injectFragment(listener.getActivityComponent());
|
||||
listener.onFragmentCreated(getUniqueTag());
|
||||
}
|
||||
|
||||
public interface BaseFragmentListener {
|
||||
|
||||
void showLoadingScreen(boolean isBlocking, int stringId);
|
||||
@@ -35,5 +48,9 @@ public abstract class BaseFragment extends Fragment {
|
||||
void runOnUiThread(Runnable runnable);
|
||||
|
||||
void runOnDbThread(Runnable runnable);
|
||||
|
||||
ActivityComponent getActivityComponent();
|
||||
|
||||
void onFragmentCreated(String tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.contact.ContactListAdapter;
|
||||
import org.briarproject.android.contact.ContactListItem;
|
||||
import org.briarproject.android.contact.ConversationItem;
|
||||
@@ -66,9 +67,13 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
@Inject
|
||||
protected volatile ConnectionRegistry connectionRegistry;
|
||||
|
||||
@Inject
|
||||
public ContactChooserFragment() {
|
||||
|
||||
public static ContactChooserFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ContactChooserFragment fragment = new ContactChooserFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +147,11 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
private void loadContacts() {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
|
||||
// TODO extend the BriarFragmentActivity ?
|
||||
public class IntroductionActivity extends BriarActivity implements
|
||||
BaseFragment.BaseFragmentListener {
|
||||
|
||||
@@ -37,7 +38,7 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.introductionContainer,
|
||||
activityComponent.newContactChooserFragment())
|
||||
ContactChooserFragment.newInstance())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
@@ -57,6 +58,11 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
// this is handled by the recycler view in ContactChooserFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentCreated(String tag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
@@ -86,8 +92,8 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
public void showMessageScreen(View view, Contact c1, Contact c2) {
|
||||
|
||||
IntroductionMessageFragment messageFragment =
|
||||
activityComponent.newIntroductionMessageFragment();
|
||||
messageFragment.initBundle(c1.getId().getInt(), c2.getId().getInt());
|
||||
IntroductionMessageFragment
|
||||
.newInstance(c1.getId().getInt(), c2.getId().getInt());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
messageFragment.setSharedElementEnterTransition(new ChangeBounds());
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
@@ -51,19 +52,21 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
@Inject
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
|
||||
public void initBundle(int contactId1, int contactId2) {
|
||||
public static IntroductionMessageFragment newInstance(int contactId1, int contactId2) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(CONTACT_ID_1, contactId1);
|
||||
args.putInt(CONTACT_ID_2, contactId2);
|
||||
setArguments(args);
|
||||
IntroductionMessageFragment fragment =
|
||||
new IntroductionMessageFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public IntroductionMessageFragment() {
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -94,6 +97,13 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
ui.text.setVisibility(GONE);
|
||||
ui.button.setEnabled(false);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// get contact IDs from fragment arguments
|
||||
int contactId1 = getArguments().getInt(CONTACT_ID_1, -1);
|
||||
int contactId2 = getArguments().getInt(CONTACT_ID_2, -1);
|
||||
@@ -101,11 +111,8 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
throw new java.lang.InstantiationError(
|
||||
"You need to use newInstance() to instantiate");
|
||||
}
|
||||
|
||||
// get contacts and then show view
|
||||
prepareToSetUpViews(contactId1, contactId2);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.identity.CreateIdentityActivity;
|
||||
import org.briarproject.android.identity.LocalAuthorItem;
|
||||
@@ -57,9 +58,18 @@ public class ChooseIdentityFragment extends BaseFragment
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
@Inject
|
||||
public ChooseIdentityFragment() {
|
||||
public static ChooseIdentityFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ChooseIdentityFragment fragment = new ChooseIdentityFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,6 +114,11 @@ public class ChooseIdentityFragment extends BaseFragment
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
loadLocalAuthors();
|
||||
}
|
||||
|
||||
|
||||
@@ -94,11 +94,11 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
|
||||
STEPS));
|
||||
switch (step) {
|
||||
case STEP_QR:
|
||||
startFragment(activityComponent.newShowQrCodeFragment());
|
||||
startFragment(ShowQrCodeFragment.newInstance());
|
||||
break;
|
||||
case STEP_ID:
|
||||
default:
|
||||
startFragment(activityComponent.newChooseIdentityFragment());
|
||||
startFragment(ChooseIdentityFragment.newInstance());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import android.widget.Toast;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.api.AndroidExecutor;
|
||||
import org.briarproject.android.fragment.BaseEventFragment;
|
||||
import org.briarproject.android.util.CameraView;
|
||||
@@ -86,9 +86,18 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
private volatile KeyAgreementTask task;
|
||||
private volatile boolean waitingForBluetooth;
|
||||
|
||||
@Inject
|
||||
public ShowQrCodeFragment() {
|
||||
public static ShowQrCodeFragment newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ShowQrCodeFragment fragment = new ShowQrCodeFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.0'
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
classpath 'de.undercouch:gradle-download-task:2.1.0'
|
||||
classpath files('briar-core/libs/gradle-witness.jar')
|
||||
|
||||
Reference in New Issue
Block a user