一款使用RxJava+Retrofit+MVP的快播App開源啦!

《快播》,仿網易雲音樂UI,總體採用RxJava+Retrofit+MVP的架構,支持在線視頻播放,在線圖片瀏覽等功能。android

用到第三方開源庫:git

  • ButterKnife:依賴注入框架
  • glide:圖片加載
  • retrofit:網絡請求
  • jieCaoVideoPlayer:播放器

抓取接口用於數據展現github

效果圖以下:






基類:bash

package com.zmj.qvod.base;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public abstract class BaseActivity extends AppCompatActivity {


    /**
     * 是否沉浸狀態欄
     **/
    private boolean isSetStatusBar = false;
    /**
     * 是否容許全屏
     **/
    private boolean mAllowFullScreen = false;
    /**
     * 是否容許屏幕旋轉
     **/
    private boolean isAllowScreenRotate = false;
    /**
     * 當前Activity渲染的視圖View
     **/
    private View mContextView = null;
    /**
     * 日誌輸出標誌
     **/
    protected final String TAG = this.getClass().getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "BaseActivity-->onCreate()");
        Bundle bundle = getIntent().getExtras();
        initPrams(bundle);
        //
        mContextView = LayoutInflater.from(this).inflate(bindLayout(), null);
        //
        if (mAllowFullScreen) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
        }
        //
        if (isSetStatusBar) {
            steepStatusBar();
        }
        //
        setContentView(bindLayout());
        //
        if (!isAllowScreenRotate) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        //
        initView(mContextView);
        //
        setListener();
        //
        doBusiness(this);
    }

    /**
     * [沉浸狀態欄]
     */
    private void steepStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // 透明狀態欄
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 透明導航欄
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

    }

    /**
     * [初始化參數--加載xml視圖以前]
     *
     * @param bundle
     */
    public abstract void initPrams(Bundle bundle);

    /**
     * [綁定佈局]
     *
     * @return
     */
    public abstract int bindLayout();

    /**
     * [初始化控件]
     *
     * @param view
     */
    public abstract void initView(final View view);

    /**
     * [綁定控件]
     *
     * @param resId
     * @return
     */
    protected <T extends View> T $(int resId) {
        return (T) super.findViewById(resId);
    }

    /**
     * [設置監聽]
     */
    public abstract void setListener();

    /**
     * [業務操做]
     *
     * @param mContext
     */
    public abstract void doBusiness(Context mContext);


    /**
     * [頁面跳轉]
     *
     * @param clz
     */
    public void startActivity(Class<?> clz) {
        startActivity(new Intent(BaseActivity.this, clz));
    }

    /**
     * [攜帶數據的頁面跳轉]
     *
     * @param clz
     * @param bundle
     */
    public void startActivity(Class<?> clz, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(this, clz);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    /**
     * [含有Bundle經過Class打開編輯界面]
     *
     * @param cls
     * @param bundle
     * @param requestCode
     */
    public void startActivityForResult(Class<?> cls, Bundle bundle,
                                       int requestCode) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivityForResult(intent, requestCode);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart()");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart()");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause()");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy()");
    }

    /**
     * [簡化Toast]
     *
     * @param msg
     */
    protected void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * [簡化Toast]
     *
     * @param msg
     */
    protected void showToast(int msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * [是否容許全屏]
     *
     * @param allowFullScreen
     */
    public void setAllowFullScreen(boolean allowFullScreen) {
        this.mAllowFullScreen = allowFullScreen;
    }

    /**
     * [是否設置沉浸狀態欄]
     *
     * @param isSetStatusBar
     */
    public void setSteepStatusBar(boolean isSetStatusBar) {
        this.isSetStatusBar = isSetStatusBar;
    }

    /**
     * [是否容許屏幕旋轉]
     *
     * @param isAllowScreenRotate
     */
    public void setScreenRoate(boolean isAllowScreenRotate) {
        this.isAllowScreenRotate = isAllowScreenRotate;
    }

}
複製代碼

做者:zhaomingjian;Github開源地址:https://github.com/zhao-mingjian/qvod

歡迎關注個人微信公衆號「碼農突圍」,分享Python、Java、大數據、機器學習、人工智能等技術,關注碼農技術提高•職場突圍•思惟躍遷,20萬+碼農成長充電第一站,陪有夢想的你一塊兒成長。微信

相關文章
相關標籤/搜索