Commit 9cad3023 authored by Volker Krause's avatar Volker Krause
Browse files

Support decoding of arrays of all convertible types and not just QStrings

parent d0c07df7
Pipeline #106616 passed with stage
in 1 minute and 23 seconds
......@@ -6,6 +6,8 @@
#include <KAndroidExtras/JniArray>
#include <KAndroidExtras/JniTypeTraits>
#include <KAndroidExtras/JavaTypes>
#include <KAndroidExtras/Uri>
#include <QtTest/qtest.h>
......@@ -38,6 +40,10 @@ private Q_SLOTS:
JNIEnv::m_arrayLength = 4;
const auto a3 = Jni::fromArray<std::vector<int>>(array);
QCOMPARE(a3.size(), 4);
JNIEnv::m_arrayLength = 1;
const auto a4 = Jni::fromArray<QVector<QUrl>>(array);
QCOMPARE(a4.size(), 1);
#endif
}
};
......
......@@ -63,8 +63,8 @@ struct FromArray<Container, QAndroidJniObject, false>
}
};
template <typename Container>
struct FromArray<Container, QString, false>
template <typename Container, typename Value>
struct FromArray<Container, Value, false>
{
inline auto operator()(const QAndroidJniObject &array) const
{
......@@ -77,7 +77,7 @@ struct FromArray<Container, QString, false>
Container r;
r.reserve(size);
for (auto i = 0; i < size; ++i) {
r.push_back(QAndroidJniObject::fromLocalRef(env->GetObjectArrayElement(a, i)).toString());
r.push_back(Jni::reverse_converter<Value>::type::convert(QAndroidJniObject::fromLocalRef(env->GetObjectArrayElement(a, i))));
}
return r;
}
......@@ -113,7 +113,10 @@ struct FromArray<Container, Value, true>
namespace Jni {
/** Convert a JNI array to a C++ container.
* Container value types can be any of QAndroidJniObject, QString or a basic JNI type.
* Container value types can be any of
* - QAndroidJniObject
* - a basic JNI type
* - a type with a conversion defined with @c JNI_DECLARE_CONVERTER
*/
template <typename Container> constexpr __attribute__((__unused__)) Internal::FromArray<Container, typename Container::value_type, Jni::is_basic_type<typename Container::value_type>::value> fromArray = {};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment