mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-25 18:32:15 -05:00
Make the conversation history size a configurable preference
This commit is contained in:
parent
61960c9add
commit
91d211c51d
@ -44,4 +44,7 @@
|
||||
|
||||
<string name="key_graphical_smilies">graphical_smilies</string>
|
||||
<string name="default_graphical_smilies">false</string>
|
||||
|
||||
<string name="key_history_size">history_size</string>
|
||||
<string name="default_history_size">30</string>
|
||||
</resources>
|
||||
|
@ -203,4 +203,6 @@
|
||||
<string name="settings_mirc_colors_desc">Show mIRC colors in messages</string>
|
||||
<string name="settings_graphical_smilies_title">Show graphical smilies</string>
|
||||
<string name="settings_graphical_smilies_desc">Text smilies will be displayed as images in chat</string>
|
||||
<string name="settings_history_size_title">History size</string>
|
||||
<string name="settings_history_size_desc">Number of lines of conversation history to keep</string>
|
||||
</resources>
|
||||
|
@ -85,6 +85,12 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:summary="@string/settings_graphical_smilies_desc"
|
||||
android:key="@string/key_graphical_smilies"
|
||||
android:defaultValue="@string/default_graphical_smilies" />
|
||||
<EditTextPreference
|
||||
android:title="@string/settings_history_size_title"
|
||||
android:summary="@string/settings_history_size_desc"
|
||||
android:key="@string/key_history_size"
|
||||
android:defaultValue="@string/default_history_size"
|
||||
android:inputType="number" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_highlight">
|
||||
|
@ -123,6 +123,8 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
||||
// We'll set it to 0 if it's not supported
|
||||
private int setInputTypeFlag;
|
||||
|
||||
private int historySize;
|
||||
|
||||
/**
|
||||
* On create
|
||||
*/
|
||||
@ -159,9 +161,13 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
||||
deck.setOnItemClickListener(new ConversationClickListener(deckAdapter, switcher));
|
||||
deck.setBackgroundDrawable(new NonScalingBackgroundDrawable(this, deck, R.drawable.background));
|
||||
|
||||
Settings settings = new Settings(this);
|
||||
historySize = settings.getHistorySize();
|
||||
|
||||
if (server.getStatus() == Status.PRE_CONNECTING) {
|
||||
server.clearConversations();
|
||||
deckAdapter.clearConversations();
|
||||
server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize);
|
||||
}
|
||||
|
||||
// Optimization : cache field lookups
|
||||
@ -538,7 +544,9 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
||||
|
||||
if (server.getStatus() == Status.CONNECTING) {
|
||||
deckAdapter.clearConversations();
|
||||
deckAdapter.addItem(server.getConversation(ServerInfo.DEFAULT_NAME));
|
||||
Conversation serverInfo = server.getConversation(ServerInfo.DEFAULT_NAME);
|
||||
serverInfo.setHistorySize(historySize);
|
||||
deckAdapter.addItem(serverInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -559,7 +567,9 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
||||
);
|
||||
server.clearConversations();
|
||||
deckAdapter.clearConversations();
|
||||
deckAdapter.addItem(server.getConversation(ServerInfo.DEFAULT_NAME));
|
||||
Conversation serverInfo = server.getConversation(ServerInfo.DEFAULT_NAME);
|
||||
serverInfo.setHistorySize(historySize);
|
||||
deckAdapter.addItem(serverInfo);
|
||||
binder.connect(server);
|
||||
}
|
||||
})
|
||||
@ -864,6 +874,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
||||
if (query == null) {
|
||||
// Open a query if there's none yet
|
||||
query = new Query(nicknameWithoutPrefix);
|
||||
query.setHistorySize(binder.getService().getSettings().getHistorySize());
|
||||
server.addConversation(query);
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
|
@ -40,6 +40,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
{
|
||||
private final LinkedList<TextView> messages;
|
||||
private final Context context;
|
||||
private int historySize;
|
||||
|
||||
/**
|
||||
* Create a new MessageAdapter
|
||||
@ -72,6 +73,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
|
||||
this.messages = messages;
|
||||
this.context = context;
|
||||
historySize = conversation.getHistorySize();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +85,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
{
|
||||
messages.add(message.renderTextView(context));
|
||||
|
||||
if (messages.size() > Conversation.HISTORY_SIZE) {
|
||||
if (messages.size() > historySize) {
|
||||
messages.remove(0);
|
||||
}
|
||||
|
||||
@ -104,7 +106,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
for (int i = mSize - 1; i > -1; i--) {
|
||||
mMessages.add(messages.get(i).renderTextView(mContext));
|
||||
|
||||
if (mMessages.size() > Conversation.HISTORY_SIZE) {
|
||||
if (mMessages.size() > historySize) {
|
||||
mMessages.remove(0);
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ public class QueryHandler extends BaseHandler
|
||||
}
|
||||
|
||||
query = new Query(params[1]);
|
||||
query.setHistorySize(service.getSettings().getHistorySize());
|
||||
server.addConversation(query);
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
|
@ -218,6 +218,7 @@ public class IRCConnection extends PircBot
|
||||
if (conversation == null) {
|
||||
// Open a query if there's none yet
|
||||
conversation = new Query(queryNick);
|
||||
conversation.setHistorySize(service.getSettings().getHistorySize());
|
||||
server.addConversation(conversation);
|
||||
conversation.addMessage(message);
|
||||
|
||||
@ -349,7 +350,9 @@ public class IRCConnection extends PircBot
|
||||
{
|
||||
if (sender.equalsIgnoreCase(getNick())) {
|
||||
// We joined a new channel
|
||||
server.addConversation(new Channel(target));
|
||||
Conversation conversation = new Channel(target);
|
||||
conversation.setHistorySize(service.getSettings().getHistorySize());
|
||||
server.addConversation(conversation);
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_NEW,
|
||||
@ -601,6 +604,7 @@ public class IRCConnection extends PircBot
|
||||
if (conversation == null) {
|
||||
// Open a query if there's none yet
|
||||
conversation = new Query(queryNick);
|
||||
conversation.setHistorySize(service.getSettings().getHistorySize());
|
||||
conversation.addMessage(message);
|
||||
server.addConversation(conversation);
|
||||
|
||||
|
@ -41,13 +41,14 @@ public abstract class Conversation
|
||||
public static final int STATUS_HIGHLIGHT = 4;
|
||||
public static final int STATUS_MISC = 5; // join/part/quit
|
||||
|
||||
public static final int HISTORY_SIZE = 30;
|
||||
private static final int DEFAULT_HISTORY_SIZE = 30;
|
||||
|
||||
private final LinkedList<Message> buffer;
|
||||
private final LinkedList<Message> history;
|
||||
private final String name;
|
||||
private int status = 1;
|
||||
private int newMentions = 0;
|
||||
private int historySize = DEFAULT_HISTORY_SIZE;
|
||||
|
||||
/**
|
||||
* Get the type of conversation (channel, query, ..)
|
||||
@ -84,7 +85,7 @@ public abstract class Conversation
|
||||
buffer.add(0, message);
|
||||
history.add(message);
|
||||
|
||||
if (history.size() > HISTORY_SIZE) {
|
||||
if (history.size() > historySize) {
|
||||
history.remove(0);
|
||||
}
|
||||
}
|
||||
@ -204,4 +205,31 @@ public abstract class Conversation
|
||||
{
|
||||
return newMentions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this conversation's history size.
|
||||
*
|
||||
* @return The conversation's history size.
|
||||
*/
|
||||
public int getHistorySize()
|
||||
{
|
||||
return historySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this conversation's history size.
|
||||
*
|
||||
* @param size The new history size for this conversation.
|
||||
*/
|
||||
public void setHistorySize(int size)
|
||||
{
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
historySize = size;
|
||||
if (history.size() > size) {
|
||||
history.subList(size, history.size()).clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,4 +247,21 @@ public class Settings
|
||||
Boolean.parseBoolean(resources.getString(R.string.default_graphical_smilies))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the conversation history size.
|
||||
*
|
||||
* @return The conversation history size
|
||||
*/
|
||||
public int getHistorySize()
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(preferences.getString(
|
||||
resources.getString(R.string.key_history_size),
|
||||
resources.getString(R.string.default_history_size)
|
||||
));
|
||||
} catch (NumberFormatException e) {
|
||||
return Integer.parseInt(resources.getString(R.string.default_history_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user