Commit 9f07a151 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix incorrect empty state for favorites + add empty view a compact mode

Fixes #1289
parent 03747856
......@@ -117,6 +117,7 @@
<declare-styleable name="EmptyLoadingStateView">
<attr name="empty_text" format="reference|string" />
<attr name="show_no_media" format="boolean" />
<attr name="compact_mode" format="boolean" />
</declare-styleable>
<declare-styleable name="TitleListView">
<attr name="title" format="reference|string" />
......
......@@ -831,4 +831,5 @@
<string name="rename_group">Rename video group</string>
<string name="ungroup">Ungroup</string>
<string name="group_similar">Regroup automatically</string>
<string name="no_favorite">No favorite</string>
</resources>
......@@ -65,10 +65,9 @@
android:id="@+id/loading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:compact_mode="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -25,6 +25,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
......@@ -61,7 +62,6 @@
app:layout_constraintBottom_toTopOf="@+id/guideline12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emptyTextView"
app:layout_constraintTop_toTopOf="@+id/guideline12"
app:srcCompat="@drawable/ic_empty" />
......
<?xml version="1.0" encoding="utf-8"?><!--
~ *************************************************************************
~ view_empty_loading_compact.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.
~ ***************************************************************************
~
~
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<TextView
android:id="@+id/emptyTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:gravity="start"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="@+id/emptyImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/emptyImageView"
app:layout_constraintTop_toTopOf="@+id/emptyImageView"
tools:text="No data"
tools:visibility="visible" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/emptyImageView"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toTopOf="@+id/guideline12"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline12"
app:srcCompat="@drawable/ic_empty" />
<Button
android:id="@+id/noMediaButton"
style="?attr/empty_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/button_medialibrary_preferences"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emptyImageView" />
<TextView
android:id="@+id/loadingTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="@string/loading"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/guideline12"
app:layout_constraintEnd_toStartOf="@+id/loadingFlipper"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline12" />
<ViewFlipper
android:id="@+id/loadingFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:autoStart="true"
android:flipInterval="1000"
app:layout_constraintBaseline_toBaselineOf="@+id/loadingTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/loadingTitle">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/empty"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/load_1_period"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/load_2_period"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/load_3_period"
android:textSize="20sp" />
</ViewFlipper>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -144,6 +144,8 @@ class MainBrowserFragment : BaseFragment(), View.OnClickListener, CtxActionRecei
})
favoritesEntry = view.findViewById(R.id.fav_browser_entry)
favoritesEntry.loading.showNoMedia = false
favoritesEntry.loading.emptyText = R.string.no_favorite
val favoritesBrowserContainer = MainBrowserContainer(isNetwork = false, isFile = true)
val favoritesAdapter = BaseBrowserAdapter(favoritesBrowserContainer)
favoritesEntry.list.adapter = favoritesAdapter
......
......@@ -29,18 +29,31 @@ import android.content.Context
import android.content.Intent
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.StringRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.transition.TransitionManager
import kotlinx.android.synthetic.main.view_empty_loading.view.*
import org.videolan.resources.ACTIVITY_RESULT_PREFERENCES
import org.videolan.vlc.R
import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.resources.ACTIVITY_RESULT_PREFERENCES
class EmptyLoadingStateView : FrameLayout {
private val normalConstraintSet = ConstraintSet()
private val compactConstraintSet = ConstraintSet()
lateinit var container: ConstraintLayout
var showNoMedia: Boolean = true
private var compactMode: Boolean = false
set(value) {
field = value
applyCompactMode()
}
var state = EmptyLoadingState.LOADING
set(value) {
loadingFlipper.visibility = if (value == EmptyLoadingState.LOADING) View.VISIBLE else View.GONE
......@@ -66,7 +79,7 @@ class EmptyLoadingStateView : FrameLayout {
field = emptyText
}
var noMediaClickListener: (() -> Unit)? = null
private var noMediaClickListener: (() -> Unit)? = null
fun setOnNoMediaClickListener(l: () -> Unit) {
noMediaClickListener = l
......@@ -81,7 +94,7 @@ class EmptyLoadingStateView : FrameLayout {
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
initialize()
initAttributes(attrs, 0)
initAttributes(attrs, defStyle)
}
private fun initAttributes(attrs: AttributeSet, defStyle: Int) {
......@@ -90,6 +103,7 @@ class EmptyLoadingStateView : FrameLayout {
try {
emptyTextView.text = a.getString(R.styleable.EmptyLoadingStateView_empty_text)
showNoMedia = a.getBoolean(R.styleable.EmptyLoadingStateView_show_no_media, true)
compactMode = a.getBoolean(R.styleable.EmptyLoadingStateView_compact_mode, true)
} catch (e: Exception) {
Log.w("", e.message, e)
} finally {
......@@ -106,6 +120,18 @@ class EmptyLoadingStateView : FrameLayout {
(context as Activity).startActivityForResult(intent, ACTIVITY_RESULT_PREFERENCES)
noMediaClickListener?.invoke()
}
container = findViewById(R.id.container)
normalConstraintSet.clone(container)
compactConstraintSet.clone(context, R.layout.view_empty_loading_compact)
if (compactMode) {
applyCompactMode()
}
}
private fun applyCompactMode() {
TransitionManager.beginDelayedTransition(container)
if (compactMode) compactConstraintSet.applyTo(container) else normalConstraintSet.applyTo(container)
emptyTextView.gravity = if (compactMode) Gravity.START else Gravity.CENTER
}
private fun initialize() {
......
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