add toggling between displaying full / not full path
This commit is contained in:
parent
252803eaa6
commit
6afd28e41b
2 changed files with 43 additions and 4 deletions
|
@ -14,8 +14,10 @@ import android.widget.TextView;
|
|||
import com.simplemobiletools.filemanager.models.FileDirItem;
|
||||
|
||||
public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
||||
private LayoutInflater mInflater;
|
||||
private int mDeviceWidth;
|
||||
private boolean mShowFullPath;
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private BreadcrumbsListener mListener;
|
||||
|
||||
public Breadcrumbs(Context context, AttributeSet attrs) {
|
||||
|
@ -100,8 +102,13 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
|||
}
|
||||
|
||||
public void setInitialBreadcrumb(String fullPath) {
|
||||
mShowFullPath = Config.newInstance(getContext()).getShowFullPath();
|
||||
final String basePath = Environment.getExternalStorageDirectory().toString();
|
||||
final String tempPath = fullPath.replace(basePath, getContext().getString(R.string.initial_breadcrumb) + "/");
|
||||
String tempPath = fullPath;
|
||||
if (!mShowFullPath) {
|
||||
tempPath = fullPath.replace(basePath, getContext().getString(R.string.initial_breadcrumb) + "/");
|
||||
}
|
||||
|
||||
removeAllViewsInLayout();
|
||||
final String[] dirs = tempPath.split("/");
|
||||
String currPath = basePath;
|
||||
|
@ -109,13 +116,19 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
|||
final String dir = dirs[i];
|
||||
if (i > 0) {
|
||||
currPath += dir + "/";
|
||||
} else if (mShowFullPath) {
|
||||
addRootFolder();
|
||||
}
|
||||
|
||||
if (dir.isEmpty())
|
||||
continue;
|
||||
|
||||
final FileDirItem item = new FileDirItem(i > 0 ? currPath : basePath, dir, true, 0, 0);
|
||||
addBreadcrumb(item, i > 1);
|
||||
addBreadcrumb(item, i > 0 || mShowFullPath);
|
||||
}
|
||||
|
||||
if (dirs.length == 0 && mShowFullPath) {
|
||||
addRootFolder();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,6 +150,11 @@ public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
|||
removeView(getChildAt(getChildCount() - 1));
|
||||
}
|
||||
|
||||
private void addRootFolder() {
|
||||
final FileDirItem item = new FileDirItem("/", " / ", true, 0, 0);
|
||||
addBreadcrumb(item, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int cnt = getChildCount();
|
||||
|
|
|
@ -25,6 +25,8 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn
|
|||
|
||||
private static final int STORAGE_PERMISSION = 1;
|
||||
private static int mRootFoldersCnt;
|
||||
private static boolean mShowFullPath;
|
||||
private static Config mConfig;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -32,9 +34,28 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn
|
|||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
mBreadcrumbs.setListener(this);
|
||||
mConfig = Config.newInstance(getApplicationContext());
|
||||
tryInitFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (Utils.hasStoragePermission(getApplicationContext())) {
|
||||
final boolean showFullPath = mConfig.getShowFullPath();
|
||||
if (showFullPath != mShowFullPath)
|
||||
initRootFileManager();
|
||||
|
||||
mShowFullPath = showFullPath;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mShowFullPath = mConfig.getShowFullPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -122,7 +143,7 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn
|
|||
public void breadcrumbClicked(int id) {
|
||||
final FileDirItem item = (FileDirItem) mBreadcrumbs.getChildAt(id).getTag();
|
||||
final String path = item.getPath();
|
||||
openPath(path);
|
||||
mBreadcrumbs.setInitialBreadcrumb(path);
|
||||
openPath(path);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue