Migrate DevProfileActivity to fragment
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -25,13 +25,11 @@ import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.applyTheme
|
||||
import com.aurora.extensions.getEmptyActivityBundle
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.data.providers.NetworkProvider
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
||||
import com.aurora.store.view.ui.account.GoogleActivity
|
||||
import com.aurora.store.view.ui.details.*
|
||||
import com.aurora.store.view.ui.sheets.NetworkDialogSheet
|
||||
import com.aurora.store.view.ui.sheets.TOSSheet
|
||||
@@ -72,24 +70,6 @@ abstract class BaseActivity : AppCompatActivity(), NetworkProvider.NetworkListen
|
||||
startActivity(intent, options.toBundle())
|
||||
}
|
||||
|
||||
fun openStreamBrowseActivity(browseUrl: String, title: String = "") {
|
||||
val intent = if (browseUrl.lowercase().contains("expanded")) {
|
||||
Intent(this, ExpandedStreamBrowseFragment::class.java)
|
||||
} else if (browseUrl.lowercase().contains("developer")) {
|
||||
Intent(this, DevProfileActivity::class.java)
|
||||
} else {
|
||||
Intent(this, StreamBrowseActivity::class.java)
|
||||
}
|
||||
intent.putExtra(Constants.BROWSE_EXTRA, browseUrl)
|
||||
intent.putExtra(Constants.STRING_EXTRA, title)
|
||||
startActivity(intent, getEmptyActivityBundle())
|
||||
}
|
||||
|
||||
fun openGoogleActivity() {
|
||||
val intent = Intent(this, GoogleActivity::class.java)
|
||||
startActivity(intent, getEmptyActivityBundle())
|
||||
}
|
||||
|
||||
fun askToReadTOS() {
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Intent
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -29,8 +28,7 @@ import com.aurora.extensions.getEmptyActivityBundle
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.Category
|
||||
import com.aurora.store.MobileNavigationDirections
|
||||
import com.aurora.store.view.ui.details.DevProfileActivity
|
||||
import com.aurora.store.view.ui.details.ScreenshotFragment
|
||||
import com.aurora.store.view.ui.details.DevProfileFragment
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.lang.reflect.Modifier
|
||||
@@ -68,12 +66,15 @@ open class BaseFragment : Fragment {
|
||||
browseUrl
|
||||
)
|
||||
)
|
||||
} else if (browseUrl.lowercase().contains("developer")) {
|
||||
findNavController().navigate(
|
||||
MobileNavigationDirections.actionGlobalDevProfileFragment(
|
||||
browseUrl.substringAfter("developer-"),
|
||||
title
|
||||
)
|
||||
)
|
||||
} else {
|
||||
val intent = if (browseUrl.lowercase().contains("developer"))
|
||||
Intent(requireContext(), DevProfileActivity::class.java)
|
||||
else
|
||||
Intent(requireContext(), StreamBrowseActivity::class.java)
|
||||
|
||||
val intent = Intent(requireContext(), StreamBrowseActivity::class.java)
|
||||
intent.putExtra(Constants.BROWSE_EXTRA, browseUrl)
|
||||
intent.putExtra(Constants.STRING_EXTRA, title)
|
||||
startActivity(intent, requireContext().getEmptyActivityBundle())
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.details
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.data.models.details.DevStream
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.ViewState
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.databinding.ActivityDevProfileBinding
|
||||
import com.aurora.extensions.load
|
||||
import com.aurora.store.view.epoxy.controller.DeveloperCarouselController
|
||||
import com.aurora.store.view.epoxy.controller.GenericCarouselController
|
||||
import com.aurora.store.view.ui.commons.BaseActivity
|
||||
import com.aurora.store.viewmodel.details.DevProfileViewModel
|
||||
|
||||
class DevProfileActivity : BaseActivity(), GenericCarouselController.Callbacks {
|
||||
|
||||
private lateinit var B: ActivityDevProfileBinding
|
||||
private lateinit var VM: DevProfileViewModel
|
||||
private lateinit var C: DeveloperCarouselController
|
||||
private lateinit var authData: AuthData
|
||||
|
||||
override fun onConnected() {
|
||||
hideNetworkConnectivitySheet()
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
showNetworkConnectivitySheet()
|
||||
}
|
||||
|
||||
override fun onReconnected() {
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
B = ActivityDevProfileBinding.inflate(layoutInflater)
|
||||
C = DeveloperCarouselController(this)
|
||||
VM = ViewModelProvider(this)[DevProfileViewModel::class.java]
|
||||
|
||||
authData = AuthProvider.with(this).getAuthData()
|
||||
|
||||
setContentView(B.root)
|
||||
|
||||
attachToolbar()
|
||||
attachRecycler()
|
||||
|
||||
VM.liveData.observe(this) {
|
||||
when (it) {
|
||||
is ViewState.Empty -> {
|
||||
}
|
||||
is ViewState.Loading -> {
|
||||
|
||||
}
|
||||
is ViewState.Error -> {
|
||||
|
||||
}
|
||||
is ViewState.Status -> {
|
||||
|
||||
}
|
||||
is ViewState.Success<*> -> {
|
||||
updateInfo(it.data as DevStream)
|
||||
updateController(it.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
B.viewFlipper.displayedChild = 1
|
||||
|
||||
onNewIntent(intent)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
if (intent != null) {
|
||||
if (intent.scheme != null && (intent.scheme == "http" || intent.scheme == "https")) {
|
||||
val devId = intent.data!!.getQueryParameter("id")
|
||||
if (devId.isNullOrEmpty()) {
|
||||
finishAfterTransition()
|
||||
} else {
|
||||
VM.getStreamBundle(devId)
|
||||
}
|
||||
} else {
|
||||
intent.getStringExtra(Constants.BROWSE_EXTRA)?.let {
|
||||
VM.getStreamBundle(it.substringAfter("developer-"))
|
||||
}
|
||||
intent.getStringExtra(Constants.STRING_EXTRA)?.let {
|
||||
B.layoutToolbarAction.txtTitle.text = it
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finishAfterTransition()
|
||||
}
|
||||
}
|
||||
|
||||
private fun attachToolbar() {
|
||||
B.layoutToolbarAction.toolbar.setOnClickListener {
|
||||
finishAfterTransition()
|
||||
}
|
||||
B.layoutToolbarAction.txtTitle.text = getString(R.string.details_dev_profile)
|
||||
}
|
||||
|
||||
private fun attachRecycler() {
|
||||
B.recycler.setController(C)
|
||||
}
|
||||
|
||||
private fun updateInfo(devStream: DevStream) {
|
||||
B.layoutToolbarAction.txtTitle.text = devStream.title
|
||||
B.txtDevName.text = devStream.title
|
||||
B.txtDevDescription.text = devStream.description
|
||||
B.imgIcon.load(devStream.imgUrl)
|
||||
B.viewFlipper.displayedChild = 0
|
||||
}
|
||||
|
||||
private fun updateController(devStream: DevStream) {
|
||||
C.setData(devStream.streamBundle)
|
||||
}
|
||||
|
||||
override fun onHeaderClicked(streamCluster: StreamCluster) {
|
||||
openStreamBrowseActivity(streamCluster.clusterBrowseUrl, streamCluster.clusterTitle)
|
||||
}
|
||||
|
||||
override fun onClusterScrolled(streamCluster: StreamCluster) {
|
||||
VM.observeCluster(streamCluster)
|
||||
}
|
||||
|
||||
override fun onAppClick(app: App) {
|
||||
openDetailsActivity(app)
|
||||
}
|
||||
|
||||
override fun onAppLongClick(app: App) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.details
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import com.aurora.extensions.load
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.gplayapi.data.models.details.DevStream
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.ViewState
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.databinding.FragmentDevProfileBinding
|
||||
import com.aurora.store.view.epoxy.controller.DeveloperCarouselController
|
||||
import com.aurora.store.view.epoxy.controller.GenericCarouselController
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.aurora.store.viewmodel.details.DevProfileViewModel
|
||||
|
||||
class DevProfileFragment : BaseFragment(R.layout.fragment_dev_profile),
|
||||
GenericCarouselController.Callbacks {
|
||||
|
||||
private var _binding: FragmentDevProfileBinding? = null
|
||||
private val binding: FragmentDevProfileBinding
|
||||
get() = _binding!!
|
||||
|
||||
private val args: DevProfileFragmentArgs by navArgs()
|
||||
|
||||
private lateinit var VM: DevProfileViewModel
|
||||
private lateinit var C: DeveloperCarouselController
|
||||
private lateinit var authData: AuthData
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentDevProfileBinding.bind(view)
|
||||
|
||||
C = DeveloperCarouselController(this)
|
||||
VM = ViewModelProvider(this)[DevProfileViewModel::class.java]
|
||||
authData = AuthProvider.with(requireContext()).getAuthData()
|
||||
|
||||
// Toolbar
|
||||
binding.layoutToolbarAction.apply {
|
||||
txtTitle.text =
|
||||
if (args.title.isNullOrBlank()) getString(R.string.details_dev_profile) else args.title
|
||||
toolbar.setOnClickListener { findNavController().navigateUp() }
|
||||
}
|
||||
|
||||
// RecyclerView
|
||||
binding.recycler.setController(C)
|
||||
|
||||
VM.liveData.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is ViewState.Empty -> {
|
||||
}
|
||||
|
||||
is ViewState.Loading -> {
|
||||
|
||||
}
|
||||
|
||||
is ViewState.Error -> {
|
||||
|
||||
}
|
||||
|
||||
is ViewState.Status -> {
|
||||
|
||||
}
|
||||
|
||||
is ViewState.Success<*> -> {
|
||||
(it.data as DevStream).apply {
|
||||
binding.layoutToolbarAction.txtTitle.text = title
|
||||
binding.txtDevName.text = title
|
||||
binding.txtDevDescription.text = description
|
||||
binding.imgIcon.load(imgUrl)
|
||||
binding.viewFlipper.displayedChild = 0
|
||||
C.setData(streamBundle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.viewFlipper.displayedChild = 1
|
||||
VM.getStreamBundle(args.devId)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onHeaderClicked(streamCluster: StreamCluster) {
|
||||
openStreamBrowseActivity(streamCluster.clusterBrowseUrl, streamCluster.clusterTitle)
|
||||
}
|
||||
|
||||
override fun onClusterScrolled(streamCluster: StreamCluster) {
|
||||
VM.observeCluster(streamCluster)
|
||||
}
|
||||
|
||||
override fun onAppClick(app: App) {
|
||||
openDetailsActivity(app)
|
||||
}
|
||||
|
||||
override fun onAppLongClick(app: App) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user