1
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-16 13:53:53 +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/>. * 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 class VideoInfo {
public String id = ""; public String id = "";
public String title = ""; public String title = "";

View File

@ -24,6 +24,7 @@ import android.os.Parcelable;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * 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 class VideoInfoItem implements Parcelable {
public String id = ""; public String id = "";
public String title = ""; public String title = "";

View File

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

View File

@ -16,6 +16,7 @@ import android.widget.Toast;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Vector; 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; mode = PRESENT_VIDEOS_MODE;
setListShown(true); setListShown(true);
getListView().smoothScrollToPosition(0); getListView().smoothScrollToPosition(0);
// inefficient like hell i know (welcome to the world of java) updateList(videoList);
//todo: make this more efficient
updateList(new Vector<>(Arrays.asList(videoList)));
} }
public void search(String query) { 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 { try {
videoListAdapter.addVideoList(list); videoListAdapter.addVideoList(list);
terminateThreads(); terminateThreads();

View File

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