===========================================================
View:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@color/base_bg”>
<TextView
android:id=“@+id/tv_activity_mvc”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:textSize=“30sp”
android:layout_centerInParent=“true”/>
Controller:
public class MVCActivity extends BaseActivity {
RetrofitManager mRetrofitManager;
@BindView(R.id.tv_activity_mvc)
TextView mTextView;
@Override
protected int getContentViewLayoutID() {
return R.layout.activity_architecture_mvc_activity;
}
@Override
protected void initViewsAndEvents(Bundle savedInstanceState) {
mTextView.setText(“I don’t do anything, but this is a MVC show anyway. Click me!”);
mRetrofitManager = new RetrofitManager();
}
@OnClick(R.id.tv_activity_mvc)
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv_activity_mvc:
mRetrofitManager.createApi(MyApplication.getInstance().getApplicationContext(), GankApis.class)
.getHistoryDate()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObserver<GankRes<List>>() {
@Override
public void onError(ApiException exception) {
LogUtil.e(TAG, “error:” + exception.getMessage());
}
@Override
public void onSuccess(GankRes<List> listGankRes) {
LogUtil.i(TAG, listGankRes.getResults().toString());
if (!MVCActivity.this.isFinishing() && !MVCActivity.this.isDestroyed()) {
mTextView.setText(“yes, I get it from net!”);
}
}
});
break;
}
}
}
Model
public class RetrofitManager {
private static final String TAG = “RetrofitManager”;
private static Retrofit singleton;
private static OkHttpClient okHttpClient = null;
private static String BASE_URL = “http://127.0.0.1”;
private void init() {
initOkHttp();
}
public RetrofitManager() {
init();
}
private void initOkHttp() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (BuildConfig.DEBUG) {
// Log信息拦截器
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);//这里可以选择拦截级别
//设置 Debug Log 模式
builder.addInterceptor(loggingInterceptor);
//配置SSL证书检测
builder.sslSocketFactory(SSLSocketClient.getNoSSLSocketFactory());
builder.hostnameVerifier(SSLSocketClient.getHostnameVerifier());
}
//错误重连
builder.retryOnConnectionFailure(true);
okHttpClient = builder.build();
LogUtil.i(TAG, “initOkHttp:getNoSSLSocketFactory”);
}
public static void initBaseUrl(String url) {
BASE_URL = url;
LogUtil.i(TAG, " base_url ->" + BASE_URL);
}
/**
-
@param context Context
-
@param clazz interface
-
@param interface实例化
-
@return
*/
public static T createApi(Context context, Class clazz) {
if (singleton == null) {
synchronized (RetrofitManager.class) {
if (singleton == null) {
Retrofit.Builder builder = new Retrofit.Builder();
重要知识点
下面是有几位Android行业大佬对应上方技术点整理的一些进阶资料。
高级进阶篇——高级UI,自定义View(部分展示)
UI这块知识是现今使用者最多的。当年火爆一时的Android入门培训,学会这小块知识就能随便找到不错的工作了。不过很显然现在远远不够了,拒绝无休止的CV,亲自去项目实战,读源码,研究原理吧!
- 面试题部分合集
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
会这小块知识就能随便找到不错的工作了。不过很显然现在远远不够了,拒绝无休止的CV,亲自去项目实战,读源码,研究原理吧!
[外链图片转存中…(img-jC0MFKNv-1714384177838)]
- 面试题部分合集
[外链图片转存中…(img-cpdPiJAE-1714384177838)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!