forked from mirror/monocles_chat_clean
update fork #128
2 changed files with 37 additions and 0 deletions
Persist selected account in CreatePostActivity
commit
1c6d075462
|
|
@ -6,11 +6,13 @@ import android.content.Intent;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
@ -217,6 +219,22 @@ public class CreatePostActivity extends XmppActivity {
|
|||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, accountJids);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
binding.accountSpinner.setAdapter(adapter);
|
||||
|
||||
int persistedPosition = getPersistedItem();
|
||||
if (!onlineAccounts.isEmpty() && persistedPosition < onlineAccounts.size()) {
|
||||
binding.accountSpinner.setSelection(persistedPosition);
|
||||
}
|
||||
|
||||
binding.accountSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parentView, View view, int position, long itemId) {
|
||||
setPersistedItem(position);
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0) {
|
||||
// Do nothing
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -245,6 +263,11 @@ public class CreatePostActivity extends XmppActivity {
|
|||
selectedAccount = onlineAccounts.get(binding.accountSpinner.getSelectedItemPosition());
|
||||
}
|
||||
|
||||
if (!selectedAccount.isOnlineAndConnected()) {
|
||||
Toast.makeText(this, R.string.account_not_connected, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (inReplyToNode != null) {
|
||||
xmppConnectionService.publishComment(selectedAccount, inReplyToNode, content, new XmppConnectionService.OnPostPublished() {
|
||||
@Override
|
||||
|
|
@ -315,6 +338,19 @@ public class CreatePostActivity extends XmppActivity {
|
|||
});
|
||||
}
|
||||
|
||||
private int getPersistedItem() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(this).getInt(makePersistedItemKeyName(), 0);
|
||||
}
|
||||
|
||||
protected void setPersistedItem(int position) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(makePersistedItemKeyName(), position).apply();
|
||||
}
|
||||
|
||||
private String makePersistedItemKeyName() {
|
||||
return "create_post_selected_account_position";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1647,6 +1647,7 @@
|
|||
<string name="unlike_with_account">Unlike post with</string>
|
||||
<string name="account_that_liked_post_is_offline">The account that was used to like this post is currently offline.</string>
|
||||
<string name="add_a_comment">Add a comment</string>
|
||||
<string name="account_not_connected">Selected account is not online</string>
|
||||
<plurals name="publishing_to_x_contacts">
|
||||
<item quantity="one">Publishing to %d contact</item>
|
||||
<item quantity="other">Publishing to %d contacts</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue