Skip to content

Commit

Permalink
checks for google play services
Browse files Browse the repository at this point in the history
  • Loading branch information
naman14 committed Dec 12, 2017
1 parent d350bfb commit 0c3c64f
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 52 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:palette-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:percent:$rootProject.supportLibraryVersion"
implementation 'com.android.support:multidex:1.0.1'

implementation "com.android.support:mediarouter-v7:$rootProject.supportLibraryVersion"
implementation 'com.google.android.gms:play-services-cast-framework:11.6.0'
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/naman14/timber/TimberApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package com.naman14.timber;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

import com.afollestad.appthemeengine.ATE;
import com.crashlytics.android.Crashlytics;
Expand All @@ -31,7 +33,7 @@

import io.fabric.sdk.android.Fabric;

public class TimberApp extends Application {
public class TimberApp extends MultiDexApplication {


private static TimberApp mInstance;
Expand Down
34 changes: 26 additions & 8 deletions app/src/main/java/com/naman14/timber/activities/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.google.android.gms.cast.framework.SessionManager;
import com.google.android.gms.cast.framework.SessionManagerListener;
import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.naman14.timber.ITimberService;
import com.naman14.timber.MusicPlayer;
import com.naman14.timber.MusicService;
Expand Down Expand Up @@ -74,6 +76,8 @@ public class BaseActivity extends ATEActivity implements ServiceConnection, Musi
new SessionManagerListenerImpl();
private WebServer castServer;

public boolean playServicesAvailable = false;

private class SessionManagerListenerImpl extends SimpleSessionManagerListener {
@Override
public void onSessionStarting(Session session) {
Expand Down Expand Up @@ -122,7 +126,15 @@ public void onCreate(Bundle savedInstanceState) {
//make volume keys change multimedia volume even if music is not playing now
setVolumeControlStream(AudioManager.STREAM_MUSIC);

initCast();
try {
playServicesAvailable = GoogleApiAvailability
.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS;
} catch (Exception ignored) {

}

if (playServicesAvailable)
initCast();
}

@Override
Expand Down Expand Up @@ -154,17 +166,21 @@ protected void onStop() {

@Override
public void onResume() {
mCastSession = mSessionManager.getCurrentCastSession();
mSessionManager.addSessionManagerListener(mSessionManagerListener);
if (playServicesAvailable) {
mCastSession = mSessionManager.getCurrentCastSession();
mSessionManager.addSessionManagerListener(mSessionManagerListener);
}
onMetaChanged();
super.onResume();
}

@Override
protected void onPause() {
super.onPause();
mSessionManager.removeSessionManagerListener(mSessionManagerListener);
mCastSession = null;
if (playServicesAvailable) {
mSessionManager.removeSessionManagerListener(mSessionManagerListener);
mCastSession = null;
}
}

@Override
Expand Down Expand Up @@ -253,9 +269,11 @@ public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.menu_cast, menu);

CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),
menu,
R.id.media_route_menu_item);
if (playServicesAvailable) {
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),
menu,
R.id.media_route_menu_item);
}

if (!TimberUtils.hasEffectsPanel(BaseActivity.this)) {
menu.removeItem(R.id.action_equalizer);
Expand Down
30 changes: 23 additions & 7 deletions app/src/main/java/com/naman14/timber/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.appthemeengine.customizers.ATEActivityThemeCustomizer;
Expand Down Expand Up @@ -235,17 +239,29 @@ public void run() {
}, 350);
}

findViewById(R.id.castMiniController).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, ExpandedControllerActivity.class));
}
});

if (!panelLayout.isPanelHidden() && MusicPlayer.getTrackName() == null ) {
panelLayout.hidePanel();
}

if (playServicesAvailable) {

final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM;

FrameLayout contentRoot = findViewById(R.id.content_root);
contentRoot.addView(LayoutInflater.from(this)
.inflate(R.layout.fragment_cast_mini_controller, null), params);

findViewById(R.id.castMiniController).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, ExpandedControllerActivity.class));
}
});
}

}

private void loadEverything() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;

import com.google.android.gms.cast.framework.CastButtonFactory;
Expand All @@ -21,6 +22,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.appthemeengine.ATE;
import com.afollestad.appthemeengine.Config;
import com.naman14.timber.MusicPlayer;
import com.naman14.timber.R;
import com.naman14.timber.activities.MainActivity;
import com.naman14.timber.adapters.AlbumSongsAdapter;
import com.naman14.timber.dataloaders.AlbumLoader;
import com.naman14.timber.dataloaders.AlbumSongLoader;
Expand All @@ -68,21 +70,21 @@

public class AlbumDetailFragment extends Fragment {

long albumID = -1;
private long albumID = -1;

ImageView albumArt, artistArt;
TextView albumTitle, albumDetails;
private ImageView albumArt, artistArt;
private TextView albumTitle, albumDetails;

RecyclerView recyclerView;
AlbumSongsAdapter mAdapter;
private RecyclerView recyclerView;
private AlbumSongsAdapter mAdapter;

Toolbar toolbar;
private Toolbar toolbar;

Album album;
private Album album;

CollapsingToolbarLayout collapsingToolbarLayout;
AppBarLayout appBarLayout;
FloatingActionButton fab;
private CollapsingToolbarLayout collapsingToolbarLayout;
private AppBarLayout appBarLayout;
private FloatingActionButton fab;

private boolean loadFailed = false;

Expand Down Expand Up @@ -207,18 +209,20 @@ public void onGenerated(Palette palette) {
}
}

MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(getActivity())
.setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE)
.setSizeDp(30);
if (primaryColor != -1) {
builder.setColor(TimberUtils.getBlackWhiteColor(primaryColor));
ATEUtils.setFabBackgroundTint(fab, primaryColor);
fab.setImageDrawable(builder.build());
} else {
if (context != null) {
ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
builder.setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
if (getActivity() != null) {
MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(getActivity())
.setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE)
.setSizeDp(30);
if (primaryColor != -1) {
builder.setColor(TimberUtils.getBlackWhiteColor(primaryColor));
ATEUtils.setFabBackgroundTint(fab, primaryColor);
fab.setImageDrawable(builder.build());
} else {
if (context != null) {
ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
builder.setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
fab.setImageDrawable(builder.build());
}
}
}
}
Expand Down Expand Up @@ -296,6 +300,8 @@ public void onActivityCreated(final Bundle savedInstanceState) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.album_detail, menu);
if (getActivity() != null)
ATE.applyMenu(getActivity(), "dark_theme", menu);
}

@Override
Expand Down Expand Up @@ -331,11 +337,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onResume() {
super.onResume();
String ateKey = Helpers.getATEKey(getActivity());
toolbar.setBackgroundColor(Color.TRANSPARENT);
if (primaryColor != -1 && getActivity() != null) {
collapsingToolbarLayout.setContentScrimColor(primaryColor);
ATEUtils.setFabBackgroundTint(fab, primaryColor);
String ateKey = Helpers.getATEKey(getActivity());
ATEUtils.setStatusBarColor(getActivity(), ateKey, primaryColor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
import android.support.v7.graphics.Palette;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.afollestad.appthemeengine.ATE;
import com.naman14.timber.R;
import com.naman14.timber.dataloaders.ArtistLoader;
import com.naman14.timber.lastfmapi.LastFmClient;
Expand Down Expand Up @@ -188,6 +191,19 @@ public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
});
}

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (getActivity() != null)
ATE.applyMenu(getActivity(), "dark_theme", menu);
}

@Override
public void onResume() {
super.onResume();
Expand Down
23 changes: 19 additions & 4 deletions app/src/main/java/com/naman14/timber/utils/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void loadAlbumArtIntoView(final long albumId, final ImageView view
public static void loadAlbumArtIntoView(final long albumId, final ImageView view,
final ImageLoadingListener listener) {
if (PreferencesUtility.getInstance(view.getContext()).alwaysLoadAlbumImagesFromLastfm()) {
loadAlbumArtFromLastfm(albumId, view);
loadAlbumArtFromLastfm(albumId, view, listener);
} else {
loadAlbumArtFromDiskWithLastfmFallback(albumId, view, listener);
}
Expand All @@ -75,13 +75,18 @@ private static void loadAlbumArtFromDiskWithLastfmFallback(final long albumId, I
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
loadAlbumArtFromLastfm(albumId, (ImageView) view);
loadAlbumArtFromLastfm(albumId, (ImageView) view, listener);
listener.onLoadingFailed(imageUri, view, failReason);
}

@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
listener.onLoadingComplete(imageUri, view, loadedImage);
}
});
}

private static void loadAlbumArtFromLastfm(long albumId, final ImageView albumArt) {
private static void loadAlbumArtFromLastfm(long albumId, final ImageView albumArt, final ImageLoadingListener listener) {
Album album = AlbumLoader.getAlbum(albumArt.getContext(), albumId);
LastFmClient.getInstance(albumArt.getContext())
.getAlbumInfo(new AlbumQuery(album.title, album.artistName),
Expand All @@ -92,7 +97,17 @@ public void albumInfoSuccess(final LastfmAlbum album) {
ImageLoader.getInstance()
.displayImage(album.mArtwork.get(4).mUrl,
albumArt,
lastfmDisplayImageOptions);
lastfmDisplayImageOptions, new SimpleImageLoadingListener(){
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
listener.onLoadingComplete(imageUri, view, loadedImage);
}

@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
listener.onLoadingFailed(imageUri, view, failReason);
}
});
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_cast_mini_controller.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/castMiniController"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom"
android:visibility="gone"
class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"/>
10 changes: 1 addition & 9 deletions app/src/main/res/layout/include_list_viewpager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/content_root"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.naman14.timber.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down Expand Up @@ -30,14 +31,5 @@

</com.naman14.timber.slidinguppanel.SlidingUpPanelLayout>

<fragment
android:id="@+id/castMiniController"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom"
android:visibility="gone"
class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"/>

</FrameLayout>
Binary file added graphics/screen10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/screen11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/screen12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/screen8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/screen9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0c3c64f

Please sign in to comment.