use crate::interop::java::JavaObject;
use ferroui_controls::platform::{INativeControlHostDestroyableControlHandle, IPlatformHandle};
use std::any::Any;
use std::cell::RefCell;
pub(crate) const ANDROID_VIEW_DESCRIPTOR: &str = "android.view.View";
pub struct AndroidViewControlHandle {
view: RefCell<Option<JavaObject>>,
handle: isize,
}
impl AndroidViewControlHandle {
pub fn new(view: JavaObject) -> Self {
let handle = view.handle();
Self { view: RefCell::new(Some(view)), handle }
}
pub fn view(&self) -> Option<JavaObject> {
self.view.borrow().clone()
}
}
impl IPlatformHandle for AndroidViewControlHandle {
fn handle(&self) -> isize {
self.handle
}
fn handle_descriptor(&self) -> Option<&str> {
Some(ANDROID_VIEW_DESCRIPTOR)
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl INativeControlHostDestroyableControlHandle for AndroidViewControlHandle {
fn destroy(&self) {
let view = self.view.borrow_mut().take();
drop(view);
}
}