Skip to content

Commit

Permalink
Bug Fix: App used to crash when the MainFragment is rotated.
Browse files Browse the repository at this point in the history
  • Loading branch information
ram-on committed Apr 10, 2017
1 parent ab3a20e commit d3a0bab
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,17 @@

package free.rm.skytube.gui.businessobjects;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import free.rm.skytube.R;
import free.rm.skytube.businessobjects.MainActivityListener;
import free.rm.skytube.businessobjects.YouTubeVideo;
import free.rm.skytube.businessobjects.db.BookmarksDb;

/**
* A ViewHolder for the videos grid view.
Expand All @@ -48,26 +38,27 @@ public class GridViewHolder extends RecyclerView.ViewHolder {
private Context context = null;
private MainActivityListener listener;

@Bind(R.id.channel_layout)
View channelLayout;
@Bind(R.id.title_text_view)
TextView titleTextView;
@Bind(R.id.channel_text_view)
TextView channelTextView;
@Bind(R.id.thumbs_up_text_view)
TextView thumbsUpPercentageTextView;
@Bind(R.id.video_duration_text_view)
TextView videoDurationTextView;
@Bind(R.id.publish_date_text_view)
TextView publishDateTextView;
@Bind(R.id.thumbnail_image_view)
ImageView thumbnailImageView;
@Bind(R.id.views_text_view)
TextView viewsTextView;
private View channelLayout;
private TextView titleTextView;
private TextView channelTextView;
private TextView thumbsUpPercentageTextView;
private TextView videoDurationTextView;
private TextView publishDateTextView;
private TextView viewsTextView;
private ImageView thumbnailImageView;


public GridViewHolder(View view, MainActivityListener listener) {
super(view);
ButterKnife.bind(this, view);
channelLayout = view.findViewById(R.id.channel_layout);
titleTextView = (TextView) view.findViewById(R.id.title_text_view);
channelTextView = (TextView) view.findViewById(R.id.channel_text_view);
thumbsUpPercentageTextView = (TextView) view.findViewById(R.id.thumbs_up_text_view);
videoDurationTextView = (TextView) view.findViewById(R.id.video_duration_text_view);
publishDateTextView = (TextView) view.findViewById(R.id.publish_date_text_view);
viewsTextView = (TextView) view.findViewById(R.id.views_text_view);
thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail_image_view);

this.listener = listener;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public Context getContext() {
return context;
}

public void setContext(Context context) {
this.context = context;
}

/**
* @return An instance of {@link LayoutInflater}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
videoGridAdapter = null;

if (bookmarksGridAdapter == null)
if (bookmarksGridAdapter == null) {
bookmarksGridAdapter = new bookmarksGridAdapter(getActivity());
} else {
bookmarksGridAdapter.setContext(getActivity());
}

bookmarksGridAdapter.setListener((MainActivityListener)getActivity());
gridView.setAdapter(bookmarksGridAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
subsListView = (RecyclerView) view.findViewById(R.id.subs_drawer);
if (subsAdapter == null) {
subsAdapter = SubsAdapter.get(getActivity(), view.findViewById(R.id.subs_drawer_progress_bar));
} else {
subsAdapter.setContext(getActivity());
}
subsAdapter.setListener((MainActivityListener)getActivity());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import android.view.ViewGroup;
import android.widget.GridView;

import com.bumptech.glide.Glide;

import free.rm.skytube.R;
import free.rm.skytube.businessobjects.MainActivityListener;
import free.rm.skytube.businessobjects.VideoCategory;
Expand Down Expand Up @@ -60,6 +62,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
gridView = (RecyclerView) view.findViewById(R.id.grid_view);
if (videoGridAdapter == null) {
videoGridAdapter = new VideoGridAdapter(getActivity());
} else {
videoGridAdapter.setContext(getActivity());
}
videoGridAdapter.setProgressBar(progressBar);

Expand All @@ -75,6 +79,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}


@Override
public void onDestroy() {
super.onDestroy();
Glide.get(getActivity()).clearMemory();
}

/**
* In case a subclass of VideosGridFragment wants to use an alternate layout resource (e.g. Subscriptions).
*/
Expand Down

0 comments on commit d3a0bab

Please sign in to comment.