2020-04-09 17:31:13 +00:00
|
|
|
package com.vanced.manager.ui.fragments
|
2020-03-18 18:10:54 +00:00
|
|
|
|
2020-05-10 13:07:00 +00:00
|
|
|
import android.animation.ObjectAnimator
|
2020-03-18 18:10:54 +00:00
|
|
|
import android.os.Bundle
|
2020-04-19 17:21:40 +00:00
|
|
|
import android.view.*
|
2020-05-23 17:17:27 +00:00
|
|
|
import android.widget.Button
|
|
|
|
import android.widget.TextView
|
2020-05-10 14:01:38 +00:00
|
|
|
import androidx.core.animation.addListener
|
2020-04-10 12:45:09 +00:00
|
|
|
import androidx.viewpager2.widget.ViewPager2
|
2020-05-20 14:33:53 +00:00
|
|
|
import com.dezlum.codelabs.getjson.GetJson
|
2020-05-24 15:06:20 +00:00
|
|
|
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
2020-04-22 09:41:18 +00:00
|
|
|
import com.google.android.material.card.MaterialCardView
|
2020-04-10 12:45:09 +00:00
|
|
|
import com.google.android.material.tabs.TabLayout
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
2020-05-23 17:17:27 +00:00
|
|
|
import com.google.gson.JsonObject
|
2020-04-09 17:31:13 +00:00
|
|
|
import com.vanced.manager.R
|
2020-04-24 16:10:29 +00:00
|
|
|
import com.vanced.manager.adapter.SectionPageAdapter
|
|
|
|
import com.vanced.manager.core.fragments.Home
|
2020-05-24 15:06:20 +00:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
|
import io.reactivex.disposables.Disposable
|
|
|
|
import io.reactivex.schedulers.Schedulers
|
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-04-12 12:00:14 +00:00
|
|
|
private lateinit var sectionPageAdapter: SectionPageAdapter
|
2020-04-10 12:45:09 +00:00
|
|
|
private lateinit var viewPager: ViewPager2
|
2020-05-24 15:06:20 +00:00
|
|
|
private var disposable: Disposable? = null
|
2020-04-10 12:45:09 +00:00
|
|
|
|
2020-03-18 18:10:54 +00:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2020-04-22 09:41:18 +00:00
|
|
|
activity?.title = getString(R.string.title_home)
|
|
|
|
setHasOptionsMenu(true)
|
2020-04-22 18:00:00 +00:00
|
|
|
|
2020-04-09 17:31:13 +00:00
|
|
|
return inflater.inflate(R.layout.fragment_home, container, false)
|
2020-03-19 19:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
2020-03-28 13:29:48 +00:00
|
|
|
|
2020-05-24 15:06:20 +00:00
|
|
|
//connectionStatus()
|
|
|
|
//checkNetwork()
|
2020-04-22 09:41:18 +00:00
|
|
|
|
2020-04-22 18:00:00 +00:00
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
2020-05-24 15:06:20 +00:00
|
|
|
checkNetwork()
|
|
|
|
|
2020-04-12 12:00:14 +00:00
|
|
|
sectionPageAdapter = SectionPageAdapter(this)
|
2020-04-10 12:45:09 +00:00
|
|
|
val tabLayout = view.findViewById(R.id.tablayout) as TabLayout
|
2020-04-12 12:00:14 +00:00
|
|
|
viewPager = view.findViewById(R.id.viewpager)
|
|
|
|
viewPager.adapter = sectionPageAdapter
|
2020-04-10 12:45:09 +00:00
|
|
|
|
|
|
|
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
|
|
|
|
when (position) {
|
|
|
|
0 -> tab.text = "Vanced"
|
|
|
|
1 -> tab.text = "MicroG"
|
2020-05-22 14:28:24 +00:00
|
|
|
2 -> tab.text = "Manager"
|
2020-04-10 12:45:09 +00:00
|
|
|
}
|
|
|
|
}.attach()
|
|
|
|
|
2020-03-18 18:10:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 15:06:20 +00:00
|
|
|
private fun checkNetwork() {
|
2020-05-24 15:15:17 +00:00
|
|
|
val networkErrorLayout = view?.findViewById<MaterialCardView>(R.id.home_network_wrapper)
|
2020-05-24 15:06:20 +00:00
|
|
|
disposable = ReactiveNetwork.observeInternetConnectivity()
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe { isConnectedToInternet ->
|
2020-05-24 15:25:11 +00:00
|
|
|
run {
|
2020-05-24 16:08:10 +00:00
|
|
|
val microginstallbtn = view?.findViewById<Button>(R.id.microg_installbtn)
|
|
|
|
val vancedinstallbtn = view?.findViewById<Button>(R.id.vanced_installbtn)
|
|
|
|
val vancedLatestTxt = view?.findViewById<TextView>(R.id.vanced_latest_version)
|
|
|
|
val microgLatestTxt = view?.findViewById<TextView>(R.id.microg_latest_version)
|
|
|
|
|
2020-05-24 15:25:11 +00:00
|
|
|
if (isConnectedToInternet) {
|
2020-05-24 16:08:10 +00:00
|
|
|
vancedinstallbtn?.visibility = View.VISIBLE
|
|
|
|
microginstallbtn?.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
val vancedVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json")
|
|
|
|
val microgVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
|
|
|
|
vancedLatestTxt?.text = vancedVer.get("version").asString
|
|
|
|
microgLatestTxt?.text = microgVer.get("version").asString
|
|
|
|
|
2020-05-24 15:25:11 +00:00
|
|
|
val oa2 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0f, 0.3f)
|
|
|
|
val oa3 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0.3f, -1f)
|
|
|
|
|
|
|
|
oa2.start()
|
|
|
|
oa3.apply {
|
|
|
|
oa3.addListener(onEnd = {
|
|
|
|
networkErrorLayout?.visibility = View.GONE
|
|
|
|
})
|
|
|
|
start()
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-24 16:08:10 +00:00
|
|
|
vancedinstallbtn?.visibility = View.INVISIBLE
|
|
|
|
microginstallbtn?.visibility = View.INVISIBLE
|
|
|
|
|
|
|
|
vancedLatestTxt?.text = getString(R.string.unavailable)
|
|
|
|
microgLatestTxt?.text = getString(R.string.unavailable)
|
|
|
|
|
2020-05-24 15:25:11 +00:00
|
|
|
val oa2 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", -1f, 0.3f)
|
|
|
|
val oa3 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0.3f, 0f)
|
|
|
|
|
|
|
|
oa2.apply {
|
|
|
|
oa2.addListener(onStart = {
|
|
|
|
networkErrorLayout?.visibility = View.VISIBLE
|
|
|
|
})
|
|
|
|
start()
|
|
|
|
}
|
|
|
|
oa3.start()
|
|
|
|
|
2020-05-24 15:06:20 +00:00
|
|
|
}
|
2020-05-24 15:25:11 +00:00
|
|
|
|
2020-05-24 15:15:17 +00:00
|
|
|
|
2020-05-24 15:06:20 +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-04-22 09:41:18 +00:00
|
|
|
super .onCreateOptionsMenu(menu, inflater)
|
2020-04-19 17:21:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 18:10:54 +00:00
|
|
|
}
|
2020-04-03 16:40:54 +00:00
|
|
|
|