Moved compact view option to menu

pull/147/head
M66B 6 years ago
parent f792f22ad6
commit 336d2947d0

@ -41,7 +41,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
private boolean contacts;
private static String[] restart = new String[]{
"unified", "threading", "compact", "avatars", "identicons", "preview", "addresses",
"unified", "threading", "avatars", "identicons", "preview", "addresses",
"pull", "actionbar", "autoclose", "autonext", "confirm", "debug"
};

@ -117,12 +117,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private FragmentManager fragmentManager;
private ViewType viewType;
private boolean outgoing;
private boolean compact;
private int zoom;
private boolean internet;
private IProperties properties;
private boolean threading;
private boolean compact;
private boolean contacts;
private boolean avatars;
private boolean identicons;
@ -1955,13 +1955,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
AdapterMessage(Context context, LifecycleOwner owner, FragmentManager fragmentManager,
ViewType viewType, boolean outgoing, int zoom, IProperties properties) {
ViewType viewType, boolean outgoing, boolean compact, int zoom, IProperties properties) {
this.context = context;
this.owner = owner;
this.inflater = LayoutInflater.from(context);
this.fragmentManager = fragmentManager;
this.viewType = viewType;
this.outgoing = outgoing;
this.compact = compact;
this.zoom = zoom;
this.internet = (Helper.isMetered(context, false) != null);
this.properties = properties;
@ -1969,7 +1970,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.threading = prefs.getBoolean("threading", true);
this.compact = prefs.getBoolean("compact", false);
this.contacts = (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED);
this.avatars = (prefs.getBoolean("avatars", true) && this.contacts);
@ -1998,6 +1998,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return differ.getCurrentList();
}
void setCompact(boolean compact) {
if (this.compact != compact) {
this.compact = compact;
notifyDataSetChanged();
}
}
void setZoom(int zoom) {
if (this.zoom != zoom) {
this.zoom = zoom;
@ -2014,6 +2021,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
}
@Override
public int getItemViewType(int position) {
return (compact ? R.layout.item_message_compact : R.layout.item_message_normal);
}
@Override
public int getItemCount() {
return differ.getItemCount();
@ -2042,10 +2054,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(inflater.inflate(
compact ? R.layout.item_message_compact : R.layout.item_message_normal,
parent,
false));
return new ViewHolder(inflater.inflate(viewType, parent, false));
}
@Override

@ -87,7 +87,6 @@ public class FragmentMessages extends FragmentEx {
private ImageButton ibHintSupport;
private ImageButton ibHintSwipe;
private ImageButton ibHintSelect;
private ImageButton ibHintCompact;
private TextView tvNoEmail;
private FixedRecyclerView rvMessage;
private BottomNavigationView bottom_navigation;
@ -96,7 +95,6 @@ public class FragmentMessages extends FragmentEx {
private Group grpHintSupport;
private Group grpHintSwipe;
private Group grpHintSelect;
private Group grpHintCompact;
private Group grpReady;
private FloatingActionButton fab;
private FloatingActionButton fabMore;
@ -108,7 +106,6 @@ public class FragmentMessages extends FragmentEx {
private long id;
private String search;
private boolean compact;
private boolean threading;
private boolean pull;
private boolean actionbar;
@ -165,7 +162,6 @@ public class FragmentMessages extends FragmentEx {
viewType = AdapterMessage.ViewType.SEARCH;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
compact = prefs.getBoolean("compact", false);
if (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)
pull = prefs.getBoolean("pull", true);
@ -193,7 +189,6 @@ public class FragmentMessages extends FragmentEx {
ibHintSupport = view.findViewById(R.id.ibHintSupport);
ibHintSwipe = view.findViewById(R.id.ibHintSwipe);
ibHintSelect = view.findViewById(R.id.ibHintSelect);
ibHintCompact = view.findViewById(R.id.ibHintCompact);
tvNoEmail = view.findViewById(R.id.tvNoEmail);
rvMessage = view.findViewById(R.id.rvMessage);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
@ -202,7 +197,6 @@ public class FragmentMessages extends FragmentEx {
grpHintSupport = view.findViewById(R.id.grpHintSupport);
grpHintSwipe = view.findViewById(R.id.grpHintSwipe);
grpHintSelect = view.findViewById(R.id.grpHintSelect);
grpHintCompact = view.findViewById(R.id.grpHintCompact);
grpReady = view.findViewById(R.id.grpReady);
fab = view.findViewById(R.id.fab);
fabMore = view.findViewById(R.id.fabMore);
@ -312,25 +306,18 @@ public class FragmentMessages extends FragmentEx {
}
});
ibHintCompact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
prefs.edit().putBoolean("message_compact", true).apply();
grpHintCompact.setVisibility(View.GONE);
}
});
rvMessage.setHasFixedSize(false);
//rvMessage.setItemViewCacheSize(10);
//rvMessage.getRecycledViewPool().setMaxRecycledViews(0, 10);
LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvMessage.setLayoutManager(llm);
boolean compact = prefs.getBoolean("compact", false);
int zoom = prefs.getInt("zoom", compact ? 0 : 1);
adapter = new AdapterMessage(
getContext(), getViewLifecycleOwner(), getFragmentManager(),
viewType, outgoing,
zoom,
compact, zoom,
new AdapterMessage.IProperties() {
@Override
public void setValue(String name, long id, boolean enabled) {
@ -1306,7 +1293,6 @@ public class FragmentMessages extends FragmentEx {
grpHintSupport.setVisibility(prefs.getBoolean("app_support", false) || !hints ? View.GONE : View.VISIBLE);
grpHintSwipe.setVisibility(prefs.getBoolean("message_swipe", false) || !hints ? View.GONE : View.VISIBLE);
grpHintSelect.setVisibility(prefs.getBoolean("message_select", false) || !hints ? View.GONE : View.VISIBLE);
grpHintCompact.setVisibility(prefs.getBoolean("message_compact", false) || !hints ? View.GONE : View.VISIBLE);
final DB db = DB.getInstance(getContext());
@ -1435,7 +1421,9 @@ public class FragmentMessages extends FragmentEx {
cm.registerNetworkCallback(builder.build(), networkCallback);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = prefs.getBoolean("compact", false);
int zoom = prefs.getInt("zoom", compact ? 0 : 1);
adapter.setCompact(compact);
adapter.setZoom(zoom);
}
@ -1557,6 +1545,9 @@ public class FragmentMessages extends FragmentEx {
menu.findItem(R.id.menu_search).setVisible(
folder >= 0 && viewType != AdapterMessage.ViewType.SEARCH);
menu.findItem(R.id.menu_folders).setVisible(primary >= 0);
menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24);
menu.findItem(R.id.menu_sort_on).setVisible(
viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER);
@ -1570,8 +1561,7 @@ public class FragmentMessages extends FragmentEx {
else if ("sender".equals(sort))
menu.findItem(R.id.menu_sort_on_sender).setChecked(true);
menu.findItem(R.id.menu_folders).setVisible(primary >= 0);
menu.findItem(R.id.menu_folders).setIcon(connected ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24);
menu.findItem(R.id.menu_compact).setChecked(prefs.getBoolean("compact", false));
menu.findItem(R.id.menu_snoozed).setVisible(!outbox &&
(viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER));
@ -1585,6 +1575,11 @@ public class FragmentMessages extends FragmentEx {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_folders:
onMenuFolders();
loadMessages();
return true;
case R.id.menu_sort_on_time:
item.setChecked(true);
onMenuSort("time");
@ -1605,17 +1600,16 @@ public class FragmentMessages extends FragmentEx {
onMenuSort("sender");
return true;
case R.id.menu_snoozed:
onMenuSnoozed();
return true;
case R.id.menu_zoom:
onMenuZoom();
return true;
case R.id.menu_folders:
onMenuFolders();
loadMessages();
case R.id.menu_compact:
onMenuCompact();
return true;
case R.id.menu_snoozed:
onMenuSnoozed();
return true;
case R.id.menu_move_sent:
@ -1627,40 +1621,49 @@ public class FragmentMessages extends FragmentEx {
}
}
private void onMenuSort(String sort) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putString("sort", sort).apply();
loadMessages();
private void onMenuFolders() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack("unified", 0);
Bundle args = new Bundle();
args.putLong("account", primary);
FragmentFolders fragment = new FragmentFolders();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("folders");
fragmentTransaction.commit();
}
private void onMenuSnoozed() {
private void onMenuSort(String sort) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean snoozed = prefs.getBoolean("snoozed", false);
prefs.edit().putBoolean("snoozed", !snoozed).apply();
prefs.edit().putString("sort", sort).apply();
loadMessages();
}
private void onMenuZoom() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = prefs.getBoolean("compact", false);
int zoom = prefs.getInt("zoom", compact ? 0 : 1);
zoom = ++zoom % 3;
prefs.edit().putInt("zoom", zoom).apply();
adapter.setZoom(zoom);
}
private void onMenuFolders() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack("unified", 0);
Bundle args = new Bundle();
args.putLong("account", primary);
FragmentFolders fragment = new FragmentFolders();
fragment.setArguments(args);
private void onMenuCompact() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = !prefs.getBoolean("compact", false);
prefs.edit().putBoolean("compact", compact).apply();
adapter.setCompact(compact);
getActivity().invalidateOptionsMenu();
}
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("folders");
fragmentTransaction.commit();
private void onMenuSnoozed() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean snoozed = prefs.getBoolean("snoozed", false);
prefs.edit().putBoolean("snoozed", !snoozed).apply();
loadMessages();
}
private void onMenuMoveSent() {

@ -63,7 +63,6 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private SwitchCompat swUnified;
private SwitchCompat swThreading;
private SwitchCompat swCompact;
private SwitchCompat swAvatars;
private SwitchCompat swIdenticons;
private SwitchCompat swPreview;
@ -92,12 +91,12 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private final static String[] ADVANCED_OPTIONS = new String[]{
"enabled", "updates",
"metered", "download",
"unified", "threading", "compact", "avatars", "identicons", "preview", "addresses",
"unified", "threading", "avatars", "identicons", "preview", "addresses",
"pull", "swipe", "actionbar", "autoclose", "autonext",
"autoread", "collapse", "automove", "confirm", "sender", "autoresize", "autosend",
"light", "sound", "debug",
"first", "why", "last_update_check",
"app_support", "message_swipe", "message_select", "message_compact",
"app_support", "message_swipe", "message_select",
"folder_actions", "folder_sync",
};
@ -119,7 +118,6 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swUnified = view.findViewById(R.id.swUnified);
swThreading = view.findViewById(R.id.swThreading);
swCompact = view.findViewById(R.id.swCompact);
swAvatars = view.findViewById(R.id.swAvatars);
swIdenticons = view.findViewById(R.id.swIdenticons);
swPreview = view.findViewById(R.id.swPreview);
@ -199,14 +197,6 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
}
});
swCompact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("compact", checked).apply();
prefs.edit().remove("zoom").apply();
}
});
swAvatars.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -458,7 +448,6 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swUnified.setChecked(prefs.getBoolean("unified", true));
swThreading.setChecked(prefs.getBoolean("threading", true));
swCompact.setChecked(prefs.getBoolean("compact", false));
swAvatars.setChecked(prefs.getBoolean("avatars", true));
swIdenticons.setChecked(prefs.getBoolean("identicons", false));
swPreview.setChecked(prefs.getBoolean("preview", false));

