Skip to content

Commit

Permalink
Revert "add lock layout function (szkolny-eu#199)"
Browse files Browse the repository at this point in the history
This reverts commit 2fd7038.
  • Loading branch information
kuba2k2 committed Jun 18, 2024
1 parent 71cfdfa commit ac0cf8a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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,7 +136,6 @@ 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 @@ -169,78 +168,56 @@ 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)
b.list.adapter = adapter
b.list.layoutManager = LinearLayoutManager(activity)

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

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)
)
)
}
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)
))
}
}

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)
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)
}
}
})

itemTouchHelper.attachToRecyclerView(b.list)
}
}
})
itemTouchHelper.attachToRecyclerView(b.list)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ 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
2 changes: 0 additions & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,4 @@
<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: 0 additions & 2 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,4 @@
<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: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,4 @@
<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 ac0cf8a

Please sign in to comment.