Merge branch '469-handle-background-errors' into 'master'

Add a handleDbException() method to BaseActivity

This adds a `handleDbException()` method to BaseActivity and a corresponding method for fragments that calls through to the activity.
For now, the method just finishes the activity
and NavDrawerActivity overrides it to do nothing,
and all the error places marked with TODO that finish the activity call the method instead.

That gives us zero functional improvement over the status quo,
but it allows us to change the default behaviour easily,
and then we can start thinking about which cases should have non-default behaviour.

First part of #469

See merge request !469
This commit is contained in:
akwizgran
2016-12-21 14:46:53 +00:00
20 changed files with 58 additions and 63 deletions

View File

@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.android.AndroidComponent; import org.briarproject.briar.android.AndroidComponent;
import org.briarproject.briar.android.BriarApplication; import org.briarproject.briar.android.BriarApplication;
import org.briarproject.briar.android.DestroyableContext; import org.briarproject.briar.android.DestroyableContext;
@@ -116,4 +117,9 @@ public abstract class BaseActivity extends AppCompatActivity
Object o = getSystemService(INPUT_METHOD_SERVICE); Object o = getSystemService(INPUT_METHOD_SERVICE);
((InputMethodManager) o).hideSoftInputFromWindow(token, 0); ((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
} }
public void handleDbException(DbException e) {
supportFinishAfterTransition();
}
} }

View File

@@ -205,8 +205,7 @@ public class BlogFragment extends BaseFragment
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
finish();
} }
} }
); );
@@ -234,8 +233,7 @@ public class BlogFragment extends BaseFragment
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
finish();
} }
}); });
} }
@@ -254,8 +252,7 @@ public class BlogFragment extends BaseFragment
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
finish();
} }
}); });
} }
@@ -277,8 +274,7 @@ public class BlogFragment extends BaseFragment
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
finish();
} }
}); });
} }
@@ -373,8 +369,7 @@ public class BlogFragment extends BaseFragment
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -55,8 +55,7 @@ public class BlogPostFragment extends BasePostFragment {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -129,7 +129,7 @@ public class FeedFragment extends BaseFragment implements
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
} }
}); });
} }
@@ -153,8 +153,8 @@ public class FeedFragment extends BaseFragment implements
} }
@Override @Override
public void onExceptionUi(DbException e) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
} }
}); });
list.startPeriodicUpdate(); list.startPeriodicUpdate();
@@ -211,7 +211,7 @@ public class FeedFragment extends BaseFragment implements
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
} }
} }
); );

View File

@@ -79,7 +79,7 @@ public class FeedPostFragment extends BasePostFragment {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI handleDbException(exception);
} }
}); });
} }

View File

@@ -99,8 +99,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO handleDbException(exception);
finish();
} }
}); });
} }
@@ -130,8 +129,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
// do nothing, this fragment is gone already
} }
}); });
finish(); finish();

View File

@@ -130,8 +130,7 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO error handling handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -192,8 +192,7 @@ public class ForumActivity extends
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -8,6 +8,7 @@ import android.support.annotation.UiThread;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.MenuItem; import android.view.MenuItem;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.android.DestroyableContext; import org.briarproject.briar.android.DestroyableContext;
import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.ActivityComponent;
@@ -71,6 +72,9 @@ public abstract class BaseFragment extends Fragment
@UiThread @UiThread
void showNextFragment(BaseFragment f); void showNextFragment(BaseFragment f);
@UiThread
void handleDbException(DbException e);
} }
@CallSuper @CallSuper
@@ -95,4 +99,9 @@ public abstract class BaseFragment extends Fragment
listener.showNextFragment(f); listener.showNextFragment(f);
} }
@UiThread
protected void handleDbException(DbException e) {
listener.handleDbException(e);
}
} }

View File

