/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* 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
*
* http://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.
*/
/**
* @addtogroup UI_Components
* @{
*
* @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
*
* @since 1.0
* @version 1.0
*/
/**
* @file abstract_adapter.h
*
* @brief Defines the base class for adapters.
*
* @since 1.0
* @version 1.0
*/
#ifndef GRAPHIC_LITE_ABSTRACT_ADAPTER_H
#define GRAPHIC_LITE_ABSTRACT_ADAPTER_H
#include "components/ui_view.h"
namespace OHOS {
/**
* @brief Defines the base class for adapters. You can derive AbstractAdapter based on actual requirements
* and use the GetView() and GetCount() functions to implement adapters of different data types.
* For details, see {@link TextAdapter}.
* @since 1.0
* @version 1.0
*/
class AbstractAdapter : public HeapBase {
public:
/**
* @brief A constructor used to create an AbstractAdapter instance.
* @since 1.0
* @version 1.0
*/
AbstractAdapter() {}
/**
* @brief A destructor used to delete the AbstractAdapter instance.
* @since 1.0
* @version 1.0
*/
virtual ~AbstractAdapter() {}
/**
* @brief Obtains the number of adapter data items.
*
* @return Returns the number of adapter data items.
* @since 1.0
* @version 1.0
*/
virtual uint16_t GetCount() = 0;
/**
* @brief Obtains a UIView instance to convert adapter data into another UIView instance.
*
* @param inView Indicates the pointer to the reusable instance. If this parameter is not NULL, a reusable
* UIView instance is available. In this case, this function does not need to create a new
* UIView instance, just reusing the instance specified by inView to update the
* inView data.
* If this parameter is NULL, there is no reusable UIView instance. In this case, this
* function needs to create a new UIView instance.
*
* @param index Indicates the adapter data index.
*
* @return UIView Returns the pointer to the UIView instance constructed by the adapter.
* @since 1.0
* @version 1.0
*/
virtual UIView* GetView(UIView* inView, int16_t index) = 0;
virtual void DeleteView(UIView*& view)
{
delete view;
view = nullptr;
};
virtual int16_t GetItemWidthWithMargin(int16_t index)
{
UIView* view = GetView(nullptr, index);
if (view == nullptr) {
return 0;
}
int16_t width = view->GetWidthWithMargin();
DeleteView(view);
return width;
}
virtual int16_t GetItemHeightWithMargin(int16_t index)
{
UIView* view = GetView(nullptr, index);
if (view == nullptr) {
return 0;
}
int16_t height = view->GetHeightWithMargin();
DeleteView(view);
return height;
}
};
} // namespace OHOS
#endif // GRAPHIC_LITE_ABSTRACT_ADAPTER_H