Skip to content

Commit

Permalink
add lock layout function (szkolny-eu#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadorowo committed Jun 14, 2024
1 parent b65f282 commit 8d0b5b8
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ConfigUI(base: Config) {
var appBackground by base.config<String?>("appBg", null)
var headerBackground by base.config<String?>("headerBg", null)

var lockLayout by base.config<Boolean>(false)
var miniMenuVisible by base.config<Boolean>(false)
var miniMenuButtons by base.config<Set<NavTarget>> {
setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class HomeFragment : Fragment(), CoroutineScope {
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show()
})
)

b.configureCards.onClick {
HomeConfigDialog(activity, reloadOnDismiss = true).show()
}
Expand Down Expand Up @@ -168,56 +169,78 @@ class HomeFragment : Fragment(), CoroutineScope {
else -> null
} as HomeCard?
}

//if (App.devMode)
// items += HomeDebugCard(100, app, activity, this, app.profile)
if (app.profile.archived)
items.add(0, HomeArchiveCard(101, app, activity, this, app.profile))

val status = app.availabilityManager.check(app.profile, cacheOnly = true)?.status
val lockLayout = app.config.ui.lockLayout
val update = app.config.update

if (update != null && update.versionCode > BuildConfig.VERSION_CODE || status?.userMessage != null) {
items.add(0, HomeAvailabilityCard(102, app, activity, this, app.profile))
}

