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 { public interface BriarApplication {
// This build expires on 21 October 2017 // This build expires on 31 December 2017
long EXPIRY_DATE = 1508544000 * 1000L; long EXPIRY_DATE = 1514761200 * 1000L;
AndroidComponent getApplicationComponent(); 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;
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener; import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.briar.android.fragment.SignOutFragment; 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.privategroup.list.GroupListFragment;
import org.briarproject.briar.android.settings.SettingsActivity; 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.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; 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; import static org.briarproject.briar.android.util.UiUtils.getDaysUntilExpiry;
public class NavDrawerActivity extends BriarActivity implements public class NavDrawerActivity extends BriarActivity implements
@@ -132,10 +135,10 @@ public class NavDrawerActivity extends BriarActivity implements
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
updateTransports(); updateTransports();
controller.showExpiryWarning(new UiResultHandler<Boolean>(this) { controller.showExpiryWarning(new UiResultHandler<ExpiryWarning>(this) {
@Override @Override
public void onResultUi(Boolean showWarning) { public void onResultUi(ExpiryWarning expiry) {
if (showWarning) showExpiryWarning(); if (expiry != NO) showExpiryWarning(expiry);
} }
}); });
} }
@@ -265,7 +268,7 @@ public class NavDrawerActivity extends BriarActivity implements
} }
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
private void showExpiryWarning() { private void showExpiryWarning(ExpiryWarning expiry) {
int daysUntilExpiry = getDaysUntilExpiry(); int daysUntilExpiry = getDaysUntilExpiry();
if (daysUntilExpiry < 0) signOut(); if (daysUntilExpiry < 0) signOut();
@@ -274,9 +277,18 @@ public class NavDrawerActivity extends BriarActivity implements
expiryWarning = (ViewGroup) findViewById(R.id.expiryWarning); expiryWarning = (ViewGroup) findViewById(R.id.expiryWarning);
TextView expiryWarningText = TextView expiryWarningText =
(TextView) expiryWarning.findViewById(R.id.expiryWarningText); (TextView) expiryWarning.findViewById(R.id.expiryWarningText);
expiryWarningText.setText(getResources()
.getQuantityString(R.plurals.expiry_warning, daysUntilExpiry, // show a different snackbar in green if this is an update
daysUntilExpiry)); 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 // make close button functional
ImageView expiryWarningClose = ImageView expiryWarningClose =

View File

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

View File

@@ -28,6 +28,7 @@
<item quantity="one">This is a beta version of Briar. Your account will expire in %d day and cannot be renewed.</item> <item quantity="one">This is a beta version of Briar. Your account will expire in %d day and cannot be renewed.</item>
<item quantity="other">This is a beta version of Briar. Your account will expire in %d days and cannot be renewed.</item> <item quantity="other">This is a beta version of Briar. Your account will expire in %d days and cannot be renewed.</item>
</plurals> </plurals>
<string name="expiry_update">The beta expiry date has been extended. Your account will now expire in %d days.</string>
<string name="expiry_date_reached">This software has expired.\nThank you for testing!</string> <string name="expiry_date_reached">This software has expired.\nThank you for testing!</string>
<!-- Navigation Drawer --> <!-- Navigation Drawer -->