aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java27
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java64
-rw-r--r--src/main/res/menu/editaccount.xml35
-rw-r--r--src/main/res/values/arrays.xml6
-rw-r--r--src/main/res/values/strings.xml3
5 files changed, 119 insertions, 16 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 4fa5ddff..3c9fd50a 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -3024,6 +3024,33 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
+ public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
+ IqPacket request = new IqPacket(IqPacket.TYPE.GET);
+ request.addChild("prefs","urn:xmpp:mam:0");
+ sendIqPacket(account, request, new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Element prefs = packet.findChild("prefs","urn:xmpp:mam:0");
+ if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
+ callback.onPreferencesFetched(prefs);
+ } else {
+ callback.onPreferencesFetchFailed();
+ }
+ }
+ });
+ }
+
+ public interface OnMamPreferencesFetched {
+ void onPreferencesFetched(Element prefs);
+ void onPreferencesFetchFailed();
+ }
+
+ public void pushMamPreferences(Account account, Element prefs) {
+ IqPacket set = new IqPacket(IqPacket.TYPE.SET);
+ set.addChild(prefs);
+ sendIqPacket(account, set, null);
+ }
+
public interface OnAccountCreated {
void onAccountCreated(Account account);
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index 5c783f54..d30fbda2 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -32,7 +32,10 @@ import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
@@ -44,6 +47,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.UIHelper;
+import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
import eu.siacs.conversations.xmpp.XmppConnection.Features;
import eu.siacs.conversations.xmpp.forms.Data;
@@ -52,7 +56,7 @@ import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.pep.Avatar;
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate,
- OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast {
+ OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
private AutoCompleteTextView mAccountJid;
private EditText mPassword;
@@ -218,6 +222,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
finish();
}
};
+ private Toast mFetchingMamPrefsToast;
public void refreshUiReal() {
invalidateOptionsMenu();
@@ -465,6 +470,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
final MenuItem clearDevices = menu.findItem(R.id.action_clear_devices);
final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
+ final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs);
renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null);
@@ -475,6 +481,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
if (!mAccount.getXmppConnection().getFeatures().register()) {
changePassword.setVisible(false);
}
+ mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam());
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
if (otherDevices == null || otherDevices.isEmpty()) {
clearDevices.setVisible(false);
@@ -485,6 +492,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
showMoreInfo.setVisible(false);
changePassword.setVisible(false);
clearDevices.setVisible(false);
+ mamPrefs.setVisible(false);
}
return true;
}
@@ -568,6 +576,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
changePasswordIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
startActivity(changePasswordIntent);
break;
+ case R.id.action_mam_prefs:
+ editMamPrefs();
+ break;
case R.id.action_clear_devices:
showWipePepDialog();
break;
@@ -799,6 +810,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
builder.create().show();
}
+ private void editMamPrefs() {
+ this.mFetchingMamPrefsToast = Toast.makeText(this, R.string.fetching_mam_prefs, Toast.LENGTH_LONG);
+ this.mFetchingMamPrefsToast.show();
+ xmppConnectionService.fetchMamPreferences(mAccount, this);
+ }
+
@Override
public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
refreshUi();
@@ -878,4 +895,49 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}
});
}
+
+ @Override
+ public void onPreferencesFetched(final Element prefs) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mFetchingMamPrefsToast != null) {
+ mFetchingMamPrefsToast.cancel();
+ }
+ AlertDialog.Builder builder = new Builder(EditAccountActivity.this);
+ builder.setTitle(R.string.mam_prefs);
+ String defaultAttr = prefs.getAttribute("default");
+ final List<String> defaults = Arrays.asList("never", "roster", "always");
+ final AtomicInteger choice = new AtomicInteger(Math.max(0,defaults.indexOf(defaultAttr)));
+ builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ choice.set(which);
+ }
+ });
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ prefs.setAttribute("default",defaults.get(choice.get()));
+ xmppConnectionService.pushMamPreferences(mAccount, prefs);
+ }
+ });
+ builder.create().show();
+ }
+ });
+ }
+
+ @Override
+ public void onPreferencesFetchFailed() {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mFetchingMamPrefsToast != null) {
+ mFetchingMamPrefsToast.cancel();
+ }
+ Toast.makeText(EditAccountActivity.this,R.string.unable_to_fetch_mam_prefs,Toast.LENGTH_LONG).show();
+ }
+ });
+ }
}
diff --git a/src/main/res/menu/editaccount.xml b/src/main/res/menu/editaccount.xml
index b7a40418..9f06fc4c 100644
--- a/src/main/res/menu/editaccount.xml
+++ b/src/main/res/menu/editaccount.xml
@@ -2,35 +2,40 @@
<item
android:id="@+id/action_show_qr_code"
- android:title="@string/show_qr_code"
- android:showAsAction="never" />
+ android:showAsAction="never"
+ android:title="@string/show_qr_code"/>
<item
android:id="@+id/action_show_block_list"
- android:title="@string/show_block_list"
- android:showAsAction="never" />
+ android:showAsAction="never"
+ android:title="@string/show_block_list"/>
<item
android:id="@+id/action_renew_certificate"
+ android:showAsAction="never"
android:title="@string/action_renew_certificate"
- android:visible="false"
- android:showAsAction="never" />
- />
+ android:visible="false"/>
<item
android:id="@+id/action_server_info_show_more"
- android:title="@string/server_info_show_more"
android:checkable="true"
android:checked="false"
- android:showAsAction="never" />
+ android:showAsAction="never"
+ android:title="@string/server_info_show_more"/>
+
+ <item
+ android:id="@+id/action_mam_prefs"
+ android:title="@string/mam_prefs"/>
- <item android:id="@+id/action_change_password_on_server"
- android:title="@string/change_password"
- android:showAsAction="never" />
+ <item
+ android:id="@+id/action_change_password_on_server"
+ android:showAsAction="never"
+ android:title="@string/change_password"/>
- <item android:id="@+id/action_clear_devices"
- android:title="@string/clear_other_devices"
- android:showAsAction="never"/>
+ <item
+ android:id="@+id/action_clear_devices"
+ android:showAsAction="never"
+ android:title="@string/clear_other_devices"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml
index ca63a0f1..2058162c 100644
--- a/src/main/res/values/arrays.xml
+++ b/src/main/res/values/arrays.xml
@@ -69,4 +69,10 @@
<item>@string/automatically</item>
<item>@string/always</item>
</string-array>
+
+ <string-array name="mam_prefs">
+ <item>@string/never</item>
+ <item>@string/contacts</item>
+ <item>@string/always</item>
+ </string-array>
</resources>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index f909d8ec..8da14a4a 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -538,6 +538,9 @@
<string name="action_add_account_with_certificate">Add account with certificate</string>
<string name="unable_to_parse_certificate">Unable to parse certificate</string>
<string name="authenticate_with_certificate">Leave empty to authenticate w/ certificate</string>
+ <string name="mam_prefs">Archiving preferences</string>
+ <string name="fetching_mam_prefs">Fetching archiving preferences. Please wait…</string>
+ <string name="unable_to_fetch_mam_prefs">Unable to fetch archiving preferences</string>
<string name="captcha_ocr">Captcha text</string>
<string name="captcha_required">Captcha required</string>
<string name="captcha_hint">enter the text from the image</string>