@ -136,37 +136,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibHintSelect" />
<TextView
android:id="@+id/tvHintCompact"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="33dp"
android:padding="6dp"
android:text="@string/title_hint_message_compact"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toStartOf="@+id/ibHintCompact"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintSelect" />
<ImageButton
android:id="@+id/ibHintCompact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_close_24"
app:layout_constraintBottom_toBottomOf="@id/tvHintCompact"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvHintCompact" />
<View
android:id="@+id/vSeparatorHintCompact"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibHintCompact" />
<TextView
android:id="@+id/tvNoEmail"
android:layout_width="wrap_content"
@ -176,7 +145,7 @@
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintCompact" />
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintSelect" />
<eu.faircode.email.FixedRecyclerView
android:id="@+id/rvMessage"
@ -187,7 +156,7 @@
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintCompact" />
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintSelect" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait"
@ -237,12 +206,6 @@
android:layout_height="0dp"
app:constraint_referenced_ids="tvHintSelect,ibHintSelect,vSeparatorHintSelect" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpHintCompact"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvHintCompact,ibHintCompact,vSeparatorHintCompact" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:layout_width="0dp"

@ -232,18 +232,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swThreading" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCompact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_compact"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvThreadingHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAvatars"
android:layout_width="match_parent"
@ -253,7 +241,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_avatars"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCompact"
app:layout_constraintTop_toBottomOf="@id/tvThreadingHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -9,6 +9,12 @@
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|always" />
<item
android:id="@+id/menu_folders"
android:icon="@drawable/baseline_folder_open_24"
android:title="@string/title_folder_primary"
app:showAsAction="always" />
<item
android:id="@+id/menu_sort_on"
android:icon="@drawable/baseline_sort_24"
@ -39,10 +45,10 @@
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_folders"
android:icon="@drawable/baseline_folder_open_24"
android:title="@string/title_folder_primary"
app:showAsAction="always" />
android:id="@+id/menu_compact"
android:checkable="true"
android:title="@string/title_compact"
app:showAsAction="never" />
<item
android:id="@+id/menu_snoozed"

@ -130,7 +130,6 @@
<string name="title_advanced_unified">Unified inbox</string>
<string name="title_advanced_threading">Conversation threading</string>
<string name="title_advanced_compact">Compact message view</string>
<string name="title_advanced_avatars">Show contact photos</string>
<string name="title_advanced_identicons">Show identicons</string>
<string name="title_advanced_preview">Show message preview</string>
@ -360,6 +359,7 @@
<string name="title_sort_on_starred">Starred</string>
<string name="title_sort_on_sender">Sender</string>
<string name="title_compact">Compact view</string>
<string name="title_zoom">Text size</string>
<string name="title_address_sent">Sent:</string>
@ -421,7 +421,6 @@
<string name="title_hint_support">If you have a question or a problem, please use the support menu to get help</string>
<string name="title_hint_message_actions">Swipe left to trash; swipe right to archive (if available)</string>
<string name="title_hint_message_selection">Long press a message to start selecting multiple messages</string>
<string name="title_hint_message_compact">You can select a more compact message view in the advanced options</string>
<string name="title_hint_sync">Downloading messages can take some time, depending on the speed of the provider, internet connection and device and on the number of messages. While downloading messages the app might respond slower.</string>
<string name="title_open_link">Open link</string>

Loading…
Cancel
Save