Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
Expand All @@ -23,7 +24,6 @@
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -32,6 +32,7 @@

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationBarView;

import net.gsantner.markor.BuildConfig;
import net.gsantner.markor.R;
Expand Down Expand Up @@ -99,6 +100,8 @@ public void onPageSelected(int position) {
});

setSupportActionBar(findViewById(R.id.toolbar));
applyActivityBarBackgroundColors();
applyMainBottomTabBarAppearance();
optShowRate();

// Setup viewpager
Expand Down Expand Up @@ -147,7 +150,7 @@ public void onActivityFirstTimeVisible() {

@Override
public Integer getNewNavigationBarColor() {
return ContextCompat.getColor(this, R.color.primary);
return _appSettings.getConfiguredBarBackgroundColor();
}

@Override
Expand Down Expand Up @@ -293,6 +296,7 @@ protected void onResume() {
}

_cu.setKeepScreenOn(this, _appSettings.isKeepScreenOn());
applyMainBottomTabBarAppearance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.isMultiWindowEnabled()) {
setTaskDescription(new ActivityManager.TaskDescription(getString(R.string.app_name)));
}
Expand All @@ -318,6 +322,31 @@ public void onPostResume() {
super.onPostResume();
}

private void applyMainBottomTabBarAppearance() {
if (_bottomNav == null) {
return;
}

final boolean showTabTitles = _appSettings.isMainBottomBarTabTitlesShown();
final int barColor = _appSettings.getConfiguredBarBackgroundColor();

_bottomNav.setBackgroundColor(barColor);
_bottomNav.setItemBackground(new ColorDrawable(barColor));
_bottomNav.setLabelVisibilityMode(showTabTitles
? NavigationBarView.LABEL_VISIBILITY_LABELED
: NavigationBarView.LABEL_VISIBILITY_UNLABELED);
applyMainBottomTabBarMinHeight(showTabTitles);
}

private void applyMainBottomTabBarMinHeight(final boolean showTabTitles) {
final int minHeight = getResources().getDimensionPixelSize(showTabTitles
? R.dimen.main_bottom_bar_min_height_labeled
: R.dimen.main_bottom_bar_min_height_unlabeled);
if (_bottomNav.getMinimumHeight() != minHeight) {
_bottomNav.setMinimumHeight(minHeight);
}
}

// Cycle between recent, favourite, and current
public boolean onLongClickFab(View view) {
if (_notebook != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;

import net.gsantner.markor.R;
Expand All @@ -32,6 +33,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}

@Override
protected void onResume() {
super.onResume();
applyActivityBarBackgroundColors();
}

protected boolean onReceiveKeyPress(GsFragmentBase fragment, int keyCode, KeyEvent event) {
return fragment.onReceiveKeyPress(keyCode, event);
}
Expand All @@ -49,6 +56,17 @@ public Integer getNewActivityBackgroundColor() {
return _appSettings.getAppThemeName().contains("black") ? Color.BLACK : null;
}

public void applyActivityBarBackgroundColors() {
final int backgroundColor = _appSettings.getConfiguredBarBackgroundColor();

final Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setBackgroundColor(backgroundColor);
}

_cu.setStatusbarColor(this, backgroundColor);
}

