mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
wrap a bit more chat code in test so java can leave it out
This commit is contained in:
parent
bd81eb4bbe
commit
1669687f19
2 changed files with 64 additions and 50 deletions
|
@ -40,6 +40,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate( Bundle savedInstanceState )
|
public void onCreate( Bundle savedInstanceState )
|
||||||
{
|
{
|
||||||
|
if ( XWApp.CHAT_SUPPORTED ) {
|
||||||
super.onCreate( savedInstanceState );
|
super.onCreate( savedInstanceState );
|
||||||
|
|
||||||
setContentView( R.layout.chat );
|
setContentView( R.layout.chat );
|
||||||
|
@ -48,12 +49,13 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
|
||||||
|
|
||||||
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_rowid );
|
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_rowid );
|
||||||
if ( null != pairs ) {
|
if ( null != pairs ) {
|
||||||
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
|
LinearLayout layout = (LinearLayout)
|
||||||
|
findViewById( R.id.chat_history );
|
||||||
LayoutInflater factory = LayoutInflater.from( this );
|
LayoutInflater factory = LayoutInflater.from( this );
|
||||||
|
|
||||||
for ( DBUtils.HistoryPair pair : pairs ) {
|
for ( DBUtils.HistoryPair pair : pairs ) {
|
||||||
TextView view =
|
TextView view = (TextView)factory
|
||||||
(TextView)factory.inflate( pair.sourceLocal
|
.inflate( pair.sourceLocal
|
||||||
? R.layout.chat_history_local
|
? R.layout.chat_history_local
|
||||||
: R.layout.chat_history_remote,
|
: R.layout.chat_history_remote,
|
||||||
null );
|
null );
|
||||||
|
@ -62,10 +64,15 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
((Button)findViewById( R.id.send_button )).setOnClickListener( this );
|
((Button)findViewById( R.id.send_button ))
|
||||||
|
.setOnClickListener( this );
|
||||||
|
|
||||||
setTitle( getString( R.string.chat_titlef,
|
setTitle( getString( R.string.chat_titlef,
|
||||||
GameUtils.getName( this, m_rowid ) ) );
|
GameUtils.getName( this, m_rowid ) ) );
|
||||||
|
} else {
|
||||||
|
// Should really assert....
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -847,6 +847,7 @@ public class DBUtils {
|
||||||
public static HistoryPair[] getChatHistory( Context context, long rowid )
|
public static HistoryPair[] getChatHistory( Context context, long rowid )
|
||||||
{
|
{
|
||||||
HistoryPair[] result = null;
|
HistoryPair[] result = null;
|
||||||
|
if ( XWApp.CHAT_SUPPORTED ) {
|
||||||
final String localPrefix = context.getString( R.string.chat_local_id );
|
final String localPrefix = context.getString( R.string.chat_local_id );
|
||||||
String history = getChatHistoryStr( context, rowid );
|
String history = getChatHistoryStr( context, rowid );
|
||||||
if ( null != history ) {
|
if ( null != history ) {
|
||||||
|
@ -858,6 +859,7 @@ public class DBUtils {
|
||||||
result[ii] = new HistoryPair( msg, isLocal );
|
result[ii] = new HistoryPair( msg, isLocal );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1107,6 +1109,7 @@ public class DBUtils {
|
||||||
private static String getChatHistoryStr( Context context, long rowid )
|
private static String getChatHistoryStr( Context context, long rowid )
|
||||||
{
|
{
|
||||||
String result = null;
|
String result = null;
|
||||||
|
if ( XWApp.CHAT_SUPPORTED ) {
|
||||||
initDB( context );
|
initDB( context );
|
||||||
synchronized( s_dbHelper ) {
|
synchronized( s_dbHelper ) {
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
@ -1118,17 +1121,20 @@ public class DBUtils {
|
||||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||||
result =
|
result =
|
||||||
cursor.getString( cursor
|
cursor.getString( cursor
|
||||||
.getColumnIndex(DBHelper.CHAT_HISTORY));
|
.getColumnIndex(DBHelper
|
||||||
|
.CHAT_HISTORY));
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void appendChatHistory( Context context, long rowid,
|
public static void appendChatHistory( Context context, long rowid,
|
||||||
String msg, boolean local )
|
String msg, boolean local )
|
||||||
{
|
{
|
||||||
|
if ( XWApp.CHAT_SUPPORTED ) {
|
||||||
Assert.assertNotNull( msg );
|
Assert.assertNotNull( msg );
|
||||||
int id = local ? R.string.chat_local_id : R.string.chat_other_id;
|
int id = local ? R.string.chat_local_id : R.string.chat_other_id;
|
||||||
msg = context.getString( id ) + msg;
|
msg = context.getString( id ) + msg;
|
||||||
|
@ -1139,6 +1145,7 @@ public class DBUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
saveChatHistory( context, rowid, msg );
|
saveChatHistory( context, rowid, msg );
|
||||||
|
}
|
||||||
} // appendChatHistory
|
} // appendChatHistory
|
||||||
|
|
||||||
public static void clearChatHistory( Context context, long rowid )
|
public static void clearChatHistory( Context context, long rowid )
|
||||||
|
|
Loading…
Reference in a new issue