Commit 8493802c authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais

Add an image click listener

parent db816f32
......@@ -55,6 +55,7 @@
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@{cover}"
android:onClick="@{holder::onImageClick}"
vlc:layout_constraintBottom_toBottomOf="parent"
vlc:layout_constraintDimensionRatio="1"
vlc:layout_constraintStart_toStartOf="parent"
......
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:targetApi="jelly_bean" >
xmlns:tools="http://schemas.android.com/tools"
tools:targetApi="jelly_bean">
<data>
<import type="android.view.View"/>
<import type="android.text.TextUtils"/>
<import type="org.videolan.medialibrary.media.MediaLibraryItem"/>
<import type="android.view.View" />
<import type="android.text.TextUtils" />
<import type="org.videolan.medialibrary.media.MediaLibraryItem" />
<variable
name="holder"
type="org.videolan.vlc.gui.browser.BaseBrowserAdapter.ViewHolder"/>
type="org.videolan.vlc.gui.browser.BaseBrowserAdapter.ViewHolder" />
<variable
name="item"
type="MediaLibraryItem"/>
type="MediaLibraryItem" />
<variable
name="filename"
type="String"/>
type="String" />
<variable
name="hasContextMenu"
type="boolean"/>
type="boolean" />
<variable
name="checkEnabled"
type="boolean"/>
type="boolean" />
<variable
name="protocol"
type="String"/>
type="String" />
<variable
name="cover"
type="android.graphics.drawable.BitmapDrawable"/>
type="android.graphics.drawable.BitmapDrawable" />
<variable
name="bgColor"
type="int" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:padding="2dp"
android:focusable="true"
android:background="@{bgColor}"
android:clickable="@{holder != null}"
android:focusable="true"
android:longClickable="@{hasContextMenu || item.getItemType() == MediaLibraryItem.TYPE_STORAGE}"
android:minHeight="48dp"
android:onClick="@{holder::onClick}"
android:onLongClick="@{holder::onLongClick}"
android:background="@{bgColor}" >
android:padding="2dp">
<org.videolan.vlc.gui.helpers.ThreeStatesCheckbox
android:id="@+id/browser_checkbox"
......@@ -51,24 +64,26 @@
android:enabled="@{checkEnabled}"
android:focusable="false"
android:onClick="@{holder::onCheckBoxClick}"
android:visibility="@{item.getItemType() == MediaLibraryItem.TYPE_STORAGE ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="@{item.getItemType() == MediaLibraryItem.TYPE_STORAGE ? View.VISIBLE : View.GONE, default=gone}" />
app:layout_constraintTop_toTopOf="parent" />
<!-- Image downloading is handled by org.videolan.vlc.gui.helpers.ImageLoader.loadImage() -->
<ImageView
android:id="@+id/item_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@{cover}"
android:scaleType="centerCrop"
android:contentDescription="@string/cover_art"
android:onClick="@{holder::onImageClick}"
android:scaleType="centerCrop"
android:src="@{cover}"
android:visibility="@{item.getItemType() == MediaLibraryItem.TYPE_STORAGE ? View.GONE : View.VISIBLE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/browser_checkbox"
app:layout_constraintTop_toTopOf="parent"
app:media="@{item}"
android:visibility="@{item.getItemType() == MediaLibraryItem.TYPE_STORAGE ? View.GONE : View.VISIBLE}" />
app:media="@{item}" />
<TextView
android:id="@+id/dvi_icon"
android:layout_width="0dp"
......@@ -77,31 +92,31 @@
android:text="@{protocol}"
android:textColor="@color/whitetransparent"
android:textSize="11sp"
android:visibility="@{ TextUtils.isEmpty(protocol) ? View.GONE : View.VISIBLE, default=gone}"
app:layout_constraintBottom_toBottomOf="@+id/item_icon"
app:layout_constraintStart_toStartOf="@+id/item_icon"
app:layout_constraintEnd_toEndOf="@+id/item_icon"
app:layout_constraintTop_toTopOf="@+id/item_icon"
android:visibility="@{ TextUtils.isEmpty(protocol) ? View.GONE : View.VISIBLE, default=gone}" />
app:layout_constraintStart_toStartOf="@+id/item_icon"
app:layout_constraintTop_toTopOf="@+id/item_icon" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_goneMarginBottom="2dp"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginStart="@dimen/default_margin"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_icon"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintEnd_toStartOf="@+id/item_more"
app:layout_constraintBottom_toTopOf="@+id/text"
android:layout_marginLeft="@dimen/default_margin"
android:ellipsize="end"
android:singleLine="true"
android:lineSpacingMultiplier="1.1"
android:maxLines="1"
android:singleLine="true"
android:text="@{filename ?? item.title}"
android:textColor="?attr/list_title"
android:textSize="16sp"
android:lineSpacingMultiplier="1.1" />
app:layout_constraintBottom_toTopOf="@+id/text"
app:layout_constraintEnd_toStartOf="@+id/item_more"
app:layout_constraintStart_toEndOf="@+id/item_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_goneMarginBottom="2dp" />
<TextView
android:id="@+id/text"
......@@ -111,23 +126,23 @@
android:text="@{item.description}"
android:textColor="?attr/list_subtitle"
android:textSize="12sp"
android:visibility="@{TextUtils.isEmpty(item.description) ? View.GONE : View.VISIBLE, default=gone}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/item_more"
app:layout_constraintStart_toStartOf="@+id/title"
app:layout_constraintTop_toBottomOf="@+id/title"
android:visibility="@{TextUtils.isEmpty(item.description) ? View.GONE : View.VISIBLE, default=gone}" />
app:layout_constraintTop_toBottomOf="@+id/title" />
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:background="@drawable/ic_more"
android:visibility="@{hasContextMenu ? View.VISIBLE : View.GONE, default=gone}"
android:clickable="@{hasContextMenu}"
android:onClick="@{holder::onMoreClick}"
android:clickable="@{hasContextMenu}" />
android:visibility="@{hasContextMenu ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="org.videolan.medialibrary.media.MediaWrapper"/>
<import type="android.text.TextUtils"/>
<import type="android.view.View"/>
<import type="org.videolan.medialibrary.media.MediaWrapper" />
<import type="android.text.TextUtils" />
<import type="android.view.View" />
<variable
name="holder"
type="org.videolan.vlc.gui.HistoryAdapter.ViewHolder"/>
type="org.videolan.vlc.gui.HistoryAdapter.ViewHolder" />
<variable
name="media"
type="MediaWrapper"/>
type="MediaWrapper" />
<variable
name="cover"
type="android.graphics.drawable.BitmapDrawable" />
<variable
name="bgColor"
type="int" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/audio_browser_item_size"
android:background="@{bgColor}"
android:clickable="true"
android:onClick="@{holder::onClick}"
android:focusable="true"
android:onLongClick="@{holder::onLongClick}" >
android:minHeight="@dimen/audio_browser_item_size"
android:onClick="@{holder::onClick}"
android:onLongClick="@{holder::onLongClick}">
<ImageView
android:id="@+id/icon"
......@@ -37,12 +45,13 @@
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:src="@{cover}"
android:onClick="@{holder::onImageClick}"
android:scaleType="centerCrop"
android:src="@{cover}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintDimensionRatio="1"
app:media="@{media}" />
<TextView
......
......@@ -63,6 +63,11 @@ public class HistoryAdapter extends DiffUtilAdapter<MediaWrapper, HistoryAdapter
return mEventsHandler.onLongClick(v, position, getItem(position));
}
public void onImageClick(View v) {
int position = getLayoutPosition();
mEventsHandler.onImageClick(v, position, getItem(position));
}
@Override
protected boolean isSelected() {
return getItem(getLayoutPosition()).hasStateFlags(MediaLibraryItem.FLAG_SELECTED);
......
......@@ -20,14 +20,8 @@
package org.videolan.vlc.gui;
import android.annotation.TargetApi;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.view.ActionMode;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -35,6 +29,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import org.jetbrains.annotations.NotNull;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
......@@ -50,6 +45,13 @@ import org.videolan.vlc.viewmodels.HistoryModel;
import java.util.List;
import androidx.annotation.Nullable;
import androidx.appcompat.view.ActionMode;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class HistoryFragment extends MediaBrowserFragment<HistoryModel> implements IRefreshable, IHistory, SwipeRefreshLayout.OnRefreshListener, IEventsHandler {
public final static String TAG = "VLC/HistoryFragment";
......@@ -245,6 +247,15 @@ public class HistoryFragment extends MediaBrowserFragment<HistoryModel> implemen
return true;
}
@Override
public void onImageClick(@NotNull View v, int position, @NotNull MediaLibraryItem item) {
if (mActionMode != null) {
onClick(v, position, item);
return;
}
onLongClick(v, position, item);
}
@Override
public void onCtxClick(View v, int position, MediaLibraryItem item) {}
......
......@@ -195,6 +195,15 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
return true;
}
@Override
public void onImageClick(@NotNull View v, int position, @NotNull MediaLibraryItem item) {
if (mActionMode != null) {
onClick(v, position, item);
return;
}
onLongClick(v, position, item);
}
@Override
public void onCtxClick(View anchor, final int position, final MediaLibraryItem mediaItem) {
if (mActionMode == null) ContextSheetKt.showContext(this, this, position, mediaItem.getTitle(), Constants.CTX_PLAYLIST_ITEM_FLAGS);
......
......@@ -213,6 +213,12 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
return item != null && mIEventsHandler.onLongClick(view, position, item);
}
public void onImageClick(View v) {
int position = getLayoutPosition();
final MediaLibraryItem item = getItem(position);
if (item != null) mIEventsHandler.onImageClick(v, position, item);
}
private void setCoverlay(boolean selected) {
int resId = selected ? R.drawable.ic_action_mode_select : 0;
if (resId != coverlayResource) {
......
......@@ -31,6 +31,7 @@ import android.view.View;
import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
......@@ -254,6 +255,15 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<MLPagedModel
return true;
}
@Override
public void onImageClick(@NotNull View v, int position, @NotNull MediaLibraryItem item) {
if (mActionMode != null) {
onClick(v, position, item);
return;
}
onLongClick(v, position, item);
}
@Override
public void onCtxClick(@NonNull View anchor, final int position, @NonNull MediaLibraryItem item) {
final int flags;
......
......@@ -158,6 +158,9 @@ public class BaseBrowserAdapter extends DiffUtilAdapter<MediaLibraryItem, BaseBr
public void onClick(View v){}
public void onImageClick(View v) {
}
public boolean onLongClick(View v){ return false; }
public void onCheckBoxClick(View v){}
......@@ -207,6 +210,13 @@ public class BaseBrowserAdapter extends DiffUtilAdapter<MediaLibraryItem, BaseBr
fragment.onClick(v, position, getDataset().get(position));
}
@Override
public void onImageClick(View v) {
int position = getLayoutPosition();
if (position < getDataset().size() && position >= 0)
fragment.onImageClick(v, position, getDataset().get(position));
}
@Override
public void onMoreClick(View v) {
int position = getLayoutPosition();
......
......@@ -457,6 +457,14 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
}
}
override fun onImageClick(v: View, position: Int, item: MediaLibraryItem) {
if (mActionMode != null) {
onClick(v, position, item)
return
}
onLongClick(v, position, item)
}
override fun onUpdateFinished(adapter: RecyclerView.Adapter<*>) {
if (mSwipeRefreshLayout != null) mSwipeRefreshLayout.isRefreshing = false
handler.sendEmptyMessage(MSG_HIDE_LOADING)
......
......@@ -37,6 +37,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import org.jetbrains.annotations.NotNull;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.Folder;
import org.videolan.medialibrary.media.MediaLibraryItem;
......@@ -119,7 +120,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mBinding = VideoGridBinding.inflate(inflater, container, false);
return mBinding.getRoot();
}
......@@ -149,6 +150,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
mSwipeRefreshLayout.setOnRefreshListener(this);
mBinding.videoGrid.setAdapter(mAdapter);
}
@Override
public void onStart() {
super.onStart();
......@@ -198,7 +200,8 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
return;
}
final Resources res = getResources();
if (mGridItemDecoration == null) mGridItemDecoration = new ItemOffsetDecoration(getResources(), R.dimen.left_right_1610_margin, R.dimen.top_bottom_1610_margin);
if (mGridItemDecoration == null)
mGridItemDecoration = new ItemOffsetDecoration(getResources(), R.dimen.left_right_1610_margin, R.dimen.top_bottom_1610_margin);
final boolean listMode = res.getBoolean(R.bool.list_mode)
|| (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT &&
Settings.INSTANCE.getInstance(requireContext()).getBoolean("force_list_portrait", false));
......@@ -264,7 +267,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
}
@Override
public void clear(){
public void clear() {
mAdapter.clear();
}
......@@ -296,7 +299,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
final List<MediaWrapper> list = new ArrayList();
for (MediaWrapper mw : multiSelectHelper.getSelection()) {
if (mw.getType() == MediaWrapper.TYPE_GROUP) list.addAll(((MediaGroup)mw).getAll());
if (mw.getType() == MediaWrapper.TYPE_GROUP) list.addAll(((MediaGroup) mw).getAll());
else list.add(mw);
}
if (!list.isEmpty()) {
......@@ -376,7 +379,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
if (media instanceof MediaGroup) {
final String title = media.getTitle().substring(media.getTitle().toLowerCase().startsWith("the") ? 4 : 0);
if (activity instanceof MainActivity)
((MainActivity)activity).getNavigator().showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, title);
((MainActivity) activity).getNavigator().showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, title);
} else {
media.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
final SharedPreferences settings = Settings.INSTANCE.getInstance(v.getContext());
......@@ -397,13 +400,18 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
return true;
}
@Override
public void onImageClick(@NotNull View v, int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onCtxClick(View v, int position, MediaLibraryItem item) {
final MediaWrapper mw = (MediaWrapper) item;
final boolean group = mw.getType() == MediaWrapper.TYPE_GROUP;
int flags = group ? Constants.CTX_VIDEO_GOUP_FLAGS : Constants.CTX_VIDEO_FLAGS;
if (mw.getTime() != 0l && !group) flags |= Constants.CTX_PLAY_FROM_START;
if (mActionMode == null) ContextSheetKt.showContext(requireActivity(), this, position, item.getTitle(), flags);
if (mActionMode == null)
ContextSheetKt.showContext(requireActivity(), this, position, item.getTitle(), flags);
}
@Override
......@@ -416,7 +424,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
public void updateSeenMediaMarker() {
mAdapter.setSeenMediaMarkerVisible(Settings.INSTANCE.getInstance(requireContext()).getBoolean("media_seen", true));
mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount()-1, Constants.UPDATE_SEEN);
mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount() - 1, Constants.UPDATE_SEEN);
}
@Override
......@@ -426,7 +434,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
if (media == null) return;
final Activity activity = getActivity();
if (activity == null) return;
switch (option){
switch (option) {
case Constants.CTX_PLAY_FROM_START:
playVideo(media, true);
break;
......@@ -447,7 +455,8 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
MediaUtils.INSTANCE.openList(activity, ((MediaGroup) media).getAll(), 0);
break;
case Constants.CTX_APPEND:
if (media instanceof MediaGroup) MediaUtils.INSTANCE.appendMedia(activity, ((MediaGroup)media).getAll());
if (media instanceof MediaGroup)
MediaUtils.INSTANCE.appendMedia(activity, ((MediaGroup) media).getAll());
else MediaUtils.INSTANCE.appendMedia(activity, media);
break;
case Constants.CTX_DOWNLOAD_SUBTITLES:
......
package org.videolan.vlc.interfaces
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.videolan.medialibrary.media.MediaLibraryItem
interface IEventsHandler {
fun onClick(v: View, position: Int, item: MediaLibraryItem)
fun onLongClick(v: View, position: Int, item: MediaLibraryItem): Boolean
fun onImageClick(v: View, position: Int, item: MediaLibraryItem)
fun onCtxClick(v: View, position: Int, item: MediaLibraryItem)
fun onUpdateFinished(adapter: RecyclerView.Adapter<*>)
}
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