val adapter = HomeCardAdapter(items)
val itemTouchHelper = ItemTouchHelper(CardItemTouchHelperCallback(adapter, b.refreshLayout))
adapter.itemTouchHelper = itemTouchHelper
b.list.layoutManager = LinearLayoutManager(activity)
b.list.adapter = adapter
b.list.setAccessibilityDelegateCompat(object : RecyclerViewAccessibilityDelegate(b.list) {
override fun getItemDelegate(): AccessibilityDelegateCompat {
return object : ItemDelegate(this) {
override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) {
super.onInitializeAccessibilityNodeInfo(host, info)
val position: Int = b.list.getChildLayoutPosition(host)
if (position != 0) {
info.addAction(AccessibilityActionCompat(
R.id.move_card_up_action,
host.resources.getString(R.string.card_action_move_up)
))
}
if (position != adapter.itemCount - 1) {
info.addAction(AccessibilityActionCompat(
R.id.move_card_down_action,
host.resources.getString(R.string.card_action_move_down)
))
b.list.layoutManager = LinearLayoutManager(activity)

val itemTouchHelper =
ItemTouchHelper(CardItemTouchHelperCallback(adapter, b.refreshLayout))

adapter.itemTouchHelper = itemTouchHelper

if (!lockLayout) {
b.list.setAccessibilityDelegateCompat(object :
RecyclerViewAccessibilityDelegate(b.list) {
override fun getItemDelegate(): AccessibilityDelegateCompat {
return object : ItemDelegate(this) {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfoCompat
) {
super.onInitializeAccessibilityNodeInfo(host, info)
val position: Int = b.list.getChildLayoutPosition(host)
if (position != 0) {
info.addAction(
AccessibilityActionCompat(
R.id.move_card_up_action,
host.resources.getString(R.string.card_action_move_up)
)
)
}
if (position != adapter.itemCount - 1) {
info.addAction(
AccessibilityActionCompat(
R.id.move_card_down_action,
host.resources.getString(R.string.card_action_move_down)
)
)
}
}
}

override fun performAccessibilityAction(host: View, action: Int, args: Bundle?): Boolean {
val fromPosition: Int = b.list.getChildLayoutPosition(host)
if (action == R.id.move_card_down_action) {
swapCards(fromPosition, fromPosition + 1, adapter)
return true
} else if (action == R.id.move_card_up_action) {
swapCards(fromPosition, fromPosition - 1, adapter)
return true
override fun performAccessibilityAction(
host: View,
action: Int,
args: Bundle?
): Boolean {
val fromPosition: Int = b.list.getChildLayoutPosition(host)
if (action == R.id.move_card_down_action) {
swapCards(fromPosition, fromPosition + 1, adapter)
return true
} else if (action == R.id.move_card_up_action) {
swapCards(fromPosition, fromPosition - 1, adapter)
return true
}
return super.performAccessibilityAction(host, action, args)
}
return super.performAccessibilityAction(host, action, args)
}
}
}
})
itemTouchHelper.attachToRecyclerView(b.list)
})

itemTouchHelper.attachToRecyclerView(b.list)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ class SettingsThemeCard(util: SettingsUtil) : SettingsCard(util) {
) { _, it ->
configGlobal.ui.miniMenuVisible = it
activity.navView.drawer.miniDrawerVisiblePortrait = it
},

util.createPropertyItem(
text = R.string.settings_ui_lock_layout_text,
subText = R.string.settings_ui_lock_layout_subtext,
icon = CommunityMaterial.Icon.cmd_axis_lock,
value = configGlobal.ui.lockLayout
) { _, it ->
configGlobal.ui.lockLayout = it
activity.recreate()
}
)

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/drawable/ic_note.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="48"
android:viewportHeight="48">
android:width="64dp"
android:height="64dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M8,39.001v-30c0,-2.2 1.8,-4 4,-4h24c2.2,0 4,1.8 4,4v30c0,2.2 -1.8,4 -4,4H12C9.8,43.001 8,41.201 8,39.001z"
android:fillColor="#42a5f5"/>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_note_legacy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?colorOnBackground"
android:autoMirrored="true">
<path
android:fillColor="?colorOnBackground"
android:pathData="M15,34.2Q15.75,34.2 16.3,33.675Q16.85,33.15 16.85,32.4Q16.85,31.65 16.3,31.1Q15.75,30.55 15,30.55Q14.25,30.55 13.725,31.1Q13.2,31.65 13.2,32.4Q13.2,33.15 13.725,33.675Q14.25,34.2 15,34.2ZM15,25.8Q15.75,25.8 16.3,25.275Q16.85,24.75 16.85,24Q16.85,23.25 16.3,22.7Q15.75,22.15 15,22.15Q14.25,22.15 13.725,22.7Q13.2,23.25 13.2,24Q13.2,24.75 13.725,25.275Q14.25,25.8 15,25.8ZM15,17.35Q15.75,17.35 16.3,16.825Q16.85,16.3 16.85,15.55Q16.85,14.8 16.3,14.25Q15.75,13.7 15,13.7Q14.25,13.7 13.725,14.25Q13.2,14.8 13.2,15.55Q13.2,16.3 13.725,16.825Q14.25,17.35 15,17.35ZM21.45,34.25H34.15V30.6H21.45ZM21.45,25.8H34.15V22.15H21.45ZM21.45,17.4H34.15V13.75H21.45ZM9,42.65Q7.55,42.65 6.45,41.55Q5.35,40.45 5.35,39V9Q5.35,7.55 6.45,6.45Q7.55,5.35 9,5.35H39Q40.45,5.35 41.55,6.45Q42.65,7.55 42.65,9V39Q42.65,40.45 41.55,41.55Q40.45,42.65 39,42.65ZM9,39H39Q39,39 39,39Q39,39 39,39V9Q39,9 39,9Q39,9 39,9H9Q9,9 9,9Q9,9 9,9V39Q9,39 9,39Q9,39 9,39ZM9,9Q9,9 9,9Q9,9 9,9V39Q9,39 9,39Q9,39 9,39Q9,39 9,39Q9,39 9,39V9Q9,9 9,9Q9,9 9,9Z"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/card_home_notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.IconButton.Filled"
app:icon="@drawable/ic_note"
app:icon="@drawable/ic_note_legacy"
app:iconTint="?colorOnPrimaryContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/note_dialog_subtitle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:drawablePadding="8dp"
android:text="@{text}"
android:textAppearance="@style/AppTheme.MaterialAlertDialog.TitleText"
app:drawableStartCompat="@drawable/ic_note"
app:drawableStartCompat="@drawable/ic_note_legacy"
tools:layout_height="28sp"
tools:text="@string/notes_list_dialog_title" />

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1227,4 +1227,6 @@
<string name="settings_about_contributors_subtext">Liste der Szkolny-Entwickler</string>
<string name="menu_teachers">Lehrer</string>
<string name="edziennik_progress_endpoint_addressbook">Addressbuch herunterladen…</string>
<string name="settings_ui_lock_layout_text">Sperren des Startbildschirm-Layouts</string>
<string name="settings_ui_lock_layout_subtext">Sie können keine Elemente auf dem Startbildschirm bearbeiten</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,4 +1434,6 @@
<string name="menu_agenda_config">Agenda settings</string>
<string name="registration_config_note_sharing_title">Share notes</string>
<string name="home_timetable_all_lessons">All lessons:</string>
<string name="settings_ui_lock_layout_text">Lock home screen layout</string>
<string name="settings_ui_lock_layout_subtext">You will not be able to edit items on the home screen</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1554,4 +1554,6 @@
<string name="home_timetable_all_lessons">Wszystkie lekcje:</string>
<string name="agenda_config_subject_important">Wyświetl nazwę przedmiotu zamiast rodzaju</string>
<string name="menu_timetable_sync">Odśwież wybrany tydzień</string>
<string name="settings_ui_lock_layout_text">Zablokuj układ ekranu głównego</string>
<string name="settings_ui_lock_layout_subtext">Nie będzie można edytować przedmiotów na ekranie głównym</string>
</resources>

0 comments on commit 8d0b5b8

Please sign in to comment.