Commit 998b661303c4343f9f53814d930613f1506570bc

Authored by 朱显松
1 parent 22fc6da6

更换首页启动模式,增加Presenter View弱引用

app/src/main/AndroidManifest.xml
@@ -40,7 +40,10 @@ @@ -40,7 +40,10 @@
40 android:roundIcon="@mipmap/ic_launcher_round" 40 android:roundIcon="@mipmap/ic_launcher_round"
41 android:supportsRtl="true" 41 android:supportsRtl="true"
42 android:theme="@style/Theme.AppCompat.Light.NoActionBar"> 42 android:theme="@style/Theme.AppCompat.Light.NoActionBar">
43 - <activity android:name=".main.ui.activity.MainActivity"> 43 + <activity
  44 + android:name=".main.ui.activity.MainActivity"
  45 + android:label="@string/app_name"
  46 + android:configChanges="keyboardHidden|screenSize|orientation">
44 <intent-filter> 47 <intent-filter>
45 <action android:name="android.intent.action.MAIN" /> 48 <action android:name="android.intent.action.MAIN" />
46 49
@@ -94,11 +97,13 @@ @@ -94,11 +97,13 @@
94 android:exported="true" 97 android:exported="true"
95 android:process=":ipc" /> 98 android:process=":ipc" />
96 99
97 - <service android:name="io.rong.imlib.ReConnectService"  
98 - android:exported="true"/> 100 + <service
  101 + android:name="io.rong.imlib.ReConnectService"
  102 + android:exported="true" />
99 103
100 - <receiver android:name="io.rong.imlib.ConnectChangeReceiver"  
101 - android:exported="true"/> 104 + <receiver
  105 + android:name="io.rong.imlib.ConnectChangeReceiver"
  106 + android:exported="true" />
102 107
103 <receiver 108 <receiver
104 android:name="io.rong.imlib.HeartbeatReceiver" 109 android:name="io.rong.imlib.HeartbeatReceiver"
app/src/main/java/com/cnlive/gundam/main/presenter/AnchorInfoPresenter.java
@@ -8,6 +8,7 @@ import com.cnlive.gundam.main.presenter.view.AnchorInfoView; @@ -8,6 +8,7 @@ import com.cnlive.gundam.main.presenter.view.AnchorInfoView;
8 import com.cnlive.gundam.stream.model.ChannelInfoModel; 8 import com.cnlive.gundam.stream.model.ChannelInfoModel;
9 import com.cnlive.libs.util.Config; 9 import com.cnlive.libs.util.Config;
10 10
  11 +import java.lang.ref.WeakReference;
11 import java.util.HashMap; 12 import java.util.HashMap;
12 import java.util.Map; 13 import java.util.Map;
13 14
@@ -21,12 +22,15 @@ import retrofit2.Response; @@ -21,12 +22,15 @@ import retrofit2.Response;
21 22
22 public class AnchorInfoPresenter { 23 public class AnchorInfoPresenter {
23 24
24 - private AnchorInfoView mView; 25 + private WeakReference<AnchorInfoView> viewRef;
25 26
26 public AnchorInfoPresenter(AnchorInfoView view) { 27 public AnchorInfoPresenter(AnchorInfoView view) {
27 - this.mView = view; 28 + viewRef = new WeakReference<>(view);
28 } 29 }
29 30
  31 + private AnchorInfoView getView(){
  32 + return viewRef == null ? null : viewRef.get();
  33 + }
30 /** 34 /**
31 * 查询主播信息 35 * 查询主播信息
32 * 36 *
@@ -43,16 +47,16 @@ public class AnchorInfoPresenter { @@ -43,16 +47,16 @@ public class AnchorInfoPresenter {
43 if (response.isSuccessful()) { 47 if (response.isSuccessful()) {
44 ChannelInfoModel info = response.body(); 48 ChannelInfoModel info = response.body();
45 if (info != null && "0".equals(info.getErrorCode())) { 49 if (info != null && "0".equals(info.getErrorCode())) {
46 - if (mView != null) mView.onAnchorInfo(info); 50 + if (getView() != null) getView().onAnchorInfo(info);
47 } else { 51 } else {
48 - if (mView != null) mView.getAnchorFailure(); 52 + if (getView() != null) getView().getAnchorFailure();
49 } 53 }
50 } 54 }
51 } 55 }
52 56
53 @Override 57 @Override
54 public void onFailure(Call<ChannelInfoModel> call, Throwable t) { 58 public void onFailure(Call<ChannelInfoModel> call, Throwable t) {
55 - if (mView != null) mView.getAnchorFailure(); 59 + if (getView() != null) getView().getAnchorFailure();
56 } 60 }
57 }); 61 });
58 } 62 }