android快速開發(fā)框架--附帶MVP模式Demo,網(wǎng)絡(luò)請(qǐng)求及緩存,快速實(shí)現(xiàn) 頁面 加載中 加載失敗 無數(shù)據(jù)等狀態(tài)以及下拉刷新和自動(dòng)加載

RapidDevelop-Android快速開發(fā)框架


功能說明

  • retrofit rxjava okhttp rxcache------------------------------網(wǎng)絡(luò)請(qǐng)求以及網(wǎng)絡(luò)緩存
  • Demo采用MVP模式開發(fā)------------------------------------數(shù)據(jù)邏輯復(fù)用,便于維護(hù)升級(jí)
  • 下拉刷新 上拉加載 及自動(dòng)加載---------------------------實(shí)現(xiàn)監(jiān)聽方便快捷
  • RecyclerView設(shè)配器------------------------------------------再也不需要寫ViewHolder
  • RecyclerView item加載動(dòng)畫--------------------------------多種動(dòng)畫效果一行代碼解決
  • 頁面狀態(tài)統(tǒng)一管理 加載中 無數(shù)據(jù) 無網(wǎng)絡(luò)-------------所有頁面均可添加
  • 圖片顯示與緩存 GIF圖片顯示
  • Tab+Fragment快速實(shí)現(xiàn)
  • 視頻播放(仿QQ空間,秒拍等List播放)

效果圖展示

下拉刷新

item動(dòng)畫

grid顯示

多布局顯示

視頻播放
狀態(tài)頁面

使用說明

導(dǎo)入 lcrapiddeveloplibrary 到項(xiàng)目

在 build.gradle 的 dependencies 添加:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
....
compile project(':lcrapiddeveloplibrary')
}

輕松實(shí)現(xiàn) 狀態(tài)頁面 下拉刷新 自動(dòng)加載 item動(dòng)畫

首先layout.xml里面的編寫啦 列表頁面基本都是這個(gè)套路

<!--ProgressActivity用于狀態(tài)頁的控制 比如加載中  網(wǎng)絡(luò)異常  無數(shù)據(jù)  適合任何頁面-->
<com.xiaochao.lcrapiddeveloplibrary.viewtype.ProgressActivity
    xmlns:progressActivity="http://schemas.android.com/apk/res-auto"
    android:id="@+id/progress"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <!--SpringView下拉刷新-->
        <com.xiaochao.lcrapiddeveloplibrary.widget.SpringView
            android:id="@+id/springview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF"
            >
            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#eeeeee"/>
        </com.xiaochao.lcrapiddeveloplibrary.widget.SpringView>

    </LinearLayout>
</com.xiaochao.lcrapiddeveloplibrary.viewtype.ProgressActivity>

然后就是Activity里面的編寫了 這個(gè)例子里使用MVP模式編寫感興趣的看我最新寫的Freebook

public class ListvViewActivity extends AppCompatActivity implements BaseQuickAdapter.RequestLoadMoreListener,SpringView.OnFreshListener,SchoolListView {

