Parcourir la source

added current programme calculation. Added dummy fragment.

yattoz il y a 4 ans
Parent
révision
0218dfab75

+ 50 - 7
app/src/main/assets/planning_example.json Voir le fichier

@@ -1,10 +1,10 @@
1 1
 {
2 2
   "planning": [
3 3
     {
4
-      "title": "Anime Matin",
5
-      "periodicity": "1111100",
6
-      "hour_begin": "9:00",
7
-      "hour_end": "10:30"
4
+      "title": "Musique Classique",
5
+      "periodicity": "1111111",
6
+      "hour_begin": "6:00",
7
+      "hour_end": "7:00"
8 8
     },
9 9
     {
10 10
       "title": "Jeux Vidéos Matin",
@@ -12,11 +12,54 @@
12 12
       "hour_begin": "09:00",
13 13
       "hour_end": "10:30"
14 14
     },
15
+    {
16
+      "title": "Anime Matin",
17
+      "periodicity": "1111100",
18
+      "hour_begin": "10:30",
19
+      "hour_end": "12:00"
20
+    },
21
+    {
22
+      "title": "Jeux Vidéos Aprem'",
23
+      "periodicity": "1111111",
24
+      "hour_begin": "14:00",
25
+      "hour_end": "15:30"
26
+    },
27
+    {
28
+      "title": "Anime Aprem'",
29
+      "periodicity": "1111111",
30
+      "hour_begin": "15:30",
31
+      "hour_end": "17:00"
32
+    },
33
+    {
34
+      "title": "Jeux Vidéos Soirée",
35
+      "periodicity": "1111100",
36
+      "hour_begin": "19:00",
37
+      "hour_end": "20:00"
38
+    },
39
+    {
40
+      "title": "Anime Soirée",
41
+      "periodicity": "1111100",
42
+      "hour_begin": "20:00",
43
+      "hour_end": "21:00"
44
+    },
45
+    {
46
+      "title": "Jeux Vidéos Nuit",
47
+      "periodicity": "1111111",
48
+      "hour_begin": "00:00",
49
+      "hour_end": "01:00"
50
+    },
51
+    {
52
+      "title": "Anime Nuit",
53
+      "periodicity": "1111111",
54
+      "hour_begin": "01:00",
55
+      "hour_end": "02:00"
56
+    },
15 57
     {
16 58
       "title": "Programmation nocturne",
17 59
       "periodicity": "1111111",
18
-      "hour_begin": "23:00",
19
-      "hour_end": "5:30"
60
+      "hour_begin": "02:00",
61
+      "hour_end": "06:00"
20 62
     }
21
-  ]
63
+  ],
64
+  "regular_programme" : "Programmation habituelle"
22 65
 }

+ 2 - 2
app/src/main/java/fr/forum_thalie/tsumugi/MainActivity.kt Voir le fichier

@@ -16,7 +16,7 @@ import fr.forum_thalie.tsumugi.playerstore.PlayerStore
16 16
 import java.util.Timer
17 17
 import android.view.MenuItem
18 18
 import fr.forum_thalie.tsumugi.alarm.RadioAlarm
19
-import fr.forum_thalie.tsumugi.planning.PlanningParser
19
+import fr.forum_thalie.tsumugi.planning.Planning
20 20
 
21 21
 
22 22
 /* Log to file import
@@ -157,7 +157,7 @@ class MainActivity : BaseActivity() {
157 157
         }
158 158
 
159 159
         // fetch program
160
-        PlanningParser.instance.parseUrl(/* getString(R.string.planning_url) */ context = this)
160
+        Planning.instance.parseUrl(/* getString(R.string.planning_url) */ context = this)
161 161
 
162 162
         // initialize the UI
163 163
         setTheme(R.style.AppTheme)

+ 2 - 0
app/src/main/java/fr/forum_thalie/tsumugi/RadioService.kt Voir le fichier

@@ -34,6 +34,7 @@ import com.google.android.exoplayer2.*
34 34
 import com.google.android.exoplayer2.metadata.icy.*
