2020-03-18 18:10:54 +00:00
|
|
|
package com.vanced.manager
|
|
|
|
|
2020-03-21 11:16:38 +00:00
|
|
|
import android.content.ComponentName
|
2020-03-19 19:55:00 +00:00
|
|
|
import android.net.Uri
|
2020-03-18 18:10:54 +00:00
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-03-19 19:55:00 +00:00
|
|
|
import android.widget.Button
|
2020-03-21 11:16:38 +00:00
|
|
|
import android.content.pm.PackageManager
|
|
|
|
import android.content.Intent
|
2020-03-19 19:55:00 +00:00
|
|
|
import androidx.browser.customtabs.CustomTabsIntent
|
2020-03-21 11:16:38 +00:00
|
|
|
import android.widget.Toast
|
2020-03-19 19:55:00 +00:00
|
|
|
import androidx.core.content.ContextCompat
|
2020-03-18 18:10:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple [Fragment] subclass.
|
|
|
|
*/
|
|
|
|
class HomeFragment : Fragment() {
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
|
|
|
return inflater.inflate(R.layout.fragment_home, container, false)
|
2020-03-19 19:55:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 11:16:38 +00:00
|
|
|
private fun isMicrogInstalled(packageName:String, packageManager:PackageManager):Boolean {
|
|
|
|
return try {
|
|
|
|
packageManager.getPackageInfo(packageName, 0)
|
|
|
|
true
|
|
|
|
} catch (e:PackageManager.NameNotFoundException) {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 19:55:00 +00:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
2020-03-21 11:16:38 +00:00
|
|
|
(activity as MainActivity).supportActionBar?.title = getString(R.string.home)
|
|
|
|
|
2020-03-19 19:55:00 +00:00
|
|
|
val braveurl = "https://brave.com/van874"
|
2020-03-21 11:16:38 +00:00
|
|
|
val vancedurl = "https://vanced.app"
|
2020-03-19 19:55:00 +00:00
|
|
|
val builder = CustomTabsIntent.Builder()
|
|
|
|
val brave = getView()?.findViewById(R.id.button) as Button
|
|
|
|
val website = getView()?.findViewById(R.id.button2) as Button
|
2020-03-21 11:16:38 +00:00
|
|
|
val mgsettings = getView()?.findViewById(R.id.button8) as Button
|
|
|
|
val pm = activity?.packageManager
|
|
|
|
val isInstalled = pm?.let { isMicrogInstalled("com.mgoogle.android.gms", it) }
|
2020-03-19 19:55:00 +00:00
|
|
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-03-18 18:10:54 +00:00
|
|
|
|
2020-03-19 19:55:00 +00:00
|
|
|
brave.setOnClickListener{
|
2020-03-21 11:16:38 +00:00
|
|
|
builder.setToolbarColor(ContextCompat.getColor(requireContext(), R.color.Brave))
|
2020-03-19 19:55:00 +00:00
|
|
|
val customTabsIntent = builder.build()
|
|
|
|
customTabsIntent.launchUrl(requireContext(), Uri.parse(braveurl))
|
|
|
|
}
|
|
|
|
website.setOnClickListener{
|
2020-03-21 11:16:38 +00:00
|
|
|
builder.setToolbarColor(ContextCompat.getColor(requireContext(), R.color.Vanced))
|
2020-03-19 19:55:00 +00:00
|
|
|
val customTabsIntent = builder.build()
|
|
|
|
customTabsIntent.launchUrl(requireContext(), Uri.parse(vancedurl))
|
|
|
|
}
|
2020-03-21 11:16:38 +00:00
|
|
|
mgsettings.setOnClickListener{
|
|
|
|
if (isInstalled == true) {
|
|
|
|
val intent = Intent()
|
|
|
|
intent.component = ComponentName(
|
|
|
|
"com.mgoogle.android.gms",
|
|
|
|
"org.microg.gms.ui.SettingsActivity"
|
|
|
|
)
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
val toast = Toast.makeText(context, "Install MicroG First!", Toast.LENGTH_SHORT)
|
|
|
|
toast.show()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-03-18 18:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|