Skip to content

Commit

Permalink
status dialog: remember old status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed Apr 28, 2014
1 parent 6fd8f03 commit 011f6c6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion res/layout/statusview.xml
Expand Up @@ -21,7 +21,7 @@
android:prompt="@string/setStatusTitle"
android:layout_marginBottom="15dp"
/>
<EditText android:id="@+id/statusview_message"
<AutoCompleteTextView android:id="@+id/statusview_message"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="@string/setStatusmsgHint"
Expand Down
14 changes: 9 additions & 5 deletions src/org/yaxim/androidclient/MainWindow.java
Expand Up @@ -577,16 +577,19 @@ public StatusMode getStatusMode() {
return StatusMode.fromString(mConfig.statusMode);
}

public String getStatusMessage() {
return mConfig.statusMessage;
}

public void setAndSaveStatus(StatusMode statusMode, String message) {
SharedPreferences.Editor prefedit = PreferenceManager
.getDefaultSharedPreferences(this).edit();
// do not save "offline" to prefs, or else!
if (statusMode != StatusMode.offline)
prefedit.putString(PreferenceConstants.STATUS_MODE, statusMode.name());
if (!message.equals(mConfig.statusMessage)) {
List<String> smh = new ArrayList<String>(java.util.Arrays.asList(mConfig.statusMessageHistory));
if (!smh.contains(message))
smh.add(message);
String smh_joined = android.text.TextUtils.join("\036", smh);
prefedit.putString(PreferenceConstants.STATUS_MESSAGE_HISTORY, smh_joined);
}
prefedit.putString(PreferenceConstants.STATUS_MESSAGE, message);
prefedit.commit();

Expand Down Expand Up @@ -673,7 +676,8 @@ private boolean applyMainMenuChoice(com.actionbarsherlock.view.MenuItem item) {

case android.R.id.home:
case R.id.menu_status:
new ChangeStatusDialog(this).show();
new ChangeStatusDialog(this, StatusMode.fromString(mConfig.statusMode),
mConfig.statusMessage, mConfig.statusMessageHistory).show();
return true;

case R.id.menu_exit:
Expand Down
8 changes: 5 additions & 3 deletions src/org/yaxim/androidclient/data/YaximConfiguration.java
Expand Up @@ -53,6 +53,7 @@ public class YaximConfiguration implements OnSharedPreferenceChangeListener {

public String statusMode;
public String statusMessage;
public String[] statusMessageHistory;

public boolean isLEDNotify;
public String vibraNotify;
Expand Down Expand Up @@ -152,9 +153,10 @@ private void loadPrefs(SharedPreferences prefs) {
false);
this.statusMode = prefs.getString(PreferenceConstants.STATUS_MODE, "available");
this.statusMessage = prefs.getString(PreferenceConstants.STATUS_MESSAGE, "");
this.theme = prefs.getString(PreferenceConstants.THEME, "dark");
this.chatFontSize = prefs.getString("setSizeChat", "18");
this.showOffline = prefs.getBoolean(PreferenceConstants.SHOW_OFFLINE, false);
this.statusMessageHistory = prefs.getString(PreferenceConstants.STATUS_MESSAGE_HISTORY, statusMessage).split("\036");
this.theme = prefs.getString(PreferenceConstants.THEME, "dark");
this.chatFontSize = prefs.getString("setSizeChat", "18");
this.showOffline = prefs.getBoolean(PreferenceConstants.SHOW_OFFLINE, false);
this.enableGroups = prefs.getBoolean(PreferenceConstants.ENABLE_GROUPS, true);

try {
Expand Down
15 changes: 10 additions & 5 deletions src/org/yaxim/androidclient/dialogs/ChangeStatusDialog.java
Expand Up @@ -20,16 +20,18 @@
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AutoCompleteTextView;

public class ChangeStatusDialog extends AlertDialog {

private final Spinner mStatus;

private final EditText mMessage;
private final AutoCompleteTextView mMessage;

private final MainWindow mContext;

public ChangeStatusDialog(final MainWindow context) {
public ChangeStatusDialog(final MainWindow context, final StatusMode status_mode,
final String status_message, final String[] status_message_history) {
super(context);

mContext = context;
Expand Down Expand Up @@ -57,13 +59,16 @@ public int compare(StatusMode object1, StatusMode object2) {
mStatus.setAdapter(mStatusAdapter);

for (int i = 0; i < modes.size(); i++) {
if (modes.get(i).equals(context.getStatusMode())) {
if (modes.get(i).equals(status_mode)) {
mStatus.setSelection(i);
}
}

mMessage = (EditText) group.findViewById(R.id.statusview_message);
mMessage.setText(context.getStatusMessage());
mMessage = (AutoCompleteTextView) group.findViewById(R.id.statusview_message);
mMessage.setText(status_message);
mMessage.setAdapter(new ArrayAdapter<String>(context,
android.R.layout.simple_dropdown_item_1line, status_message_history));
mMessage.setThreshold(1);

setTitle(R.string.statuspopup_name);
setView(group);
Expand Down
1 change: 1 addition & 0 deletions src/org/yaxim/androidclient/util/PreferenceConstants.java
Expand Up @@ -23,5 +23,6 @@ public class PreferenceConstants {
public final static String REQUIRE_SSL = "require_ssl";
public final static String STATUS_MODE = "status_mode";
public final static String STATUS_MESSAGE = "status_message";
public static final String STATUS_MESSAGE_HISTORY = "status_message_history";
public final static String THEME = "theme";
}

0 comments on commit 011f6c6

Please sign in to comment.