Skip to content

Commit

Permalink
Fix crashes with Cast, network errors, and TVs
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Dec 23, 2016
1 parent 1de2aef commit b85a2b4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 19
targetSdkVersion 25
versionCode 105
versionName '4.0.3'
versionCode 106
versionName '4.0.4'
multiDexEnabled true
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void onCreate(Bundle savedInstanceState) {
Intent tvIntent = new Intent(this, TvActivity.class);
startActivity(tvIntent);
finish();
return;
}

PutioApplication application = (PutioApplication) getApplication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stevenschoen.putionew.cast

import android.net.Uri
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu
import com.google.android.gms.cast.MediaInfo
import com.google.android.gms.cast.MediaMetadata
Expand All @@ -16,6 +17,7 @@ import com.stevenschoen.putionew.R
import com.stevenschoen.putionew.model.files.PutioFile
import com.stevenschoen.putionew.model.files.PutioSubtitle
import org.apache.commons.io.FilenameUtils
import rx.android.schedulers.AndroidSchedulers

abstract class BaseCastActivity : AppCompatActivity(), PutioApplication.CastCallbacks {

Expand All @@ -32,15 +34,13 @@ abstract class BaseCastActivity : AppCompatActivity(), PutioApplication.CastCall
}

override fun load(file: PutioFile, url: String, utils: PutioUtils) {
if (castContext == null || castSession == null) {
utils.getStreamUrlAndPlay(this, file, url)
} else {
if (castContext != null && castSession != null && castSession!!.remoteMediaClient != null && castSession!!.isConnected) {
fun play(subtitles: List<PutioSubtitle>? = null) {
val metaData = MediaMetadata(
if (file.isVideo)
MediaMetadata.MEDIA_TYPE_MOVIE
else
MediaMetadata.MEDIA_TYPE_MUSIC_TRACK)
MediaMetadata.MEDIA_TYPE_MOVIE
else
MediaMetadata.MEDIA_TYPE_MUSIC_TRACK)
val title = FilenameUtils.removeExtension(file.name).let {
if (it.length <= 18) {
it
Expand Down Expand Up @@ -80,6 +80,8 @@ abstract class BaseCastActivity : AppCompatActivity(), PutioApplication.CastCall
} else {
play()
}
} else {
utils.getStreamUrlAndPlay(this, file, url)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class CastOptionsProvider implements OptionsProvider {

public static final String CAST_APPLICATION_ID = "E5977464"; // Styled media receiver
// public static final String CAST_APPLICATION_ID = "C18ACC9E";
// public static final String CAST_APPLICATION_ID = "C18ACC9E";
// public static final String CAST_APPLICATION_ID = "79E32AF2"; // Put.io's

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.TextView
import android.widget.*
import com.squareup.picasso.Picasso
import com.stevenschoen.putionew.*
import com.stevenschoen.putionew.PutioApplication.CastCallbacks
Expand All @@ -29,7 +26,7 @@ class FileDetailsFragment : RxFragment() {
val EXTRA_FILE = "file"

val FRAGTAG_RENAME = "rename"
val FRAGTAG_DELETE = "delete";
val FRAGTAG_DELETE = "delete"

fun newInstance(context: Context, file: PutioFile): FileDetailsFragment {
if (file.isFolder) {
Expand Down Expand Up @@ -235,7 +232,9 @@ class FileDetailsFragment : RxFragment() {
PutioApplication.get(context).putioUtils.restInterface
.renameFile(file.id, newName)
.observeOn(AndroidSchedulers.mainThread())
.subscribe()
.subscribe({ }, { error ->
Toast.makeText(context, R.string.network_error, Toast.LENGTH_SHORT).show()
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String getSource() {
}

public String getUrl(String format, long fileId, String tokenWithStuff) {
return PutioUtils.baseUrl + "/files/" + fileId + "/subtitles/" + getKey() + tokenWithStuff
return PutioUtils.baseUrl + "files/" + fileId + "/subtitles/" + getKey() + tokenWithStuff
+ "&format=" + format;
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<string name="notatorrent">This doesn\'t seem to be a torrent file!</string>
<string name="couldntgetdownloadlink">There was a problem getting the download link.</string>
<string name="noactivityfound">No installed apps can open this.</string>
<string name="network_error">Network error!</string>

<!-- Other stuff -->
<string name="account">Account</string>
Expand Down

0 comments on commit b85a2b4

Please sign in to comment.