Archived
Unfinished news fragment, will probably be deleted
This commit is contained in:
@@ -39,6 +39,7 @@ dependencies {
|
||||
|
||||
implementation 'com.jaredrummler:android-device-names:1.1.8'
|
||||
implementation 'com.github.mukeshsolanki:easypreferences:1.0.6'
|
||||
implementation 'com.romandanylyk:pageindicatorview:1.0.3@aar'
|
||||
|
||||
def lifecycle_version = "2.0.0"
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.select.Elements
|
||||
import java.lang.IndexOutOfBoundsException
|
||||
import java.lang.NullPointerException
|
||||
import java.net.URL
|
||||
import java.net.URLConnection
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
@@ -93,7 +93,7 @@ class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
val mRootView = rootView
|
||||
private val fadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out)
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var exceptionOccured = false
|
||||
private var exceptionOccurred = false
|
||||
|
||||
override fun doInBackground(vararg params: Void?): Void? {
|
||||
try {
|
||||
@@ -156,14 +156,14 @@ class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
progressBar.progress = 100
|
||||
|
||||
mEasyPrefs.putListString("foodListPrefs", foodList)
|
||||
} catch (e: Exception) { exceptionOccured = true }
|
||||
} catch (e: Exception) { exceptionOccurred = true }
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Void?) {
|
||||
super.onPostExecute(result)
|
||||
|
||||
if (!exceptionOccured) {
|
||||
if (!exceptionOccurred) {
|
||||
try {
|
||||
mRecyclerView.removeAllViews()
|
||||
mFoodArrayList.removeAll(mFoodArrayList)
|
||||
@@ -196,6 +196,4 @@ class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
@@ -128,9 +129,7 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
bottomSheetCloser.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
}
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
||||
})
|
||||
|
||||
bottomSheetCloser.setOnClickListener {
|
||||
@@ -276,12 +275,14 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
toolbarTxt.text = getString(R.string.foodmenu)
|
||||
}
|
||||
R.id.openinfopanel -> {
|
||||
if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
} else if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
fragmentLoading = false
|
||||
// if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
// bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
// } else if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
// bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
// }
|
||||
// fragmentLoading = false
|
||||
fragment = NewsFragment()
|
||||
toolbarTxt.text = getString(R.string.news)
|
||||
}
|
||||
R.id.settings -> {
|
||||
fragment = SettingsFragment()
|
||||
@@ -317,6 +318,15 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
}
|
||||
} catch (e: NullPointerException) {}
|
||||
}
|
||||
R.id.openinfopanel -> {
|
||||
try {
|
||||
val nsvnewscard = findViewById<NestedScrollView>(R.id.nsvnewscard)
|
||||
nsvnewscard.post {
|
||||
nsvnewscard.smoothScrollTo(0, 0)
|
||||
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
} catch (e: NullPointerException) {}
|
||||
}
|
||||
R.id.settings -> {
|
||||
try {
|
||||
val nsv = findViewById<NestedScrollView>(R.id.nsvsettings)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
class News(val title: String, val content: String)
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
|
||||
import java.util.ArrayList
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class NewsAdapter(news: ArrayList<News>) : RecyclerView.Adapter<NewsAdapter.CardViewHolder>() {
|
||||
private var mNews: List<News>? = null
|
||||
|
||||
class CardViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var title = itemView.findViewById<TextView>(R.id.title)
|
||||
var content = itemView.findViewById<TextView>(R.id.content)
|
||||
}
|
||||
|
||||
init {
|
||||
mNews = news
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardViewHolder {
|
||||
val v = LayoutInflater.from(parent.context).inflate(R.layout.news_card, parent, false)
|
||||
return CardViewHolder(v)
|
||||
}
|
||||
|
||||
fun getNewsAt(i: Int): News {
|
||||
return mNews!![i]
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CardViewHolder, position: Int) {
|
||||
val currentItem = mNews!![position]
|
||||
|
||||
holder.title.text = currentItem.title
|
||||
holder.content.text = currentItem.content
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return mNews!!.size
|
||||
}
|
||||
|
||||
fun setNews(news: List<News>) {
|
||||
mNews = news
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ProgressBar
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.madapps.prefrences.EasyPrefrences
|
||||
import com.rd.PageIndicatorView
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.select.Elements
|
||||
import java.lang.IndexOutOfBoundsException
|
||||
|
||||
|
||||
|
||||
class NewsFragment : Fragment(R.layout.news) {
|
||||
|
||||
private lateinit var mContext: Context
|
||||
private lateinit var prefs: SharedPreferences
|
||||
private lateinit var edit: SharedPreferences.Editor
|
||||
private lateinit var easyPrefs: EasyPrefrences
|
||||
private lateinit var pageIndicatorView: PageIndicatorView
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
mContext = context
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
edit = prefs.edit()
|
||||
easyPrefs = EasyPrefrences(mContext)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { // TODO go on stackoverflow and get the necessary code lol
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh)
|
||||
|
||||
val viewPager2 = view.findViewById<ViewPager2>(R.id.viewPager2)
|
||||
val list = ArrayList<News>()
|
||||
val adapter = NewsAdapter(list)
|
||||
viewPager2.orientation = ViewPager2.ORIENTATION_HORIZONTAL
|
||||
viewPager2.adapter = adapter
|
||||
|
||||
pageIndicatorView = view.findViewById(R.id.indicator)
|
||||
|
||||
viewPager2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
pageIndicatorView.selection = position
|
||||
}
|
||||
})
|
||||
|
||||
pageIndicatorView.count = 0
|
||||
pageIndicatorView.selection = 0
|
||||
|
||||
pullToRefresh.isRefreshing = true
|
||||
FetchNews(mContext, adapter, list, pageIndicatorView, viewPager2, pullToRefresh, view.rootView).execute()
|
||||
|
||||
pullToRefresh.setOnRefreshListener {
|
||||
pullToRefresh.isRefreshing = true
|
||||
FetchNews(mContext, adapter, list, pageIndicatorView, viewPager2, pullToRefresh, view.rootView).execute()
|
||||
}
|
||||
}
|
||||
|
||||
class FetchNews(context: Context, adapter: NewsAdapter, arrayList: ArrayList<News>, pageIndicatorView: PageIndicatorView, viewPager2: ViewPager2,
|
||||
swipeRefreshLayout: SwipeRefreshLayout, rootView: View) : AsyncTask<Void, Void, Void>() {
|
||||
|
||||
private val mContext = context
|
||||
private val mAdapter = adapter
|
||||
private val mArrayList = arrayList
|
||||
private val mPageIndicatorView = pageIndicatorView
|
||||
private val mViewPager2 = viewPager2
|
||||
private val frameLayout = rootView.findViewById<FrameLayout>(R.id.frameLayoutNews)
|
||||
private var foodList = ArrayList<String>()
|
||||
private lateinit var foodElements: Elements
|
||||
private lateinit var doc: Document
|
||||
private val pullToRefresh = swipeRefreshLayout
|
||||
private lateinit var progressBar: ProgressBar
|
||||
val mRootView = rootView
|
||||
private val fadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out)
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var exceptionOccured = false
|
||||
private var size = 0
|
||||
|
||||
override fun doInBackground(vararg params: Void?): Void? {
|
||||
try {
|
||||
doc = Jsoup.connect("http://307.joomla.schule.bremen.de/index.php/schulleben/aktuelles").maxBodySize(0).get()
|
||||
val blog = doc.getElementsByClass("blog").first()
|
||||
val a = blog.getElementsByTag("h2")
|
||||
|
||||
size = a.size
|
||||
|
||||
for (i in 0 until a.size) {
|
||||
// var searching = true
|
||||
var content = ""
|
||||
for (e in a[i].parent().parent().getElementsByTag("p")) {
|
||||
if (e.text().isNotEmpty()) {
|
||||
if (content.isEmpty()) {
|
||||
content = e.text()
|
||||
} else {
|
||||
content += "\n\n" + e.text()
|
||||
}
|
||||
}
|
||||
}
|
||||
mArrayList.add(News(a[i].text(), content))
|
||||
}
|
||||
|
||||
} catch (e: Exception) { exceptionOccured = true }
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Void?) {
|
||||
super.onPostExecute(result)
|
||||
|
||||
if (!exceptionOccured) {
|
||||
mAdapter.setNews(mArrayList)
|
||||
frameLayout.scheduleLayoutAnimation()
|
||||
mPageIndicatorView.count = size
|
||||
mPageIndicatorView.selection = 0
|
||||
mViewPager2.setCurrentItem(0, true)
|
||||
pullToRefresh.isRefreshing = false
|
||||
|
||||
} else {
|
||||
pullToRefresh.isRefreshing = false
|
||||
val snackbarview = mRootView.findViewById<View>(R.id.coordination)
|
||||
Snackbar.make(snackbarview, mContext.getText(R.string.nointernet), Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,6 +199,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
createDialog("Licences", "Libraries:\n • Android Device Names © 2015 Jared Rummler, licensed under the Apache Licence, Version 2.0" +
|
||||
"\n • EasyPreferences © 2018 Mukesh Solanki, licensed under the MIT Licence" +
|
||||
"\n • jsoup HTML parser © 2009-2018 Jonathan Hedley, licensed under the open source MIT Licence" +
|
||||
"\n • PageIndicatorView © 2017 Roman Danylyk, licensed under the Apache Licence, Version 2.0" +
|
||||
"\n\nFont:\n • Manrope © 2018-2019 Michael Sharanda, licensed under the SIL Open Font Licence 1.1" +
|
||||
"\n\nIcons:\n • bqlqn\n • fjstudio\n • Freepik\n • Smashicons\n • © 2013-2019 Freepik Company S.L., licensed under Creative Commons BY 3.0" +
|
||||
"\n\nMarketing & Publishing:\n • Leon Becker\n • Alex Lick\n • Batuhan Özcan\n • Erich Kerkesner")
|
||||
@@ -387,7 +388,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
}
|
||||
"2018-04-20" -> {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=u8tdT5pAE34"))
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=Jc2xfYuLWgE"))
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setPackage("com.google.android.youtube")
|
||||
startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:backgroundTint="@color/lightbackground"
|
||||
app:cardCornerRadius="4dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_marginStart="8dp"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/pullToRefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@color/background">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/frameLayoutNews"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layoutAnimation="@anim/layout_animation_fall_down">
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/viewPager2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.rd.PageIndicatorView
|
||||
android:id="@+id/indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
app:piv_animationType="worm"
|
||||
app:piv_dynamicCount="true"
|
||||
app:piv_interactiveAnimation="true"
|
||||
app:piv_selectedColor="@color/accent"
|
||||
app:piv_unselectedColor="@color/hintcolor"
|
||||
app:piv_viewPager="@+id/viewPager2"
|
||||
app:piv_padding="8dp"
|
||||
app:piv_radius="4dp"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/linearNews"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/nsvnewscard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/lightbackground"
|
||||
app:cardCornerRadius="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:cardElevation="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/textcolor"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/textcolor"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -19,7 +19,7 @@
|
||||
<item
|
||||
android:id="@+id/openinfopanel"
|
||||
android:icon="@drawable/ic_information"
|
||||
android:title=""
|
||||
android:title="@string/news"
|
||||
android:enabled="true"/>
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
|
||||
@@ -121,4 +121,5 @@
|
||||
<string name="showinfo">Zeige Info-Tab in Navigationsleisete</string>
|
||||
<string name="lastupdatedK">"Zuletzt aktualisiert: "</string>
|
||||
<string name="darkmode2">Aktiviert den Nachtmodus</string>
|
||||
<string name="news">News (Alpha)</string>
|
||||
</resources>
|
||||
@@ -140,4 +140,6 @@
|
||||
|
||||
<string name="darkmode2">Enables night mode</string>
|
||||
|
||||
<string name="news">News (Alpha)</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user