Sfoglia il codice sorgente

moved URLs in string.xml

yattoz 4 anni fa
parent
commit
f5e0034302

+ 2 - 1
app/src/main/java/fr/forum_thalie/tsumugi/MainActivity.kt Vedi File

@@ -74,6 +74,7 @@ class MainActivity : BaseActivity() {
74 74
         // Handle item selection
75 75
         return when (item.itemId) {
76 76
             /*
77
+            // You can add more actions. This one is used in R/a/dio app Radio2.
77 78
             R.id.action_refresh -> {
78 79
                 PlayerStore.instance.queue.clear()
79 80
                 PlayerStore.instance.lp.clear()
@@ -89,7 +90,7 @@ class MainActivity : BaseActivity() {
89 90
             }
90 91
             R.id.action_sleep -> {
91 92
                 val i = Intent(this, ParametersActivity::class.java)
92
-                i.putExtra("action", ActionOpenParam.SLEEP.name) // TODO change value with Actions.something
93
+                i.putExtra("action", ActionOpenParam.SLEEP.name)
93 94
                 startActivity(i)
94 95
                 true
95 96
             }

+ 3 - 3
app/src/main/java/fr/forum_thalie/tsumugi/ui/news/NewsFragment.kt Vedi File

@@ -36,7 +36,7 @@ class NewsFragment : Fragment() {
36 36
                     newsViewModel.root = inflater.inflate(R.layout.fragment_news, container, false)
37 37
                     newsViewModel.webView = newsViewModel.root.findViewById(R.id.news_webview)
38 38
                     newsViewModel.webViewNews = WebViewNews(newsViewModel.webView as WebView)
39
-                    newsViewModel.webViewNews!!.start()
39
+                    newsViewModel.webViewNews!!.start(getString(R.string.website_url))
40 40
                 } catch (e: Exception) {
41 41
                     newsViewModel.root = inflater.inflate(R.layout.fragment_error_webview, container, false)
42 42
                 }
@@ -71,7 +71,7 @@ class NewsFragment : Fragment() {
71 71
 
72 72
         root.setOnRefreshListener {
73 73
 
74
-            newsViewModel.fetch(root, viewAdapter)
74
+            newsViewModel.fetch(root, viewAdapter, context!!)
75 75
 
76 76
         }
77 77
 
@@ -82,7 +82,7 @@ class NewsFragment : Fragment() {
82 82
         newsViewModel =
83 83
             ViewModelProviders.of(this).get(NewsViewModel::class.java)
84 84
 
85
-        newsViewModel.fetch()
85
+        newsViewModel.fetch(c = context!!)
86 86
         Log.d(tag, "news fetched onCreate")
87 87
         super.onCreate(savedInstanceState)
88 88
     }

+ 5 - 26
app/src/main/java/fr/forum_thalie/tsumugi/ui/news/NewsViewModel.kt Vedi File

@@ -1,5 +1,6 @@
1 1
 package fr.forum_thalie.tsumugi.ui.news
2 2
 
3
+import android.content.Context
3 4
 import android.os.Build
4 5
 import android.util.Log
5 6
 import android.view.View
@@ -8,6 +9,7 @@ import androidx.lifecycle.ViewModel
8 9
 import androidx.recyclerview.widget.RecyclerView
9 10
 import com.prof.rssparser.Parser
10 11
 import fr.forum_thalie.tsumugi.Async
12
+import fr.forum_thalie.tsumugi.R
11 13
 import fr.forum_thalie.tsumugi.tag
12 14
 import kotlinx.coroutines.CoroutineScope
13 15
 import kotlinx.coroutines.Dispatchers
@@ -31,35 +33,12 @@ class NewsViewModel : ViewModel() {
31 33
     val newsArray : ArrayList<News> = ArrayList()
32 34
     var isWebViewLoaded = false
33 35
 
34
-    private val urlToScrape = "https://tsumugi.forum-thalie.fr/?feed=rss2"
35
-
36
-    private val scrape : (Any?) -> Unit =
37
-    {
38
-        val t = URL(urlToScrape).readText()
39
-        val result = JSONArray(t)
40
-        newsArray.clear()
41
-        for (n in 0 until result.length())
42
-        {
43
-            val news = News()
44
-            news.title = (result[n] as JSONObject).getString("title")
45
-            news.author = (result[n] as JSONObject).getJSONObject("author").getString("user")
46
-            news.text = (result[n] as JSONObject).getString("text")
47
-            news.header = (result[n] as JSONObject).getString("header")
48
-
49
-            val formatter6 = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
50
-
51
-            news.date = formatter6.parse((result[n] as JSONObject).getString("updated_at")) ?: Date()
52
-
53
-            Log.d(tag, "$news")
54
-            newsArray.add(news)
55
-        }
56
-    }
57
-
58 36
     private val viewModelJob = Job()
59 37
     private val coroutineScope = CoroutineScope(Dispatchers.Main + viewModelJob)
60 38
 
61
-    fun fetch(root: androidx.swiperefreshlayout.widget.SwipeRefreshLayout? = null, viewAdapter: RecyclerView.Adapter<*>? = null)
39
+    fun fetch(root: androidx.swiperefreshlayout.widget.SwipeRefreshLayout? = null, viewAdapter: RecyclerView.Adapter<*>? = null, c: Context)
62 40
     {
41
+        val urlToScrape = c.getString(R.string.rss_url)
63 42
         if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT)
64 43
             return // the RSS Parser does not support API20- because of no TLS v1.2
65 44
 
@@ -90,7 +69,7 @@ class NewsViewModel : ViewModel() {
90 69
                 }
91 70
                 // The list contains all article's data. For example you can use it for your adapter.
92 71
                 root?.isRefreshing = false
93
-
72
+                viewAdapter?.notifyDataSetChanged()
94 73
         }
95 74
     }
96 75
 }

+ 2 - 2
app/src/main/java/fr/forum_thalie/tsumugi/ui/news/WebViewNews.kt Vedi File

@@ -9,7 +9,7 @@ import android.webkit.WebView
9 9
 class WebViewNews(private val webView: WebView) {
10 10
 
11 11
     @SuppressLint("SetJavaScriptEnabled")
12
-    fun start() {
12
+    fun start(url: String) {
13 13
 
14 14
         val webSetting = this.webView.settings
15 15
         webSetting.javaScriptEnabled = true
@@ -36,7 +36,7 @@ class WebViewNews(private val webView: WebView) {
36 36
             }
37 37
         }
38 38
 
39
-        webView.loadUrl("https://tsumugi.forum-thalie.fr/")
39
+        webView.loadUrl(url)
40 40
     }
41 41
 
42 42
 }

+ 2 - 0
app/src/main/res/values/strings.xml Vedi File

@@ -41,5 +41,7 @@
41 41
     <string name="action_alarm">Alarm</string>
42 42
     <string name="sleep_fade_out_text">One minute before the end of the timer, the volume will gradually decrease.</string>
43 43
     <string name="disable">Disable</string>
44
+    <string name="website_url">https://tsumugi.forum-thalie.fr/</string>
45
+    <string name="rss_url">https://tsumugi.forum-thalie.fr/?feed=rss2</string>
44 46
 
45 47
 </resources>