From 313365d11833de2943b670555f95a1449fffc339 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Wed, 19 Feb 2025 11:29:18 -0700 Subject: [PATCH] musikr: reformat --- musikr/src/main/jni/build.rs | 12 ++-- musikr/src/main/jni/src/jtagmap.rs | 104 +++++++++++++++++++---------- musikr/src/main/jni/src/lib.rs | 13 ++-- 3 files changed, 84 insertions(+), 45 deletions(-) diff --git a/musikr/src/main/jni/build.rs b/musikr/src/main/jni/build.rs index 617eea86a..c9a6bc84f 100644 --- a/musikr/src/main/jni/build.rs +++ b/musikr/src/main/jni/build.rs @@ -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"); diff --git a/musikr/src/main/jni/src/jtagmap.rs b/musikr/src/main/jni/src/jtagmap.rs index 87d030ec7..821360499 100644 --- a/musikr/src/main/jni/src/jtagmap.rs +++ b/musikr/src/main/jni/src/jtagmap.rs @@ -14,8 +14,14 @@ pub struct JTagMap<'local> { impl<'local> JTagMap<'local> { pub fn new(env: Rc>>) -> 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 = values.iter() + let j_values: Vec = 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, values: Vec) { // 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, value: impl Into) { 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, values: Vec) { 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, description: impl Into, value: impl Into) { + pub fn add_combined( + &self, + id: impl Into, + description: impl Into, + value: impl Into, + ) { 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, description: impl Into, values: Vec) { + pub fn add_combined_list( + &self, + id: impl Into, + description: impl Into, + values: Vec, + ) { 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() } } diff --git a/musikr/src/main/jni/src/lib.rs b/musikr/src/main/jni/src/lib.rs index 0f20cc280..d3d489faa 100644 --- a/musikr/src/main/jni/src/lib.rs +++ b/musikr/src/main/jni/src/lib.rs @@ -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>>; // 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() }