    RecyclerView mRecyclerView;
    ProgressActivity progress;
    private Toolbar toolbar;
    private BaseQuickAdapter mQuickAdapter;
    private int PageIndex=1;
    private SpringView springView;
    private SchoolListPresent present;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listv_view);
        initView();
    }


    private void initView() {
        present = new SchoolListPresent(this);
        mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
        springView = (SpringView) findViewById(R.id.springview);
        //設(shè)置下拉刷新監(jiān)聽
        springView.setListener(this);
        //設(shè)置下拉刷新樣式
        springView.setHeader(new RotationHeader(this));
        //springView.setFooter(new RotationFooter(this));mRecyclerView內(nèi)部集成的自動(dòng)加載  上啦加載用不上   在其他View使用
        progress = (ProgressActivity) findViewById(R.id.progress);
        //設(shè)置RecyclerView的顯示模式  當(dāng)前List模式
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        //如果Item高度固定  增加該屬性能夠提高效率
        mRecyclerView.setHasFixedSize(true);
        //設(shè)置頁面為加載中..
        progress.showLoading();
        //設(shè)置適配器
        mQuickAdapter = new ListViewAdapter(R.layout.list_view_item_layout,null);
        //設(shè)置加載動(dòng)畫
        mQuickAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
        //設(shè)置是否自動(dòng)加載以及加載個(gè)數(shù)
        mQuickAdapter.openLoadMore(6,true);
        //將適配器添加到RecyclerView
        mRecyclerView.setAdapter(mQuickAdapter);
         //設(shè)置自動(dòng)加載監(jiān)聽
        mQuickAdapter.setOnLoadMoreListener(this);
        //請(qǐng)求網(wǎng)絡(luò)數(shù)據(jù)
        present.LoadData(PageIndex,12,false);
    }
   //自動(dòng)加載
    @Override
    public void onLoadMoreRequested() {
        PageIndex++;
        present.LoadData(PageIndex,12,true);
    }
    //下拉刷新
    @Override
    public void onRefresh() {
        PageIndex=1;
        present.LoadData(PageIndex,12,false);
    }
  
    /*
    * MVP模式的相關(guān)狀態(tài)
    *
    * */
    @Override
    public void showProgress() {
        progress.showLoading();
    }

    @Override
    public void hideProgress() {
        progress.showContent();
    }

    @Override
    public void newDatas(List<UniversityListDto> newsList) {
        //進(jìn)入顯示的初始數(shù)據(jù)或者下拉刷新顯示的數(shù)據(jù)
        mQuickAdapter.setNewData(newsList);//新增數(shù)據(jù)
        mQuickAdapter.openLoadMore(10,true);//設(shè)置是否可以下拉加載  以及加載條數(shù)
        springView.onFinishFreshAndLoad();//刷新完成
    }

    @Override
    public void addDatas(List<UniversityListDto> addList) {
        //新增自動(dòng)加載的的數(shù)據(jù)
        mQuickAdapter.notifyDataChangedAfterLoadMore(addList, true);
    }

    @Override
    public void showLoadFailMsg() {
        //設(shè)置加載錯(cuò)誤頁顯示
        progress.showError(getResources().getDrawable(R.mipmap.monkey_cry), Constant.ERROR_TITLE, Constant.ERROR_CONTEXT, Constant.ERROR_BUTTON, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PageIndex=1;
                present.LoadData(PageIndex,12,false);
            }
        });
    }

    @Override
    public void showLoadCompleteAllData() {
        //所有數(shù)據(jù)加載完成后顯示
        mQuickAdapter.notifyDataChangedAfterLoadMore(false);
        View view = getLayoutInflater().inflate(R.layout.not_loading, (ViewGroup) mRecyclerView.getParent(), false);
        mQuickAdapter.addFooterView(view);
    }

    @Override
    public void showNoData() {
        //設(shè)置無數(shù)據(jù)顯示頁面
        progress.showEmpty(getResources().getDrawable(R.mipmap.monkey_cry),Constant.EMPTY_TITLE,Constant.EMPTY_CONTEXT);
    }
}

輕松實(shí)現(xiàn)視頻列表播放

列表部分和上面的一樣就不說了,我這邊主要描敘視頻播放的部分 是在不懂得可以clone到本地倉庫跑一邊

item_layout.xml

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:orientation="vertical">
        <com.xiaochao.lcrapiddeveloplibrary.Video.JCVideoPlayerStandard
            android:id="@+id/video_list_item_playr"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:padding="5dp"
            android:gravity="center_vertical">
            <ImageView
                android:id="@+id/video_list_item_image"
                android:layout_width="100dp"
                android:layout_height="70dp"
                android:src="@mipmap/def_head"/>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="10dp"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/video_list_item_text_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#666666"
                    android:text="標(biāo)題"
                    android:textSize="15dp"/>
                <TextView
                    android:id="@+id/video_list_item_text_context"
                    android:layout_width="wrap_content"
                    android:layout_marginTop="5dp"
                    android:textColor="#999999"
                    android:textSize="13dp"
                    android:text="內(nèi)容"
                    android:lines="3"
                    android:ellipsize="end"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

然后就是adapter里面對(duì)視頻控件的賦值處理

public class VideoLisViewAdapter extends BaseQuickAdapter<VideoListDto> {

    public VideoLisViewAdapter(int layoutResId, List<VideoListDto> data) {
        super(layoutResId, data);
    }

    public VideoLisViewAdapter(List<VideoListDto> data) {
        super(data);
    }

