Skip to content

Commit

Permalink
fix AccountService
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Oct 22, 2024
1 parent 8ff4858 commit be3f4c1
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ public boolean linkingOpenMail(String email, String subject, String body) {
return true;
}

public void linkingOpenDeleteAccount() {
public boolean linkingOpenDeleteAccount() {
MengineLog.logMessage(TAG, "request delete account");

MengineUtils.showAreYouSureAlertDialog(this
Expand All @@ -1420,8 +1420,11 @@ public void linkingOpenDeleteAccount() {
, () -> { //Cancel
MengineLog.logMessage(TAG, "delete account [CANCEL]");
}
, 3000
, "Delete Account"
, "Click 'YES' will delete all account data. All game progress, virtual goods, and currency will be permanently removed and unrecoverable."
);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AlignmentSpan;
import android.text.style.StyleSpan;
import android.util.DisplayMetrics;
import android.view.Display;
Expand Down Expand Up @@ -546,104 +548,112 @@ public static boolean openUrl(Context context, String url) {
}

public static void showToast(Context context, String format, Object ... args) {
String message = MengineLog.buildTotalMsg(format, args);
MengineUtils.performOnMainThread(() -> {
String message = MengineLog.buildTotalMsg(format, args);

Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);

toast.show();
toast.show();
});
}

public static void showOkAlertDialog(Context context, Runnable ok, String title, String format, Object ... args) {
String message = MengineLog.buildTotalMsg(format, args);
MengineUtils.performOnMainThread(() -> {
String message = MengineLog.buildTotalMsg(format, args);

MengineLog.logMessage(TAG, "show OK alert dialog title: %s message: %s"
, title
, message
);
MengineLog.logMessage(TAG, "show OK alert dialog title: %s message: %s"
, title
, message
);

AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog.Builder builder = new AlertDialog.Builder(context);

builder.setTitle(title);
builder.setMessage(message);
builder.setCancelable(false);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MengineLog.logMessage(TAG, "show OK alert dialog OK clicked");
builder.setTitle(title);
builder.setMessage(message);
builder.setCancelable(false);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MengineLog.logMessage(TAG, "show OK alert dialog OK clicked");

ok.run();
dialog.dismiss();
}
});
ok.run();
dialog.dismiss();
}
});

AlertDialog alert = builder.create();
AlertDialog alert = builder.create();

alert.show();
alert.show();
});
}

public static void showAreYouSureAlertDialog(Context context, Runnable yes, Runnable cancel, String title, String format, Object ... args) {
String messageText = MengineLog.buildTotalMsg(format, args);
public static void showAreYouSureAlertDialog(Context context, Runnable yes, Runnable cancel, long delayMillis, String title, String format, Object ... args) {
MengineUtils.performOnMainThread(() -> {
String messageText = MengineLog.buildTotalMsg(format, args);

MengineLog.logMessage(TAG, "show YES|CANCEL alert dialog title: %s message: %s"
, title
, messageText
);
MengineLog.logMessage(TAG, "show YES|CANCEL alert dialog title: %s message: %s"
, title
, messageText
);

String AreYouSureText = "\n\nAre you sure?";
String AreYouSureText = "\n\nAre you sure?";

SpannableString spannableMessage = new SpannableString(messageText + AreYouSureText);
SpannableString spannableMessage = new SpannableString(messageText + AreYouSureText);

spannableMessage.setSpan(new StyleSpan(Typeface.BOLD), messageText.length(), (messageText + AreYouSureText).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableMessage.setSpan(new StyleSpan(Typeface.BOLD), messageText.length(), (messageText + AreYouSureText).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableMessage.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), messageText.length(), spannableMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog.Builder builder = new AlertDialog.Builder(context);

builder.setTitle(title);
builder.setMessage(spannableMessage);
builder.setCancelable(false);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MengineLog.logMessage(TAG, "show YES|CANCEL alert dialog YES clicked");
builder.setTitle(title);
builder.setMessage(spannableMessage);
builder.setCancelable(false);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MengineLog.logMessage(TAG, "show YES|CANCEL alert dialog YES clicked");

yes.run();
dialog.dismiss();
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
MengineLog.logMessage(TAG, "show YES|CANCEL alert dialog CANCEL clicked");
yes.run();
dialog.dismiss();
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
MengineLog.logMessage(TAG, "show YES|CANCEL alert dialog CANCEL clicked");

cancel.run();
dialog.dismiss();
}
});

AlertDialog alert = builder.create();
cancel.run();
dialog.dismiss();
}
});

alert.show();
AlertDialog alert = builder.create();

int darker_gray = ContextCompat.getColor(context, android.R.color.darker_gray);
alert.show();

alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(darker_gray);
alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);

MengineUtils.performOnMainThreadDelayed(() -> {
int darker_gray = ContextCompat.getColor(context, android.R.color.darker_gray);
int holo_red_light = ContextCompat.getColor(context, android.R.color.holo_red_light);

alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(holo_red_light);
alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}, 3000);
if (delayMillis > 0) {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(darker_gray);
alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);

MengineUtils.performOnMainThreadDelayed(() -> {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(holo_red_light);
alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}, delayMillis);
} else {
alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(holo_red_light);
}
});
}

public static void finishActivityWithAlertDialog(Activity activity, String format, Object... args) {
MengineLog.logErrorException(TAG, format, args);

MengineUtils.performOnMainThreadDelayed(() -> {
MengineUtils.showOkAlertDialog(activity, () -> {
activity.finishAndRemoveTask();
}, "Mengine", format, args);
}, 0);
MengineUtils.showOkAlertDialog(activity, () -> {
activity.finishAndRemoveTask();
}, "Mengine", format, args);
}

public static void sleep(long millis) {
Expand Down
37 changes: 22 additions & 15 deletions src/Services/AccountService/AccountService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ namespace Mengine
//////////////////////////////////////////////////////////////////////////
bool AccountService::deleteAccount( const ConstString & _accountId )
{
if( m_currentAccountId.empty() == false )
{
if( m_currentAccountId == _accountId )
{
this->unselectCurrentAccount_();
}
}

if( m_accountProvider != nullptr )
{
m_accountProvider->onDeleteAccount( _accountId );
}

AccountPtr account = m_accounts.erase( _accountId );

if( account == nullptr )
Expand All @@ -292,28 +305,17 @@ namespace Mengine
return false;
}

if( m_currentAccountId.empty() == false )
{
if( m_currentAccountId == _accountId )
{
this->unselectCurrentAccount_();
}
}

LOGGER_INFO( "account", "delete account '%s' UID '%.20s'"
, account->getId().c_str()
, account->getUID().data
);

account->finalize();

if( m_accountProvider != nullptr )
{
m_accountProvider->onDeleteAccount( _accountId );
}

m_invalidateAccounts = true;

this->saveAccounts();

return true;
}
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -371,7 +373,9 @@ namespace Mengine
return false;
}

if( this->deleteAccount( m_currentAccountId ) == false )
ConstString deleteAccountId = m_currentAccountId;

if( this->deleteAccount( deleteAccountId ) == false )
{
return false;
}
Expand Down Expand Up @@ -598,7 +602,10 @@ namespace Mengine
continue;
}

validAccount = account;
if( accountId != m_globalAccountId )
{
validAccount = account;
}
}

if( this->hasAccount( selectAccountId ) == false )
Expand Down

0 comments on commit be3f4c1

Please sign in to comment.