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

Added skeleton loading and fixed null checks #66

Merged
merged 13 commits into from
Nov 24, 2017
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ app/google-services.json
bin/
gen/
out/
app/release/

# Gradle files
.gradle/
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android:
# Additional components
- extra-google-android-support


# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-armeabi-v7a-android-27
Expand All @@ -33,4 +33,4 @@ install:

script: ./gradlew clean build -Pbuild=dev
script: ./gradlew test -Pbuild=dev
# script: ./gradlew connectedAndroidTest -Pbuild=dev
# script: ./gradlew connectedAndroidTest -Pbuild=dev
16 changes: 11 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.oss.licenses.plugin'
apply plugin: 'project-report'
apply plugin: 'io.fabric'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand All @@ -11,8 +12,8 @@ android {
applicationId "com.koalatea.thehollidayinn.softwareengineeringdaily"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 4
versionName "1.1"
versionCode 10
versionName "1.24"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

//Note this will be deprecated soon....
Expand Down Expand Up @@ -113,14 +114,19 @@ dependencies {
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofit2Version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofit2Version"
//Presentation
implementation "com.squareup.picasso:picasso:$rootProject.picassoVersion"
implementation "com.google.android.gms:play-services-oss-licenses:$rootProject.playVersion"
compile "com.squareup.picasso:picasso:$rootProject.picassoVersion"
compile "com.google.android.gms:play-services-oss-licenses:$rootProject.playVersion"
compile 'com.ethanhua:skeleton:1.0.0'
compile 'de.hdodenhof:circleimageview:2.2.0'
//UI
implementation "com.github.pchmn:MaterialChipsInput:$rootProject.materialChipsVersion"
implementation "com.jakewharton:butterknife:$rootProject.butterknifeVersion"
kapt "com.jakewharton:butterknife-compiler:$rootProject.butterknifeVersion"
implementation "blue.aodev:material-values:$rootProject.materialValuesVersion"
//Firebase
compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true
}
implementation "com.google.firebase:firebase-core:$rootProject.firebaseServicesVersion"
implementation "com.google.firebase:firebase-crash:$rootProject.firebaseServicesVersion"
//Architecture
Expand Down Expand Up @@ -149,4 +155,4 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
</intent-filter>
</service>

<!--
A receiver that will receive media buttons and send as
intents to your MediaBrowserServiceCompat implementation.
Required on pre-Lollipop. More information at
http://developer.android.com/reference/android/support/v4/media/session/MediaButtonReceiver.html
-->
<receiver android:name="android.support.v4.media.session.MediaButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON"/>
</intent-filter>
</receiver>

<activity
android:name=".podcast.PodcastDetailActivity"
android:label="@string/title_activity_podcast_detail"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.koalatea.thehollidayinn.softwareengineeringdaily.audio;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.RemoteException;
import android.support.annotation.NonNull;
import android.support.v4.app.NotificationManagerCompat;
Expand All @@ -17,7 +20,7 @@
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v7.app.NotificationCompat;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.koalatea.thehollidayinn.softwareengineeringdaily.R;
Expand Down Expand Up @@ -133,7 +136,17 @@ public Notification createNotification() {
R.drawable.sedaily_logo);
}

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
final NotificationManager mNotifyManager =
(NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);
String CHANNEL_ID = "sedaily_player_notifications";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = mService.getString(R.string.app_name);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
mNotifyManager.createNotificationChannel(mChannel);
}

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService, CHANNEL_ID);
notificationBuilder
.setLargeIcon(art)
.setContentIntent(controller.getSessionActivity())
Expand All @@ -142,15 +155,10 @@ public Notification createNotification() {
.setSmallIcon(R.drawable.sedaily_logo)
.setColor(ContextCompat.getColor(mService, R.color.colorPrimaryDark))
.addAction(action)
.setStyle(new NotificationCompat.MediaStyle()
// show only play/pause in compact view.
.setShowActionsInCompactView(new int[]{0})
.setMediaSession(mSessionToken))
.setShowWhen(false)
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle());


return notificationBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.text.TextUtils;
import android.util.Log;

import com.google.firebase.crash.FirebaseCrash;
import java.io.IOException;


