Commit 915b1b18abba91002c8463a9cf1a9a30bdef4459

Authored by 朱显松
1 parent 4e4f80a5

主播认证View层代码从Activity中抽离,使用单独实现类

app/src/main/java/com/cnlive/gundam/main/presenter/AnchorInfoPresenter.java
@@ -4,7 +4,7 @@ import android.content.Context; @@ -4,7 +4,7 @@ import android.content.Context;
4 4
5 import com.cnlive.gundam.data.network.RetrofitUtil; 5 import com.cnlive.gundam.data.network.RetrofitUtil;
6 import com.cnlive.gundam.data.network.util.SignUtil; 6 import com.cnlive.gundam.data.network.util.SignUtil;
7 -import com.cnlive.gundam.main.presenter.view.AnchorInfoView; 7 +import com.cnlive.gundam.main.presenter.view.IAnchorInfoView;
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
@@ -22,13 +22,13 @@ import retrofit2.Response; @@ -22,13 +22,13 @@ import retrofit2.Response;
22 22
23 public class AnchorInfoPresenter { 23 public class AnchorInfoPresenter {
24 24
25 - private WeakReference<AnchorInfoView> viewRef; 25 + private WeakReference<IAnchorInfoView> viewRef;
26 26
27 - public AnchorInfoPresenter(AnchorInfoView view) { 27 + public AnchorInfoPresenter(IAnchorInfoView view) {
28 viewRef = new WeakReference<>(view); 28 viewRef = new WeakReference<>(view);
29 } 29 }
30 30
31 - private AnchorInfoView getView(){ 31 + private IAnchorInfoView getView(){
32 return viewRef == null ? null : viewRef.get(); 32 return viewRef == null ? null : viewRef.get();
33 } 33 }
34 /** 34 /**
app/src/main/java/com/cnlive/gundam/main/presenter/view/AnchorInfoView.java
1 package com.cnlive.gundam.main.presenter.view; 1 package com.cnlive.gundam.main.presenter.view;
2 2
  3 +import android.app.Activity;
  4 +import android.app.AlertDialog;
  5 +import android.content.DialogInterface;
  6 +import android.content.Intent;
  7 +import android.support.v4.app.Fragment;
  8 +import android.widget.Toast;
  9 +
  10 +import com.cnlive.gundam.R;
  11 +import com.cnlive.gundam.main.ui.activity.WebViewActivity;
3 import com.cnlive.gundam.stream.model.ChannelInfoModel; 12 import com.cnlive.gundam.stream.model.ChannelInfoModel;
  13 +import com.cnlive.gundam.stream.ui.activity.StreamActivity;
  14 +import com.cnlive.gundam.user.auth.UserService;
  15 +import com.cnlive.libs.util.Config;
  16 +
  17 +/**
  18 + * Created by xiansong on 2017/7/10.
  19 + */
  20 +
  21 +public class AnchorInfoView implements IAnchorInfoView{
  22 +
  23 + private Activity activity;
  24 +
  25 + public AnchorInfoView(Activity activity){
  26 + this.activity = activity;
  27 + }
  28 +
  29 + public AnchorInfoView(Fragment fragment){
  30 + this.activity = fragment != null ? fragment.getActivity() : null;
  31 + }
  32 +
  33 + @Override
  34 + public void onAnchorInfo(ChannelInfoModel info) {
  35 + switch (info.getData().getStatus()) {
  36 + case -1:
  37 + Toast.makeText(activity, "主播不存在", Toast.LENGTH_SHORT).show();
  38 + showVerifiedDialog();
  39 + break;
  40 + case 1:
  41 + Toast.makeText(activity, "审核中,请耐心等待", Toast.LENGTH_SHORT).show();
  42 + break;
  43 + case 2:
  44 + Toast.makeText(activity, "审核失败", Toast.LENGTH_SHORT).show();
  45 + break;
  46 + case 3:
  47 + Toast.makeText(activity, "开启直播", Toast.LENGTH_SHORT).show();
  48 + startStreamActivity(info);
  49 + break;
  50 + case 4:
  51 + Toast.makeText(activity, "主播被禁用", Toast.LENGTH_SHORT).show();
  52 + break;
  53 + }
  54 + }
  55 +
  56 + @Override
  57 + public void getAnchorFailure() {
  58 + Toast.makeText(activity, "主播信息认证失败", Toast.LENGTH_LONG).show();
  59 + }
4 60
5 -public interface AnchorInfoView {  
6 /** 61 /**
7 - * 获取主播信息成功 62 + * 开启直播推流页面
8 * 63 *
9 - * @param channelInfo 主播信息 64 + * @param info 主播信息
10 */ 65 */
11 - void onAnchorInfo(ChannelInfoModel channelInfo); 66 + private void startStreamActivity(ChannelInfoModel info) {
  67 + String activityId = System.currentTimeMillis() + "";
  68 + String channelId = info.getData().getChannelId();
  69 + String channelName = info.getData().getChannelName();
  70 + String coverImgUrl = info.getData().getCoverImgUrl();
  71 + StreamActivity.start(activity, activityId, channelId, channelName, coverImgUrl);
  72 + }
12 73
13 /** 74 /**
14 - * 获取主播信息失败 75 + * 显示主播申请页面
15 */ 76 */
16 - void getAnchorFailure();  
17 -}  
18 \ No newline at end of file 77 \ No newline at end of file
  78 + private void showVerifiedDialog() {
  79 + new AlertDialog.Builder(activity)
  80 + .setMessage("亲,完成实名认证就可以开播啦,现在就去认证吧?")
  81 + .setPositiveButton("去认证", new DialogInterface.OnClickListener() {
  82 + @Override
  83 + public void onClick(DialogInterface dialogInterface, int i) {
  84 + dialogInterface.dismiss();
  85 + String channelId = UserService.getInstance(activity).getActiveAccountInfo().getUid() + "";
  86 + String base_url = activity.getString(Config.debug ? R.string.debug_verified_url : R.string.verified_url);
  87 + String url = String.format(base_url, channelId, Config.getAppId());
  88 + Intent intent = new Intent(activity, WebViewActivity.class);
  89 + intent.putExtra("url", url);
  90 + intent.putExtra("title", "主播认证");
  91 + activity.startActivity(intent);
  92 + }
  93 + })
  94 + .setNegativeButton("取消", new DialogInterface.OnClickListener() {
  95 + @Override
  96 + public void onClick(DialogInterface dialogInterface, int i) {
  97 + dialogInterface.dismiss();
  98 + }
  99 + }).show();
  100 + }
  101 +
  102 +}
app/src/main/java/com/cnlive/gundam/main/presenter/view/IAnchorInfoView.java 0 → 100644
  1 +package com.cnlive.gundam.main.presenter.view;
  2 +
  3 +import com.cnlive.gundam.stream.model.ChannelInfoModel;
  4 +
  5 +public interface IAnchorInfoView {
  6 + /**
  7 + * 获取主播信息成功
  8 + *
  9 + * @param channelInfo 主播信息
  10 + */
  11 + void onAnchorInfo(ChannelInfoModel channelInfo);
  12 +
  13 + /**
  14 + * 获取主播信息失败
  15 + */
  16 + void getAnchorFailure();
  17 +}
0 \ No newline at end of file 18 \ No newline at end of file
app/src/main/java/com/cnlive/gundam/main/ui/activity/MainActivity.java
1 package com.cnlive.gundam.main.ui.activity; 1 package com.cnlive.gundam.main.ui.activity;
2 2
3 -import android.app.AlertDialog;  
4 -import android.content.DialogInterface;  
5 import android.content.Intent; 3 import android.content.Intent;
6 import android.databinding.DataBindingUtil; 4 import android.databinding.DataBindingUtil;
7 import android.os.Bundle; 5 import android.os.Bundle;
8 import android.support.v7.app.AppCompatActivity; 6 import android.support.v7.app.AppCompatActivity;
9 -import android.widget.Toast;  
10 7
11 import com.cnlive.gundam.R; 8 import com.cnlive.gundam.R;
12 import com.cnlive.gundam.databinding.ActivityMainBinding; 9 import com.cnlive.gundam.databinding.ActivityMainBinding;
@@ -18,14 +15,11 @@ import com.cnlive.gundam.main.ui.fragment.LiveFragment; @@ -18,14 +15,11 @@ import com.cnlive.gundam.main.ui.fragment.LiveFragment;
18 import com.cnlive.gundam.main.ui.fragment.UGCListFragment; 15 import com.cnlive.gundam.main.ui.fragment.UGCListFragment;
19 import com.cnlive.gundam.main.ui.widget.FragmentTabHost; 16 import com.cnlive.gundam.main.ui.widget.FragmentTabHost;
20 import com.cnlive.gundam.main.utils.SharedPreferencesHelper; 17 import com.cnlive.gundam.main.utils.SharedPreferencesHelper;
21 -import com.cnlive.gundam.stream.model.ChannelInfoModel;  
22 -import com.cnlive.gundam.stream.ui.activity.StreamActivity;  
23 import com.cnlive.gundam.stream.util.FileUtil; 18 import com.cnlive.gundam.stream.util.FileUtil;
24 import com.cnlive.gundam.user.activity.LoginActivity; 19 import com.cnlive.gundam.user.activity.LoginActivity;
25 import com.cnlive.gundam.user.auth.UserService; 20 import com.cnlive.gundam.user.auth.UserService;
26 import com.cnlive.gundam.user.model.User; 21 import com.cnlive.gundam.user.model.User;
27 import com.cnlive.gundam.video.view.VideoView; 22 import com.cnlive.gundam.video.view.VideoView;
28 -import com.cnlive.libs.util.Config;  
29 23
30 import java.util.Arrays; 24 import java.util.Arrays;
31 25
@@ -33,7 +27,7 @@ import java.util.Arrays; @@ -33,7 +27,7 @@ import java.util.Arrays;
33 * Created by xiansong on 2017/6/27. 27 * Created by xiansong on 2017/6/27.
34 */ 28 */
35 29
36 -public class MainActivity extends AppCompatActivity implements FragmentTabHost.OnSetCurrentTabListener, AnchorInfoView { 30 +public class MainActivity extends AppCompatActivity implements FragmentTabHost.OnSetCurrentTabListener {
37 31
38 private AnchorInfoPresenter mAnchorInfoPresenter; 32 private AnchorInfoPresenter mAnchorInfoPresenter;
39 33
@@ -51,7 +45,7 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O @@ -51,7 +45,7 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O
51 FragmentTabHost.newTab("config", R.layout.indicator_main_mine, ConfigFragment.class) 45 FragmentTabHost.newTab("config", R.layout.indicator_main_mine, ConfigFragment.class)
52 )); 46 ));
53 47
54 - mAnchorInfoPresenter = new AnchorInfoPresenter(this); 48 + mAnchorInfoPresenter = new AnchorInfoPresenter(new AnchorInfoView(this));
55 49
56 //加载水印图片 50 //加载水印图片
57 FileUtil.copyFile(this, "cnlive_logo.png"); 51 FileUtil.copyFile(this, "cnlive_logo.png");
@@ -79,74 +73,6 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O @@ -79,74 +73,6 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O
79 } 73 }
80 } 74 }
81 75
82 -  
83 - @Override  
84 - public void onAnchorInfo(ChannelInfoModel info) {  
85 - switch (info.getData().getStatus()) {  
86 - case -1:  
87 - Toast.makeText(this, "主播不存在", Toast.LENGTH_SHORT).show();  
88 - showVerifiedDialog();  
89 - break;  
90 - case 1:  
91 - Toast.makeText(this, "审核中,请耐心等待", Toast.LENGTH_SHORT).show();  
92 - break;  
93 - case 2:  
94 - Toast.makeText(this, "审核失败", Toast.LENGTH_SHORT).show();  
95 - break;  
96 - case 3:  
97 - Toast.makeText(this, "开启直播", Toast.LENGTH_SHORT).show();  
98 - startStreamActivity(info);  
99 - break;  
100 - case 4:  
101 - Toast.makeText(this, "主播被禁用", Toast.LENGTH_SHORT).show();  
102 - break;  
103 - }  
104 - }  
105 -  
106 - @Override  
107 - public void getAnchorFailure() {  
108 - Toast.makeText(this, "主播信息认证失败", Toast.LENGTH_LONG).show();  
109 - }  
110 -  
111 - /**  
112 - * 开启直播推流页面  
113 - *  
114 - * @param info 主播信息  
115 - */  
116 - private void startStreamActivity(ChannelInfoModel info) {  
117 - String activityId = System.currentTimeMillis() + "";  
118 - String channelId = info.getData().getChannelId();  
119 - String channelName = info.getData().getChannelName();  
120 - String coverImgUrl = info.getData().getCoverImgUrl();  
121 - StreamActivity.start(this, activityId, channelId, channelName, coverImgUrl);  
122 - }  
123 -  
124 - /**  
125 - * 显示主播申请页面  
126 - */  
127 - private void showVerifiedDialog() {  
128 - new AlertDialog.Builder(this)  
129 - .setMessage("亲,完成实名认证就可以开播啦,现在就去认证吧?")  
130 - .setPositiveButton("去认证", new DialogInterface.OnClickListener() {  
131 - @Override  
132 - public void onClick(DialogInterface dialogInterface, int i) {  
133 - dialogInterface.dismiss();  
134 - String channelId = UserService.getInstance(MainActivity.this).getActiveAccountInfo().getUid() + "";  
135 - String url = String.format(getString(Config.debug ? R.string.debug_verified_url : R.string.verified_url), channelId, Config.getAppId());  
136 - Intent intent = new Intent(MainActivity.this, WebViewActivity.class);  
137 - intent.putExtra("url", url);  
138 - intent.putExtra("title", "主播认证");  
139 - startActivity(intent);  
140 - }  
141 - })  
142 - .setNegativeButton("取消", new DialogInterface.OnClickListener() {  
143 - @Override  
144 - public void onClick(DialogInterface dialogInterface, int i) {  
145 - dialogInterface.dismiss();  
146 - }  
147 - }).show();  
148 - }  
149 -  
150 @Override 76 @Override
151 protected void onDestroy() { 77 protected void onDestroy() {
152 super.onDestroy(); 78 super.onDestroy();