Fragment transition animations, information dialog, SettingsFragment implements OnCheckedChangeListener

This commit is contained in:
Deniz Düzgören
2019-07-30 16:58:51 +02:00
parent 2fb0506db9
commit b82f595bdf
16 changed files with 138 additions and 343 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
+2 -6
View File
@@ -10,7 +10,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 17 versionCode 17
versionName "2.0.5" versionName "2.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@@ -20,10 +20,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
} }
dependencies { dependencies {
@@ -36,7 +32,7 @@ dependencies {
implementation 'org.jsoup:jsoup:1.11.3' implementation 'org.jsoup:jsoup:1.11.3'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01' implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01'
implementation 'com.google.android.material:material:1.1.0-alpha08' implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'com.android.support:customtabs:28.0.0' implementation 'com.android.support:customtabs:28.0.0'
// implementation 'androidx.core:core-ktx:1.0.2' // implementation 'androidx.core:core-ktx:1.0.2'
@@ -21,9 +21,6 @@ import com.google.android.material.snackbar.Snackbar
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.select.Elements import org.jsoup.select.Elements
import java.lang.IndexOutOfBoundsException import java.lang.IndexOutOfBoundsException
import java.net.URL
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, context: Context, application: Application, parentview: View?) : AsyncTask<Void, Void, Void>() { class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, context: Context, application: Application, parentview: View?) : AsyncTask<Void, Void, Void>() {
@@ -139,7 +136,7 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
if (plan) { if (plan) {
val substViewModel = SubstViewModel(mApplication) val substViewModel = SubstViewModel(mApplication)
val doc = Jsoup.connect("https://djd4rkn355.github.io/subst_test").get() val doc = Jsoup.connect("https://djd4rkn355.github.io/subst_test").get()
currentTime = doc.select("h1").text() currentTime = doc.select("h1")[0].text()
if (currentTime != prefs.getString("time", "")) { if (currentTime != prefs.getString("time", "")) {
val rows = doc.select("tr") val rows = doc.select("tr")
val paragraphs = doc.select("p") val paragraphs = doc.select("p")
@@ -12,7 +12,6 @@ class GeneralPlanFragment : PlanFragment() {
substViewModel.allSubst?.observe(this, Observer<List<Subst>> { substViewModel.allSubst?.observe(this, Observer<List<Subst>> {
mAdapter.setSubst(it) mAdapter.setSubst(it)
recyclerView.scheduleLayoutAnimation() recyclerView.scheduleLayoutAnimation()
bottomSheetText.text = prefs.getString("informational", getString(R.string.noinfo))
}) })
} }
} }
@@ -1,37 +1,27 @@
package com.denizd.substitutionplan package com.denizd.substitutionplan
import android.app.ActivityManager
import android.app.job.JobInfo import android.app.job.JobInfo
import android.app.job.JobScheduler import android.app.job.JobScheduler
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.res.Configuration
import android.graphics.BitmapFactory
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.util.AttributeSet
import android.view.* import android.view.*
import android.view.animation.Animation import android.view.animation.Animation
import android.view.animation.AnimationUtils import android.view.animation.AnimationUtils
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
@@ -39,18 +29,18 @@ import com.google.android.material.chip.Chip
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.jaredrummler.android.device.DeviceName import com.jaredrummler.android.device.DeviceName
import java.lang.IllegalArgumentException import java.lang.IllegalArgumentException
import java.text.SimpleDateFormat
import java.util.* import java.util.*
class Main : AppCompatActivity(R.layout.activity_main) { class Main : AppCompatActivity(R.layout.app_bar_main) {
private var bottomSheetExpanded = false
private lateinit var bottomSheetBehaviour: BottomSheetBehavior<*> private lateinit var bottomSheetBehaviour: BottomSheetBehavior<*>
private lateinit var context: Context
private lateinit var prefs: SharedPreferences
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val context = this as Context context = this
val prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences
val edit = prefs.edit() val edit = prefs.edit()
val firstTime = Intent(context, FirstTime::class.java) val firstTime = Intent(context, FirstTime::class.java)
@@ -67,19 +57,17 @@ class Main : AppCompatActivity(R.layout.activity_main) {
val appbarlayout = findViewById<AppBarLayout>(R.id.appbarlayout) val appbarlayout = findViewById<AppBarLayout>(R.id.appbarlayout)
val toolbarTxt = findViewById<TextView>(R.id.toolbarTxt) val toolbarTxt = findViewById<TextView>(R.id.toolbarTxt)
val bottomSheetRoot = findViewById<LinearLayout>(R.id.bottom_sheet)
bottomSheetBehaviour = BottomSheetBehavior.from(bottomSheetRoot)
val bottomNav = findViewById<BottomNavigationView>(R.id.bottom_nav) val bottomNav = findViewById<BottomNavigationView>(R.id.bottom_nav)
val fragmentContainer = findViewById<CoordinatorLayout>(R.id.fragment_container)
val bottomSheetCloser = findViewById<LinearLayout>(R.id.bottom_sheet_closer)
val chip = findViewById<Chip>(R.id.chip) val chip = findViewById<Chip>(R.id.chip)
val contextView = findViewById<View>(R.id.coordination) val contextView = findViewById<View>(R.id.coordination)
val window = this.window as Window val window = this.window as Window
bottomSheetExpanded = bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED
setTheme(R.style.AppTheme0) setTheme(R.style.AppTheme0)
if (prefs.getBoolean("openInfo", false)) {
openInfoDialog()
}
when (prefs.getInt("themeInt", 0)) { when (prefs.getInt("themeInt", 0)) {
0 -> { 0 -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
@@ -109,42 +97,10 @@ class Main : AppCompatActivity(R.layout.activity_main) {
// } // TODO theming based on system settings for Android Q // } // TODO theming based on system settings for Android Q
} }
if (!prefs.getBoolean("showinfotab", true)) {
bottomNav.menu.removeItem(R.id.openinfopanel)
}
fragmentContainer.setOnClickListener {
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_COLLAPSED)
}
bottomSheetBehaviour.setBottomSheetCallback(object: BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetCloser.visibility = View.VISIBLE
} else if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_COLLAPSED) {
bottomSheetCloser.visibility = View.GONE
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
})
bottomSheetCloser.setOnClickListener {
bottomSheetCloser.visibility = View.GONE
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
}
if (!prefs.getBoolean("autoRefresh", false) && prefs.getInt("firstTimeOpening", 0) != 0) { if (!prefs.getBoolean("autoRefresh", false) && prefs.getInt("firstTimeOpening", 0) != 0) {
try { try {
val oldFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
val newFormat = "yyyy-MM-dd, HH:mm:ss"
val d = Date(prefs.getString("time", ""))
val sdf = SimpleDateFormat(oldFormat)
sdf.applyPattern(newFormat)
val newDate = sdf.format(d)
val sb = StringBuilder() val sb = StringBuilder()
val updated = sb.append(getText(R.string.lastupdatedK)).append(newDate).toString() val updated = sb.append(getText(R.string.lastupdatedK)).append(prefs.getString("time", "")).toString()
Snackbar.make(contextView, updated, Snackbar.LENGTH_LONG).show() Snackbar.make(contextView, updated, Snackbar.LENGTH_LONG).show()
} catch (e: IllegalArgumentException) {} } catch (e: IllegalArgumentException) {}
@@ -169,7 +125,7 @@ class Main : AppCompatActivity(R.layout.activity_main) {
} }
if (prefs.getBoolean("greeting", false)) { if (prefs.getBoolean("greeting", false)) {
if (prefs.getString("username", "").isNotEmpty()) { if ((prefs.getString("username", "") ?: "").isNotEmpty()) {
val animationIn = AnimationUtils.loadAnimation(context, R.anim.chip_slide_in) val animationIn = AnimationUtils.loadAnimation(context, R.anim.chip_slide_in)
val animationOut = AnimationUtils.loadAnimation(context, R.anim.chip_slide_out) val animationOut = AnimationUtils.loadAnimation(context, R.anim.chip_slide_out)
val generator = Random() val generator = Random()
@@ -216,43 +172,28 @@ class Main : AppCompatActivity(R.layout.activity_main) {
} }
if (prefs.getInt("firstTimeOpening", 0) == 0) { if (prefs.getInt("firstTimeOpening", 0) == 0) {
handler.postDelayed({
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
}, 600)
handler.postDelayed({
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
}, 2000)
edit.putInt("firstTimeOpening", prefs.getInt("firstTimeOpening", 0) + 1).apply() edit.putInt("firstTimeOpening", prefs.getInt("firstTimeOpening", 0) + 1).apply()
} }
if (prefs.getBoolean("openInfo", false)) { val userPlan: String = if ((prefs.getString("username", "") ?: "").toString().isNotEmpty()) {
handler.postDelayed({ when ((prefs.getString("username", "") ?: "")[(prefs.getString("username", "") ?: "").length - 1].toString().toLowerCase()) {
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED "s", "x", "z" -> (prefs.getString("username", "") ?: "") + getString(R.string.nosplan)
}, 600) else -> (prefs.getString("username", "") ?: "") + getString(R.string.splan)
}
val userPlan: String = if (prefs.getString("username", "").toString().isNotEmpty()) {
when (prefs.getString("username", "")[prefs.getString("username", "").length - 1].toString().toLowerCase()) {
"s", "x", "z" -> prefs.getString("username", "") + getString(R.string.nosplan)
else -> prefs.getString("username", "") + getString(R.string.splan)
} }
} else { } else {
getString(R.string.personalplan) getString(R.string.personalplan)
} }
lateinit var fragment: Fragment lateinit var defaultFragment: Fragment
if (prefs.getBoolean("defaultPersonalised", false)) { if (prefs.getBoolean("defaultPersonalised", false)) {
fragment = PersonalPlanFragment() defaultFragment = PersonalPlanFragment()
bottomNav.selectedItemId = R.id.personal bottomNav.selectedItemId = R.id.personal
toolbarTxt.text = userPlan toolbarTxt.text = userPlan
} else { } else {
fragment = GeneralPlanFragment() defaultFragment = GeneralPlanFragment()
bottomNav.selectedItemId = R.id.plan bottomNav.selectedItemId = R.id.plan
toolbarTxt.text = getString(R.string.app_name) toolbarTxt.text = getString(R.string.app_name)
} }
loadFragment(fragment) loadFragment(defaultFragment)
bottomNav.setOnNavigationItemSelectedListener { item: MenuItem -> bottomNav.setOnNavigationItemSelectedListener { item: MenuItem ->
var fragmentLoading = true var fragmentLoading = true
@@ -271,11 +212,7 @@ 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) { openInfoDialog()
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_EXPANDED
} else if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
}
fragmentLoading = false fragmentLoading = false
} }
R.id.settings -> { R.id.settings -> {
@@ -284,7 +221,6 @@ class Main : AppCompatActivity(R.layout.activity_main) {
} }
} }
if (fragmentLoading) { if (fragmentLoading) {
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
appbarlayout.setExpanded(true) appbarlayout.setExpanded(true)
loadFragment(fragment) loadFragment(fragment)
} else { } else {
@@ -299,8 +235,8 @@ class Main : AppCompatActivity(R.layout.activity_main) {
val recyclerView = findViewById<RecyclerView>(R.id.linearRecycler) val recyclerView = findViewById<RecyclerView>(R.id.linearRecycler)
recyclerView.post { recyclerView.post {
recyclerView.smoothScrollToPosition(0) recyclerView.smoothScrollToPosition(0)
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
} }
appbarlayout.setExpanded(true)
} catch (e: NullPointerException) {} } catch (e: NullPointerException) {}
} }
R.id.menu -> { R.id.menu -> {
@@ -308,8 +244,8 @@ class Main : AppCompatActivity(R.layout.activity_main) {
val recyclerView = findViewById<RecyclerView>(R.id.linear_food) val recyclerView = findViewById<RecyclerView>(R.id.linear_food)
recyclerView.post { recyclerView.post {
recyclerView.smoothScrollToPosition(0) recyclerView.smoothScrollToPosition(0)
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
} }
appbarlayout.setExpanded(true)
} catch (e: NullPointerException) {} } catch (e: NullPointerException) {}
} }
R.id.settings -> { R.id.settings -> {
@@ -317,18 +253,25 @@ class Main : AppCompatActivity(R.layout.activity_main) {
val nsv = findViewById<NestedScrollView>(R.id.nsvsettings) val nsv = findViewById<NestedScrollView>(R.id.nsvsettings)
nsv.post { nsv.post {
nsv.smoothScrollTo(0, 0) nsv.smoothScrollTo(0, 0)
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
} }
appbarlayout.setExpanded(true)
} catch (e: NullPointerException) {} } catch (e: NullPointerException) {}
} }
} }
appbarlayout.setExpanded(true)
} }
} }
} }
private fun openInfoDialog() {
val dialog = AlertDialog.Builder(context)
val dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null)
dialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(R.string.information)
dialogView.findViewById<TextView>(R.id.dialogtext).text = prefs.getString("informational", "")
dialog.setView(dialogView).show()
}
private fun loadFragment(fragment: Fragment): Boolean { private fun loadFragment(fragment: Fragment): Boolean {
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit() supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit()
return true return true
} }
@@ -342,12 +285,4 @@ class Main : AppCompatActivity(R.layout.activity_main) {
val scheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler val scheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
scheduler.schedule(info) scheduler.schedule(info)
} }
override fun onBackPressed() {
if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
} else {
super.onBackPressed()
}
}
} }
@@ -21,17 +21,17 @@ class PersonalPlanFragment : PlanFragment() {
persPlanEmpty = true persPlanEmpty = true
recyclerView.visibility = View.VISIBLE recyclerView.visibility = View.VISIBLE
for (i in 0 until it.size) { for (i in 0 until it.size) {
if (prefs.getString("courses", "").isEmpty() && prefs.getString("classes", "").isNotEmpty()) { if ((prefs.getString("courses", "") ?: "").isEmpty() && (prefs.getString("classes", "") ?: "").isNotEmpty()) {
if (it[i].group.isNotEmpty() && !it[i].group.equals("")) { if (it[i].group.isNotEmpty() && it[i].group != "") {
if (prefs.getString("classes", "").contains(it[i].group) || it[i].group.contains(prefs.getString("classes", "").toString())) { if ((prefs.getString("classes", "") ?: "").contains(it[i].group) || it[i].group.contains((prefs.getString("classes", "") ?: "").toString())) {
planCardList.add(it[i]) planCardList.add(it[i])
persPlanEmpty = false persPlanEmpty = false
} }
} }
} else if (prefs.getString("classes", "").isNotEmpty() && prefs.getString("courses", "").isNotEmpty()) { } else if ((prefs.getString("classes", "") ?: "").isNotEmpty() && (prefs.getString("courses", "") ?: "").isNotEmpty()) {
if (!it[i].group.equals("") && !it[i].course.equals("")) { if (it[i].group != "" && it[i].course != "") {
if (prefs.getString("courses", "").contains(it[i].course)) { if ((prefs.getString("courses", "") ?: "").contains(it[i].course)) {
if (prefs.getString("classes", "").contains(it[i].group) || it[i].group.contains(prefs.getString("classes", "").toString())) { if ((prefs.getString("classes", "") ?: "").contains(it[i].group) || it[i].group.contains((prefs.getString("classes", "") ?: "").toString())) {
planCardList.add(it[i]) planCardList.add(it[i])
persPlanEmpty = false persPlanEmpty = false
} }
@@ -10,12 +10,10 @@ import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class PlanFragment : Fragment(R.layout.plan) { open class PlanFragment : Fragment(R.layout.plan) {
@@ -23,7 +21,6 @@ open class PlanFragment : Fragment(R.layout.plan) {
lateinit var mAdapter: CardAdapter lateinit var mAdapter: CardAdapter
private lateinit var layoutManager: GridLayoutManager private lateinit var layoutManager: GridLayoutManager
val planCardList = ArrayList<Subst>() val planCardList = ArrayList<Subst>()
lateinit var bottomSheetText: TextView
lateinit var substViewModel: SubstViewModel lateinit var substViewModel: SubstViewModel
lateinit var mContext: Context lateinit var mContext: Context
lateinit var prefs: SharedPreferences lateinit var prefs: SharedPreferences
@@ -64,8 +61,6 @@ open class PlanFragment : Fragment(R.layout.plan) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh) val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh)
bottomSheetText = view.rootView.findViewById(R.id.bottom_sheet_text)
bottomSheetText.text = prefs.getString("informational", getString(R.string.noinfo))
recyclerView = view.findViewById(R.id.linearRecycler) recyclerView = view.findViewById(R.id.linearRecycler)
recyclerView.hasFixedSize() recyclerView.hasFixedSize()
@@ -100,14 +95,12 @@ open class PlanFragment : Fragment(R.layout.plan) {
if (prefs.getBoolean("autoRefresh", false)) { if (prefs.getBoolean("autoRefresh", false)) {
pullToRefresh.isRefreshing = true pullToRefresh.isRefreshing = true
DataFetcher(true, false, false, mContext, activity!!.application, view.rootView).execute() DataFetcher(true, false, false, mContext, activity!!.application, view.rootView).execute()
bottomSheetText.text = prefs.getString("informational", getString(R.string.noinfo))
} }
substViewModel = ViewModelProviders.of(this).get(SubstViewModel::class.java) substViewModel = ViewModelProviders.of(this).get(SubstViewModel::class.java)
pullToRefresh.setOnRefreshListener { pullToRefresh.setOnRefreshListener {
pullToRefresh.isRefreshing = true pullToRefresh.isRefreshing = true
DataFetcher(true, false, false, mContext, activity!!.application, view.rootView).execute() DataFetcher(true, false, false, mContext, activity!!.application, view.rootView).execute()
bottomSheetText.text = prefs.getString("informational", getString(R.string.noinfo))
} }
} }
} }
@@ -26,7 +26,7 @@ import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputEditText
import com.jaredrummler.android.device.DeviceName import com.jaredrummler.android.device.DeviceName
class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListener, ColourAdapter.OnClickListener { class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListener, CompoundButton.OnCheckedChangeListener, ColourAdapter.OnClickListener {
private lateinit var name: String private lateinit var name: String
private lateinit var model: String private lateinit var model: String
@@ -59,7 +59,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
val switchDisableGreeting = view.findViewById<Switch>(R.id.switchDisableGreeting) val switchDisableGreeting = view.findViewById<Switch>(R.id.switchDisableGreeting)
val switchDark = view.findViewById<Switch>(R.id.switchDark) val switchDark = view.findViewById<Switch>(R.id.switchDark)
val switchHideInfo = view.findViewById<Switch>(R.id.switchHideInfo)
val switchNotifications = view.findViewById<Switch>(R.id.switchNotifications) val switchNotifications = view.findViewById<Switch>(R.id.switchNotifications)
val switchDefaultPlan = view.findViewById<Switch>(R.id.switchDefaultPlan) val switchDefaultPlan = view.findViewById<Switch>(R.id.switchDefaultPlan)
val switchOpenInfo = view.findViewById<Switch>(R.id.switchOpenInfo) val switchOpenInfo = view.findViewById<Switch>(R.id.switchOpenInfo)
@@ -70,13 +69,12 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
val btnCustomiseColours = view.findViewById<LinearLayout>(R.id.btnCustomiseColours) val btnCustomiseColours = view.findViewById<LinearLayout>(R.id.btnCustomiseColours)
val btnVersion = view.findViewById<LinearLayout>(R.id.btnVersion) val btnVersion = view.findViewById<LinearLayout>(R.id.btnVersion)
switchDisableGreeting.setOnClickListener(this) switchDisableGreeting.setOnCheckedChangeListener(this)
switchDark.setOnClickListener(this) switchDark.setOnCheckedChangeListener(this)
switchHideInfo.setOnClickListener(this) switchNotifications.setOnCheckedChangeListener(this)
switchNotifications.setOnClickListener(this) switchDefaultPlan.setOnCheckedChangeListener(this)
switchDefaultPlan.setOnClickListener(this) switchOpenInfo.setOnCheckedChangeListener(this)
switchOpenInfo.setOnClickListener(this) switchAutoRefresh.setOnCheckedChangeListener(this)
switchAutoRefresh.setOnClickListener(this)
helpCourses.setOnClickListener(this) helpCourses.setOnClickListener(this)
helpClasses.setOnClickListener(this) helpClasses.setOnClickListener(this)
btnCustomiseColours.setOnClickListener(this) btnCustomiseColours.setOnClickListener(this)
@@ -91,7 +89,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
1 -> true 1 -> true
else -> false else -> false
} }
switchHideInfo.isChecked = prefs.getBoolean("showinfotab", true)
switchNotifications.isChecked = prefs.getBoolean("notif", false) switchNotifications.isChecked = prefs.getBoolean("notif", false)
switchDefaultPlan.isChecked = prefs.getBoolean("defaultPersonalised", false) switchDefaultPlan.isChecked = prefs.getBoolean("defaultPersonalised", false)
switchOpenInfo.isChecked = prefs.getBoolean("openInfo", false) switchOpenInfo.isChecked = prefs.getBoolean("openInfo", false)
@@ -136,54 +133,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
when (v?.id) { when (v?.id) {
R.id.chipHelpCourses -> createDialog(getString(R.string.helpCoursesTitle), getString(R.string.helpCourses)) R.id.chipHelpCourses -> createDialog(getString(R.string.helpCoursesTitle), getString(R.string.helpCourses))
R.id.chipHelpClasses -> createDialog(getString(R.string.helpClassesTitle), getString(R.string.helpClasses)) R.id.chipHelpClasses -> createDialog(getString(R.string.helpClassesTitle), getString(R.string.helpClasses))
R.id.switchDisableGreeting -> {
val switchDisableGreeting = v.findViewById<Switch>(R.id.switchDisableGreeting)
if (switchDisableGreeting.isChecked) edit.putBoolean("greeting", true) else edit.putBoolean("greeting", false)
}
R.id.switchDark -> {
val switchDark = v.findViewById<Switch>(R.id.switchDark)
val bottomNav = v.rootView.findViewById<BottomNavigationView>(R.id.bottom_nav)
if (switchDark.isChecked) {
edit.putInt("themeInt", 1)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
window?.navigationBarColor = ContextCompat.getColor(mContext, R.color.background)
} else {
edit.putInt("themeInt", 0)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window?.navigationBarColor = ContextCompat.getColor(mContext, R.color.background)
}
}
if (prefs.getBoolean("defaultPersonalised", false)) {
bottomNav.selectedItemId = R.id.personal
} else {
bottomNav.selectedItemId = R.id.plan
}
}
R.id.switchHideInfo -> {
val switchHideInfo = v.findViewById<Switch>(R.id.switchHideInfo)
if (switchHideInfo.isChecked) edit.putBoolean("showinfotab", true) else edit.putBoolean("showinfotab", false)
}
R.id.btnCustomiseColours -> createColourDialog() R.id.btnCustomiseColours -> createColourDialog()
R.id.switchNotifications -> {
val switchNotifications = v.findViewById<Switch>(R.id.switchNotifications)
if (switchNotifications.isChecked) edit.putBoolean("notif", true) else edit.putBoolean("notif", false)
}
R.id.switchDefaultPlan -> {
val switchDefaultPlan = v.findViewById<Switch>(R.id.switchDefaultPlan)
if (switchDefaultPlan.isChecked) edit.putBoolean("defaultPersonalised", true) else edit.putBoolean("defaultPersonalised", false)
}
R.id.switchOpenInfo -> {
val switchOpenInfo = v.findViewById<Switch>(R.id.switchOpenInfo)
if (switchOpenInfo.isChecked) edit.putBoolean("openInfo", true) else edit.putBoolean("openInfo", false)
}
R.id.switchAutoRefresh -> {
val switchAutoRefresh = v.findViewById<Switch>(R.id.switchAutoRefresh)
if (switchAutoRefresh.isChecked) edit.putBoolean("autoRefresh", true) else edit.putBoolean("autoRefresh", false)
}
R.id.btnWebsite -> { R.id.btnWebsite -> {
try { try {
customTabsIntent.launchUrl(mContext, Uri.parse("http://307.joomla.schule.bremen.de")) customTabsIntent.launchUrl(mContext, Uri.parse("http://307.joomla.schule.bremen.de"))
@@ -254,13 +204,56 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
edit.apply() edit.apply()
} }
override fun onCheckedChanged(v: CompoundButton?, isChecked: Boolean) {
if (v?.isPressed == true) {
when (v.id) {
R.id.switchDisableGreeting -> {
edit.putBoolean("greeting", isChecked)
}
R.id.switchDark -> {
val bottomNav = v.rootView.findViewById<BottomNavigationView>(R.id.bottom_nav)
if (isChecked) {
edit.putInt("themeInt", 1)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
window?.navigationBarColor = ContextCompat.getColor(mContext, R.color.background)
} else {
edit.putInt("themeInt", 0)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window?.navigationBarColor = ContextCompat.getColor(mContext, R.color.background)
}
}
if (prefs.getBoolean("defaultPersonalised", false)) {
bottomNav.selectedItemId = R.id.personal
} else {
bottomNav.selectedItemId = R.id.plan
}
}
R.id.switchNotifications -> {
edit.putBoolean("notif", isChecked)
}
R.id.switchDefaultPlan -> {
edit.putBoolean("defaultPersonalised", isChecked)
}
R.id.switchOpenInfo -> {
edit.putBoolean("openInfo", isChecked)
}
R.id.switchAutoRefresh -> {
edit.putBoolean("autoRefresh", isChecked)
}
}
edit.apply()
}
}
private fun createDialog(title: String, text: String) { private fun createDialog(title: String, text: String) {
val alertDialog = AlertDialog.Builder(mContext, R.style.AlertDialog) val alertDialog = AlertDialog.Builder(mContext, R.style.AlertDialog)
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.simple_dialog, null) val dialogView = LayoutInflater.from(mContext).inflate(R.layout.simple_dialog, null)
val dialogTitle = dialogView.findViewById<TextView>(R.id.textviewtitle) dialogView.findViewById<TextView>(R.id.textviewtitle).text = title
val dialogText = dialogView.findViewById<TextView>(R.id.dialogtext) dialogView.findViewById<TextView>(R.id.dialogtext).text = text
dialogTitle.text = title
dialogText.text = text
alertDialog.setView(dialogView).show() alertDialog.setView(dialogView).show()
} }
-16
View File
@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:background="@color/background">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.drawerlayout.widget.DrawerLayout>
+27 -15
View File
@@ -10,20 +10,18 @@
android:id="@+id/appbarlayout" android:id="@+id/appbarlayout"
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:background="@color/background"
app:elevation="0dp"> android:elevation="0dp">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="@color/background"
app:popupTheme="@style/AppThemeLight.PopupOverlay" app:popupTheme="@style/AppThemeLight.PopupOverlay"
app:titleTextColor="@color/accent" app:titleTextColor="@color/accent"
app:contentInsetStart="0dp" app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed" android:elevation="0dp"
app:layout_collapseMode="pin" app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
android:layout_gravity="bottom">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -79,22 +77,36 @@
<include layout="@layout/content_main" /> <include layout="@layout/content_main" />
<LinearLayout <View
android:id="@+id/bottom_sheet_closer" android:id="@+id/bottom_nav_divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="1dp"
android:visibility="gone" android:layout_marginStart="8dp"
android:orientation="vertical" android:layout_marginEnd="8dp"
android:clickable="true" app:layout_anchor="@+id/bottom_nav"
android:focusable="true"/> android:layout_gravity="top"
android:background="@color/lighthintcolor"
android:clickable="false"
android:focusable="false"/>
<include layout="@layout/bottom_sheet" /> <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginBottom="0dp"
app:elevation="0dp"
android:layout_gravity="bottom"
app:menu="@menu/nav_items"
android:background="@color/background"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"
app:itemRippleColor="@color/accent"/>
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordination" android:id="@+id/coordination"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp" android:layout_height="80dp"
app:layout_anchor="@+id/bottom_sheet" app:layout_anchor="@+id/bottom_nav"
android:layout_gravity="top" android:layout_gravity="top"
android:clickable="false" android:clickable="false"
android:focusable="false"/> android:focusable="false"/>
-81
View File
@@ -1,81 +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/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical"
android:paddingTop="0dp"
app:behavior_hideable="false"
app:behavior_peekHeight="56dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View
android:id="@+id/bottom_nav_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_anchor="@+id/bottom_sheet"
android:layout_gravity="top"
android:background="@color/lighthintcolor"
android:clickable="false"
android:focusable="false"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginBottom="0dp"
app:elevation="0dp"
app:layout_anchor="@+id/bottom_sheet"
android:layout_gravity="bottom"
app:menu="@menu/nav_items"
android:background="@color/background"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"
app:itemRippleColor="@color/accent"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:clickable="true"
android:focusable="true">
<LinearLayout
android:id="@+id/bottom_sheet_linear"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background">
<TextView
android:id="@+id/bottom_sheet_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_information"
android:drawableTint="@color/textcolor"
android:paddingStart="16dp"
android:drawablePadding="8dp"
android:gravity="top|start"
android:text="@string/information"
android:textSize="16sp"
android:textColor="@color/textcolor"/>
<TextView
android:id="@+id/bottom_sheet_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:gravity="top|start"
android:text="@string/noinfo"
android:textSize="12sp"
android:textColor="@color/textcolor"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
+3 -37
View File
@@ -143,40 +143,6 @@
app:layout_constraintStart_toStartOf="@+id/txtDark" app:layout_constraintStart_toStartOf="@+id/txtDark"
app:layout_constraintTop_toTopOf="@+id/txtDark" /> app:layout_constraintTop_toTopOf="@+id/txtDark" />
<!-- a-->
<TextView
android:id="@+id/txtHideInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/showinfo"
android:textColor="@color/textcolor"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@+id/txtRestart"
app:layout_constraintTop_toBottomOf="@+id/txtRestart" />
<TextView
android:id="@+id/txtHideInfo2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/swipeindependent"
android:textColor="@color/hintcolor"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/txtHideInfo"
app:layout_constraintTop_toBottomOf="@+id/txtHideInfo" />
<Switch
android:id="@+id/switchHideInfo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="16dp"
android:gravity="end|center"
app:layout_constraintBottom_toBottomOf="@+id/txtHideInfo2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/txtHideInfo"
app:layout_constraintTop_toTopOf="@+id/txtHideInfo" />
<!-- a-->
<TextView <TextView
android:id="@+id/txtCustomiseColours1" android:id="@+id/txtCustomiseColours1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -185,8 +151,8 @@
android:text="@string/customisecolor1" android:text="@string/customisecolor1"
android:textColor="@color/textcolor" android:textColor="@color/textcolor"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintStart_toStartOf="@+id/txtHideInfo2" app:layout_constraintStart_toStartOf="@+id/txtRestart"
app:layout_constraintTop_toBottomOf="@+id/txtHideInfo2" /> app:layout_constraintTop_toBottomOf="@+id/txtRestart" />
<TextView <TextView
android:id="@+id/txtCustomiseColours2" android:id="@+id/txtCustomiseColours2"
@@ -213,7 +179,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtHideInfo2" /> app:layout_constraintTop_toBottomOf="@+id/txtRestart" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
+1 -1
View File
@@ -13,7 +13,7 @@
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_marginBottom="3dp" android:layout_marginBottom="3dp"
app:cardElevation="1dp"> app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
+2 -1
View File
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="@color/lightbackground">
<TextView <TextView
android:id="@+id/textviewtitle" android:id="@+id/textviewtitle"
+5 -5
View File
@@ -11,16 +11,16 @@
android:icon="@drawable/ic_idea" android:icon="@drawable/ic_idea"
android:title="@string/personal" android:title="@string/personal"
android:enabled="true"/> android:enabled="true"/>
<item
android:id="@+id/menu"
android:icon="@drawable/ic_tomato"
android:title="@string/menu"
android:enabled="true"/>
<item <item
android:id="@+id/openinfopanel" android:id="@+id/openinfopanel"
android:icon="@drawable/ic_information" android:icon="@drawable/ic_information"
android:title="" android:title=""
android:enabled="true"/> android:enabled="true"/>
<item
android:id="@+id/menu"
android:icon="@drawable/ic_tomato"
android:title="@string/menu"
android:enabled="true"/>
<item <item
android:id="@+id/settings" android:id="@+id/settings"
android:icon="@drawable/ic_cogwheel" android:icon="@drawable/ic_cogwheel"
+2 -2
View File
@@ -56,8 +56,8 @@
<string name="version">Versionsnummer</string> <string name="version">Versionsnummer</string>
<string name="privacy">Datenschutzerklärung</string> <string name="privacy">Datenschutzerklärung</string>
<string name="tac">AGB</string> <string name="tac">AGB</string>
<string name="tactwo">Überprüfe die AGB der App</string> <string name="tactwo">Überprüfe die AGB der App (Englisch)</string>
<string name="privacytwo">Überprüfe die Datenschutzerklärung der App</string> <string name="privacytwo">Überprüfe die Datenschutzerklärung der App (Englisch)</string>
<string name="noinfo">Keine Informationen verfügbar</string> <string name="noinfo">Keine Informationen verfügbar</string>
<string name="information">Informationen</string> <string name="information">Informationen</string>
<string name="devby">Entwickelt von Deniz :)</string> <string name="devby">Entwickelt von Deniz :)</string>