Commit 2855b775 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Show subtitles presence in Info Panel

parent 707411a0
......@@ -34,6 +34,7 @@ public class Media implements Parcelable {
public final static HashSet<String> VIDEO_EXTENSIONS;
public final static HashSet<String> AUDIO_EXTENSIONS;
public final static HashSet<String> SUBTITLES_EXTENSIONS;
static {
final String[] video_extensions = {
......@@ -51,12 +52,20 @@ public class Media implements Parcelable {
".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta",
".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };
final String[] subtitles_extensions = {
"idx", "sub", "srt", "ssa", "ass", "smi", "utf", "utf8", "utf-8",
"rt", "aqt", "txt", "usf", "jss", "cdg", "psb", "mpsub","mpl2",
"pjs", "dks", "stl", "vtt" };
VIDEO_EXTENSIONS = new HashSet<String>();
for (String item : video_extensions)
VIDEO_EXTENSIONS.add(item);
AUDIO_EXTENSIONS = new HashSet<String>();
for (String item : audio_extensions)
AUDIO_EXTENSIONS.add(item);
SUBTITLES_EXTENSIONS = new HashSet<String>();
for (String item : subtitles_extensions)
SUBTITLES_EXTENSIONS.add(item);
}
public final static int TYPE_ALL = -1;
......
......@@ -77,6 +77,15 @@
android:layout_alignBottom="@+id/info_delete"
android:layout_alignTop="@+id/info_delete"
android:gravity="center_vertical"/>
<ImageView
android:id="@+id/info_subtitles"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/info_path"
android:layout_toRightOf="@+id/size_value"
android:src="@drawable/ic_subtitle_circle_normal_o"
android:visibility="invisible"/>
<TextView
android:id="@+id/info_delete"
android:layout_width="wrap_content"
......
......@@ -51,6 +51,8 @@
android:id="@+id/info_path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_below="@+id/image_container"/>
<TextView
......@@ -67,6 +69,15 @@
android:layout_height="wrap_content"
android:layout_below="@+id/info_path"
android:layout_toRightOf="@+id/size_title"/>
<ImageView
android:id="@+id/info_subtitles"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/info_path"
android:layout_toRightOf="@+id/size_value"
android:src="@drawable/ic_subtitle_circle_normal_o"
android:visibility="invisible"/>
<TextView
android:id="@+id/info_delete"
android:layout_width="wrap_content"
......
......@@ -67,6 +67,7 @@ public class MediaInfoFragment extends ListFragment {
private TextView mPathView;
private ImageButton mPlayButton;
private TextView mDelete;
private ImageView mSubtitles;
private TrackInfo[] mTracks;
private MediaInfoAdapter mAdapter;
private final static int NEW_IMAGE = 0;
......@@ -74,6 +75,7 @@ public class MediaInfoFragment extends ListFragment {
private final static int NEW_SIZE = 2;
private final static int HIDE_DELETE = 3;
private final static int EXIT = 4;
private final static int SHOW_SUBTITLES = 5;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
......@@ -85,6 +87,7 @@ public class MediaInfoFragment extends ListFragment {
mPathView = (TextView) v.findViewById(R.id.info_path);
mPlayButton = (ImageButton) v.findViewById(R.id.play);
mDelete = (TextView) v.findViewById(R.id.info_delete);
mSubtitles = (ImageView) v.findViewById(R.id.info_subtitles);
if (!LibVlcUtil.isICSOrLater())
mDelete.setText(getString(R.string.delete).toUpperCase());
......@@ -148,9 +151,26 @@ public class MediaInfoFragment extends ListFragment {
mHandler.obtainMessage(HIDE_DELETE).sendToTarget();
long length = itemFile.length();
mHandler.obtainMessage(NEW_SIZE, Long.valueOf(length)).sendToTarget();
checkSubtitles(itemFile);
}
};
private void checkSubtitles(File itemFile) {
String extension, filename, videoName = Uri.decode(itemFile.getName());
videoName = videoName.substring(0, videoName.lastIndexOf('.'));
String[] files = itemFile.getParentFile().list();
for (int i = 0; i<files.length ; ++i){
filename = Uri.decode(files[i]);
extension = filename.substring(filename.lastIndexOf('.')+1);
if (!Media.SUBTITLES_EXTENSIONS.contains(extension))
continue;
if (filename.startsWith(videoName)) {
mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
return;
}
}
}
Runnable mLoadImage = new Runnable() {
@Override
public void run() {
......@@ -159,12 +179,12 @@ public class MediaInfoFragment extends ListFragment {
} catch (LibVlcException e) {
return;
}
mTracks = mLibVlc.readTracksInfo(mItem.getLocation());
int videoHeight = mItem.getHeight();
int videoWidth = mItem.getWidth();
if (videoWidth == 0 || videoHeight == 0)
return;
mTracks = mLibVlc.readTracksInfo(mItem.getLocation());
mHandler.sendEmptyMessage(NEW_TEXT);
DisplayMetrics screen = new DisplayMetrics();
......@@ -207,14 +227,20 @@ public class MediaInfoFragment extends ListFragment {
}
private void updateText() {
boolean hasSubs = false;
for (TrackInfo track : mTracks) {
if (track.Type != TrackInfo.TYPE_META)
if (track.Type != TrackInfo.TYPE_META) {
mAdapter.add(track);
if (track.Type == TrackInfo.TYPE_TEXT)
hasSubs = true;
}
}
if (mAdapter.isEmpty()) {
((MainActivity) getActivity()).popSecondaryFragment();
return;
}
if (hasSubs)
mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
}
private void updateSize(Long size){
......@@ -250,6 +276,9 @@ public class MediaInfoFragment extends ListFragment {
((MainActivity) fragment.getActivity()).popSecondaryFragment();
MediaLibrary.getInstance().loadMediaItems(fragment.getActivity(), true);
break;
case SHOW_SUBTITLES:
fragment.mSubtitles.setVisibility(View.VISIBLE);
break;
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment