mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
allow clicking on breadcrumb items
This commit is contained in:
@ -10,9 +10,10 @@ import android.view.WindowManager;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class Breadcrumbs extends LinearLayout {
|
public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private int mDeviceWidth;
|
private int mDeviceWidth;
|
||||||
|
private BreadcrumbsListener mListener;
|
||||||
|
|
||||||
public Breadcrumbs(Context context, AttributeSet attrs) {
|
public Breadcrumbs(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@ -27,15 +28,20 @@ public class Breadcrumbs extends LinearLayout {
|
|||||||
mDeviceWidth = deviceDisplay.x;
|
mDeviceWidth = deviceDisplay.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(BreadcrumbsListener listener) {
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
final int paddingTop = getPaddingTop();
|
final int paddingTop = getPaddingTop();
|
||||||
final int paddingLeft = getPaddingLeft();
|
final int paddingLeft = getPaddingLeft();
|
||||||
final int childRight = getMeasuredWidth() - getPaddingRight();
|
final int paddingRight = getPaddingRight();
|
||||||
|
final int childRight = getMeasuredWidth() - paddingRight;
|
||||||
final int childBottom = getMeasuredHeight() - getPaddingBottom();
|
final int childBottom = getMeasuredHeight() - getPaddingBottom();
|
||||||
final int childHeight = childBottom - paddingTop;
|
final int childHeight = childBottom - paddingTop;
|
||||||
|
|
||||||
final int usableWidth = mDeviceWidth - paddingLeft - getPaddingRight();
|
final int usableWidth = mDeviceWidth - paddingLeft - paddingRight;
|
||||||
int maxHeight = 0;
|
int maxHeight = 0;
|
||||||
int curWidth;
|
int curWidth;
|
||||||
int curHeight;
|
int curHeight;
|
||||||
@ -91,17 +97,30 @@ public class Breadcrumbs extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setInitialBreadcrumb() {
|
public void setInitialBreadcrumb() {
|
||||||
addBreadcrumb("home");
|
addBreadcrumb(getResources().getString(R.string.initial_breadcrumb));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBreadcrumb(String text) {
|
public void addBreadcrumb(String text) {
|
||||||
final View view = mInflater.inflate(R.layout.breadcrumb_item, null, false);
|
final View view = mInflater.inflate(R.layout.breadcrumb_item, null, false);
|
||||||
|
view.setTag(getChildCount());
|
||||||
final TextView textView = (TextView) view.findViewById(R.id.breadcrumb_text);
|
final TextView textView = (TextView) view.findViewById(R.id.breadcrumb_text);
|
||||||
textView.setText(text);
|
textView.setText(text);
|
||||||
addView(view);
|
addView(view);
|
||||||
|
view.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBreadcrumb() {
|
public void removeBreadcrumb() {
|
||||||
removeView(getChildAt(getChildCount() - 1));
|
removeView(getChildAt(getChildCount() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.breadcrumbClicked((Integer) v.getTag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface BreadcrumbsListener {
|
||||||
|
void breadcrumbClicked(int id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import com.simplemobiletools.filemanager.models.FileDirItem;
|
|||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements ItemsFragment.ItemInteractionListener {
|
public class MainActivity extends AppCompatActivity implements ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
|
||||||
@BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs;
|
@BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs;
|
||||||
|
|
||||||
private static final int STORAGE_PERMISSION = 1;
|
private static final int STORAGE_PERMISSION = 1;
|
||||||
@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
mBreadcrumbs.setListener(this);
|
||||||
tryInitFileManager();
|
tryInitFileManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,4 +113,14 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
|
|||||||
openPath(item.getPath());
|
openPath(item.getPath());
|
||||||
mBreadcrumbs.addBreadcrumb(" -> " + item.getName());
|
mBreadcrumbs.addBreadcrumb(" -> " + item.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void breadcrumbClicked(int id) {
|
||||||
|
final int children = mBreadcrumbs.getChildCount() - 1;
|
||||||
|
final int removeCnt = children - id;
|
||||||
|
for (int i = 0; i < removeCnt; i++) {
|
||||||
|
getSupportFragmentManager().popBackStack();
|
||||||
|
mBreadcrumbs.removeBreadcrumb();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<string name="invalid_destination">Could not write to the selected destination</string>
|
<string name="invalid_destination">Could not write to the selected destination</string>
|
||||||
<string name="copy_failed">Could not copy the files</string>
|
<string name="copy_failed">Could not copy the files</string>
|
||||||
<string name="copying">Copying</string>
|
<string name="copying">Copying</string>
|
||||||
|
<string name="initial_breadcrumb">home</string>
|
||||||
|
|
||||||
<plurals name="items_deleted">
|
<plurals name="items_deleted">
|
||||||
<item quantity="one">1 item deleted</item>
|
<item quantity="one">1 item deleted</item>
|
||||||
|
Reference in New Issue
Block a user