mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Show beta expiry warning in main activity
This commit is contained in:
@@ -6,5 +6,9 @@ package org.briarproject.briar.android;
|
||||
*/
|
||||
public interface BriarApplication {
|
||||
|
||||
// This build expires on 1 October 2017
|
||||
long EXPIRY_DATE = 1506812400 * 1000L;
|
||||
|
||||
AndroidComponent getApplicationComponent();
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.blog.FeedFragment;
|
||||
import org.briarproject.briar.android.contact.ContactListFragment;
|
||||
import org.briarproject.briar.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.briar.android.forum.ForumListFragment;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
@@ -45,6 +46,9 @@ import javax.inject.Inject;
|
||||
import static android.support.v4.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
|
||||
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.util.UiUtils.getDaysUntilExpiry;
|
||||
|
||||
public class NavDrawerActivity extends BriarActivity implements
|
||||
BaseFragmentListener, TransportStateListener,
|
||||
@@ -128,6 +132,12 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
updateTransports();
|
||||
controller.showExpiryWarning(new UiResultHandler<Boolean>(this) {
|
||||
@Override
|
||||
public void onResultUi(Boolean showWarning) {
|
||||
if (showWarning) showExpiryWarning();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void exitIfStartupFailed(Intent intent) {
|
||||
@@ -254,6 +264,34 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
// Do nothing for now
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private void showExpiryWarning() {
|
||||
int daysUntilExpiry = getDaysUntilExpiry();
|
||||
if (daysUntilExpiry < 0) signOut();
|
||||
|
||||
// show expiry warning text
|
||||
final ViewGroup
|
||||
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);
|
||||
expiryWarningClose.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
controller.expiryWarningDismissed();
|
||||
expiryWarning.setVisibility(GONE);
|
||||
}
|
||||
});
|
||||
|
||||
expiryWarning.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
private void initializeTransports(final LayoutInflater inflater) {
|
||||
transports = new ArrayList<>(3);
|
||||
|
||||
|
||||
@@ -3,10 +3,15 @@ package org.briarproject.briar.android.navdrawer;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface NavDrawerController extends ActivityLifecycleController {
|
||||
|
||||
boolean isTransportRunning(TransportId transportId);
|
||||
|
||||
void showExpiryWarning(final ResultHandler<Boolean> handler);
|
||||
|
||||
void expiryWarningDismissed();
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.navdrawer;
|
||||
import android.app.Activity;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
@@ -14,7 +15,10 @@ import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
@@ -22,6 +26,9 @@ import java.util.logging.Logger;
|
||||
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.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -30,18 +37,21 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(NavDrawerControllerImpl.class.getName());
|
||||
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
|
||||
|
||||
private final PluginManager pluginManager;
|
||||
private final SettingsManager settingsManager;
|
||||
private final EventBus eventBus;
|
||||
|
||||
private volatile TransportStateListener listener;
|
||||
|
||||
@Inject
|
||||
NavDrawerControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager,
|
||||
PluginManager pluginManager, EventBus eventBus) {
|
||||
LifecycleManager lifecycleManager, PluginManager pluginManager,
|
||||
SettingsManager settingsManager, EventBus eventBus) {
|
||||
super(dbExecutor, lifecycleManager);
|
||||
this.pluginManager = pluginManager;
|
||||
this.settingsManager = settingsManager;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
@@ -92,6 +102,63 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showExpiryWarning(final ResultHandler<Boolean> handler) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
int warningInt = settings.getInt(EXPIRY_DATE_WARNING, 0);
|
||||
|
||||
if (warningInt == 0) {
|
||||
// we have not warned before
|
||||
handler.onResult(true);
|
||||
} else {
|
||||
long warningLong = warningInt * 1000L;
|
||||
long now = System.currentTimeMillis();
|
||||
long daysSinceLastWarning =
|
||||
(now - warningLong) / 1000 / 60 / 60 / 24;
|
||||
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);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expiryWarningDismissed() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Settings settings = new Settings();
|
||||
int date = (int) (System.currentTimeMillis() / 1000L);
|
||||
settings.putInt(EXPIRY_DATE_WARNING, date);
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransportRunning(TransportId transportId) {
|
||||
Plugin plugin = pluginManager.getPlugin(transportId);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.android.BriarApplication.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.TestingConstants.DEFAULT_LOG_LEVEL;
|
||||
import static org.briarproject.briar.android.TestingConstants.TESTING;
|
||||
|
||||
@@ -30,9 +31,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SplashScreenActivity.class.getName());
|
||||
|
||||
// This build expires on 1 September 2017
|
||||
private static final long EXPIRY_DATE = 1504220400 * 1000L;
|
||||
|
||||
@Inject
|
||||
protected ConfigController configController;
|
||||
@Inject
|
||||
|
||||
@@ -31,6 +31,7 @@ import static android.text.format.DateUtils.FORMAT_ABBREV_TIME;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
||||
import static org.briarproject.briar.android.BriarApplication.EXPIRY_DATE;
|
||||
|
||||
public class UiUtils {
|
||||
|
||||
@@ -64,6 +65,12 @@ public class UiUtils {
|
||||
MIN_DATE_RESOLUTION, flags).toString();
|
||||
}
|
||||
|
||||
public static int getDaysUntilExpiry() {
|
||||
long now = System.currentTimeMillis();
|
||||
long daysBeforeExpiry = (EXPIRY_DATE - now) / 1000 / 60 / 60 / 24;
|
||||
return (int) daysBeforeExpiry;
|
||||
}
|
||||
|
||||
public static SpannableStringBuilder getTeaser(Context ctx, Spanned body) {
|
||||
if (body.length() < TEASER_LENGTH)
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
Reference in New Issue
Block a user