moved URLs in string.xml
parent
4a2aedd57f
commit
f5e0034302
|
|
@ -74,6 +74,7 @@ class MainActivity : BaseActivity() {
|
|||
// Handle item selection
|
||||
return when (item.itemId) {
|
||||
/*
|
||||
// You can add more actions. This one is used in R/a/dio app Radio2.
|
||||
R.id.action_refresh -> {
|
||||
PlayerStore.instance.queue.clear()
|
||||
PlayerStore.instance.lp.clear()
|
||||
|
|
@ -89,7 +90,7 @@ class MainActivity : BaseActivity() {
|
|||
}
|
||||
R.id.action_sleep -> {
|
||||
val i = Intent(this, ParametersActivity::class.java)
|
||||
i.putExtra("action", ActionOpenParam.SLEEP.name) // TODO change value with Actions.something
|
||||
i.putExtra("action", ActionOpenParam.SLEEP.name)
|
||||
startActivity(i)
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class NewsFragment : Fragment() {
|
|||
newsViewModel.root = inflater.inflate(R.layout.fragment_news, container, false)
|
||||
newsViewModel.webView = newsViewModel.root.findViewById(R.id.news_webview)
|
||||
newsViewModel.webViewNews = WebViewNews(newsViewModel.webView as WebView)
|
||||
newsViewModel.webViewNews!!.start()
|
||||
newsViewModel.webViewNews!!.start(getString(R.string.website_url))
|
||||
} catch (e: Exception) {
|
||||
newsViewModel.root = inflater.inflate(R.layout.fragment_error_webview, container, false)
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ class NewsFragment : Fragment() {
|
|||
|
||||
root.setOnRefreshListener {
|
||||
|
||||
newsViewModel.fetch(root, viewAdapter)
|
||||
newsViewModel.fetch(root, viewAdapter, context!!)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ class NewsFragment : Fragment() {
|
|||
newsViewModel =
|
||||
ViewModelProviders.of(this).get(NewsViewModel::class.java)
|
||||
|
||||
newsViewModel.fetch()
|
||||
newsViewModel.fetch(c = context!!)
|
||||
Log.d(tag, "news fetched onCreate")
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.forum_thalie.tsumugi.ui.news
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
|
|
@ -8,6 +9,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.prof.rssparser.Parser
|
||||
import fr.forum_thalie.tsumugi.Async
|
||||
import fr.forum_thalie.tsumugi.R
|
||||
import fr.forum_thalie.tsumugi.tag
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -31,35 +33,12 @@ class NewsViewModel : ViewModel() {
|
|||
val newsArray : ArrayList<News> = ArrayList()
|
||||
var isWebViewLoaded = false
|
||||
|
||||
private val urlToScrape = "https://tsumugi.forum-thalie.fr/?feed=rss2"
|
||||
|
||||
private val scrape : (Any?) -> Unit =
|
||||
{
|
||||
val t = URL(urlToScrape).readText()
|
||||
val result = JSONArray(t)
|
||||
newsArray.clear()
|
||||
for (n in 0 until result.length())
|
||||
{
|
||||
val news = News()
|
||||
news.title = (result[n] as JSONObject).getString("title")
|
||||
news.author = (result[n] as JSONObject).getJSONObject("author").getString("user")
|
||||
news.text = (result[n] as JSONObject).getString("text")
|
||||
news.header = (result[n] as JSONObject).getString("header")
|
||||
|
||||
val formatter6 = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
|
||||
news.date = formatter6.parse((result[n] as JSONObject).getString("updated_at")) ?: Date()
|
||||
|
||||
Log.d(tag, "$news")
|
||||
newsArray.add(news)
|
||||
}
|
||||
}
|
||||
|
||||
private val viewModelJob = Job()
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Main + viewModelJob)
|
||||
|
||||
fun fetch(root: androidx.swiperefreshlayout.widget.SwipeRefreshLayout? = null, viewAdapter: RecyclerView.Adapter<*>? = null)
|
||||
fun fetch(root: androidx.swiperefreshlayout.widget.SwipeRefreshLayout? = null, viewAdapter: RecyclerView.Adapter<*>? = null, c: Context)
|
||||
{
|
||||
val urlToScrape = c.getString(R.string.rss_url)
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT)
|
||||
return // the RSS Parser does not support API20- because of no TLS v1.2
|
||||
|
||||
|
|
@ -90,7 +69,7 @@ class NewsViewModel : ViewModel() {
|
|||
}
|
||||
// The list contains all article's data. For example you can use it for your adapter.
|
||||
root?.isRefreshing = false
|
||||
|
||||
viewAdapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import android.webkit.WebView
|
|||
class WebViewNews(private val webView: WebView) {
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
fun start() {
|
||||
fun start(url: String) {
|
||||
|
||||
val webSetting = this.webView.settings
|
||||
webSetting.javaScriptEnabled = true
|
||||
|
|
@ -36,7 +36,7 @@ class WebViewNews(private val webView: WebView) {
|
|||
}
|
||||
}
|
||||
|
||||
webView.loadUrl("https://tsumugi.forum-thalie.fr/")
|
||||
webView.loadUrl(url)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,5 +41,7 @@
|
|||
<string name="action_alarm">Alarm</string>
|
||||
<string name="sleep_fade_out_text">One minute before the end of the timer, the volume will gradually decrease.</string>
|
||||
<string name="disable">Disable</string>
|
||||
<string name="website_url">https://tsumugi.forum-thalie.fr/</string>
|
||||
<string name="rss_url">https://tsumugi.forum-thalie.fr/?feed=rss2</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue