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 {
// 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
@@ -83,7 +86,8 @@ public class NavDrawerActivity extends BriarActivity implements
} else if (intent.getBooleanExtra(INTENT_FORUMS, false)) {
startFragment(ForumListFragment.newInstance(), R.id.nav_btn_forums);
} 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)) {
startFragment(FeedFragment.newInstance(), R.id.nav_btn_blogs);
}
@@ -121,7 +125,8 @@ public class NavDrawerActivity extends BriarActivity implements
transportsView.setAdapter(transportsAdapter);
if (state == null) {
startFragment(ContactListFragment.newInstance(), R.id.nav_btn_contacts);
startFragment(ContactListFragment.newInstance(),
R.id.nav_btn_contacts);
}
if (getIntent() != null) {
onNewIntent(getIntent());
@@ -132,10 +137,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);
}
});
}
@@ -178,7 +183,7 @@ public class NavDrawerActivity extends BriarActivity implements
clearBackStack();
loadFragment(item.getItemId());
//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 true;
@@ -204,7 +209,8 @@ public class NavDrawerActivity extends BriarActivity implements
* exiting. This models the typical Google navigation behaviour such
* as in Gmail/Inbox.
*/
startFragment(ContactListFragment.newInstance(), R.id.nav_btn_contacts);
startFragment(ContactListFragment.newInstance(),
R.id.nav_btn_contacts);
} else {
super.onBackPressed();
}
@@ -228,7 +234,7 @@ public class NavDrawerActivity extends BriarActivity implements
signOut(false);
}
private void startFragment(BaseFragment fragment, int itemId){
private void startFragment(BaseFragment fragment, int itemId) {
navigation.setCheckedItem(itemId);
startFragment(fragment);
}
@@ -265,7 +271,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,13 +280,26 @@ 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));
// make close button functional
ImageView 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() {
@Override
public void onClick(View v) {

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

@@ -28,6 +28,9 @@ import javax.inject.Inject;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
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 +41,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_SHOW_UPDATE = "expiryShowUpdate";
private final PluginManager pluginManager;
private final SettingsManager settingsManager;
@@ -103,7 +107,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 +115,12 @@ public class NavDrawerControllerImpl extends DbControllerImpl
Settings settings =
settingsManager.getSettings(SETTINGS_NAMESPACE);
int warningInt = settings.getInt(EXPIRY_DATE_WARNING, 0);
boolean showUpdate =
settings.getBoolean(EXPIRY_SHOW_UPDATE, true);
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,16 @@ public class NavDrawerControllerImpl extends DbControllerImpl
long daysBeforeExpiry =
(EXPIRY_DATE - now) / 1000 / 60 / 60 / 24;
if (daysSinceLastWarning >= 30) {
handler.onResult(true);
return;
if (showUpdate) {
handler.onResult(UPDATE);
} 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) {
if (LOG.isLoggable(WARNING))
@@ -150,6 +157,7 @@ public class NavDrawerControllerImpl extends DbControllerImpl
Settings settings = new Settings();
int date = (int) (System.currentTimeMillis() / 1000L);
settings.putInt(EXPIRY_DATE_WARNING, date);
settings.putBoolean(EXPIRY_SHOW_UPDATE, false);
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
} catch (DbException e) {
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="other">This is a beta version of Briar. Your account will expire in %d days and cannot be renewed.</item>
</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>
<!-- Navigation Drawer -->