From 97e0d3301f4e832aabfaf664b233edaae2d3f558 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Jul 2016 22:18:35 +0200 Subject: [PATCH] do not show hidden items by default --- app/src/main/AndroidManifest.xml | 4 ++ .../simplemobiletools/filemanager/Config.java | 8 ++++ .../filemanager/Constants.java | 1 + .../filemanager/activities/AboutActivity.java | 18 +++++++++ .../activities/SettingsActivity.java | 38 ++++++++++++++++++ .../filemanager/fragments/ItemsFragment.java | 18 +++++++++ app/src/main/res/layout/activity_settings.xml | 40 +++++++++++++++++++ app/src/main/res/menu/menu_about.xml | 8 ++++ app/src/main/res/values/dimens.xml | 4 +- app/src/main/res/values/strings.xml | 4 ++ 10 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java create mode 100644 app/src/main/res/layout/activity_settings.xml create mode 100644 app/src/main/res/menu/menu_about.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e08357e0..139c2cc6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,5 +24,9 @@ + + diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Config.java b/app/src/main/java/com/simplemobiletools/filemanager/Config.java index af6c4d88..7366c287 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Config.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Config.java @@ -21,4 +21,12 @@ public class Config { public void setIsFirstRun(boolean firstRun) { mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply(); } + + public boolean getShowHidden() { + return mPrefs.getBoolean(Constants.SHOW_HIDDEN, false); + } + + public void setShowHidden(boolean show) { + mPrefs.edit().putBoolean(Constants.SHOW_HIDDEN, show).apply(); + } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Constants.java b/app/src/main/java/com/simplemobiletools/filemanager/Constants.java index c9b362fe..258b3835 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Constants.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Constants.java @@ -6,4 +6,5 @@ public class Constants { // shared preferences public static final String PREFS_KEY = "File Manager"; public static final String IS_FIRST_RUN = "is_first_run"; + public static final String SHOW_HIDDEN = "show_hidden"; } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java index 39e7cafb..0e3d7bf5 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java @@ -42,6 +42,24 @@ public class AboutActivity extends AppCompatActivity { setupRateUs(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_about, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.settings: + final Intent intent = new Intent(getApplicationContext(), SettingsActivity.class); + startActivity(intent); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + private void setupEmail() { final String email = mRes.getString(R.string.email); final String appName = mRes.getString(R.string.app_name); diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java new file mode 100644 index 00000000..203a86ce --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java @@ -0,0 +1,38 @@ +package com.simplemobiletools.filemanager.activities; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SwitchCompat; + +import com.simplemobiletools.filemanager.Config; +import com.simplemobiletools.filemanager.R; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class SettingsActivity extends AppCompatActivity { + @BindView(R.id.settings_show_hidden) SwitchCompat mShowHiddenSwitch; + + private static Config mConfig; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_settings); + mConfig = Config.newInstance(getApplicationContext()); + ButterKnife.bind(this); + + setupShowHidden(); + } + + private void setupShowHidden() { + mShowHiddenSwitch.setChecked(mConfig.getShowHidden()); + } + + @OnClick(R.id.settings_show_hidden_holder) + public void handleShowHidden() { + mShowHiddenSwitch.setChecked(!mShowHiddenSwitch.isChecked()); + mConfig.setShowHidden(mShowHiddenSwitch.isChecked()); + } +} diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index 4c7d5373..07b1d17a 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -12,6 +12,7 @@ import android.webkit.MimeTypeMap; import android.widget.AdapterView; import android.widget.ListView; +import com.simplemobiletools.filemanager.Config; import com.simplemobiletools.filemanager.Constants; import com.simplemobiletools.filemanager.R; import com.simplemobiletools.filemanager.Utils; @@ -31,6 +32,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad private List mItems; private ItemInteractionListener mListener; + private boolean mShowHidden; @Nullable @Override @@ -43,7 +45,20 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + mShowHidden = Config.newInstance(getContext()).getShowHidden(); + fillItems(); + } + @Override + public void onResume() { + super.onResume(); + if (mShowHidden != Config.newInstance(getContext()).getShowHidden()) { + mShowHidden = !mShowHidden; + fillItems(); + } + } + + private void fillItems() { final String path = getArguments().getString(Constants.PATH); mItems = getItems(path); Collections.sort(mItems); @@ -64,6 +79,9 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad for (File file : files) { final String curPath = file.getAbsolutePath(); final String curName = Utils.getFilename(curPath); + if (!mShowHidden && curName.startsWith(".")) + continue; + items.add(new FileDirItem(curPath, curName, file.isDirectory())); } return items; diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 00000000..51c1dc8e --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/menu_about.xml b/app/src/main/res/menu/menu_about.xml new file mode 100644 index 00000000..f408693c --- /dev/null +++ b/app/src/main/res/menu/menu_about.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 99cca20b..7abf40ca 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,7 +1,7 @@ 16dp - 8dp - 44dp + 10dp + 48dp 8dp 40dp 8dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f5a1a85..0b491901 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,4 +19,8 @@ Butter Knife (view injector) Copyright 2013 Jake Wharton\n\nLicensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions and limitations under the License. https://github.com/JakeWharton/butterknife + + + Settings + Show hidden files and directories