mirror of https://github.com/M66B/FairEmail.git
Added option to hide action bar on scrolling down
This commit is contained in:
parent
f40e4ec17d
commit
a15a10a8a1
|
@ -27,6 +27,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
@ -48,6 +49,7 @@ import androidx.documentfile.provider.DocumentFile;
|
|||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -64,6 +66,7 @@ import static android.app.Activity.RESULT_OK;
|
|||
public class FragmentBase extends Fragment {
|
||||
private String title = null;
|
||||
private String subtitle = " ";
|
||||
private boolean action = true;
|
||||
private boolean finish = false;
|
||||
|
||||
private long message = -1;
|
||||
|
@ -94,6 +97,28 @@ public class FragmentBase extends Fragment {
|
|||
updateSubtitle();
|
||||
}
|
||||
|
||||
protected void setActionBar(boolean show) {
|
||||
Log.i("Set action bar=" + show);
|
||||
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if (activity == null)
|
||||
return;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
boolean hide_actionbar = prefs.getBoolean("hide_actionbar", false);
|
||||
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar == null)
|
||||
return;
|
||||
|
||||
if (show || !hide_actionbar)
|
||||
actionBar.show();
|
||||
else
|
||||
actionBar.hide();
|
||||
|
||||
this.action = show;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
try {
|
||||
|
@ -176,6 +201,7 @@ public class FragmentBase extends Fragment {
|
|||
Log.d("Resume " + this);
|
||||
super.onResume();
|
||||
updateSubtitle();
|
||||
setActionBar(action);
|
||||
if (finish) {
|
||||
getParentFragmentManager().popBackStack();
|
||||
finish = false;
|
||||
|
@ -230,6 +256,13 @@ public class FragmentBase extends Fragment {
|
|||
View focused = getActivity().getCurrentFocus();
|
||||
if (focused != null)
|
||||
im.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if (activity != null) {
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null)
|
||||
actionBar.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -155,9 +155,35 @@ public class FragmentFolders extends FragmentBase {
|
|||
});
|
||||
|
||||
rvFolder.setHasFixedSize(false);
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getContext()) {
|
||||
@Override
|
||||
public void onScrollStateChanged(int state) {
|
||||
super.onScrollStateChanged(state);
|
||||
|
||||
try {
|
||||
int y = rvFolder.computeVerticalScrollOffset();
|
||||
Log.i("Scroll state=" + state + " y=" + y);
|
||||
setActionBar(y == 0);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
rvFolder.setLayoutManager(llm);
|
||||
|
||||
rvFolder.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
try {
|
||||
int y = rvFolder.computeVerticalScrollOffset();
|
||||
Log.i("Layout completed y=" + y);
|
||||
setActionBar(y == 0);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!cards) {
|
||||
DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()) {
|
||||
@Override
|
||||
|
|
|
@ -90,6 +90,7 @@ import android.widget.Toast;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
|
@ -202,6 +203,8 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
|||
import static android.text.format.DateUtils.DAY_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_WEEKDAY;
|
||||
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
|
||||
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_SETTLING;
|
||||
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_KEY_MISSING;
|
||||
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_NO_SIGNATURE;
|
||||
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED;
|
||||
|
@ -552,9 +555,35 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(int state) {
|
||||
super.onScrollStateChanged(state);
|
||||
|
||||
try {
|
||||
int y = rvMessage.computeVerticalScrollOffset();
|
||||
Log.i("Scroll state=" + state + " y=" + y);
|
||||
setActionBar(y == 0);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
rvMessage.setLayoutManager(llm);
|
||||
|
||||
rvMessage.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
try {
|
||||
int y = rvMessage.computeVerticalScrollOffset();
|
||||
Log.i("Layout completed y=" + y);
|
||||
setActionBar(y == 0);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!cards) {
|
||||
DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()) {
|
||||
@Override
|
||||
|
|
|
@ -43,6 +43,7 @@ import androidx.preference.PreferenceManager;
|
|||
public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private SwitchCompat swDoubleBack;
|
||||
private SwitchCompat swPull;
|
||||
private SwitchCompat swHideActionBar;
|
||||
private SwitchCompat swAutoScroll;
|
||||
private SwitchCompat swDoubleTap;
|
||||
private SwitchCompat swSwipeNav;
|
||||
|
@ -65,7 +66,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
private NumberPicker npDefaultSnooze;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"double_back", "pull", "autoscroll", "doubletap", "swipenav", "volumenav", "reversed",
|
||||
"double_back", "pull", "hide_actionbar", "autoscroll", "doubletap", "swipenav", "volumenav", "reversed",
|
||||
"autoexpand", "expand_all", "expand_one", "collapse_multiple",
|
||||
"autoclose", "onclose", "quick_filter", "quick_scroll",
|
||||
"autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance", "discard_delete",
|
||||
|
@ -84,6 +85,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
|
||||
swDoubleBack = view.findViewById(R.id.swDoubleBack);
|
||||
swPull = view.findViewById(R.id.swPull);
|
||||
swHideActionBar = view.findViewById(R.id.swHideActionBar);
|
||||
swAutoScroll = view.findViewById(R.id.swAutoScroll);
|
||||
swDoubleTap = view.findViewById(R.id.swDoubleTap);
|
||||
swSwipeNav = view.findViewById(R.id.swSwipeNav);
|
||||
|
@ -128,6 +130,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
}
|
||||
});
|
||||
|
||||
swHideActionBar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("hide_actionbar", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swAutoScroll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
|
@ -330,6 +339,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
|
||||
swDoubleBack.setChecked(prefs.getBoolean("double_back", true));
|
||||
swPull.setChecked(prefs.getBoolean("pull", true));
|
||||
swHideActionBar.setChecked(prefs.getBoolean("hide_actionbar", false));
|
||||
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", true));
|
||||
swDoubleTap.setChecked(prefs.getBoolean("doubletap", false));
|
||||
swSwipeNav.setChecked(prefs.getBoolean("swipenav", true));
|
||||
|
|
|
@ -40,15 +40,27 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/swDoubleBack"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swHideActionBar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_hide_actionbar"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swPull"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swAutoScroll"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:checked="true"
|
||||
android:text="@string/title_advanced_autoscroll"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swPull"
|
||||
app:layout_constraintTop_toBottomOf="@id/swHideActionBar"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
|
|
|
@ -338,6 +338,7 @@
|
|||
|
||||
<string name="title_advanced_double_back">Double \'back\' to exit</string>
|
||||
<string name="title_advanced_pull_refresh">Pull down to refresh</string>
|
||||
<string name="title_advanced_hide_actionbar">Hide action bar on scrolling down</string>
|
||||
<string name="title_advanced_autoscroll">Scroll to top on receiving new messages</string>
|
||||
<string name="title_advanced_double_tap">Double tap to mark message read/unread</string>
|
||||
<string name="title_advanced_swipenav">Swipe left/right to go to next/previous conversation</string>
|
||||
|
|
Loading…
Reference in New Issue