Skip to content

Commit 4fc0b0c

Browse files
committed
fix
1 parent 5778f6e commit 4fc0b0c

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

app/src/main/java/com/wirelessalien/android/moviedb/fragment/EpisodeDetailsBottomSheet.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
2929
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
3030
import com.squareup.picasso.Picasso
3131
import com.wirelessalien.android.moviedb.R
32-
import com.wirelessalien.android.moviedb.activity.BaseActivity
3332
import com.wirelessalien.android.moviedb.activity.CastActivity
3433
import com.wirelessalien.android.moviedb.adapter.EpisodeCastAdapter
3534
import com.wirelessalien.android.moviedb.data.CastMember
@@ -98,17 +97,21 @@ class EpisodeDetailsBottomSheet : BottomSheetDialogFragment() {
9897
}
9998

10099
private fun fetchEpisodeDetails() {
101-
val apiKey = ConfigHelper.getConfigValue(requireContext(), "api_key")
102-
val language = BaseActivity.getLanguageParameter(requireContext()).replace("&language=", "")
103-
val url = "https://api.themoviedb.org/3/tv/$tvShowId/season/$seasonNumber/episode/$episodeNumber?api_key=$apiKey&append_to_response=credits&language=$language"
100+
val apiKey = ConfigHelper.getConfigValue(requireContext(), "api_read_access_token")
101+
val url = "https://api.themoviedb.org/3/tv/$tvShowId/season/$seasonNumber/episode/$episodeNumber?append_to_response=credits"
104102

105103
CoroutineScope(Dispatchers.IO).launch {
106104
try {
107105
val client = OkHttpClient()
108-
val request = Request.Builder().url(url).build()
106+
val request = Request.Builder()
107+
.url(url)
108+
.get()
109+
.addHeader("accept", "application/json")
110+
.addHeader("Authorization", "Bearer $apiKey")
111+
.build()
109112
val response = client.newCall(request).execute()
110113
val jsonData = response.body?.string()
111-
val episodeObject = JSONObject(jsonData?: "{}")
114+
val episodeObject = JSONObject(jsonData ?: "{}")
112115

113116
withContext(Dispatchers.Main) {
114117
populateViews(episodeObject)

app/src/main/java/com/wirelessalien/android/moviedb/widget/UpcomingRemoteViewsFactory.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.wirelessalien.android.moviedb.helper.EpisodeReminderDatabaseHelper
3535
import com.wirelessalien.android.moviedb.helper.MovieDatabaseHelper
3636
import com.wirelessalien.android.moviedb.helper.TraktDatabaseHelper
3737
import org.json.JSONObject
38+
import java.text.NumberFormat
3839
import java.text.SimpleDateFormat
3940
import java.util.Calendar
4041
import java.util.Date
@@ -306,8 +307,13 @@ class UpcomingRemoteViewsFactory(
306307
val episodeName = if (!reminderName.isNullOrEmpty()) ": $reminderName" else ""
307308

308309
title = showTitle
309-
val seasonEpisodeInfo = "S${String.format("%02d", seasonNum)}E$episodeNum$episodeName"
310-
310+
val episodeNumFormatted = try {
311+
val episodeNumInt = episodeNum.toIntOrNull() ?: 0
312+
NumberFormat.getInstance(Locale.getDefault()).format(episodeNumInt)
313+
} catch (e: NumberFormatException) {
314+
episodeNum
315+
}
316+
val seasonEpisodeInfo = "S${String.format("%02d", seasonNum)}E$episodeNumFormatted$episodeName"
311317
jsonObject.put("name", title)
312318
jsonObject.put("seasonEpisode", seasonEpisodeInfo)
313319
jsonObject.put(ListFragment.IS_MOVIE, 0)
@@ -367,7 +373,14 @@ class UpcomingRemoteViewsFactory(
367373
val episodeName = epCursor.getString(epCursor.getColumnIndexOrThrow(EpisodeReminderDatabaseHelper.COLUMN_NAME))
368374
val seasonNum = epCursor.getInt(epCursor.getColumnIndexOrThrow(EpisodeReminderDatabaseHelper.COL_SEASON))
369375
val episodeNum = epCursor.getString(epCursor.getColumnIndexOrThrow(EpisodeReminderDatabaseHelper.COLUMN_EPISODE_NUMBER))
370-
val seasonEpisodeInfo = "S${String.format("%02d", seasonNum)}E$episodeNum: $episodeName"
376+
val episodeNumFormatted = try {
377+
val episodeNumInt = episodeNum?.toIntOrNull() ?: 0
378+
NumberFormat.getInstance(Locale.getDefault()).format(episodeNumInt)
379+
} catch (e: NumberFormatException) {
380+
episodeNum ?: "0"
381+
}
382+
383+
val seasonEpisodeInfo = "S${String.format("%02d", seasonNum)}E$episodeNumFormatted: $episodeName"
371384
jsonObject.put("name", itemTitleFromDb)
372385
jsonObject.put("seasonEpisode", seasonEpisodeInfo)
373386
} else {

app/src/main/res/layout/bottom_sheet_season_episode.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
android:id="@+id/seasonActionButton"
176176
android:layout_width="match_parent"
177177
android:layout_height="wrap_content"
178-
android:text="Add Season to Watched"
178+
android:text="@string/add_season_to_watched"
179179
android:layout_marginStart="16dp"
180180
android:layout_marginEnd="16dp"
181181
android:layout_marginTop="10dp"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,5 @@
431431
</plurals>
432432
<string name="videos">Videos</string>
433433
<string name="no_videos_available">No videos available</string>
434+
<string name="add_season_to_watched">Add Season to Watched</string>
434435
</resources>

app/src/main/res/xml/provider_paths.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
<paths>
2222
<external-files-path
2323
name="downloads"
24-
path="Download/" />
24+
path="." />
2525
</paths>

0 commit comments

Comments
 (0)