1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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};
}
}
}
|