Update settings activity ui

This commit is contained in:
Koitharu
2024-05-25 16:11:21 +03:00
parent 2ae488544b
commit 0faa97b08c
9 changed files with 95 additions and 83 deletions

View File

@@ -16,8 +16,8 @@ android {
applicationId 'org.koitharu.kotatsu' applicationId 'org.koitharu.kotatsu'
minSdk = 21 minSdk = 21
targetSdk = 34 targetSdk = 34
versionCode = 643 versionCode = 644
versionName = '7.1' versionName = '7.1.1'
generatedDensities = [] generatedDensities = []
testInstrumentationRunner 'org.koitharu.kotatsu.HiltTestRunner' testInstrumentationRunner 'org.koitharu.kotatsu.HiltTestRunner'
ksp { ksp {

View File

@@ -0,0 +1,33 @@
package org.koitharu.kotatsu.settings
import android.content.Context
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.core.view.MenuProvider
import leakcanary.LeakCanary
import org.koitharu.kotatsu.R
import org.koitharu.workinspector.WorkInspector
class SettingsMenuProvider(
private val context: Context,
) : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.opt_settings, menu)
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
R.id.action_leaks -> {
context.startActivity(LeakCanary.newLeakDisplayActivityIntent())
true
}
R.id.action_works -> {
context.startActivity(WorkInspector.getIntent(context))
true
}
else -> false
}
}

View File

@@ -8,14 +8,9 @@
android:title="@string/leak_canary_display_activity_label" android:title="@string/leak_canary_display_activity_label"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@id/action_tracker"
android:title="@string/check_for_new_chapters"
app:showAsAction="never" />
<item <item
android:id="@id/action_works" android:id="@id/action_works"
android:title="Works" android:title="@string/wi_lib_name"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@@ -63,7 +63,7 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
) )
} }
protected fun setTitle(title: CharSequence?) { protected open fun setTitle(title: CharSequence?) {
(activity as? SettingsActivity)?.setSectionTitle(title) (activity as? SettingsActivity)?.setSectionTitle(title)
} }

View File

@@ -43,6 +43,12 @@ class RootSettingsFragment : BasePreferenceFragment(0) {
} }
} }
override fun setTitle(title: CharSequence?) {
if (!resources.getBoolean(R.bool.is_tablet)) {
super.setTitle(title)
}
}
private fun bindPreferenceSummary(key: String, @StringRes vararg items: Int) { private fun bindPreferenceSummary(key: String, @StringRes vararg items: Int) {
findPreference<Preference>(key)?.summary = items.joinToString { getString(it) } findPreference<Preference>(key)?.summary = items.joinToString { getString(it) }
} }

View File

@@ -1,11 +1,8 @@
package org.koitharu.kotatsu.settings package org.koitharu.kotatsu.settings
import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup.MarginLayoutParams import android.view.ViewGroup.MarginLayoutParams
import androidx.core.graphics.Insets import androidx.core.graphics.Insets
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
@@ -44,9 +41,12 @@ class SettingsActivity :
private val isMasterDetails private val isMasterDetails
get() = viewBinding.containerMaster != null get() = viewBinding.containerMaster != null
private var screenPadding = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(ActivitySettingsBinding.inflate(layoutInflater)) setContentView(ActivitySettingsBinding.inflate(layoutInflater))
screenPadding = resources.getDimensionPixelOffset(R.dimen.screen_padding)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
val fm = supportFragmentManager val fm = supportFragmentManager
val currentFragment = fm.findFragmentById(R.id.container) val currentFragment = fm.findFragmentById(R.id.container)
@@ -59,38 +59,7 @@ class SettingsActivity :
replace(R.id.container_master, RootSettingsFragment()) replace(R.id.container_master, RootSettingsFragment())
} }
} }
} addMenuProvider(SettingsMenuProvider(this))
override fun onCreateOptionsMenu(menu: Menu): Boolean {
super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.opt_settings, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.action_leaks -> {
val intent = Intent()
intent.component = ComponentName(this, "leakcanary.internal.activity.LeakActivity")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(intent)
true
}
R.id.action_tracker -> {
val intent = Intent()
intent.component = ComponentName(this, "org.koitharu.kotatsu.tracker.ui.debug.TrackerDebugActivity")
startActivity(intent)
true
}
R.id.action_works -> {
val intent = Intent()
intent.component = ComponentName(this, "org.koitharu.workinspector.WorkInspectorActivity")
startActivity(intent)
true
}
else -> super.onOptionsItemSelected(item)
} }
override fun onPreferenceStartFragment( override fun onPreferenceStartFragment(
@@ -109,8 +78,8 @@ class SettingsActivity :
left = insets.left, left = insets.left,
right = insets.right, right = insets.right,
) )
viewBinding.cardDetails?.updateLayoutParams<MarginLayoutParams> { viewBinding.textViewHeader?.updateLayoutParams<MarginLayoutParams> {
bottomMargin = marginStart + insets.bottom topMargin = screenPadding + insets.top
} }
} }