Expand Down Expand Up @@ -259,7 +260,11 @@ public void setSpeed(int speed) {
}

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(speedFloat));
try {
mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(speedFloat));
} catch (Exception e) {
FirebaseCrash.report(new Exception(e));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ public void removePodcastDownload(String podcastId) {
}

public Boolean isPodcastDownloaded(Post post) {
if (this.filesLoaded.get(post.getId()) != null && this.filesLoaded.get(post.getId())) return true;
if (this.filesLoaded.get(post.get_id()) != null && this.filesLoaded.get(post.get_id())) return true;

if (post.getMp3() == null || post.getMp3().isEmpty()) {
return false;
}

File file = new MP3FileManager().getFileFromUrl(post.getMp3(), SDEApp.component().context());
if (file.exists()) {
this.filesLoaded.put(post.getId(), true);
this.filesLoaded.put(post.get_id(), true);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,29 @@ public void onStopTrackingTouch(SeekBar seekBar) {
});

setSpeedText();
setUpSpeedSubscription();

return rootView;
}

@Override
public void onStart() {
super.onStart();
long currentPlayTime = PodcastSessionStateManager.getInstance().getCurrentProgress();
mLastPlaybackState = PodcastSessionStateManager.getInstance().getLastPlaybackState();

if (currentPlayTime > 0) {
scheduleSeekbarUpdate();
}
mStart.setText(DateUtils.formatElapsedTime(currentPlayTime / 1000));
setSpeedTextView();

if (speedSubscription != null && speedSubscription.isUnsubscribed()) {
setUpSpeedSubscription();
}
}

private void setUpSpeedSubscription () {
speedSubscription = new Subscriber<Integer>() {
@Override public void onCompleted() {
}
Expand All @@ -156,20 +178,6 @@ public void onStopTrackingTouch(SeekBar seekBar) {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(speedSubscription);

return rootView;
}

@Override
public void onStart() {
super.onStart();
long currentPlayTime = PodcastSessionStateManager.getInstance().getCurrentProgress();
mLastPlaybackState = PodcastSessionStateManager.getInstance().getLastPlaybackState();

if (currentPlayTime > 0) {
scheduleSeekbarUpdate();
}
mStart.setText(DateUtils.formatElapsedTime(currentPlayTime / 1000));
}

@Override
Expand Down Expand Up @@ -217,12 +225,12 @@ public void onDestroy() {
}

public void onConnected() {
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller != null) {
updateWithMeta(controller.getMetadata());
handlePlaybackStateChange(controller.getPlaybackState());
controller.registerCallback(mCallback);
}
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller != null) {
updateWithMeta(controller.getMetadata());
handlePlaybackStateChange(controller.getPlaybackState());
controller.registerCallback(mCallback);
}
}

private void updateWithMeta(MediaMetadataCompat metadata) {
Expand Down Expand Up @@ -277,6 +285,8 @@ private void handlePlaybackStateChange(PlaybackStateCompat state) {
@Override
public void onClick(View v) {
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller == null) return;

PlaybackStateCompat stateObj = controller.getPlaybackState();
final int state = stateObj == null ? PlaybackStateCompat.STATE_NONE : stateObj.getState();

Expand Down Expand Up @@ -368,14 +378,18 @@ private void showSpeedDialog() {
new SpeedDialog().show(this.getFragmentManager(), "tag");
}

private void setSpeedText() {
private int setSpeedTextView () {
int currentSpeed = PodcastSessionStateManager.getInstance().getCurrentSpeed();
String[] speedArray = getResources().getStringArray(R.array.speed_options);
speed.setText(speedArray[currentSpeed]);
return currentSpeed;

}
private void setSpeedText() {
int currentSpeed = setSpeedTextView();

MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller != null) {

Bundle args = new Bundle();
args.putInt("SPEED", currentSpeed);
// @TODO: Make constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.view.View;
import android.view.ViewGroup;

import com.ethanhua.skeleton.RecyclerViewSkeletonScreen;
import com.ethanhua.skeleton.Skeleton;
import com.koalatea.thehollidayinn.softwareengineeringdaily.R;
import com.koalatea.thehollidayinn.softwareengineeringdaily.data.models.Post;
import com.koalatea.thehollidayinn.softwareengineeringdaily.data.remote.APIInterface;
Expand Down Expand Up @@ -36,6 +38,7 @@ public class PodListFragment extends Fragment {
private String tagId;
private PodcastAdapter podcastAdapter;
private Subscriber<String> mySubscriber;
private RecyclerViewSkeletonScreen skeletonScreen;

public static PodListFragment newInstance(String title, String tagId) {
PodListFragment f = new PodListFragment();
Expand All @@ -53,7 +56,6 @@ public View onCreateView(LayoutInflater inflater,
R.layout.fragment_podcast_horizontal, container, false);

RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);

recyclerView.setHasFixedSize(true);

LinearLayoutManager mLayoutManager = new LinearLayoutManager(this.getContext());
Expand All @@ -62,6 +64,12 @@ public View onCreateView(LayoutInflater inflater,
podcastAdapter = new PodcastAdapter(this);
recyclerView.setAdapter(podcastAdapter);

skeletonScreen = Skeleton.bind(recyclerView)
.adapter(podcastAdapter)
.load(R.layout.item_skeleton_news)
.shimmer(true)
.show();

FilterRepository filterRepository = FilterRepository.getInstance();
mySubscriber = new Subscriber<String>() {
@Override
Expand Down Expand Up @@ -121,7 +129,7 @@ private void getPosts(String search) {
.subscribe(new Subscriber<List<Post>>() {
@Override
public void onCompleted() {

skeletonScreen.hide();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ private void confirmRemoveLocalDownload() {
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (post.getMp3() == null || post.getMp3().isEmpty()) {
return;
}

File file = new MP3FileManager().getFileFromUrl(post.getMp3(), getApplicationContext());
file.delete();
PodcastDownloadsRepository.getInstance().removePodcastDownload(post.getId());
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="8dp">
android:paddingTop="10dp">

<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/sedaily_logo"
android:contentDescription="@string/logo" />

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/app_name"
android:paddingTop="4dp"
android:paddingLeft="8dp"
android:paddingStart="8dp"
android:textSize="16sp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Expand All @@ -40,7 +50,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginBottom="40dp"
android:layout_marginBottom="48dp"
android:id="@+id/fragment_container">
</FrameLayout>

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/fragment_podcast_horizontal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_recycler_view"
android:paddingBottom="24dp"
android:paddingTop="12dp"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title" />
Loading