allow clicking on breadcrumb items
This commit is contained in:
parent
31a4f65cc9
commit
54421678c2
3 changed files with 36 additions and 5 deletions
|
@ -10,9 +10,10 @@ import android.view.WindowManager;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Breadcrumbs extends LinearLayout {
|
||||
public class Breadcrumbs extends LinearLayout implements View.OnClickListener {
|
||||
private LayoutInflater mInflater;
|
||||
private int mDeviceWidth;
|
||||
private BreadcrumbsListener mListener;
|
||||
|
||||
public Breadcrumbs(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
@ -27,15 +28,20 @@ public class Breadcrumbs extends LinearLayout {
|
|||
mDeviceWidth = deviceDisplay.x;
|
||||
}
|
||||
|
||||
public void setListener(BreadcrumbsListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final int paddingTop = getPaddingTop();
|
||||
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 childHeight = childBottom - paddingTop;
|
||||
|
||||
final int usableWidth = mDeviceWidth - paddingLeft - getPaddingRight();
|
||||
final int usableWidth = mDeviceWidth - paddingLeft - paddingRight;
|
||||
int maxHeight = 0;
|
||||
int curWidth;
|
||||
int curHeight;
|
||||
|
@ -91,17 +97,30 @@ public class Breadcrumbs extends LinearLayout {
|
|||
}
|
||||
|
||||
public void setInitialBreadcrumb() {
|
||||
addBreadcrumb("home");
|
||||
addBreadcrumb(getResources().getString(R.string.initial_breadcrumb));
|
||||
}
|
||||
|
||||
public void addBreadcrumb(String text) {
|
||||
final View view = mInflater.inflate(R.layout.breadcrumb_item, null, false);
|
||||
view.setTag(getChildCount());
|
||||
final TextView textView = (TextView) view.findViewById(R.id.breadcrumb_text);
|
||||
textView.setText(text);
|
||||
addView(view);
|
||||
view.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void removeBreadcrumb() {
|
||||
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.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;
|
||||
|
||||
private static final int STORAGE_PERMISSION = 1;
|
||||
|
@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
mBreadcrumbs.setListener(this);
|
||||
tryInitFileManager();
|
||||
}
|
||||
|
||||
|
@ -112,4 +113,14 @@ public class MainActivity extends AppCompatActivity implements ItemsFragment.Ite
|
|||
openPath(item.getPath());
|
||||
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="copy_failed">Could not copy the files</string>
|
||||
<string name="copying">Copying</string>
|
||||
<string name="initial_breadcrumb">home</string>
|
||||
|
||||
<plurals name="items_deleted">
|
||||
<item quantity="one">1 item deleted</item>
|
||||
|
|
Loading…
Reference in a new issue