Add tabs to the LockActivity

This commit is contained in:
Jonas Lochmann 2020-11-02 01:00:00 +01:00
parent a8bc2de6a0
commit 6f00b06313
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
6 changed files with 42 additions and 19 deletions

View file

@ -97,7 +97,7 @@ class LockActivity : AppCompatActivity(), ActivityViewModelHolder {
model.init(blockedPackageName, blockedActivityName) model.init(blockedPackageName, blockedActivityName)
pager.adapter = LockActivityAdapter(supportFragmentManager) pager.adapter = LockActivityAdapter(supportFragmentManager, this)
model.content.observe(this) { model.content.observe(this) {
if (isResumed && it is LockscreenContent.Blocked.BlockedCategory && it.reason == BlockingReason.RequiresCurrentDevice && !model.didOpenSetCurrentDeviceScreen) { if (isResumed && it is LockscreenContent.Blocked.BlockedCategory && it.reason == BlockingReason.RequiresCurrentDevice && !model.didOpenSetCurrentDeviceScreen) {
@ -126,6 +126,8 @@ class LockActivity : AppCompatActivity(), ActivityViewModelHolder {
showAuth.value = position > 0 showAuth.value = position > 0
} }
}) })
tabs.setupWithViewPager(pager)
} }
override fun onDestroy() { override fun onDestroy() {

View file

@ -16,11 +16,13 @@
package io.timelimit.android.ui.lock package io.timelimit.android.ui.lock
import android.content.Context
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
import io.timelimit.android.R
class LockActivityAdapter(fragmentManager: FragmentManager): FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { class LockActivityAdapter(fragmentManager: FragmentManager, private val context: Context): FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getCount(): Int = 2 override fun getCount(): Int = 2
override fun getItem(position: Int): Fragment = when (position) { override fun getItem(position: Int): Fragment = when (position) {
@ -28,4 +30,10 @@ class LockActivityAdapter(fragmentManager: FragmentManager): FragmentPagerAdapte
1 -> LockActionFragment() 1 -> LockActionFragment()
else -> throw IllegalArgumentException() else -> throw IllegalArgumentException()
} }
override fun getPageTitle(position: Int): CharSequence? = context.getString(when (position) {
0 -> R.string.lock_tab_reason
1 -> R.string.lock_tab_action
else -> throw IllegalArgumentException()
})
} }

View file

@ -13,14 +13,25 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<androidx.coordinatorlayout.widget.CoordinatorLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.lock.LockActivity" > tools:context=".ui.lock.LockActivity" >
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabs"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -36,3 +47,4 @@
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>

View file

@ -14,11 +14,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<resources> <resources>
<string name="lock_tab_reason">Grund</string>
<string name="lock_tab_action">Aktionen</string>
<string name="lock_header_blocked">Gesperrt!</string> <string name="lock_header_blocked">Gesperrt!</string>
<string name="lock_header_what">Was wurde gesperrt?</string> <string name="lock_header_what">Was wurde gesperrt?</string>
<string name="lock_header_why">Warum wurde es gesperrt?</string> <string name="lock_header_why">Warum wurde es gesperrt?</string>
<string name="lock_header_how_proceed">Wie geht es jetzt weiter?</string>
<string name="lock_allow_temporarily_header">Vorübergehend erlauben</string> <string name="lock_allow_temporarily_header">Vorübergehend erlauben</string>
<string name="lock_allow_temporarily_text"> <string name="lock_allow_temporarily_text">

View file

@ -18,7 +18,6 @@
<string name="lock_header_what">O que foi bloqueado?</string> <string name="lock_header_what">O que foi bloqueado?</string>
<string name="lock_header_why">Por que foi bloqueado?</string> <string name="lock_header_why">Por que foi bloqueado?</string>
<string name="lock_header_how_proceed">O que você pode fazer?</string>
<string name="lock_allow_temporarily_header">permitir temporariamente</string> <string name="lock_allow_temporarily_header">permitir temporariamente</string>
<string name="lock_allow_temporarily_text"> <string name="lock_allow_temporarily_text">

View file

@ -13,12 +13,13 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<string name="lock_tab_reason" tools:ignore="MissingTranslation">Reason</string>
<string name="lock_tab_action" tools:ignore="MissingTranslation">Actions</string>
<string name="lock_header_blocked">Blocked!</string> <string name="lock_header_blocked">Blocked!</string>
<string name="lock_header_what">What was blocked?</string> <string name="lock_header_what">What was blocked?</string>
<string name="lock_header_why">Why was it blocked?</string> <string name="lock_header_why">Why was it blocked?</string>
<string name="lock_header_how_proceed">What can you do?</string>
<string name="lock_allow_temporarily_header">allow temporarily</string> <string name="lock_allow_temporarily_header">allow temporarily</string>
<string name="lock_allow_temporarily_text"> <string name="lock_allow_temporarily_text">