1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

fixed inefficient double-conversion of parceled VideoInfoItems, from being cast from VideoInfoItem[] to Vector<>, to using ArrayList as an implementation of List

This commit is contained in:
Adam Howard 2015-11-13 10:47:05 +00:00
parent f13f9a066a
commit cc7ce5cf93
5 changed files with 12 additions and 10 deletions

View File

@ -26,7 +26,7 @@ import java.util.Vector;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
/**Info object for opened videos, ie the video ready to play.*/
public class VideoInfo {
public String id = "";
public String title = "";

View File

@ -24,6 +24,7 @@ import android.os.Parcelable;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
/**Info object for previews of unopened videos, eg search results, related videos*/
public class VideoInfoItem implements Parcelable {
public String id = "";
public String title = "";

View File

@ -16,6 +16,7 @@ import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import java.util.ArrayList;
import java.util.Arrays;
/**
@ -114,13 +115,13 @@ public class VideoItemListActivity extends AppCompatActivity
Bundle arguments = getIntent().getExtras();
if(arguments != null) {
Parcelable[] p = arguments.getParcelableArray(VIDEO_INFO_ITEMS);
//Parcelable[] p = arguments.getParcelableArray(VIDEO_INFO_ITEMS);
ArrayList<VideoInfoItem> p = arguments.getParcelableArrayList(VIDEO_INFO_ITEMS);
if(p != null) {
mode = PRESENT_VIDEOS_MODE;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//todo: make this more efficient
listFragment.present(Arrays.copyOf(p, p.length, VideoInfoItem[].class));
listFragment.present(p);
}
}

View File

@ -16,6 +16,7 @@ import android.widget.Toast;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
@ -167,14 +168,12 @@ public class VideoItemListFragment extends ListFragment {
}
}
public void present(VideoInfoItem[] videoList) {
public void present(List<VideoInfoItem> videoList) {
mode = PRESENT_VIDEOS_MODE;
setListShown(true);
getListView().smoothScrollToPosition(0);
// inefficient like hell i know (welcome to the world of java)
//todo: make this more efficient
updateList(new Vector<>(Arrays.asList(videoList)));
updateList(videoList);
}
public void search(String query) {
@ -221,7 +220,7 @@ public class VideoItemListFragment extends ListFragment {
}
}
private void updateList(Vector<VideoInfoItem> list) {
private void updateList(List<VideoInfoItem> list) {
try {
videoListAdapter.addVideoList(list);
terminateThreads();

View File

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import java.util.List;
import java.util.Vector;
/**
@ -48,7 +49,7 @@ public class VideoListAdapter extends BaseAdapter {
this.context = context;
}
public void addVideoList(Vector<VideoInfoItem> videos) {
public void addVideoList(List<VideoInfoItem> videos) {
videoList.addAll(videos);
for(int i = 0; i < videos.size(); i++) {
downloadedThumbnailList.add(false);