Added app language support (I think); fragments rely on Bundles instead of constructor parameters to get data, mitigating a source of crashes

This commit is contained in:
denizk0461
2023-04-30 22:47:59 +02:00
parent 7243df0f06
commit 079e66ad50
23 changed files with 619 additions and 472 deletions
@@ -1,12 +1,12 @@
package com.denizk0461.studip.activity
import android.annotation.SuppressLint
import android.app.Activity
import android.os.Bundle
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.denizk0461.studip.R
import com.denizk0461.studip.data.showErrorSnackBar
@@ -19,7 +19,7 @@ import java.net.URLDecoder
* Activity for allowing the user to log in to access and fetch their schedule from their Stud.IP
* profile. Launched through a button in the app's settings.
*/
class FetcherActivity : Activity() {
class FetcherActivity : AppCompatActivity() {
// View binding
private lateinit var binding: ActivityFetcherBinding
@@ -0,0 +1,32 @@
package com.denizk0461.studip.activity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import com.denizk0461.studip.R
import com.denizk0461.studip.databinding.ActivityImageBinding
/**
* Activity used solely to display a single image. Not a critical part of the app.
*/
class ImageActivity : AppCompatActivity() {
// View binding
private lateinit var binding: ActivityImageBinding
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
// Inflate view binding and bind to this activity
binding = ActivityImageBinding.inflate(layoutInflater)
setContentView(binding.root)
// Set the image of the view
binding.imageView.setImageResource(when (intent.extras?.getString("img") ?: "") {
"bojack" -> { R.drawable.man }
"garbage" -> { R.drawable.garbage }
else -> { R.drawable.engineering }
})
}
}
@@ -41,20 +41,6 @@ class MainActivity : FragmentActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
// Open the fragment that the user specified to open on app start
if (
AppRepository.getRepositoryInstance(application)
.getBooleanPreference(SettingsPreferences.LAUNCH_CANTEEN_ON_START)
) {
// Open canteen fragment
binding.contentMain.navView.selectedItemId = R.id.food
currentFragment = "canteen"
} else {
// Open event fragment
binding.contentMain.navView.selectedItemId = R.id.plan
currentFragment = "event"
}
// Set up navigation view bar to launch fragments
binding.contentMain.navView.setOnItemSelectedListener { item ->
// Launch fragment based on the item that has been clicked
@@ -65,8 +51,24 @@ class MainActivity : FragmentActivity() {
})
}
// Launch the fragment defined in currentFragment
loadFragment(currentFragment)
// Set up bottom nav bar and the initial fragment when the app launches
if (savedInstanceState == null) {
// Open the fragment that the user specified to open on app start
if (AppRepository.getRepositoryInstance(application)
.getBooleanPreference(SettingsPreferences.LAUNCH_CANTEEN_ON_START)
) {
// Open canteen fragment
binding.contentMain.navView.selectedItemId = R.id.food
currentFragment = "canteen"
} else {
// Open event fragment
binding.contentMain.navView.selectedItemId = R.id.plan
currentFragment = "event"
}
// Launch the fragment defined in currentFragment
loadFragment(currentFragment)
}
}
/**