From c33e069e79cf16a05d882d18757e71ba97be0090 Mon Sep 17 00:00:00 2001 From: Xinto Date: Sun, 15 Nov 2020 13:49:40 +0400 Subject: [PATCH] language selector fixes --- app/build.gradle | 17 +++++++++------ .../com/vanced/manager/adapter/LinkAdapter.kt | 21 ++++++++++--------- .../vanced/manager/adapter/SponsorAdapter.kt | 7 +++++-- .../manager/ui/fragments/AboutFragment.kt | 6 +++++- .../manager/ui/viewmodels/HomeViewModel.kt | 14 ++++++------- app/src/main/res/layout/dialog_app_info.xml | 2 +- app/src/main/res/layout/fragment_about.xml | 1 + app/src/main/res/layout/fragment_welcome.xml | 2 +- app/src/main/res/layout/view_social_link.xml | 1 - app/src/main/res/layout/view_sponsor.xml | 1 - 10 files changed, 42 insertions(+), 30 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 55882e68..1c878fe4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -71,19 +71,24 @@ android { def getLanguages() { List langs = new ArrayList() langs.add("en") + //Add languages with dialects + langs.add("bn_BD") + langs.add("bn_IN") + langs.add("pt_BR") + langs.add("pt_PT") + langs.add("zh_CN") + langs.add("zh_TW") + List exceptions = [ "bn", "pt", "zh"] Pattern pattern = Pattern.compile("-(\\w+)-") new File("${projectDir}/src/main/res").eachDir { dir -> if (dir.name.startsWith("values-") && !dir.name.contains("v23")) { Matcher matcher = pattern.matcher(dir.name) - if (matcher.find()) { - if (langs.contains(matcher.group(1))) - langs.add(matcher.group(1) + "_${dir.name.substring(dir.name.length() - 2)}") - else - langs.add(matcher.group(1)) + if (matcher.find() && !exceptions.any { matcher.group(1) == it } ) { + langs.add(matcher.group(1)) } } } - return langs.toArray() + return langs.toArray().toSorted() } static def surroundWithQuotes(Object[] arr) { diff --git a/app/src/main/java/com/vanced/manager/adapter/LinkAdapter.kt b/app/src/main/java/com/vanced/manager/adapter/LinkAdapter.kt index 92107ec9..c3108c05 100644 --- a/app/src/main/java/com/vanced/manager/adapter/LinkAdapter.kt +++ b/app/src/main/java/com/vanced/manager/adapter/LinkAdapter.kt @@ -3,7 +3,7 @@ package com.vanced.manager.adapter import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup -import androidx.core.content.ContextCompat +import androidx.appcompat.content.res.AppCompatResources import androidx.recyclerview.widget.RecyclerView import com.vanced.manager.R import com.vanced.manager.databinding.ViewSocialLinkBinding @@ -13,49 +13,49 @@ import com.vanced.manager.ui.viewmodels.HomeViewModel class LinkAdapter(context: Context, private val viewModel: HomeViewModel) : RecyclerView.Adapter() { private val instagram = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_instagram), + AppCompatResources.getDrawable(context, R.drawable.ic_instagram), "https://instagram.com/vanced.youtube" ) private val youtube = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_youtube), + AppCompatResources.getDrawable(context, R.drawable.ic_youtube), "https://youtube.com/c/YouTubeVanced" ) private val github = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_github), + AppCompatResources.getDrawable(context, R.drawable.ic_github), "https://github.com/YTVanced/VancedManager" ) private val website = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_website), + AppCompatResources.getDrawable(context, R.drawable.ic_website), "https://vancedapp.com" ) private val telegram = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_telegram), + AppCompatResources.getDrawable(context, R.drawable.ic_telegram), "https://t.me/joinchat/AAAAAEHf-pi4jH1SDlAL4w" ) private val twitter = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_twitter), + AppCompatResources.getDrawable(context, R.drawable.ic_twitter), "https://twitter.com/YTVanced" ) private val discord = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_discord), + AppCompatResources.getDrawable(context, R.drawable.ic_discord), "https://discord.gg/WCGNdRruzb" ) private val reddit = LinkModel( - ContextCompat.getDrawable(context, R.drawable.ic_reddit), + AppCompatResources.getDrawable(context, R.drawable.ic_reddit), "https://www.reddit.com/r/Vanced/" ) val links = arrayOf(instagram, youtube, github, website, telegram, twitter, discord, reddit) inner class LinkViewHolder(private val binding: ViewSocialLinkBinding) : RecyclerView.ViewHolder(binding.root) { - + val logo = binding.linkImage fun bind(position: Int) { binding.viewModel = viewModel binding.linkModel = links[position] @@ -70,6 +70,7 @@ class LinkAdapter(context: Context, private val viewModel: HomeViewModel) : Recy override fun onBindViewHolder(holder: LinkViewHolder, position: Int) { holder.bind(position) + holder.logo.setImageDrawable(links[position].linkIcon) } override fun getItemCount(): Int = links.size diff --git a/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt b/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt index 6b8bc821..41095e72 100644 --- a/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt +++ b/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt @@ -3,6 +3,7 @@ package com.vanced.manager.adapter import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup +import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.vanced.manager.R @@ -17,13 +18,13 @@ class SponsorAdapter( ) : RecyclerView.Adapter() { private val brave = SponsorModel( - ContextCompat.getDrawable(context, R.drawable.ic_brave), + AppCompatResources.getDrawable(context, R.drawable.ic_brave), "Brave", "https://vancedapp.com/brave" ) private val adguard = SponsorModel( - ContextCompat.getDrawable(context, R.drawable.ic_adguard), + AppCompatResources.getDrawable(context, R.drawable.ic_adguard), "AdGuard", "https://adguard.com/?aid=31141&source=manager" ) @@ -33,6 +34,7 @@ class SponsorAdapter( inner class LinkViewHolder(private val binding: ViewSponsorBinding) : RecyclerView.ViewHolder( binding.root ) { + val logo = binding.sponsorLogo fun bind(position: Int) { binding.viewModel = viewModel binding.sponsor = sponsors[position] @@ -47,6 +49,7 @@ class SponsorAdapter( override fun onBindViewHolder(holder: LinkViewHolder, position: Int) { holder.bind(position) + holder.logo.setImageDrawable(sponsors[position].logo) } override fun getItemCount(): Int = 2 diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/AboutFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/AboutFragment.kt index bbdfcca3..c3388e16 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/AboutFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/AboutFragment.kt @@ -7,6 +7,7 @@ import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.edit import androidx.databinding.DataBindingUtil import androidx.fragment.app.Fragment @@ -14,7 +15,10 @@ import androidx.fragment.app.viewModels import androidx.preference.PreferenceManager import com.vanced.manager.R import com.vanced.manager.databinding.FragmentAboutBinding +import com.vanced.manager.ui.dialogs.AppInfoDialog import com.vanced.manager.ui.viewmodels.AboutViewModel +import com.vanced.manager.utils.Extensions.show +import com.vanced.manager.utils.InternetTools.manager class AboutFragment : Fragment() { @@ -37,7 +41,7 @@ class AboutFragment : Fragment() { @SuppressLint("ClickableViewAccessibility") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - + binding.aboutHeader.setOnClickListener { AppInfoDialog(getString(R.string.app_name), AppCompatResources.getDrawable(requireActivity(), R.mipmap.ic_launcher), manager.get()?.string("changelog")).show(requireActivity()) } view.setOnTouchListener { _, event: MotionEvent -> val eventAction = event.action diff --git a/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt b/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt index ac602fcc..aeca2df8 100644 --- a/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/vanced/manager/ui/viewmodels/HomeViewModel.kt @@ -5,7 +5,7 @@ import android.content.ComponentName import android.content.Intent import android.view.View import android.widget.Toast -import androidx.core.content.ContextCompat +import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat.startActivity import androidx.databinding.ObservableField import androidx.fragment.app.FragmentActivity @@ -126,12 +126,12 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() { init { activity.setRefreshing(true) - vanced.set(DataModel(InternetTools.vanced, activity, vancedPkg, activity.getString(R.string.vanced), ContextCompat.getDrawable(activity, R.drawable.ic_vanced))) - vancedRoot.set(DataModel(InternetTools.vanced, activity, vancedRootPkg, activity.getString(R.string.vanced), ContextCompat.getDrawable(activity, R.drawable.ic_vanced))) - music.set(DataModel(InternetTools.music, activity, musicPkg, activity.getString(R.string.music), ContextCompat.getDrawable(activity, R.drawable.ic_music))) - musicRoot.set(DataModel(InternetTools.music, activity, musicRootPkg, activity.getString(R.string.music), ContextCompat.getDrawable(activity, R.drawable.ic_music))) - microg.set(DataModel(InternetTools.microg, activity, microgPkg, activity.getString(R.string.microg), ContextCompat.getDrawable(activity, R.drawable.ic_microg))) - manager.set(DataModel(InternetTools.manager, activity, managerPkg, activity.getString(R.string.app_name), ContextCompat.getDrawable(activity, R.mipmap.ic_launcher))) + vanced.set(DataModel(InternetTools.vanced, activity, vancedPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced))) + vancedRoot.set(DataModel(InternetTools.vanced, activity, vancedRootPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced))) + music.set(DataModel(InternetTools.music, activity, musicPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music))) + musicRoot.set(DataModel(InternetTools.music, activity, musicRootPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music))) + microg.set(DataModel(InternetTools.microg, activity, microgPkg, activity.getString(R.string.microg), AppCompatResources.getDrawable(activity, R.drawable.ic_microg))) + manager.set(DataModel(InternetTools.manager, activity, managerPkg, activity.getString(R.string.app_name), AppCompatResources.getDrawable(activity, R.mipmap.ic_launcher))) activity.setRefreshing(false) } diff --git a/app/src/main/res/layout/dialog_app_info.xml b/app/src/main/res/layout/dialog_app_info.xml index aef8cb2a..d24c6620 100644 --- a/app/src/main/res/layout/dialog_app_info.xml +++ b/app/src/main/res/layout/dialog_app_info.xml @@ -25,7 +25,7 @@ app:layout_constraintTop_toTopOf="parent" tools:text="About YouTube Vanced" /> - diff --git a/app/src/main/res/layout/fragment_welcome.xml b/app/src/main/res/layout/fragment_welcome.xml index 8331a70e..31ff0c8d 100644 --- a/app/src/main/res/layout/fragment_welcome.xml +++ b/app/src/main/res/layout/fragment_welcome.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="@dimen/top_header_margin" - android:src="@drawable/ic_launch_text" + app:srcCompat="@drawable/ic_launch_text" android:textAlignment="center" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/view_social_link.xml b/app/src/main/res/layout/view_social_link.xml index 6496be2c..2147053a 100644 --- a/app/src/main/res/layout/view_social_link.xml +++ b/app/src/main/res/layout/view_social_link.xml @@ -36,7 +36,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:src="@{linkModel.linkIcon}" app:tint="?colorLinkImage" tools:src="@drawable/ic_instagram" /> diff --git a/app/src/main/res/layout/view_sponsor.xml b/app/src/main/res/layout/view_sponsor.xml index 21f64af3..fe97b1d3 100644 --- a/app/src/main/res/layout/view_sponsor.xml +++ b/app/src/main/res/layout/view_sponsor.xml @@ -34,7 +34,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:src="@{sponsor.logo}" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:tint="?colorLinkImage"