Skip to content
This repository has been archived by the owner on Oct 16, 2018. It is now read-only.

Commit

Permalink
fixed leaking singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHollidayInn committed Oct 8, 2017
1 parent 6370f7f commit 6cf78ff
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 227 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ dependencies {
compile 'com.github.pchmn:MaterialChipsInput:1.0.8'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-crash:10.0.1'

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

testCompile 'junit:junit:4.12'
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:label="@string/app_name"
android:roundIcon="@drawable/sedaily_logo"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".SEDailyApplication">

<activity android:name=".MainActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@

public class MainActivity extends PlaybackControllerActivity implements SearchView.OnQueryTextListener {
private UserRepository userRepository;
private RecentPodcastFragment firstFragment;
private FilterRepository filterRepository;

private RecentPodcastFragment firstFragment;
private PodListFragment secondPage;
private PodListFragment thirdPage;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -54,7 +58,9 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void showInitialPage () {
firstFragment = RecentPodcastFragment.newInstance();
if (firstFragment == null) {
firstFragment = RecentPodcastFragment.newInstance();
}
this.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, firstFragment)
Expand All @@ -80,17 +86,21 @@ private Boolean navigationItemSelected(@NonNull MenuItem item) {
showInitialPage();
break;
case R.id.action_schedules:
PodListFragment second = PodListFragment.newInstance("Greatest Hits", "");
if (secondPage == null) {
secondPage = PodListFragment.newInstance("Greatest Hits", "");
}
this.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, second)
.replace(R.id.fragment_container, secondPage)
.commit();
break;
case R.id.action_music:
PodListFragment third = PodListFragment.newInstance("Just For You", "");
if (thirdPage == null) {
thirdPage = PodListFragment.newInstance("Just For You", "");
}
this.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, third)
.replace(R.id.fragment_container, thirdPage)
.commit();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.ComponentName;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
Expand All @@ -25,6 +26,9 @@ public class PlaybackControllerActivity extends AppCompatActivity {
private MediaBrowserCompat mMediaBrowser;
private PlaybackControlsFragment mControlsFragment;

private PlaybackStateCompat state;
private String mCurrentMediaId;

private final MediaBrowserCompat.ConnectionCallback mConnectionCallbacks =
new MediaBrowserCompat.ConnectionCallback() {
@Override
Expand All @@ -47,12 +51,10 @@ public void onConnectionFailed() {
}
};

MediaControllerCompat.Callback controllerCallback =
private MediaControllerCompat.Callback controllerCallback =
new MediaControllerCompat.Callback() {
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
if (metadata != null) {
}
}

@Override
Expand All @@ -72,26 +74,37 @@ protected void onCreate(Bundle savedInstanceState) {
}

protected void setUp() {
mMediaBrowser = new MediaBrowserCompat(this,
new ComponentName(this, MusicService.class),
mConnectionCallbacks,
null); // optional Bundle
if (mMediaBrowser == null) {
mMediaBrowser = new MediaBrowserCompat(this,
new ComponentName(this, MusicService.class),
mConnectionCallbacks,
null); // optional Bundle
}
}

@Override
public void onStart() {
super.onStart();
mControlsFragment = (PlaybackControlsFragment) getSupportFragmentManager()
.findFragmentById(R.id.fragment_playback_controls);
if (mControlsFragment == null) {
mControlsFragment = (PlaybackControlsFragment) getSupportFragmentManager()
.findFragmentById(R.id.fragment_playback_controls);
}
mMediaBrowser.connect();

}

@Override
public void onPause() {
super.onPause();
if (MediaControllerCompat.getMediaController(this) != null) {
MediaControllerCompat.getMediaController(this).unregisterCallback(controllerCallback);
}
mMediaBrowser.disconnect();
}

@Override
public void onResume() {
super.onResume();


}

@Override
Expand All @@ -105,20 +118,17 @@ public void onStop() {
}

protected void showPlaybackControls() {
// if (NetworkHelper.isOnline(this)) {
// @TODO: check for network
getSupportFragmentManager().beginTransaction()
// .setCustomAnimations(
// R.animator.slide_in_from_bottom, R.animator.slide_out_to_bottom,
// R.animator.slide_in_from_bottom, R.animator.slide_out_to_bottom)
.show(mControlsFragment)
.commit();
// }
.commitAllowingStateLoss();

}

protected void hidePlaybackControls() {
getSupportFragmentManager().beginTransaction()
.hide(mControlsFragment)
.commit();
.commitAllowingStateLoss();
}

/**
Expand All @@ -144,7 +154,7 @@ protected boolean shouldShowControls() {
}
}

private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat mediaController = new MediaControllerCompat(
this, token);

Expand All @@ -161,4 +171,24 @@ private void connectToSession(MediaSessionCompat.Token token) throws RemoteExcep
mControlsFragment.onConnected();
}
}

public void onMediaItemSelected(MediaBrowserCompat.MediaItem item, boolean isPlaying) {
if (item.isPlayable()) {
MediaControllerCompat controller = MediaControllerCompat.getMediaController(this);
MediaControllerCompat.TransportControls controls = controller.getTransportControls();

if (isPlaying) {
controls.pause();
} else {
controls.playFromMediaId(item.getMediaId(), null);
}
}
}

@Nullable
public String getPlayingMediaId() {
boolean isPlaying = state != null
&& state.getState() == PlaybackStateCompat.STATE_PLAYING;
return isPlaying ? mCurrentMediaId : null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View rootView = (View) inflater.inflate(
R.layout.fragment_podcast_horizontal, container, false);

Log.v("keithtest", "onCreateView");
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);

recyclerView.setHasFixedSize(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.koalatea.thehollidayinn.softwareengineeringdaily.R;
import com.koalatea.thehollidayinn.softwareengineeringdaily.audio.MediaPlayer;
import com.koalatea.thehollidayinn.softwareengineeringdaily.audio.MusicProvider;
import com.koalatea.thehollidayinn.softwareengineeringdaily.data.models.Post;
import com.squareup.picasso.Picasso;

Expand Down
Loading

0 comments on commit 6cf78ff

Please sign in to comment.