Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UAMP MediaBrowser orientation

I am trying uamp sample, whenever orientation changes MediaBrowserFragment recyclerview state is lost(its scroll position is not maintained).

My problem is how to maintain scroll position in uamp sample.

I know I can save scroll position and restore it later but since recyclerView itself maintains scroll state I don't want that hacks.

I tried pushing this simple fragment instead of MediaBrowserFragment and its maintaining its scroll

public class TestFragment extends Fragment {

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mRootView = inflater.inflate(R.layout.fragment_test, container, false);
        RecyclerView recyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(new RecAdapter());
        return mRootView;
    }


    private class RecAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_text, null);
            return new ItemViewHolder(itemView);
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            ((ItemViewHolder) holder).title.setText(""+ position);
        }

        @Override
        public int getItemCount() {
            return 200;
        }
    }

    private class ItemViewHolder extends RecyclerView.ViewHolder {
        TextView title;

        ItemViewHolder(View itemLayoutView) {
            super(itemLayoutView);
            title = (TextView) itemLayoutView.findViewById(R.id.title);
        }
    }
}

Update

I raised the issue with uamp

https://github.com/googlesamples/android-UniversalMusicPlayer/issues/217

like image 755
ingsaurabh Avatar asked Jun 11 '18 12:06

ingsaurabh


1 Answers

you can just add configChanges in your manifest file as below:

 <activity android:name=".YourActivity"
           android:configChanges="orientation|screenSize"/>
like image 126
Milan Pansuriya Avatar answered Sep 17 '22 01:09

Milan Pansuriya