diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java index 3eded05d..b8b18157 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -15,7 +15,7 @@ import com.simplemobiletools.filemanager.R; import com.simplemobiletools.filemanager.Utils; import com.simplemobiletools.filemanager.fragments.ItemsFragment; import com.simplemobiletools.filepicker.models.FileDirItem; -import com.simplemobiletools.filepicker.Breadcrumbs; +import com.simplemobiletools.filepicker.views.Breadcrumbs; import butterknife.BindView; import butterknife.ButterKnife; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5fd54390..cfa54ad1 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - = childRight) { - curLeft = paddingLeft - curTop += maxHeight - maxHeight = 0 - } - - child.layout(curLeft, curTop, curLeft + curWidth, curTop + curHeight) - if (maxHeight < curHeight) - maxHeight = curHeight - - curLeft += curWidth - } - } - - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - val usableWidth = mDeviceWidth - paddingLeft - paddingRight - var width = 0 - var rowHeight = 0 - var lines = 1 - - val cnt = childCount - for (i in 0..cnt - 1) { - val child = getChildAt(i) - measureChild(child, widthMeasureSpec, heightMeasureSpec) - width += child.measuredWidth - rowHeight = child.measuredHeight - - if (width / usableWidth > 0) { - lines++ - width = child.measuredWidth - } - } - - val parentWidth = MeasureSpec.getSize(widthMeasureSpec) - val calculatedHeight = paddingTop + paddingBottom + rowHeight * lines - setMeasuredDimension(parentWidth, calculatedHeight) - } - - fun setInitialBreadcrumb(fullPath: String) { - val showFullPath = false//com.simplemobiletools.filemanager.Config.newInstance(context).showFullPath - val basePath = Environment.getExternalStorageDirectory().toString() - var tempPath = fullPath - var currPath = basePath - if (!showFullPath) { - tempPath = fullPath.replace(basePath, context.getString(R.string.smtfp_initial_breadcrumb) + "/") - } else { - currPath = "/" - } - - removeAllViewsInLayout() - val dirs = tempPath.split("/".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() - for (i in dirs.indices) { - val dir = dirs[i] - if (i > 0) { - currPath += dir + "/" - } else if (showFullPath) { - addRootFolder() - } - - if (dir.isEmpty()) - continue - - val item = FileDirItem(currPath, dir, true, 0, 0) - addBreadcrumb(item, i > 0 || showFullPath) - } - - if (dirs.size == 0 && showFullPath) { - addRootFolder() - } - } - - fun addBreadcrumb(item: FileDirItem, addPrefix: Boolean) { - val view = mInflater!!.inflate(R.layout.smtfp_breadcrumb_item, null, false) - val textView = view.findViewById(R.id.breadcrumb_text) as TextView - - var textToAdd = item.name - if (addPrefix) - textToAdd = " -> " + textToAdd - textView.text = textToAdd - addView(view) - view.setOnClickListener(this) - - view.tag = item - } - - fun removeBreadcrumb() { - removeView(getChildAt(childCount - 1)) - } - - private fun addRootFolder() { - val item = FileDirItem("/", " / ", true, 0, 0) - addBreadcrumb(item, false) - } - - override fun onClick(v: View) { - val cnt = childCount - for (i in 0..cnt - 1) { - if (getChildAt(i) != null && getChildAt(i) == v) { - mListener?.breadcrumbClicked(i) - } - } - } - - interface BreadcrumbsListener { - fun breadcrumbClicked(id: Int) - } -} diff --git a/library/src/main/kotlin/com/simplemobiletools/filepicker/dialogs/SelectFolderDialog.kt b/library/src/main/kotlin/com/simplemobiletools/filepicker/dialogs/SelectFolderDialog.kt index ec934522..51e56649 100644 --- a/library/src/main/kotlin/com/simplemobiletools/filepicker/dialogs/SelectFolderDialog.kt +++ b/library/src/main/kotlin/com/simplemobiletools/filepicker/dialogs/SelectFolderDialog.kt @@ -7,11 +7,11 @@ import android.os.Bundle import android.support.v4.app.DialogFragment import android.support.v7.app.AlertDialog import android.view.View -import com.simplemobiletools.filepicker.Breadcrumbs import com.simplemobiletools.filepicker.R import com.simplemobiletools.filepicker.adapters.ItemsAdapter import com.simplemobiletools.filepicker.extensions.getFilenameFromPath import com.simplemobiletools.filepicker.models.FileDirItem +import com.simplemobiletools.filepicker.views.Breadcrumbs import kotlinx.android.synthetic.main.smtfp_directory_picker.view.* import java.io.File import java.util.* diff --git a/library/src/main/kotlin/com/simplemobiletools/filepicker/views/Breadcrumbs.kt b/library/src/main/kotlin/com/simplemobiletools/filepicker/views/Breadcrumbs.kt index 949dcc2a..5174431c 100644 --- a/library/src/main/kotlin/com/simplemobiletools/filepicker/views/Breadcrumbs.kt +++ b/library/src/main/kotlin/com/simplemobiletools/filepicker/views/Breadcrumbs.kt @@ -53,8 +53,8 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : LinearLayout(context, for (i in 0..cnt - 1) { val child = getChildAt(i) - child.measure(View.MeasureSpec.makeMeasureSpec(usableWidth, View.MeasureSpec.AT_MOST), - View.MeasureSpec.makeMeasureSpec(childHeight, View.MeasureSpec.AT_MOST)) + child.measure(MeasureSpec.makeMeasureSpec(usableWidth, MeasureSpec.AT_MOST), + MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST)) curWidth = child.measuredWidth curHeight = child.measuredHeight @@ -91,7 +91,7 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : LinearLayout(context, } } - val parentWidth = View.MeasureSpec.getSize(widthMeasureSpec) + val parentWidth = MeasureSpec.getSize(widthMeasureSpec) val calculatedHeight = paddingTop + paddingBottom + rowHeight * lines setMeasuredDimension(parentWidth, calculatedHeight) } @@ -131,10 +131,10 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : LinearLayout(context, fun addBreadcrumb(item: FileDirItem, addPrefix: Boolean) { val view = mInflater!!.inflate(R.layout.smtfp_breadcrumb_item, null, false) - var textToAdd = item.name if (addPrefix) textToAdd = " -> " + textToAdd + view.breadcrumb_text.text = textToAdd addView(view) view.setOnClickListener(this) diff --git a/library/src/main/res/layout/smtfp_directory_picker.xml b/library/src/main/res/layout/smtfp_directory_picker.xml index 76de4b7f..ebe2ca5a 100644 --- a/library/src/main/res/layout/smtfp_directory_picker.xml +++ b/library/src/main/res/layout/smtfp_directory_picker.xml @@ -6,14 +6,13 @@ android:layout_height="wrap_content" android:orientation="vertical"> -