Fixed overlapping app bar, news fragment removed

This commit is contained in:
Deniz Düzgören
2019-06-15 09:26:11 +02:00
parent e93683263d
commit d3f6a7f2d8
10 changed files with 8 additions and 313 deletions
@@ -275,14 +275,12 @@ class Main : AppCompatActivity(R.layout.activity_main) {
toolbarTxt.text = getString(R.string.foodmenu) toolbarTxt.text = getString(R.string.foodmenu)
} }
R.id.openinfopanel -> { R.id.openinfopanel -> {
// if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_COLLAPSED) { if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_COLLAPSED) {
// bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
// } else if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) { } else if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
// bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
// } }
// fragmentLoading = false fragmentLoading = false
fragment = NewsFragment()
toolbarTxt.text = getString(R.string.news)
} }
R.id.settings -> { R.id.settings -> {
fragment = SettingsFragment() fragment = SettingsFragment()
@@ -318,15 +316,6 @@ class Main : AppCompatActivity(R.layout.activity_main) {
} }
} catch (e: NullPointerException) {} } 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 -> { R.id.settings -> {
try { try {
val nsv = findViewById<NestedScrollView>(R.id.nsvsettings) val nsv = findViewById<NestedScrollView>(R.id.nsvsettings)
@@ -1,3 +0,0 @@
package com.denizd.substitutionplan
class News(val title: String, val content: String)
@@ -1,47 +0,0 @@
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()
}
}
@@ -1,144 +0,0 @@
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()
}
}
}
}
+1 -2
View File
@@ -11,8 +11,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppThemeLight.AppBarOverlay" android:theme="@style/AppThemeLight.AppBarOverlay"
app:elevation="0dp" app:elevation="0dp">
android:translationZ="0.1dp">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
-38
View File
@@ -1,38 +0,0 @@
<?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>
-58
View File
@@ -1,58 +0,0 @@
<?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>
+1 -1
View File
@@ -19,7 +19,7 @@
<item <item
android:id="@+id/openinfopanel" android:id="@+id/openinfopanel"
android:icon="@drawable/ic_information" android:icon="@drawable/ic_information"
android:title="@string/news" android:title=""
android:enabled="true"/> android:enabled="true"/>
<item <item
android:id="@+id/settings" android:id="@+id/settings"
-1
View File
@@ -121,5 +121,4 @@
<string name="showinfo">Zeige Info-Tab in Navigationsleisete</string> <string name="showinfo">Zeige Info-Tab in Navigationsleisete</string>
<string name="lastupdatedK">"Zuletzt aktualisiert: "</string> <string name="lastupdatedK">"Zuletzt aktualisiert: "</string>
<string name="darkmode2">Aktiviert den Nachtmodus</string> <string name="darkmode2">Aktiviert den Nachtmodus</string>
<string name="news">News (Alpha)</string>
</resources> </resources>
-2
View File
@@ -140,6 +140,4 @@
<string name="darkmode2">Enables night mode</string> <string name="darkmode2">Enables night mode</string>
<string name="news">News (Alpha)</string>
</resources> </resources>