View File

@@ -13,7 +13,7 @@
android:elevation="0dp" android:elevation="0dp"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
app:elevation="0dp" app:elevation="0dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="@id/container_master"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:liftOnScroll="false"> app:liftOnScroll="false">
@@ -30,50 +30,46 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/card_details" app:layout_constraintEnd_toStartOf="@id/container"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar" app:layout_constraintTop_toBottomOf="@id/appbar"
app:layout_constraintWidth_max="400dp" app:layout_constraintWidth_max="400dp"
app:layout_constraintWidth_min="320dp" app:layout_constraintWidth_min="320dp"
app:layout_constraintWidth_percent="0.35" /> app:layout_constraintWidth_percent="0.4" />
<com.google.android.material.card.MaterialCardView <TextView
android:id="@+id/card_details" android:id="@+id/textView_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="?listPreferredItemPaddingStart"
android:layout_marginTop="@dimen/screen_padding"
android:layout_marginEnd="?listPreferredItemPaddingEnd"
android:gravity="center_vertical|start"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.Kotatsu.SectionHeader"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/container_master"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/appearance" />
<androidx.fragment.app.FragmentContainerView
android:id="@id/container"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginStart="@dimen/side_card_offset"
android:layout_marginTop="2dp"
android:layout_marginEnd="@dimen/side_card_offset"
android:layout_marginBottom="@dimen/side_card_offset"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/container_master" app:layout_constraintStart_toEndOf="@id/container_master"
app:layout_constraintTop_toBottomOf="@id/appbar"> app:layout_constraintTop_toBottomOf="@id/textView_header"
tools:layout="@layout/fragment_settings_sources" />
<LinearLayout <View
android:layout_width="match_parent" android:layout_width="1dp"
android:layout_height="match_parent" android:layout_height="0dp"
android:orientation="vertical"> android:background="?colorSurfaceDim"
app:layout_constraintBottom_toBottomOf="parent"
<TextView app:layout_constraintEnd_toEndOf="@id/container_master"
android:id="@+id/textView_header" app:layout_constraintStart_toEndOf="@id/container_master"
android:layout_width="match_parent" app:layout_constraintTop_toTopOf="parent" />
android:layout_height="wrap_content"
android:layout_marginStart="?listPreferredItemPaddingStart"
android:layout_marginEnd="?listPreferredItemPaddingEnd"
android:gravity="center_vertical|start"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.Kotatsu.SectionHeader"
tools:text="@string/appearance" />
<androidx.fragment.app.FragmentContainerView
android:id="@id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu />

View File

@@ -0,0 +1,15 @@
package org.koitharu.kotatsu.settings
import android.content.Context
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.core.view.MenuProvider
@Suppress("UNUSED_PARAMETER")
class SettingsMenuProvider(context: Context) : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) = Unit
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = false
}