aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/util
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-02-07 21:24:12 +0100
committerChristian Schneppe <christian@pix-art.de>2019-02-07 21:24:12 +0100
commitb31a9daf992012be7fa839cc3d25a042c55f9c7a (patch)
treee5b9ece969c8137f9849b87af6710a7bf3208c31 /src/main/java/de/pixart/messenger/ui/util
parent1b3406cdbb6c620cca975b0bc32b43b60fa246cb (diff)
show different room settings for channels and groups
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/util')
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java b/src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java
new file mode 100644
index 000000000..4630a5a93
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java
@@ -0,0 +1,111 @@
+package de.pixart.messenger.ui.util;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.StringRes;
+
+import de.pixart.messenger.R;
+import de.pixart.messenger.entities.MucOptions;
+
+public class MucConfiguration {
+
+ public final @StringRes
+ int title;
+ public final String[] names;
+ public final boolean[] values;
+ public final Option[] options;
+
+ private MucConfiguration(@StringRes int title, String[] names, boolean[] values, Option[] options) {
+ this.title = title;
+ this.names = names;
+ this.values = values;
+ this.options = options;
+ }
+
+ public static MucConfiguration get(Context context, MucOptions mucOptions) {
+ if (mucOptions.isPrivateAndNonAnonymous()) {
+ String[] names = new String[]{
+ context.getString(R.string.allow_participants_to_edit_subject),
+ context.getString(R.string.allow_participants_to_invite_others)
+ };
+ boolean[] values = new boolean[]{
+ mucOptions.participantsCanChangeSubject(),
+ mucOptions.allowInvites()
+ };
+ final Option[] options = new Option[]{
+ new Option("muc#roomconfig_changesubject"),
+ new Option("muc#roomconfig_allowinvites")
+ };
+ return new MucConfiguration(R.string.conference_options, names, values, options);
+ } else {
+ String[] names = new String[]{
+ context.getString(R.string.non_anonymous),
+ context.getString(R.string.allow_participants_to_edit_subject),
+ };
+ boolean[] values = new boolean[]{
+ mucOptions.nonanonymous(),
+ mucOptions.participantsCanChangeSubject()
+ };
+ final Option[] options = new Option[]{
+ new Option("muc#roomconfig_whois", "anyone", "moderators"),
+ new Option("muc#roomconfig_changesubject")
+ };
+ return new MucConfiguration(R.string.channel_options, names, values, options);
+ }
+ }
+
+ public static String describe(final Context context, final MucOptions mucOptions) {
+ final StringBuilder builder = new StringBuilder();
+ if (mucOptions.isPrivateAndNonAnonymous()) {
+ if (mucOptions.participantsCanChangeSubject()) {
+ builder.append(context.getString(R.string.anyone_can_edit_subject));
+ } else {
+ builder.append(context.getString(R.string.owners_can_edit_subject));
+ }
+ builder.append(' ');
+ if (mucOptions.allowInvites()) {
+ builder.append(context.getString(R.string.anyone_can_invite_others));
+ } else {
+ builder.append(context.getString(R.string.owners_can_invite_others));
+ }
+ } else {
+ if (mucOptions.nonanonymous()) {
+ builder.append(context.getString(R.string.jabber_ids_are_visible_to_anyone));
+ } else {
+ builder.append(context.getString(R.string.jabber_ids_are_visible_to_admins));
+ }
+ builder.append(' ');
+ if (mucOptions.participantsCanChangeSubject()) {
+ builder.append(context.getString(R.string.anyone_can_edit_subject));
+ } else {
+ builder.append(context.getString(R.string.admins_can_edit_subject));
+ }
+ }
+ return builder.toString();
+ }
+
+ public Bundle toBundle(boolean[] values) {
+ Bundle bundle = new Bundle();
+ for (int i = 0; i < values.length; ++i) {
+ final Option option = options[i];
+ bundle.putString(option.name, option.values[values[i] ? 0 : 1]);
+ }
+ return bundle;
+ }
+
+ private static class Option {
+ public final String name;
+ public final String[] values;
+
+ private Option(String name) {
+ this.name = name;
+ this.values = new String[]{"1", "0"};
+ }
+
+ private Option(String name, String on, String off) {
+ this.name = name;
+ this.values = new String[]{on, off};
+ }
+ }
+
+} \ No newline at end of file