mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
copy breadcrumbs to filepicker module too
This commit is contained in:
1
simplefilepicker/.gitignore
vendored
Normal file
1
simplefilepicker/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
@@ -0,0 +1,166 @@
|
|||||||
|
package com.simplemobiletools.filepicker.views
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Point
|
||||||
|
import android.os.Environment
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import com.simplemobiletools.filepicker.R
|
||||||
|
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||||
|
import kotlinx.android.synthetic.main.breadcrumb_item.view.*
|
||||||
|
|
||||||
|
class Breadcrumbs(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs), View.OnClickListener {
|
||||||
|
private var mDeviceWidth: Int = 0
|
||||||
|
|
||||||
|
private var mInflater: LayoutInflater? = null
|
||||||
|
private var mListener: BreadcrumbsListener? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
init(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun init(context: Context) {
|
||||||
|
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
|
val display = (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
|
||||||
|
val deviceDisplay = Point()
|
||||||
|
display.getSize(deviceDisplay)
|
||||||
|
mDeviceWidth = deviceDisplay.x
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setListener(listener: BreadcrumbsListener) {
|
||||||
|
mListener = listener
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
||||||
|
val paddingTop = paddingTop
|
||||||
|
val paddingLeft = paddingLeft
|
||||||
|
val paddingRight = paddingRight
|
||||||
|
val childRight = measuredWidth - paddingRight
|
||||||
|
val childBottom = measuredHeight - paddingBottom
|
||||||
|
val childHeight = childBottom - paddingTop
|
||||||
|
|
||||||
|
val usableWidth = mDeviceWidth - paddingLeft - paddingRight
|
||||||
|
var maxHeight = 0
|
||||||
|
var curWidth: Int
|
||||||
|
var curHeight: Int
|
||||||
|
var curLeft = paddingLeft
|
||||||
|
var curTop = paddingTop
|
||||||
|
|
||||||
|
val cnt = childCount
|
||||||
|
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))
|
||||||
|
curWidth = child.measuredWidth
|
||||||
|
curHeight = child.measuredHeight
|
||||||
|
|
||||||
|
if (curLeft + curWidth >= 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 = View.MeasureSpec.getSize(widthMeasureSpec)
|
||||||
|
val calculatedHeight = paddingTop + paddingBottom + rowHeight * lines
|
||||||
|
setMeasuredDimension(parentWidth, calculatedHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setInitialBreadcrumb(fullPath: String) {
|
||||||
|
val showFullPath = false//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.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.breadcrumb_item, null, false)
|
||||||
|
|
||||||
|
var textToAdd = item.name
|
||||||
|
if (addPrefix)
|
||||||
|
textToAdd = " -> " + textToAdd
|
||||||
|
view.breadcrumb_text.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)
|
||||||
|
}
|
||||||
|
}
|
6
simplefilepicker/src/main/res/layout/breadcrumb_item.xml
Normal file
6
simplefilepicker/src/main/res/layout/breadcrumb_item.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/breadcrumb_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple File Picker</string>
|
<string name="app_name">Simple File Picker</string>
|
||||||
<string name="select_destination">Ziel auswählen</string>
|
<string name="select_destination">Ziel auswählen</string>
|
||||||
|
<string name="initial_breadcrumb">home</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Abbrechen</string>
|
<string name="cancel">Abbrechen</string>
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple File Picker</string>
|
<string name="app_name">Simple File Picker</string>
|
||||||
<string name="select_destination">Seleziona destinazione</string>
|
<string name="select_destination">Seleziona destinazione</string>
|
||||||
|
<string name="initial_breadcrumb">home</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Annulla</string>
|
<string name="cancel">Annulla</string>
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple File Picker</string>
|
<string name="app_name">Simple File Picker</string>
|
||||||
<string name="select_destination">宛先を選択</string>
|
<string name="select_destination">宛先を選択</string>
|
||||||
|
<string name="initial_breadcrumb">ホーム</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple File Picker</string>
|
<string name="app_name">Simple File Picker</string>
|
||||||
<string name="select_destination">Selecionar destino</string>
|
<string name="select_destination">Selecionar destino</string>
|
||||||
|
<string name="initial_breadcrumb">início</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancelar</string>
|
<string name="cancel">Cancelar</string>
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple File Picker</string>
|
<string name="app_name">Simple File Picker</string>
|
||||||
<string name="select_destination">Välj mål</string>
|
<string name="select_destination">Välj mål</string>
|
||||||
|
<string name="initial_breadcrumb">home</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple File Picker</string>
|
<string name="app_name">Simple File Picker</string>
|
||||||
<string name="select_destination">Select destination</string>
|
<string name="select_destination">Select destination</string>
|
||||||
|
<string name="initial_breadcrumb">home</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user