Added compact compose view

pull/162/head
M66B 5 years ago
parent 60a012efd2
commit 5286287b73

@ -150,8 +150,15 @@ public class ApplicationEx extends Application {
editor.putBoolean("suggest_sent", true); editor.putBoolean("suggest_sent", true);
editor.remove("suggest_local"); editor.remove("suggest_local");
} }
} else if (version < 703) {
if (!prefs.getBoolean("style_toolbar", true)) {
editor.putBoolean("compose_media", false);
editor.remove("style_toolbar");
}
} }
if (BuildConfig.DEBUG && false) { if (BuildConfig.DEBUG && false) {
editor.remove("app_support"); editor.remove("app_support");
editor.remove("notify_archive"); editor.remove("notify_archive");

@ -183,7 +183,7 @@ public class FragmentCompose extends FragmentBase {
private ImageButton ibReferenceDelete; private ImageButton ibReferenceDelete;
private ImageButton ibReferenceEdit; private ImageButton ibReferenceEdit;
private ImageButton ibReferenceImages; private ImageButton ibReferenceImages;
private BottomNavigationView edit_bar; private BottomNavigationView media_bar;
private BottomNavigationView bottom_navigation; private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpHeader; private Group grpHeader;
@ -199,7 +199,8 @@ public class FragmentCompose extends FragmentBase {
private boolean prefix_once = false; private boolean prefix_once = false;
private boolean monospaced = false; private boolean monospaced = false;
private boolean style = true; private boolean media = true;
private boolean compact = false;
private long working = -1; private long working = -1;
private State state = State.NONE; private State state = State.NONE;
@ -242,7 +243,8 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefix_once = prefs.getBoolean("prefix_once", true); prefix_once = prefs.getBoolean("prefix_once", true);
monospaced = prefs.getBoolean("monospaced", false); monospaced = prefs.getBoolean("monospaced", false);
style = prefs.getBoolean("style_toolbar", true); media = prefs.getBoolean("compose_media", true);
compact = prefs.getBoolean("compose_compact", false);
setTitle(R.string.page_compose); setTitle(R.string.page_compose);
setSubtitle(getResources().getQuantityString(R.plurals.page_message, 1)); setSubtitle(getResources().getQuantityString(R.plurals.page_message, 1));
@ -276,7 +278,7 @@ public class FragmentCompose extends FragmentBase {
ibReferenceDelete = view.findViewById(R.id.ibReferenceDelete); ibReferenceDelete = view.findViewById(R.id.ibReferenceDelete);
ibReferenceEdit = view.findViewById(R.id.ibReferenceEdit); ibReferenceEdit = view.findViewById(R.id.ibReferenceEdit);
ibReferenceImages = view.findViewById(R.id.ibReferenceImages); ibReferenceImages = view.findViewById(R.id.ibReferenceImages);
edit_bar = view.findViewById(R.id.edit_bar); media_bar = view.findViewById(R.id.media_bar);
bottom_navigation = view.findViewById(R.id.bottom_navigation); bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
@ -423,10 +425,10 @@ public class FragmentCompose extends FragmentBase {
PackageManager pm = getContext().getPackageManager(); PackageManager pm = getContext().getPackageManager();
Intent take_photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent take_photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent record_audio = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); Intent record_audio = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
edit_bar.getMenu().findItem(R.id.menu_take_photo).setVisible(take_photo.resolveActivity(pm) != null); media_bar.getMenu().findItem(R.id.menu_take_photo).setVisible(take_photo.resolveActivity(pm) != null);
edit_bar.getMenu().findItem(R.id.menu_record_audio).setVisible(record_audio.resolveActivity(pm) != null); media_bar.getMenu().findItem(R.id.menu_record_audio).setVisible(record_audio.resolveActivity(pm) != null);
edit_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { media_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int action = item.getItemId(); int action = item.getItemId();
@ -452,6 +454,8 @@ public class FragmentCompose extends FragmentBase {
} }
}); });
setCompact(compact);
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@ -470,7 +474,7 @@ public class FragmentCompose extends FragmentBase {
} }
}); });
view.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener); //view.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
addBackPressedListener(onBackPressedListener); addBackPressedListener(onBackPressedListener);
@ -493,7 +497,7 @@ public class FragmentCompose extends FragmentBase {
ibReferenceEdit.setVisibility(View.GONE); ibReferenceEdit.setVisibility(View.GONE);
ibReferenceImages.setVisibility(View.GONE); ibReferenceImages.setVisibility(View.GONE);
tvReference.setVisibility(View.GONE); tvReference.setVisibility(View.GONE);
edit_bar.setVisibility(View.GONE); media_bar.setVisibility(View.GONE);
bottom_navigation.setVisibility(View.GONE); bottom_navigation.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
@ -899,18 +903,21 @@ public class FragmentCompose extends FragmentBase {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_zoom).setVisible(state == State.LOADED); menu.findItem(R.id.menu_zoom).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_media_toolbar).setVisible(state == State.LOADED); menu.findItem(R.id.menu_media).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_compact).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_clear).setVisible(state == State.LOADED); menu.findItem(R.id.menu_clear).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_contact_group).setVisible(state == State.LOADED); menu.findItem(R.id.menu_contact_group).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_answer).setVisible(state == State.LOADED); menu.findItem(R.id.menu_answer).setVisible(state == State.LOADED);
menu.findItem(R.id.menu_zoom).setEnabled(!busy); menu.findItem(R.id.menu_zoom).setEnabled(!busy);
menu.findItem(R.id.menu_media_toolbar).setEnabled(!busy); menu.findItem(R.id.menu_media).setEnabled(!busy);
menu.findItem(R.id.menu_compact).setEnabled(!busy);
menu.findItem(R.id.menu_clear).setEnabled(!busy); menu.findItem(R.id.menu_clear).setEnabled(!busy);
menu.findItem(R.id.menu_contact_group).setEnabled(!busy && hasPermission(Manifest.permission.READ_CONTACTS)); menu.findItem(R.id.menu_contact_group).setEnabled(!busy && hasPermission(Manifest.permission.READ_CONTACTS));
menu.findItem(R.id.menu_answer).setEnabled(!busy); menu.findItem(R.id.menu_answer).setEnabled(!busy);
menu.findItem(R.id.menu_media_toolbar).setChecked(style); menu.findItem(R.id.menu_media).setChecked(media);
menu.findItem(R.id.menu_compact).setChecked(compact);
} }
@Override @Override
@ -923,8 +930,11 @@ public class FragmentCompose extends FragmentBase {
case R.id.menu_zoom: case R.id.menu_zoom:
onMenuZoom(); onMenuZoom();
return true; return true;
case R.id.menu_media_toolbar: case R.id.menu_media:
onMenuStyleToolbar(); onMenuMediabar();
return true;
case R.id.menu_compact:
onMenuCompact();
return true; return true;
case R.id.menu_clear: case R.id.menu_clear:
onMenuClear(); onMenuClear();
@ -971,11 +981,27 @@ public class FragmentCompose extends FragmentBase {
} }
} }
private void onMenuStyleToolbar() { private void onMenuMediabar() {
style = !style; media = !media;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("style_toolbar", style).apply(); prefs.edit().putBoolean("compose_media", media).apply();
edit_bar.setVisibility(style ? View.VISIBLE : View.GONE); media_bar.setVisibility(media ? View.VISIBLE : View.GONE);
}
private void onMenuCompact() {
compact = !compact;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("compose_compact", compact).apply();
setCompact(compact);
}
private void setCompact(boolean compact) {
bottom_navigation.setLabelVisibilityMode(compact
? LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED
: LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
ViewGroup.LayoutParams params = bottom_navigation.getLayoutParams();
params.height = Helper.dp2pixels(view.getContext(), compact ? 36 : 56);
bottom_navigation.setLayoutParams(params);
} }
private void onMenuClear() { private void onMenuClear() {
@ -3000,7 +3026,7 @@ public class FragmentCompose extends FragmentBase {
autosave = true; autosave = true;
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
edit_bar.setVisibility(style ? View.VISIBLE : View.GONE); media_bar.setVisibility(media ? View.VISIBLE : View.GONE);
bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision != null && draft.revision > 1); bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision != null && draft.revision > 1);
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision != null && !draft.revision.equals(draft.revisions)); bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision != null && !draft.revision.equals(draft.revisions));
bottom_navigation.setVisibility(View.VISIBLE); bottom_navigation.setVisibility(View.VISIBLE);
@ -3402,7 +3428,7 @@ public class FragmentCompose extends FragmentBase {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
int bottom = view.getBottom() int bottom = view.getBottom()
- edit_bar.getHeight() - media_bar.getHeight()
- Helper.dp2pixels(view.getContext(), 56); // full bottom navigation - Helper.dp2pixels(view.getContext(), 56); // full bottom navigation
int remain = bottom - etBody.getTop(); int remain = bottom - etBody.getTop();
int threshold = Helper.dp2pixels(view.getContext(), 100); int threshold = Helper.dp2pixels(view.getContext(), 100);

@ -9,7 +9,7 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/edit_bar" app:layout_constraintBottom_toTopOf="@+id/media_bar"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
@ -413,7 +413,7 @@
</ScrollView> </ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/edit_bar" android:id="@+id/media_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="36dp" android:layout_height="36dp"
android:background="?attr/colorActionBackground" android:background="?attr/colorActionBackground"

@ -8,11 +8,17 @@
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item <item
android:id="@+id/menu_media_toolbar" android:id="@+id/menu_media"
android:checkable="true" android:checkable="true"
android:title="@string/title_media_toolbar" android:title="@string/title_media_toolbar"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_compact"
android:checkable="true"
android:title="@string/title_compact"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_clear" android:id="@+id/menu_clear"
android:title="@string/title_style_clear" android:title="@string/title_style_clear"

Loading…
Cancel
Save