Check storage space on start

This commit is contained in:
M66B 2022-08-30 08:50:17 +02:00
parent 98a88d0ebe
commit 2b813ad2ce
5 changed files with 123 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
@ -46,11 +47,50 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
private static final long SPLASH_DELAY = 1500L; // milliseconds
private static final long SERVICE_START_DELAY = 5 * 1000L; // milliseconds
private static final long IGNORE_STORAGE_SPACE = 24 * 60 * 60 * 1000L; // milliseconds
@Override
protected void onCreate(Bundle savedInstanceState) {
long now = new Date().getTime();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean accept_unsupported = prefs.getBoolean("accept_unsupported", false);
long accept_space = prefs.getLong("accept_space", 0);
long cake = Helper.getAvailableStorageSpace();
if (cake < Helper.MIN_REQUIRED_SPACE && accept_space < now) {
setTheme(R.style.AppThemeBlueOrangeLight);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_space);
TextView tvRemaining = findViewById(R.id.tvRemaining);
tvRemaining.setText(getString(R.string.app_cake_remaining,
Helper.humanReadableByteCount(cake)));
TextView tvRequired = findViewById(R.id.tvRequired);
tvRequired.setText(getString(R.string.app_cake_required,
Helper.humanReadableByteCount(Helper.MIN_REQUIRED_SPACE, true)));
Button btnFix = findViewById(R.id.btnFix);
btnFix.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
v.getContext().startActivity(intent);
}
});
Button btnContinue = findViewById(R.id.btnContinue);
btnContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
prefs.edit().putLong("accept_space", now + IGNORE_STORAGE_SPACE).commit();
ApplicationEx.restart(v.getContext(), "accept_space");
}
});
return;
}
if (!accept_unsupported &&
!Helper.isSupportedDevice() &&

View File

@ -267,7 +267,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"eml_auto_confirm",
"open_with_pkg", "open_with_tabs",
"gmail_checked", "outlook_checked",
"redmi_note"
"redmi_note",
"accept_space", "accept_unsupported"
};
@Override

View File

@ -174,7 +174,7 @@ public class Helper {
static final float LOW_LIGHT = 0.6f;
static final int BUFFER_SIZE = 8192; // Same as in Files class
static final long MIN_REQUIRED_SPACE = 250 * 1024L * 1024L;
static final long MIN_REQUIRED_SPACE = 100 * 1000L * 1000L;
static final int AUTOLOCK_GRACE = 15; // seconds
static final long PIN_FAILURE_DELAY = 3; // seconds

View File

@ -0,0 +1,78 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<eu.faircode.email.ScrollViewEx
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="12dp"
android:scrollbarStyle="outsideOverlay"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvCaption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/app_cake"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvRemaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/app_cake_remaining"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:textColorPrimary"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<TextView
android:id="@+id/tvRequired"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/app_cake_required"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemaining" />
<Button
android:id="@+id/btnFix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:drawableEnd="@drawable/twotone_settings_24"
android:drawablePadding="6dp"
android:text="@string/title_fix"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRequired" />
<Button
android:id="@+id/btnContinue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:drawableEnd="@drawable/twotone_check_24"
android:drawablePadding="6dp"
android:text="@string/app_continue"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnFix" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -12,6 +12,8 @@
<string name="app_continue">Continue anyway</string>
<string name="app_exit">Go \'back\' again to exit</string>
<string name="app_cake">Insufficient storage space left</string>
<string name="app_cake_remaining">Remaining storage space on the device: %1$s</string>
<string name="app_cake_required">Minimum required storage space: %1$s</string>
<string name="app_updated">Last update: %1$s</string>
<string name="app_download">Downloaded from: %1$s</string>