mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-13 11:39:09 +00:00
RetroAchievements - Android login callback
Modify the RetroAchievements login code in Android to pass in a callback, pop a message if login fails, close the login box if it succeeds.
This commit is contained in:
parent
20061676b6
commit
e700745a19
3 changed files with 35 additions and 6 deletions
|
@ -2,12 +2,21 @@
|
|||
|
||||
package org.dolphinemu.dolphinemu.features.settings.model
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
object AchievementModel {
|
||||
@JvmStatic
|
||||
external fun init()
|
||||
|
||||
suspend fun asyncLogin(password: String): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
login(password)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
external fun login(password: String)
|
||||
private external fun login(password: String): Boolean
|
||||
|
||||
@JvmStatic
|
||||
external fun logout()
|
||||
|
|
|
@ -7,8 +7,11 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.dolphinemu.dolphinemu.databinding.DialogLoginBinding
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AchievementModel.login
|
||||
import org.dolphinemu.dolphinemu.dialogs.AlertMessage
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AchievementModel.asyncLogin
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting
|
||||
|
||||
|
@ -45,7 +48,12 @@ class LoginDialog : DialogFragment() {
|
|||
private fun onLoginClicked() {
|
||||
StringSetting.ACHIEVEMENTS_USERNAME.setString(NativeConfig.LAYER_BASE_OR_CURRENT,
|
||||
binding.usernameInput.text.toString())
|
||||
login(binding.passwordInput.text.toString())
|
||||
dismiss()
|
||||
lifecycleScope.launch {
|
||||
if (asyncLogin(binding.passwordInput.text.toString()))
|
||||
dismiss()
|
||||
else
|
||||
AlertMessage.newInstance("Login Failed", "Login Failed", false, false)
|
||||
.show(childFragmentManager, "AlertMessage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
|
||||
#include <jni.h>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Core/AchievementManager.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -14,11 +16,21 @@ Java_org_dolphinemu_dolphinemu_features_settings_model_AchievementModel_init(JNI
|
|||
AchievementManager::GetInstance().Init(nullptr);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_settings_model_AchievementModel_login(JNIEnv* env, jclass,
|
||||
jstring password)
|
||||
{
|
||||
AchievementManager::GetInstance().Login(GetJString(env, password));
|
||||
auto& instance = AchievementManager::GetInstance();
|
||||
bool success;
|
||||
auto login_complete_event = std::make_shared<Common::Event>();
|
||||
instance.SetUpdateCallback(
|
||||
[&login_complete_event, &success](AchievementManager::UpdatedItems updated_items) {
|
||||
success = (updated_items.failed_login_code == 0);
|
||||
login_complete_event->Set();
|
||||
});
|
||||
instance.Login(GetJString(env, password));
|
||||
login_complete_event->Wait();
|
||||
return success;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue