Skip to content

Commit

Permalink
Merge pull request #92 from snehilrx/dev
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
snehilrx authored Feb 11, 2024
2 parents 9240379 + e1ab098 commit 42806d2
Show file tree
Hide file tree
Showing 57 changed files with 4,010 additions and 290 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
local.properties
/.idea
/version.properties
/app/google-services.json
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ dependencies {
implementation "androidx.work:work-runtime-ktx:$versions.work"
implementation project(path: ':kickassanime')
implementation 'com.google.firebase:firebase-perf:20.5.0'
implementation project(path: ':shinebar')
androidTestImplementation "io.github.rascaler:assertj:$versions.assertJ"
testImplementation "junit:junit:$versions.junit"
androidTestImplementation "androidx.test.ext:junit:$versions.androidx_junit"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.KickassAnime"
android:usesCleartextTraffic="true">
<profileable
android:shell="true"
tools:targetApi="q" />

<activity
android:name=".MainActivity"
android:exported="true">
Expand Down
25 changes: 24 additions & 1 deletion app/src/main/java/com/otaku/fetch/ModuleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.otaku.fetch
import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -25,16 +26,19 @@ import com.otaku.fetch.base.settings.Settings
import com.otaku.fetch.base.settings.dataStore
import com.otaku.fetch.base.ui.BindingActivity
import com.otaku.fetch.base.ui.SearchInterface
import com.otaku.fetch.base.ui.ShineBarInterface
import com.otaku.fetch.base.utils.UiUtils.statusBarHeight
import com.otaku.fetch.databinding.ActivityModuleBinding
import dagger.hilt.android.AndroidEntryPoint
import io.github.snehilrx.shinebar.Shinebar
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch


@AndroidEntryPoint
class ModuleActivity :
BindingActivity<ActivityModuleBinding>(R.layout.activity_module), SearchInterface {
BindingActivity<ActivityModuleBinding>(R.layout.activity_module), SearchInterface,
ShineBarInterface {

inner class SearchComponents(
val suggestionsList: RecyclerView,
Expand All @@ -44,12 +48,31 @@ class ModuleActivity :

private lateinit var searchUi: SearchComponents

override val shinebar: Shinebar
get() = binding.shinebar

private fun setupShineBar(shinebar: Shinebar) {
val start = TypedValue()
val end = TypedValue()
theme?.resolveAttribute(
com.google.android.material.R.attr.colorPrimary,
start,
true
)
theme?.resolveAttribute(com.google.android.material.R.attr.colorAccent, end, true)
shinebar.apply {
setStartColor(start.data)
setEndColor(end.data)
}
}

override fun onBind(binding: ActivityModuleBinding, savedInstanceState: Bundle?) {
super.onBind(binding, savedInstanceState)
initNavigationView()
setTransparentStatusBar()
initSearchView(binding)
checkPermissions()
setupShineBar(shinebar)
}

private fun checkPermissions() {
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/layout-land/activity_module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<io.github.snehilrx.shinebar.Shinebar
android:id="@+id/shinebar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
Expand All @@ -22,12 +28,11 @@
<com.google.android.material.navigationrail.NavigationRailView
android:id="@+id/railNavigation"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
app:menuAlignmentMode="auto"
android:orientation="vertical"
android:paddingStart="@dimen/cardview_margin"
android:paddingEnd="@dimen/cardview_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<io.github.snehilrx.shinebar.Shinebar
android:id="@+id/shinebar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:fitsSystemWindows="false"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<domain-config>
<domain includeSubdomains="true">kaaplayer.com</domain>
<domain includeSubdomains="true">kaas.am</domain>
<domain includeSubdomains="true">kickassanime.mx</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CloudflareInterceptor(
*/
private val headers = Headers.headersOf(
"User-Agent",
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0",
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1",
"Upgrade-Insecure-Requests",
"1",
"Accept-Language",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ object ApplicationModule {
.header("origin", origin)
.header(
"user-agent",
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1"
)
.method(original.method, original.body)
.build()

chain.proceed(request)
}).callTimeout(4, TimeUnit.MINUTES)
.connectTimeout(4, TimeUnit.MINUTES)
.addInterceptor(logger).build()
.addInterceptor(logger)
.build()

private const val MAX_CACHE_SIZE: Long = 2000000000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ import kotlin.math.min
@androidx.annotation.OptIn(UnstableApi::class)
fun DownloadScreen(
downloadsVM: DownloadViewModel,
statusBarHeight: Float? = null,
setupShineBar: (Shinebar) -> Unit = { _ -> run {} }
statusBarHeight: Float? = null
) {

val items = downloadsVM.anime()
Expand All @@ -65,7 +64,6 @@ fun DownloadScreen(
downloadsVM.resume(context)
}, isPaused = downloadsVM.isDownloadPaused)
},
setupShineBar = setupShineBar
) {
DownloadList(items.toItemTreeIndex(downloadsVM))
}
Expand Down
4 changes: 1 addition & 3 deletions base/src/main/java/com/otaku/fetch/base/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.otaku.fetch.base.ui.composepref.PrefsScreen
import com.otaku.fetch.base.ui.composepref.prefs.ListPref
import com.otaku.fetch.base.ui.composepref.prefs.SwitchPref
import dagger.hilt.android.internal.managers.ViewComponentManager.FragmentContextWrapper
import io.github.snehilrx.shinebar.Shinebar
import java.util.Locale


Expand Down Expand Up @@ -79,11 +78,10 @@ object Settings {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Settings(
statusBarHeight: Float? = null, setupShineBar: (Shinebar) -> Unit = { _ -> run {} }
statusBarHeight: Float? = null
) {
FetchScaffold(title = stringResource(id = R.string.settings),
statusBarHeight = statusBarHeight ?: 0f,
setupShineBar = setupShineBar,
content = {
val context = LocalContext.current
val dataStore = context.dataStore
Expand Down
63 changes: 28 additions & 35 deletions base/src/main/java/com/otaku/fetch/base/ui/BindingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package com.otaku.fetch.base.ui

import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -23,7 +22,6 @@ import com.otaku.fetch.base.databinding.AppbarImageBinding
import com.otaku.fetch.base.databinding.AppbarShineBinding
import com.otaku.fetch.base.utils.UiUtils.statusBarHeight
import com.otaku.fetch.bindings.ImageViewBindings
import io.github.snehilrx.shinebar.Shinebar
import java.lang.ref.WeakReference


Expand All @@ -49,52 +47,24 @@ open class BindingFragment<T : ViewDataBinding>(@LayoutRes private val layoutRes
protected fun AppBarLayout.getAppBarBehavior() =
(layoutParams as? CoordinatorLayout.LayoutParams)?.behavior as? AppBarLayout.Behavior

private lateinit var appBarLayout: AppBarLayout

protected fun initAppbar(
binding: AppbarShineBinding?,
navController: NavController,
hideBackButton: Boolean = false
) {
if (binding == null) return
appBarLayout = binding.appbarLayout
appBarLayout.addOnOffsetChangedListener((activity as? ShineBarInterface)?.shinebar)
initAppbar(
binding.shinebar,
binding.toolbar,
binding.collapsingToolbar,
navController,
hideBackButton
)
}

protected fun initAppbar(
shinebar: Shinebar?,
toolbar: Toolbar?,
collapsingToolbar: CollapsingToolbarLayout?,
navController: NavController?,
hideBackButton: Boolean = false
) {
setupShineBar(shinebar)
initAppbar(
toolbar,
collapsingToolbar,
navController,
hideBackButton
)
}

fun setupShineBar(shinebar: Shinebar?) {
val start = TypedValue()
val end = TypedValue()
context?.theme?.resolveAttribute(
com.google.android.material.R.attr.colorPrimary,
start,
true
)
context?.theme?.resolveAttribute(com.google.android.material.R.attr.colorAccent, end, true)
shinebar?.apply {
setStartColor(start.data)
setEndColor(end.data)
}
}

private fun initAppbar(
imageView: ImageView?,
toolbar: Toolbar?,
Expand Down Expand Up @@ -186,9 +156,32 @@ open class BindingFragment<T : ViewDataBinding>(@LayoutRes private val layoutRes
// no-op̊
}

override fun onResume() {
super.onResume()
if (this::appBarLayout.isInitialized) {
(activity as? ShineBarInterface)?.shinebar?.let {
appBarLayout.addOnOffsetChangedListener(it)
}
}
}

override fun onPause() {
super.onPause()
if (this::appBarLayout.isInitialized) {
(activity as? ShineBarInterface)?.shinebar?.let {
appBarLayout.removeOnOffsetChangedListener(it)
}
}
}

override fun onDestroy() {
super.onDestroy()
(activity as AppCompatActivity).setSupportActionBar(null)
(activity as? AppCompatActivity)?.setSupportActionBar(null)
if (this::appBarLayout.isInitialized) {
(activity as? ShineBarInterface)?.shinebar?.let {
appBarLayout.removeOnOffsetChangedListener(it)
}
}
if (this::weakReference.isInitialized) {
weakReference.clear()
}
Expand Down
4 changes: 2 additions & 2 deletions base/src/main/java/com/otaku/fetch/base/ui/ComposeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class ComposeFragment : BindingFragment<ComposeBinding>(R.layout.compose) {
DownloadScreen(
downloadsVM,
statusBarHeight
) { shinebar -> setupShineBar(shinebar) }
)
}
composable(BaseRoutes.SETTINGS) {
Settings(
statusBarHeight,
) { shinebar -> setupShineBar(shinebar) }
)
}
}
}
Expand Down
35 changes: 22 additions & 13 deletions base/src/main/java/com/otaku/fetch/base/ui/FetchScaffold.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.otaku.fetch.base.ui

import android.content.Context
import android.content.ContextWrapper
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.RowScope
Expand All @@ -15,9 +18,11 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
Expand All @@ -30,25 +35,14 @@ fun FetchScaffold(
title: String,
statusBarHeight: Float = 0f,
scrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(),
setupShineBar: (Shinebar) -> Unit = { _ -> run {} },
actions: @Composable (RowScope.() -> Unit) = {},
content: @Composable () -> Unit,
) {
val top = statusBarHeight.dp
val windowInsets = WindowInsets(0.dp, top / LocalDensity.current.density, 0.dp, 0.dp)
UpdateShineBar(-scrollBehavior.state.heightOffsetLimit, scrollBehavior.state.heightOffset.toInt())
Box(Modifier.fillMaxSize()) {
AndroidView(factory = { context ->
Shinebar(context).apply {
setupShineBar(this)
}
},
update = { shinebar ->
shinebar.redrawCurve(
-scrollBehavior.state.heightOffsetLimit,
scrollBehavior.state.heightOffset.toInt()
)
}
)

Scaffold(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -78,4 +72,19 @@ fun FetchScaffold(
}
}
}
}

@Composable
private fun UpdateShineBar(totalScrollRange: Float, heightOffset: Int) {
val shineBarInterface = LocalContext.current.getActivity() as? ShineBarInterface
shineBarInterface?.shinebar?.redrawCurve(
totalScrollRange,
heightOffset
)
}

fun Context.getActivity(): AppCompatActivity? = when (this) {
is AppCompatActivity -> this
is ContextWrapper -> baseContext.getActivity()
else -> null
}
Loading

0 comments on commit 42806d2

Please sign in to comment.