Merge pull request #1365 from Bnyro/master

Add and improve toolbars
This commit is contained in:
Bnyro 2022-09-24 11:12:11 +02:00 committed by GitHub
commit d68d33accc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 44 additions and 273 deletions

View File

@ -2,6 +2,7 @@ package com.github.libretube.extensions
import android.view.View
import android.widget.FrameLayout
import androidx.core.content.res.ResourcesCompat
import com.github.libretube.R
import com.google.android.material.snackbar.Snackbar
@ -21,6 +22,6 @@ fun View.getStyledSnackBar(text: Int): Snackbar {
)
snackBar.view.layoutParams = params
snackBar.view.background = resources.getDrawable(R.drawable.snackbar_shape, null)
snackBar.view.background = ResourcesCompat.getDrawable(resources, R.drawable.snackbar_shape, null)
return snackBar
}

View File

@ -10,7 +10,6 @@ import android.os.Bundle
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import com.github.libretube.R
import com.github.libretube.constants.DONATE_URL
import com.github.libretube.constants.GITHUB_URL
import com.github.libretube.constants.LICENSE_URL
import com.github.libretube.constants.PIPED_GITHUB_URL
@ -31,6 +30,10 @@ class AboutActivity : BaseActivity() {
binding = ActivityAboutBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.toolbar.setNavigationOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.appIcon.setOnClickListener {
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
@ -66,14 +69,6 @@ class AboutActivity : BaseActivity() {
true
}
binding.donate.setOnClickListener {
openLinkFromHref(DONATE_URL)
}
binding.donate.setOnLongClickListener {
onLongClick(DONATE_URL)
true
}
binding.github.setOnClickListener {
openLinkFromHref(GITHUB_URL)
}

View File

@ -20,6 +20,10 @@ class CommunityActivity : BaseActivity() {
binding = ActivityCommunityBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.toolbar.setNavigationOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.telegram.setOnClickListener {
openLinkFromHref(TELEGRAM_URL)
}

View File

@ -17,7 +17,7 @@ class SettingsActivity : BaseActivity() {
setContentView(binding.root)
binding.backImageButton.setOnClickListener {
binding.toolbar.setNavigationOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
@ -51,6 +51,6 @@ class SettingsActivity : BaseActivity() {
}
fun changeTopBarText(text: String) {
if (this::binding.isInitialized) binding.topBarTextView.text = text
if (this::binding.isInitialized) binding.toolbar.title = text
}
}

View File

@ -1,38 +0,0 @@
package com.github.libretube.ui.adapters
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.BackupRowBinding
class BackupOptionsAdapter(
private val options: List<Int>,
private val onChange: (position: Int, isChecked: Boolean) -> Unit
) : RecyclerView.Adapter<BackupOptionsViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BackupOptionsViewHolder {
val binding = BackupRowBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return BackupOptionsViewHolder(binding)
}
override fun getItemCount(): Int {
return options.size
}
override fun onBindViewHolder(holder: BackupOptionsViewHolder, position: Int) {
holder.binding.apply {
title.text = root.context?.getString(options[position])
switchWidget.setOnCheckedChangeListener { _, isChecked ->
onChange.invoke(position, isChecked)
}
}
}
}
class BackupOptionsViewHolder(
val binding: BackupRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -3,25 +3,20 @@ package com.github.libretube.ui.dialogs
import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.databinding.DialogBackupBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.obj.BackupFile
import com.github.libretube.obj.PreferenceItem
import com.github.libretube.ui.adapters.BackupOptionsAdapter
import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class BackupDialog(
private val createBackupFile: (BackupFile) -> Unit
) : DialogFragment() {
private lateinit var binding: DialogBackupBinding
private val backupFile = BackupFile()
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val backupOptions = listOf(
val backupOptionNames = listOf(
R.string.watch_history,
R.string.watch_positions,
R.string.search_history,
@ -30,18 +25,15 @@ class BackupDialog(
R.string.preferences
)
val selected = MutableList(backupOptions.size) { false }
val backupItems = backupOptionNames.map { context?.getString(it)!! }.toTypedArray()
binding = DialogBackupBinding.inflate(layoutInflater)
binding.backupOptionsRecycler.layoutManager = LinearLayoutManager(context)
binding.backupOptionsRecycler.adapter =
BackupOptionsAdapter(backupOptions) { position, isChecked ->
selected[position] = isChecked
}
val selected = BooleanArray(backupOptionNames.size) { false }
return MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.backup)
.setView(binding.root)
.setMultiChoiceItems(backupItems, selected) { _, index, newValue ->
selected[index] = newValue
}
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.backup) { _, _ ->
val thread = Thread {

View File

@ -1,11 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M18,11v2h4v-2h-4zM16,17.61c0.96,0.71 2.21,1.65 3.2,2.39 0.4,-0.53 0.8,-1.07 1.2,-1.6 -0.99,-0.74 -2.24,-1.68 -3.2,-2.4 -0.4,0.54 -0.8,1.08 -1.2,1.61zM20.4,5.6c-0.4,-0.53 -0.8,-1.07 -1.2,-1.6 -0.99,0.74 -2.24,1.68 -3.2,2.4 0.4,0.53 0.8,1.07 1.2,1.6 0.96,-0.72 2.21,-1.65 3.2,-2.4zM4,9c-1.1,0 -2,0.9 -2,2v2c0,1.1 0.9,2 2,2h1v4h2v-4h1l5,3L13,6L8,9L4,9zM15.5,12c0,-1.33 -0.58,-2.53 -1.5,-3.35v6.69c0.92,-0.81 1.5,-2.01 1.5,-3.34z" />
</vector>

View File

@ -1,15 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#000000"
android:fillType="evenOdd"
android:pathData="M20,32C28.837,32 36,26.627 36,20C36,13.373 28.837,8 20,8C11.163,8 4,13.373 4,20C4,22.684 5.175,25.163 7.16,27.162C6.356,29.454 5.313,31.172 4.65,32.132C4.407,32.483 4.657,32.98 5.083,32.945C6.785,32.806 10.122,32.311 12.374,30.552C14.641,31.475 17.239,32 20,32Z" />
<path
android:fillColor="#000000"
android:fillType="evenOdd"
android:pathData="M22.784,33.834C31.403,32.793 38,26.996 38,20C38,19.463 37.961,18.933 37.886,18.412C41.553,20.1 44,23.136 44,26.6C44,28.748 43.06,30.73 41.472,32.329C42.068,34.028 42.828,35.333 43.358,36.126C43.595,36.481 43.342,36.978 42.917,36.937C41.504,36.802 39.011,36.377 37.301,35.042C35.487,35.781 33.409,36.2 31.2,36.2C27.978,36.2 25.034,35.307 22.784,33.834Z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M10,18h4v-2h-4v2zM3,6v2h18L21,6L3,6zM6,13h12v-2L6,11v2z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z" />
</vector>

View File

@ -1,11 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M11,39H18.5V26.5H29.5V39H37V19.5L24,9.75L11,19.5ZM11,42Q9.75,42 8.875,41.125Q8,40.25 8,39V19.5Q8,18.8 8.325,18.15Q8.65,17.5 9.2,17.1L22.2,7.35Q22.6,7.05 23.05,6.9Q23.5,6.75 24,6.75Q24.5,6.75 24.95,6.9Q25.4,7.05 25.8,7.35L38.8,17.1Q39.35,17.5 39.675,18.15Q40,18.8 40,19.5V39Q40,40.25 39.125,41.125Q38.25,42 37,42H26.5V29.5H21.5V42ZM24,24.35Z" />
</vector>

View File

@ -1,13 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,22.7994C11.55,22.7994 11.1,22.7094 10.74,22.4394 4.89,18.8394 1.29,12.6294 1.2,5.7894 1.2,4.8894 1.65,3.9894 2.46,3.5394 8.4,0.3894 15.6,0.3894 21.54,3.6294 22.35,3.9894 22.8,4.8894 22.8,5.7894 22.71,12.6294 19.11,18.8394 13.35,22.4394 12.9,22.7094 12.45,22.7994 12,22.7994ZM12,1.9194c-3.15,0 -6.3,0.81 -9.18,2.34 -0.54,0.27 -0.9,0.9 -0.9,1.53 0.09,6.57 3.51,12.51 9.18,16.02 0.54,0.36 1.26,0.36 1.8,0C18.57,18.3894 21.9,12.3594 22.08,5.7894 22.08,5.1594 21.72,4.5294 21.18,4.2594 18.3,2.7294 15.15,1.9194 12,1.9194Z" />
<path
android:fillColor="#FF000000"
android:pathData="M20.73,4.9794C15.24,2.0994 8.76,2.0994 3.27,4.9794 3,5.1594 2.82,5.4294 2.82,5.7894c0.09,6.48 3.51,12.06 8.73,15.3 0.27,0.18 0.63,0.18 0.9,0 5.13,-3.15 8.64,-8.82 8.73,-15.3C21.18,5.4294 21,5.1594 20.73,4.9794ZM9.66,15.1494L9.66,6.7794l7.29,4.23z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@android:color/white"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M14,36q-5,0 -8.5,-3.5T2,24q0,-5 3.5,-8.5T14,12h20q5,0 8.5,3.5T46,24q0,5 -3.5,8.5T34,36ZM14,33h20q3.75,0 6.375,-2.625T43,24q0,-3.75 -2.625,-6.375T34,15L14,15q-3.75,0 -6.375,2.625T5,24q0,3.75 2.625,6.375T14,33ZM13.95,29.05q2.1,0 3.575,-1.475T19,24q0,-2.1 -1.475,-3.575T13.95,18.95q-2.1,0 -3.575,1.475T8.9,24q0,2.1 1.475,3.575t3.575,1.475ZM24,24Z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@android:color/white"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M14,36q-5,0 -8.5,-3.5T2,24q0,-5 3.5,-8.5T14,12h20q5,0 8.5,3.5T46,24q0,5 -3.5,8.5T34,36ZM14,33h20q3.75,0 6.375,-2.625T43,24q0,-3.75 -2.625,-6.375T34,15L14,15q-3.75,0 -6.375,2.625T5,24q0,3.75 2.625,6.375T14,33ZM34.05,29.05q2.1,0 3.575,-1.475T39.1,24q0,-2.1 -1.475,-3.575T34.05,18.95q-2.1,0 -3.575,1.475T29,24q0,2.1 1.475,3.575t3.575,1.475ZM24,24Z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M24,31.5q3.55,0 6.025,-2.475Q32.5,26.55 32.5,23q0,-3.55 -2.475,-6.025Q27.55,14.5 24,14.5q-3.55,0 -6.025,2.475Q15.5,19.45 15.5,23q0,3.55 2.475,6.025Q20.45,31.5 24,31.5ZM24,28.6q-2.35,0 -3.975,-1.625T18.4,23q0,-2.35 1.625,-3.975T24,17.4q2.35,0 3.975,1.625T29.6,23q0,2.35 -1.625,3.975T24,28.6ZM24,38q-7.3,0 -13.2,-4.15Q4.9,29.7 2,23q2.9,-6.7 8.8,-10.85Q16.7,8 24,8q7.3,0 13.2,4.15Q43.1,16.3 46,23q-2.9,6.7 -8.8,10.85Q31.3,38 24,38Z" />
</vector>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners
android:topLeftRadius="100dp"
android:topRightRadius="100dp" />
</shape>

View File

@ -9,12 +9,19 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationIcon="?homeAsUpIndicator"
app:title="@string/about" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/appIcon"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:layout_marginTop="30dp"
android:src="@mipmap/ic_launcher_round"
app:shapeAppearanceOverlay="@style/CircleImageView" />
@ -100,24 +107,6 @@
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/donate"
style="@style/AboutCard">
<LinearLayout style="@style/AboutItem">
<ImageView
style="@style/AboutImageView"
android:src="@drawable/ic_donate" />
<TextView
style="@style/AboutTextView"
android:text="@string/donate" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/license"
style="@style/AboutCard">

View File

@ -9,24 +9,22 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationIcon="?homeAsUpIndicator"
app:title="@string/community" />
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="40dp"
android:src="@mipmap/ic_launcher_round"
app:shapeAppearanceOverlay="@style/CircleImageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:text="@string/community"
android:textSize="24sp"
android:textStyle="bold" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/telegram"
style="@style/AboutCard">

View File

@ -1,37 +1,20 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="5dp">
app:navigationIcon="?homeAsUpIndicator"
app:title="@string/settings" />
<ImageButton
android:id="@+id/back_imageButton"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_marginVertical="10dp"
android:layout_marginLeft="15dp"
android:background="?android:selectableItemBackgroundBorderless"
android:backgroundTint="@android:color/transparent"
android:src="@drawable/ic_arrow_back" />
<TextView
android:id="@+id/topBar_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="25dp"
android:text="@string/settings"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingHorizontal="30dp"
android:paddingVertical="5dp">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_weight="1"
android:textSize="16sp" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -8,8 +8,8 @@
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginVertical="5dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="55dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/backupOptionsRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>