Commit d4819f8c authored by fallenstardust's avatar fallenstardust

同步聊天室与萌卡的登录状态

parent 79e40df4
...@@ -18,6 +18,7 @@ import androidx.annotation.Nullable; ...@@ -18,6 +18,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.RecyclerViewItemListener; import androidx.appcompat.widget.RecyclerViewItemListener;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.FastScrollLinearLayoutManager; import androidx.recyclerview.widget.FastScrollLinearLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.ourygo.assistant.util.DuelAssistantManagement; import com.ourygo.assistant.util.DuelAssistantManagement;
......
...@@ -59,7 +59,7 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener ...@@ -59,7 +59,7 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
private TextView mNameView, mStatusView; private TextView mNameView, mStatusView;
private TextView tv_back_mc; private TextView tv_back_mc;
//萌卡webview //萌卡webview
private MyCardWebView mWebViewPlus; public MyCardWebView mWebViewPlus;
private MyCard mMyCard; private MyCard mMyCard;
//聊天室 //聊天室
private RelativeLayout rl_chat; private RelativeLayout rl_chat;
...@@ -80,7 +80,9 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener ...@@ -80,7 +80,9 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
} }
mNameView.setText(ss[0]); mNameView.setText(ss[0]);
mStatusView.setText(ss[2]); mStatusView.setText(ss[2]);
initData(); initData();
} }
} }
}; };
...@@ -92,7 +94,7 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener ...@@ -92,7 +94,7 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState); super.onCreateView(inflater, container, savedInstanceState);
homeActivity = (HomeActivity)getActivity(); homeActivity = (HomeActivity) getActivity();
View view; View view;
view = inflater.inflate(R.layout.fragment_mycard, container, false); view = inflater.inflate(R.layout.fragment_mycard, container, false);
initView(view); initView(view);
...@@ -119,14 +121,12 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener ...@@ -119,14 +121,12 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
tv_message = view.findViewById(R.id.tv_message); tv_message = view.findViewById(R.id.tv_message);
pb_chat_loading = view.findViewById(R.id.pb_chat_loading); pb_chat_loading = view.findViewById(R.id.pb_chat_loading);
SharedPreferences lastModified = getActivity().getSharedPreferences("lastModified", Context.MODE_PRIVATE);
UserManagement.setUserName(lastModified.getString("user_name", null));
UserManagement.setUserPassword(lastModified.getString("user_external_id", null));
serviceManagement = ServiceManagement.getDx(); serviceManagement = ServiceManagement.getDx();
serviceManagement.addJoinRoomListener(this); serviceManagement.addJoinRoomListener(this);
serviceManagement.addListener(this); serviceManagement.addListener(this);
initData();
WebSettings settings = mWebViewPlus.getSettings(); WebSettings settings = mWebViewPlus.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + MessageFormat.format( settings.setUserAgentString(settings.getUserAgentString() + MessageFormat.format(
" YGOMobile/{0} ({1} {2,number,#})", " YGOMobile/{0} ({1} {2,number,#})",
...@@ -178,14 +178,14 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener ...@@ -178,14 +178,14 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
}); });
mMyCard.attachWeb(mWebViewPlus, this); mMyCard.attachWeb(mWebViewPlus, this);
mWebViewPlus.loadUrl(mMyCard.getHomeUrl()); mWebViewPlus.loadUrl(mMyCard.getHomeUrl());
getChildFragmentManager().beginTransaction().add(R.id.fragment_content, homeActivity.fragment_mycard_chatting_room).hide(homeActivity.fragment_mycard_chatting_room).commit();
} }
private void initData() { private void initData() {
SharedPreferences lastModified = getActivity().getSharedPreferences("lastModified", Context.MODE_PRIVATE);
UserManagement.setUserName(lastModified.getString("user_name", null));
UserManagement.setUserPassword(lastModified.getString("user_external_id", null));
if (UserManagement.getUserName() != null) { if (UserManagement.getUserName() != null) {
serviceManagement.start(); serviceManagement.start();
} else {
} }
} }
...@@ -305,10 +305,20 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener ...@@ -305,10 +305,20 @@ public class MycardFragment extends BaseFragemnt implements View.OnClickListener
break; break;
case R.id.rl_chat: case R.id.rl_chat:
//这里显示聊天室fragment //这里显示聊天室fragment
if (homeActivity.fragment_mycard_chatting_room.isHidden()) { if (serviceManagement.isConnected()) {
getChildFragmentManager().beginTransaction().show(homeActivity.fragment_mycard_chatting_room).commit(); if (!homeActivity.fragment_mycard_chatting_room.isAdded()) {
} else { getChildFragmentManager().beginTransaction().add(R.id.fragment_content, homeActivity.fragment_mycard_chatting_room).commit();
getChildFragmentManager().beginTransaction().hide(homeActivity.fragment_mycard_chatting_room).commit(); mWebViewPlus.setVisibility(View.INVISIBLE);
} else {
if (homeActivity.fragment_mycard_chatting_room.isHidden()) {
getChildFragmentManager().beginTransaction().show(homeActivity.fragment_mycard_chatting_room).commit();
mWebViewPlus.setVisibility(View.INVISIBLE);
} else {
getChildFragmentManager().beginTransaction().hide(homeActivity.fragment_mycard_chatting_room).commit();
mWebViewPlus.setVisibility(View.VISIBLE);
}
}
} }
break; break;
} }
......
...@@ -20,6 +20,7 @@ import com.ourygo.assistant.util.Util; ...@@ -20,6 +20,7 @@ import com.ourygo.assistant.util.Util;
import cn.garymb.ygomobile.base.BaseFragemnt; import cn.garymb.ygomobile.base.BaseFragemnt;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.home.HomeActivity; import cn.garymb.ygomobile.ui.home.HomeActivity;
import cn.garymb.ygomobile.ui.mycard.MycardFragment;
import cn.garymb.ygomobile.ui.mycard.mcchat.adapter.ChatAdapter; import cn.garymb.ygomobile.ui.mycard.mcchat.adapter.ChatAdapter;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement; import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.utils.YGOUtil; import cn.garymb.ygomobile.utils.YGOUtil;
...@@ -55,6 +56,7 @@ public class MycardChatFragment extends BaseFragemnt implements ChatListener { ...@@ -55,6 +56,7 @@ public class MycardChatFragment extends BaseFragemnt implements ChatListener {
main_send = view.findViewById(R.id.main_send); main_send = view.findViewById(R.id.main_send);
main_send_message = view.findViewById(R.id.main_send_message); main_send_message = view.findViewById(R.id.main_send_message);
main_title = view.findViewById(R.id.main_title); main_title = view.findViewById(R.id.main_title);
main_title.setText(getString(R.string.mc_chat) + "(" + serviceManagement.getMemberNum() + ")");
btn_hide = view.findViewById(R.id.btn_hide); btn_hide = view.findViewById(R.id.btn_hide);
main_bottom_bar = view.findViewById(R.id.main_bottom_bar); main_bottom_bar = view.findViewById(R.id.main_bottom_bar);
...@@ -79,7 +81,7 @@ public class MycardChatFragment extends BaseFragemnt implements ChatListener { ...@@ -79,7 +81,7 @@ public class MycardChatFragment extends BaseFragemnt implements ChatListener {
public void reChatJoin(boolean state) { public void reChatJoin(boolean state) {
if (state) { if (state) {
main_bottom_bar.setVisibility(View.VISIBLE); main_bottom_bar.setVisibility(View.VISIBLE);
main_title.setText(getString(R.string.mc_chat) + "("+serviceManagement.getMemberNum() + ")"); main_title.setText(getString(R.string.mc_chat) + "(" + serviceManagement.getMemberNum() + ")");
} else { } else {
main_bottom_bar.setVisibility(View.GONE); main_bottom_bar.setVisibility(View.GONE);
main_title.setText(R.string.reChatJoining); main_title.setText(R.string.reChatJoining);
...@@ -117,6 +119,7 @@ public class MycardChatFragment extends BaseFragemnt implements ChatListener { ...@@ -117,6 +119,7 @@ public class MycardChatFragment extends BaseFragemnt implements ChatListener {
}); });
btn_hide.setOnClickListener(p1 -> { btn_hide.setOnClickListener(p1 -> {
getParentFragmentManager().beginTransaction().hide(homeActivity.fragment_mycard_chatting_room).commit(); getParentFragmentManager().beginTransaction().hide(homeActivity.fragment_mycard_chatting_room).commit();
homeActivity.fragment_mycard.mWebViewPlus.setVisibility(View.VISIBLE);
}); });
} }
......
...@@ -70,9 +70,9 @@ public class ServiceManagement { ...@@ -70,9 +70,9 @@ public class ServiceManagement {
switch (msg.what) { switch (msg.what) {
case TYPE_ADD_MESSAGE: case TYPE_ADD_MESSAGE:
while (i < chatListenerList.size()) { while (i < chatListenerList.size()) {
ChatListener c = chatListenerList.get(i); ChatListener chatListener = chatListenerList.get(i);
if (c.isListenerEffective()) { if (chatListener.isListenerEffective()) {
c.addChatMessage((ChatMessage) msg.obj); chatListener.addChatMessage((ChatMessage) msg.obj);
i++; i++;
} else { } else {
chatListenerList.remove(i); chatListenerList.remove(i);
...@@ -81,9 +81,9 @@ public class ServiceManagement { ...@@ -81,9 +81,9 @@ public class ServiceManagement {
break; break;
case TYPE_RE_LOGIN: case TYPE_RE_LOGIN:
while (i < chatListenerList.size()) { while (i < chatListenerList.size()) {
ChatListener c = chatListenerList.get(i); ChatListener chatListener = chatListenerList.get(i);
if (c.isListenerEffective()) { if (chatListener.isListenerEffective()) {
c.reChatLogin((boolean) msg.obj); chatListener.reChatLogin((boolean) msg.obj);
i++; i++;
} else { } else {
chatListenerList.remove(i); chatListenerList.remove(i);
...@@ -93,9 +93,9 @@ public class ServiceManagement { ...@@ -93,9 +93,9 @@ public class ServiceManagement {
case TYPE_RE_JOIN: case TYPE_RE_JOIN:
while (i < chatListenerList.size()) { while (i < chatListenerList.size()) {
ChatListener c = chatListenerList.get(i); ChatListener chatListener = chatListenerList.get(i);
if (c.isListenerEffective()) { if (chatListener.isListenerEffective()) {
c.reChatJoin((boolean) msg.obj); chatListener.reChatJoin((boolean) msg.obj);
i++; i++;
} else { } else {
chatListenerList.remove(i); chatListenerList.remove(i);
...@@ -115,9 +115,9 @@ public class ServiceManagement { ...@@ -115,9 +115,9 @@ public class ServiceManagement {
// break; // break;
case CHAT_LOGIN_OK: case CHAT_LOGIN_OK:
while (i < joinChatListenerList.size()) { while (i < joinChatListenerList.size()) {
OnJoinChatListener ou = joinChatListenerList.get(i); OnJoinChatListener onJoinChatListener = joinChatListenerList.get(i);
if (ou.isListenerEffective()) { if (onJoinChatListener.isListenerEffective()) {
ou.onChatLogin(null); onJoinChatListener.onChatLogin(null);
i++; i++;
} else { } else {
joinChatListenerList.remove(i); joinChatListenerList.remove(i);
...@@ -126,9 +126,9 @@ public class ServiceManagement { ...@@ -126,9 +126,9 @@ public class ServiceManagement {
break; break;
case CHAT_LOGIN_EXCEPTION: case CHAT_LOGIN_EXCEPTION:
while (i < joinChatListenerList.size()) { while (i < joinChatListenerList.size()) {
OnJoinChatListener ou = joinChatListenerList.get(i); OnJoinChatListener onJoinChatListener = joinChatListenerList.get(i);
if (ou.isListenerEffective()) { if (onJoinChatListener.isListenerEffective()) {
ou.onChatLogin(msg.obj + ""); onJoinChatListener.onChatLogin(msg.obj + "");
i++; i++;
} else { } else {
joinChatListenerList.remove(i); joinChatListenerList.remove(i);
...@@ -137,9 +137,9 @@ public class ServiceManagement { ...@@ -137,9 +137,9 @@ public class ServiceManagement {
break; break;
case CHAT_LOGIN_LOADING: case CHAT_LOGIN_LOADING:
while (i < joinChatListenerList.size()) { while (i < joinChatListenerList.size()) {
OnJoinChatListener ou = joinChatListenerList.get(i); OnJoinChatListener onJoinChatListener = joinChatListenerList.get(i);
if (ou.isListenerEffective()) { if (onJoinChatListener.isListenerEffective()) {
ou.onChatLoginLoading(); onJoinChatListener.onChatLoginLoading();
i++; i++;
} else { } else {
joinChatListenerList.remove(i); joinChatListenerList.remove(i);
...@@ -148,9 +148,9 @@ public class ServiceManagement { ...@@ -148,9 +148,9 @@ public class ServiceManagement {
break; break;
case CHAT_JOIN_ROOM_LOADING: case CHAT_JOIN_ROOM_LOADING:
while (i < joinChatListenerList.size()) { while (i < joinChatListenerList.size()) {
OnJoinChatListener ou = joinChatListenerList.get(i); OnJoinChatListener onJoinChatListener = joinChatListenerList.get(i);
if (ou.isListenerEffective()) { if (onJoinChatListener.isListenerEffective()) {
ou.onJoinRoomLoading(); onJoinChatListener.onJoinRoomLoading();
i++; i++;
} else { } else {
joinChatListenerList.remove(i); joinChatListenerList.remove(i);
...@@ -159,9 +159,9 @@ public class ServiceManagement { ...@@ -159,9 +159,9 @@ public class ServiceManagement {
break; break;
case CHAT_USER_NULL: case CHAT_USER_NULL:
while (i < joinChatListenerList.size()) { while (i < joinChatListenerList.size()) {
OnJoinChatListener ou = joinChatListenerList.get(i); OnJoinChatListener onJoinChatListener = joinChatListenerList.get(i);
if (ou.isListenerEffective()) { if (onJoinChatListener.isListenerEffective()) {
ou.onChatUserNull(); onJoinChatListener.onChatUserNull();
i++; i++;
} else { } else {
joinChatListenerList.remove(i); joinChatListenerList.remove(i);
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
android:id="@+id/webbrowser" android:id="@+id/webbrowser"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="10"> android:layout_weight="11">
<ProgressBar <ProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"
...@@ -103,8 +103,8 @@ ...@@ -103,8 +103,8 @@
android:id="@+id/tv_message_s" android:id="@+id/tv_message_s"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/mc_chat"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:text="@string/mc_chat"
android:textColor="@color/holo_green_bright" android:textColor="@color/holo_green_bright"
android:textStyle="bold" /> android:textStyle="bold" />
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
android:layout_height="15dp" android:layout_height="15dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:visibility="gone"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toRightOf="@id/tv_message_s" /> android:layout_toRightOf="@id/tv_message_s" />
...@@ -126,7 +127,7 @@ ...@@ -126,7 +127,7 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:ellipsize="end" android:ellipsize="end"
android:lines="1" android:lines="1"
android:text="" android:text="@string/login_mycard"
android:textColor="@color/holo_orange_bright" /> android:textColor="@color/holo_orange_bright" />
</RelativeLayout> </RelativeLayout>
</androidx.appcompat.widget.LinearLayoutCompat> </androidx.appcompat.widget.LinearLayoutCompat>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment