// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.Play.Core.Internal;
using UnityEngine;
namespace Google.Play.AssetDelivery.Internal
{
///
/// Wraps Play Core's AssetPackStates which represents the current state of all requested asset packs.
///
internal class AssetPackStates
{
///
/// The total size of all requested packs in bytes.
///
public long TotalBytes { get; private set; }
///
/// A dictionary containing the download states of all requested asset packs.
///
public Dictionary PackStates { get; private set; }
///
/// Creates an AssetPackStates with all the fields of the underlying Java object.
///
public AssetPackStates(AndroidJavaObject packStates)
{
using (packStates)
{
TotalBytes = packStates.Call("totalBytes");
PackStates = ConvertPackStatesJavaMapToDictionary(packStates);
}
}
private Dictionary ConvertPackStatesJavaMapToDictionary(
AndroidJavaObject packStates)
{
using (var javaMap = packStates.Call("packStates"))
{
return PlayCoreHelper.ConvertJavaMap(javaMap)
.ToDictionary(kvp => kvp.Key, kvp => new AssetPackState(kvp.Value));
}
}
public override string ToString()
{
var stateDescription = new StringBuilder();
stateDescription.AppendFormat("total bytes: {0}\n", TotalBytes);
stateDescription.AppendLine("pack names: " + string.Join(", ", PackStates.Keys.ToArray()));
return stateDescription.ToString();
}
}
}