Android: Scan on background thread and show progress

This commit is contained in:
Connor McLaughlin
2020-10-24 15:46:08 +10:00
parent 5084c90e08
commit e22c7608e3
9 changed files with 314 additions and 17 deletions

View File

@ -1,6 +1,8 @@
set(SRCS
android_host_interface.cpp
android_host_interface.h
android_progress_callback.cpp
android_progress_callback.h
android_settings_interface.cpp
android_settings_interface.h
)

View File

@ -1,4 +1,5 @@
#include "android_host_interface.h"
#include "android_progress_callback.h"
#include "common/assert.h"
#include "common/audio_stream.h"
#include "common/file_system.h"
@ -522,10 +523,10 @@ void AndroidHostInterface::SetControllerAxisState(u32 index, s32 button_code, fl
false);
}
void AndroidHostInterface::RefreshGameList(bool invalidate_cache, bool invalidate_database)
void AndroidHostInterface::RefreshGameList(bool invalidate_cache, bool invalidate_database, ProgressCallback* progress_callback)
{
m_game_list->SetSearchDirectoriesFromSettings(m_settings_interface);
m_game_list->Refresh(invalidate_cache, invalidate_database);
m_game_list->Refresh(invalidate_cache, invalidate_database, progress_callback);
}
void AndroidHostInterface::ApplySettings(bool display_osd_messages)
@ -709,9 +710,10 @@ DEFINE_JNI_ARGS_METHOD(jint, AndroidHostInterface_getControllerAxisCode, jobject
}
DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_refreshGameList, jobject obj, jboolean invalidate_cache,
jboolean invalidate_database)
jboolean invalidate_database, jobject progress_callback)
{
AndroidHelpers::GetNativeClass(env, obj)->RefreshGameList(invalidate_cache, invalidate_database);
AndroidProgressCallback cb(env, progress_callback);
AndroidHelpers::GetNativeClass(env, obj)->RefreshGameList(invalidate_cache, invalidate_database, &cb);
}
static const char* DiscRegionToString(DiscRegion region)

View File

@ -1,6 +1,7 @@
#pragma once
#include "android_settings_interface.h"
#include "common/event.h"
#include "common/progress_callback.h"
#include "frontend-common/common_host_interface.h"
#include <array>
#include <atomic>
@ -49,7 +50,7 @@ public:
void SetControllerButtonState(u32 index, s32 button_code, bool pressed);
void SetControllerAxisState(u32 index, s32 button_code, float value);
void RefreshGameList(bool invalidate_cache, bool invalidate_database);
void RefreshGameList(bool invalidate_cache, bool invalidate_database, ProgressCallback* progress_callback);
void ApplySettings(bool display_osd_messages);
protected:

View File

