musikr: reformat

This commit is contained in:
Alexander Capehart 2025-02-19 11:29:18 -07:00
parent 03c596e03c
commit 313365d118
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 84 additions and 45 deletions

View file

@ -61,7 +61,7 @@ fn main() {
cmake_args.extend(vec![
format!("-DANDROID_NDK_PATH={}", ndk_path),
format!("-DCMAKE_TOOLCHAIN_FILE={}", ndk_toolchain.to_str().unwrap()),
format!("-DANDROID_ABI={}", arch)
format!("-DANDROID_ABI={}", arch),
]);
}
@ -130,12 +130,12 @@ fn main() {
.include(".") // Add the current directory to include path
.flag_if_supported("-std=c++14");
if is_android {
builder.cpp_link_stdlib("c++_static")
.flag("-static-libstdc++")
.flag("-fexceptions")
.flag("-funwind-tables"); // Use shared C++ runtime for Android compatibility
builder
.cpp_link_stdlib("c++_static")
.flag("-static-libstdc++")
.flag("-fexceptions")
.flag("-funwind-tables"); // Use shared C++ runtime for Android compatibility
}
builder.compile("taglib_cxx_bindings");

View file

@ -14,8 +14,14 @@ pub struct JTagMap<'local> {
impl<'local> JTagMap<'local> {
pub fn new(env: Rc<RefCell<JNIEnv<'local>>>) -> Self {
// Get NativeTagMap class and create instance
let tag_map_class = env.borrow_mut().find_class("org/oxycblt/musikr/metadata/NativeTagMap").unwrap();
let tag_map = env.borrow_mut().new_object(&tag_map_class, "()V", &[]).unwrap();
let tag_map_class = env
.borrow_mut()
.find_class("org/oxycblt/musikr/metadata/NativeTagMap")
.unwrap();
let tag_map = env
.borrow_mut()
.new_object(&tag_map_class, "()V", &[])
.unwrap();
// Get ArrayList class
let array_list_class = env.borrow_mut().find_class("java/util/ArrayList").unwrap();
@ -30,12 +36,13 @@ impl<'local> JTagMap<'local> {
fn create_array_list(&self, values: &[String]) -> JObject<'local> {
let mut env = self.env.borrow_mut();
let array_list = env.new_object(&self.array_list_class, "()V", &[]).unwrap();
// Create all JString values first
let j_values: Vec<JString> = values.iter()
let j_values: Vec<JString> = values
.iter()
.map(|value| env.new_string(value).unwrap())
.collect();
// Then add them to the ArrayList
for j_value in j_values {
env.call_method(
@ -43,9 +50,10 @@ impl<'local> JTagMap<'local> {
"add",
"(Ljava/lang/Object;)Z",
&[JValueGen::Object(&j_value)],
).unwrap();
)
.unwrap();
}
array_list
}
@ -53,94 +61,122 @@ impl<'local> JTagMap<'local> {
let mut env = self.env.borrow_mut();
let j_id = env.new_string(id.into()).unwrap();
let j_value = env.new_string(value.into()).unwrap();
env.call_method(
&self.tag_map,
"addID",
"(Ljava/lang/String;Ljava/lang/String;)V",
&[JValueGen::Object(&j_id), JValueGen::Object(&j_value)],
).unwrap();
)
.unwrap();
}
pub fn add_id_list(&self, id: impl Into<String>, values: Vec<String>) {
// Create array list first while holding the borrow
let j_values = self.create_array_list(&values);
// Then create the id and make the call with a new borrow
let mut env = self.env.borrow_mut();
let j_id = env.new_string(id.into()).unwrap();
env.call_method(
&self.tag_map,
"addID",
"(Ljava/lang/String;Ljava/util/List;)V",
&[JValueGen::Object(&j_id), JValueGen::Object(&j_values)],
).unwrap();
)
.unwrap();
}
pub fn add_custom(&self, description: impl Into<String>, value: impl Into<String>) {
let mut env = self.env.borrow_mut();
let j_description = env.new_string(description.into()).unwrap();
let j_value = env.new_string(value.into()).unwrap();
env.call_method(
&self.tag_map,
"addCustom",
"(Ljava/lang/String;Ljava/lang/String;)V",
&[JValueGen::Object(&j_description), JValueGen::Object(&j_value)],
).unwrap();
&[
JValueGen::Object(&j_description),
JValueGen::Object(&j_value),
],
)
.unwrap();
}
pub fn add_custom_list(&self, description: impl Into<String>, values: Vec<String>) {
let j_values = self.create_array_list(&values);
let mut env = self.env.borrow_mut();
let j_description = env.new_string(description.into()).unwrap();
env.call_method(
&self.tag_map,
"addCustom",
"(Ljava/lang/String;Ljava/util/List;)V",
&[JValueGen::Object(&j_description), JValueGen::Object(&j_values)],
).unwrap();
&[
JValueGen::Object(&j_description),
JValueGen::Object(&j_values),
],
)
.unwrap();
}
pub fn add_combined(&self, id: impl Into<String>, description: impl Into<String>, value: impl Into<String>) {
pub fn add_combined(
&self,
id: impl Into<String>,
description: impl Into<String>,
value: impl Into<String>,
) {
let mut env = self.env.borrow_mut();
let j_id = env.new_string(id.into()).unwrap();
let j_description = env.new_string(description.into()).unwrap();
let j_value = env.new_string(value.into()).unwrap();
env.call_method(
&self.tag_map,
"addCombined",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
&[JValueGen::Object(&j_id), JValueGen::Object(&j_description), JValueGen::Object(&j_value)],
).unwrap();
&[
JValueGen::Object(&j_id),
JValueGen::Object(&j_description),
JValueGen::Object(&j_value),
],
)
.unwrap();
}
pub fn add_combined_list(&self, id: impl Into<String>, description: impl Into<String>, values: Vec<String>) {
pub fn add_combined_list(
&self,
id: impl Into<String>,
description: impl Into<String>,
values: Vec<String>,
) {
let j_values = self.create_array_list(&values);
let mut env = self.env.borrow_mut();
let j_id = env.new_string(id.into()).unwrap();
let j_description = env.new_string(description.into()).unwrap();
env.call_method(
&self.tag_map,
"addCombined",
"(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V",
&[JValueGen::Object(&j_id), JValueGen::Object(&j_description), JValueGen::Object(&j_values)],
).unwrap();
&[
JValueGen::Object(&j_id),
JValueGen::Object(&j_description),
JValueGen::Object(&j_values),
],
)
.unwrap();
}
pub fn get_object(&self) -> JObject<'local> {
let mut env = self.env.borrow_mut();
env.call_method(
&self.tag_map,
"getObject",
"()Ljava/util/Map;",
&[],
).unwrap().l().unwrap()
env.call_method(&self.tag_map, "getObject", "()Ljava/util/Map;", &[])
.unwrap()
.l()
.unwrap()
}
}

View file

@ -10,13 +10,12 @@ use std::rc::Rc;
mod jbuilder;
mod jstream;
mod taglib;
mod jtagmap;
mod taglib;
use jbuilder::JMetadataBuilder;
use jstream::JInputStream;
use taglib::file_ref::FileRef;
use android_logger::Filter;
type SharedEnv<'local> = Rc<RefCell<JNIEnv<'local>>>;
// Initialize the logger and panic hook when the library is loaded
@ -26,7 +25,7 @@ fn init() {
android_logger::init_once(
Config::default()
.with_max_level(LevelFilter::Error)
.with_tag("musikr")
.with_tag("musikr"),
);
// Set custom panic hook
@ -40,7 +39,12 @@ fn init() {
};
let location = if let Some(location) = panic_info.location() {
format!("{}:{}:{}", location.file(), location.line(), location.column())
format!(
"{}:{}:{}",
location.file(),
location.line(),
location.column()
)
} else {
"Unknown location".to_string()
};
@ -116,7 +120,6 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
None => {}
}
let metadata = jbuilder.build();
metadata.into_raw()
}