musikr: reformat
This commit is contained in:
parent
03c596e03c
commit
313365d118
3 changed files with 84 additions and 45 deletions
|
|
@ -61,7 +61,7 @@ fn main() {
|
||||||
cmake_args.extend(vec![
|
cmake_args.extend(vec![
|
||||||
format!("-DANDROID_NDK_PATH={}", ndk_path),
|
format!("-DANDROID_NDK_PATH={}", ndk_path),
|
||||||
format!("-DCMAKE_TOOLCHAIN_FILE={}", ndk_toolchain.to_str().unwrap()),
|
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
|
.include(".") // Add the current directory to include path
|
||||||
.flag_if_supported("-std=c++14");
|
.flag_if_supported("-std=c++14");
|
||||||
|
|
||||||
|
|
||||||
if is_android {
|
if is_android {
|
||||||
builder.cpp_link_stdlib("c++_static")
|
builder
|
||||||
.flag("-static-libstdc++")
|
.cpp_link_stdlib("c++_static")
|
||||||
.flag("-fexceptions")
|
.flag("-static-libstdc++")
|
||||||
.flag("-funwind-tables"); // Use shared C++ runtime for Android compatibility
|
.flag("-fexceptions")
|
||||||
|
.flag("-funwind-tables"); // Use shared C++ runtime for Android compatibility
|
||||||
}
|
}
|
||||||
builder.compile("taglib_cxx_bindings");
|
builder.compile("taglib_cxx_bindings");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,14 @@ pub struct JTagMap<'local> {
|
||||||
impl<'local> JTagMap<'local> {
|
impl<'local> JTagMap<'local> {
|
||||||
pub fn new(env: Rc<RefCell<JNIEnv<'local>>>) -> Self {
|
pub fn new(env: Rc<RefCell<JNIEnv<'local>>>) -> Self {
|
||||||
// Get NativeTagMap class and create instance
|
// Get NativeTagMap class and create instance
|
||||||
let tag_map_class = env.borrow_mut().find_class("org/oxycblt/musikr/metadata/NativeTagMap").unwrap();
|
let tag_map_class = env
|
||||||
let tag_map = env.borrow_mut().new_object(&tag_map_class, "()V", &[]).unwrap();
|
.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
|
// Get ArrayList class
|
||||||
let array_list_class = env.borrow_mut().find_class("java/util/ArrayList").unwrap();
|
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> {
|
fn create_array_list(&self, values: &[String]) -> JObject<'local> {
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
let array_list = env.new_object(&self.array_list_class, "()V", &[]).unwrap();
|
let array_list = env.new_object(&self.array_list_class, "()V", &[]).unwrap();
|
||||||
|
|
||||||
// Create all JString values first
|
// 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())
|
.map(|value| env.new_string(value).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Then add them to the ArrayList
|
// Then add them to the ArrayList
|
||||||
for j_value in j_values {
|
for j_value in j_values {
|
||||||
env.call_method(
|
env.call_method(
|
||||||
|
|
@ -43,9 +50,10 @@ impl<'local> JTagMap<'local> {
|
||||||
"add",
|
"add",
|
||||||
"(Ljava/lang/Object;)Z",
|
"(Ljava/lang/Object;)Z",
|
||||||
&[JValueGen::Object(&j_value)],
|
&[JValueGen::Object(&j_value)],
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
array_list
|
array_list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,94 +61,122 @@ impl<'local> JTagMap<'local> {
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
let j_id = env.new_string(id.into()).unwrap();
|
let j_id = env.new_string(id.into()).unwrap();
|
||||||
let j_value = env.new_string(value.into()).unwrap();
|
let j_value = env.new_string(value.into()).unwrap();
|
||||||
|
|
||||||
env.call_method(
|
env.call_method(
|
||||||
&self.tag_map,
|
&self.tag_map,
|
||||||
"addID",
|
"addID",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;)V",
|
"(Ljava/lang/String;Ljava/lang/String;)V",
|
||||||
&[JValueGen::Object(&j_id), JValueGen::Object(&j_value)],
|
&[JValueGen::Object(&j_id), JValueGen::Object(&j_value)],
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_id_list(&self, id: impl Into<String>, values: Vec<String>) {
|
pub fn add_id_list(&self, id: impl Into<String>, values: Vec<String>) {
|
||||||
// Create array list first while holding the borrow
|
// Create array list first while holding the borrow
|
||||||
let j_values = self.create_array_list(&values);
|
let j_values = self.create_array_list(&values);
|
||||||
|
|
||||||
// Then create the id and make the call with a new borrow
|
// Then create the id and make the call with a new borrow
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
let j_id = env.new_string(id.into()).unwrap();
|
let j_id = env.new_string(id.into()).unwrap();
|
||||||
|
|
||||||
env.call_method(
|
env.call_method(
|
||||||
&self.tag_map,
|
&self.tag_map,
|
||||||
"addID",
|
"addID",
|
||||||
"(Ljava/lang/String;Ljava/util/List;)V",
|
"(Ljava/lang/String;Ljava/util/List;)V",
|
||||||
&[JValueGen::Object(&j_id), JValueGen::Object(&j_values)],
|
&[JValueGen::Object(&j_id), JValueGen::Object(&j_values)],
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_custom(&self, description: impl Into<String>, value: impl Into<String>) {
|
pub fn add_custom(&self, description: impl Into<String>, value: impl Into<String>) {
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
let j_description = env.new_string(description.into()).unwrap();
|
let j_description = env.new_string(description.into()).unwrap();
|
||||||
let j_value = env.new_string(value.into()).unwrap();
|
let j_value = env.new_string(value.into()).unwrap();
|
||||||
|
|
||||||
env.call_method(
|
env.call_method(
|
||||||
&self.tag_map,
|
&self.tag_map,
|
||||||
"addCustom",
|
"addCustom",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;)V",
|
"(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>) {
|
pub fn add_custom_list(&self, description: impl Into<String>, values: Vec<String>) {
|
||||||
let j_values = self.create_array_list(&values);
|
let j_values = self.create_array_list(&values);
|
||||||
|
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
let j_description = env.new_string(description.into()).unwrap();
|
let j_description = env.new_string(description.into()).unwrap();
|
||||||
|
|
||||||
env.call_method(
|
env.call_method(
|
||||||
&self.tag_map,
|
&self.tag_map,
|
||||||
"addCustom",
|
"addCustom",
|
||||||
"(Ljava/lang/String;Ljava/util/List;)V",
|
"(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 mut env = self.env.borrow_mut();
|
||||||
let j_id = env.new_string(id.into()).unwrap();
|
let j_id = env.new_string(id.into()).unwrap();
|
||||||
let j_description = env.new_string(description.into()).unwrap();
|
let j_description = env.new_string(description.into()).unwrap();
|
||||||
let j_value = env.new_string(value.into()).unwrap();
|
let j_value = env.new_string(value.into()).unwrap();
|
||||||
|
|
||||||
env.call_method(
|
env.call_method(
|
||||||
&self.tag_map,
|
&self.tag_map,
|
||||||
"addCombined",
|
"addCombined",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
"(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 j_values = self.create_array_list(&values);
|
||||||
|
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
let j_id = env.new_string(id.into()).unwrap();
|
let j_id = env.new_string(id.into()).unwrap();
|
||||||
let j_description = env.new_string(description.into()).unwrap();
|
let j_description = env.new_string(description.into()).unwrap();
|
||||||
|
|
||||||
env.call_method(
|
env.call_method(
|
||||||
&self.tag_map,
|
&self.tag_map,
|
||||||
"addCombined",
|
"addCombined",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V",
|
"(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> {
|
pub fn get_object(&self) -> JObject<'local> {
|
||||||
let mut env = self.env.borrow_mut();
|
let mut env = self.env.borrow_mut();
|
||||||
env.call_method(
|
env.call_method(&self.tag_map, "getObject", "()Ljava/util/Map;", &[])
|
||||||
&self.tag_map,
|
.unwrap()
|
||||||
"getObject",
|
.l()
|
||||||
"()Ljava/util/Map;",
|
.unwrap()
|
||||||
&[],
|
|
||||||
).unwrap().l().unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,12 @@ use std::rc::Rc;
|
||||||
|
|
||||||
mod jbuilder;
|
mod jbuilder;
|
||||||
mod jstream;
|
mod jstream;
|
||||||
mod taglib;
|
|
||||||
mod jtagmap;
|
mod jtagmap;
|
||||||
|
mod taglib;
|
||||||
|
|
||||||
use jbuilder::JMetadataBuilder;
|
use jbuilder::JMetadataBuilder;
|
||||||
use jstream::JInputStream;
|
use jstream::JInputStream;
|
||||||
use taglib::file_ref::FileRef;
|
use taglib::file_ref::FileRef;
|
||||||
use android_logger::Filter;
|
|
||||||
type SharedEnv<'local> = Rc<RefCell<JNIEnv<'local>>>;
|
type SharedEnv<'local> = Rc<RefCell<JNIEnv<'local>>>;
|
||||||
|
|
||||||
// Initialize the logger and panic hook when the library is loaded
|
// Initialize the logger and panic hook when the library is loaded
|
||||||
|
|
@ -26,7 +25,7 @@ fn init() {
|
||||||
android_logger::init_once(
|
android_logger::init_once(
|
||||||
Config::default()
|
Config::default()
|
||||||
.with_max_level(LevelFilter::Error)
|
.with_max_level(LevelFilter::Error)
|
||||||
.with_tag("musikr")
|
.with_tag("musikr"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set custom panic hook
|
// Set custom panic hook
|
||||||
|
|
@ -40,7 +39,12 @@ fn init() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let location = if let Some(location) = panic_info.location() {
|
let location = if let Some(location) = panic_info.location() {
|
||||||
format!("{}:{}:{}", location.file(), location.line(), location.column())
|
format!(
|
||||||
|
"{}:{}:{}",
|
||||||
|
location.file(),
|
||||||
|
location.line(),
|
||||||
|
location.column()
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
"Unknown location".to_string()
|
"Unknown location".to_string()
|
||||||
};
|
};
|
||||||
|
|
@ -116,7 +120,6 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let metadata = jbuilder.build();
|
let metadata = jbuilder.build();
|
||||||
metadata.into_raw()
|
metadata.into_raw()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue