Skip to content

Commit

Permalink
请求图片和地址
Browse files Browse the repository at this point in the history
  • Loading branch information
472530498 committed Mar 5, 2019
1 parent 16923b4 commit f73880e
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 54 deletions.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
9 changes: 3 additions & 6 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 5 additions & 29 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ android {
jniLibs.srcDirs = ['libs']
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand All @@ -41,4 +46,13 @@ dependencies {
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
implementation 'com.shuyu:GSYVideoPlayer:6.0.1'
implementation 'com.android.support:percent:28.0.0-alpha1'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
/*网络请求体系 Retrofit + Rxjava*/
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'// 序列化解析器
implementation "io.reactivex.rxjava2:rxjava:2.1.0" // 必要rxjava2依赖
implementation "io.reactivex.rxjava2:rxandroid:2.0.1" // 必要rxandrroid依赖,切线程时需要用到
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0' // 必要依赖,和Rxjava结合必须用到,下面会提到
implementation 'com.squareup.okhttp3:okhttp:3.13.1'//
}
21 changes: 11 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.example.a47253.tvproject">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature
android:name="android.software.leanback"
android:required="false" />
Expand All @@ -20,11 +21,11 @@
android:banner = "@drawable/banner">
<activity android:name=".mvp.view.activity.MainActivity"
android:theme="@style/Theme.AppCompat">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".mvp.view.activity.VideoMainActivity"></activity>
<activity
Expand All @@ -33,11 +34,11 @@
android:screenOrientation="portrait">
</activity>
<activity android:name=".mvp.view.activity.LiveVideoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.AdapterView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.a47253.tvproject.R;
import com.example.a47253.tvproject.bean.PosterBean;

Expand Down Expand Up @@ -43,8 +44,9 @@ public void onBindViewHolder(@NonNull GridAdapter.ViewHolder viewHolder, int i)
PosterBean object = (PosterBean)list.get(i);
viewHolder.poster_name.setText(object.getPosterName());
FileInputStream in = null;
Bitmap bitmap = BitmapFactory.decodeResource(viewHolder.itemView.getResources(), R.drawable.poster);
viewHolder.poster.setImageBitmap(bitmap);
Glide.with(viewHolder.itemView.getContext()).load(object.getPosterUrl()).into(viewHolder.poster);
// Bitmap bitmap = BitmapFactory.decodeResource(viewHolder.itemView.getResources(), R.drawable.poster);
// viewHolder.poster.setImageBitmap(bitmap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.a47253.tvproject.bean;

public class ResponseBean {
private String resultCode;
private String resultMsg;
private Object data;

public ResponseBean() {
}

public ResponseBean(String resultCode, String resultMsg, Object data) {
this.resultCode = resultCode;
this.resultMsg = resultMsg;
this.data = data;
}

public String getResultCode() {
return resultCode;
}

public void setResultCode(String resultCode) {
this.resultCode = resultCode;
}

public String getResultMsg() {
return resultMsg;
}

public void setResultMsg(String resultMsg) {
this.resultMsg = resultMsg;
}

public Object getData() {
return data;
}

public void setData(Object data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.example.a47253.tvproject.R;
import com.example.a47253.tvproject.adapter.GridAdapter;
import com.example.a47253.tvproject.adapter.OnItemClickListener;
import com.example.a47253.tvproject.bean.PosterBean;
import com.example.a47253.tvproject.bean.ResponseBean;
import com.example.a47253.tvproject.retrofit.VideoRequest;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.internal.LinkedTreeMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class VideoMainActivity extends AppCompatActivity {
private final static String TAG = "VideoMainActivity";
List<Object> videoList = new ArrayList<Object>();
GridAdapter gridAdapter;
RecyclerView viedioView;
Gson gson = new Gson();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -33,11 +49,42 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
((GridLayoutManager) manager).setOrientation(GridLayoutManager.VERTICAL);
viedioView.setLayoutManager(manager);
viedioView.setAdapter(gridAdapter);
for (int i = 0; i<7; i++) {
videoList.add(new PosterBean("","海报名字"));
}
Log.i("list", videoList.toString());
gridAdapter.update(videoList);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.retryOnConnectionFailure(true)
.connectTimeout(30, TimeUnit.SECONDS)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.0.103:7001/")
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();

VideoRequest service = retrofit.create(VideoRequest.class);
service.selectVideoAll().enqueue(new Callback<ResponseBean>() {
@Override
public void onResponse(Call<ResponseBean> call, Response<ResponseBean> response) {
Log.i(TAG, response.body().getResultMsg());
Log.i(TAG, response.body().getResultCode());
Log.i(TAG, gson.toJson(response.body().getData()));
Log.i(TAG, response.body().getData().getClass().getName());
for (Object datum : (java.util.ArrayList) (response.body().getData())) {
Log.i(TAG, datum.getClass().getName());
LinkedTreeMap temp = (LinkedTreeMap)datum;
videoList.add(new PosterBean( (String) temp.get("video_poster_url"), (String) temp.get("video_name")));
Log.i("list", videoList.toString());
gridAdapter.update(videoList);
}
}
@Override
public void onFailure(Call<ResponseBean> call, Throwable t) {
System.out.print("onFailure response.body():");
}
});
// for (int i = 0; i<7; i++) {
// videoList.add(new PosterBean("","海报名字"));
// }
// Log.i("list", videoList.toString());
// gridAdapter.update(videoList);
gridAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View view, int postion) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.a47253.tvproject.retrofit;

import com.example.a47253.tvproject.bean.ResponseBean;


import retrofit2.Call;
import retrofit2.http.GET;

public interface VideoRequest {
@GET("commonModel/videoManager/selectVideoAll")
Call<ResponseBean> selectVideoAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.a47253.tvproject.utils;

public class NetWorkManager {
// private static NetWorkManager mInstance;
// private static Retrofit retrofit;
// private static volatile VideoRequest request = null;
//
// public static NetWorkManager getInstance() {
// if (mInstance == null) {
// synchronized (NetWorkManager.class) {
// if (mInstance == null) {
// mInstance = new NetWorkManager();
// }
// }
// }
// return mInstance;
// }
//
// /**
// * 初始化必要对象和参数
// */
// public void init() {
// // 初始化okhttp
// OkHttpClient client = new OkHttpClient.Builder()
// .build();
//
// // 初始化Retrofit
// retrofit = new Retrofit.Builder()
// .client(client)
// .baseUrl(VideoRequest.HOST)
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
// .addConverterFactory(GsonConverterFactory.create())
// .build();
// }
//
// public static VideoRequest getRequest() {
// if (request == null) {
// synchronized (VideoRequest.class) {
// request = retrofit.create(VideoRequest.class);
// }
// }
// return request;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:id="@+id/poster"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
/>
<TextView
android:id="@+id/poster_name"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Empty file added git
Empty file.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Sun Mar 03 15:58:26 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

0 comments on commit f73880e

Please sign in to comment.