mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-15 19:20:53 -04:00
Migrate ScreenshotActivity to fragment
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -108,7 +108,6 @@
|
||||
</activity>
|
||||
|
||||
<activity android:name=".view.ui.commons.StreamBrowseActivity" />
|
||||
<activity android:name=".view.ui.details.ScreenshotActivity" />
|
||||
<activity android:name=".view.ui.details.DetailsMoreActivity" />
|
||||
<activity android:name=".view.ui.details.DetailsReviewActivity" />
|
||||
<activity android:name=".view.ui.account.GoogleActivity" />
|
||||
|
||||
@@ -85,15 +85,6 @@ abstract class BaseActivity : AppCompatActivity(), NetworkProvider.NetworkListen
|
||||
startActivity(intent, getEmptyActivityBundle())
|
||||
}
|
||||
|
||||
fun openScreenshotActivity(app: App, position: Int) {
|
||||
val intent = Intent(this, ScreenshotActivity::class.java).apply {
|
||||
putExtra(Constants.STRING_EXTRA, gson.toJson(app.screenshots))
|
||||
putExtra(Constants.INT_EXTRA, position)
|
||||
}
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(this)
|
||||
startActivity(intent, options.toBundle())
|
||||
}
|
||||
|
||||
fun openGoogleActivity() {
|
||||
val intent = Intent(this, GoogleActivity::class.java)
|
||||
startActivity(intent, getEmptyActivityBundle())
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
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,6 +30,7 @@ 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.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.lang.reflect.Modifier
|
||||
@@ -83,4 +85,13 @@ open class BaseFragment : Fragment {
|
||||
MobileNavigationDirections.actionGlobalEditorStreamBrowseFragment(title, browseUrl)
|
||||
)
|
||||
}
|
||||
|
||||
fun openScreenshotFragment(app: App, position: Int) {
|
||||
findNavController().navigate(
|
||||
MobileNavigationDirections.actionGlobalScreenshotFragment(
|
||||
position,
|
||||
gson.toJson(app.screenshots)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import com.airbnb.epoxy.EpoxyModel
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.MainActivity
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.databinding.ActivityGenericRecyclerBinding
|
||||
import com.aurora.store.view.epoxy.groups.CarouselHorizontalModel_
|
||||
@@ -99,10 +98,7 @@ class EditorStreamBrowseFragment : BaseFragment(R.layout.activity_generic_recycl
|
||||
.artwork(artwork)
|
||||
.callback(object : MiniScreenshotView.ScreenshotCallback {
|
||||
override fun onClick(position: Int) {
|
||||
(activity as MainActivity).openScreenshotActivity(
|
||||
app,
|
||||
position
|
||||
)
|
||||
openScreenshotFragment(app, position)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -26,7 +26,6 @@ import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import com.airbnb.epoxy.EpoxyModel
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
import com.aurora.store.MainActivity
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.databinding.ActivityGenericRecyclerBinding
|
||||
import com.aurora.store.view.custom.recycler.EndlessRecyclerOnScrollListener
|
||||
@@ -119,10 +118,7 @@ class ExpandedStreamBrowseFragment : BaseFragment(R.layout.activity_generic_recy
|
||||
.artwork(artwork)
|
||||
.callback(object : MiniScreenshotView.ScreenshotCallback {
|
||||
override fun onClick(position: Int) {
|
||||
(activity as MainActivity).openScreenshotActivity(
|
||||
it,
|
||||
position
|
||||
)
|
||||
openScreenshotFragment(it, position)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -938,7 +938,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
.position(position++)
|
||||
.callback(object : ScreenshotView.ScreenshotCallback {
|
||||
override fun onClick(position: Int) {
|
||||
(activity as MainActivity).openScreenshotActivity(app, position)
|
||||
openScreenshotFragment(app, position)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -1,114 +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.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.PagerSnapHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.Artwork
|
||||
import com.aurora.store.databinding.ActivityScreenshotBinding
|
||||
import com.aurora.store.view.epoxy.views.details.LargeScreenshotViewModel_
|
||||
import com.aurora.store.view.ui.commons.BaseActivity
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
class ScreenshotActivity : BaseActivity() {
|
||||
|
||||
private lateinit var B: ActivityScreenshotBinding
|
||||
private lateinit var artworks: MutableList<Artwork>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// ViewUtil.configureActivityLayout(this, false)
|
||||
|
||||
B = ActivityScreenshotBinding.inflate(layoutInflater)
|
||||
setContentView(B.root)
|
||||
|
||||
attachToolbar()
|
||||
attachRecycler()
|
||||
|
||||
if (intent != null) {
|
||||
val rawArtWorks = intent.getStringExtra(Constants.STRING_EXTRA).toString()
|
||||
val position = intent.getIntExtra(Constants.INT_EXTRA, 0)
|
||||
artworks = gson.fromJson(rawArtWorks, object : TypeToken<List<Artwork?>?>() {}.type)
|
||||
updateController(artworks, position)
|
||||
} else {
|
||||
finishAfterTransition()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun attachToolbar() {
|
||||
setSupportActionBar(B.toolbar)
|
||||
val actionBar = supportActionBar
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayShowCustomEnabled(true)
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.elevation = 0f
|
||||
actionBar.title = ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun attachRecycler() {
|
||||
B.recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(
|
||||
this@ScreenshotActivity,
|
||||
RecyclerView.HORIZONTAL,
|
||||
false
|
||||
)
|
||||
PagerSnapHelper().attachToRecyclerView(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateController(artworks: MutableList<Artwork>, position: Int) {
|
||||
B.recyclerView.withModels {
|
||||
artworks.forEach {
|
||||
add(
|
||||
LargeScreenshotViewModel_()
|
||||
.id(it.url)
|
||||
.artwork(it)
|
||||
)
|
||||
}
|
||||
B.recyclerView.scrollToPosition(position)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConnected() {
|
||||
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
}
|
||||
|
||||
override fun onReconnected() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.core.content.ContextCompat
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.PagerSnapHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.aurora.gplayapi.data.models.Artwork
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.databinding.FragmentScreenshotBinding
|
||||
import com.aurora.store.view.epoxy.views.details.LargeScreenshotViewModel_
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
class ScreenshotFragment : BaseFragment(R.layout.fragment_screenshot) {
|
||||
|
||||
private var _binding: FragmentScreenshotBinding? = null
|
||||
private val binding: FragmentScreenshotBinding
|
||||
get() = _binding!!
|
||||
|
||||
private val args: ScreenshotFragmentArgs by navArgs()
|
||||
|
||||
private lateinit var artworks: MutableList<Artwork>
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentScreenshotBinding.bind(view)
|
||||
|
||||
// Toolbar
|
||||
binding.toolbar.apply {
|
||||
elevation = 0f
|
||||
navigationIcon = ContextCompat.getDrawable(view.context, R.drawable.ic_arrow_back)
|
||||
setNavigationOnClickListener { findNavController().navigateUp() }
|
||||
}
|
||||
|
||||
// Recycler View
|
||||
binding.recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(view.context, RecyclerView.HORIZONTAL, false)
|
||||
PagerSnapHelper().attachToRecyclerView(this)
|
||||
}
|
||||
|
||||
artworks = gson.fromJson(args.rawArtWorks, object : TypeToken<List<Artwork?>?>() {}.type)
|
||||
updateController(artworks, args.position)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
private fun updateController(artworks: MutableList<Artwork>, position: Int) {
|
||||
binding.recyclerView.withModels {
|
||||
artworks.forEach {
|
||||
add(
|
||||
LargeScreenshotViewModel_()
|
||||
.id(it.url)
|
||||
.artwork(it)
|
||||
)
|
||||
}
|
||||
binding.recyclerView.scrollToPosition(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,8 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".view.ui.details.ScreenshotFragment">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
@@ -140,6 +140,17 @@
|
||||
android:name="expandedStreamUrl"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/screenshotFragment"
|
||||
android:name="com.aurora.store.view.ui.details.ScreenshotFragment"
|
||||
tools:layout="@layout/fragment_screenshot" >
|
||||
<argument
|
||||
android:name="position"
|
||||
app:argType="integer" />
|
||||
<argument
|
||||
android:name="rawArtWorks"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
<action
|
||||
android:id="@+id/action_global_appDetailsFragment"
|
||||
app:destination="@id/appDetailsFragment" />
|
||||
@@ -152,4 +163,7 @@
|
||||
<action
|
||||
android:id="@+id/action_global_expandedStreamBrowseFragment"
|
||||
app:destination="@id/expandedStreamBrowseFragment" />
|
||||
<action
|
||||
android:id="@+id/action_global_screenshotFragment"
|
||||
app:destination="@id/screenshotFragment" />
|
||||
</navigation>
|
||||
|
||||
Reference in New Issue
Block a user