@@ -19,6 +19,7 @@ import android.widget.GridView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.plugin.BluetoothConstants; import org.briarproject.bramble.api.plugin.BluetoothConstants;
import org.briarproject.bramble.api.plugin.LanTcpConstants; import org.briarproject.bramble.api.plugin.LanTcpConstants;
import org.briarproject.bramble.api.plugin.TorConstants; import org.briarproject.bramble.api.plugin.TorConstants;
@@ -246,6 +247,11 @@ public class NavDrawerActivity extends BriarActivity implements
POP_BACK_STACK_INCLUSIVE); POP_BACK_STACK_INCLUSIVE);
} }
@Override
public void handleDbException(DbException e) {
// Do nothing for now
}
private void initializeTransports(final LayoutInflater inflater) { private void initializeTransports(final LayoutInflater inflater) {
transports = new ArrayList<>(3); transports = new ArrayList<>(3);

View File

@@ -117,8 +117,7 @@ public class GroupActivity extends
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -137,8 +136,7 @@ public class GroupActivity extends
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -276,8 +274,7 @@ public class GroupActivity extends
// GroupRemovedEvent being fired // GroupRemovedEvent being fired
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -43,9 +43,8 @@ public abstract class BaseGroupInviteActivity
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); handleDbException(exception);
} }
}); });
return true; return true;

View File

@@ -58,8 +58,7 @@ public class CreateGroupActivity extends BaseGroupInviteActivity implements
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -132,7 +132,7 @@ public class GroupListFragment extends BaseFragment implements
// result handled by GroupRemovedEvent and onGroupRemoved() // result handled by GroupRemovedEvent and onGroupRemoved()
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO handle error handleDbException(exception);
} }
}); });
} }
@@ -202,7 +202,7 @@ public class GroupListFragment extends BaseFragment implements
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO handle this error handleDbException(exception);
} }
}); });
} }
@@ -224,8 +224,7 @@ public class GroupListFragment extends BaseFragment implements
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO handle this error handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -67,8 +67,7 @@ public class GroupMemberListActivity extends BriarActivity {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
list.startPeriodicUpdate(); list.startPeriodicUpdate();

View File

@@ -80,8 +80,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -132,7 +131,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
} }
}); });
} }
@@ -149,8 +148,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
supportFinishAfterTransition(); supportFinishAfterTransition();

View File

@@ -97,8 +97,7 @@ public abstract class InvitationActivity<I extends InvitationItem>
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -111,8 +110,7 @@ public abstract class InvitationActivity<I extends InvitationItem>
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling handleDbException(exception);
finish();
} }
}); });
} }

View File

@@ -56,10 +56,10 @@ public class ShareBlogActivity extends ShareActivity {
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling
Toast.makeText(ShareBlogActivity.this, Toast.makeText(ShareBlogActivity.this,
R.string.blogs_sharing_error, LENGTH_SHORT) R.string.blogs_sharing_error, LENGTH_SHORT)
.show(); .show();
handleDbException(exception);
} }
}); });

View File

@@ -56,10 +56,10 @@ public class ShareForumActivity extends ShareActivity {
new UiExceptionHandler<DbException>(this) { new UiExceptionHandler<DbException>(this) {
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO proper error handling
Toast.makeText(ShareForumActivity.this, Toast.makeText(ShareForumActivity.this,
R.string.forum_share_error, LENGTH_SHORT) R.string.forum_share_error, LENGTH_SHORT)
.show(); .show();
handleDbException(exception);
} }
}); });
} }

View File

@@ -114,8 +114,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO Proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -147,8 +146,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO Proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -165,9 +163,8 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
} }
@Override @Override
public void onExceptionUi(DbException e) { public void onExceptionUi(DbException exception) {
// TODO Proper error handling handleDbException(exception);
finish();
} }
}); });
} }
@@ -299,8 +296,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO add proper exception handling handleDbException(exception);
finish();
} }
}; };
getController().createAndStoreMessage(text, replyItem, handler); getController().createAndStoreMessage(text, replyItem, handler);
@@ -323,8 +319,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override @Override
public void onExceptionUi(DbException exception) { public void onExceptionUi(DbException exception) {
// TODO add proper exception handling handleDbException(exception);
finish();
} }
}); });
} }