Merge pull request #933 from Bnyro/ui

New Toolbar Design
This commit is contained in:
Bnyro 2022-07-31 21:10:25 +02:00 committed by GitHub
commit f33b9b7afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 109 additions and 126 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"> android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -7,7 +8,9 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application <application
@ -20,13 +23,25 @@
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Purple"> android:theme="@style/Theme.Purple"
tools:targetApi="n">
<activity <activity
android:name=".activities.NoInternetActivity" android:name=".activities.NoInternetActivity"
android:label="@string/noInternet" /> android:label="@string/noInternet" />
<activity <activity
android:name=".activities.SettingsActivity" android:name=".activities.SettingsActivity"
android:label="@string/settings" /> android:label="@string/settings" />
<activity
android:name=".activities.AboutActivity"
android:label="@string/settings" />
<activity
android:name=".activities.CommunityActivity"
android:label="@string/settings" />
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"

View File

@ -1,48 +1,35 @@
package com.github.libretube.preferences package com.github.libretube.activities
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.Html import android.text.Html
import android.view.LayoutInflater import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.github.libretube.DONATE_URL import com.github.libretube.DONATE_URL
import com.github.libretube.GITHUB_URL import com.github.libretube.GITHUB_URL
import com.github.libretube.PIPED_GITHUB_URL import com.github.libretube.PIPED_GITHUB_URL
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.WEBLATE_URL import com.github.libretube.WEBLATE_URL
import com.github.libretube.WEBSITE_URL import com.github.libretube.WEBSITE_URL
import com.github.libretube.activities.SettingsActivity import com.github.libretube.databinding.ActivityAboutBinding
import com.github.libretube.databinding.FragmentAboutBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
class AboutFragment : Fragment() { class AboutActivity : AppCompatActivity() {
private lateinit var binding: FragmentAboutBinding private lateinit var binding: ActivityAboutBinding
override fun onCreateView( override fun onCreate(savedInstanceState: Bundle?) {
inflater: LayoutInflater, super.onCreate(savedInstanceState)
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentAboutBinding.inflate(layoutInflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding = ActivityAboutBinding.inflate(layoutInflater)
super.onViewCreated(view, savedInstanceState) setContentView(binding.root)
val settingsActivity = activity as SettingsActivity
settingsActivity.changeTopBarText(getString(R.string.about))
binding.website.setOnClickListener { binding.website.setOnClickListener {
openLinkFromHref(WEBSITE_URL) openLinkFromHref(WEBSITE_URL)
} }
binding.website.setOnLongClickListener { binding.website.setOnLongClickListener {
val text = context?.getString(R.string.website_summary)!! val text = getString(R.string.website_summary)
showSnackBar(text) showSnackBar(text)
true true
} }
@ -51,7 +38,7 @@ class AboutFragment : Fragment() {
openLinkFromHref(PIPED_GITHUB_URL) openLinkFromHref(PIPED_GITHUB_URL)
} }
binding.piped.setOnLongClickListener { binding.piped.setOnLongClickListener {
val text = context?.getString(R.string.piped_summary)!! val text = getString(R.string.piped_summary)
showSnackBar(text) showSnackBar(text)
true true
} }
@ -60,7 +47,7 @@ class AboutFragment : Fragment() {
openLinkFromHref(WEBLATE_URL) openLinkFromHref(WEBLATE_URL)
} }
binding.translate.setOnLongClickListener { binding.translate.setOnLongClickListener {
val text = context?.getString(R.string.translate_summary)!! val text = getString(R.string.translate_summary)
showSnackBar(text) showSnackBar(text)
true true
} }
@ -69,7 +56,7 @@ class AboutFragment : Fragment() {
openLinkFromHref(DONATE_URL) openLinkFromHref(DONATE_URL)
} }
binding.donate.setOnLongClickListener { binding.donate.setOnLongClickListener {
val text = context?.getString(R.string.donate_summary)!! val text = getString(R.string.donate_summary)
showSnackBar(text) showSnackBar(text)
true true
} }
@ -78,7 +65,7 @@ class AboutFragment : Fragment() {
openLinkFromHref(GITHUB_URL) openLinkFromHref(GITHUB_URL)
} }
binding.github.setOnLongClickListener { binding.github.setOnLongClickListener {
val text = context?.getString(R.string.contributing_summary)!! val text = getString(R.string.contributing_summary)
showSnackBar(text) showSnackBar(text)
true true
} }
@ -87,17 +74,10 @@ class AboutFragment : Fragment() {
showLicense() showLicense()
} }
binding.license.setOnLongClickListener { binding.license.setOnLongClickListener {
val text = context?.getString(R.string.license_summary)!! val text = getString(R.string.license_summary)
showSnackBar(text) showSnackBar(text)
true true
} }
binding.community.setOnClickListener {
val communityFragment = CommunityFragment()
parentFragmentManager.beginTransaction()
.replace(R.id.settings, communityFragment)
.commitNow()
}
} }
private fun openLinkFromHref(link: String) { private fun openLinkFromHref(link: String) {
@ -117,7 +97,6 @@ class AboutFragment : Fragment() {
} }
private fun showLicense() { private fun showLicense() {
val assets = view?.context?.assets
val licenseString = assets val licenseString = assets
?.open("gpl3.html") ?.open("gpl3.html")
?.bufferedReader() ?.bufferedReader()
@ -131,7 +110,7 @@ class AboutFragment : Fragment() {
Html.fromHtml(licenseString.toString()) Html.fromHtml(licenseString.toString())
} }
MaterialAlertDialogBuilder(requireContext()) MaterialAlertDialogBuilder(this)
.setPositiveButton(getString(R.string.okay)) { _, _ -> } .setPositiveButton(getString(R.string.okay)) { _, _ -> }
.setMessage(licenseHtml) .setMessage(licenseHtml)
.create() .create()

View File

@ -1,38 +1,24 @@
package com.github.libretube.preferences package com.github.libretube.activities
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.github.libretube.DISCORD_URL import com.github.libretube.DISCORD_URL
import com.github.libretube.MATRIX_URL import com.github.libretube.MATRIX_URL
import com.github.libretube.R
import com.github.libretube.REDDIT_URL import com.github.libretube.REDDIT_URL
import com.github.libretube.TELEGRAM_URL import com.github.libretube.TELEGRAM_URL
import com.github.libretube.TWITTER_URL import com.github.libretube.TWITTER_URL
import com.github.libretube.activities.SettingsActivity import com.github.libretube.databinding.ActivityCommunityBinding
import com.github.libretube.databinding.FragmentCommunityBinding
class CommunityFragment : Fragment() { class CommunityActivity : AppCompatActivity() {
private lateinit var binding: FragmentCommunityBinding private lateinit var binding: ActivityCommunityBinding
override fun onCreateView( override fun onCreate(savedInstanceState: Bundle?) {
inflater: LayoutInflater, super.onCreate(savedInstanceState)
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentCommunityBinding.inflate(layoutInflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding = ActivityCommunityBinding.inflate(layoutInflater)
super.onViewCreated(view, savedInstanceState) setContentView(binding.root)
val settingsActivity = activity as SettingsActivity
settingsActivity.changeTopBarText(getString(R.string.community))
binding.telegram.setOnClickListener { binding.telegram.setOnClickListener {
openLinkFromHref(TELEGRAM_URL) openLinkFromHref(TELEGRAM_URL)

View File

@ -9,6 +9,8 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.Log import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View import android.view.View
import android.view.WindowInsets import android.view.WindowInsets
import android.view.WindowInsetsController import android.view.WindowInsetsController
@ -82,6 +84,9 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
// set the action bar for the activity
setSupportActionBar(binding.toolbar)
navController = findNavController(R.id.fragment) navController = findNavController(R.id.fragment)
binding.bottomNav.setupWithNavController(navController) binding.bottomNav.setupWithNavController(navController)
@ -143,21 +148,40 @@ class MainActivity : AppCompatActivity() {
} }
binding.toolbar.title = ThemeHelper.getStyledAppName(this) binding.toolbar.title = ThemeHelper.getStyledAppName(this)
}
}
binding.toolbar.setNavigationOnClickListener { override fun onCreateOptionsMenu(menu: Menu): Boolean {
// settings activity stuff // Inflate the menu; this adds items to the action bar if it is present.
val intent = Intent(this, SettingsActivity::class.java) menuInflater.inflate(R.menu.action_bar, menu)
startActivity(intent) return true
} }
binding.toolbar.setOnMenuItemClickListener { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (it.itemId) { // Handle action bar item clicks here. The action bar will
R.id.action_search -> { // automatically handle clicks on the Home/Up button, so long
navController.navigate(R.id.searchFragment) // as you specify a parent activity in AndroidManifest.xml.
} return when (item.itemId) {
} R.id.action_search -> {
false navController.navigate(R.id.searchFragment)
true
} }
R.id.action_settings -> {
val settingsIntent = Intent(this, SettingsActivity::class.java)
startActivity(settingsIntent)
true
}
R.id.action_about -> {
val aboutIntent = Intent(this, AboutActivity::class.java)
startActivity(aboutIntent)
true
}
R.id.action_community -> {
val communityIntent = Intent(this, CommunityActivity::class.java)
startActivity(communityIntent)
true
}
else -> super.onOptionsItemSelected(item)
} }
} }

View File

@ -5,8 +5,6 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.databinding.ActivitySettingsBinding import com.github.libretube.databinding.ActivitySettingsBinding
import com.github.libretube.preferences.AboutFragment
import com.github.libretube.preferences.CommunityFragment
import com.github.libretube.preferences.MainSettings import com.github.libretube.preferences.MainSettings
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
@ -51,12 +49,6 @@ class SettingsActivity : AppCompatActivity() {
super.onBackPressed() super.onBackPressed()
finishAndRemoveTask() finishAndRemoveTask()
} }
is CommunityFragment -> {
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, AboutFragment())
.commit()
}
else -> { else -> {
supportFragmentManager supportFragmentManager
.beginTransaction() .beginTransaction()

View File

@ -116,13 +116,6 @@ class MainSettings : PreferenceFragmentCompat() {
} }
true true
} }
val about = findPreference<Preference>("about")
about?.setOnPreferenceClickListener {
val newFragment = AboutFragment()
navigateToSettingsFragment(newFragment)
true
}
} }
private fun navigateToSettingsFragment(newFragment: Fragment) { private fun navigateToSettingsFragment(newFragment: Fragment) {

View File

@ -135,24 +135,6 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/community"
style="@style/AboutCard">
<LinearLayout style="@style/AboutItem">
<ImageView
style="@style/AboutImageView"
android:src="@drawable/ic_community" />
<TextView
style="@style/AboutTextView"
android:text="@string/community" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -8,17 +8,22 @@
app:layoutDescription="@xml/activity_main_scene" app:layoutDescription="@xml/activity_main_scene"
tools:context=".activities.MainActivity"> tools:context=".activities.MainActivity">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.AppBarLayout
android:id="@+id/toolbar" android:id="@+id/appBarLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="wrap_content"
app:menu="@menu/action_bar" android:background="@android:color/transparent"
app:navigationIcon="@drawable/ic_settings" app:layout_constraintStart_toStartOf="parent"
app:subtitleCentered="true" app:layout_constraintTop_toTopOf="parent">
app:title="@string/app_name"
app:titleCentered="true"
/> <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:menu="@menu/action_bar"
app:title="@string/app_name" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNav" android:id="@+id/bottomNav"
@ -37,7 +42,7 @@
app:layout_constraintBottom_toTopOf="@+id/bottomNav" app:layout_constraintBottom_toTopOf="@+id/bottomNav"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" app:layout_constraintTop_toBottomOf="@id/appBarLayout"
app:navGraph="@navigation/nav" /> app:navGraph="@navigation/nav" />
<FrameLayout <FrameLayout

View File

@ -6,6 +6,21 @@
android:id="@+id/action_search" android:id="@+id/action_search"
android:icon="@drawable/ic_search" android:icon="@drawable/ic_search"
android:title="@string/search_hint" android:title="@string/search_hint"
app:showAsAction="always" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
android:title="@string/settings"
app:showAsAction="never" />
<item
android:id="@+id/action_about"
android:title="@string/about"
app:showAsAction="never" />
<item
android:id="@+id/action_community"
android:title="@string/community"
app:showAsAction="never" />
</menu> </menu>

View File

@ -2,8 +2,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory>
<Preference <Preference
android:icon="@drawable/ic_settings" android:icon="@drawable/ic_settings"
android:summary="@string/general_summary" android:summary="@string/general_summary"
@ -52,8 +50,6 @@
app:summary="@string/advanced_summary" app:summary="@string/advanced_summary"
app:title="@string/advanced" /> app:title="@string/advanced" />
</PreferenceCategory>
<PreferenceCategory> <PreferenceCategory>
<Preference <Preference
@ -62,10 +58,6 @@
app:summary="@string/update_summary" app:summary="@string/update_summary"
app:title="App version" /> app:title="App version" />
<Preference
android:icon="@drawable/ic_info"
app:key="about"
app:title="@string/about" />
</PreferenceCategory> </PreferenceCategory>