35 35
 import fr.forum_thalie.tsumugi.alarm.RadioAlarm
36 36
 import fr.forum_thalie.tsumugi.alarm.RadioSleeper
37
+import fr.forum_thalie.tsumugi.planning.Planning
37 38
 import fr.forum_thalie.tsumugi.playerstore.PlayerStore
38 39
 import java.util.*
39 40
 import kotlin.math.exp
@@ -129,6 +130,7 @@ class RadioService : MediaBrowserServiceCompat() {
129 130
             PlayerStore.instance.updateLp()
130 131
         }
131 132
         nowPlayingNotification.update(this)
133
+        Log.d(tag, Planning.instance.currentProgramme())
132 134
     }
133 135
 
134 136
     private val streamerPictureObserver = Observer<Bitmap> {

app/src/main/java/fr/forum_thalie/tsumugi/planning/PlanningParser.kt → app/src/main/java/fr/forum_thalie/tsumugi/planning/Planning.kt Voir le fichier

@@ -6,9 +6,19 @@ import org.json.JSONObject
6 6
 import java.io.IOException
7 7
 import java.net.URL
8 8
 
9
-class PlanningParser {
9
+class Planning {
10 10
 
11
-    val programs: ArrayList<Program> = ArrayList()
11
+    private val programmes: ArrayList<Programme> = ArrayList()
12
+    private var regularProgramme: String? = null
13
+
14
+    fun currentProgramme(): String
15
+    {
16
+        programmes.forEach {
17
+            if (it.isCurrent())
18
+                return it.title
19
+        }
20
+        return regularProgramme ?: "none"
21
+    }
12 22
 
13 23
     fun parseUrl(url: String? = null, context: Context? = null)
14 24
     {
@@ -46,16 +56,18 @@ class PlanningParser {
46 56
                     val hourEndS = item.getString("hour_end").split(":")
47 57
                     val hourEnd = hourEndS.first().toInt()* 60 + hourEndS.last().toInt()
48 58
                     val title = item.getString("title")
49
-                    programs.add(Program(title, periodicity, hourBegin, hourEnd))
59
+                    programmes.add(Programme(title, periodicity, hourBegin, hourEnd))
50 60
                 }
51 61
             }
62
+            if (result.has("regular_programme"))
63
+                regularProgramme = result.getString("regular_programme")
52 64
         }
53 65
         Async(scrape, post)
54 66
     }
55 67
 
56 68
     companion object {
57 69
         val instance by lazy {
58
-            PlanningParser()
70
+            Planning()
59 71
         }
60 72
     }
61 73
 }

+ 0 - 41
app/src/main/java/fr/forum_thalie/tsumugi/planning/Program.kt Voir le fichier

@@ -1,41 +0,0 @@
1
-package fr.forum_thalie.tsumugi.planning
2
-
3
-import android.util.Log
4
-import fr.forum_thalie.tsumugi.tag
5
-import org.json.JSONObject
6
-import java.util.*
7
-
8
-class Program (val title: String, private val periodicity: Int, private val hourBegin: Int, private val hourEnd: Int) {
9
-    fun isCurrent(): Boolean
10
-    {
11
-        val now = Calendar.getInstance()
12
-        val currentDay = if (now.get(Calendar.DAY_OF_WEEK) - 1 == 0) 6 else now.get(Calendar.DAY_OF_WEEK) - 2
13
-        // 0 (Monday) to 5 (Saturday) + 6 (Sunday)
14
-
15
-        // this translates to "true" when:
16
-        // - the currentDay is flagged in the "periodicity" bit array
17
-        // OR
18
-        // - Yesterday is flagged in the "periodicity" bit array AND the program does span over 2 days (night programs typically).
19
-        // We'll check a after this whether the current hour is within the span.
20
-        val isNow: Boolean = ((((1000000 shr currentDay) and (periodicity)) == 1)) || (((1000000 shr ((currentDay-1)%7) and (periodicity)) == 1) && hourEnd < hourBegin)
21
-
22
-        // shr = shift-right. It's a binary mask.
23
-        if (isNow)
24
-        {
25
-            val hasBegun = (now.get(Calendar.HOUR_OF_DAY)*60 + now.get(Calendar.MINUTE) >= hourBegin )
26
-            val hasNotEnded = (now.get(Calendar.HOUR_OF_DAY)*60 + now.get(Calendar.MINUTE) <= hourEnd )
27
-            if (hasBegun && hasNotEnded)
28
-                return true
29
-        }
30
-
31
-        return false
32
-    }
33
-
34
-    override fun toString(): String {
35
-        return "Title: $title, time info (periodicity, begin, end): $periodicity, $hourBegin, $hourEnd"
36
-    }
37
-
38
-    init {
39
-        Log.d(tag, this.toString())
40
-    }
41
-}