    public VideoLisViewAdapter(View contentView, List<VideoListDto> data) {
        super(contentView, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VideoListDto item) {
        helper.setText(R.id.video_list_item_text_title,item.getTitle()).setText(R.id.video_list_item_text_context,item.getIntroduction());
        //Glide加載圖片  并且支持gif動(dòng)圖
        Glide.with(mContext)
                .load(item.getPictureUrl())
                .crossFade()
                .placeholder(R.mipmap.def_head)
                .into((ImageView) helper.getView(R.id.video_list_item_image));
        //對(duì)視頻的賦值 添加視頻播放地址(使用原地址  .mp4之類的  這個(gè)要注意)和標(biāo)題
        ((JCVideoPlayerStandard)helper.getView(R.id.video_list_item_playr)).setUp(item.getAppVideoUrl(),item.getTitle());
        Glide.with(mContext)
                .load(item.getPictureUrl())
                .crossFade()
                .placeholder(R.mipmap.main_mini_m)
                .into((((JCVideoPlayerStandard) helper.getView(R.id.video_list_item_playr)).thumbImageView));
    }
}

Tab+Fragment快速實(shí)現(xiàn)

還是原來的配方 layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context="com.xiaochao.lcrapiddevelop.UI.Tab.TabActivity">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    <!--顯示頭部滑塊-->
    <FrameLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

然后就是頭部的xml編寫了

<com.xiaochao.lcrapiddeveloplibrary.SmartTab.SmartTabLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/viewpagertab"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="#FFFFFF"

    app:stl_defaultTabTextColor="@color/custom_tab"
    app:stl_distributeEvenly="true"
    app:stl_defaultTabTextHorizontalPadding="5dp"
    app:stl_indicatorColor="@color/title_bag"
    app:stl_indicatorCornerRadius="0dp"
    app:stl_indicatorInterpolation="smart"
    app:stl_indicatorThickness="3dp"
    app:stl_defaultTabTextSize="13dp"
    app:stl_dividerColor="@color/bag_gray"
    app:stl_dividerThickness="1dp"
    app:stl_overlineColor="@color/bag_gray"
    app:stl_underlineColor="#00000000"
    app:stl_defaultTabBackground="@color/bag_gray_transparent"
    />

完全可以按照自己想要的風(fēng)格玩 下面表格為 可設(shè)置的屬性


attr 描述
stl_indicatorAlwaysInCenter 如果設(shè)置為真,有源標(biāo)簽總是顯示在中心(如報(bào)攤google app),默認(rèn)的錯(cuò)誤
stl_indicatorWithoutPadding 如果設(shè)置為true,畫的指標(biāo)沒有填充選項(xiàng)卡中,默認(rèn)的錯(cuò)誤
stl_indicatorInFront 畫前的指示器下劃線,默認(rèn)的錯(cuò)誤
stl_indicatorInterpolation 行為的指標(biāo):“線性”或“智能”
stl_indicatorGravity 圖的位置指示器:“底”或“前”或“中心”,默認(rèn)“底”
stl_indicatorColor 標(biāo)志的顏色
stl_indicatorColors 多種顏色的指標(biāo),可以設(shè)置每個(gè)選項(xiàng)卡的顏色
stl_indicatorThickness 厚度指標(biāo)
stl_indicatorWidth 的寬度指標(biāo),默認(rèn)“汽車”
stl_indicatorCornerRadius 圓角半徑的指標(biāo)
stl_overlineColor 頂線的顏色
stl_overlineThickness 頂線的厚度
stl_underlineColor 顏色的底線
stl_underlineThickness 厚度的底線
stl_dividerColor 顏色之間的分隔器選項(xiàng)卡
stl_dividerColors 多種顏色的選項(xiàng)卡之間的分隔器,可以設(shè)置每個(gè)選項(xiàng)卡的顏色
stl_dividerThickness 分頻器的厚度
stl_defaultTabBackground 背景可拉的每個(gè)選項(xiàng)卡其兴。 一般設(shè)置StateListDrawable
stl_defaultTabTextAllCaps 如果設(shè)置為真,所有選項(xiàng)卡標(biāo)題大寫,違約事實(shí)
stl_defaultTabTextColor 文本的顏色包括默認(rèn)的選項(xiàng)卡
stl_defaultTabTextSize 文本包括默認(rèn)的選項(xiàng)卡的大小
stl_defaultTabTextHorizontalPadding 文本布局填充默認(rèn)的選項(xiàng)卡包括
stl_defaultTabTextMinWidth 最小寬度的標(biāo)簽
stl_customTabTextLayoutId 布局ID定義自定義選項(xiàng)卡蠢涝。 如果你不指定一個(gè)布局,使用默認(rèn)選項(xiàng)卡
stl_customTabTextViewId 文本視圖ID在一個(gè)自定義選項(xiàng)卡布局月匣。 如果你不與customTabTextLayoutId定義,不工作
stl_distributeEvenly 如果設(shè)置為真,每個(gè)選項(xiàng)卡都給出同樣的重量,默認(rèn)的錯(cuò)誤
stl_clickable 如果設(shè)置為false,禁用選擇選項(xiàng)卡單擊,違約事實(shí)
stl_titleOffset 如果設(shè)置為“auto_center”,中間的幻燈片的位置選項(xiàng)卡中心將繼續(xù)凌那。 如果指定一個(gè)維度將抵消從左邊緣,默認(rèn)24 dp
stl_drawDecorationAfterTab 畫裝飾(指示器和線)繪圖選項(xiàng)卡后,默認(rèn)的錯(cuò)誤

好了接下來就TabActivity

public class TabActivity extends AppCompatActivity {

