Skip to content

Commit c336af4

Browse files
committed
show and set ngc group voice state
1 parent a09bc06 commit c336af4

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/GroupInfoActivity.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.os.Bundle;
2626
import android.util.Log;
2727
import android.view.View;
28+
import android.widget.AdapterView;
29+
import android.widget.ArrayAdapter;
2830
import android.widget.Button;
2931
import android.widget.EditText;
3032
import android.widget.TextView;
@@ -36,19 +38,27 @@
3638

3739
import androidx.appcompat.app.AlertDialog;
3840
import androidx.appcompat.app.AppCompatActivity;
41+
import androidx.appcompat.widget.AppCompatButton;
42+
import androidx.appcompat.widget.AppCompatSpinner;
3943
import androidx.appcompat.widget.Toolbar;
4044

4145
import static com.zoffcc.applications.trifa.CameraWrapper.YUV420rotate90;
4246
import static com.zoffcc.applications.trifa.HelperGeneric.display_toast;
4347
import static com.zoffcc.applications.trifa.HelperGeneric.update_savedata_file_wrapper;
48+
import static com.zoffcc.applications.trifa.HelperGroup.get_group_peernum_from_peer_pubkey;
4449
import static com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper;
50+
import static com.zoffcc.applications.trifa.HelperGroup.update_group_in_groupmessagelist;
51+
import static com.zoffcc.applications.trifa.HelperGroup.update_group_peer_in_db;
4552
import static com.zoffcc.applications.trifa.MainActivity.SD_CARD_ENC_FILES_EXPORT_DIR;
4653
import static com.zoffcc.applications.trifa.MainActivity.context_s;
4754
import static com.zoffcc.applications.trifa.MainActivity.main_handler_s;
4855
import static com.zoffcc.applications.trifa.MainActivity.tox_group_founder_set_peer_limit;
56+
import static com.zoffcc.applications.trifa.MainActivity.tox_group_founder_set_voice_state;
4957
import static com.zoffcc.applications.trifa.MainActivity.tox_group_get_name;
5058
import static com.zoffcc.applications.trifa.MainActivity.tox_group_get_peer_limit;
59+
import static com.zoffcc.applications.trifa.MainActivity.tox_group_get_voice_state;
5160
import static com.zoffcc.applications.trifa.MainActivity.tox_group_is_connected;
61+
import static com.zoffcc.applications.trifa.MainActivity.tox_group_mod_set_role;
5262
import static com.zoffcc.applications.trifa.MainActivity.tox_group_offline_peer_count;
5363
import static com.zoffcc.applications.trifa.MainActivity.tox_group_peer_count;
5464
import static com.zoffcc.applications.trifa.MainActivity.tox_group_peer_get_name;
@@ -79,6 +89,9 @@ public class GroupInfoActivity extends AppCompatActivity
7989
Button group_reconnect_button = null;
8090
Button group_dumpofflinepeers_button = null;
8191
Button group_del_sysmsgs_button = null;
92+
AppCompatSpinner group_voicestate_select = null;
93+
private AppCompatButton group_voicestate_set_button = null;
94+
private String[] tox_ngc_group_voicestate_items;
8295
String group_id = "-1";
8396

8497
@Override
@@ -103,6 +116,93 @@ protected void onCreate(Bundle savedInstanceState)
103116
group_reconnect_button = (Button) findViewById(R.id.group_reconnect_button);
104117
group_dumpofflinepeers_button = (Button) findViewById(R.id.group_dumpofflinepeers_button);
105118
group_del_sysmsgs_button = (Button) findViewById(R.id.group_del_sysmsgs_button);
119+
group_voicestate_select = findViewById(R.id.group_voicestate_select);
120+
group_voicestate_set_button = findViewById(R.id.group_voicestate_set_button);
121+
122+
this.tox_ngc_group_voicestate_items = new String[]{"---", "FOUNDER", "MODERATOR", "ALL"};
123+
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
124+
tox_ngc_group_voicestate_items);
125+
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
126+
group_voicestate_select.setAdapter(adapter);
127+
128+
int current_voicestate = 0;
129+
try
130+
{
131+
current_voicestate = tox_group_get_voice_state(tox_group_by_groupid__wrapper(group_id));
132+
Log.i(TAG, "current_voicestate:" + current_voicestate);
133+
if (current_voicestate == ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_FOUNDER.value)
134+
{
135+
group_voicestate_select.setSelection(1);
136+
}
137+
else if (current_voicestate == ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_MODERATOR.value)
138+
{
139+
group_voicestate_select.setSelection(2);
140+
}
141+
else if (current_voicestate == ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_ALL.value)
142+
{
143+
group_voicestate_select.setSelection(3);
144+
}
145+
else
146+
{
147+
// nothing valid selected
148+
group_voicestate_select.setSelection(0);
149+
}
150+
}
151+
catch(Exception e)
152+
{
153+
}
154+
155+
group_voicestate_select.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
156+
{
157+
@Override
158+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
159+
{
160+
Log.i(TAG, "selected_new_voicestate:" + parent.getItemAtPosition(position));
161+
}
162+
163+
@Override
164+
public void onNothingSelected(AdapterView<?> parent)
165+
{
166+
167+
}
168+
});
169+
170+
group_voicestate_set_button.setOnClickListener(new View.OnClickListener()
171+
{
172+
@Override
173+
public void onClick(View view)
174+
{
175+
try
176+
{
177+
String role_str = (String) group_voicestate_select.getSelectedItem();
178+
int new_role = ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_ALL.value;
179+
if (role_str.equals("FOUNDER"))
180+
{
181+
new_role = ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_FOUNDER.value;
182+
}
183+
else if (role_str.equals("MODERATOR"))
184+
{
185+
new_role = ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_MODERATOR.value;
186+
}
187+
else if (role_str.equals("ALL"))
188+
{
189+
new_role = ToxVars.Tox_Group_Voice_State.TOX_GROUP_VOICE_STATE_ALL.value;
190+
}
191+
else
192+
{
193+
// nothing valid selected
194+
return;
195+
}
196+
197+
int result = tox_group_founder_set_voice_state(tox_group_by_groupid__wrapper(group_id), new_role);
198+
Log.i(TAG, "setting new voicestate to: " + new_role + " result=" + result);
199+
update_savedata_file_wrapper();
200+
}
201+
catch (Exception ignored)
202+
{
203+
}
204+
}
205+
});
106206

