Merge branch 'extend-expiry' into 'master'

Extend expiry and show a green snackbar about it once

See merge request !606
This commit is contained in:
akwizgran
2017-10-12 17:03:26 +00:00
5 changed files with 56 additions and 26 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
@@ -83,7 +86,8 @@ public class NavDrawerActivity extends BriarActivity implements
} else if (intent.getBooleanExtra(INTENT_FORUMS, false)) { } else if (intent.getBooleanExtra(INTENT_FORUMS, false)) {
startFragment(ForumListFragment.newInstance(), R.id.nav_btn_forums); startFragment(ForumListFragment.newInstance(), R.id.nav_btn_forums);
} else if (intent.getBooleanExtra(INTENT_CONTACTS, false)) { } else if (intent.getBooleanExtra(INTENT_CONTACTS, false)) {
startFragment(ContactListFragment.newInstance(), R.id.nav_btn_contacts); startFragment(ContactListFragment.newInstance(),
R.id.nav_btn_contacts);
} else if (intent.getBooleanExtra(INTENT_BLOGS, false)) { } else if (intent.getBooleanExtra(INTENT_BLOGS, false)) {
startFragment(FeedFragment.newInstance(), R.id.nav_btn_blogs); startFragment(FeedFragment.newInstance(), R.id.nav_btn_blogs);
} }
@@ -121,7 +125,8 @@ public class NavDrawerActivity extends BriarActivity implements
transportsView.setAdapter(transportsAdapter); transportsView.setAdapter(transportsAdapter);
if (state == null) { if (state == null) {
startFragment(ContactListFragment.newInstance(), R.id.nav_btn_contacts); startFragment(ContactListFragment.newInstance(),
R.id.nav_btn_contacts);
} }
if (getIntent() != null) { if (getIntent() != null) {
onNewIntent(getIntent()); onNewIntent(getIntent());
@@ -132,10 +137,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);
} }
}); });
} }
@@ -178,7 +183,7 @@ public class NavDrawerActivity extends BriarActivity implements
clearBackStack(); clearBackStack();
loadFragment(item.getItemId()); loadFragment(item.getItemId());
//Don't display the Settings Item as checked //Don't display the Settings Item as checked
if (item.getItemId() == R.id.nav_btn_settings){ if (item.getItemId() == R.id.nav_btn_settings) {
return false; return false;
} }
return true; return true;
@@ -204,7 +209,8 @@ public class NavDrawerActivity extends BriarActivity implements
* exiting. This models the typical Google navigation behaviour such * exiting. This models the typical Google navigation behaviour such
* as in Gmail/Inbox. * as in Gmail/Inbox.
*/ */
startFragment(ContactListFragment.newInstance(), R.id.nav_btn_contacts); startFragment(ContactListFragment.newInstance(),
R.id.nav_btn_contacts);
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }
@@ -228,7 +234,7 @@ public class NavDrawerActivity extends BriarActivity implements
signOut(false); signOut(false);
} }
private void startFragment(BaseFragment fragment, int itemId){ private void startFragment(BaseFragment fragment, int itemId) {
navigation.setCheckedItem(itemId); navigation.setCheckedItem(itemId);
startFragment(fragment); startFragment(fragment);
} }
@@ -265,7 +271,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,13 +280,26 @@ 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,
daysUntilExpiry));
// make close button functional // make close button functional
ImageView expiryWarningClose = ImageView expiryWarningClose =
(ImageView) expiryWarning.findViewById(R.id.expiryWarningClose); (ImageView) expiryWarning.findViewById(R.id.expiryWarningClose);
// 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));
expiryWarningText.setTextColor(
ContextCompat.getColor(this, android.R.color.black));
expiryWarningClose.setColorFilter(
ContextCompat.getColor(this, android.R.color.black));
} else {
expiryWarningText.setText(getResources()
.getQuantityString(R.plurals.expiry_warning,
daysUntilExpiry, daysUntilExpiry));
}
expiryWarningClose.setOnClickListener(new View.OnClickListener() { expiryWarningClose.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {

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

@@ -28,6 +28,9 @@ 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.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 +41,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_SHOW_UPDATE = "expiryShowUpdate";
private final PluginManager pluginManager; private final PluginManager pluginManager;
private final SettingsManager settingsManager; private final SettingsManager settingsManager;
@@ -103,7 +107,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 +115,12 @@ 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);
boolean showUpdate =
settings.getBoolean(EXPIRY_SHOW_UPDATE, true);
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,16 @@ 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 (showUpdate) {
handler.onResult(true); handler.onResult(UPDATE);
return; } else if (daysSinceLastWarning >= 30) {
handler.onResult(SHOW);
} else if (daysBeforeExpiry <= 3 &&
daysSinceLastWarning > 0) {
handler.onResult(SHOW);
} else {
handler.onResult(NO);
} }
if (daysBeforeExpiry <= 3 && daysSinceLastWarning > 0) {
handler.onResult(true);
return;
}
handler.onResult(false);
} }
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
@@ -150,6 +157,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.putBoolean(EXPIRY_SHOW_UPDATE, false);
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 -->