    ViewGroup tab;
    ViewPager viewpager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab);
        initView();
    }

    private void initView() {
        tab = (ViewGroup) findViewById(R.id.tab);
        viewpager = (ViewPager) findViewById(R.id.viewpager);
        //使用方才定義頭部
        tab.addView(LayoutInflater.from(this).inflate(R.layout.tab_top_layout, tab, false));
    
        SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
        
        FragmentPagerItems pages = new FragmentPagerItems(this);
        
        //添加Fragment  FragmentPagerItem.of("頭部顯示標(biāo)題", "建立的fragment","需要傳值的可以傳Bundle")
        for (int i=0;i<4;i++) {
            pages.add(FragmentPagerItem.of("Tab"+i, TabFragment.class));
        }

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getSupportFragmentManager(), pages);

        viewpager.setAdapter(adapter);
        viewPagerTab.setViewPager(viewpager);
    }
}

功能還在繼續(xù)完善中感興趣的朋友可以一起

當(dāng)然也歡迎您提上寶貴的意見

最近寫了一個(gè)基于MVP模式開發(fā)的帶緩存網(wǎng)絡(luò)爬蟲,采用最流行框架搭建,干貨多多

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末奏篙,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子贮懈,更是在濱河造成了極大的恐慌旬牲,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,591評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呢燥,死亡現(xiàn)場(chǎng)離奇詭異崭添,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)叛氨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,448評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門呼渣,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人寞埠,你說我怎么就攤上這事屁置。” “怎么了仁连?”我有些...
    開封第一講書人閱讀 162,823評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵蓝角,是天一觀的道長。 經(jīng)常有香客問我,道長使鹅,這世上最難降的妖魔是什么揪阶? 我笑而不...
    開封第一講書人閱讀 58,204評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮患朱,結(jié)果婚禮上鲁僚,老公的妹妹穿的比我還像新娘。我一直安慰自己麦乞,他們只是感情好蕴茴,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,228評(píng)論 6 388
  • 文/花漫 我一把揭開白布劝评。 她就那樣靜靜地躺著姐直,像睡著了一般。 火紅的嫁衣襯著肌膚如雪蒋畜。 梳的紋絲不亂的頭發(fā)上声畏,一...
    開封第一講書人閱讀 51,190評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音姻成,去河邊找鬼插龄。 笑死,一個(gè)胖子當(dāng)著我的面吹牛科展,可吹牛的內(nèi)容都是我干的均牢。 我是一名探鬼主播,決...
    沈念sama閱讀 40,078評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼才睹,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼徘跪!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起琅攘,我...
    開封第一講書人閱讀 38,923評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤垮庐,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后坞琴,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體哨查,經(jīng)...
    沈念sama閱讀 45,334評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,550評(píng)論 2 333
  • 正文 我和宋清朗相戀三年剧辐,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了寒亥。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,727評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡荧关,死狀恐怖溉奕,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情羞酗,我是刑警寧澤腐宋,帶...
    沈念sama閱讀 35,428評(píng)論 5 343
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響胸竞,放射性物質(zhì)發(fā)生泄漏欺嗤。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,022評(píng)論 3 326
  • 文/蒙蒙 一卫枝、第九天 我趴在偏房一處隱蔽的房頂上張望煎饼。 院中可真熱鬧,春花似錦校赤、人聲如沸吆玖。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,672評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽沾乘。三九已至,卻和暖如春浑测,著一層夾襖步出監(jiān)牢的瞬間翅阵,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,826評(píng)論 1 269
  • 我被黑心中介騙來泰國打工迁央, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留掷匠,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,734評(píng)論 2 368
  • 正文 我出身青樓岖圈,卻偏偏與公主長得像讹语,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子蜂科,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,619評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容