Commit 30e0be9f authored by akwizgran's avatar akwizgran

Merge branch '1580-show-snackbar' into 'master'

Show snackbar when there is no internet connection

Closes #1580

See merge request !1139
parents a54eb64e c73801c7
Pipeline #3587 passed with stage
in 8 minutes and 31 seconds
......@@ -4,6 +4,7 @@ import android.arch.lifecycle.ViewModelProvider;
import android.arch.lifecycle.ViewModelProviders;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
......@@ -15,6 +16,7 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
import org.briarproject.briar.android.view.BriarRecyclerView;
import java.util.Collection;
......@@ -22,6 +24,7 @@ import java.util.Collection;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
import static org.briarproject.bramble.api.contact.PendingContactState.FAILED;
import static org.briarproject.briar.android.contact.add.remote.PendingContactItem.POLL_DURATION_MS;
......@@ -36,6 +39,7 @@ public class PendingContactListActivity extends BriarActivity
private PendingContactListViewModel viewModel;
private PendingContactListAdapter adapter;
private BriarRecyclerView list;
private Snackbar offlineSnackbar;
@Override
public void injectActivity(ActivityComponent component) {
......@@ -58,6 +62,8 @@ public class PendingContactListActivity extends BriarActivity
viewModel.onCreate();
viewModel.getPendingContacts()
.observe(this, this::onPendingContactsChanged);
viewModel.getHasInternetConnection()
.observe(this, this::onInternetConnectionChanged);
adapter = new PendingContactListAdapter(this, this,
PendingContactItem.class);
......@@ -66,6 +72,10 @@ public class PendingContactListActivity extends BriarActivity
list.setLayoutManager(new LinearLayoutManager(this));
list.setAdapter(adapter);
list.showProgressBar();
offlineSnackbar = new BriarSnackbarBuilder()
.setBackgroundColor(R.color.briar_red)
.make(list, R.string.offline_state, LENGTH_INDEFINITE);
}
@Override
......@@ -130,4 +140,9 @@ public class PendingContactListActivity extends BriarActivity
}
}
private void onInternetConnectionChanged(boolean online) {
if (online) offlineSnackbar.dismiss();
else offlineSnackbar.show();
}
}
......@@ -31,6 +31,7 @@ import javax.inject.Inject;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.api.contact.PendingContactState.OFFLINE;
import static org.briarproject.bramble.util.LogUtils.logException;
@NotNullByDefault
......@@ -48,6 +49,8 @@ public class PendingContactListViewModel extends AndroidViewModel
private final MutableLiveData<Collection<PendingContactItem>>
pendingContacts = new MutableLiveData<>();
private final MutableLiveData<Boolean> hasInternetConnection =
new MutableLiveData<>();
@Inject
PendingContactListViewModel(Application application,
......@@ -88,13 +91,16 @@ public class PendingContactListViewModel extends AndroidViewModel
Collection<Pair<PendingContact, PendingContactState>> pairs =
contactManager.getPendingContacts();
List<PendingContactItem> items = new ArrayList<>(pairs.size());
boolean online = false;
for (Pair<PendingContact, PendingContactState> pair : pairs) {
PendingContact p = pair.getFirst();
PendingContactState state = pair.getSecond();
long lastPoll = rendezvousPoller.getLastPollTime(p.getId());
items.add(new PendingContactItem(p, pair.getSecond(),
lastPoll));
items.add(new PendingContactItem(p, state, lastPoll));
online = online || state != OFFLINE;
}
pendingContacts.postValue(items);
hasInternetConnection.postValue(online);
} catch (DbException e) {
logException(LOG, WARNING, e);
}
......@@ -115,4 +121,8 @@ public class PendingContactListViewModel extends AndroidViewModel
});
}
LiveData<Boolean> getHasInternetConnection() {
return hasInternetConnection;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment