mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
UI code cleanup.
This commit is contained in:
@@ -28,6 +28,7 @@ import dagger.Component;
|
||||
@Component(modules = ActivityModule.class,
|
||||
dependencies = AndroidComponent.class)
|
||||
public interface ActivityComponent {
|
||||
|
||||
Activity activity();
|
||||
|
||||
void inject(SplashScreenActivity activity);
|
||||
@@ -64,23 +65,8 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(SettingsActivity activity);
|
||||
|
||||
/*
|
||||
void inject(ContactListFragment fragment);
|
||||
|
||||
void inject(ForumListFragment fragment);
|
||||
|
||||
void inject(ShowQrCodeFragment fragment);
|
||||
*/
|
||||
|
||||
void inject(IntroductionActivity activity);
|
||||
|
||||
/*
|
||||
void inject(ContactChooserFragment fragment);
|
||||
|
||||
void inject(introductionmessagefragment fragment);
|
||||
|
||||
*/
|
||||
|
||||
@Named("ContactListFragment")
|
||||
BaseFragment newContactListFragment();
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import dagger.Component;
|
||||
AndroidSystemModule.class
|
||||
})
|
||||
public interface AndroidComponent extends CoreEagerSingletons {
|
||||
|
||||
// Exposed objects
|
||||
@CryptoExecutor
|
||||
Executor cryptoExecutor();
|
||||
|
||||
@@ -19,12 +19,13 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
protected ActivityComponent activityComponent;
|
||||
|
||||
private List<ActivityLifecycleController> lifecycleControllers =
|
||||
new ArrayList<ActivityLifecycleController>();
|
||||
private final List<ActivityLifecycleController> lifecycleControllers =
|
||||
new ArrayList<>();
|
||||
|
||||
public void addLifecycleController(
|
||||
ActivityLifecycleController lifecycleController) {
|
||||
this.lifecycleControllers.add(lifecycleController);
|
||||
public abstract void injectActivity(ActivityComponent component);
|
||||
|
||||
public void addLifecycleController(ActivityLifecycleController alc) {
|
||||
lifecycleControllers.add(alc);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,9 +78,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void injectActivity(ActivityComponent component);
|
||||
|
||||
protected void showSoftKeyboard(View view) {
|
||||
public void showSoftKeyboard(View view) {
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).showSoftInput(view, SHOW_IMPLICIT);
|
||||
}
|
||||
@@ -89,5 +88,4 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,14 +69,13 @@ public abstract class BriarActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void startExitActivity() {
|
||||
Intent intent = new Intent(BriarActivity.this,
|
||||
ExitActivity.class);
|
||||
intent.addFlags(FLAG_ACTIVITY_NEW_TASK
|
||||
Intent i = new Intent(this, ExitActivity.class);
|
||||
i.addFlags(FLAG_ACTIVITY_NEW_TASK
|
||||
| FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
||||
| FLAG_ACTIVITY_NO_ANIMATION);
|
||||
if (Build.VERSION.SDK_INT >= 11)
|
||||
intent.addFlags(FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
i.addFlags(FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
private void finishAndExit() {
|
||||
@@ -94,6 +93,7 @@ public abstract class BriarActivity extends BaseActivity {
|
||||
@Deprecated
|
||||
protected void finishOnUiThread() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ import java.util.logging.Logger;
|
||||
resDialogOkToast = R.string.dev_report_saved,
|
||||
deleteOldUnsentReportsOnApplicationStart = false
|
||||
)
|
||||
public class BriarApplicationImpl extends Application implements BriarApplication {
|
||||
public class BriarApplicationImpl extends Application
|
||||
implements BriarApplication {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BriarApplicationImpl.class.getName());
|
||||
@@ -50,6 +51,7 @@ public class BriarApplicationImpl extends Application implements BriarApplicatio
|
||||
AndroidEagerSingletons.initEagerSingletons(applicationComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AndroidComponent getApplicationComponent() {
|
||||
return applicationComponent;
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ public abstract class BriarFragmentActivity extends BriarActivity {
|
||||
|
||||
protected void startFragment(BaseFragment fragment) {
|
||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
|
||||
this.startFragment(fragment, false);
|
||||
else
|
||||
this.startFragment(fragment, true);
|
||||
startFragment(fragment, false);
|
||||
else startFragment(fragment, true);
|
||||
}
|
||||
|
||||
protected void showMessageDialog(int titleStringId, int msgStringId) {
|
||||
@@ -76,7 +75,7 @@ public abstract class BriarFragmentActivity extends BriarActivity {
|
||||
|
||||
protected void startFragment(BaseFragment fragment,
|
||||
boolean isAddedToBackStack) {
|
||||
this.startFragment(fragment, 0, 0, isAddedToBackStack);
|
||||
startFragment(fragment, 0, 0, isAddedToBackStack);
|
||||
}
|
||||
|
||||
protected void startFragment(BaseFragment fragment,
|
||||
@@ -94,5 +93,4 @@ public abstract class BriarFragmentActivity extends BriarActivity {
|
||||
trans.commit();
|
||||
updateToolbarTitle(fragment.getUniqueTag());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ACRAConstants;
|
||||
import org.acra.ReportField;
|
||||
import org.acra.collector.CrashReportData;
|
||||
import org.acra.dialog.BaseCrashReportDialog;
|
||||
@@ -24,7 +23,6 @@ import org.acra.file.CrashReportPersister;
|
||||
import org.acra.prefs.SharedPreferencesFactory;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.UserFeedback;
|
||||
import org.briarproject.api.reporting.DevReporter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -34,12 +32,12 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.acra.ACRAConstants.EXTRA_REPORT_FILE;
|
||||
import static org.acra.ReportField.ANDROID_VERSION;
|
||||
import static org.acra.ReportField.APP_VERSION_CODE;
|
||||
import static org.acra.ReportField.APP_VERSION_NAME;
|
||||
@@ -68,9 +66,6 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
requiredFields.add(STACK_TRACE);
|
||||
}
|
||||
|
||||
@Inject
|
||||
protected DevReporter reporter;
|
||||
|
||||
private SharedPreferencesFactory sharedPreferencesFactory;
|
||||
private Set<ReportField> excludedFields;
|
||||
private EditText userCommentView = null;
|
||||
@@ -86,17 +81,15 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
super.onCreate(state);
|
||||
setContentView(R.layout.activity_dev_report);
|
||||
|
||||
((BriarApplication) getApplication()).getApplicationComponent()
|
||||
.inject(this);
|
||||
BriarApplication app = (BriarApplication) getApplication();
|
||||
app.getApplicationComponent().inject(this);
|
||||
|
||||
|
||||
sharedPreferencesFactory =
|
||||
new SharedPreferencesFactory(getApplicationContext(),
|
||||
getConfig());
|
||||
sharedPreferencesFactory = new SharedPreferencesFactory(
|
||||
getApplicationContext(), getConfig());
|
||||
|
||||
final SharedPreferences prefs = sharedPreferencesFactory.create();
|
||||
excludedFields = new HashSet<>();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
for (String name : prefs.getStringSet(PREF_EXCLUDED_FIELDS,
|
||||
new HashSet<String>())) {
|
||||
excludedFields.add(ReportField.valueOf(name));
|
||||
@@ -163,11 +156,8 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
dialog.cancel();
|
||||
}
|
||||
if (which == BUTTON_POSITIVE) dialog.dismiss();
|
||||
else dialog.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,10 +169,8 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
ReportField field = (ReportField) buttonView.getTag();
|
||||
if (field != null) {
|
||||
if (isChecked)
|
||||
excludedFields.remove(field);
|
||||
else
|
||||
excludedFields.add(field);
|
||||
if (isChecked) excludedFields.remove(field);
|
||||
else excludedFields.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +202,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
@Override
|
||||
protected CrashReportData doInBackground(Void... args) {
|
||||
File reportFile = (File) getIntent().getSerializableExtra(
|
||||
ACRAConstants.EXTRA_REPORT_FILE);
|
||||
EXTRA_REPORT_FILE);
|
||||
final CrashReportPersister persister =
|
||||
new CrashReportPersister();
|
||||
try {
|
||||
@@ -272,7 +260,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... args) {
|
||||
File reportFile = (File) getIntent().getSerializableExtra(
|
||||
ACRAConstants.EXTRA_REPORT_FILE);
|
||||
EXTRA_REPORT_FILE);
|
||||
CrashReportPersister persister = new CrashReportPersister();
|
||||
try {
|
||||
CrashReportData data = persister.load(reportFile);
|
||||
@@ -303,7 +291,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
protected void onPostExecute(Boolean success) {
|
||||
final SharedPreferences prefs =
|
||||
sharedPreferencesFactory.create();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
final SharedPreferences.Editor prefEditor =
|
||||
prefs.edit();
|
||||
Set<String> fields = new HashSet<>();
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
@@ -33,6 +32,11 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.support.v4.view.GravityCompat.START;
|
||||
import static android.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
|
||||
import static android.support.v4.widget.DrawerLayout.LOCK_MODE_UNLOCKED;
|
||||
import static android.view.View.INVISIBLE;
|
||||
|
||||
public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
BaseFragment.BaseFragmentListener, TransportStateListener {
|
||||
|
||||
@@ -51,7 +55,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
private Toolbar toolbar;
|
||||
private DrawerLayout drawerLayout;
|
||||
private GridView transportsView;
|
||||
private TextView progressTitle;
|
||||
private ViewGroup progressViewGroup;
|
||||
|
||||
@@ -88,7 +91,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
transportsView = (GridView) findViewById(R.id.transportsView);
|
||||
GridView transportsView = (GridView) findViewById(R.id.transportsView);
|
||||
progressTitle = (TextView) findViewById(R.id.title_progress_bar);
|
||||
progressViewGroup = (ViewGroup) findViewById(R.id.container_progress);
|
||||
|
||||
@@ -98,19 +101,10 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
||||
R.string.nav_drawer_open_description,
|
||||
R.string.nav_drawer_close_description
|
||||
) {
|
||||
|
||||
public void onDrawerClosed(View view) {
|
||||
super.onDrawerClosed(view);
|
||||
}
|
||||
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
}
|
||||
};
|
||||
R.string.nav_drawer_close_description);
|
||||
drawerLayout.setDrawerListener(drawerToggle);
|
||||
if (state == null) startFragment(activityComponent.newContactListFragment());
|
||||
if (state == null)
|
||||
startFragment(activityComponent.newContactListFragment());
|
||||
checkAuthorHandle(getIntent());
|
||||
|
||||
initializeTransports(getLayoutInflater());
|
||||
@@ -156,18 +150,17 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
return false;
|
||||
}
|
||||
|
||||
private void storeLocalAuthor(final LocalAuthor a) {
|
||||
controller.storeLocalAuthor(a,
|
||||
new UiResultHandler<Void>(this) {
|
||||
@Override
|
||||
public void onResultUi(Void result) {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
});
|
||||
private void storeLocalAuthor(LocalAuthor a) {
|
||||
controller.storeLocalAuthor(a, new UiResultHandler<Void>(this) {
|
||||
@Override
|
||||
public void onResultUi(Void result) {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onNavigationClick(View view) {
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
drawerLayout.closeDrawer(START);
|
||||
clearBackStack();
|
||||
switch (view.getId()) {
|
||||
case R.id.nav_btn_contacts:
|
||||
@@ -189,8 +182,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0
|
||||
&& drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
&& drawerLayout.isDrawerOpen(START)) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
@@ -218,8 +211,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
public void showLoadingScreen(boolean isBlocking, int stringId) {
|
||||
if (isBlocking) {
|
||||
// Disable navigation drawer slide to open
|
||||
drawerLayout
|
||||
.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||
drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED);
|
||||
CustomAnimations.animateHeight(toolbar, false, 250);
|
||||
}
|
||||
progressTitle.setText(stringId);
|
||||
@@ -228,14 +220,13 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
@Override
|
||||
public void hideLoadingScreen() {
|
||||
drawerLayout
|
||||
.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||
drawerLayout.setDrawerLockMode(LOCK_MODE_UNLOCKED);
|
||||
CustomAnimations.animateHeight(toolbar, true, 250);
|
||||
progressViewGroup.setVisibility(View.INVISIBLE);
|
||||
progressViewGroup.setVisibility(INVISIBLE);
|
||||
}
|
||||
|
||||
private void initializeTransports(final LayoutInflater inflater) {
|
||||
transports = new ArrayList<Transport>(3);
|
||||
transports = new ArrayList<>(3);
|
||||
|
||||
Transport tor = new Transport();
|
||||
tor.id = new TransportId("tor");
|
||||
@@ -277,8 +268,8 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
@Override
|
||||
public View getView(int position, View convertView,
|
||||
ViewGroup parent) {
|
||||
ViewGroup view = (ViewGroup) inflater
|
||||
.inflate(R.layout.list_item_transport, parent, false);
|
||||
ViewGroup view = (ViewGroup) inflater.inflate(
|
||||
R.layout.list_item_transport, parent, false);
|
||||
|
||||
Transport t = getItem(position);
|
||||
Resources r = getResources();
|
||||
@@ -304,6 +295,7 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
|
||||
private void setTransport(final TransportId id, final boolean enabled) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
@@ -331,9 +323,10 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
|
||||
}
|
||||
|
||||
private static class Transport {
|
||||
TransportId id;
|
||||
boolean enabled;
|
||||
int iconId;
|
||||
int textId;
|
||||
|
||||
private TransportId id;
|
||||
private boolean enabled;
|
||||
private int iconId;
|
||||
private int textId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,20 +30,20 @@ import static android.view.View.VISIBLE;
|
||||
|
||||
public class PasswordActivity extends BaseActivity {
|
||||
|
||||
@Inject
|
||||
protected PasswordController passwordController;
|
||||
|
||||
private Button signInButton;
|
||||
private ProgressBar progress;
|
||||
private TextInputLayout input;
|
||||
private EditText password;
|
||||
|
||||
@Inject
|
||||
PasswordController passwordController;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
if (!passwordController.initialized()) {
|
||||
clearSharedPrefsAndDeleteEverything();
|
||||
if (!passwordController.accountExists()) {
|
||||
deleteAccount();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public class PasswordActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
password.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
@@ -91,9 +92,8 @@ public class PasswordActivity extends BaseActivity {
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void clearSharedPrefsAndDeleteEverything() {
|
||||
passwordController.clearPrefs();
|
||||
AndroidUtils.deleteAppData(this);
|
||||
private void deleteAccount() {
|
||||
passwordController.deleteAccount(this);
|
||||
setResult(RESULT_CANCELED);
|
||||
startActivity(new Intent(this, SetupActivity.class));
|
||||
finish();
|
||||
@@ -114,7 +114,7 @@ public class PasswordActivity extends BaseActivity {
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
clearSharedPrefsAndDeleteEverything();
|
||||
deleteAccount();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
@@ -140,8 +140,7 @@ public class PasswordActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void tryAgain() {
|
||||
AndroidUtils.setError(input, getString(R.string.try_again),
|
||||
true);
|
||||
AndroidUtils.setError(input, getString(R.string.try_again), true);
|
||||
signInButton.setVisibility(VISIBLE);
|
||||
progress.setVisibility(INVISIBLE);
|
||||
password.setText("");
|
||||
@@ -149,5 +148,4 @@ public class PasswordActivity extends BaseActivity {
|
||||
// show the keyboard again
|
||||
showSoftKeyboard(password);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ import javax.inject.Inject;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
||||
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
|
||||
import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK;
|
||||
import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
@@ -38,15 +36,15 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
|
||||
@Inject
|
||||
protected SetupController setupController;
|
||||
|
||||
TextInputLayout nicknameEntryWrapper;
|
||||
TextInputLayout passwordEntryWrapper;
|
||||
TextInputLayout passwordConfirmationWrapper;
|
||||
EditText nicknameEntry;
|
||||
EditText passwordEntry;
|
||||
EditText passwordConfirmation;
|
||||
StrengthMeter strengthMeter;
|
||||
Button createAccountButton;
|
||||
ProgressBar progress;
|
||||
private TextInputLayout nicknameEntryWrapper;
|
||||
private TextInputLayout passwordEntryWrapper;
|
||||
private TextInputLayout passwordConfirmationWrapper;
|
||||
private EditText nicknameEntry;
|
||||
private EditText passwordEntry;
|
||||
private EditText passwordConfirmation;
|
||||
private StrengthMeter strengthMeter;
|
||||
private Button createAccountButton;
|
||||
private ProgressBar progress;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -66,9 +64,8 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
|
||||
createAccountButton = (Button) findViewById(R.id.create_account);
|
||||
progress = (ProgressBar) findViewById(R.id.progress_wheel);
|
||||
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
TextWatcher tw = new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
@@ -107,7 +104,8 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
|
||||
String firstPassword = passwordEntry.getText().toString();
|
||||
String secondPassword = passwordConfirmation.getText().toString();
|
||||
boolean passwordsMatch = firstPassword.equals(secondPassword);
|
||||
float strength = setupController.estimatePasswordStrength(firstPassword);
|
||||
float strength =
|
||||
setupController.estimatePasswordStrength(firstPassword);
|
||||
strengthMeter.setStrength(strength);
|
||||
AndroidUtils.setError(nicknameEntryWrapper,
|
||||
getString(R.string.name_too_long),
|
||||
@@ -123,18 +121,19 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
|
||||
&& passwordsMatch && strength >= WEAK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
hideSoftKeyboard(v);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// Replace the button with a progress bar
|
||||
createAccountButton.setVisibility(INVISIBLE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
final String nickname = nicknameEntry.getText().toString();
|
||||
final String password = passwordEntry.getText().toString();
|
||||
String nickname = nicknameEntry.getText().toString();
|
||||
String password = passwordEntry.getText().toString();
|
||||
setupController.createIdentity(nickname, password,
|
||||
new UiResultHandler<Long>(this) {
|
||||
@Override
|
||||
@@ -145,8 +144,7 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
|
||||
}
|
||||
|
||||
private void showMain(final long handle) {
|
||||
Intent i = new Intent(SetupActivity.this,
|
||||
NavDrawerActivity.class);
|
||||
Intent i = new Intent(this, NavDrawerActivity.class);
|
||||
i.putExtra(BriarActivity.KEY_LOCAL_AUTHOR_HANDLE, handle);
|
||||
i.setFlags(FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.support.v7.preference.PreferenceManager;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.api.AndroidExecutor;
|
||||
import org.briarproject.android.controller.ConfigController;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -29,7 +28,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
private static final long EXPIRY_DATE = 1464735600 * 1000L;
|
||||
|
||||
@Inject
|
||||
ConfigController configController;
|
||||
protected ConfigController configController;
|
||||
@Inject
|
||||
protected AndroidExecutor androidExecutor;
|
||||
|
||||
@@ -65,12 +64,10 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
LOG.info("Expired");
|
||||
startActivity(new Intent(this, ExpiredActivity.class));
|
||||
} else {
|
||||
if (configController.initialized()) {
|
||||
if (configController.accountExists()) {
|
||||
startActivity(new Intent(this, NavDrawerActivity.class));
|
||||
} else {
|
||||
configController.clearPrefs();
|
||||
// TODO replace this static call with a controller method
|
||||
AndroidUtils.deleteAppData(this);
|
||||
configController.deleteAccount(this);
|
||||
startActivity(new Intent(this, SetupActivity.class));
|
||||
}
|
||||
}
|
||||
@@ -91,6 +88,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private void setPreferencesDefaults() {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
||||
R.xml.panic_preferences, false);
|
||||
|
||||
@@ -25,15 +25,15 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
protected final OnItemClickListener listener;
|
||||
protected Context ctx;
|
||||
|
||||
public BaseContactListAdapter(Context context, OnItemClickListener listener) {
|
||||
this.ctx = context;
|
||||
public BaseContactListAdapter(Context ctx, OnItemClickListener listener) {
|
||||
this.ctx = ctx;
|
||||
this.listener = listener;
|
||||
this.contacts = new SortedList<>(ContactListItem.class,
|
||||
new SortedListCallBacks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final VH ui, final int position) {
|
||||
public void onBindViewHolder(final VH ui, int position) {
|
||||
final ContactListItem item = getItem(position);
|
||||
|
||||
Author author = item.getContact().getAuthor();
|
||||
@@ -96,6 +96,7 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
}
|
||||
|
||||
public static class BaseContactHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public final ViewGroup layout;
|
||||
public final ImageView avatar;
|
||||
public final TextView name;
|
||||
@@ -132,7 +133,8 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected class SortedListCallBacks extends SortedList.Callback<ContactListItem> {
|
||||
protected class SortedListCallBacks
|
||||
extends SortedList.Callback<ContactListItem> {
|
||||
|
||||
@Override
|
||||
public void onInserted(int position, int count) {
|
||||
@@ -185,5 +187,4 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(View view, ContactListItem item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,17 +20,17 @@ public class ContactListAdapter
|
||||
|
||||
@Override
|
||||
public ContactHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_contact, viewGroup, false);
|
||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_contact, viewGroup, false);
|
||||
|
||||
return new ContactHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ContactHolder ui, final int position) {
|
||||
public void onBindViewHolder(ContactHolder ui, int position) {
|
||||
super.onBindViewHolder(ui, position);
|
||||
|
||||
final ContactListItem item = getItem(position);
|
||||
ContactListItem item = getItem(position);
|
||||
|
||||
// name and unread count
|
||||
String contactName = item.getContact().getAuthor().getName();
|
||||
@@ -84,5 +84,4 @@ public class ContactListAdapter
|
||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
||||
return compareByTime(c1, c2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,18 +54,16 @@ import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
|
||||
public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
public final static String TAG = "ContactListFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactListFragment.class.getName());
|
||||
|
||||
public final static String TAG = "ContactListFragment";
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Inject
|
||||
protected ConnectionRegistry connectionRegistry;
|
||||
@Inject
|
||||
protected EventBus eventBus;
|
||||
|
||||
private ContactListAdapter adapter = null;
|
||||
private BriarRecyclerView list = null;
|
||||
|
||||
@@ -80,15 +78,17 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
|
||||
|
||||
@Inject
|
||||
public ContactListFragment() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -160,11 +160,11 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void loadContacts() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<ContactListItem>();
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
try {
|
||||
ContactId id = c.getId();
|
||||
@@ -196,6 +196,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void displayContacts(final List<ContactListItem> contacts) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (contacts.size() == 0) list.showData();
|
||||
else adapter.addAll(contacts);
|
||||
@@ -203,9 +204,10 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactAddedEvent) {
|
||||
if(((ContactAddedEvent) e).isActive()) {
|
||||
if (((ContactAddedEvent) e).isActive()) {
|
||||
LOG.info("Contact added as active, reloading");
|
||||
loadContacts();
|
||||
}
|
||||
@@ -233,6 +235,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void reloadConversation(final GroupId g) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ContactId c = messagingManager.getContactId(g);
|
||||
@@ -252,6 +255,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
private void updateItem(final ContactId c,
|
||||
final Collection<ConversationItem> messages) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -265,6 +269,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void removeItem(final ContactId c) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -275,6 +280,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void setConnected(final ContactId c, final boolean connected) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -286,14 +292,13 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
/** This needs to be called from the DbThread */
|
||||
// This needs to be called from the DB thread
|
||||
private Collection<ConversationItem> getMessages(ContactId id)
|
||||
throws DbException {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Collection<ConversationItem> messages =
|
||||
new ArrayList<ConversationItem>();
|
||||
Collection<ConversationItem> messages = new ArrayList<>();
|
||||
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessageHeaders(id);
|
||||
|
||||
@@ -24,12 +24,12 @@ 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;
|
||||
import org.briarproject.android.introduction.IntroductionActivity;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
@@ -55,7 +55,6 @@ import org.briarproject.api.introduction.IntroductionManager;
|
||||
import org.briarproject.api.introduction.IntroductionMessage;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.messaging.MessagingManager;
|
||||
import org.briarproject.api.messaging.PrivateMessage;
|
||||
import org.briarproject.api.messaging.PrivateMessageFactory;
|
||||
@@ -95,25 +94,37 @@ public class ConversationActivity extends BriarActivity
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ConversationActivity.class.getName());
|
||||
|
||||
@Inject protected AndroidNotificationManager notificationManager;
|
||||
@Inject protected ConnectionRegistry connectionRegistry;
|
||||
@Inject @CryptoExecutor protected Executor cryptoExecutor;
|
||||
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
|
||||
private ConversationAdapter adapter = null;
|
||||
@Inject
|
||||
protected AndroidNotificationManager notificationManager;
|
||||
@Inject
|
||||
protected ConnectionRegistry connectionRegistry;
|
||||
@Inject
|
||||
@CryptoExecutor
|
||||
protected Executor cryptoExecutor;
|
||||
|
||||
private Map<MessageId, byte[]> bodyCache = new HashMap<>();
|
||||
private ConversationAdapter adapter;
|
||||
private CircleImageView toolbarAvatar;
|
||||
private ImageView toolbarStatus;
|
||||
private TextView toolbarTitle;
|
||||
private BriarRecyclerView list = null;
|
||||
private EditText content = null;
|
||||
private ImageButton sendButton = null;
|
||||
private BriarRecyclerView list;
|
||||
private EditText content;
|
||||
private ImageButton sendButton;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile ContactManager contactManager;
|
||||
@Inject protected volatile MessagingManager messagingManager;
|
||||
@Inject protected volatile EventBus eventBus;
|
||||
@Inject protected volatile PrivateMessageFactory privateMessageFactory;
|
||||
@Inject protected volatile IntroductionManager introductionManager;
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile ContactManager contactManager;
|
||||
@Inject
|
||||
protected volatile MessagingManager messagingManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
@Inject
|
||||
protected volatile PrivateMessageFactory privateMessageFactory;
|
||||
@Inject
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
private volatile GroupId groupId = null;
|
||||
private volatile ContactId contactId = null;
|
||||
private volatile String contactName = null;
|
||||
@@ -218,6 +229,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void loadData() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -248,6 +260,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void displayContactDetails() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toolbarAvatar.setImageDrawable(
|
||||
new IdenticonDrawable(contactIdenticonKey));
|
||||
@@ -273,6 +286,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void loadMessages() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -304,6 +318,7 @@ public class ConversationActivity extends BriarActivity
|
||||
final Collection<IntroductionMessage> introductions,
|
||||
final Collection<ForumInvitationMessage> invitations) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendButton.setEnabled(true);
|
||||
if (headers.isEmpty() && introductions.isEmpty() &&
|
||||
@@ -312,8 +327,7 @@ public class ConversationActivity extends BriarActivity
|
||||
// so let the list know to hide progress bar
|
||||
list.showData();
|
||||
} else {
|
||||
List<ConversationItem> items =
|
||||
new ArrayList<ConversationItem>();
|
||||
List<ConversationItem> items = new ArrayList<>();
|
||||
for (PrivateMessageHeader h : headers) {
|
||||
ConversationMessageItem item =
|
||||
(ConversationMessageItem) ConversationItem
|
||||
@@ -350,6 +364,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void loadMessageBody(final PrivateMessageHeader h) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -370,6 +385,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void displayMessageBody(final MessageId m, final byte[] body) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bodyCache.put(m, body);
|
||||
SparseArray<ConversationMessageItem> messages =
|
||||
@@ -399,9 +415,8 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void markMessagesRead() {
|
||||
List<MessageId> unread = new ArrayList<MessageId>();
|
||||
SparseArray<IncomingItem> list =
|
||||
adapter.getIncomingMessages();
|
||||
List<MessageId> unread = new ArrayList<>();
|
||||
SparseArray<IncomingItem> list = adapter.getIncomingMessages();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
IncomingItem item = list.valueAt(i);
|
||||
if (!item.isRead()) unread.add(item.getId());
|
||||
@@ -414,6 +429,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void markMessagesRead(final Collection<MessageId> unread) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -432,6 +448,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
||||
@@ -501,6 +518,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void markMessageReadIfNew(final Message m) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ConversationItem item = adapter.getLastItem();
|
||||
if (item != null) {
|
||||
@@ -519,6 +537,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void markNewMessageRead(final Message m) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
messagingManager.setReadFlag(m.getId(), true);
|
||||
@@ -534,10 +553,10 @@ public class ConversationActivity extends BriarActivity
|
||||
private void markMessages(final Collection<MessageId> messageIds,
|
||||
final boolean sent, final boolean seen) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Set<MessageId> messages = new HashSet<MessageId>(messageIds);
|
||||
SparseArray<OutgoingItem> list =
|
||||
adapter.getOutgoingMessages();
|
||||
Set<MessageId> messages = new HashSet<>(messageIds);
|
||||
SparseArray<OutgoingItem> list = adapter.getOutgoingMessages();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
OutgoingItem item = list.valueAt(i);
|
||||
if (messages.contains(item.getId())) {
|
||||
@@ -550,6 +569,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
markMessagesRead();
|
||||
String message = content.getText().toString();
|
||||
@@ -569,6 +589,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void createMessage(final byte[] body, final long timestamp) {
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
storeMessage(privateMessageFactory.createPrivateMessage(
|
||||
@@ -582,6 +603,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void storeMessage(final PrivateMessage m) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -617,6 +639,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void removeContact() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// make sure contactId is initialised
|
||||
@@ -648,6 +671,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void hideIntroductionActionWhenOneContact(final MenuItem item) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (contactManager.getActiveContacts().size() < 2) {
|
||||
@@ -689,11 +713,7 @@ public class ConversationActivity extends BriarActivity
|
||||
timestamp);
|
||||
}
|
||||
loadMessages();
|
||||
} catch (DbException e) {
|
||||
introductionResponseError();
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch (FormatException e) {
|
||||
} catch (DbException | FormatException e) {
|
||||
introductionResponseError();
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
@@ -41,6 +41,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private final SortedList<ConversationItem> items =
|
||||
new SortedList<>(ConversationItem.class, new ListCallbacks());
|
||||
|
||||
private Context ctx;
|
||||
private IntroductionHandler intro;
|
||||
private String contactName;
|
||||
@@ -67,44 +68,38 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
// outgoing message (local)
|
||||
if (type == MSG_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_msg_out, viewGroup, false);
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_msg_out, viewGroup, false);
|
||||
return new MessageHolder(v, type);
|
||||
}
|
||||
else if (type == INTRODUCTION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_introduction_in, viewGroup, false);
|
||||
} else if (type == INTRODUCTION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_introduction_in, viewGroup, false);
|
||||
return new IntroductionHolder(v, type);
|
||||
}
|
||||
else if (type == INTRODUCTION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_introduction_out, viewGroup, false);
|
||||
} else if (type == INTRODUCTION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_introduction_out, viewGroup, false);
|
||||
return new IntroductionHolder(v, type);
|
||||
}
|
||||
else if (type == NOTICE_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_notice_in, viewGroup, false);
|
||||
} else if (type == NOTICE_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_notice_in, viewGroup, false);
|
||||
return new NoticeHolder(v, type);
|
||||
}
|
||||
else if (type == NOTICE_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_notice_out, viewGroup, false);
|
||||
} else if (type == NOTICE_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_notice_out, viewGroup, false);
|
||||
return new NoticeHolder(v, type);
|
||||
}
|
||||
else if (type == FORUM_INVITATION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_forum_invitation_in, viewGroup, false);
|
||||
} else if (type == FORUM_INVITATION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_forum_invitation_in, viewGroup, false);
|
||||
return new InvitationHolder(v, type);
|
||||
}
|
||||
else if (type == FORUM_INVITATION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_forum_invitation_out, viewGroup, false);
|
||||
} else if (type == FORUM_INVITATION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_forum_invitation_out, viewGroup, false);
|
||||
return new InvitationHolder(v, type);
|
||||
}
|
||||
// incoming message (non-local)
|
||||
else {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_msg_in, viewGroup, false);
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_msg_in, viewGroup, false);
|
||||
return new MessageHolder(v, type);
|
||||
}
|
||||
}
|
||||
@@ -126,10 +121,10 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item);
|
||||
} else if (item instanceof ConversationForumInvitationOutItem) {
|
||||
bindInvitation((InvitationHolder) ui,
|
||||
(ConversationForumInvitationOutItem) item, position);
|
||||
(ConversationForumInvitationOutItem) item);
|
||||
} else if (item instanceof ConversationForumInvitationInItem) {
|
||||
bindInvitation((InvitationHolder) ui,
|
||||
(ConversationForumInvitationInItem) item, position);
|
||||
(ConversationForumInvitationInItem) item);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled Conversation Item");
|
||||
}
|
||||
@@ -200,13 +195,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
(ConversationIntroductionOutItem) item;
|
||||
if (i.isSeen()) {
|
||||
ui.status.setImageResource(R.drawable.message_delivered);
|
||||
ui.message.status.setImageResource(R.drawable.message_delivered_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_delivered_white);
|
||||
} else if (i.isSent()) {
|
||||
ui.status.setImageResource(R.drawable.message_sent);
|
||||
ui.message.status.setImageResource(R.drawable.message_sent_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_sent_white);
|
||||
} else {
|
||||
ui.status.setImageResource(R.drawable.message_stored);
|
||||
ui.message.status.setImageResource(R.drawable.message_stored_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_stored_white);
|
||||
}
|
||||
}
|
||||
// Incoming Introduction Request (Answered)
|
||||
@@ -279,7 +277,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
private void bindInvitation(InvitationHolder ui,
|
||||
final ConversationForumInvitationItem item, final int position) {
|
||||
final ConversationForumInvitationItem item) {
|
||||
|
||||
ForumInvitationMessage fim = item.getForumInvitationMessage();
|
||||
|
||||
@@ -301,13 +299,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
(ConversationForumInvitationOutItem) item;
|
||||
if (i.isSeen()) {
|
||||
ui.status.setImageResource(R.drawable.message_delivered);
|
||||
ui.message.status.setImageResource(R.drawable.message_delivered_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_delivered_white);
|
||||
} else if (i.isSent()) {
|
||||
ui.status.setImageResource(R.drawable.message_sent);
|
||||
ui.message.status.setImageResource(R.drawable.message_sent_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_sent_white);
|
||||
} else {
|
||||
ui.status.setImageResource(R.drawable.message_stored);
|
||||
ui.message.status.setImageResource(R.drawable.message_stored_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_stored_white);
|
||||
}
|
||||
}
|
||||
// Incoming Invitation
|
||||
@@ -321,9 +322,8 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent =
|
||||
new Intent(ctx,
|
||||
AvailableForumsActivity.class);
|
||||
Intent intent = new Intent(ctx,
|
||||
AvailableForumsActivity.class);
|
||||
ctx.startActivity(intent);
|
||||
}
|
||||
});
|
||||
@@ -380,7 +380,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
public SparseArray<ConversationMessageItem> getPrivateMessages() {
|
||||
SparseArray<ConversationMessageItem> messages = new SparseArray<>();
|
||||
SparseArray<ConversationMessageItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ConversationItem item = items.get(i);
|
||||
@@ -426,19 +426,17 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static class IntroductionHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final private ViewGroup layout;
|
||||
final private View messageLayout;
|
||||
final private MessageHolder message;
|
||||
final private TextView text;
|
||||
final private Button acceptButton;
|
||||
final private Button declineButton;
|
||||
final private TextView date;
|
||||
final private ImageView status;
|
||||
private final View messageLayout;
|
||||
private final MessageHolder message;
|
||||
private final TextView text;
|
||||
private final Button acceptButton;
|
||||
private final Button declineButton;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public IntroductionHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.introductionLayout);
|
||||
messageLayout = v.findViewById(R.id.messageLayout);
|
||||
message = new MessageHolder(messageLayout,
|
||||
type == INTRODUCTION_IN ? MSG_IN : MSG_OUT);
|
||||
@@ -457,15 +455,13 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static class NoticeHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final private ViewGroup layout;
|
||||
final private TextView text;
|
||||
final private TextView date;
|
||||
final private ImageView status;
|
||||
private final TextView text;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public NoticeHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.noticeLayout);
|
||||
text = (TextView) v.findViewById(R.id.noticeText);
|
||||
date = (TextView) v.findViewById(R.id.noticeTime);
|
||||
|
||||
@@ -479,18 +475,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static class InvitationHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final private ViewGroup layout;
|
||||
final private View messageLayout;
|
||||
final private MessageHolder message;
|
||||
final private TextView text;
|
||||
final private Button showForumsButton;
|
||||
final private TextView date;
|
||||
final private ImageView status;
|
||||
private final View messageLayout;
|
||||
private final MessageHolder message;
|
||||
private final TextView text;
|
||||
private final Button showForumsButton;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public InvitationHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.introductionLayout);
|
||||
messageLayout = v.findViewById(R.id.messageLayout);
|
||||
message = new MessageHolder(messageLayout,
|
||||
type == FORUM_INVITATION_IN ? MSG_IN : MSG_OUT);
|
||||
@@ -507,6 +501,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
private class ListCallbacks extends SortedList.Callback<ConversationItem> {
|
||||
|
||||
@Override
|
||||
public void onInserted(int position, int count) {
|
||||
notifyItemRangeInserted(position, count);
|
||||
@@ -551,8 +546,6 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
public interface IntroductionHandler {
|
||||
void respondToIntroduction(final SessionId sessionId,
|
||||
final boolean accept);
|
||||
void respondToIntroduction(SessionId sessionId, boolean accept);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,5 +29,4 @@ public class ConversationForumInvitationInItem
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
|
||||
abstract class ConversationForumInvitationItem extends ConversationItem {
|
||||
|
||||
private ForumInvitationMessage fim;
|
||||
private final ForumInvitationMessage fim;
|
||||
|
||||
public ConversationForumInvitationItem(ForumInvitationMessage fim) {
|
||||
super(fim.getId(), fim.getTimestamp());
|
||||
@@ -15,5 +15,4 @@ abstract class ConversationForumInvitationItem extends ConversationItem {
|
||||
public ForumInvitationMessage getForumInvitationMessage() {
|
||||
return fim;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
* This class is needed and can not be replaced by an ConversationNoticeOutItem,
|
||||
* because it carries the optional invitation message
|
||||
* to be displayed as a regular private message.
|
||||
*
|
||||
* <p/>
|
||||
* This class is not thread-safe
|
||||
*/
|
||||
public class ConversationForumInvitationOutItem
|
||||
@@ -45,5 +45,4 @@ public class ConversationForumInvitationOutItem
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationIntroductionInItem extends ConversationIntroductionItem
|
||||
@@ -29,5 +28,4 @@ public class ConversationIntroductionInItem extends ConversationIntroductionItem
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
|
||||
// This class is not thread-safe
|
||||
abstract class ConversationIntroductionItem extends ConversationItem {
|
||||
|
||||
private IntroductionRequest ir;
|
||||
private final IntroductionRequest ir;
|
||||
private boolean answered;
|
||||
|
||||
public ConversationIntroductionItem(IntroductionRequest ir) {
|
||||
@@ -25,5 +26,4 @@ abstract class ConversationIntroductionItem extends ConversationItem {
|
||||
public void setAnswered(boolean answered) {
|
||||
this.answered = answered;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,5 +45,4 @@ public class ConversationIntroductionOutItem
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,8 +103,9 @@ public abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
/** This method should not be used to get user-facing objects,
|
||||
* Its purpose is to provider data for the contact list.
|
||||
/**
|
||||
* This method should not be used to get user-facing objects,
|
||||
* Its purpose is to provider data for the contact list.
|
||||
*/
|
||||
public static ConversationItem from(IntroductionMessage im) {
|
||||
if (im.isLocal())
|
||||
@@ -115,17 +116,24 @@ public abstract class ConversationItem {
|
||||
}
|
||||
|
||||
protected interface OutgoingItem {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
boolean isSent();
|
||||
|
||||
void setSent(boolean sent);
|
||||
|
||||
boolean isSeen();
|
||||
|
||||
void setSeen(boolean seen);
|
||||
}
|
||||
|
||||
protected interface IncomingItem {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
boolean isRead();
|
||||
|
||||
void setRead(boolean read);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,5 +28,4 @@ public class ConversationMessageInItem extends ConversationMessageItem
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,5 +26,4 @@ abstract class ConversationMessageItem extends ConversationItem {
|
||||
void setBody(byte[] body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,5 +39,4 @@ public class ConversationMessageOutItem extends ConversationMessageItem
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.briarproject.android.contact;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationNoticeInItem extends ConversationNoticeItem implements
|
||||
ConversationItem.IncomingItem {
|
||||
public class ConversationNoticeInItem extends ConversationNoticeItem
|
||||
implements ConversationItem.IncomingItem {
|
||||
|
||||
private boolean read;
|
||||
|
||||
@@ -29,5 +29,4 @@ public class ConversationNoticeInItem extends ConversationNoticeItem implements
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.briarproject.api.sync.MessageId;
|
||||
|
||||
abstract class ConversationNoticeItem extends ConversationItem {
|
||||
|
||||
private String text;
|
||||
private final String text;
|
||||
|
||||
public ConversationNoticeItem(MessageId id, String text, long time) {
|
||||
super(id, time);
|
||||
@@ -15,5 +15,4 @@ abstract class ConversationNoticeItem extends ConversationItem {
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@ package org.briarproject.android.contact;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationNoticeOutItem extends ConversationNoticeItem implements
|
||||
ConversationItem.OutgoingItem {
|
||||
public class ConversationNoticeOutItem extends ConversationNoticeItem
|
||||
implements ConversationItem.OutgoingItem {
|
||||
|
||||
private boolean sent, seen;
|
||||
|
||||
public ConversationNoticeOutItem(MessageId id, String text, long time,
|
||||
boolean sent, boolean seen) {
|
||||
|
||||
super(id, text, time);
|
||||
|
||||
this.sent = sent;
|
||||
@@ -41,5 +40,4 @@ public class ConversationNoticeOutItem extends ConversationNoticeItem implements
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
|
||||
public interface BriarController extends ActivityLifecycleController {
|
||||
|
||||
void runOnDbThread(final Runnable task);
|
||||
|
||||
void startAndBindService();
|
||||
|
||||
@@ -26,14 +26,15 @@ public class BriarControllerImpl implements BriarController {
|
||||
protected BriarServiceConnection serviceConnection;
|
||||
@Inject
|
||||
protected DatabaseConfig databaseConfig;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@DatabaseExecutor
|
||||
protected volatile Executor dbExecutor;
|
||||
@Inject
|
||||
protected volatile LifecycleManager lifecycleManager;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
|
||||
private boolean bound = false;
|
||||
|
||||
@@ -64,6 +65,7 @@ public class BriarControllerImpl implements BriarController {
|
||||
unbindService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAndBindService() {
|
||||
activity.startService(new Intent(activity, BriarService.class));
|
||||
bound = activity.bindService(new Intent(activity, BriarService.class),
|
||||
@@ -83,7 +85,8 @@ public class BriarControllerImpl implements BriarController {
|
||||
try {
|
||||
// Wait for the service to finish starting up
|
||||
IBinder binder = serviceConnection.waitForBinder();
|
||||
BriarService service = ((BriarService.BriarBinder) binder).getService();
|
||||
BriarService service =
|
||||
((BriarService.BriarBinder) binder).getService();
|
||||
service.waitForStartup();
|
||||
// Shut down the service and wait for it to shut down
|
||||
LOG.info("Shutting down service");
|
||||
@@ -101,8 +104,10 @@ public class BriarControllerImpl implements BriarController {
|
||||
if (bound) activity.unbindService(serviceConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnDbThread(final Runnable task) {
|
||||
dbExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
@@ -114,5 +119,4 @@ public class BriarControllerImpl implements BriarController {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public interface ConfigController {
|
||||
|
||||
String getEncryptedDatabaseKey();
|
||||
|
||||
void clearPrefs();
|
||||
void deleteAccount(Context ctx);
|
||||
|
||||
boolean initialized();
|
||||
boolean accountExists();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ConfigControllerImpl implements ConfigController {
|
||||
|
||||
private final static String PREF_DB_KEY = "key";
|
||||
private static final String PREF_DB_KEY = "key";
|
||||
|
||||
@Inject
|
||||
protected SharedPreferences briarPrefs;
|
||||
@@ -20,22 +22,22 @@ public class ConfigControllerImpl implements ConfigController {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncryptedDatabaseKey() {
|
||||
return briarPrefs.getString(PREF_DB_KEY, null);
|
||||
}
|
||||
|
||||
public void clearPrefs() {
|
||||
@Override
|
||||
public void deleteAccount(Context ctx) {
|
||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||
editor.clear();
|
||||
editor.apply();
|
||||
AndroidUtils.deleteAppData(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
public boolean accountExists() {
|
||||
String hex = getEncryptedDatabaseKey();
|
||||
if (hex != null && databaseConfig.databaseExists()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return hex != null && databaseConfig.databaseExists();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
|
||||
public interface NavDrawerController extends BriarController {
|
||||
|
||||
void setTransportListener(TransportStateListener transportListener);
|
||||
|
||||
boolean isTransportRunning(TransportId transportId);
|
||||
|
||||
@@ -16,8 +16,6 @@ import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -34,15 +32,15 @@ public class NavDrawerControllerImpl extends BriarControllerImpl
|
||||
@Inject
|
||||
protected ReferenceManager referenceManager;
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
@Inject
|
||||
protected PluginManager pluginManager;
|
||||
@Inject
|
||||
protected EventBus eventBus;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
|
||||
private List<Plugin> transports = new ArrayList<Plugin>();
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
private TransportStateListener transportStateListener;
|
||||
|
||||
@@ -112,6 +110,7 @@ public class NavDrawerControllerImpl extends BriarControllerImpl
|
||||
public void storeLocalAuthor(final LocalAuthor author,
|
||||
final UiResultHandler<Void> resultHandler) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -130,7 +129,6 @@ public class NavDrawerControllerImpl extends BriarControllerImpl
|
||||
|
||||
@Override
|
||||
public LocalAuthor removeAuthorHandle(long handle) {
|
||||
return referenceManager.removeReference(handle,
|
||||
LocalAuthor.class);
|
||||
return referenceManager.removeReference(handle, LocalAuthor.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android.controller;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
|
||||
public interface PasswordController extends ConfigController {
|
||||
|
||||
void validatePassword(String password,
|
||||
ResultHandler<Boolean> resultHandler);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
final ResultHandler<Boolean> resultHandler) {
|
||||
final byte[] encrypted = getEncryptedKey();
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] key = crypto.decryptWithPassword(encrypted, password);
|
||||
if (key == null) {
|
||||
@@ -48,7 +49,7 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
private byte[] getEncryptedKey() {
|
||||
String hex = getEncryptedDatabaseKey();
|
||||
if (hex == null)
|
||||
throw new IllegalStateException("Encrypted database key is null.");
|
||||
throw new IllegalStateException("Encrypted database key is null");
|
||||
return StringUtils.fromHexString(hex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android.controller;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
|
||||
public interface SetupController {
|
||||
|
||||
float estimatePasswordStrength(String password);
|
||||
|
||||
void createIdentity(String nickname, String password,
|
||||
|
||||
@@ -34,6 +34,10 @@ public class SetupControllerImpl implements SetupController {
|
||||
protected Executor cryptoExecutor;
|
||||
@Inject
|
||||
protected PasswordStrengthEstimator strengthEstimator;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
@Inject
|
||||
protected SharedPreferences briarPrefs;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@@ -44,10 +48,6 @@ public class SetupControllerImpl implements SetupController {
|
||||
protected volatile AuthorFactory authorFactory;
|
||||
@Inject
|
||||
protected volatile ReferenceManager referenceManager;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
@Inject
|
||||
protected SharedPreferences briarPrefs;
|
||||
|
||||
@Inject
|
||||
public SetupControllerImpl() {
|
||||
@@ -85,6 +85,7 @@ public class SetupControllerImpl implements SetupController {
|
||||
public void createIdentity(final String nickname, final String password,
|
||||
final ResultHandler<Long> resultHandler) {
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SecretKey key = crypto.generateSecretKey();
|
||||
databaseConfig.setEncryptionKey(key);
|
||||
@@ -98,10 +99,9 @@ public class SetupControllerImpl implements SetupController {
|
||||
});
|
||||
}
|
||||
|
||||
private void storeEncryptedDatabaseKey(final String hex) {
|
||||
private void storeEncryptedDatabaseKey(String hex) {
|
||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||
editor.putString(PREF_DB_KEY, hex);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ package org.briarproject.android.controller;
|
||||
import org.briarproject.api.TransportId;
|
||||
|
||||
public interface TransportStateListener {
|
||||
|
||||
void stateUpdate(TransportId id, boolean enabled);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
public interface ResultExceptionHandler<R, E extends Exception> {
|
||||
|
||||
void onResult(R result);
|
||||
|
||||
void onException(E exception);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
public interface ResultHandler<R> {
|
||||
|
||||
void onResult(R result);
|
||||
}
|
||||
|
||||
@@ -11,16 +11,20 @@ public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onExceptionUi(exception);
|
||||
}
|
||||
|
||||
@@ -10,8 +10,10 @@ public abstract class UiResultHandler<R> implements ResultHandler<R> {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onResultUi(result);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ 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;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
@@ -44,9 +43,12 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
private AvailableForumsAdapter adapter;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile ForumManager forumManager;
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject protected volatile EventBus eventBus;
|
||||
@Inject
|
||||
protected volatile ForumManager forumManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -75,6 +77,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
|
||||
private void loadForums() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Collection<ForumContacts> available = new ArrayList<>();
|
||||
@@ -102,6 +105,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
|
||||
private void displayForums(final Collection<ForumContacts> available) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (available.isEmpty()) {
|
||||
LOG.info("No forums available, finishing");
|
||||
@@ -124,6 +128,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
LOG.info("Contact removed, reloading");
|
||||
@@ -146,6 +151,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AvailableForumsItem item, boolean accept) {
|
||||
respondToInvitation(item.getForum(), accept);
|
||||
|
||||
@@ -157,6 +163,7 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
|
||||
private void respondToInvitation(final Forum f, final boolean accept) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
forumSharingManager.respondToInvitation(f, accept);
|
||||
@@ -168,5 +175,4 @@ public class AvailableForumsActivity extends BriarActivity
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ class AvailableForumsAdapter extends
|
||||
new SortedList<>(AvailableForumsItem.class,
|
||||
new SortedListCallBacks());
|
||||
|
||||
AvailableForumsAdapter(Context ctx,
|
||||
AvailableForumClickListener listener) {
|
||||
|
||||
AvailableForumsAdapter(Context ctx, AvailableForumClickListener listener) {
|
||||
this.ctx = ctx;
|
||||
this.listener = listener;
|
||||
}
|
||||
@@ -90,16 +88,14 @@ class AvailableForumsAdapter extends
|
||||
protected static class AvailableForumViewHolder
|
||||
extends RecyclerView.ViewHolder {
|
||||
|
||||
public final ViewGroup layout;
|
||||
public final TextView name;
|
||||
public final TextView sharedBy;
|
||||
public final Button accept;
|
||||
public final Button decline;
|
||||
private final TextView name;
|
||||
private final TextView sharedBy;
|
||||
private final Button accept;
|
||||
private final Button decline;
|
||||
|
||||
public AvailableForumViewHolder(View v) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v;
|
||||
name = (TextView) v.findViewById(R.id.forumNameView);
|
||||
sharedBy = (TextView) v.findViewById(R.id.sharedByView);
|
||||
accept = (Button) v.findViewById(R.id.acceptButton);
|
||||
@@ -156,5 +152,4 @@ class AvailableForumsAdapter extends
|
||||
interface AvailableForumClickListener {
|
||||
void onItemClick(AvailableForumsItem item, boolean accept);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class ContactSelectorAdapter
|
||||
extends
|
||||
BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> {
|
||||
extends BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> {
|
||||
|
||||
public ContactSelectorAdapter(Context context,
|
||||
OnItemClickListener listener) {
|
||||
@@ -32,19 +31,17 @@ public class ContactSelectorAdapter
|
||||
@Override
|
||||
public SelectableContactHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int i) {
|
||||
View v = LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.list_item_selectable_contact, viewGroup,
|
||||
false);
|
||||
View v = LayoutInflater.from(ctx).inflate(
|
||||
R.layout.list_item_selectable_contact, viewGroup, false);
|
||||
|
||||
return new SelectableContactHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final SelectableContactHolder ui,
|
||||
final int position) {
|
||||
public void onBindViewHolder(SelectableContactHolder ui, int position) {
|
||||
super.onBindViewHolder(ui, position);
|
||||
|
||||
final SelectableContactListItem item =
|
||||
SelectableContactListItem item =
|
||||
(SelectableContactListItem) getItem(position);
|
||||
|
||||
if (item.isSelected()) {
|
||||
@@ -90,7 +87,7 @@ public class ContactSelectorAdapter
|
||||
}
|
||||
|
||||
private void grayOutItem(final SelectableContactHolder ui) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
float alpha = 0.25f;
|
||||
ui.avatar.setAlpha(alpha);
|
||||
ui.name.setAlpha(alpha);
|
||||
@@ -103,5 +100,4 @@ public class ContactSelectorAdapter
|
||||
ui.checkBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,17 +44,17 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
BaseContactListAdapter.OnItemClickListener {
|
||||
|
||||
public final static String TAG = "ContactSelectorFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactSelectorFragment.class.getName());
|
||||
|
||||
private ShareForumActivity shareForumActivity;
|
||||
private Menu menu;
|
||||
private BriarRecyclerView list;
|
||||
private ContactSelectorAdapter adapter;
|
||||
private Collection<ContactId> selectedContacts;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactSelectorFragment.class.getName());
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
protected volatile GroupId groupId;
|
||||
@Inject
|
||||
protected volatile ContactManager contactManager;
|
||||
@Inject
|
||||
@@ -62,6 +62,8 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
protected volatile GroupId groupId;
|
||||
|
||||
public void initBundle(GroupId groupId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
@@ -97,11 +99,10 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View contentView =
|
||||
inflater.inflate(R.layout.introduction_contact_chooser,
|
||||
container, false);
|
||||
View contentView = inflater.inflate(
|
||||
R.layout.introduction_contact_chooser, container, false);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
setExitTransition(new Fade());
|
||||
}
|
||||
|
||||
@@ -116,7 +117,8 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
if (savedInstanceState != null) {
|
||||
ArrayList<Integer> intContacts =
|
||||
savedInstanceState.getIntegerArrayList(CONTACTS);
|
||||
selectedContacts = ShareForumActivity.getContactsFromIntegers(intContacts);
|
||||
selectedContacts = ShareForumActivity.getContactsFromIntegers(
|
||||
intContacts);
|
||||
}
|
||||
|
||||
return contentView;
|
||||
@@ -126,11 +128,9 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (selectedContacts != null) {
|
||||
if (selectedContacts != null)
|
||||
loadContacts(Collections.unmodifiableCollection(selectedContacts));
|
||||
} else {
|
||||
loadContacts(null);
|
||||
}
|
||||
else loadContacts(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,11 +182,11 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
|
||||
private void loadContacts(final Collection<ContactId> selection) {
|
||||
shareForumActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<>();
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
LocalAuthor localAuthor = identityManager
|
||||
@@ -197,9 +197,8 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
// do we have already some sharing with that contact?
|
||||
boolean disabled =
|
||||
!forumSharingManager.canBeShared(groupId, c);
|
||||
contacts.add(
|
||||
new SelectableContactListItem(c, localAuthor,
|
||||
groupId, selected, disabled));
|
||||
contacts.add(new SelectableContactListItem(c,
|
||||
localAuthor, groupId, selected, disabled));
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
@@ -216,12 +215,10 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
|
||||
private void displayContacts(final List<ContactListItem> contacts) {
|
||||
shareForumActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!contacts.isEmpty()) {
|
||||
adapter.addAll(contacts);
|
||||
} else {
|
||||
list.showData();
|
||||
}
|
||||
if (!contacts.isEmpty()) adapter.addAll(contacts);
|
||||
else list.showData();
|
||||
updateMenuItem();
|
||||
}
|
||||
});
|
||||
@@ -239,5 +236,4 @@ public class ContactSelectorFragment extends BaseFragment implements
|
||||
item.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ public class CreateForumActivity extends BriarActivity
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(CreateForumActivity.class.getName());
|
||||
|
||||
private EditText nameEntry = null;
|
||||
private Button createForumButton = null;
|
||||
private ProgressBar progress = null;
|
||||
private TextView feedback = null;
|
||||
private EditText nameEntry;
|
||||
private Button createForumButton;
|
||||
private ProgressBar progress;
|
||||
private TextView feedback;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@@ -95,6 +95,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
createForumButton.setEnabled(validateName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||
hideSoftKeyboard(textView);
|
||||
return true;
|
||||
@@ -111,6 +112,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
return length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view == createForumButton) {
|
||||
hideSoftKeyboard(view);
|
||||
@@ -123,6 +125,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
|
||||
private void storeForum(final String name) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -143,6 +146,7 @@ public class CreateForumActivity extends BriarActivity
|
||||
|
||||
private void displayForum(final Forum f) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent i = new Intent(CreateForumActivity.this,
|
||||
ForumActivity.class);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ForumListAdapter extends
|
||||
|
||||
private SortedList<ForumListItem> forums = new SortedList<>(
|
||||
ForumListItem.class, new SortedList.Callback<ForumListItem>() {
|
||||
|
||||
@Override
|
||||
public int compare(ForumListItem a, ForumListItem b) {
|
||||
if (a == b) return 0;
|
||||
@@ -71,6 +72,7 @@ public class ForumListAdapter extends
|
||||
return a.getForum().equals(b.getForum());
|
||||
}
|
||||
});
|
||||
|
||||
private final Context ctx;
|
||||
|
||||
public ForumListAdapter(Context ctx) {
|
||||
@@ -78,11 +80,9 @@ public class ForumListAdapter extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForumViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
|
||||
View v = LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.list_item_forum, parent, false);
|
||||
public ForumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(ctx).inflate(
|
||||
R.layout.list_item_forum, parent, false);
|
||||
return new ForumViewHolder(v);
|
||||
}
|
||||
|
||||
@@ -175,10 +175,10 @@ public class ForumListAdapter extends
|
||||
|
||||
protected static class ForumViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public final ViewGroup layout;
|
||||
public final TextView name;
|
||||
public final TextView unread;
|
||||
public final TextView date;
|
||||
private final ViewGroup layout;
|
||||
private final TextView name;
|
||||
private final TextView unread;
|
||||
private final TextView date;
|
||||
|
||||
public ForumViewHolder(View v) {
|
||||
super(v);
|
||||
@@ -189,5 +189,4 @@ public class ForumListAdapter extends
|
||||
date = (TextView) v.findViewById(R.id.dateView);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void loadForumHeaders() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// load forums
|
||||
@@ -162,6 +163,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void displayForumHeaders(final Collection<ForumListItem> forums) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (forums.size() > 0) adapter.addAll(forums);
|
||||
else list.showData();
|
||||
@@ -171,6 +173,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void loadAvailableForums() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -190,6 +193,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void displayAvailableForums(final int availableCount) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (availableCount == 0) {
|
||||
snackbar.dismiss();
|
||||
@@ -203,6 +207,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
LOG.info("Contact removed, reloading available forums");
|
||||
@@ -235,6 +240,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
|
||||
private void loadForumHeaders(final GroupId g) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -272,9 +278,9 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// snackbar click
|
||||
startActivity(new Intent(getContext(), AvailableForumsActivity.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ public class SelectableContactListItem extends ContactListItem {
|
||||
public SelectableContactListItem(Contact contact, LocalAuthor localAuthor,
|
||||
GroupId groupId, boolean selected, boolean disabled) {
|
||||
|
||||
super(contact, localAuthor, false, groupId, Collections.<ConversationItem>emptyList());
|
||||
super(contact, localAuthor, false, groupId,
|
||||
Collections.<ConversationItem>emptyList());
|
||||
|
||||
this.selected = selected;
|
||||
this.disabled = disabled;
|
||||
@@ -37,5 +38,4 @@ public class SelectableContactListItem extends ContactListItem {
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
@@ -25,6 +24,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.forum.ShareForumActivity.CONTACTS;
|
||||
import static org.briarproject.android.forum.ShareForumActivity.getContactsFromIds;
|
||||
@@ -32,15 +32,17 @@ import static org.briarproject.api.forum.ForumConstants.GROUP_ID;
|
||||
|
||||
public class ShareForumMessageFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = "IntroductionMessageFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ShareForumMessageFragment.class.getName());
|
||||
|
||||
public final static String TAG = "IntroductionMessageFragment";
|
||||
private ShareForumActivity shareForumActivity;
|
||||
private ViewHolder ui;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
private volatile GroupId groupId;
|
||||
private volatile Collection<ContactId> contacts;
|
||||
|
||||
@@ -81,9 +83,8 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// inflate view
|
||||
View v =
|
||||
inflater.inflate(R.layout.share_forum_message, container,
|
||||
false);
|
||||
View v = inflater.inflate(R.layout.share_forum_message, container,
|
||||
false);
|
||||
ui = new ViewHolder(v);
|
||||
ui.button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -131,11 +132,12 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
|
||||
private void shareForum(final String msg) {
|
||||
shareForumActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (ContactId c : contacts) {
|
||||
forumSharingManager
|
||||
.sendForumInvitation(groupId, c, msg);
|
||||
forumSharingManager.sendForumInvitation(groupId, c,
|
||||
msg);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
sharingError();
|
||||
@@ -148,21 +150,20 @@ public class ShareForumMessageFragment extends BaseFragment {
|
||||
|
||||
private void sharingError() {
|
||||
shareForumActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(shareForumActivity,
|
||||
R.string.introduction_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
R.string.introduction_error, LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
final private TextView text;
|
||||
final private EditText message;
|
||||
final private Button button;
|
||||
|
||||
private final EditText message;
|
||||
private final Button button;
|
||||
|
||||
ViewHolder(View v) {
|
||||
text = (TextView) v.findViewById(R.id.introductionText);
|
||||
message = (EditText) v.findViewById(R.id.invitationMessageView);
|
||||
button = (Button) v.findViewById(R.id.shareForumButton);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import android.support.v4.app.Fragment;
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
|
||||
public abstract String getUniqueTag();
|
||||
|
||||
protected BaseFragmentListener listener;
|
||||
|
||||
public abstract String getUniqueTag();
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -27,6 +27,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
}
|
||||
|
||||
public interface BaseFragmentListener {
|
||||
|
||||
void showLoadingScreen(boolean isBlocking, int stringId);
|
||||
|
||||
void hideLoadingScreen();
|
||||
@@ -35,5 +36,4 @@ public abstract class BaseFragment extends Fragment {
|
||||
|
||||
void runOnDbThread(Runnable runnable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ 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.LayoutUtils;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
@@ -47,21 +46,27 @@ import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
public class CreateIdentityActivity extends BriarActivity
|
||||
implements OnEditorActionListener, OnClickListener {
|
||||
implements OnEditorActionListener, OnClickListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(CreateIdentityActivity.class.getName());
|
||||
|
||||
@Inject @CryptoExecutor protected Executor cryptoExecutor;
|
||||
private EditText nicknameEntry = null;
|
||||
private Button createIdentityButton = null;
|
||||
private ProgressBar progress = null;
|
||||
private TextView feedback = null;
|
||||
@Inject
|
||||
@CryptoExecutor
|
||||
protected Executor cryptoExecutor;
|
||||
|
||||
private EditText nicknameEntry;
|
||||
private Button createIdentityButton;
|
||||
private ProgressBar progress;
|
||||
private TextView feedback;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile CryptoComponent crypto;
|
||||
@Inject protected volatile AuthorFactory authorFactory;
|
||||
@Inject protected volatile IdentityManager identityManager;
|
||||
@Inject
|
||||
protected volatile CryptoComponent crypto;
|
||||
@Inject
|
||||
protected volatile AuthorFactory authorFactory;
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -124,6 +129,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
createIdentityButton.setEnabled(validateNickname());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||
hideSoftKeyboard(textView);
|
||||
return true;
|
||||
@@ -140,6 +146,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
return length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
hideSoftKeyboard(view);
|
||||
if (!validateNickname()) return;
|
||||
@@ -149,6 +156,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
// Create the identity in a background thread
|
||||
final String nickname = nicknameEntry.getText().toString();
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
final byte[] publicKey = keyPair.getPublic().getEncoded();
|
||||
@@ -162,6 +170,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
|
||||
private void storeLocalAuthor(final LocalAuthor a) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -180,6 +189,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
|
||||
private void setResultAndFinish(final LocalAuthor a) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.LOCAL_AUTHOR_ID", a.getId().getBytes());
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ContactChooserAdapter extends ContactListAdapter {
|
||||
}
|
||||
|
||||
private void grayOutItem(final ContactHolder ui) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
float alpha = 0.25f;
|
||||
ui.bulb.setAlpha(alpha);
|
||||
ui.avatar.setAlpha(alpha);
|
||||
|
||||
@@ -44,14 +44,15 @@ import static java.util.logging.Level.WARNING;
|
||||
public class ContactChooserFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = "ContactChooserFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactChooserFragment.class.getName());
|
||||
|
||||
private IntroductionActivity introductionActivity;
|
||||
private BriarRecyclerView list;
|
||||
private ContactChooserAdapter adapter;
|
||||
private int contactId;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactChooserFragment.class.getName());
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
protected volatile Contact c1;
|
||||
@Inject
|
||||
@@ -76,7 +77,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
try {
|
||||
introductionActivity = (IntroductionActivity) context;
|
||||
} catch (ClassCastException e) {
|
||||
throw new java.lang.InstantiationError(
|
||||
throw new InstantiationError(
|
||||
"This fragment is only meant to be attached to the IntroductionActivity");
|
||||
}
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
container, false);
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
setExitTransition(new Fade());
|
||||
}
|
||||
|
||||
@@ -99,14 +100,15 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onItemClick(View view, ContactListItem item) {
|
||||
if (c1 == null) {
|
||||
throw new RuntimeException("c1 not initialized");
|
||||
throw new RuntimeException("c1 not accountExists");
|
||||
}
|
||||
Contact c2 = item.getContact();
|
||||
if (!c1.getLocalAuthorId()
|
||||
.equals(c2.getLocalAuthorId())) {
|
||||
warnAboutDifferentIdentities(view, c1, c2);
|
||||
} else {
|
||||
introductionActivity.showMessageScreen(view, c1, c2);
|
||||
introductionActivity.showMessageScreen(view, c1,
|
||||
c2);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -142,11 +144,11 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
|
||||
private void loadContacts() {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<ContactListItem>();
|
||||
AuthorId localAuthorId= null;
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
AuthorId localAuthorId = null;
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
if (c.getId().getInt() == contactId) {
|
||||
c1 = c;
|
||||
@@ -177,6 +179,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
private void displayContacts(final AuthorId localAuthorId,
|
||||
final List<ContactListItem> contacts) {
|
||||
introductionActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.setLocalAuthor(localAuthorId);
|
||||
if (contacts.size() == 0) list.showData();
|
||||
@@ -206,14 +209,15 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
builder.show();
|
||||
}
|
||||
|
||||
/** This needs to be called from the DbThread */
|
||||
/**
|
||||
* This needs to be called from the DbThread
|
||||
*/
|
||||
private Collection<ConversationItem> getMessages(ContactId id)
|
||||
throws DbException {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Collection<ConversationItem> messages =
|
||||
new ArrayList<ConversationItem>();
|
||||
Collection<ConversationItem> messages = new ArrayList<>();
|
||||
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessageHeaders(id);
|
||||
@@ -237,5 +241,4 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.android.introduction;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.transition.ChangeBounds;
|
||||
import android.transition.Fade;
|
||||
@@ -20,6 +19,7 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
BaseFragment.BaseFragmentListener {
|
||||
|
||||
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
||||
|
||||
private int contactId;
|
||||
|
||||
@Override
|
||||
@@ -34,7 +34,8 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
setContentView(R.layout.activity_introduction);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.introductionContainer,
|
||||
activityComponent.newContactChooserFragment())
|
||||
.commit();
|
||||
@@ -82,21 +83,21 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public void showMessageScreen(final View view, final Contact c1,
|
||||
final Contact c2) {
|
||||
public void showMessageScreen(View view, Contact c1, Contact c2) {
|
||||
|
||||
IntroductionMessageFragment messageFragment =
|
||||
activityComponent.newIntroductionMessageFragment();
|
||||
messageFragment.initBundle(c1.getId().getInt(), c2.getId().getInt());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
messageFragment.setSharedElementEnterTransition(new ChangeBounds());
|
||||
messageFragment.setEnterTransition(new Fade());
|
||||
messageFragment
|
||||
.setSharedElementReturnTransition(new ChangeBounds());
|
||||
messageFragment.setSharedElementReturnTransition(
|
||||
new ChangeBounds());
|
||||
}
|
||||
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.setCustomAnimations(android.R.anim.fade_in,
|
||||
android.R.anim.fade_out,
|
||||
android.R.anim.slide_in_left,
|
||||
@@ -107,5 +108,4 @@ public class IntroductionActivity extends BriarActivity implements
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,19 +28,22 @@ import javax.inject.Inject;
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class IntroductionMessageFragment extends BaseFragment {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(IntroductionMessageFragment.class.getName());
|
||||
|
||||
public final static String TAG = "IntroductionMessageFragment";
|
||||
private IntroductionActivity introductionActivity;
|
||||
private ViewHolder ui;
|
||||
|
||||
private final static String CONTACT_ID_1 = "contact1";
|
||||
private final static String CONTACT_ID_2 = "contact2";
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(IntroductionMessageFragment.class.getName());
|
||||
|
||||
private IntroductionActivity introductionActivity;
|
||||
private ViewHolder ui;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@@ -83,13 +86,12 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
// inflate view
|
||||
View v =
|
||||
inflater.inflate(R.layout.introduction_message, container,
|
||||
false);
|
||||
View v = inflater.inflate(R.layout.introduction_message, container,
|
||||
false);
|
||||
|
||||
// show progress bar until contacts have been loaded
|
||||
ui = new ViewHolder(v);
|
||||
ui.text.setVisibility(View.GONE);
|
||||
ui.text.setVisibility(GONE);
|
||||
ui.button.setEnabled(false);
|
||||
|
||||
// get contact IDs from fragment arguments
|
||||
@@ -114,12 +116,13 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
private void prepareToSetUpViews(final int contactId1,
|
||||
final int contactId2) {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Contact c1 = contactManager
|
||||
.getContact(new ContactId(contactId1));
|
||||
Contact c2 = contactManager
|
||||
.getContact(new ContactId(contactId2));
|
||||
Contact c1 = contactManager.getContact(
|
||||
new ContactId(contactId1));
|
||||
Contact c2 = contactManager.getContact(
|
||||
new ContactId(contactId2));
|
||||
setUpViews(c1, c2);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
@@ -131,6 +134,7 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
|
||||
private void setUpViews(final Contact c1, final Contact c2) {
|
||||
introductionActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// set avatars
|
||||
ui.avatar1.setImageDrawable(new IdenticonDrawable(
|
||||
@@ -152,8 +156,8 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
});
|
||||
|
||||
// hide progress bar and show views
|
||||
ui.progressBar.setVisibility(View.GONE);
|
||||
ui.text.setVisibility(View.VISIBLE);
|
||||
ui.progressBar.setVisibility(GONE);
|
||||
ui.text.setVisibility(VISIBLE);
|
||||
ui.button.setEnabled(true);
|
||||
}
|
||||
});
|
||||
@@ -174,17 +178,14 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
private void makeIntroduction(final Contact c1, final Contact c2,
|
||||
final String msg) {
|
||||
introductionActivity.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// actually make the introduction
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
introductionManager
|
||||
.makeIntroduction(c1, c2, msg, timestamp);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
introductionError();
|
||||
} catch (FormatException e) {
|
||||
introductionManager.makeIntroduction(c1, c2, msg,
|
||||
timestamp);
|
||||
} catch (DbException | FormatException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
introductionError();
|
||||
@@ -195,26 +196,24 @@ public class IntroductionMessageFragment extends BaseFragment {
|
||||
|
||||
private void introductionError() {
|
||||
introductionActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(introductionActivity,
|
||||
R.string.introduction_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
R.string.introduction_error, LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
ProgressBar progressBar;
|
||||
ViewGroup header;
|
||||
CircleImageView avatar1;
|
||||
CircleImageView avatar2;
|
||||
TextView text;
|
||||
EditText message;
|
||||
Button button;
|
||||
|
||||
private final ProgressBar progressBar;
|
||||
private final CircleImageView avatar1, avatar2;
|
||||
private final TextView text;
|
||||
private final EditText message;
|
||||
private final Button button;
|
||||
|
||||
ViewHolder(View v) {
|
||||
progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
|
||||
header = (ViewGroup) v.findViewById(R.id.introductionHeader);
|
||||
avatar1 = (CircleImageView) v.findViewById(R.id.avatarContact1);
|
||||
avatar2 = (CircleImageView) v.findViewById(R.id.avatarContact2);
|
||||
text = (TextView) v.findViewById(R.id.introductionText);
|
||||
|
||||
@@ -13,8 +13,6 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.identity.CreateIdentityActivity;
|
||||
import org.briarproject.android.identity.LocalAuthorItem;
|
||||
@@ -42,18 +40,17 @@ public class ChooseIdentityFragment extends BaseFragment
|
||||
void identitySelected(AuthorId localAuthorId);
|
||||
}
|
||||
|
||||
public static final String TAG = "ChooseIdentityFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ChooseIdentityFragment.class.getName());
|
||||
|
||||
public static final String TAG = "ChooseIdentityFragment";
|
||||
|
||||
private static final int REQUEST_CREATE_IDENTITY = 1;
|
||||
|
||||
private IdentitySelectedListener lsnr;
|
||||
private LocalAuthorSpinnerAdapter adapter;
|
||||
private Spinner spinner;
|
||||
private View button;
|
||||
|
||||
private AuthorId localAuthorId;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@@ -112,6 +109,7 @@ public class ChooseIdentityFragment extends BaseFragment
|
||||
|
||||
private void loadLocalAuthors() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -157,6 +155,7 @@ public class ChooseIdentityFragment extends BaseFragment
|
||||
button.setEnabled(localAuthorId != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
LocalAuthorItem item = adapter.getItem(position);
|
||||
@@ -169,6 +168,7 @@ public class ChooseIdentityFragment extends BaseFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
setLocalAuthorId(null);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.BriarFragmentActivity;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.util.CustomAnimations;
|
||||
@@ -24,7 +23,6 @@ import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.keyagreement.KeyAgreementResult;
|
||||
import org.briarproject.api.settings.SettingsManager;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -49,8 +47,6 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
|
||||
|
||||
@Inject
|
||||
protected EventBus eventBus;
|
||||
@Inject
|
||||
protected SettingsManager settingsManager;
|
||||
|
||||
private Toolbar toolbar;
|
||||
private View progressContainer;
|
||||
@@ -58,6 +54,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
|
||||
|
||||
private AuthorId localAuthorId;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile ContactExchangeTask contactExchangeTask;
|
||||
@Inject
|
||||
@@ -193,6 +190,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
|
||||
@Override
|
||||
public void contactExchangeSucceeded(final Author remoteAuthor) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String contactName = remoteAuthor.getName();
|
||||
String format = getString(R.string.contact_added_toast);
|
||||
@@ -207,6 +205,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
|
||||
@Override
|
||||
public void duplicateContact(final Author remoteAuthor) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String contactName = remoteAuthor.getName();
|
||||
String format = getString(R.string.contact_already_exists);
|
||||
@@ -221,6 +220,7 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements
|
||||
@Override
|
||||
public void contactExchangeFailed() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(KeyAgreementActivity.this,
|
||||
R.string.contact_exchange_failed, LENGTH_LONG).show();
|
||||
|
||||
@@ -57,11 +57,11 @@ import static java.util.logging.Level.WARNING;
|
||||
public class ShowQrCodeFragment extends BaseEventFragment
|
||||
implements QrCodeDecoder.ResultCallback {
|
||||
|
||||
public static final String TAG = "ShowQrCodeFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ShowQrCodeFragment.class.getName());
|
||||
|
||||
public static final String TAG = "ShowQrCodeFragment";
|
||||
|
||||
@Inject
|
||||
protected KeyAgreementTaskFactory keyAgreementTaskFactory;
|
||||
@Inject
|
||||
@@ -138,6 +138,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
if (adapter != null && !adapter.isEnabled()) {
|
||||
waitingForBluetooth = true;
|
||||
androidExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.enable();
|
||||
}
|
||||
@@ -342,6 +343,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
@Override
|
||||
public void handleResult(final Result result) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.info("Got result from decoder");
|
||||
if (!gotRemotePayload) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.BaseActivity;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.view.MenuItem;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
|
||||
public class PanicPreferencesActivity extends BriarActivity {
|
||||
@@ -29,6 +28,7 @@ public class PanicPreferencesActivity extends BriarActivity {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
@@ -36,5 +36,4 @@ public class PanicPreferencesActivity extends BriarActivity {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.api.AndroidExecutor;
|
||||
import org.briarproject.android.controller.ConfigController;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.iilab.IilabEngineeringRSA2048Pin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
@@ -32,7 +31,9 @@ public class PanicResponderActivity extends BriarActivity {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(PanicResponderActivity.class.getName());
|
||||
@Inject protected ConfigController configController;
|
||||
|
||||
@Inject
|
||||
protected ConfigController configController;
|
||||
@Inject
|
||||
protected AndroidExecutor androidExecutor;
|
||||
|
||||
@@ -76,8 +77,6 @@ public class PanicResponderActivity extends BriarActivity {
|
||||
LOG.info("Signing out...");
|
||||
signOut(true);
|
||||
}
|
||||
|
||||
// TODO send a pre-defined message to certain contacts (#212)
|
||||
}
|
||||
// Performing non-destructive default panic response
|
||||
else if (sharedPref.getBoolean(KEY_LOCK, true)) {
|
||||
@@ -109,11 +108,10 @@ public class PanicResponderActivity extends BriarActivity {
|
||||
|
||||
private void deleteAllData() {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
configController.clearPrefs();
|
||||
configController.deleteAccount(PanicResponderActivity.this);
|
||||
// TODO somehow delete/shred the database more thoroughly
|
||||
// TODO replace this static call with a controller method
|
||||
AndroidUtils.deleteAppData(PanicResponderActivity.this);
|
||||
PanicResponder.deleteAllAppData(PanicResponderActivity.this);
|
||||
|
||||
// nothing left to do after everything is deleted,
|
||||
|
||||
@@ -4,67 +4,61 @@ import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.MeasureSpec.UNSPECIFIED;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
public class CustomAnimations {
|
||||
|
||||
public static void animateHeight(
|
||||
final ViewGroup viewGroup, final boolean isExtending,
|
||||
public static void animateHeight(ViewGroup viewGroup, boolean isExtending,
|
||||
int duration) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
animateHeightPostGingerbread(viewGroup, isExtending, duration);
|
||||
} else {
|
||||
animateHeightGingerbread(viewGroup, isExtending, duration);
|
||||
animateHeightGingerbread(viewGroup, isExtending);
|
||||
}
|
||||
}
|
||||
|
||||
private static void animateHeightGingerbread(final ViewGroup viewGroup,
|
||||
final boolean isExtending, int duration) {
|
||||
private static void animateHeightGingerbread(ViewGroup viewGroup,
|
||||
boolean isExtending) {
|
||||
// No animations for Gingerbread
|
||||
if (isExtending) {
|
||||
viewGroup.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
viewGroup.setVisibility(View.GONE);
|
||||
}
|
||||
if (isExtending) viewGroup.setVisibility(VISIBLE);
|
||||
else viewGroup.setVisibility(GONE);
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private static void animateHeightPostGingerbread(
|
||||
final ViewGroup viewGroup,
|
||||
final boolean isExtending,
|
||||
int duration) {
|
||||
private static void animateHeightPostGingerbread(final ViewGroup viewGroup,
|
||||
final boolean isExtending, int duration) {
|
||||
ValueAnimator anim;
|
||||
if (isExtending) {
|
||||
viewGroup.setVisibility(View.VISIBLE);
|
||||
viewGroup.measure(View.MeasureSpec.UNSPECIFIED,
|
||||
View.MeasureSpec.UNSPECIFIED);
|
||||
viewGroup.setVisibility(VISIBLE);
|
||||
viewGroup.measure(UNSPECIFIED, UNSPECIFIED);
|
||||
anim = ValueAnimator.ofInt(0, viewGroup.getMeasuredHeight());
|
||||
} else {
|
||||
anim = ValueAnimator.ofInt(viewGroup.getHeight(), 0);
|
||||
}
|
||||
anim.addListener(new Animator.AnimatorListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (!isExtending) {
|
||||
viewGroup.setVisibility(View.GONE);
|
||||
viewGroup.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
});
|
||||
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@@ -76,7 +70,6 @@ public class CustomAnimations {
|
||||
layoutParams.height = val;
|
||||
viewGroup.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
});
|
||||
anim.setDuration(duration);
|
||||
anim.start();
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.provider.Settings;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -16,9 +15,6 @@ import static android.provider.Settings.Secure.ANDROID_ID;
|
||||
|
||||
class AndroidSeedProvider extends LinuxSeedProvider {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(LinuxSeedProvider.class.getName());
|
||||
|
||||
private final Context appContext;
|
||||
|
||||
@Inject
|
||||
@@ -34,10 +30,8 @@ class AndroidSeedProvider extends LinuxSeedProvider {
|
||||
if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
|
||||
if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
|
||||
ContentResolver contentResolver = appContext.getContentResolver();
|
||||
String str = Settings.Secure.getString(contentResolver, ANDROID_ID);
|
||||
if (str != null) {
|
||||
out.writeUTF(str);
|
||||
}
|
||||
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
|
||||
if (id != null) out.writeUTF(id);
|
||||
super.writeToEntropyPool(out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,23 +48,23 @@ import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 21,
|
||||
application = TestBriarApplicationImp.class)
|
||||
application = TestBriarApplication.class)
|
||||
public class SetupActivityTest {
|
||||
|
||||
TestSetupActivity setupActivity;
|
||||
TextInputLayout nicknameEntryWrapper;
|
||||
TextInputLayout passwordEntryWrapper;
|
||||
TextInputLayout passwordConfirmationWrapper;
|
||||
EditText nicknameEntry;
|
||||
EditText passwordEntry;
|
||||
EditText passwordConfirmation;
|
||||
StrengthMeter strengthMeter;
|
||||
Button createAccountButton;
|
||||
private TestSetupActivity setupActivity;
|
||||
private TextInputLayout nicknameEntryWrapper;
|
||||
private TextInputLayout passwordEntryWrapper;
|
||||
private TextInputLayout passwordConfirmationWrapper;
|
||||
private EditText nicknameEntry;
|
||||
private EditText passwordEntry;
|
||||
private EditText passwordConfirmation;
|
||||
private StrengthMeter strengthMeter;
|
||||
private Button createAccountButton;
|
||||
|
||||
@Mock
|
||||
SetupController setupController;
|
||||
private SetupController setupController;
|
||||
@Captor
|
||||
ArgumentCaptor<ResultHandler<Long>> resultCaptor;
|
||||
private ArgumentCaptor<ResultHandler<Long>> resultCaptor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -225,5 +225,4 @@ public class SetupActivityTest {
|
||||
Mockito.verify(mockedController, Mockito.times(1))
|
||||
.estimatePasswordStrength(eq("empty"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.briarproject.android.DaggerAndroidComponent;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This Class only exists to get around ACRA
|
||||
* This class only exists to avoid static initialisation of ACRA
|
||||
*/
|
||||
public class TestBriarApplicationImp extends Application implements
|
||||
BriarApplication{
|
||||
public class TestBriarApplication extends Application
|
||||
implements BriarApplication {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(TestBriarApplicationImp.class.getName());
|
||||
Logger.getLogger(TestBriarApplication.class.getName());
|
||||
|
||||
private AndroidComponent applicationComponent;
|
||||
|
||||
@@ -37,6 +37,7 @@ public class TestBriarApplicationImp extends Application implements
|
||||
AndroidEagerSingletons.initEagerSingletons(applicationComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AndroidComponent getApplicationComponent() {
|
||||
return applicationComponent;
|
||||
}
|
||||
@@ -10,11 +10,10 @@ import org.briarproject.android.controller.SetupController;
|
||||
public class TestSetupActivity extends SetupActivity {
|
||||
|
||||
public SetupController getController() {
|
||||
return this.setupController;
|
||||
return setupController;
|
||||
}
|
||||
|
||||
public void setController(SetupController setupController) {
|
||||
this.setupController = setupController;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user