Commit 01643e3d682f6498d5c73e13b01be6a94fa36cc1
1 parent
ce07866a
区分接口地址
Showing
17 changed files
with
109 additions
and
84 deletions
app/build.gradle
| ... | ... | @@ -31,8 +31,13 @@ dependencies { |
| 31 | 31 | compile 'com.github.bumptech.glide:glide:3.7.0' |
| 32 | 32 | compile 'org.greenrobot:eventbus:3.0.0' |
| 33 | 33 | |
| 34 | - compile 'com.squareup.retrofit2:retrofit:2.3.0' | |
| 35 | - compile 'com.squareup.retrofit2:converter-gson:2.3.0' | |
| 34 | + //Retrofit | |
| 35 | + compile 'com.squareup.retrofit2:retrofit:2.0.2' | |
| 36 | + compile 'com.squareup.retrofit2:converter-gson:2.0.2' | |
| 37 | + //OKhttp | |
| 38 | + compile 'com.squareup.okhttp3:okhttp:3.2.0' | |
| 39 | + compile 'com.squareup.okhttp3:okhttp-ws:3.2.0' | |
| 40 | + compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' | |
| 36 | 41 | compile project(':user') |
| 37 | 42 | |
| 38 | 43 | } | ... | ... |
app/src/main/java/com/cnlive/gundam/main/application/CNLiveApplication.java
| ... | ... | @@ -13,8 +13,6 @@ public class CNLiveApplication extends Application { |
| 13 | 13 | @Override |
| 14 | 14 | public void onCreate() { |
| 15 | 15 | super.onCreate(); |
| 16 | - //TODO 测试ID 在正式与测试环境均可通过,正式ID则不行~! | |
| 17 | -// Config.init(getApplicationContext(), "60_j4fc7dsm83", "4c8658abc5d66f270f9bf5dcd1ef11e3597fab4c4e0af9",true); | |
| 18 | - Config.init(getApplicationContext(), "60_j4faozoq85", "7b6da5a6e2955aaf7f73a06b5bdc6d50e6d5bfda3da86b"); | |
| 16 | + Config.init(getApplicationContext(), "60_j4fc7dsm83", "4c8658abc5d66f270f9bf5dcd1ef11e3597fab4c4e0af9", true);//测试信息 | |
| 19 | 17 | } |
| 20 | 18 | } | ... | ... |
app/src/main/java/com/cnlive/gundam/main/network/ApiService.java
| ... | ... | @@ -3,7 +3,7 @@ package com.cnlive.gundam.main.network; |
| 3 | 3 | import com.cnlive.gundam.main.model.ActiveListModel; |
| 4 | 4 | import com.cnlive.gundam.main.model.ActivePlayInfo; |
| 5 | 5 | import com.cnlive.gundam.main.model.VodListPage; |
| 6 | -import com.cnlive.gundam.user.model.ChannelInfoModel; | |
| 6 | +import com.cnlive.gundam.stream.model.ChannelInfoModel; | |
| 7 | 7 | |
| 8 | 8 | import java.util.Map; |
| 9 | 9 | ... | ... |
app/src/main/java/com/cnlive/gundam/main/network/RetrofitUtil.java
| 1 | 1 | package com.cnlive.gundam.main.network; |
| 2 | 2 | |
| 3 | + | |
| 4 | +import com.cnlive.libs.util.Config; | |
| 5 | + | |
| 3 | 6 | import okhttp3.OkHttpClient; |
| 7 | +import okhttp3.logging.HttpLoggingInterceptor; | |
| 4 | 8 | import retrofit2.Retrofit; |
| 5 | 9 | import retrofit2.converter.gson.GsonConverterFactory; |
| 6 | 10 | |
| ... | ... | @@ -10,14 +14,25 @@ import retrofit2.converter.gson.GsonConverterFactory; |
| 10 | 14 | |
| 11 | 15 | public class RetrofitUtil { |
| 12 | 16 | |
| 13 | - private static final String BASE_URL = "http://test.open.cnlive.com/openapi/api2/"; | |
| 14 | 17 | |
| 15 | - public static ApiService getApiService(){ | |
| 18 | + private static final String BASE_URL_DEBUG = "http://test.open.cnlive.com/openapi/api2/"; | |
| 19 | + | |
| 20 | + private static final String BASE_URL_RELEASE = "https://api.cnlive.com/open/api2/"; | |
| 21 | + | |
| 22 | + public static ApiService getApiService() { | |
| 23 | + | |
| 24 | + | |
| 16 | 25 | Retrofit retrofit = new Retrofit.Builder() |
| 17 | - .baseUrl(BASE_URL) | |
| 26 | + .baseUrl(Config.debug ? BASE_URL_DEBUG : BASE_URL_RELEASE) | |
| 18 | 27 | .addConverterFactory(GsonConverterFactory.create()) |
| 19 | - .client(new OkHttpClient()) | |
| 28 | + .client(getNewClient()) | |
| 20 | 29 | .build(); |
| 21 | 30 | return retrofit.create(ApiService.class); |
| 22 | 31 | } |
| 32 | + | |
| 33 | + private static OkHttpClient getNewClient() { | |
| 34 | + HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); | |
| 35 | + httpLoggingInterceptor.setLevel(Config.debug ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE); | |
| 36 | + return new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).build(); | |
| 37 | + } | |
| 23 | 38 | } | ... | ... |
app/src/main/java/com/cnlive/gundam/main/presenter/AnchorInfoPresenter.java
| ... | ... | @@ -5,7 +5,7 @@ import android.content.Context; |
| 5 | 5 | import com.cnlive.gundam.main.network.RetrofitUtil; |
| 6 | 6 | import com.cnlive.gundam.main.network.util.SignUtil; |
| 7 | 7 | import com.cnlive.gundam.main.presenter.view.AnchorInfoView; |
| 8 | -import com.cnlive.gundam.user.model.ChannelInfoModel; | |
| 8 | +import com.cnlive.gundam.stream.model.ChannelInfoModel; | |
| 9 | 9 | import com.cnlive.libs.util.Config; |
| 10 | 10 | |
| 11 | 11 | import java.util.HashMap; | ... | ... |
app/src/main/java/com/cnlive/gundam/main/presenter/view/AnchorInfoView.java
| 1 | 1 | package com.cnlive.gundam.main.presenter.view; |
| 2 | 2 | |
| 3 | -import com.cnlive.gundam.user.model.ChannelInfoModel; | |
| 3 | +import com.cnlive.gundam.stream.model.ChannelInfoModel; | |
| 4 | 4 | |
| 5 | 5 | public interface AnchorInfoView { |
| 6 | + /** | |
| 7 | + * 获取主播信息成功 | |
| 8 | + * | |
| 9 | + * @param channelInfo 主播信息 | |
| 10 | + */ | |
| 6 | 11 | void onAnchorInfo(ChannelInfoModel channelInfo); |
| 7 | 12 | |
| 13 | + /** | |
| 14 | + * 获取主播信息失败 | |
| 15 | + */ | |
| 8 | 16 | void getAnchorFailure(); |
| 9 | 17 | } |
| 10 | 18 | \ No newline at end of file | ... | ... |
app/src/main/java/com/cnlive/gundam/main/ui/activity/MainActivity.java
| 1 | 1 | package com.cnlive.gundam.main.ui.activity; |
| 2 | 2 | |
| 3 | 3 | import android.app.AlertDialog; |
| 4 | -import android.app.Dialog; | |
| 5 | 4 | import android.content.DialogInterface; |
| 6 | 5 | import android.content.Intent; |
| 7 | 6 | import android.databinding.DataBindingUtil; |
| ... | ... | @@ -18,10 +17,10 @@ import com.cnlive.gundam.main.ui.fragment.HomeFragment; |
| 18 | 17 | import com.cnlive.gundam.main.ui.fragment.LiveFragment; |
| 19 | 18 | import com.cnlive.gundam.main.ui.fragment.UGCListFragment; |
| 20 | 19 | import com.cnlive.gundam.main.ui.widget.FragmentTabHost; |
| 20 | +import com.cnlive.gundam.stream.model.ChannelInfoModel; | |
| 21 | 21 | import com.cnlive.gundam.stream.ui.activity.StreamActivity; |
| 22 | 22 | import com.cnlive.gundam.user.activity.LoginActivity; |
| 23 | 23 | import com.cnlive.gundam.user.auth.UserService; |
| 24 | -import com.cnlive.gundam.user.model.ChannelInfoModel; | |
| 25 | 24 | import com.cnlive.gundam.user.model.User; |
| 26 | 25 | import com.cnlive.libs.util.Config; |
| 27 | 26 | |
| ... | ... | @@ -33,8 +32,6 @@ import java.util.Arrays; |
| 33 | 32 | |
| 34 | 33 | public class MainActivity extends AppCompatActivity implements FragmentTabHost.OnSetCurrentTabListener, AnchorInfoView { |
| 35 | 34 | |
| 36 | - private Dialog verifiedDialog; | |
| 37 | - | |
| 38 | 35 | private AnchorInfoPresenter mAnchorInfoPresenter; |
| 39 | 36 | |
| 40 | 37 | @Override |
| ... | ... | @@ -78,8 +75,8 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O |
| 78 | 75 | |
| 79 | 76 | |
| 80 | 77 | @Override |
| 81 | - public void onAnchorInfo(ChannelInfoModel model) { | |
| 82 | - switch (model.getData().getStatus()) { | |
| 78 | + public void onAnchorInfo(ChannelInfoModel info) { | |
| 79 | + switch (info.getData().getStatus()) { | |
| 83 | 80 | case -1: |
| 84 | 81 | Toast.makeText(this, "主播不存在", Toast.LENGTH_SHORT).show(); |
| 85 | 82 | showVerifiedDialog(); |
| ... | ... | @@ -92,11 +89,7 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O |
| 92 | 89 | break; |
| 93 | 90 | case 3: |
| 94 | 91 | Toast.makeText(this, "开启直播", Toast.LENGTH_SHORT).show(); |
| 95 | - String activityId = System.currentTimeMillis() + ""; | |
| 96 | - String channelId = model.getData().getChannelId(); | |
| 97 | - String channelName = model.getData().getChannelName(); | |
| 98 | - String coverImgUrl = model.getData().getCoverImgUrl(); | |
| 99 | - StreamActivity.start(this, activityId, channelId, channelName, coverImgUrl, false); | |
| 92 | + startStreamActivity(info); | |
| 100 | 93 | break; |
| 101 | 94 | case 4: |
| 102 | 95 | Toast.makeText(this, "主播被禁用", Toast.LENGTH_SHORT).show(); |
| ... | ... | @@ -106,18 +99,33 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O |
| 106 | 99 | |
| 107 | 100 | @Override |
| 108 | 101 | public void getAnchorFailure() { |
| 109 | - Toast.makeText(this, getString(R.string.request_state_error), Toast.LENGTH_LONG).show(); | |
| 102 | + Toast.makeText(this, "主播信息认证失败", Toast.LENGTH_LONG).show(); | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * 开启直播推流页面 | |
| 107 | + * @param info 主播信息 | |
| 108 | + */ | |
| 109 | + private void startStreamActivity(ChannelInfoModel info) { | |
| 110 | + String activityId = System.currentTimeMillis() + ""; | |
| 111 | + String channelId = info.getData().getChannelId(); | |
| 112 | + String channelName = info.getData().getChannelName(); | |
| 113 | + String coverImgUrl = info.getData().getCoverImgUrl(); | |
| 114 | + StreamActivity.start(this, activityId, channelId, channelName, coverImgUrl, false); | |
| 110 | 115 | } |
| 111 | 116 | |
| 117 | + /** | |
| 118 | + * 显示主播申请页面 | |
| 119 | + */ | |
| 112 | 120 | private void showVerifiedDialog() { |
| 113 | - verifiedDialog = new AlertDialog.Builder(this) | |
| 121 | + new AlertDialog.Builder(this) | |
| 114 | 122 | .setMessage("亲,完成实名认证就可以开播啦,现在就去认证吧?") |
| 115 | 123 | .setPositiveButton("去认证", new DialogInterface.OnClickListener() { |
| 116 | 124 | @Override |
| 117 | 125 | public void onClick(DialogInterface dialogInterface, int i) { |
| 118 | - verifiedDialog.dismiss(); | |
| 126 | + dialogInterface.dismiss(); | |
| 119 | 127 | String channelId = UserService.getInstance(MainActivity.this).getActiveAccountInfo().getUid() + ""; |
| 120 | - String url = String.format(getString(R.string.verified_url), channelId, Config.getAppId()); | |
| 128 | + String url = String.format(getString(Config.debug ? R.string.debug_verified_url : R.string.verified_url), channelId, Config.getAppId()); | |
| 121 | 129 | Intent intent = new Intent(MainActivity.this, WebViewActivity.class); |
| 122 | 130 | intent.putExtra("url", url); |
| 123 | 131 | intent.putExtra("title", "主播认证"); |
| ... | ... | @@ -127,9 +135,8 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O |
| 127 | 135 | .setNegativeButton("取消", new DialogInterface.OnClickListener() { |
| 128 | 136 | @Override |
| 129 | 137 | public void onClick(DialogInterface dialogInterface, int i) { |
| 130 | - verifiedDialog.dismiss(); | |
| 138 | + dialogInterface.dismiss(); | |
| 131 | 139 | } |
| 132 | - }) | |
| 133 | - .show(); | |
| 140 | + }).show(); | |
| 134 | 141 | } |
| 135 | 142 | } |
| 136 | 143 | \ No newline at end of file | ... | ... |
app/src/main/java/com/cnlive/gundam/main/ui/widget/FragmentTabHost.java
| ... | ... | @@ -30,7 +30,6 @@ public class FragmentTabHost extends TabHost |
| 30 | 30 | implements TabHost.OnTabChangeListener { |
| 31 | 31 | private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); |
| 32 | 32 | private FrameLayout mRealTabContent; |
| 33 | - private Context mContext; | |
| 34 | 33 | private FragmentManager mFragmentManager; |
| 35 | 34 | private int mContainerId; |
| 36 | 35 | private OnSetCurrentTabListener onSetCurrentTabListener; |
| ... | ... | @@ -45,7 +44,7 @@ public class FragmentTabHost extends TabHost |
| 45 | 44 | boolean onSetCurrentTab(String tag); |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | - public static final class TabItemInfo{ | |
| 47 | + public static final class TabItemInfo { | |
| 49 | 48 | private final String tag; |
| 50 | 49 | private final int layoutId; |
| 51 | 50 | private final Class<?> clss; |
| ... | ... | @@ -145,14 +144,14 @@ public class FragmentTabHost extends TabHost |
| 145 | 144 | a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.inflatedId}, 0, 0); |
| 146 | 145 | try { |
| 147 | 146 | mContainerId = a.getResourceId(0, 0); |
| 148 | - }finally { | |
| 147 | + } finally { | |
| 149 | 148 | a.recycle(); |
| 150 | 149 | } |
| 151 | 150 | |
| 152 | 151 | a = context.obtainStyledAttributes(attrs, R.styleable.FragmentTabHost); |
| 153 | 152 | try { |
| 154 | 153 | mDiciderDrawable = a.getDrawable(R.styleable.FragmentTabHost_dividerDrawable); |
| 155 | - }finally { | |
| 154 | + } finally { | |
| 156 | 155 | a.recycle(); |
| 157 | 156 | } |
| 158 | 157 | super.setOnTabChangedListener(this); |
| ... | ... | @@ -188,8 +187,8 @@ public class FragmentTabHost extends TabHost |
| 188 | 187 | |
| 189 | 188 | /** |
| 190 | 189 | * @deprecated Don't call the original TabHost setup, you must instead |
| 191 | - * call {@link #setup(Context, FragmentManager)} or | |
| 192 | - * {@link #setup(Context, FragmentManager, int)}. | |
| 190 | + * call {@link #setup( FragmentManager)} or | |
| 191 | + * {@link #setup( FragmentManager, int)}. | |
| 193 | 192 | */ |
| 194 | 193 | @Override |
| 195 | 194 | @Deprecated |
| ... | ... | @@ -198,19 +197,17 @@ public class FragmentTabHost extends TabHost |
| 198 | 197 | "Must call setup() that takes a Context and FragmentManager"); |
| 199 | 198 | } |
| 200 | 199 | |
| 201 | - public void setup(Context context, FragmentManager manager) { | |
| 202 | - ensureHierarchy(context); // Ensure views required by super.setup() | |
| 200 | + public void setup(FragmentManager manager) { | |
| 201 | + ensureHierarchy(getContext()); // Ensure views required by super.setup() | |
| 203 | 202 | super.setup(); |
| 204 | - mContext = context; | |
| 205 | 203 | mFragmentManager = manager; |
| 206 | 204 | ensureContent(); |
| 207 | 205 | setDividerDrawable(mDiciderDrawable); |
| 208 | 206 | } |
| 209 | 207 | |
| 210 | - public void setup(Context context, FragmentManager manager, int containerId) { | |
| 211 | - ensureHierarchy(context); // Ensure views required by super.setup() | |
| 208 | + public void setup(FragmentManager manager, int containerId) { | |
| 209 | + ensureHierarchy(getContext()); // Ensure views required by super.setup() | |
| 212 | 210 | super.setup(); |
| 213 | - mContext = context; | |
| 214 | 211 | mFragmentManager = manager; |
| 215 | 212 | mContainerId = containerId; |
| 216 | 213 | ensureContent(); |
| ... | ... | @@ -226,15 +223,17 @@ public class FragmentTabHost extends TabHost |
| 226 | 223 | |
| 227 | 224 | /** |
| 228 | 225 | * 设置内容ID并初始化 |
| 226 | + * | |
| 229 | 227 | * @param contentId 展示内容的Layout ID |
| 230 | 228 | */ |
| 231 | - public void setContentId(int contentId){ | |
| 232 | - FragmentActivity activity = ((FragmentActivity)getContext()); | |
| 233 | - setup(activity, activity.getSupportFragmentManager(), contentId); | |
| 229 | + public void setContentId(int contentId) { | |
| 230 | + FragmentActivity activity = ((FragmentActivity) getContext()); | |
| 231 | + setup(activity.getSupportFragmentManager(), contentId); | |
| 234 | 232 | } |
| 235 | 233 | |
| 236 | 234 | /** |
| 237 | 235 | * 添加标签内容信息 |
| 236 | + * | |
| 238 | 237 | * @param list |
| 239 | 238 | */ |
| 240 | 239 | public void setTabItemList(List<TabItemInfo> list) { |
| ... | ... | @@ -257,7 +256,7 @@ public class FragmentTabHost extends TabHost |
| 257 | 256 | } |
| 258 | 257 | |
| 259 | 258 | public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) { |
| 260 | - tabSpec.setContent(new DummyTabFactory(mContext)); | |
| 259 | + tabSpec.setContent(new DummyTabFactory(getContext())); | |
| 261 | 260 | String tag = tabSpec.getTag(); |
| 262 | 261 | |
| 263 | 262 | TabInfo info = new TabInfo(tag, clss, args); |
| ... | ... | @@ -391,7 +390,7 @@ public class FragmentTabHost extends TabHost |
| 391 | 390 | this.onSetCurrentTabListener = onSetCurrentTabListener; |
| 392 | 391 | } |
| 393 | 392 | |
| 394 | - public void setDividerDrawable(@Nullable Drawable drawable){ | |
| 393 | + public void setDividerDrawable(@Nullable Drawable drawable) { | |
| 395 | 394 | getTabWidget().setDividerDrawable(drawable); |
| 396 | 395 | } |
| 397 | 396 | |
| ... | ... | @@ -417,7 +416,7 @@ public class FragmentTabHost extends TabHost |
| 417 | 416 | } |
| 418 | 417 | if (newTab != null) { |
| 419 | 418 | if (newTab.fragment == null) { |
| 420 | - newTab.fragment = Fragment.instantiate(mContext, | |
| 419 | + newTab.fragment = Fragment.instantiate(getContext(), | |
| 421 | 420 | newTab.clss.getName(), newTab.args); |
| 422 | 421 | ft.add(mContainerId, newTab.fragment, newTab.tag); |
| 423 | 422 | } else { | ... | ... |
app/src/main/java/com/cnlive/gundam/user/model/ChannelInfoModel.java renamed to app/src/main/java/com/cnlive/gundam/stream/model/ChannelInfoModel.java
app/src/main/java/com/cnlive/gundam/video/adpter/CommonAdapter.java
| 1 | 1 | package com.cnlive.gundam.video.adpter; |
| 2 | 2 | |
| 3 | -import android.content.Context; | |
| 4 | 3 | import android.databinding.DataBindingUtil; |
| 5 | 4 | import android.databinding.ViewDataBinding; |
| 6 | 5 | import android.view.LayoutInflater; |
| ... | ... | @@ -20,13 +19,11 @@ import java.util.List; |
| 20 | 19 | * @desc ${TODD} |
| 21 | 20 | */ |
| 22 | 21 | public class CommonAdapter<T> extends BaseAdapter { |
| 23 | - private Context mContext; | |
| 24 | 22 | private List<T> mDataList; |
| 25 | 23 | private int layoutId; // 条目布局ID |
| 26 | 24 | private int variableId; // DataBinding的变量ID,可通过类似R文件的BR文件来获取 |
| 27 | 25 | |
| 28 | - public CommonAdapter(Context context, List<T> dataList, int layoutId, int variableId) { | |
| 29 | - this.mContext = context; | |
| 26 | + public CommonAdapter(List<T> dataList, int layoutId, int variableId) { | |
| 30 | 27 | this.mDataList = dataList; |
| 31 | 28 | this.layoutId = layoutId; |
| 32 | 29 | this.variableId = variableId; |
| ... | ... | @@ -52,7 +49,7 @@ public class CommonAdapter<T> extends BaseAdapter { |
| 52 | 49 | |
| 53 | 50 | ViewDataBinding binding; |
| 54 | 51 | if (convertView == null) { |
| 55 | - binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), layoutId, parent, false); | |
| 52 | + binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), layoutId, parent, false); | |
| 56 | 53 | } else { |
| 57 | 54 | binding = DataBindingUtil.getBinding(convertView); |
| 58 | 55 | } | ... | ... |
app/src/main/java/com/cnlive/gundam/video/adpter/GiftAdapter.java
| 1 | 1 | package com.cnlive.gundam.video.adpter; |
| 2 | 2 | |
| 3 | -import android.content.Context; | |
| 4 | 3 | import android.databinding.DataBindingUtil; |
| 5 | 4 | import android.databinding.ViewDataBinding; |
| 6 | 5 | import android.support.v7.widget.RecyclerView; |
| ... | ... | @@ -19,24 +18,20 @@ import java.util.List; |
| 19 | 18 | */ |
| 20 | 19 | |
| 21 | 20 | public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> { |
| 22 | - private Context mContext; | |
| 23 | 21 | private List<GiftModle> mDataList; |
| 24 | 22 | private int mLayoutId; // 条目布局文件ID |
| 25 | 23 | private int mVariableId; // DataBinding变量ID |
| 26 | 24 | |
| 27 | - public GiftAdapter(Context context, List<GiftModle> list, int layoutId, int variableId) { | |
| 28 | - this.mContext = context; | |
| 25 | + public GiftAdapter(List<GiftModle> list, int layoutId, int variableId) { | |
| 29 | 26 | this.mDataList = list; |
| 30 | 27 | this.mLayoutId = layoutId; |
| 31 | 28 | mVariableId = variableId; |
| 32 | - | |
| 33 | - | |
| 34 | 29 | } |
| 35 | 30 | |
| 36 | 31 | |
| 37 | 32 | @Override |
| 38 | 33 | public RVHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 39 | - ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), mLayoutId, parent, false); | |
| 34 | + ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), mLayoutId, parent, false); | |
| 40 | 35 | RVHolder holder = new RVHolder(binding.getRoot()); |
| 41 | 36 | holder.binding = binding; |
| 42 | 37 | return holder; | ... | ... |
app/src/main/java/com/cnlive/gundam/video/fragment/chat/ChatRoomFragment.java
| ... | ... | @@ -88,6 +88,13 @@ public class ChatRoomFragment extends Fragment implements View.OnClickListener { |
| 88 | 88 | initChat(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | + @Override | |
| 92 | + public void onDestroyView() { | |
| 93 | + super.onDestroyView(); | |
| 94 | + onSendMessageListener = null; | |
| 95 | + onConnectListener = null; | |
| 96 | + } | |
| 97 | + | |
| 91 | 98 | private void initDate() { |
| 92 | 99 | int[] imaSource = new int[]{R.drawable.porsch_small80, R.drawable.fighter_small80, |
| 93 | 100 | R.drawable.plane_small80, |
| ... | ... | @@ -112,7 +119,7 @@ public class ChatRoomFragment extends Fragment implements View.OnClickListener { |
| 112 | 119 | private void initMessageAdapter() { |
| 113 | 120 | messageContentArrayList = new ArrayList<>(); |
| 114 | 121 | if (messageContentCommonAdapter == null) |
| 115 | - messageContentCommonAdapter = new CommonAdapter<>(getActivity(), messageContentArrayList, R.layout.item_list_right, BR.user); | |
| 122 | + messageContentCommonAdapter = new CommonAdapter<>(messageContentArrayList, R.layout.item_list_right, BR.user); | |
| 116 | 123 | } |
| 117 | 124 | |
| 118 | 125 | private void initGiftAdapter() { |
| ... | ... | @@ -120,7 +127,7 @@ public class ChatRoomFragment extends Fragment implements View.OnClickListener { |
| 120 | 127 | GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2); |
| 121 | 128 | gridLayoutManager.setOrientation(OrientationHelper.HORIZONTAL); |
| 122 | 129 | fragmentChatBinding.recyclerGift.setLayoutManager(gridLayoutManager); |
| 123 | - fragmentChatBinding.setGiftAdapter(new GiftAdapter(getActivity(), giftArray, R.layout.fragment_gift_receycel, BR.dataBean)); | |
| 130 | + fragmentChatBinding.setGiftAdapter(new GiftAdapter(giftArray, R.layout.fragment_gift_receycel, BR.dataBean)); | |
| 124 | 131 | } |
| 125 | 132 | |
| 126 | 133 | ... | ... |
app/src/main/java/com/cnlive/gundam/video/view/BaseVideoView.java
| ... | ... | @@ -30,7 +30,6 @@ public abstract class BaseVideoView extends RelativeLayout implements |
| 30 | 30 | IMediaPlayer.OnBufferingUpdateListener, ISwitchVideoView.OnSwitchVideoPreparedListener, |
| 31 | 31 | ISwitchVideoView.OnSwitchVideoErrorListener, ISwitchVideoView.OnSwitchVideoCompleteListener { |
| 32 | 32 | |
| 33 | - protected Context mContext; | |
| 34 | 33 | protected LayoutVideoViewBinding binding; |
| 35 | 34 | |
| 36 | 35 | //记录当前视频播放状态 |
| ... | ... | @@ -71,7 +70,6 @@ public abstract class BaseVideoView extends RelativeLayout implements |
| 71 | 70 | |
| 72 | 71 | public BaseVideoView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 73 | 72 | super(context, attrs, defStyleAttr); |
| 74 | - this.mContext = context; | |
| 75 | 73 | init(); |
| 76 | 74 | } |
| 77 | 75 | |
| ... | ... | @@ -81,7 +79,7 @@ public abstract class BaseVideoView extends RelativeLayout implements |
| 81 | 79 | |
| 82 | 80 | protected void init() { |
| 83 | 81 | sharedPreferencesHelper = SharedPreferencesHelper.getInstance(getContext()); |
| 84 | - binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.layout_video_view, this, true); | |
| 82 | + binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.layout_video_view, this, true); | |
| 85 | 83 | binding.videoView.setOnPreparedListener(this); |
| 86 | 84 | binding.videoView.setOnInfoListener(this); |
| 87 | 85 | binding.videoView.setOnErrorListener(this); |
| ... | ... | @@ -138,6 +136,7 @@ public abstract class BaseVideoView extends RelativeLayout implements |
| 138 | 136 | } |
| 139 | 137 | |
| 140 | 138 | public void onDestroy() { |
| 139 | + binding.videoView.releaseSwitchVideo(); | |
| 141 | 140 | binding.videoView.release(); |
| 142 | 141 | VideoStatusUtil.quit(); |
| 143 | 142 | saveCurPlayPosition(); |
| ... | ... | @@ -290,13 +289,13 @@ public abstract class BaseVideoView extends RelativeLayout implements |
| 290 | 289 | //主播暂时离开 |
| 291 | 290 | canPlay = false; |
| 292 | 291 | binding.videoView.stop(); |
| 293 | - binding.infoView.show(PlayerInfoView.SHOW_UGC_LIVE_STATUS, mContext.getString(R.string.player_status_leave)); | |
| 292 | + binding.infoView.show(PlayerInfoView.SHOW_UGC_LIVE_STATUS, getContext().getString(R.string.player_status_leave)); | |
| 294 | 293 | break; |
| 295 | 294 | case IVideoStatus.MEDIA_STATUS_END: |
| 296 | 295 | //直播结束 |
| 297 | 296 | canPlay = false; |
| 298 | 297 | binding.videoView.stop(); |
| 299 | - binding.infoView.show(PlayerInfoView.SHOW_UGC_LIVE_STATUS, mContext.getString(R.string.player_status_end)); | |
| 298 | + binding.infoView.show(PlayerInfoView.SHOW_UGC_LIVE_STATUS, getContext().getString(R.string.player_status_end)); | |
| 300 | 299 | break; |
| 301 | 300 | } |
| 302 | 301 | ... | ... |
app/src/main/java/com/cnlive/gundam/video/view/PlayerInfoView.java
| ... | ... | @@ -45,9 +45,6 @@ public class PlayerInfoView extends RelativeLayout { |
| 45 | 45 | //展示手机网视图 |
| 46 | 46 | public static final int SHOW_MOBILE_NET = 0x2007; |
| 47 | 47 | |
| 48 | - private Context mContext; | |
| 49 | - | |
| 50 | - private ViewDataBinding binding; | |
| 51 | 48 | |
| 52 | 49 | //存储展示哪个视图 |
| 53 | 50 | private ObservableInt observableShowType; |
| ... | ... | @@ -76,7 +73,6 @@ public class PlayerInfoView extends RelativeLayout { |
| 76 | 73 | |
| 77 | 74 | public PlayerInfoView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 78 | 75 | super(context, attrs, defStyleAttr); |
| 79 | - mContext = context; | |
| 80 | 76 | init(); |
| 81 | 77 | } |
| 82 | 78 | |
| ... | ... | @@ -96,7 +92,7 @@ public class PlayerInfoView extends RelativeLayout { |
| 96 | 92 | public void setInfoViewLayout(int infoType) { |
| 97 | 93 | switch (infoType) { |
| 98 | 94 | case VIDEO_INFO_NORMAL: |
| 99 | - binding = DataBindingUtil.bind(getView(R.layout.layout_player_info)); | |
| 95 | + ViewDataBinding binding = DataBindingUtil.bind(getView(R.layout.layout_player_info)); | |
| 100 | 96 | binding.setVariable(BR.playerInfoView, this); |
| 101 | 97 | binding.setVariable(BR.showType, observableShowType); |
| 102 | 98 | binding.setVariable(BR.isNews, observableIsNews); |
| ... | ... | @@ -122,7 +118,7 @@ public class PlayerInfoView extends RelativeLayout { |
| 122 | 118 | |
| 123 | 119 | //获取对应布局的视图 |
| 124 | 120 | private View getView(int layout) { |
| 125 | - View view = LayoutInflater.from(mContext).inflate(layout, null, false); | |
| 121 | + View view = LayoutInflater.from(getContext()).inflate(layout, null, false); | |
| 126 | 122 | if (getChildCount() > 0) |
| 127 | 123 | removeAllViews(); |
| 128 | 124 | addView(view); |
| ... | ... | @@ -169,9 +165,9 @@ public class PlayerInfoView extends RelativeLayout { |
| 169 | 165 | break; |
| 170 | 166 | case R.id.back: |
| 171 | 167 | if (!PlayerUtils.isPortrait(getContext()) && !isUgc) { |
| 172 | - ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | |
| 168 | + ((Activity) getContext()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | |
| 173 | 169 | } else { |
| 174 | - ((Activity) mContext).onBackPressed(); | |
| 170 | + ((Activity) getContext()).onBackPressed(); | |
| 175 | 171 | } |
| 176 | 172 | break; |
| 177 | 173 | case R.id.playByMobileNet: | ... | ... |
app/src/main/java/com/cnlive/gundam/video/view/PlayerTouchView.java
| ... | ... | @@ -29,7 +29,6 @@ import com.cnlive.gundam.video.utils.PlayerUtils; |
| 29 | 29 | |
| 30 | 30 | public class PlayerTouchView extends RelativeLayout { |
| 31 | 31 | private VideoTouchListener l; |
| 32 | - private static Context mContext; | |
| 33 | 32 | |
| 34 | 33 | //点下时的x坐标 |
| 35 | 34 | private int downX; |
| ... | ... | @@ -76,7 +75,6 @@ public class PlayerTouchView extends RelativeLayout { |
| 76 | 75 | |
| 77 | 76 | public PlayerTouchView(Context context, AttributeSet attrs, int defStyle) { |
| 78 | 77 | super(context, attrs, defStyle); |
| 79 | - this.mContext = context; | |
| 80 | 78 | audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| 81 | 79 | binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.layout_player_touch, this, true); |
| 82 | 80 | binding.setLeftAreaMove(leftArea); |
| ... | ... | @@ -104,11 +102,11 @@ public class PlayerTouchView extends RelativeLayout { |
| 104 | 102 | if (downX < controlAreaWidth) { |
| 105 | 103 | if (preVolume == -1) |
| 106 | 104 | preVolume = getSystemVolume(); |
| 107 | - brightnessAndVolumeProgress.set(preVolume * DensityUtils.dp2px(mContext, 93) / getSystemMaxVolume()); | |
| 105 | + brightnessAndVolumeProgress.set(preVolume * DensityUtils.dp2px(getContext(), 93) / getSystemMaxVolume()); | |
| 108 | 106 | } else if (downX > getWidth() - controlAreaWidth) { |
| 109 | 107 | if (preBrightness == -1) |
| 110 | 108 | preBrightness = getSystemBrightness(); |
| 111 | - brightnessAndVolumeProgress.set(preBrightness * DensityUtils.dp2px(mContext, 93) / 255); | |
| 109 | + brightnessAndVolumeProgress.set(preBrightness * DensityUtils.dp2px(getContext(), 93) / 255); | |
| 112 | 110 | } |
| 113 | 111 | curBrightnessProgress = -1; |
| 114 | 112 | curVolumeProgress = -1; |
| ... | ... | @@ -190,7 +188,7 @@ public class PlayerTouchView extends RelativeLayout { |
| 190 | 188 | int curBrightness = PlayerUtils.checkSize(preBrightness + moveY * 255 / getHeight(), 1, 255); |
| 191 | 189 | if (curBrightnessProgress == curBrightness) return; |
| 192 | 190 | |
| 193 | - int progress = curBrightness * DensityUtils.dp2px(mContext, 93) / 255; | |
| 191 | + int progress = curBrightness * DensityUtils.dp2px(getContext(), 93) / 255; | |
| 194 | 192 | brightnessAndVolumeProgress.set(progress); |
| 195 | 193 | |
| 196 | 194 | curBrightnessProgress = curBrightness; |
| ... | ... | @@ -237,7 +235,7 @@ public class PlayerTouchView extends RelativeLayout { |
| 237 | 235 | int curVolume = PlayerUtils.checkSize(preVolume + (moveY * getSystemMaxVolume() / getHeight()), 0, getSystemMaxVolume()); |
| 238 | 236 | if (curVolumeProgress == curVolume) return; |
| 239 | 237 | |
| 240 | - int progress = curVolume * DensityUtils.dp2px(mContext, 93) / getSystemMaxVolume(); | |
| 238 | + int progress = curVolume * DensityUtils.dp2px(getContext(), 93) / getSystemMaxVolume(); | |
| 241 | 239 | brightnessAndVolumeProgress.set(progress); |
| 242 | 240 | |
| 243 | 241 | curVolumeProgress = curVolume; | ... | ... |
app/src/main/java/com/cnlive/gundam/video/view/VideoView.java
| ... | ... | @@ -109,7 +109,7 @@ public class VideoView extends BaseVideoView implements PlayerTouchView.VideoTou |
| 109 | 109 | observableIsUgc = new ObservableBoolean(); |
| 110 | 110 | observableVideoHeight = new ObservableInt(); |
| 111 | 111 | observableVideoWidth = new ObservableInt(); |
| 112 | - observableVideoHeight.set((int) mContext.getResources().getDimension(R.dimen.videoPortraitHeight)); | |
| 112 | + observableVideoHeight.set((int) getContext().getResources().getDimension(R.dimen.videoPortraitHeight)); | |
| 113 | 113 | observableVideoWidth.set(ViewGroup.LayoutParams.MATCH_PARENT); |
| 114 | 114 | observableIsPortrait.set(PlayerUtils.isPortrait(getContext())); |
| 115 | 115 | binding.setVideoPortraitHeight(observableVideoHeight); | ... | ... |
app/src/main/res/values/strings.xml
| ... | ... | @@ -36,6 +36,7 @@ |
| 36 | 36 | <string name="request_null">暂无数据</string> |
| 37 | 37 | <string name="request_state_error">获取活动状态失败</string> |
| 38 | 38 | <string name="request_state_play_error">此活动状态无法播放</string> |
| 39 | - <string name="verified_url" formatted="false">https://mobile.cnlive.com/CnliveMobile/web/review/review.jsp?sid=%s&plat=a&appId=%s </string> | |
| 40 | 39 | |
| 40 | + <string name="verified_url" formatted="false">https://mobile.cnlive.com/CnliveMobile/web/review/review.jsp?sid=%s&plat=a&appId=%s </string> | |
| 41 | + <string name="debug_verified_url" formatted="false">https://mobile.cnlive.com/CnliveMobile/web/review/review.jsp?sid=%s&plat=a&appId=%s&type=0 </string> | |
| 41 | 42 | </resources> | ... | ... |