我正在使用MVVMCross和InfiniteScroll IncrementalListView,我有商店视图,商店视图模型,商店商品视图和商店商品视图模型。
问题出在列表视图中,我显示了一个音频文件列表。每个列表项都包含音频名称,说明,播放按钮,下载按钮和进度条。
当用户点击播放按钮时,我会将商店项目视图模型中的IsBusy属性设置为true,这将绑定到进度条可见性,效果很好。但是在媒体播放器开始播放之后,我会让IsBusy变错,但进度条仍然显示。 PlayIcon属性也会发生。我不确定是什么原因造成的。请帮我下面是我的代码。
我的主视图模型
using Japam.Core.ClientModels;
using Japam.Core.Services.DataServices;
using System.Collections.ObjectModel;
using Japam.Core.Helpers;
using Sequence.Plugins.InfiniteScroll;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform;
using Japam.Core.Services.PlatformServices;
namespace Japam.Core.ViewModels
{
public class MantraStoreViewModel : BaseViewModel
{
private readonly IFirebaseService fbs;
private readonly IIncrementalCollectionFactory _incrementalCollectionFactory;
private readonly IMantraService ms;
private int CurrentPage = 1;
private string startKey = "m01";
private bool AnythingLeft = true;
public MantraStoreViewModel(IFirebaseService firebaseService,IMantraService mantraService, IIncrementalCollectionFactory incrementalCollectionFactory)
{
fbs = firebaseService;
ms = mantraService;
_incrementalCollectionFactory = incrementalCollectionFactory;
}
private ObservableCollection<MantraStoreItemViewModel> _RemoteMantraas;
public ObservableCollection<MantraStoreItemViewModel> RemoteMantraas
{
get { return _RemoteMantraas; }
set { SetProperty(ref _RemoteMantraas, value); }
}
public void UpdateList(MantraStoreItemViewModel CurrentMantra)
{
int location = RemoteMantraas.IndexOf(CurrentMantra);
RemoteMantraas.Remove(CurrentMantra);
RemoteMantraas.Insert(location, CurrentMantra);
}
public void Init()
{
RemoteMantraas = _incrementalCollectionFactory.GetCollection<MantraStoreItemViewModel>(async (count, pageSize) => {
ObservableCollection<MantraStoreItemViewModel> newMantraas = new ObservableCollection<MantraStoreItemViewModel>();
if (AnythingLeft)
{
var mantraas = await fbs.GetMantraas(startKey, CurrentPage);
if (mantraas != null)
{
if (mantraas.Count < Settings.StorePageSize)
AnythingLeft = false;
foreach (var mantra in mantraas)
{
newMantraas.Add(new MantraStoreItemViewModel(Mvx.GetSingleton<ISimplePlayService>()) { MantraItem = mantra.Object } );
}
startKey = "m" + (mantraas.Count + 1);
}
}
return newMantraas;
},Settings.StorePageSize);
}
}
}
我的主视图axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/toolbar" layout="@layout/toolbar" />
<Sequence.Plugins.InfiniteScroll.Droid.IncrementalListView
android:smoothScrollbar="true"
android:scrollingCache="false"
android:animationCache="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:divider="@color/primary"
android:dividerHeight="1dp"
local:MvxBind="ItemsSource RemoteMantraas;"
local:MvxItemTemplate="@layout/mantrastoreitem" />
</LinearLayout>
我的商店项目视图模型
using Japam.Core.ClientModels;
using MvvmCross.Core.ViewModels;
using Japam.Core.Services.PlatformServices;
using Japam.Core.Common;
namespace Japam.Core.ViewModels
{
public class MantraStoreItemViewModel: MvxViewModel
{
private Mantra _MantraItem;
private ISimplePlayService playService;
public MantraStoreItemViewModel(ISimplePlayService _playService)
{
playService = _playService;
playService.MediaEnded = MediaEnded;
playService.MediaBusyChanged = MediaBusyChanged;
PlayIcon = AppConstants.Icons.FAIcons[AppConstants.FAIconNames.FAPlayCircleO];
}
public void MediaEnded()
{
PlayIcon = AppConstants.Icons.FAIcons[AppConstants.FAIconNames.FAPlayCircleO];
}
public void MediaBusyChanged(bool status)
{
IsBusy = status;//not working here
}
private bool _IsBusy;
public bool IsBusy
{
get { return _IsBusy; }
set { SetProperty(ref _IsBusy, value); }
}
public Mantra MantraItem
{
get { return _MantraItem; }
set { SetProperty(ref _MantraItem, value); }
}
private FontAwesomeIcon _PlayIcon;
public FontAwesomeIcon PlayIcon
{
get { return _PlayIcon; }
set { SetProperty(ref _PlayIcon, value); }
}
private MvxCommand _DownloadCommand;
public MvxCommand DownloadCommand
{
get
{
_DownloadCommand = _DownloadCommand ?? new MvxCommand(() => Download());
return _DownloadCommand;
}
}
private void Download()
{
}
private MvxCommand _PlayCommand;
public MvxCommand PlayCommand
{
get
{
_PlayCommand = _PlayCommand ?? new MvxCommand(() => Play());
return _PlayCommand;
}
}
private void Play()
{
PlayIcon = AppConstants.Icons.FAIcons[AppConstants.FAIconNames.FAStopCircleO];
IsBusy = true;//works here
playService.Play(MantraItem.AudioFileName);
}
}
}
我的商品项目axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txtMantraName"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="2dp"
android:layout_marginLeft="2dp"
android:foreground="@color/primarytext"
android:textSize="20dp"
local:MvxBind="Text MantraItem.MantraName" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txtMantraFor"
android:gravity="center_vertical"
android:textSize="15dp"
android:layout_below="@id/txtMantraName"
android:layout_alignParentLeft="true"
android:layout_marginTop="2dp"
android:foreground="@color/secondartext"
local:MvxBind="Text MantraItem.MantraFor" />
<Plugin.Iconize.Droid.Controls.IconButton
android:id="@+id/btnPlay"
android:textSize="15dp"
android:textColor="@color/accent"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roundedbutton"
local:MvxBind="Text PlayIcon,Converter=FontAwesomeToText;Click PlayCommand" />
<Plugin.Iconize.Droid.Controls.IconButton
android:id="@+id/btnDownload"
android:textSize="15dp"
android:textColor="@color/accent"
android:text="{fa-download}"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true"
android:layout_below="@id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roundedbutton"
local:MvxBind="Click DownloadCommand" />
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/ctrlActivityIndicator"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateOnly="true"
android:keepScreenOn="true"
local:MvxBind="Visibility IsBusy,Converter=VisibleOrInvisible" />
</RelativeLayout>