From f4b39287a59f8b347dde11868e65294991a27b94 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 20 Aug 2015 07:03:21 -0700 Subject: [PATCH] confirm before deleting chat history --- .../android/XWords4/res/values/strings.xml | 4 +++ .../org/eehouse/android/xw4/ChatDelegate.java | 34 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index de57f248b..f2ffaf7d5 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2579,4 +2579,8 @@ The \"%1$s\" option copies an invitation URL to the clipboard. Paste it into the app of your choice and send it to your friend. + + Are you sure you want to delete + all chat history for this game?\n\n(This action cannot be + undone.) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java index 82d6572eb..bb2cbcd67 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatDelegate.java @@ -21,16 +21,18 @@ package org.eehouse.android.xw4; import android.app.Activity; +import android.app.AlertDialog; import android.content.Intent; import android.os.Bundle; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; -import android.view.View; import android.view.Menu; import android.view.MenuItem; -import android.view.MenuInflater; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.TextView; + +import org.eehouse.android.xw4.DlgDelegate.Action; public class ChatDelegate extends DelegateBase implements View.OnClickListener { @@ -82,10 +84,7 @@ public class ChatDelegate extends DelegateBase { boolean handled = R.id.chat_menu_clear == item.getItemId(); if ( handled ) { - DBUtils.clearChatHistory( m_activity, m_rowid ); - LinearLayout layout = - (LinearLayout)findViewById( R.id.chat_history ); - layout.removeAllViews(); + showConfirmThen( R.string.confirm_clear_chat, Action.CLEAR_ACTION ); } return handled; } @@ -105,4 +104,21 @@ public class ChatDelegate extends DelegateBase } finish(); } + + @Override + public void dlgButtonClicked( Action action, int which, Object[] params ) + { + switch ( action ) { + case CLEAR_ACTION: + if ( AlertDialog.BUTTON_POSITIVE == which ) { + DBUtils.clearChatHistory( m_activity, m_rowid ); + LinearLayout layout = + (LinearLayout)findViewById( R.id.chat_history ); + layout.removeAllViews(); + } + break; + default: + super.dlgButtonClicked( action, which, params ); + } + } }