mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[UI/Login] Make Lab accessible from login page.
This commit is contained in:
parent
a85f935eb4
commit
a5d0f4212d
@ -8,6 +8,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -17,6 +18,8 @@ import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.databinding.TemplateFragmentBinding
|
||||
import pl.szczodrzynski.edziennik.ext.addOnPageSelectedListener
|
||||
import pl.szczodrzynski.edziennik.ui.base.lazypager.FragmentLazyPagerAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.login.LoginActivity
|
||||
import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class LabFragment : Fragment(), CoroutineScope {
|
||||
@ -26,7 +29,7 @@ class LabFragment : Fragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var activity: AppCompatActivity
|
||||
private lateinit var b: TemplateFragmentBinding
|
||||
|
||||
private val job: Job = Job()
|
||||
@ -36,11 +39,14 @@ class LabFragment : Fragment(), CoroutineScope {
|
||||
// local/private variables go here
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
activity = (getActivity() as AppCompatActivity?) ?: return null
|
||||
context ?: return null
|
||||
app = activity.application as App
|
||||
b = TemplateFragmentBinding.inflate(inflater)
|
||||
b.refreshLayout.setParent(activity.swipeRefreshLayout)
|
||||
when (activity) {
|
||||
is MainActivity -> b.refreshLayout.setParent((activity as MainActivity).swipeRefreshLayout)
|
||||
is LoginActivity -> b.refreshLayout.setParent((activity as LoginActivity).swipeRefreshLayout)
|
||||
}
|
||||
b.refreshLayout.isEnabled = false
|
||||
return b.root
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import android.os.Process
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import com.chuckerteam.chucker.api.Chucker
|
||||
@ -35,7 +36,7 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var activity: AppCompatActivity
|
||||
private lateinit var b: LabFragmentBinding
|
||||
|
||||
private val job: Job = Job()
|
||||
@ -45,7 +46,7 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
// local/private variables go here
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
activity = (getActivity() as AppCompatActivity?) ?: return null
|
||||
context ?: return null
|
||||
app = activity.application as App
|
||||
b = LabFragmentBinding.inflate(inflater)
|
||||
@ -55,6 +56,16 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
override fun onPageCreated(): Boolean {
|
||||
b.app = app
|
||||
|
||||
if (app.profile.id == 0) {
|
||||
b.last10unseen.isVisible = false
|
||||
b.fullSync.isVisible = false
|
||||
b.clearProfile.isVisible = false
|
||||
b.rodo.isVisible = false
|
||||
b.removeHomework.isVisible = false
|
||||
b.unarchive.isVisible = false
|
||||
b.profile.isVisible = false
|
||||
}
|
||||
|
||||
b.last10unseen.onClick {
|
||||
launch(Dispatchers.Default) {
|
||||
val events = app.db.eventDao().getAllNow(App.profileId)
|
||||
@ -139,7 +150,8 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
b.profile += profiles.map { TextInputDropDown.Item(it.id.toLong(), "${it.id} ${it.name} archived ${it.archived}", tag = it) }
|
||||
b.profile.select(app.profileId.toLong())
|
||||
b.profile.setOnChangeListener {
|
||||
activity.loadProfile(it.id.toInt())
|
||||
if (activity is MainActivity)
|
||||
(activity as MainActivity).loadProfile(it.id.toInt())
|
||||
return@setOnChangeListener true
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
@ -22,6 +23,7 @@ import pl.szczodrzynski.edziennik.ext.input
|
||||
import pl.szczodrzynski.edziennik.ext.set
|
||||
import pl.szczodrzynski.edziennik.ext.startCoroutineTimer
|
||||
import pl.szczodrzynski.edziennik.ui.base.lazypager.LazyFragment
|
||||
import pl.szczodrzynski.edziennik.ui.login.LoginActivity
|
||||
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@ -31,7 +33,7 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var activity: AppCompatActivity
|
||||
private lateinit var b: TemplateListPageFragmentBinding
|
||||
|
||||
private val job: Job = Job()
|
||||
@ -45,7 +47,7 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
activity = (getActivity() as AppCompatActivity?) ?: return null
|
||||
context ?: return null
|
||||
app = activity.application as App
|
||||
b = TemplateListPageFragmentBinding.inflate(inflater)
|
||||
@ -142,7 +144,10 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
|
||||
.show()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
activity.error(ApiError.fromThrowable(TAG, e))
|
||||
if (activity is MainActivity)
|
||||
(activity as MainActivity).error(ApiError.fromThrowable(TAG, e))
|
||||
if (activity is LoginActivity)
|
||||
(activity as LoginActivity).error(ApiError.fromThrowable(TAG, e))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -20,6 +20,7 @@ import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.databinding.LoginActivityBinding
|
||||
import pl.szczodrzynski.edziennik.ui.error.ErrorSnackbar
|
||||
import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class LoginActivity : AppCompatActivity(), CoroutineScope {
|
||||
@ -32,6 +33,7 @@ class LoginActivity : AppCompatActivity(), CoroutineScope {
|
||||
lateinit var navOptions: NavOptions
|
||||
val nav by lazy { Navigation.findNavController(this, R.id.nav_host_fragment) }
|
||||
val errorSnackbar: ErrorSnackbar by lazy { ErrorSnackbar(this) }
|
||||
val swipeRefreshLayout: SwipeRefreshLayoutNoTouch by lazy { b.swipeRefreshLayout }
|
||||
|
||||
private val job: Job = Job()
|
||||
override val coroutineContext: CoroutineContext
|
||||
|
@ -66,6 +66,8 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
if (!isAdded) return
|
||||
|
||||
val adapter = LoginChooserAdapter(activity, this::onLoginModeClicked)
|
||||
|
||||
b.versionText.setText(
|
||||
R.string.login_chooser_version_format,
|
||||
app.buildManager.versionName,
|
||||
@ -73,10 +75,33 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
)
|
||||
b.versionText.onClick {
|
||||
app.buildManager.showVersionDialog(activity)
|
||||
if (!App.devMode)
|
||||
return@onClick
|
||||
if (adapter.items.firstOrNull { it is LoginInfo.Register && it.internalName == "lab" } != null)
|
||||
return@onClick
|
||||
adapter.items.add(
|
||||
index = 0,
|
||||
element = LoginInfo.Register(
|
||||
loginType = 999999,
|
||||
internalName = "lab",
|
||||
registerName = R.string.menu_lab,
|
||||
registerLogo = R.drawable.face_2,
|
||||
loginModes = listOf(
|
||||
LoginInfo.Mode(
|
||||
loginMode = 0,
|
||||
name = 0,
|
||||
icon = 0,
|
||||
guideText = 0,
|
||||
credentials = listOf(),
|
||||
errorCodes = mapOf()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
adapter.notifyItemInserted(0)
|
||||
b.list.smoothScrollToPosition(0)
|
||||
}
|
||||
|
||||
val adapter = LoginChooserAdapter(activity, this::onLoginModeClicked)
|
||||
|
||||
LoginInfo.chooserList = LoginInfo.chooserList
|
||||
?: LoginInfo.list.toMutableList()
|
||||
|
||||
@ -164,7 +189,7 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
anim.fillAfter = true
|
||||
activity.getRootView().startAnimation(anim)
|
||||
|
||||
b.list.smoothScrollToPosition(0)
|
||||
adapter.items.removeAll { it !is LoginInfo.Register }
|
||||
adapter.items.add(
|
||||
LoginInfo.Register(
|
||||
loginType = 74,
|
||||
@ -183,7 +208,8 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
)
|
||||
)
|
||||
)
|
||||
adapter.notifyItemInserted(adapter.items.size - 1)
|
||||
adapter.notifyDataSetChanged()
|
||||
b.list.smoothScrollToPosition(adapter.items.size - 1)
|
||||
}
|
||||
|
||||
when {
|
||||
@ -216,6 +242,11 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
return
|
||||
}
|
||||
|
||||
if (loginType.internalName == "lab") {
|
||||
nav.navigate(R.id.labFragment, null, activity.navOptions)
|
||||
return
|
||||
}
|
||||
|
||||
if (!app.config.privacyPolicyAccepted) {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setTitle(R.string.privacy_policy)
|
||||
|
BIN
app/src/main/res/drawable/face_2.png
Normal file
BIN
app/src/main/res/drawable/face_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
@ -19,6 +19,11 @@
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
@ -26,6 +31,7 @@
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="false"
|
||||
app:navGraph="@navigation/nav_login" />
|
||||
</pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
|
@ -22,6 +22,9 @@
|
||||
<action
|
||||
android:id="@+id/action_loginChooserFragment_to_loginEggsFragment"
|
||||
app:destination="@id/loginEggsFragment" />
|
||||
<action
|
||||
android:id="@+id/action_loginChooserFragment_to_labFragment"
|
||||
app:destination="@id/labFragment" />
|
||||
</fragment>
|
||||
<!-- eggs -->
|
||||
<fragment
|
||||
@ -95,4 +98,8 @@
|
||||
android:id="@+id/loginFinishFragment"
|
||||
android:name="pl.szczodrzynski.edziennik.ui.login.LoginFinishFragment"
|
||||
android:label="LoginFinishFragment" />
|
||||
<fragment
|
||||
android:id="@+id/labFragment"
|
||||
android:name="pl.szczodrzynski.edziennik.ui.debug.LabFragment"
|
||||
android:label="LabFragment" />
|
||||
</navigation>
|
||||
|
Loading…
Reference in New Issue
Block a user