@Override
protected AppSettings createAppSettingsInstance() {
return new AppSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
Expand Down Expand Up @@ -57,7 +56,6 @@ public static class RESULT {
}

public static int activityRetVal = RESULT.NOCHANGE;
private static int iconColor = Color.WHITE;

protected Toolbar toolbar;

Expand All @@ -72,7 +70,6 @@ public void onCreate(Bundle b) {

// Custom code
GsFontPreferenceCompat.additionalyCheckedFolder = new File(_appSettings.getNotebookDirectory(), ".app/fonts");
iconColor = _cu.rcolor(this, R.color.primary_text);
toolbar.setTitle(R.string.settings);
setSupportActionBar(findViewById(R.id.toolbar));
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp));
Expand Down Expand Up @@ -191,7 +188,6 @@ public void doUpdatePreferences() {
R.string.pref_key__swipe_to_change_mode,
R.string.pref_key__todotxt__hl_delay,
R.string.pref_key__markdown__hl_delay_v2,
R.string.pref_key__theming_hide_system_statusbar,
R.string.pref_key__tab_width_v2,
R.string.pref_key__editor_line_spacing,
};
Expand Down Expand Up @@ -223,6 +219,13 @@ protected void onPreferenceChanged(final SharedPreferences prefs, final String k
} else if (eq(key, R.string.pref_key__theming_hide_system_statusbar)) {
activityRetVal = RESULT.RESTART_REQ;
_appSettings.setRecreateMainRequired(true);
} else if (eq(key, R.string.pref_key__ui_flat_top_bottom_bars)) {
final Activity activity = getActivity();
if (activity instanceof MarkorBaseActivity) {
((MarkorBaseActivity) activity).applyActivityBarBackgroundColors();
}
} else if (eq(key, R.string.pref_key__file_browser_show_dividers)) {
_appSettings.setRecreateMainRequired(true);
} else if (eq(key, R.string.pref_key__is_launcher_for_special_files_enabled)) {
boolean extraLaunchersEnabled = prefs.getBoolean(key, false);
new MarkorContextUtils(getActivity()).applySpecialLaunchersVisibility(getActivity(), extraLaunchersEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static void updateFsViewerOpts(final GsFileBrowserOptions.Options opts, f
opts.popularFiles = appSettings.getPopularFiles();

opts.descriptionFormat = appSettings.getString(R.string.pref_key__file_description_format, "");
opts.primaryColor = appSettings.isFlatTopBottomBarColorEnabled() ? R.color.background : R.color.primary;
opts.showDividers = appSettings.isFileBrowserDividerEnabled();

final File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
opts.addVirtualFile("Download", downloads, R.drawable.baseline_download_24);
Expand Down
27 changes: 23 additions & 4 deletions app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,29 @@ public String getAppThemeName() {
return getString(R.string.pref_key__app_theme, _context.getString(R.string.app_theme_system));
}

public boolean isFlatTopBottomBarColorEnabled() {
return getBool(R.string.pref_key__ui_flat_top_bottom_bars, false);
}

public boolean isMainBottomBarTabTitlesShown() {
return getBool(R.string.pref_key__main_bottom_bar_show_tab_titles, true);
}

public boolean isFileBrowserDividerEnabled() {
return getBool(R.string.pref_key__file_browser_show_dividers, true);
}

public @ColorInt int getUiBackgroundColor() {
if (getAppThemeName().contains("black")) {
return Color.BLACK;
}
return rcolor(R.color.background);
}

public @ColorInt int getConfiguredBarBackgroundColor() {
return isFlatTopBottomBarColorEnabled() ? getUiBackgroundColor() : rcolor(R.color.primary);
}

public void setEditorBasicColor(boolean forDarkMode, @ColorRes int fgColor, @ColorRes int bgColor) {
int resIdFg = forDarkMode ? R.string.pref_key__basic_color_scheme__fg_dark : R.string.pref_key__basic_color_scheme__fg_light;
int resIdBg = forDarkMode ? R.string.pref_key__basic_color_scheme__bg_dark : R.string.pref_key__basic_color_scheme__bg_light;
Expand Down Expand Up @@ -802,10 +825,6 @@ public boolean isFileBrowserSortFolderFirst() {
return getBool(R.string.pref_key__filesystem_folder_first, true);
}

public String getNavigationBarColor() {
return getString(R.string.pref_key__navigationbar_color, "#000000");
}

public String getAppStartupFolderMenuId() {
return getString(R.string.pref_key__app_start_folder, "notebook");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
@SuppressWarnings({"WeakerAccess", "unused", "UnusedReturnValue"})
public abstract class GsPreferenceFragmentBase<AS extends GsSharedPreferencesPropertyBackend> extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener, PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
private static final int DEFAULT_ICON_TINT_DELAY = 200;
protected boolean _isDividerVisible = false;

//
Expand Down Expand Up @@ -167,23 +166,27 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

// on bottom
afterOnCreate(savedInstanceState, activity);
tintPreferenceIcons();
}

public final GsCallback.a1<PreferenceFragmentCompat> updatePreferenceIcons = (frag) -> {
private void tintPreferenceIcons() {
try {
View view = frag.getView();
final Integer color = getIconTintColor();
if (view != null && color != null) {
Runnable r = () -> tintAllPrefIcons(frag, color);
for (long delayFactor : new int[]{1, 10, 50, 100, 500}) {
view.postDelayed(r, delayFactor * DEFAULT_ICON_TINT_DELAY);
}
if (color == null) {
return;
}

tintAllPrefIcons(color);

final View view = getView();
if (view != null) {
view.post(() -> tintAllPrefIcons(color));
}
} catch (Exception ignored) {
}
};
}

public void tintAllPrefIcons(PreferenceFragmentCompat preferenceFragment, @ColorInt int iconColor) {
public void tintAllPrefIcons(@ColorInt int iconColor) {
tintPrefIconsRecursive(getPreferenceScreen(), iconColor);
}

Expand Down Expand Up @@ -231,7 +234,6 @@ protected int keyToStringResId(String keyAsString) {
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
updatePreferenceIcons.callback(this);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
view.postDelayed(() -> {
Expand Down Expand Up @@ -343,7 +345,7 @@ public void onStop() {
public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) {
_prefScreenBackstack.add(getPreferenceScreen());
preferenceFragmentCompat.setPreferenceScreen(preferenceScreen);
updatePreferenceIcons.callback(this);
tintPreferenceIcons();
onPreferenceScreenChangedPriv(preferenceFragmentCompat, preferenceScreen);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void onViewCreated(final View root, final @Nullable Bundle savedInstanceS

root.setBackgroundColor(rcolor(_dopt.backgroundColor));

GsFileBrowserFragment.addDivider(activity, _recyclerList);
GsFileBrowserFragment.addDivider(activity, _recyclerList, _dopt.showDividers);

_recyclerList.setItemViewCacheSize(20);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat
}
setDialogOptions(((FilesystemFragmentOptionsListener) activity).getFilesystemFragmentOptions(_dopt));

addDivider(activity, _recyclerList);
addDivider(activity, _recyclerList, _dopt.showDividers);

_filesystemViewerAdapter = new GsFileBrowserListAdapter(_dopt, activity);
_recyclerList.setAdapter(_filesystemViewerAdapter);
Expand Down Expand Up @@ -636,11 +636,15 @@ public MarkorContextUtils createContextUtilsInstance(Context context) {
return new MarkorContextUtils(context);
}

public static void addDivider(final Activity activity, final RecyclerView recyclerView) {
public static void addDivider(final Activity activity, final RecyclerView recyclerView, final boolean showDividers) {
if (recyclerView == null || activity == null) {
return;
}

if (!showDividers) {
return;
}

final LinearLayoutManager lam = (LinearLayoutManager) recyclerView.getLayoutManager();

if (lam == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public static class Options {
@ColorRes
public int folderColor = 0;

public boolean showDividers = true;

public final Map<File, File> storageMaps = new LinkedHashMap<>();
public final Map<File, Integer> iconMaps = new HashMap<>();
public Collection<File> favouriteFiles, recentFiles, popularFiles = null;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/bottomnav_color_selector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/accent" android:state_checked="true" />
<item android:color="@color/white" />
</selector>
</selector>
Loading
Loading