do not show hidden items by default

This commit is contained in:
tibbi 2016-07-13 22:18:35 +02:00
parent 19cccb1abc
commit 97e0d3301f
10 changed files with 141 additions and 2 deletions

View File

@ -24,5 +24,9 @@
<activity
android:name=".activities.LicenseActivity"
android:label="@string/third_party_licences"/>
<activity
android:name=".activities.SettingsActivity"
android:label="@string/settings"/>
</application>
</manifest>

View File

@ -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();
}
}

View File

@ -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";
}

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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<FileDirItem> 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;

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/settings_scrollview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/settings_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/settings_show_hidden_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_padding"
android:background="?android:attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_show_hidden_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/show_hidden"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_show_hidden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/settings"
android:title="@string/settings"
app:showAsAction="never"/>
</menu>

View File

@ -1,7 +1,7 @@
<resources>
<dimen name="activity_margin">16dp</dimen>
<dimen name="medium_margin">8dp</dimen>
<dimen name="icon_size">44dp</dimen>
<dimen name="medium_margin">10dp</dimen>
<dimen name="icon_size">48dp</dimen>
<dimen name="social_padding">8dp</dimen>
<dimen name="social_logo">40dp</dimen>
<dimen name="settings_padding">8dp</dimen>

View File

@ -19,4 +19,8 @@
<string name="butterknife_title"><u>Butter Knife (view injector)</u></string>
<string name="butterknife_text">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.</string>
<string name="butterknife_url">https://github.com/JakeWharton/butterknife</string>
<!-- Settings -->
<string name="settings">Settings</string>
<string name="show_hidden">Show hidden files and directories</string>
</resources>