From 6b1d3c20c99b1f7397d5f9d7f996f9020460b049 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 31 Jul 2022 21:09:47 +0200 Subject: [PATCH] new toolbar --- app/src/main/AndroidManifest.xml | 19 ++++++- .../AboutActivity.kt} | 53 ++++++------------- .../CommunityActivity.kt} | 32 ++++------- .../libretube/activities/MainActivity.kt | 48 ++++++++++++----- .../libretube/activities/SettingsActivity.kt | 8 --- .../libretube/preferences/MainSettings.kt | 7 --- ...{fragment_about.xml => activity_about.xml} | 18 ------- ...t_community.xml => activity_community.xml} | 0 app/src/main/res/xml/settings.xml | 8 --- 9 files changed, 78 insertions(+), 115 deletions(-) rename app/src/main/java/com/github/libretube/{preferences/AboutFragment.kt => activities/AboutActivity.kt} (62%) rename app/src/main/java/com/github/libretube/{preferences/CommunityFragment.kt => activities/CommunityActivity.kt} (51%) rename app/src/main/res/layout/{fragment_about.xml => activity_about.xml} (88%) rename app/src/main/res/layout/{fragment_community.xml => activity_community.xml} (100%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 794ace7cc..0d92e5490 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -7,7 +8,9 @@ - + + android:theme="@style/Theme.Purple" + tools:targetApi="n"> + + + + + + + } .setMessage(licenseHtml) .create() diff --git a/app/src/main/java/com/github/libretube/preferences/CommunityFragment.kt b/app/src/main/java/com/github/libretube/activities/CommunityActivity.kt similarity index 51% rename from app/src/main/java/com/github/libretube/preferences/CommunityFragment.kt rename to app/src/main/java/com/github/libretube/activities/CommunityActivity.kt index 90b2d9a5b..d28db2fa8 100644 --- a/app/src/main/java/com/github/libretube/preferences/CommunityFragment.kt +++ b/app/src/main/java/com/github/libretube/activities/CommunityActivity.kt @@ -1,38 +1,24 @@ -package com.github.libretube.preferences +package com.github.libretube.activities import android.content.Intent import android.net.Uri import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment +import androidx.appcompat.app.AppCompatActivity import com.github.libretube.DISCORD_URL import com.github.libretube.MATRIX_URL -import com.github.libretube.R import com.github.libretube.REDDIT_URL import com.github.libretube.TELEGRAM_URL import com.github.libretube.TWITTER_URL -import com.github.libretube.activities.SettingsActivity -import com.github.libretube.databinding.FragmentCommunityBinding +import com.github.libretube.databinding.ActivityCommunityBinding -class CommunityFragment : Fragment() { - private lateinit var binding: FragmentCommunityBinding +class CommunityActivity : AppCompatActivity() { + private lateinit var binding: ActivityCommunityBinding - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - binding = FragmentCommunityBinding.inflate(layoutInflater) - return binding.root - } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val settingsActivity = activity as SettingsActivity - settingsActivity.changeTopBarText(getString(R.string.community)) + binding = ActivityCommunityBinding.inflate(layoutInflater) + setContentView(binding.root) binding.telegram.setOnClickListener { openLinkFromHref(TELEGRAM_URL) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 0a07f5699..41131a4ef 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -9,6 +9,8 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.util.Log +import android.view.Menu +import android.view.MenuItem import android.view.View import android.view.WindowInsets import android.view.WindowInsetsController @@ -82,6 +84,9 @@ class MainActivity : AppCompatActivity() { binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) + // set the action bar for the activity + setSupportActionBar(binding.toolbar) + navController = findNavController(R.id.fragment) binding.bottomNav.setupWithNavController(navController) @@ -143,21 +148,40 @@ class MainActivity : AppCompatActivity() { } binding.toolbar.title = ThemeHelper.getStyledAppName(this) + } + } - binding.toolbar.setNavigationOnClickListener { - // settings activity stuff - val intent = Intent(this, SettingsActivity::class.java) - startActivity(intent) - } + override fun onCreateOptionsMenu(menu: Menu): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.action_bar, menu) + return true + } - binding.toolbar.setOnMenuItemClickListener { - when (it.itemId) { - R.id.action_search -> { - navController.navigate(R.id.searchFragment) - } - } - false + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + return when (item.itemId) { + R.id.action_search -> { + 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) } } diff --git a/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt b/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt index 433317ff2..00ad42411 100644 --- a/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt @@ -5,8 +5,6 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.github.libretube.R 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.util.ThemeHelper @@ -51,12 +49,6 @@ class SettingsActivity : AppCompatActivity() { super.onBackPressed() finishAndRemoveTask() } - is CommunityFragment -> { - supportFragmentManager - .beginTransaction() - .replace(R.id.settings, AboutFragment()) - .commit() - } else -> { supportFragmentManager .beginTransaction() diff --git a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt index 3622e3ee7..befc17f81 100644 --- a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt @@ -116,13 +116,6 @@ class MainSettings : PreferenceFragmentCompat() { } true } - - val about = findPreference("about") - about?.setOnPreferenceClickListener { - val newFragment = AboutFragment() - navigateToSettingsFragment(newFragment) - true - } } private fun navigateToSettingsFragment(newFragment: Fragment) { diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/activity_about.xml similarity index 88% rename from app/src/main/res/layout/fragment_about.xml rename to app/src/main/res/layout/activity_about.xml index 41713ad11..e9c7e5914 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -135,24 +135,6 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_community.xml b/app/src/main/res/layout/activity_community.xml similarity index 100% rename from app/src/main/res/layout/fragment_community.xml rename to app/src/main/res/layout/activity_community.xml diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 0d79b3805..f83d6cb24 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -2,8 +2,6 @@ - - - - -