Local storage screen v4 facelift

This commit is contained in:
Zorica Stojchevska 2021-06-03 00:18:07 +02:00
parent c0cb8de35b
commit 92c1d431f2
7 changed files with 166 additions and 207 deletions

View File

@ -313,7 +313,7 @@
android:label="@string/notification_settings"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name=".activities.SnoozeNotificationsActivity"
android:name=".settings.presentation.SnoozeNotificationsActivity"
android:exported="false"
android:screenOrientation="portrait"
android:label="@string/notifications_snooze"

View File

@ -1,132 +0,0 @@
/*
* Copyright (c) 2020 Proton Technologies AG
*
* This file is part of ProtonMail.
*
* ProtonMail is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProtonMail is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
*/
package ch.protonmail.android.activities.settings;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import butterknife.BindView;
import butterknife.OnClick;
import ch.protonmail.android.R;
import ch.protonmail.android.activities.BaseActivity;
import ch.protonmail.android.api.models.User;
import ch.protonmail.android.core.Constants;
import ch.protonmail.android.storage.AttachmentClearingService;
import ch.protonmail.android.utils.extensions.TextExtensions;
public class AttachmentStorageActivity extends BaseActivity {
public static final String EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE = "EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE";
@BindView(R.id.attachment_storage_value)
SeekBar mSeekBar;
@BindView(R.id.storage_text_value)
TextView mStorageTextValue;
private int mAttachmentStorageCurrentValue;
@Override
protected int getLayoutId() {
return R.layout.activity_attachment_storage;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
mAttachmentStorageCurrentValue = getIntent().getIntExtra(EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE, Constants.MAX_ATTACHMENT_STORAGE_IN_MB);
if (mAttachmentStorageCurrentValue == -1) {
mSeekBar.setProgress(5);
mStorageTextValue.setText(getString(R.string.attachment_storage_value_current_unlimited));
} else {
mStorageTextValue.setText(String.format(getString(R.string.attachment_storage_value_current), mAttachmentStorageCurrentValue));
mSeekBar.setProgress((mAttachmentStorageCurrentValue / Constants.MIN_ATTACHMENT_STORAGE_IN_MB) - 1); // 0-based
}
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mSeekBar.setProgress(progress);
if (progress == 5) {
mAttachmentStorageCurrentValue = -1;
mStorageTextValue.setText(getString(R.string.attachment_storage_value_current_unlimited));
return;
}
int value = (progress + 1) * Constants.MIN_ATTACHMENT_STORAGE_IN_MB;
mAttachmentStorageCurrentValue = value;
mStorageTextValue.setText(String.format(getString(R.string.attachment_storage_value_current), value));
User user = mUserManager.getCurrentLegacyUser();
boolean attachmentStorageChanged = mAttachmentStorageCurrentValue != user.getMaxAttachmentStorage();
if (attachmentStorageChanged) {
user.setMaxAttachmentStorage(mAttachmentStorageCurrentValue);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// noop
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// noop
}
});
}
@OnClick(R.id.clear_local_cache)
public void onLocalCacheClearClicked() {
AttachmentClearingService.startClearUpImmediatelyService(
getApplicationContext(),
mUserManager.requireCurrentUserId()
);
TextExtensions.showToast(this, R.string.local_storage_cleared, Toast.LENGTH_SHORT);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
saveLastInteraction();
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
setResult(Activity.RESULT_OK);
saveLastInteraction();
finish();
}
}

View File

@ -71,6 +71,7 @@ import ch.protonmail.android.jobs.FetchByLocationJob
import ch.protonmail.android.mailbox.data.local.ConversationDao
import ch.protonmail.android.servers.notification.CHANNEL_ID_EMAIL
import ch.protonmail.android.settings.pin.PinSettingsActivity
import ch.protonmail.android.settings.presentation.AttachmentStorageActivity
import ch.protonmail.android.settings.presentation.CustomDividerItemDecoration
import ch.protonmail.android.settings.presentation.SnoozeNotificationsActivity
import ch.protonmail.android.uiModel.SettingsItemUiModel

View File

