Commit efaed70e authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix clear history + move button

parent 382f04a5
<!--
~ *************************************************************************
~ ic_trash_32.xml
~ **************************************************************************
~ Copyright © 2020 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillAlpha="1"
android:fillColor="@color/standard_selection_control_normal"
android:fillType="nonZero"
android:pathData="m10,4c-0.7396,0 -1.3727,0.4031 -1.7187,1l-2.2813,-0.013 0,2 12,0 0,-2 -2.2813,0.013c-0.346,-0.5969 -0.9791,-1 -1.7188,-1zM7,8 L7,18c0,1.108 0.892,2 2,2l6,0c1.108,0 2,-0.892 2,-2l0,-10z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
......@@ -119,6 +119,8 @@
</declare-styleable>
<declare-styleable name="TitleListView">
<attr name="title" format="reference|string" />
<attr name="show_button" format="boolean" />
<attr name="button_icon" format="reference" />
</declare-styleable>
<declare-styleable name="HalfCircleView">
......
......@@ -91,6 +91,7 @@
android:id="@+id/history_entry"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:button_icon="@drawable/ic_trash_32"
android:layout_marginTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
......@@ -38,6 +38,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/action_button"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="@+id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/title" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="0dp"
......
......@@ -35,16 +35,14 @@
android:id="@+id/nav_audio"
android:title="@string/audio"
android:icon="@drawable/ic_menu_audio" />
<item
android:id="@+id/nav_playlists"
android:title="@string/playlists"
android:icon="@drawable/ic_menu_playlist" />
<item
android:id="@+id/nav_directories"
android:title="@string/browse"
android:icon="@drawable/ic_menu_folder" />
<item
android:id="@+id/nav_playlists"
android:title="@string/playlists"
android:icon="@drawable/ic_menu_playlist" />
<item
android:id="@+id/nav_more"
android:title="@string/more"
......
......@@ -4,7 +4,7 @@
<item
android:orderInCategory="2"
android:id="@+id/ml_menu_clean"
android:icon="@drawable/ic_trash_w"
android:icon="@drawable/ic_trash"
android:title="@string/clear_history"
android:visible="false"
vlc:showAsAction="ifRoom"/>
......
......@@ -38,6 +38,7 @@ import kotlinx.android.synthetic.main.more_fragment.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.flow.onEach
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.resources.ACTIVITY_RESULT_PREFERENCES
import org.videolan.tools.*
......@@ -64,7 +65,6 @@ class MoreFragment : BaseFragment(), IRefreshable, IHistory, SwipeRefreshLayout.
private lateinit var historyEntry: TitleListView
private lateinit var viewModel: HistoryModel
private lateinit var cleanMenuItem: MenuItem
private lateinit var multiSelectHelper: MultiSelectHelper<MediaWrapper>
private val historyAdapter: HistoryAdapter = HistoryAdapter(true)
override fun hasFAB() = false
......@@ -89,13 +89,11 @@ class MoreFragment : BaseFragment(), IRefreshable, IHistory, SwipeRefreshLayout.
viewModel.dataset.observe(viewLifecycleOwner, Observer<List<MediaWrapper>> { list ->
list?.let {
historyAdapter.update(it)
if (::cleanMenuItem.isInitialized) {
cleanMenuItem.isVisible = list.isNotEmpty()
}
if (list.isEmpty()) historyEntry.setGone() else {
historyEntry.setVisible()
historyEntry.loading.state = EmptyLoadingState.NONE
}
if (list.isNotEmpty()) historyEntry.actionButton.setVisible() else historyEntry.actionButton.setGone()
}
restoreMultiSelectHelper()
})
......@@ -138,6 +136,10 @@ class MoreFragment : BaseFragment(), IRefreshable, IHistory, SwipeRefreshLayout.
historyEntry.list.nextFocusRightId = android.R.id.list
historyEntry.list.nextFocusForwardId = android.R.id.list
historyEntry.setOnActionClickListener {
clearHistory()
}
multiSelectHelper = historyAdapter.multiSelectHelper
historyEntry.list.requestFocus()
registerForContextMenu(historyEntry.list)
......@@ -151,23 +153,6 @@ class MoreFragment : BaseFragment(), IRefreshable, IHistory, SwipeRefreshLayout.
super.onSaveInstanceState(outState)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.fragment_option_history, menu)
super.onCreateOptionsMenu(menu, inflater)
cleanMenuItem = menu.findItem(R.id.ml_menu_clean)
cleanMenuItem.isVisible = !isEmpty()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.ml_menu_clean -> {
clearHistory()
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun refresh() = viewModel.refresh()
override fun onRefresh() {
......@@ -180,11 +165,11 @@ class MoreFragment : BaseFragment(), IRefreshable, IHistory, SwipeRefreshLayout.
override fun clearHistory() {
viewModel.clearHistory()
Medialibrary.getInstance().clearHistory()
}
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
mode?.menuInflater?.inflate(R.menu.action_mode_history, menu)
return true
return false
}
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
......
......@@ -30,14 +30,17 @@ import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageButton
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.videolan.tools.setGone
import org.videolan.vlc.R
class TitleListView : ConstraintLayout {
private var actionClickListener: ((View) -> Unit)? = null
private val titleView: TextView by lazy {
findViewById<TextView>(R.id.title)
}
......@@ -50,6 +53,14 @@ class TitleListView : ConstraintLayout {
findViewById<EmptyLoadingStateView>(R.id.loading)
}
val actionButton: ImageButton by lazy {
findViewById<ImageButton>(R.id.action_button)
}
fun setOnActionClickListener(listener: (View) -> Unit) {
this.actionClickListener = listener
}
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
......@@ -67,6 +78,12 @@ class TitleListView : ConstraintLayout {
val a = context.theme.obtainStyledAttributes(attrs, R.styleable.TitleListView, 0, defStyle)
try {
titleView.text = a.getString(R.styleable.TitleListView_title)
if (!a.getBoolean(R.styleable.TitleListView_show_button, false)) actionButton.setGone()
actionButton.setImageDrawable(a.getDrawable(R.styleable.TitleListView_button_icon))
actionButton.setOnClickListener {
actionClickListener?.let { listener -> listener(actionButton) }
}
// actionButton.icon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.icon))
} catch (e: Exception) {
Log.w("", e.message, e)
} finally {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment