Skip to content
Snippets Groups Projects
Unverified Commit 7b552bde authored by Ernir Erlingsson's avatar Ernir Erlingsson
Browse files

phase 1: Activities and Fragments

parent 1724fbe5
No related branches found
No related tags found
No related merge requests found
Showing
with 277 additions and 61 deletions
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dashboard_background"
>
</RelativeLayout>
\ No newline at end of file
package org.briarproject.android;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import org.briarproject.android.contact.ContactListFragment;
import org.briarproject.android.contact.ConversationActivity;
import org.briarproject.android.forum.AvailableForumsActivity;
import org.briarproject.android.forum.CreateForumActivity;
import org.briarproject.android.forum.ForumActivity;
import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.forum.ReadForumPostActivity;
import org.briarproject.android.forum.ShareForumActivity;
import org.briarproject.android.forum.WriteForumPostActivity;
import org.briarproject.android.fragment.BaseFragment;
import org.briarproject.android.identity.CreateIdentityActivity;
import org.briarproject.android.invitation.AddContactActivity;
import org.briarproject.android.panic.PanicPreferencesActivity;
import org.briarproject.android.panic.PanicResponderActivity;
import javax.inject.Named;
import dagger.Component;
import dagger.Provides;
@ActivityScope
@Component(modules = ActivityModule.class,
dependencies = AndroidComponent.class)
public interface ActivityComponent {
Activity activity();
void inject(SplashScreenActivity activity);
void inject(SetupActivity activity);
void inject(NavDrawerActivity activity);
void inject(PasswordActivity activity);
void inject(PanicResponderActivity activity);
void inject(PanicPreferencesActivity activity);
void inject(AddContactActivity activity);
void inject(ConversationActivity activity);
void inject(CreateIdentityActivity activity);
void inject(TestingActivity activity);
void inject(AvailableForumsActivity activity);
void inject(WriteForumPostActivity activity);
void inject(CreateForumActivity activity);
void inject(ShareForumActivity activity);
void inject(ReadForumPostActivity activity);
void inject(ForumActivity activity);
void inject(SettingsActivity activity);
@Named("ContactListFragment")
BaseFragment newContactListFragment();
@Named("ForumListFragment")
BaseFragment newForumListFragment();
// void inject(ContactListFragment fragment);
// void inject(ForumListFragment fragment);
}
package org.briarproject.android;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import org.briarproject.android.contact.ContactListFragment;
import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.fragment.BaseFragment;
import org.briarproject.android.sdk.BriarHelper;
import org.briarproject.android.sdk.BriarHelperImp;
import java.util.logging.Logger;
import javax.inject.Named;
import dagger.Module;
import dagger.Provides;
@Module
public class ActivityModule {
private final BaseActivity activity;
public ActivityModule(BaseActivity activity) {
this.activity = activity;
}
@ActivityScope
@Provides
Activity providesActivity() {
return activity;
}
@ActivityScope
@Provides
BriarHelper provideBriarHelper(BriarHelperImp briarHelperImp) {
return briarHelperImp;
}
@ActivityScope
Logger provideLogger(Activity activity) {
return Logger.getLogger(activity.getClass().getName());
}
@ActivityScope
@Provides
SharedPreferences provideSharedPreferences(Activity activity) {
return activity.getSharedPreferences("db", Context.MODE_PRIVATE);
}
@Provides
@Named("ForumListFragment")
BaseFragment provideForumListFragment(
ForumListFragment forumListFragment) {
forumListFragment.setArguments(new Bundle());
return forumListFragment;
}
@Provides
@Named("ContactListFragment")
BaseFragment provideContactListFragment(
ContactListFragment contactListFragment) {
contactListFragment.setArguments(new Bundle());
return contactListFragment;
}
}
package org.briarproject.android;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.inject.Scope;
@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface ActivityScope {
}
......@@ -2,6 +2,8 @@ package org.briarproject.android;
import org.briarproject.CoreEagerSingletons;
import org.briarproject.CoreModule;
import org.briarproject.android.api.AndroidNotificationManager;
import org.briarproject.android.api.ReferenceManager;
import org.briarproject.android.contact.ContactListFragment;
import org.briarproject.android.contact.ConversationActivity;
import org.briarproject.android.forum.AvailableForumsActivity;
......@@ -23,10 +25,31 @@ 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 org.briarproject.android.util.BriarReportSender;
import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.crypto.PasswordStrengthEstimator;
import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.api.db.DatabaseExecutor;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.forum.ForumPostFactory;
import org.briarproject.api.forum.ForumSharingManager;
import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.invitation.InvitationTaskFactory;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.messaging.PrivateMessageFactory;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.plugins.PluginManager;
import org.briarproject.api.properties.TransportPropertyManager;
import org.briarproject.api.settings.SettingsManager;
import org.briarproject.plugins.AndroidPluginsModule;
import org.briarproject.system.AndroidSystemModule;
import java.util.concurrent.Executor;
import javax.inject.Singleton;
import dagger.Component;
......@@ -39,16 +62,29 @@ import dagger.Component;
AndroidSystemModule.class
})
public interface AndroidComponent extends CoreEagerSingletons {
void inject(DevReportActivity devReportActivity);
void inject(SplashScreenActivity activity);
void inject(SetupActivity activity);
void inject(NavDrawerActivity activity);
void inject(PasswordActivity activity);
// Exposed objects
@CryptoExecutor Executor cryptoExecutor();
PasswordStrengthEstimator passwordStrengthIndicator();
CryptoComponent cryptoComponent();
DatabaseConfig databaseConfig();
AuthorFactory authFactory();
ReferenceManager referenceMangager();
@DatabaseExecutor Executor databaseExecutor();
LifecycleManager lifecycleManager();
IdentityManager identityManager();
PluginManager pluginManager();
EventBus eventBus();
InvitationTaskFactory invitationTaskFactory();
AndroidNotificationManager androidNotificationManager();
ConnectionRegistry connectionRegistry();
ContactManager contactManager();
MessagingManager messagingManager();
PrivateMessageFactory privateMessageFactory();
TransportPropertyManager transportPropertyManager();
ForumManager forumManager();
ForumSharingManager forumSharingManager();
ForumPostFactory forumPostFactory();
SettingsManager settingsManager();
void inject(BriarService activity);
......@@ -64,6 +100,8 @@ public interface AndroidComponent extends CoreEagerSingletons {
void inject(CreateIdentityActivity activity);
void inject(TestingActivity activity);
void inject(AvailableForumsActivity activity);
void inject(WriteForumPostActivity activity);
......
package org.briarproject.android;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import javax.inject.Inject;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
......@@ -17,17 +21,28 @@ public abstract class BaseActivity extends AppCompatActivity {
public final static String PREF_DB_KEY = "key";
public final static String PREF_SEEN_WELCOME_MESSAGE = "welcome_message";
protected ActivityComponent activityComponent;
// TODO Shared prefs
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
BriarApplication application = (BriarApplication) getApplication();
injectActivity(application.getApplicationComponent());
AndroidComponent applicationComponent =
((BriarApplication) getApplication()).getApplicationComponent();
activityComponent = DaggerActivityComponent.builder()
.androidComponent(applicationComponent)
.activityModule(new ActivityModule(this))
.build();
injectActivity(activityComponent);
}
public abstract void injectActivity(AndroidComponent component);
public abstract void injectActivity(ActivityComponent component);
private SharedPreferences getSharedPrefs() {
return getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
......
......@@ -10,7 +10,6 @@ import org.briarproject.R;
import org.briarproject.android.contact.ContactListFragment;
import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.fragment.BaseFragment;
import org.briarproject.android.fragment.DashboardFragment;
/**
* This class should be extended by classes that wish to utilise fragments in
......@@ -23,9 +22,7 @@ public abstract class BriarFragmentActivity extends BriarActivity {
if (actionBar == null)
return;
if (fragmentTag.equals(DashboardFragment.TAG)) {
actionBar.setTitle(R.string.dashboard_toolbar_header);
} else if (fragmentTag.equals(ContactListFragment.TAG)) {
if (fragmentTag.equals(ContactListFragment.TAG)) {
actionBar.setTitle(R.string.contacts_toolbar_header);
} else if (fragmentTag.equals(ForumListFragment.TAG)) {
actionBar.setTitle(R.string.forums_toolbar_header);
......@@ -52,7 +49,8 @@ public abstract class BriarFragmentActivity extends BriarActivity {
exiting. This models the typical Google navigation behaviour such
as in Gmail/Inbox.
*/
startFragment(ContactListFragment.newInstance());
// FIXME
// startFragment(ContactListFragment.newInstance());
} else {
super.onBackPressed();
......
......@@ -68,9 +68,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
private Toolbar toolbar;
private DrawerLayout drawerLayout;
private Button contactButton;
private Button forumsButton;
private Button settingsButton;
private GridView transportsView;
private TextView progressTitle;
private ViewGroup progressViewGroup;
......@@ -85,14 +82,14 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
checkAuthorHandle(intent);
clearBackStack();
if (intent.getBooleanExtra(INTENT_FORUMS, false))
startFragment(ForumListFragment.newInstance());
startFragment(activityComponent.newForumListFragment());
else if (intent.getBooleanExtra(INTENT_CONTACTS, false))
startFragment(ContactListFragment.newInstance());
startFragment(activityComponent.newContactListFragment());
}
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......@@ -108,9 +105,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
toolbar = (Toolbar)findViewById(R.id.toolbar);
drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
contactButton = (Button)findViewById(R.id.nav_btn_contacts);
forumsButton = (Button)findViewById(R.id.nav_btn_forums);
settingsButton = (Button)findViewById(R.id.nav_btn_settings);
transportsView = (GridView)findViewById(R.id.transportsView);
progressTitle = (TextView)findViewById(R.id.title_progress_bar);
progressViewGroup = (ViewGroup)findViewById(R.id.container_progress);
......@@ -133,7 +127,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
}
};
drawerLayout.setDrawerListener(drawerToggle);
if (state == null) startFragment(ContactListFragment.newInstance());
if (state == null) startFragment(activityComponent.newContactListFragment());
checkAuthorHandle(getIntent());
initializeTransports(getLayoutInflater());
......@@ -217,10 +211,10 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
clearBackStack();
switch (view.getId()) {
case R.id.nav_btn_contacts:
startFragment(ContactListFragment.newInstance());
startFragment(activityComponent.newContactListFragment());
break;
case R.id.nav_btn_forums:
startFragment(ForumListFragment.newInstance());
startFragment(activityComponent.newForumListFragment());
break;
case R.id.nav_btn_settings:
startActivity(new Intent(this, SettingsActivity.class));
......
......@@ -90,7 +90,7 @@ public class PasswordActivity extends BaseActivity {
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -34,7 +34,7 @@ public class SettingsActivity extends BriarActivity {
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -109,7 +109,7 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -56,7 +56,7 @@ public class SplashScreenActivity extends BaseActivity {
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -20,7 +20,7 @@ public class StartupFailureActivity extends BaseActivity {
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
}
......
......@@ -13,12 +13,14 @@ import android.view.ViewGroup;
import org.briarproject.R;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.BriarApplication;
import org.briarproject.android.fragment.BaseEventFragment;
import org.briarproject.android.keyagreement.KeyAgreementActivity;
import org.briarproject.android.util.BriarRecyclerView;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.event.ContactAddedEvent;
......@@ -28,6 +30,7 @@ import org.briarproject.api.event.ContactRemovedEvent;
import org.briarproject.api.event.ContactStatusChangedEvent;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageValidatedEvent;
import org.briarproject.api.forum.ForumInvitationMessage;
import org.briarproject.api.forum.ForumSharingManager;
......@@ -52,13 +55,14 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.BriarActivity.GROUP_ID;
public class ContactListFragment extends BaseEventFragment {
public class ContactListFragment extends BaseFragment implements EventListener {
private static final Logger LOG =
Logger.getLogger(ContactListFragment.class.getName());
public final static String TAG = "ContactListFragment";
/*
public static ContactListFragment newInstance() {
Bundle args = new Bundle();
......@@ -67,6 +71,7 @@ public class ContactListFragment extends BaseEventFragment {
fragment.setArguments(args);
return fragment;
}
*/
@Override
public String getUniqueTag() {
......@@ -92,9 +97,14 @@ public class ContactListFragment extends BaseEventFragment {
@Inject
protected volatile EventBus eventBus;
@Override
public void injectActivity(AndroidComponent component) {
component.inject(this);
// @Override
// public void injectActivity(AndroidComponent component) {
// component.inject(this);
// }
@Inject
public ContactListFragment() {
}
@Nullable
......@@ -155,7 +165,7 @@ public class ContactListFragment extends BaseEventFragment {
@Override
public void onResume() {
super.onResume();
eventBus.addListener(this);
loadContacts();
}
......@@ -163,6 +173,7 @@ public class ContactListFragment extends BaseEventFragment {
public void onPause() {
super.onPause();
adapter.clear();
eventBus.removeListener(this);
}
private void loadContacts() {
......
......@@ -23,6 +23,7 @@ import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.ActivityComponent;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.api.AndroidNotificationManager;
......@@ -157,7 +158,7 @@ public class ConversationActivity extends BriarActivity
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -5,6 +5,7 @@ import android.support.v7.widget.LinearLayoutManager;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.ActivityComponent;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.BriarRecyclerView;
......@@ -61,7 +62,7 @@ public class AvailableForumsActivity extends BriarActivity
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -15,7 +15,7 @@ import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.ActivityComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.api.db.DbException;
import org.briarproject.api.forum.Forum;
......@@ -86,7 +86,7 @@ public class CreateForumActivity extends BriarActivity
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
......@@ -19,6 +19,7 @@ import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.ActivityComponent;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.api.AndroidNotificationManager;
......@@ -127,7 +128,7 @@ public class ForumActivity extends BriarActivity implements EventListener,
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(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.AndroidComponent;
import org.briarproject.android.fragment.BaseEventFragment;
import org.briarproject.android.util.BriarRecyclerView;
......@@ -50,6 +51,7 @@ public class ForumListFragment extends BaseEventFragment implements
private static final Logger LOG =
Logger.getLogger(ForumListFragment.class.getName());
/*
public static ForumListFragment newInstance() {
Bundle args = new Bundle();
......@@ -58,6 +60,7 @@ public class ForumListFragment extends BaseEventFragment implements
fragment.setArguments(args);
return fragment;
}
*/
private BriarRecyclerView list;
private ForumListAdapter adapter;
......@@ -67,6 +70,11 @@ public class ForumListFragment extends BaseEventFragment implements
@Inject protected volatile ForumManager forumManager;
@Inject protected volatile ForumSharingManager forumSharingManager;
@Inject
public ForumListFragment() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
......@@ -99,10 +107,10 @@ public class ForumListFragment extends BaseEventFragment implements
return TAG;
}
@Override
public void injectActivity(AndroidComponent component) {
component.inject(this);
}
// @Override
// public void injectActivity(ActivityComponent component) {
// component.inject(this);
// }
@Override
public void onResume() {
......
......@@ -12,6 +12,7 @@ import android.widget.ScrollView;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.ActivityComponent;
import org.briarproject.android.AndroidComponent;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.AuthorView;
......@@ -168,7 +169,7 @@ implements OnClickListener {
}
@Override
public void injectActivity(AndroidComponent component) {
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
......
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