Explorer grid layout
This commit is contained in:
parent
91de54018d
commit
4f9aa55dfe
@ -29,6 +29,7 @@ class ExplorerElementAdapter(
|
|||||||
val dateFormat: DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault())
|
val dateFormat: DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault())
|
||||||
var explorerElements = listOf<ExplorerElement>()
|
var explorerElements = listOf<ExplorerElement>()
|
||||||
val selectedItems: MutableList<Int> = ArrayList()
|
val selectedItems: MutableList<Int> = ArrayList()
|
||||||
|
var isUsingListLayout = true
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return explorerElements.size
|
return explorerElements.size
|
||||||
@ -197,7 +198,13 @@ class ExplorerElementAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.adapter_explorer_element, parent, false)
|
val view = activity.layoutInflater.inflate(
|
||||||
|
if (isUsingListLayout) {
|
||||||
|
R.layout.adapter_explorer_element_list
|
||||||
|
} else {
|
||||||
|
R.layout.adapter_explorer_element_grid
|
||||||
|
}, parent, false
|
||||||
|
)
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
ExplorerElement.REGULAR_FILE_TYPE -> FileViewHolder(view)
|
ExplorerElement.REGULAR_FILE_TYPE -> FileViewHolder(view)
|
||||||
ExplorerElement.DIRECTORY_TYPE -> DirectoryViewHolder(view)
|
ExplorerElement.DIRECTORY_TYPE -> DirectoryViewHolder(view)
|
||||||
|
@ -10,12 +10,14 @@ import android.os.IBinder
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.ImageButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
@ -60,6 +62,9 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
protected var isStartingActivity = false
|
protected var isStartingActivity = false
|
||||||
private var usf_open = false
|
private var usf_open = false
|
||||||
protected var usf_keep_open = false
|
protected var usf_keep_open = false
|
||||||
|
private lateinit var linearLayoutManager: LinearLayoutManager
|
||||||
|
private var isUsingListLayout = true
|
||||||
|
private lateinit var layoutIcon: ImageButton
|
||||||
private lateinit var titleText: TextView
|
private lateinit var titleText: TextView
|
||||||
private lateinit var recycler_view_explorer: RecyclerView
|
private lateinit var recycler_view_explorer: RecyclerView
|
||||||
private lateinit var refresher: SwipeRefreshLayout
|
private lateinit var refresher: SwipeRefreshLayout
|
||||||
@ -103,12 +108,22 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
::onExplorerItemLongClick,
|
::onExplorerItemLongClick,
|
||||||
sharedPrefs.getLong(ConstValues.THUMBNAIL_MAX_SIZE_KEY, ConstValues.DEFAULT_THUMBNAIL_MAX_SIZE)*1000,
|
sharedPrefs.getLong(ConstValues.THUMBNAIL_MAX_SIZE_KEY, ConstValues.DEFAULT_THUMBNAIL_MAX_SIZE)*1000,
|
||||||
)
|
)
|
||||||
explorerViewModel= ViewModelProvider(this).get(ExplorerViewModel::class.java)
|
explorerViewModel = ViewModelProvider(this).get(ExplorerViewModel::class.java)
|
||||||
currentDirectoryPath = explorerViewModel.currentDirectoryPath
|
currentDirectoryPath = explorerViewModel.currentDirectoryPath
|
||||||
setCurrentPath(currentDirectoryPath)
|
setCurrentPath(currentDirectoryPath)
|
||||||
recycler_view_explorer.apply {
|
linearLayoutManager = LinearLayoutManager(this@BaseExplorerActivity)
|
||||||
adapter = explorerAdapter
|
recycler_view_explorer.adapter = explorerAdapter
|
||||||
layoutManager = LinearLayoutManager(this@BaseExplorerActivity)
|
isUsingListLayout = sharedPrefs.getBoolean("useListLayout", true)
|
||||||
|
layoutIcon = findViewById(R.id.layout_icon)
|
||||||
|
setRecyclerViewLayout()
|
||||||
|
layoutIcon.setOnClickListener {
|
||||||
|
isUsingListLayout = !isUsingListLayout
|
||||||
|
setRecyclerViewLayout()
|
||||||
|
recycler_view_explorer.recycledViewPool.clear()
|
||||||
|
with (sharedPrefs.edit()) {
|
||||||
|
putBoolean("useListLayout", isUsingListLayout)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
refresher.setOnRefreshListener {
|
refresher.setOnRefreshListener {
|
||||||
setCurrentPath(currentDirectoryPath)
|
setCurrentPath(currentDirectoryPath)
|
||||||
@ -121,6 +136,20 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
var currentDirectoryPath = ""
|
var currentDirectoryPath = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setRecyclerViewLayout() {
|
||||||
|
layoutIcon.setImageResource(if (isUsingListLayout) {
|
||||||
|
recycler_view_explorer.layoutManager = linearLayoutManager
|
||||||
|
explorerAdapter.isUsingListLayout = true
|
||||||
|
R.drawable.icon_view_list
|
||||||
|
} else {
|
||||||
|
val displayMetrics = resources.displayMetrics
|
||||||
|
val columnsNumber = (displayMetrics.widthPixels / displayMetrics.density / 200 + 0.5).toInt()
|
||||||
|
recycler_view_explorer.layoutManager = GridLayoutManager(this, columnsNumber)
|
||||||
|
explorerAdapter.isUsingListLayout = false
|
||||||
|
R.drawable.icon_view_grid
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
protected open fun init() {
|
protected open fun init() {
|
||||||
setContentView(R.layout.activity_explorer_base)
|
setContentView(R.layout.activity_explorer_base)
|
||||||
}
|
}
|
||||||
|
10
app/src/main/res/drawable/icon_view_grid.xml
Normal file
10
app/src/main/res/drawable/icon_view_grid.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M4,11h5L9,5L4,5v6zM4,18h5v-6L4,12v6zM10,18h5v-6h-5v6zM16,18h5v-6h-5v6zM10,11h5L15,5h-5v6zM16,5v6h5L21,5h-5z"/>
|
||||||
|
</vector>
|
10
app/src/main/res/drawable/icon_view_list.xml
Normal file
10
app/src/main/res/drawable/icon_view_list.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M4,14h4v-4L4,10v4zM4,19h4v-4L4,15v4zM4,9h4L8,5L4,5v4zM9,14h12v-4L9,10v4zM9,19h12v-4L9,15v4zM9,5v4h12L21,5L9,5z"/>
|
||||||
|
</vector>
|
59
app/src/main/res/layout/adapter_explorer_element_grid.xml
Normal file
59
app/src/main/res/layout/adapter_explorer_element_grid.xml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/selectable_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/icon_element"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="130dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:layout_gravity="center_horizontal"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_gravity="center_horizontal|bottom"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_element_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="@dimen/adapter_text_size"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_gravity="bottom">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_element_mtime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="@dimen/details_text_size"
|
||||||
|
android:layout_marginEnd="7dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_element_size"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="@dimen/details_text_size"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -35,14 +35,14 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_path"
|
android:id="@+id/text_path"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="7dp"
|
android:layout_marginEnd="7dp"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:ellipsize="middle"
|
android:ellipsize="middle"
|
||||||
app:layout_constraintHorizontal_chainStyle="packed"
|
app:layout_constraintHorizontal_chainStyle="packed"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
app:layout_constraintHorizontal_bias="0"
|
||||||
app:layout_constraintWidth_default="wrap"
|
app:layout_constrainedWidth="true"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@id/text_info"
|
app:layout_constraintEnd_toStartOf="@id/text_info"
|
||||||
|
@ -1,28 +1,47 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="25dp"
|
android:layout_height="50dp"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:background="?attr/infoBarBackgroundColor"
|
android:background="?attr/infoBarBackgroundColor"
|
||||||
android:gravity="center_vertical">
|
android:paddingHorizontal="20dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/current_path_text"
|
android:id="@+id/current_path_text"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/infoBarTextView"
|
style="@style/infoBarTextView"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:ellipsize="start"
|
||||||
|
app:layout_constraintHorizontal_chainStyle="packed"
|
||||||
|
app:layout_constraintHorizontal_bias="0"
|
||||||
|
app:layout_constrainedWidth="true"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@id/total_size_text"/>
|
app:layout_constraintEnd_toStartOf="@id/total_size_text"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/total_size_text"
|
android:id="@+id/total_size_text"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/infoBarTextView"
|
style="@style/infoBarTextView"
|
||||||
android:text="@string/default_total_size"
|
android:text="@string/default_total_size"
|
||||||
|
android:layout_marginHorizontal="20dp"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@id/current_path_text"/>
|
app:layout_constraintStart_toEndOf="@id/current_path_text"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/layout_icon"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/layout_icon"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:src="@drawable/icon_view_grid"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/switch_display_layout"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -233,4 +233,5 @@
|
|||||||
<string name="invalid_number">Invalid number</string>
|
<string name="invalid_number">Invalid number</string>
|
||||||
<string name="new_volume_name">New volume name:</string>
|
<string name="new_volume_name">New volume name:</string>
|
||||||
<string name="volume_rename_failed">Failed to rename volume</string>
|
<string name="volume_rename_failed">Failed to rename volume</string>
|
||||||
|
<string name="switch_display_layout">Switch display layout</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -59,6 +59,5 @@
|
|||||||
<item name="android:ellipsize">start</item>
|
<item name="android:ellipsize">start</item>
|
||||||
<item name="android:singleLine">true</item>
|
<item name="android:singleLine">true</item>
|
||||||
<item name="android:textSize">15sp</item>
|
<item name="android:textSize">15sp</item>
|
||||||
<item name="android:textAlignment">center</item>
|
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.1.2'
|
classpath 'com.android.tools.build:gradle:7.1.3'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user