CameraActivity refactoring
This commit is contained in:
parent
679bd4e4c9
commit
e625543b94
13 changed files with 193 additions and 224 deletions
|
@ -7,9 +7,7 @@
|
|||
|
||||
#include "core/errorstrings.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "../../platforms/android/android_controller.h"
|
||||
#include "../../platforms/android/androidutils.h"
|
||||
#include <QJniObject>
|
||||
#include "platforms/android/android_controller.h"
|
||||
#endif
|
||||
#ifdef Q_OS_IOS
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
@ -48,10 +46,6 @@ namespace
|
|||
#if defined Q_OS_ANDROID
|
||||
ImportController *mInstance = nullptr;
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
constexpr auto AndroidCameraActivity = "org.amnezia.vpn.CameraActivity";
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
ImportController::ImportController(const QSharedPointer<ServersModel> &serversModel,
|
||||
|
@ -61,18 +55,6 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
mInstance = this;
|
||||
|
||||
AndroidUtils::runOnAndroidThreadAsync([]() {
|
||||
JNINativeMethod methods[] {
|
||||
{ "passDataToDecoder", "(Ljava/lang/String;)V", reinterpret_cast<void *>(onNewQrCodeDataChunk) },
|
||||
};
|
||||
|
||||
QJniObject javaClass(AndroidCameraActivity);
|
||||
QJniEnvironment env;
|
||||
jclass objectClass = env->GetObjectClass(javaClass.object<jobject>());
|
||||
env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));
|
||||
env->DeleteLocalRef(objectClass);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -320,26 +302,20 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
|
|||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
void ImportController::onNewQrCodeDataChunk(JNIEnv *env, jobject thiz, jstring data)
|
||||
static QMutex qrDecodeMutex;
|
||||
|
||||
// static
|
||||
bool ImportController::decodeQrCode(const QString &code)
|
||||
{
|
||||
Q_UNUSED(thiz);
|
||||
const char *buffer = env->GetStringUTFChars(data, nullptr);
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
QMutexLocker lock(&qrDecodeMutex);
|
||||
|
||||
QString parcelBody(buffer);
|
||||
env->ReleaseStringUTFChars(data, buffer);
|
||||
|
||||
if (mInstance != nullptr) {
|
||||
if (!mInstance->m_isQrCodeProcessed) {
|
||||
mInstance->m_qrCodeChunks.clear();
|
||||
mInstance->m_isQrCodeProcessed = true;
|
||||
mInstance->m_totalQrCodeChunksCount = 0;
|
||||
mInstance->m_receivedQrCodeChunksCount = 0;
|
||||
}
|
||||
mInstance->parseQrCodeChunk(parcelBody);
|
||||
if (!mInstance->m_isQrCodeProcessed) {
|
||||
mInstance->m_qrCodeChunks.clear();
|
||||
mInstance->m_isQrCodeProcessed = true;
|
||||
mInstance->m_totalQrCodeChunksCount = 0;
|
||||
mInstance->m_receivedQrCodeChunksCount = 0;
|
||||
}
|
||||
return mInstance->parseQrCodeChunk(code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -360,17 +336,14 @@ void ImportController::startDecodingQr()
|
|||
|
||||
void ImportController::stopDecodingQr()
|
||||
{
|
||||
#if defined Q_OS_ANDROID
|
||||
QJniObject::callStaticMethod<void>(AndroidCameraActivity, "stopQrCodeReader", "()V");
|
||||
#endif
|
||||
emit qrDecodingFinished();
|
||||
}
|
||||
|
||||
void ImportController::parseQrCodeChunk(const QString &code)
|
||||
bool ImportController::parseQrCodeChunk(const QString &code)
|
||||
{
|
||||
// qDebug() << code;
|
||||
if (!m_isQrCodeProcessed)
|
||||
return;
|
||||
return false;
|
||||
|
||||
// check if chunk received
|
||||
QByteArray ba = QByteArray::fromBase64(code.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
|
@ -404,6 +377,7 @@ void ImportController::parseQrCodeChunk(const QString &code)
|
|||
m_isQrCodeProcessed = false;
|
||||
qDebug() << "stopDecodingQr";
|
||||
stopDecodingQr();
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << "error while extracting data from qr";
|
||||
m_qrCodeChunks.clear();
|
||||
|
@ -417,8 +391,10 @@ void ImportController::parseQrCodeChunk(const QString &code)
|
|||
m_isQrCodeProcessed = false;
|
||||
qDebug() << "stopDecodingQr";
|
||||
stopDecodingQr();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
double ImportController::getQrCodeScanProgressBarValue()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue