Extend expiry and show a green snackbar about it once

This commit is contained in:
Torsten Grote
2017-10-10 15:11:24 -03:00
committed by akwizgran
parent 13d35229d5
commit 8c29c85696
5 changed files with 42 additions and 21 deletions

View File

@@ -6,8 +6,8 @@ package org.briarproject.briar.android;
*/
public interface BriarApplication {
// This build expires on 21 October 2017
long EXPIRY_DATE = 1508544000 * 1000L;
// This build expires on 31 December 2017
long EXPIRY_DATE = 1514761200 * 1000L;
AndroidComponent getApplicationComponent();

View File

@@ -34,6 +34,7 @@ import org.briarproject.briar.android.forum.ForumListFragment;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.briar.android.fragment.SignOutFragment;
import org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning;
import org.briarproject.briar.android.privategroup.list.GroupListFragment;
import org.briarproject.briar.android.settings.SettingsActivity;
@@ -48,6 +49,8 @@ import static android.support.v4.view.GravityCompat.START;
import static android.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.NO;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.UPDATE;
import static org.briarproject.briar.android.util.UiUtils.getDaysUntilExpiry;
public class NavDrawerActivity extends BriarActivity implements
@@ -132,10 +135,10 @@ public class NavDrawerActivity extends BriarActivity implements
public void onStart() {
super.onStart();
updateTransports();
controller.showExpiryWarning(new UiResultHandler<Boolean>(this) {
controller.showExpiryWarning(new UiResultHandler<ExpiryWarning>(this) {
@Override
public void onResultUi(Boolean showWarning) {
if (showWarning) showExpiryWarning();
public void onResultUi(ExpiryWarning expiry) {
if (expiry != NO) showExpiryWarning(expiry);
}
});
}
@@ -265,7 +268,7 @@ public class NavDrawerActivity extends BriarActivity implements
}
@SuppressWarnings("ConstantConditions")
private void showExpiryWarning() {
private void showExpiryWarning(ExpiryWarning expiry) {
int daysUntilExpiry = getDaysUntilExpiry();
if (daysUntilExpiry < 0) signOut();
@@ -274,9 +277,18 @@ public class NavDrawerActivity extends BriarActivity implements
expiryWarning = (ViewGroup) findViewById(R.id.expiryWarning);
TextView expiryWarningText =
(TextView) expiryWarning.findViewById(R.id.expiryWarningText);
expiryWarningText.setText(getResources()
.getQuantityString(R.plurals.expiry_warning, daysUntilExpiry,
daysUntilExpiry));
// show a different snackbar in green if this is an update
if (expiry == UPDATE) {
expiryWarning.setBackgroundColor(
ContextCompat.getColor(this, R.color.briar_green_light));
expiryWarningText.setText(
getString(R.string.expiry_update, daysUntilExpiry));
} else {
expiryWarningText.setText(getResources()
.getQuantityString(R.plurals.expiry_warning, daysUntilExpiry,
daysUntilExpiry));
}
// make close button functional
ImageView expiryWarningClose =

View File

@@ -8,9 +8,11 @@ import org.briarproject.briar.android.controller.handler.ResultHandler;
@NotNullByDefault
public interface NavDrawerController extends ActivityLifecycleController {
enum ExpiryWarning { SHOW, NO, UPDATE };
boolean isTransportRunning(TransportId transportId);
void showExpiryWarning(final ResultHandler<Boolean> handler);
void showExpiryWarning(final ResultHandler<ExpiryWarning> handler);
void expiryWarningDismissed();

View File

@@ -27,7 +27,11 @@ import javax.inject.Inject;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.briar.BuildConfig.VERSION_CODE;
import static org.briarproject.briar.android.BriarApplication.EXPIRY_DATE;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.NO;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.SHOW;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.UPDATE;
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
@MethodsNotNullByDefault
@@ -38,6 +42,7 @@ public class NavDrawerControllerImpl extends DbControllerImpl
private static final Logger LOG =
Logger.getLogger(NavDrawerControllerImpl.class.getName());
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
private static final String EXPIRY_DATE_VERSION = "expiryDateVersion";
private final PluginManager pluginManager;
private final SettingsManager settingsManager;
@@ -103,7 +108,7 @@ public class NavDrawerControllerImpl extends DbControllerImpl
}
@Override
public void showExpiryWarning(final ResultHandler<Boolean> handler) {
public void showExpiryWarning(final ResultHandler<ExpiryWarning> handler) {
runOnDbThread(new Runnable() {
@Override
public void run() {
@@ -111,10 +116,11 @@ public class NavDrawerControllerImpl extends DbControllerImpl
Settings settings =
settingsManager.getSettings(SETTINGS_NAMESPACE);
int warningInt = settings.getInt(EXPIRY_DATE_WARNING, 0);
int versionCode = settings.getInt(EXPIRY_DATE_VERSION, 0);
if (warningInt == 0) {
// we have not warned before
handler.onResult(true);
handler.onResult(SHOW);
} else {
long warningLong = warningInt * 1000L;
long now = System.currentTimeMillis();
@@ -123,15 +129,14 @@ public class NavDrawerControllerImpl extends DbControllerImpl
long daysBeforeExpiry =
(EXPIRY_DATE - now) / 1000 / 60 / 60 / 24;
if (daysSinceLastWarning >= 30) {
handler.onResult(true);
return;
}
if (daysBeforeExpiry <= 3 && daysSinceLastWarning > 0) {
handler.onResult(true);
return;
}
handler.onResult(false);
if (versionCode < 1611) {
handler.onResult(UPDATE);
} else if (daysSinceLastWarning >= 30) {
handler.onResult(SHOW);
} else if (daysBeforeExpiry <= 3 &&
daysSinceLastWarning > 0) {
handler.onResult(SHOW);
} else handler.onResult(NO);
}
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
@@ -150,6 +155,7 @@ public class NavDrawerControllerImpl extends DbControllerImpl
Settings settings = new Settings();
int date = (int) (System.currentTimeMillis() / 1000L);
settings.putInt(EXPIRY_DATE_WARNING, date);
settings.putInt(EXPIRY_DATE_VERSION, VERSION_CODE);
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))