2020-04-09 17:31:13 +00:00
|
|
|
package com.vanced.manager.ui.fragments
|
2020-03-18 18:10:54 +00:00
|
|
|
|
2020-07-03 17:46:09 +00:00
|
|
|
import android.content.*
|
2020-03-18 18:10:54 +00:00
|
|
|
import android.os.Bundle
|
2020-04-19 17:21:40 +00:00
|
|
|
import android.view.*
|
2020-06-28 14:47:51 +00:00
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator
|
2020-07-03 17:46:09 +00:00
|
|
|
import android.widget.Toast
|
2020-06-04 07:35:26 +00:00
|
|
|
import androidx.databinding.DataBindingUtil
|
2020-06-04 08:39:04 +00:00
|
|
|
import androidx.fragment.app.viewModels
|
2020-06-08 11:23:45 +00:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
2020-05-30 13:49:03 +00:00
|
|
|
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
2020-04-10 12:45:09 +00:00
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
2020-04-09 17:31:13 +00:00
|
|
|
import com.vanced.manager.R
|
2020-07-04 16:06:32 +00:00
|
|
|
import com.vanced.manager.adapter.*
|
2020-04-24 16:10:29 +00:00
|
|
|
import com.vanced.manager.core.fragments.Home
|
2020-06-04 07:35:26 +00:00
|
|
|
import com.vanced.manager.databinding.FragmentHomeBinding
|
2020-06-04 08:39:04 +00:00
|
|
|
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
2020-03-18 18:10:54 +00:00
|
|
|
|
2020-04-24 16:10:29 +00:00
|
|
|
class HomeFragment : Home() {
|
2020-03-18 18:10:54 +00:00
|
|
|
|
2020-06-04 07:35:26 +00:00
|
|
|
private lateinit var binding: FragmentHomeBinding
|
2020-06-25 14:22:33 +00:00
|
|
|
private var isExpanded: Boolean = false
|
2020-07-04 13:44:28 +00:00
|
|
|
private val viewModel: HomeViewModel by viewModels()
|
|
|
|
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
|
2020-04-10 12:45:09 +00:00
|
|
|
|
2020-03-18 18:10:54 +00:00
|
|
|
override fun onCreateView(
|
2020-07-16 21:05:31 +00:00
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
2020-03-18 18:10:54 +00:00
|
|
|
): View? {
|
2020-07-04 13:44:28 +00:00
|
|
|
requireActivity().title = getString(R.string.title_home)
|
2020-04-22 09:41:18 +00:00
|
|
|
setHasOptionsMenu(true)
|
2020-06-04 07:35:26 +00:00
|
|
|
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
|
|
|
|
return binding.root
|
2020-03-19 19:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
2020-04-22 18:00:00 +00:00
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-06-04 09:06:02 +00:00
|
|
|
binding.viewModel = viewModel
|
2020-05-24 15:06:20 +00:00
|
|
|
|
2020-06-20 15:11:24 +00:00
|
|
|
val variantPref = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
|
2020-06-08 11:23:45 +00:00
|
|
|
registerReceivers()
|
2020-06-04 17:12:50 +00:00
|
|
|
|
2020-07-16 21:05:31 +00:00
|
|
|
/*
|
|
|
|
if (variantPref == "nonroot") {
|
2020-07-05 15:05:09 +00:00
|
|
|
if (!viewModel.microgInstalled.get()!!) {
|
2020-06-26 16:00:17 +00:00
|
|
|
disableVancedButton()
|
2020-06-24 19:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-10 12:45:09 +00:00
|
|
|
|
2020-07-16 21:05:31 +00:00
|
|
|
*/
|
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
binding.includeChangelogsLayout.changelogButton.setOnClickListener {
|
2020-06-27 15:03:59 +00:00
|
|
|
cardExpandCollapse()
|
2020-06-25 14:22:33 +00:00
|
|
|
}
|
2020-07-03 17:46:09 +00:00
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
binding.includeVancedLayout.vancedCard.setOnLongClickListener {
|
|
|
|
val clip = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
2020-07-05 15:06:23 +00:00
|
|
|
clip.setPrimaryClip(ClipData.newPlainText("vanced", this.viewModel.vancedInstalledVersion.get()))
|
2020-07-03 23:22:50 +00:00
|
|
|
versionToast("Vanced")
|
2020-07-03 17:46:09 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
binding.includeMicrogLayout.microgCard.setOnLongClickListener {
|
|
|
|
val clip = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
2020-07-05 15:06:23 +00:00
|
|
|
clip.setPrimaryClip(ClipData.newPlainText("microg", viewModel.microgInstalledVersion.get()))
|
2020-07-03 23:22:50 +00:00
|
|
|
versionToast("MicroG")
|
2020-07-03 17:46:09 +00:00
|
|
|
true
|
|
|
|
}
|
2020-07-16 21:05:31 +00:00
|
|
|
|
|
|
|
with(binding.includeChangelogsLayout) {
|
|
|
|
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
|
|
|
|
TabLayoutMediator(tablayout, viewpager) { tab, position ->
|
|
|
|
if (variantPref == "root")
|
|
|
|
when (position) {
|
|
|
|
0 -> tab.text = "Vanced"
|
|
|
|
1 -> tab.text = "Manager"
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
when (position) {
|
|
|
|
0 -> tab.text = "Vanced"
|
|
|
|
1 -> tab.text = "MicroG"
|
|
|
|
2 -> tab.text = "Manager"
|
|
|
|
}
|
|
|
|
|
|
|
|
}.attach()
|
|
|
|
}
|
2020-06-25 15:58:23 +00:00
|
|
|
}
|
2020-06-25 14:22:33 +00:00
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
private fun versionToast(name: String) {
|
2020-07-03 17:52:15 +00:00
|
|
|
Toast.makeText(activity, getString(R.string.version_toast, name), Toast.LENGTH_LONG).show()
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:22:33 +00:00
|
|
|
private fun cardExpandCollapse() {
|
2020-07-04 13:44:28 +00:00
|
|
|
with(binding.includeChangelogsLayout) {
|
2020-07-22 13:33:45 +00:00
|
|
|
activity?.runOnUiThread { viewModel?.expanded?.set(!isExpanded) }
|
2020-07-04 13:44:28 +00:00
|
|
|
changelogButton.animate().apply {
|
|
|
|
rotation(if (isExpanded) 0F else 180F)
|
|
|
|
interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
}
|
|
|
|
isExpanded = !isExpanded
|
2020-06-25 14:22:33 +00:00
|
|
|
}
|
2020-03-18 18:10:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 11:23:45 +00:00
|
|
|
override fun onPause() {
|
2020-07-04 13:44:28 +00:00
|
|
|
localBroadcastManager.unregisterReceiver(broadcastReceiver)
|
2020-06-08 11:23:45 +00:00
|
|
|
super.onPause()
|
|
|
|
}
|
|
|
|
|
|
|
|
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
|
|
|
override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
when (intent.action) {
|
2020-07-05 15:05:09 +00:00
|
|
|
MICROG_DOWNLOADED -> binding.includeMicrogLayout.microgInstalling.visibility = View.VISIBLE
|
|
|
|
VANCED_DOWNLOADED -> binding.includeVancedLayout.vancedInstalling.visibility = View.VISIBLE
|
2020-07-22 13:33:45 +00:00
|
|
|
REFRESH_HOME -> activity?.runOnUiThread { viewModel.fetchData() }
|
2020-06-08 11:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun registerReceivers() {
|
2020-06-23 13:47:20 +00:00
|
|
|
val intentFilter = IntentFilter()
|
|
|
|
intentFilter.addAction(VANCED_DOWNLOADED)
|
|
|
|
intentFilter.addAction(MICROG_DOWNLOADED)
|
2020-07-16 21:05:31 +00:00
|
|
|
intentFilter.addAction(REFRESH_HOME)
|
2020-07-04 13:44:28 +00:00
|
|
|
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
|
2020-06-08 11:23:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-19 17:21:40 +00:00
|
|
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
|
|
|
inflater.inflate(R.menu.toolbar_menu, menu)
|
2020-07-04 13:44:28 +00:00
|
|
|
super.onCreateOptionsMenu(menu, inflater)
|
2020-04-19 17:21:40 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 21:05:31 +00:00
|
|
|
/*
|
2020-06-26 16:00:17 +00:00
|
|
|
private fun disableVancedButton() {
|
2020-07-04 13:44:28 +00:00
|
|
|
binding.includeVancedLayout.vancedInstallbtn.apply {
|
|
|
|
icon = null
|
|
|
|
isEnabled = false
|
|
|
|
backgroundTintList = ColorStateList.valueOf(Color.DKGRAY)
|
|
|
|
setTextColor(ColorStateList.valueOf(Color.GRAY))
|
|
|
|
}
|
2020-06-15 16:56:56 +00:00
|
|
|
}
|
2020-07-16 21:05:31 +00:00
|
|
|
*/
|
2020-06-15 16:56:56 +00:00
|
|
|
|
2020-06-08 11:23:45 +00:00
|
|
|
companion object {
|
2020-07-04 13:44:28 +00:00
|
|
|
const val VANCED_DOWNLOADED = "vanced_downloaded"
|
|
|
|
const val MICROG_DOWNLOADED = "microg_downloaded"
|
2020-07-16 21:05:31 +00:00
|
|
|
const val REFRESH_HOME = "refresh_home"
|
2020-06-08 11:23:45 +00:00
|
|
|
}
|
2020-03-18 18:10:54 +00:00
|
|
|
}
|
2020-04-03 16:40:54 +00:00
|
|
|
|