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.
This commit is contained in:
Torsten Grote
2016-12-21 12:06:20 -02:00
parent 79fc41477c
commit 0a9840997f
20 changed files with 58 additions and 63 deletions
@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.android.AndroidComponent;
import org.briarproject.briar.android.BriarApplication;
import org.briarproject.briar.android.DestroyableContext;
@@ -116,4 +117,9 @@ public abstract class BaseActivity extends AppCompatActivity
Object o = getSystemService(INPUT_METHOD_SERVICE);
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
}
public void handleDbException(DbException e) {
supportFinishAfterTransition();
}
}
@@ -205,8 +205,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
finish();
handleDbException(exception);
}
}
);
@@ -234,8 +233,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
finish();
handleDbException(exception);
}
});
}
@@ -254,8 +252,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
finish();
handleDbException(exception);
}
});
}
@@ -277,8 +274,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
finish();
handleDbException(exception);
}
});
}
@@ -373,8 +369,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
finish();
handleDbException(exception);
}
});
}
@@ -55,8 +55,7 @@ public class BlogPostFragment extends BasePostFragment {
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
finish();
handleDbException(exception);
}
});
}
@@ -129,7 +129,7 @@ public class FeedFragment extends BaseFragment implements
@Override
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
public void onExceptionUi(DbException e) {
// TODO: Decide how to handle errors in the UI
public void onExceptionUi(DbException exception) {
handleDbException(exception);
}
});
list.startPeriodicUpdate();
@@ -211,7 +211,7 @@ public class FeedFragment extends BaseFragment implements
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
handleDbException(exception);
}
}
);
@@ -79,7 +79,7 @@ public class FeedPostFragment extends BasePostFragment {
@Override
public void onExceptionUi(DbException exception) {
// TODO: Decide how to handle errors in the UI
handleDbException(exception);
}
});
}
@@ -99,8 +99,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
@Override
public void onExceptionUi(DbException exception) {
// TODO
finish();
handleDbException(exception);
}
});
}
@@ -130,8 +129,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
// do nothing, this fragment is gone already
handleDbException(exception);
}
});
finish();
@@ -130,8 +130,7 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
@Override
public void onExceptionUi(DbException exception) {
// TODO error handling
finish();
handleDbException(exception);
}
});
}
@@ -192,8 +192,7 @@ public class ForumActivity extends
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -8,6 +8,7 @@ import android.support.annotation.UiThread;
import android.support.v4.app.Fragment;
import android.view.MenuItem;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.android.DestroyableContext;
import org.briarproject.briar.android.activity.ActivityComponent;
@@ -71,6 +72,9 @@ public abstract class BaseFragment extends Fragment
@UiThread
void showNextFragment(BaseFragment f);
@UiThread
void handleDbException(DbException e);
}
@CallSuper
@@ -95,4 +99,9 @@ public abstract class BaseFragment extends Fragment
listener.showNextFragment(f);
}
@UiThread
protected void handleDbException(DbException e) {
listener.handleDbException(e);
}
}
@@ -19,6 +19,7 @@ import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.plugin.BluetoothConstants;
import org.briarproject.bramble.api.plugin.LanTcpConstants;
import org.briarproject.bramble.api.plugin.TorConstants;
@@ -246,6 +247,11 @@ public class NavDrawerActivity extends BriarActivity implements
POP_BACK_STACK_INCLUSIVE);
}
@Override
public void handleDbException(DbException e) {
// Do nothing for now
}
private void initializeTransports(final LayoutInflater inflater) {
transports = new ArrayList<>(3);
@@ -117,8 +117,7 @@ public class GroupActivity extends
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -137,8 +136,7 @@ public class GroupActivity extends
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -276,8 +274,7 @@ public class GroupActivity extends
// GroupRemovedEvent being fired
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -43,9 +43,8 @@ public abstract class BaseGroupInviteActivity
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
setResult(RESULT_CANCELED);
finish();
handleDbException(exception);
}
});
return true;
@@ -58,8 +58,7 @@ public class CreateGroupActivity extends BaseGroupInviteActivity implements
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -132,7 +132,7 @@ public class GroupListFragment extends BaseFragment implements
// result handled by GroupRemovedEvent and onGroupRemoved()
@Override
public void onExceptionUi(DbException exception) {
// TODO handle error
handleDbException(exception);
}
});
}
@@ -202,7 +202,7 @@ public class GroupListFragment extends BaseFragment implements
@Override
public void onExceptionUi(DbException exception) {
// TODO handle this error
handleDbException(exception);
}
});
}
@@ -224,8 +224,7 @@ public class GroupListFragment extends BaseFragment implements
@Override
public void onExceptionUi(DbException exception) {
// TODO handle this error
finish();
handleDbException(exception);
}
});
}
@@ -67,8 +67,7 @@ public class GroupMemberListActivity extends BriarActivity {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
list.startPeriodicUpdate();
@@ -80,8 +80,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -132,7 +131,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
handleDbException(exception);
}
});
}
@@ -149,8 +148,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
supportFinishAfterTransition();
@@ -97,8 +97,7 @@ public abstract class InvitationActivity<I extends InvitationItem>
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -111,8 +110,7 @@ public abstract class InvitationActivity<I extends InvitationItem>
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -56,10 +56,10 @@ public class ShareBlogActivity extends ShareActivity {
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
Toast.makeText(ShareBlogActivity.this,
R.string.blogs_sharing_error, LENGTH_SHORT)
.show();
handleDbException(exception);
}
});
@@ -56,10 +56,10 @@ public class ShareForumActivity extends ShareActivity {
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
// TODO proper error handling
Toast.makeText(ShareForumActivity.this,
R.string.forum_share_error, LENGTH_SHORT)
.show();
handleDbException(exception);
}
});
}
@@ -114,8 +114,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
// TODO Proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -147,8 +146,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
// TODO Proper error handling
finish();
handleDbException(exception);
}
});
}
@@ -165,9 +163,8 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
}
@Override
public void onExceptionUi(DbException e) {
// TODO Proper error handling
finish();
public void onExceptionUi(DbException exception) {
handleDbException(exception);
}
});
}
@@ -299,8 +296,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
// TODO add proper exception handling
finish();
handleDbException(exception);
}
};
getController().createAndStoreMessage(text, replyItem, handler);
@@ -323,8 +319,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
// TODO add proper exception handling
finish();
handleDbException(exception);
}
});
}