+ 50 - 0
app/src/main/java/fr/forum_thalie/tsumugi/planning/Programme.kt Voir le fichier

@@ -0,0 +1,50 @@
1
+package fr.forum_thalie.tsumugi.planning
2
+
3
+import android.util.Log
4
+import fr.forum_thalie.tsumugi.tag
5
+import java.util.*
6
+
7
+class Programme (val title: String, private val periodicity: Int, private val hourBegin: Int, private val hourEnd: Int) {
8
+    fun isCurrent(): Boolean {
9
+        val now = Calendar.getInstance()
10
+        val currentDay =
11
+            if (now.get(Calendar.DAY_OF_WEEK) - 1 == 0) 6 else now.get(Calendar.DAY_OF_WEEK) - 2
12
+        // 0 (Monday) to 5 (Saturday) + 6 (Sunday)
13
+
14
+        // this translates to "true" when:
15
+        // - the currentDay is flagged in the "periodicity" bit array
16
+        // OR
17
+        // - Yesterday is flagged in the "periodicity" bit array AND the program does span over 2 days (night programs).
18
+        // We'll check a after this whether the current hour is within the span.
19
+        val isToday: Boolean = ((((1000000 shr currentDay) and (periodicity)) != 0))
20
+        val isSpanningOverNight =
21
+            (((1000000 shr ((currentDay - 1) % 7) and (periodicity)) != 0) && hourEnd < hourBegin)
22
+
23
+        Log.d(tag, "$title is today: $isToday or spanning $isSpanningOverNight")
24
+        // shr = shift-right. It's a binary mask.
25
+
26
+        // if the program started yesterday, and spanned over night, it means that there could be a chance that it's still active.
27
+        // we only need to check if the end time has been reached.
28
+        if (isSpanningOverNight) {
29
+            return (now.get(Calendar.HOUR_OF_DAY) * 60 + now.get(Calendar.MINUTE) < hourEnd)
30
+        }
31
+
32
+        // if the program is today, we need to check if we're in the hour span.
33
+        if (isToday) {
34
+            val hasBegun =
35
+                (now.get(Calendar.HOUR_OF_DAY) * 60 + now.get(Calendar.MINUTE) >= hourBegin)
36
+            val hasNotEnded =
37
+                (now.get(Calendar.HOUR_OF_DAY) * 60 + now.get(Calendar.MINUTE) < hourEnd) || hourEnd < hourBegin
38
+            return (hasBegun && hasNotEnded)
39
+        }
40
+        return false
41
+    }
42
+
43
+    override fun toString(): String {
44
+        return "Title: $title, time info (periodicity, begin, end): $periodicity, $hourBegin, $hourEnd"
45
+    }
46
+
47
+    init {
48
+        Log.d(tag, this.toString())
49
+    }
50
+}

+ 57 - 0
app/src/main/java/fr/forum_thalie/tsumugi/ui/songs/ProgrammeFragment.kt Voir le fichier

@@ -0,0 +1,57 @@
1
+package fr.forum_thalie.tsumugi.ui.songs
2
+
3
+import android.os.Bundle
4
+import android.view.LayoutInflater
5
+import android.view.View
6
+import android.view.ViewGroup
7
+import androidx.fragment.app.Fragment
8
+import androidx.recyclerview.widget.LinearLayoutManager
9
+import androidx.recyclerview.widget.RecyclerView
10
+import fr.forum_thalie.tsumugi.R
11
+import fr.forum_thalie.tsumugi.playerstore.PlayerStore
12
+import fr.forum_thalie.tsumugi.ui.songs.queuelp.LastPlayedFragment
13
+import fr.forum_thalie.tsumugi.ui.songs.queuelp.SongAdaptater
14
+
15
+class ProgrammeFragment  : Fragment() {
16
+
17
+    private lateinit var recyclerView: RecyclerView
18
+    private lateinit var viewAdapter: RecyclerView.Adapter<*>
19
+    private lateinit var viewManager: RecyclerView.LayoutManager
20
+
21
+    override fun onCreateView(
22
+        inflater: LayoutInflater, container: ViewGroup?,
23
+        savedInstanceState: Bundle?
24
+    ): View? {
25
+        // Inflate the layout for this fragment
26
+        val root = inflater.inflate(R.layout.fragment_programme, container, false)
27
+
28
+        /*
29
+        viewManager = LinearLayoutManager(context)
30
+        viewAdapter = SongAdaptater(PlayerStore.instance.lp)
31
+
32
+        recyclerView = root.findViewById<RecyclerView>(R.id.queue_lp_recycler).apply {
33
+            // use this setting to improve performance if you know that changes
34
+            // in content do not change the layout size of the RecyclerView
35
+            setHasFixedSize(true)
36
+
37
+            // use a linear layout manager
38
+            layoutManager = viewManager
39
+
40
+            // specify an viewAdapter (see also next example)
41
+            adapter = viewAdapter
42
+        }
43
+
44
+         */
45
+
46
+        return root
47
+    }
48
+
49
+    override fun onDestroyView() {
50
+        super.onDestroyView()
51
+    }
52
+
53
+    companion object {
54
+        @JvmStatic
55
+        fun newInstance() = LastPlayedFragment()
56
+    }
57
+}

+ 3 - 1
app/src/main/java/fr/forum_thalie/tsumugi/ui/songs/SongsFragment.kt Voir le fichier

@@ -27,9 +27,11 @@ class SongsFragment : Fragment() {
27 27
         root = inflater.inflate(R.layout.fragment_songs, container, false)
28 28
         viewPager = root.findViewById(R.id.tabPager)
29 29
         adapter = SongsPagerAdapter(childFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)
30
-        adapter.addFragment(LastPlayedFragment.newInstance(), "last played")
30
+        adapter.addFragment(LastPlayedFragment.newInstance(), getString(R.string.lp))
31 31
 
32 32
         // You can add more fragments to the adapter, to display more information (for example with R/a/dio, queue, request, faves...)
33
+        adapter.addFragment(ProgrammeFragment.newInstance(), getString(R.string.programme))
34
+
33 35
 
34 36
         viewPager.adapter = adapter
35 37
 

+ 7 - 0
app/src/main/res/layout/fragment_programme.xml Voir le fichier

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.constraintlayout.widget.ConstraintLayout
3
+    xmlns:android="http://schemas.android.com/apk/res/android"
4
+    android:orientation="vertical" android:layout_width="match_parent"
5
+    android:layout_height="match_parent">
6
+
7
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 1
app/src/main/res/values/strings.xml Voir le fichier

@@ -13,7 +13,6 @@
13 13
     <string name="STREAM_URL_RSTLSS">http://stream.radiosolution.fr/rstlss.mp3</string>
14 14
 
15 15
     <string name="volume">Volume: </string>
16
-    <string name="MAIN_API">https://r-a-d.io/api</string>
17 16
 
18 17
     <string name="up_next">Up next:</string>
19 18
     <string name="now_streaming">Now streaming</string>
@@ -47,5 +46,7 @@
47 46
     <string name="select_one_day">Select at least one day</string>
48 47
     <string name="no_alarm_set">No alarm set</string>
49 48
     <string name="next_alarm">Next alarm:</string>
49
+    <string name="lp">Last played</string>
50
+    <string name="programme">Programme</string>
50 51
 
51 52
 </resources>