@ -65,7 +65,6 @@ object Constants {
const val MAX_ATTACHMENT_FILE_SIZE_IN_BYTES = (25 * 1000 * 1000).toLong() // 25 MB
const val MAX_ATTACHMENT_STORAGE_IN_MB = 1000
const val MIN_ATTACHMENT_STORAGE_IN_MB = 200
const val MAX_EMAILS_PER_CONTACT_GROUP = 25
const val MAX_USERNAME_LENGTH = 40
const val MAX_INCORRECT_PIN_ATTEMPTS = 10
const val MAX_INTENT_STRING_SIZE = 200000

View File

@ -0,0 +1,110 @@
/*
* Copyright (c) 2020 Proton Technologies AG
*
* This file is part of ProtonMail.
*
* ProtonMail is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProtonMail is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
*/
package ch.protonmail.android.settings.presentation
import android.os.Bundle
import android.view.MenuItem
import android.widget.TextView
import android.widget.Toast
import butterknife.OnClick
import ch.protonmail.android.R
import ch.protonmail.android.activities.BaseActivity
import ch.protonmail.android.core.Constants
import ch.protonmail.android.storage.AttachmentClearingService
import ch.protonmail.android.utils.extensions.showToast
import com.google.android.material.slider.Slider
class AttachmentStorageActivity : BaseActivity() {
private val slider by lazy { findViewById<Slider>(R.id.attachment_storage_value) }
private val storageTextValue by lazy { findViewById<TextView>(R.id.storage_text_value) }
private var mAttachmentStorageCurrentValue = 0
override fun getLayoutId(): Int {
return R.layout.activity_attachment_storage
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val actionBar = supportActionBar
actionBar?.setDisplayHomeAsUpEnabled(true)
val elevation = resources.getDimensionPixelSize(R.dimen.action_bar_elevation).toFloat()
actionBar?.elevation = elevation
mAttachmentStorageCurrentValue =
intent.getIntExtra(EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE, Constants.MAX_ATTACHMENT_STORAGE_IN_MB)
if (mAttachmentStorageCurrentValue == -1) {
slider.value = MAX_STORAGE_VALUE.toFloat()
storageTextValue.text = getString(R.string.attachment_storage_value_current_unlimited)
} else {
storageTextValue.text =
String.format(getString(R.string.attachment_storage_value_current), mAttachmentStorageCurrentValue)
slider.value = mAttachmentStorageCurrentValue.toFloat()
}
slider.addOnChangeListener(
Slider.OnChangeListener { slider, value, _ ->
slider.value = value
if (value == MAX_STORAGE_VALUE.toFloat()) {
mAttachmentStorageCurrentValue = -1
storageTextValue.text = getString(R.string.attachment_storage_value_current_unlimited)
return@OnChangeListener
}
mAttachmentStorageCurrentValue = value.toInt()
storageTextValue.text =
String.format(getString(R.string.attachment_storage_value_current), mAttachmentStorageCurrentValue)
val user = mUserManager.currentLegacyUser
val attachmentStorageChanged = mAttachmentStorageCurrentValue != user?.maxAttachmentStorage
if (attachmentStorageChanged) {
user?.maxAttachmentStorage = mAttachmentStorageCurrentValue
}
})
}
@OnClick(R.id.clear_local_cache)
fun onLocalCacheClearClicked() {
AttachmentClearingService.startClearUpImmediatelyService(
applicationContext,
mUserManager.requireCurrentUserId()
)
this.showToast(R.string.local_storage_cleared, Toast.LENGTH_SHORT)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val itemId = item.itemId
if (itemId == android.R.id.home) {
saveLastInteraction()
finish()
return true
}
return super.onOptionsItemSelected(item)
}
override fun onBackPressed() {
setResult(RESULT_OK)
saveLastInteraction()
finish()
}
companion object {
const val EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE = "EXTRA_SETTINGS_ATTACHMENT_STORAGE_VALUE"
const val MAX_STORAGE_VALUE = 1200
}
}

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (c) 2020 Proton Technologies AG
This file is part of ProtonMail.
@ -18,7 +17,6 @@ You should have received a copy of the GNU General Public License
along with ProtonMail. If not, see https://www.gnu.org/licenses/.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@ -30,34 +28,28 @@ along with ProtonMail. If not, see https://www.gnu.org/licenses/.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingEnd="@dimen/view_padding"
android:paddingLeft="@dimen/view_padding"
android:paddingRight="@dimen/view_padding"
android:paddingStart="@dimen/view_padding">
android:orientation="vertical">
<ch.protonmail.android.views.CustomFontTextView
<TextView
android:id="@+id/description"
style="@style/Proton.Text.DefaultSmall.Weak"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/fields_default_space"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:text="@string/attachment_offline_max_storage"
android:textColor="@color/iron_gray"
android:textSize="@dimen/h4"
app:fontName="Roboto-Light.ttf" />
android:layout_marginTop="@dimen/padding_xl"
android:layout_marginBottom="@dimen/padding_xl"
android:paddingStart="@dimen/padding_l"
android:paddingEnd="@dimen/padding_l"
android:text="@string/attachment_offline_max_storage" />
<ch.protonmail.android.views.CustomFontTextView
<TextView
style="@style/Proton.Text.Default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/fields_default_space"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:text="@string/storage_limit"
android:textSize="@dimen/h2"
app:fontName="Roboto-Light.ttf" />
android:layout_marginBottom="@dimen/padding_l"
android:paddingStart="@dimen/padding_l"
android:paddingEnd="@dimen/padding_l"
android:text="@string/storage_limit" />
<LinearLayout
android:layout_width="match_parent"
@ -66,89 +58,78 @@ along with ProtonMail. If not, see https://www.gnu.org/licenses/.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:paddingStart="@dimen/padding_l"
android:paddingEnd="@dimen/padding_l">
<ch.protonmail.android.views.CustomFontTextView
<TextView
style="@style/Proton.Text.DefaultSmall.Weak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="200MB"
android:textColor="@color/iron_gray"
android:textSize="@dimen/h4"
app:fontName="Roboto-Light.ttf" />
android:text="200MB" />
<ch.protonmail.android.views.CustomFontTextView
<TextView
style="@style/Proton.Text.DefaultSmall.Weak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="@string/unlimited"
android:textColor="@color/iron_gray"
android:textSize="@dimen/h4"
app:fontName="Roboto-Light.ttf" />
android:text="@string/unlimited" />
</RelativeLayout>
<androidx.appcompat.widget.AppCompatSeekBar
<com.google.android.material.slider.Slider
android:id="@+id/attachment_storage_value"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:max="5" />
android:layout_marginStart="@dimen/padding_m"
android:layout_marginEnd="@dimen/padding_m"
android:stepSize="200"
android:valueFrom="200"
android:valueTo="1200" />
</LinearLayout>
<ch.protonmail.android.views.CustomFontTextView
<TextView
android:id="@+id/storage_text_value"
style="@style/Proton.Text.DefaultSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/fields_default_space"
android:layout_marginBottom="@dimen/fields_default_space_large"
android:minWidth="75dp"
android:textSize="@dimen/h3"
app:fontName="Roboto-Light.ttf" />
android:layout_marginBottom="@dimen/padding_l"
android:paddingStart="@dimen/padding_l"
android:paddingEnd="@dimen/padding_l" />
<include layout="@layout/horizontal_divider" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/list_divider" />
<RelativeLayout
android:id="@+id/clear_cache_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/fields_default_space"
android:minHeight="50dp">
android:padding="@dimen/padding_l">
<ch.protonmail.android.views.CustomFontButton
<Button
android:id="@+id/clear_local_cache"
style="@style/SettingsButtonBlue"
style="@style/ProtonButton"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="2dp"
android:paddingEnd="@dimen/fields_default_space"
android:paddingLeft="@dimen/fields_default_space"
android:paddingRight="@dimen/fields_default_space"
android:paddingStart="@dimen/fields_default_space"
android:text="@string/empty_data"
android:textAllCaps="true"
android:maxLines="1"
app:fontName="Roboto-Regular.ttf" />
android:text="@string/empty_data" />
<ch.protonmail.android.views.CustomFontTextView
style="@style/SettingsHeadingText"
<TextView
style="@style/Proton.Text.Default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/clear_local_cache"
android:layout_toStartOf="@id/clear_local_cache"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/clear_local_cache"
android:text="@string/local_cache_management" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/list_divider" />
</LinearLayout>
</LinearLayout>

View File

@ -964,7 +964,7 @@
<string name="combined_contacts">Combined Contacts</string>
<string name="turn_combined_contacts_on">Turn this feature on to auto-complete email addresses using contacts from all your logged in accounts.</string>
<string name="local_cache_management">Local Cache Management</string>
<string name="local_cache_management">Local Cache</string>
<string name="cache_cleared">Local Cache is Refreshed</string>
<string name="empty_data">Empty Data</string>
<!-- endregion -->