mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-05-11 15:12:24 +08:00
#118 simplify sample app
This commit is contained in:
@@ -18,6 +18,8 @@ public class App extends Application {
|
||||
}
|
||||
|
||||
private HttpProxyCacheServer newProxy() {
|
||||
return new HttpProxyCacheServer(this);
|
||||
return new HttpProxyCacheServer.Builder(this)
|
||||
.cacheDirectory(Utils.getVideoCacheDir(this))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.danikula.videocache.sample;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -22,10 +21,7 @@ import java.io.File;
|
||||
@EFragment(R.layout.fragment_video)
|
||||
public class GalleryVideoFragment extends Fragment implements CacheListener {
|
||||
|
||||
private static final String LOG_TAG = "VideoFragment";
|
||||
|
||||
@FragmentArg String url;
|
||||
@FragmentArg String cachePath;
|
||||
|
||||
@InstanceState int position;
|
||||
@InstanceState boolean playerStarted;
|
||||
@@ -37,14 +33,9 @@ public class GalleryVideoFragment extends Fragment implements CacheListener {
|
||||
|
||||
private final VideoProgressUpdater updater = new VideoProgressUpdater();
|
||||
|
||||
public static Fragment build(Context context, Video video) {
|
||||
return build(video.url, video.getCacheFile(context).getAbsolutePath());
|
||||
}
|
||||
|
||||
public static Fragment build(String url, String cachePath) {
|
||||
public static Fragment build(String url) {
|
||||
return GalleryVideoFragment_.builder()
|
||||
.url(url)
|
||||
.cachePath(cachePath)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ public class MenuActivity extends FragmentActivity {
|
||||
@Click(R.id.cleanCacheButton)
|
||||
void onClearCacheButtonClick() {
|
||||
try {
|
||||
Utils.cleanDirectory(getExternalCacheDir());
|
||||
|
||||
Utils.cleanVideoCacheDir(this);
|
||||
} catch (IOException e) {
|
||||
Log.e(null, "Error cleaning cache", e);
|
||||
Toast.makeText(this, "Error cleaning cache", Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class MultipleVideosActivity extends FragmentActivity {
|
||||
private void addVideoFragment(Video video, int containerViewId) {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(containerViewId, VideoFragment.build(this, video))
|
||||
.add(containerViewId, VideoFragment.build(video.url))
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class SharedCacheActivity extends FragmentActivity {
|
||||
private void addVideoFragment(Video video, int containerViewId) {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(containerViewId, VideoFragment.build(this, video))
|
||||
.add(containerViewId, VideoFragment.build(video.url))
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class SingleVideoActivity extends FragmentActivity {
|
||||
if (state == null) {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.containerView, VideoFragment.build(this, Video.ORANGE_1))
|
||||
.add(R.id.containerView, VideoFragment.build(Video.ORANGE_1.url))
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.danikula.videocache.sample;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -10,7 +12,16 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static void cleanDirectory(File file) throws IOException {
|
||||
public static File getVideoCacheDir(Context context) {
|
||||
return new File(context.getExternalCacheDir(), "video-cache");
|
||||
}
|
||||
|
||||
public static void cleanVideoCacheDir(Context context) throws IOException {
|
||||
File videoCacheDir = getVideoCacheDir(context);
|
||||
cleanDirectory(videoCacheDir);
|
||||
}
|
||||
|
||||
private static void cleanDirectory(File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.danikula.videocache.sample;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public enum Video {
|
||||
|
||||
ORANGE_1(Config.ROOT + "orange1.mp4"),
|
||||
@@ -18,10 +14,6 @@ public enum Video {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public File getCacheFile(Context context) {
|
||||
return new File(context.getExternalCacheDir(), name());
|
||||
}
|
||||
|
||||
private class Config {
|
||||
private static final String ROOT = "https://raw.githubusercontent.com/danikula/AndroidVideoCache/master/files/";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.danikula.videocache.sample;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -26,7 +25,6 @@ public class VideoFragment extends Fragment implements CacheListener {
|
||||
private static final String LOG_TAG = "VideoFragment";
|
||||
|
||||
@FragmentArg String url;
|
||||
@FragmentArg String cachePath;
|
||||
|
||||
@ViewById ImageView cacheStatusImageView;
|
||||
@ViewById VideoView videoView;
|
||||
@@ -34,14 +32,9 @@ public class VideoFragment extends Fragment implements CacheListener {
|
||||
|
||||
private final VideoProgressUpdater updater = new VideoProgressUpdater();
|
||||
|
||||
public static Fragment build(Context context, Video video) {
|
||||
return build(video.url, video.getCacheFile(context).getAbsolutePath());
|
||||
}
|
||||
|
||||
public static Fragment build(String url, String cachePath) {
|
||||
public static Fragment build(String url) {
|
||||
return VideoFragment_.builder()
|
||||
.url(url)
|
||||
.cachePath(cachePath)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.danikula.videocache.sample;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
@@ -27,17 +26,14 @@ public class VideoGalleryActivity extends FragmentActivity {
|
||||
|
||||
private static final class ViewsPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
private final Context context;
|
||||
|
||||
public ViewsPagerAdapter(FragmentActivity activity) {
|
||||
super(activity.getSupportFragmentManager());
|
||||
this.context = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
Video video = Video.values()[position];
|
||||
return GalleryVideoFragment.build(context, video);
|
||||
return GalleryVideoFragment.build(video.url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user