107207
try
108208
{

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/MainActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,10 @@ static void allocate_video_buffer_1(int frame_width_px1, int frame_height_px1, l
34453445

34463446
public static native int tox_group_mod_set_role(long group_number, long peer_id, int a_Tox_Group_Role);
34473447

3448+
public static native int tox_group_founder_set_voice_state(long group_number, int a_Tox_Group_Voice_State);
3449+
3450+
public static native int tox_group_get_voice_state(long group_number);
3451+
34483452
public static native String tox_group_peer_get_public_key(long group_number, long peer_id);
34493453

34503454
public static native String tox_group_savedpeer_get_public_key(long group_number, long slot_num);

android-refimpl-app/app/src/main/java/com/zoffcc/applications/trifa/ToxVars.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,65 @@ else if (value == TOX_GROUP_PRIVACY_STATE_PRIVATE.value)
17621762
}
17631763
}
17641764

1765+
public static enum Tox_Group_Voice_State
1766+
{
1767+
/**
1768+
* All group roles above Observer have permission to speak.
1769+
*/
1770+
TOX_GROUP_VOICE_STATE_ALL(0),
1771+
1772+
/**
1773+
* Moderators and Founders have permission to speak.
1774+
*/
1775+
TOX_GROUP_VOICE_STATE_MODERATOR(1),
1776+
1777+
/**
1778+
* Only the founder may speak.
1779+
*/
1780+
TOX_GROUP_VOICE_STATE_FOUNDER(2);
1781+
1782+
public int value;
1783+
1784+
private Tox_Group_Voice_State(int value)
1785+
{
1786+
this.value = value;
1787+
}
1788+
1789+
public static String value_str(int value)
1790+
{
1791+
if (value == TOX_GROUP_VOICE_STATE_ALL.value)
1792+
{
1793+
return "TOX_GROUP_VOICE_STATE_ALL";
1794+
}
1795+
else if (value == TOX_GROUP_VOICE_STATE_MODERATOR.value)
1796+
{
1797+
return "TOX_GROUP_VOICE_STATE_MODERATOR";
1798+
}
1799+
else if (value == TOX_GROUP_VOICE_STATE_FOUNDER.value)
1800+
{
1801+
return "TOX_GROUP_VOICE_STATE_FOUNDER";
1802+
}
1803+
return "UNKNOWN";
1804+
}
1805+
1806+
public static String value_char(int value)
1807+
{
1808+
if (value == TOX_GROUP_VOICE_STATE_ALL.value)
1809+
{
1810+
return "A";
1811+
}
1812+
else if (value == TOX_GROUP_VOICE_STATE_MODERATOR.value)
1813+
{
1814+
return "M";
1815+
}
1816+
else if (value == TOX_GROUP_VOICE_STATE_FOUNDER.value)
1817+
{
1818+
return "F";
1819+
}
1820+
return "x";
1821+
}
1822+
}
1823+
17651824
public static enum Tox_Group_Role
17661825
{
17671826
/**

android-refimpl-app/app/src/main/res/layout/activity_groupinfo.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,39 @@
108108
android:textSize="16sp"
109109
android:textStyle="bold" />
110110

111+
<TextView
112+
android:layout_width="match_parent"
113+
android:layout_height="20dp" />
114+
115+
<LinearLayout
116+
android:layout_width="match_parent"
117+
android:layout_height="wrap_content"
118+
android:layout_marginLeft="20dp"
119+
android:layout_marginRight="20dp"
120+
android:orientation="horizontal"
121+
android:visibility="visible">
122+
123+
<androidx.appcompat.widget.AppCompatSpinner
124+
android:id="@+id/group_voicestate_select"
125+
android:layout_width="wrap_content"
126+
android:layout_height="match_parent"
127+
android:layout_gravity="left"
128+
android:layout_weight="80"
129+
android:textSize="13sp" />
130+
131+
<androidx.appcompat.widget.AppCompatButton
132+
android:id="@+id/group_voicestate_set_button"
133+
android:layout_width="wrap_content"
134+
android:layout_height="match_parent"
135+
android:layout_gravity="right"
136+
android:layout_weight="10"
137+
android:gravity="center"
138+
android:text="Set new Voice State"
139+
android:textAllCaps="false"
140+
android:textSize="13sp" />
141+
142+
</LinearLayout>
143+
111144
<TextView
112145
android:layout_width="match_parent"
113146
android:layout_height="20dp" />

0 commit comments

Comments
 (0)