feat: open stat in new window
This commit is contained in:
parent
49dc9d55b5
commit
d181dcf837
7 changed files with 88 additions and 28 deletions
|
@ -122,6 +122,8 @@
|
|||
android:name=".media.CalendarActivity"
|
||||
android:parentActivityName=".MainActivity" />
|
||||
<activity android:name=".media.user.ListActivity" />
|
||||
<activity android:name=".profile.SingleStatActivity"
|
||||
android:parentActivityName=".profile.ProfileActivity"/>
|
||||
<activity
|
||||
android:name=".media.manga.mangareader.MangaReaderActivity"
|
||||
android:excludeFromRecents="true"
|
||||
|
|
|
@ -116,7 +116,7 @@ class ChartBuilder {
|
|||
aaOptions.chart?.scrollablePlotArea(AAScrollablePlotArea().scrollPositionX(scrollPos))
|
||||
aaOptions.chart?.scrollablePlotArea?.minWidth((context.resources.displayMetrics.widthPixels.toFloat() / context.resources.displayMetrics.density) * (names.size.toFloat() / 18.0f))
|
||||
}
|
||||
val min = statData.minOfOrNull { it.toDouble() } ?: 0.0
|
||||
val min = ((statData.minOfOrNull { it.toDouble() } ?: 0.0) - 1.0).coerceAtLeast(0.0)
|
||||
val max = statData.maxOfOrNull { it.toDouble() } ?: 0.0
|
||||
val aaYaxis = AAYAxis().min(min).max(max)
|
||||
val tickInterval = when (max) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ani.dantotsu.profile
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.databinding.ItemChartBinding
|
||||
|
@ -8,12 +9,19 @@ import com.xwray.groupie.viewbinding.BindableItem
|
|||
|
||||
class ChartItem(
|
||||
private val title: String,
|
||||
private val aaOptions: AAOptions): BindableItem<ItemChartBinding>() {
|
||||
private val aaOptions: AAOptions,
|
||||
private val activity: ProfileActivity): BindableItem<ItemChartBinding>() {
|
||||
private lateinit var binding: ItemChartBinding
|
||||
override fun bind(viewBinding: ItemChartBinding, position: Int) {
|
||||
binding = viewBinding
|
||||
binding.typeText.text = title
|
||||
binding.chartView.aa_drawChartWithChartOptions(aaOptions)
|
||||
binding.openButton.setOnClickListener {
|
||||
SingleStatActivity.chartOptions = aaOptions
|
||||
activity.startActivity(
|
||||
Intent(activity, SingleStatActivity::class.java)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayout(): Int {
|
||||
|
|
|
@ -1,42 +1,36 @@
|
|||
package ani.dantotsu.profile
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.connections.anilist.Anilist
|
||||
import ani.dantotsu.connections.anilist.api.Query
|
||||
import ani.dantotsu.databinding.ActivityProfileBinding
|
||||
import ani.dantotsu.initActivity
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.media.MediaDetailsActivity
|
||||
import ani.dantotsu.media.user.ListActivity
|
||||
import ani.dantotsu.navBarHeight
|
||||
import ani.dantotsu.others.ImageViewDialog
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.statusBarHeight
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
import ani.dantotsu.toast
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import nl.joery.animatedbottombar.AnimatedBottomBar
|
||||
|
||||
|
||||
class ProfileActivity : AppCompatActivity(){
|
||||
class ProfileActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityProfileBinding
|
||||
private var selected: Int = 0
|
||||
private lateinit var navBar: AnimatedBottomBar
|
||||
|
@ -61,13 +55,16 @@ class ProfileActivity : AppCompatActivity(){
|
|||
val respond = Anilist.query.getUserProfile(userid)
|
||||
val user = respond?.data?.user
|
||||
if (user == null) {
|
||||
snackString("User not found")
|
||||
toast("User not found")
|
||||
finish()
|
||||
return@launch
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.profileViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarHeight }
|
||||
binding.profileViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, user)
|
||||
binding.profileViewPager.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = navBarHeight
|
||||
}
|
||||
binding.profileViewPager.adapter =
|
||||
ViewPagerAdapter(supportFragmentManager, lifecycle, user)
|
||||
navBar.visibility = View.VISIBLE
|
||||
navBar.selectTabAt(selected)
|
||||
navBar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
|
||||
|
@ -81,7 +78,7 @@ class ProfileActivity : AppCompatActivity(){
|
|||
binding.profileViewPager.setCurrentItem(selected, true)
|
||||
}
|
||||
})
|
||||
val userLevel = intent.getStringExtra("username")?: ""
|
||||
val userLevel = intent.getStringExtra("username") ?: ""
|
||||
|
||||
binding.profileProgressBar.visibility = View.GONE
|
||||
binding.profileTopContainer.visibility = View.VISIBLE
|
||||
|
@ -131,6 +128,7 @@ class ProfileActivity : AppCompatActivity(){
|
|||
}
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
private class ViewPagerAdapter(
|
||||
fragmentManager: FragmentManager,
|
||||
lifecycle: Lifecycle,
|
||||
|
|
38
app/src/main/java/ani/dantotsu/profile/SingleStatActivity.kt
Normal file
38
app/src/main/java/ani/dantotsu/profile/SingleStatActivity.kt
Normal file
|
@ -0,0 +1,38 @@
|
|||
package ani.dantotsu.profile
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import ani.dantotsu.databinding.ActivitySingleStatBinding
|
||||
import ani.dantotsu.initActivity
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
import ani.dantotsu.toast
|
||||
import com.github.aachartmodel.aainfographics.aachartcreator.AAOptions
|
||||
|
||||
class SingleStatActivity : AppCompatActivity()
|
||||
{
|
||||
private lateinit var binding: ActivitySingleStatBinding
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ThemeManager(this).applyTheme()
|
||||
initActivity(this)
|
||||
binding = ActivitySingleStatBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
val chartOptions = chartOptions
|
||||
if (chartOptions != null) {
|
||||
val typedvalue = TypedValue()
|
||||
theme.resolveAttribute(android.R.attr.windowBackground, typedvalue, true)
|
||||
chartOptions.chart?.backgroundColor = typedvalue.data
|
||||
binding.chartView.aa_drawChartWithChartOptions(chartOptions)
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
} else {
|
||||
toast("No chart data")
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
var chartOptions: AAOptions? = null // I cba to pass this through an intent
|
||||
}
|
||||
}
|
|
@ -144,7 +144,7 @@ class StatsFragment() :
|
|||
names,
|
||||
values
|
||||
)
|
||||
adapter.add(ChartItem("Format", formatChart))
|
||||
adapter.add(ChartItem("Format", formatChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ class StatsFragment() :
|
|||
names,
|
||||
values
|
||||
)
|
||||
adapter.add(ChartItem("Status", statusChart))
|
||||
adapter.add(ChartItem("Status", statusChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ class StatsFragment() :
|
|||
values,
|
||||
xAxisName = "Score",
|
||||
)
|
||||
adapter.add(ChartItem("Score", scoreChart))
|
||||
adapter.add(ChartItem("Score", scoreChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ class StatsFragment() :
|
|||
values,
|
||||
xAxisName = "Length",
|
||||
)
|
||||
adapter.add(ChartItem("Length", lengthChart))
|
||||
adapter.add(ChartItem("Length", lengthChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ class StatsFragment() :
|
|||
values,
|
||||
xAxisName = "Year",
|
||||
)
|
||||
adapter.add(ChartItem("Release Year", releaseYearChart))
|
||||
adapter.add(ChartItem("Release Year", releaseYearChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ class StatsFragment() :
|
|||
values,
|
||||
xAxisName = "Year",
|
||||
)
|
||||
adapter.add(ChartItem("Start Year", startYearChart))
|
||||
adapter.add(ChartItem("Start Year", startYearChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,13 +347,13 @@ class StatsFragment() :
|
|||
AAChartType.Areaspline,
|
||||
statType,
|
||||
type,
|
||||
names.take(15),
|
||||
values.take(15),
|
||||
names,
|
||||
values,
|
||||
xAxisName = "Genre",
|
||||
polar = true,
|
||||
categories = names
|
||||
)
|
||||
adapter.add(ChartItem("Genre", genreChart))
|
||||
adapter.add(ChartItem("Genre", genreChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ class StatsFragment() :
|
|||
scrollPos = 0.0f
|
||||
)
|
||||
tagChart.yAxis = AAYAxis().min(min).max(max).tickInterval(if (max > 100) 20 else 10)
|
||||
adapter.add(ChartItem("Tag", tagChart))
|
||||
adapter.add(ChartItem("Tag", tagChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ class StatsFragment() :
|
|||
categories = names,
|
||||
scrollPos = null
|
||||
)
|
||||
adapter.add(ChartItem("Country", countryChart))
|
||||
adapter.add(ChartItem("Country", countryChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -467,7 +467,7 @@ class StatsFragment() :
|
|||
categories = names,
|
||||
scrollPos = 0.0f
|
||||
)
|
||||
adapter.add(ChartItem("Voice Actor", voiceActorsChart))
|
||||
adapter.add(ChartItem("Voice Actor", voiceActorsChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,7 @@ class StatsFragment() :
|
|||
categories = names,
|
||||
scrollPos = 0.0f
|
||||
)
|
||||
adapter.add(ChartItem("Staff", staffChart))
|
||||
adapter.add(ChartItem("Staff", staffChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -541,7 +541,7 @@ class StatsFragment() :
|
|||
categories = names,
|
||||
scrollPos = null
|
||||
)
|
||||
adapter.add(ChartItem("Studio", studioChart))
|
||||
adapter.add(ChartItem("Studio", studioChart, activity))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
app/src/main/res/layout/activity_single_stat.xml
Normal file
14
app/src/main/res/layout/activity_single_stat.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.github.aachartmodel.aainfographics.aachartcreator.AAChartView
|
||||
android:id="@+id/chartView"
|
||||
android:layout_margin="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:colorBackground" />
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Add table
Add a link
Reference in a new issue