@ -0,0 +1,105 @@
#include "android_progress_callback.h"
#include "android_host_interface.h"
#include "common/log.h"
#include "common/assert.h"
Log_SetChannel(AndroidProgressCallback);
AndroidProgressCallback::AndroidProgressCallback(JNIEnv* env, jobject java_object)
: m_java_object(java_object)
{
jclass cls = env->GetObjectClass(java_object);
m_set_title_method = env->GetMethodID(cls, "setTitle", "(Ljava/lang/String;)V");
m_set_status_text_method = env->GetMethodID(cls, "setStatusText", "(Ljava/lang/String;)V");
m_set_progress_range_method = env->GetMethodID(cls, "setProgressRange", "(I)V");
m_set_progress_value_method = env->GetMethodID(cls, "setProgressValue", "(I)V");
m_modal_error_method = env->GetMethodID(cls, "modalError", "(Ljava/lang/String;)V");
m_modal_information_method = env->GetMethodID(cls, "modalInformation", "(Ljava/lang/String;)V");
m_modal_confirmation_method = env->GetMethodID(cls, "modalConfirmation", "(Ljava/lang/String;)Z");
Assert(m_set_status_text_method && m_set_progress_range_method && m_set_progress_value_method && m_modal_error_method && m_modal_information_method && m_modal_confirmation_method);
}
AndroidProgressCallback::~AndroidProgressCallback() = default;
bool AndroidProgressCallback::IsCancelled() const
{
return false;
}
void AndroidProgressCallback::SetCancellable(bool cancellable)
{
if (m_cancellable == cancellable)
return;
BaseProgressCallback::SetCancellable(cancellable);
}
void AndroidProgressCallback::SetTitle(const char* title)
{
JNIEnv* env = AndroidHelpers::GetJNIEnv();
jstring text_jstr = env->NewStringUTF(title);
env->CallVoidMethod(m_java_object, m_set_title_method, text_jstr);
}
void AndroidProgressCallback::SetStatusText(const char* text)
{
JNIEnv* env = AndroidHelpers::GetJNIEnv();
jstring text_jstr = env->NewStringUTF(text);
env->CallVoidMethod(m_java_object, m_set_status_text_method, text_jstr);
}
void AndroidProgressCallback::SetProgressRange(u32 range)
{
BaseProgressCallback::SetProgressRange(range);
JNIEnv* env = AndroidHelpers::GetJNIEnv();
env->CallVoidMethod(m_java_object, m_set_progress_range_method, static_cast<jint>(range));
}
void AndroidProgressCallback::SetProgressValue(u32 value)
{
BaseProgressCallback::SetProgressValue(value);
JNIEnv* env = AndroidHelpers::GetJNIEnv();
env->CallVoidMethod(m_java_object, m_set_progress_value_method, static_cast<jint>(value));
}
void AndroidProgressCallback::DisplayError(const char* message)
{
Log_ErrorPrintf("%s", message);
}
void AndroidProgressCallback::DisplayWarning(const char* message)
{
Log_WarningPrintf("%s", message);
}
void AndroidProgressCallback::DisplayInformation(const char* message)
{
Log_InfoPrintf("%s", message);
}
void AndroidProgressCallback::DisplayDebugMessage(const char* message)
{
Log_DevPrintf("%s", message);
}
void AndroidProgressCallback::ModalError(const char* message)
{
JNIEnv* env = AndroidHelpers::GetJNIEnv();
jstring message_jstr = env->NewStringUTF(message);
env->CallVoidMethod(m_java_object, m_modal_error_method, message_jstr);
}
bool AndroidProgressCallback::ModalConfirmation(const char* message)
{
JNIEnv* env = AndroidHelpers::GetJNIEnv();
jstring message_jstr = env->NewStringUTF(message);
return env->CallBooleanMethod(m_java_object, m_modal_confirmation_method, message_jstr);
}
void AndroidProgressCallback::ModalInformation(const char* message)
{
JNIEnv* env = AndroidHelpers::GetJNIEnv();
jstring message_jstr = env->NewStringUTF(message);
env->CallVoidMethod(m_java_object, m_modal_information_method, message_jstr);
}

View File

@ -0,0 +1,38 @@
#pragma once
#include "common/progress_callback.h"
#include <jni.h>
class AndroidProgressCallback final : public BaseProgressCallback
{
public:
AndroidProgressCallback(JNIEnv* env, jobject java_object);
~AndroidProgressCallback();
bool IsCancelled() const override;
void SetCancellable(bool cancellable) override;
void SetTitle(const char* title) override;
void SetStatusText(const char* text) override;
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override;
void DisplayError(const char* message) override;
void DisplayWarning(const char* message) override;
void DisplayInformation(const char* message) override;
void DisplayDebugMessage(const char* message) override;
void ModalError(const char* message) override;
bool ModalConfirmation(const char* message) override;
void ModalInformation(const char* message) override;
private:
jobject m_java_object;
jmethodID m_set_title_method;
jmethodID m_set_status_text_method;
jmethodID m_set_progress_range_method;
jmethodID m_set_progress_value_method;
jmethodID m_modal_error_method;
jmethodID m_modal_confirmation_method;
jmethodID m_modal_information_method;
};