Resuit

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.example.dhilongcin"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    //rxjava相关依赖
    compile 'io.reactivex:rxjava:1.2.1'
    compile 'io.reactivex:rxandroid:1.2.1'
//retrofit相关依赖
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
//okhttp相关依赖
    compile 'com.squareup.okhttp3:okhttp:3.4.1'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.android.support:recyclerview-v7:23.2.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'

}

以上是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dhilongcin">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
以上是

package com.example.dhilongcin.view;

import com.example.dhilongcin.bean.Bean;

/**
 * Created by HP on 2017/11/21.
 */

public interface IView {
    void show(Bean bean);
}
以上是

package com.example.dhilongcin.utils;

import com.example.dhilongcin.bean.Bean;

import retrofit2.http.GET;
import rx.Observable;

/**
 * Created by HP on 2017/11/21.
 */

public interface BaseRetrofit {
    @GET("data.js")
    Observable<Bean> getCall();
}
以上是

package com.example.dhilongcin.utils;

/**
 * Created by HP on 2017/11/21.
 */

public class BaseUrl {
    public static String url="http://huixinguiyu.cn/Assets/js/";
}
以上是
package com.example.dhilongcin.model;

import com.example.dhilongcin.bean.Bean;
import com.example.dhilongcin.utils.BaseRetrofit;
import com.example.dhilongcin.utils.BaseUrl;
import com.example.dhilongcin.utils.LoggingInterceptor;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by HP on 2017/11/21.
 */

public class Model {

    public void getData(Observer<Bean> observer){
        OkHttpClient okHttpClient=new OkHttpClient.Builder()
                .addInterceptor(new LoggingInterceptor())
                .build();
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(BaseUrl.url)
                .client(okHttpClient)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        BaseRetrofit baseRetrofit = retrofit.create(BaseRetrofit.class);
        Observable<Bean> observable = baseRetrofit.getCall();
        observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    };
}
以上是
package com.example.dhilongcin.presenter;

import com.example.dhilongcin.bean.Bean;
import com.example.dhilongcin.model.Model;
import com.example.dhilongcin.view.IView;

import rx.Observer;

/**
 * Created by HP on 2017/11/21.
 */

public class Presenter {
    IView iView;
    private final Model model;

    public Presenter(IView iView) {
        this.iView = iView;
        model = new Model();
    }

    public void GetUrl(){
        model.getData(new Observer<Bean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(Bean bean) {
                iView.show(bean);
            }
        });
    }

    public void del(){
        if (iView!=null){
            iView=null;
        }
    }
}
以上是

package com.example.dhilongcin;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.dhilongcin.bean.Bean;
import com.example.dhilongcin.presenter.Presenter;
import com.example.dhilongcin.view.IView;

public class MainActivity extends AppCompatActivity implements IView{

    private TextView tv;
    private Presenter presenter;
//    private RecyclerView recy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = (TextView) findViewById(R.id.tv);
//        recy= (RecyclerView) findViewById(R.id.rexy);
        presenter = new Presenter(this);
        presenter.GetUrl();

    }

    @Override
    public void show(Bean bean) {
        tv.setText(bean.getApk().get(0).getName());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.del();
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值