1010import androidx .annotation .NonNull ;
1111import androidx .annotation .Nullable ;
1212import androidx .fragment .app .Fragment ;
13+ import androidx .lifecycle .Observer ;
1314import androidx .lifecycle .ViewModelProviders ;
1415
1516import com .afollestad .materialdialogs .MaterialDialog ;
1617
1718import java .util .Collections ;
19+ import java .util .List ;
1820
1921import butterknife .BindView ;
2022import butterknife .ButterKnife ;
@@ -30,6 +32,7 @@ public class GroupManageFragment extends Fragment {
3032 OptionItemView joinOptionItemView ;
3133 @ BindView (R .id .searchOptionItemView )
3234 OptionItemView searchOptionItemView ;
35+ private GroupViewModel groupViewModel ;
3336
3437 public static GroupManageFragment newInstance (GroupInfo groupInfo ) {
3538 Bundle args = new Bundle ();
@@ -57,6 +60,19 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
5760 private void init () {
5861 String [] types = getResources ().getStringArray (R .array .group_join_type );
5962 joinOptionItemView .setDesc (types [groupInfo .joinType ]);
63+ groupViewModel = ViewModelProviders .of (this ).get (GroupViewModel .class );
64+ groupViewModel .groupInfoUpdateLiveData ().observe (getActivity (), new Observer <List <GroupInfo >>() {
65+ @ Override
66+ public void onChanged (List <GroupInfo > groupInfos ) {
67+ for (GroupInfo info : groupInfos ) {
68+ if (info .target .equals (groupInfo .target )) {
69+ groupInfo = info ;
70+ break ;
71+ }
72+ }
73+
74+ }
75+ });
6076 }
6177
6278 @ OnClick (R .id .managerOptionItemView )
@@ -83,29 +99,28 @@ void showMemberPermissionSetting() {
8399
84100 @ OnClick (R .id .joinOptionItemView )
85101 void showJoinTypeSetting () {
86- GroupViewModel groupViewModel = ViewModelProviders .of (this ).get (GroupViewModel .class );
87102 new MaterialDialog .Builder (getActivity ())
88- .items (R .array .group_join_type )
89- .itemsCallback ((dialog , itemView , position , text ) -> {
90- groupViewModel .setGroupJoinType (groupInfo .target , position , null , Collections .singletonList (0 ))
91- .observe (GroupManageFragment .this , booleanOperateResult -> {
92- if (booleanOperateResult .isSuccess ()) {
93- joinOptionItemView .setDesc ((String ) text );
94- } else {
95- Toast .makeText (getActivity (), "修改加群方式失败" , Toast .LENGTH_SHORT ).show ();
96- }
97- });
98- })
99- .show ();
103+ .items (R .array .group_join_type )
104+ .itemsCallback ((dialog , itemView , position , text ) -> {
105+ groupViewModel .setGroupJoinType (groupInfo .target , position , null , Collections .singletonList (0 ))
106+ .observe (GroupManageFragment .this , booleanOperateResult -> {
107+ if (booleanOperateResult .isSuccess ()) {
108+ joinOptionItemView .setDesc ((String ) text );
109+ } else {
110+ Toast .makeText (getActivity (), "修改加群方式失败" , Toast .LENGTH_SHORT ).show ();
111+ }
112+ });
113+ })
114+ .show ();
100115 }
101116
102117 @ OnClick (R .id .searchOptionItemView )
103118 void showSearchSetting () {
104119 new MaterialDialog .Builder (getActivity ())
105- .items (R .array .group_search_type )
106- .itemsCallback ((dialog , itemView , position , text ) -> {
107- searchOptionItemView .setDesc ((String ) text );
108- })
109- .show ();
120+ .items (R .array .group_search_type )
121+ .itemsCallback ((dialog , itemView , position , text ) -> {
122+ searchOptionItemView .setDesc ((String ) text );
123+ })
124+ .show ();
110125 }
111126}
0 commit comments