This repository has been archived by the owner on Mar 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from YTVanced/dev
Vanced Manager v2.5.1
- Loading branch information
Showing
97 changed files
with
696 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/vanced/manager/adapter/WelcomePageAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.vanced.manager.adapter | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
import com.vanced.manager.ui.fragments.GrantRootFragment | ||
import com.vanced.manager.ui.fragments.SelectAppsFragment | ||
import com.vanced.manager.ui.fragments.WelcomeFragment | ||
|
||
class WelcomePageAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) { | ||
|
||
override fun getItemCount(): Int = 3 | ||
|
||
override fun createFragment(position: Int): Fragment { | ||
return when (position) { | ||
0 -> WelcomeFragment() | ||
1 -> SelectAppsFragment() | ||
2 -> GrantRootFragment() | ||
else -> throw IllegalArgumentException("Unknown fragment") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 69 additions & 6 deletions
75
app/src/main/java/com/vanced/manager/ui/WelcomeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,84 @@ | ||
package com.vanced.manager.ui | ||
|
||
import android.animation.Animator | ||
import android.animation.ValueAnimator | ||
import android.os.Bundle | ||
import android.view.animation.AccelerateDecelerateInterpolator | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.navigation.findNavController | ||
import com.vanced.manager.R | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.vanced.manager.adapter.WelcomePageAdapter | ||
import com.vanced.manager.databinding.ActivityWelcomeBinding | ||
import kotlin.math.abs | ||
|
||
class WelcomeActivity : AppCompatActivity() { | ||
|
||
private val navHost by lazy { findNavController(R.id.welcome_navhost) } | ||
private lateinit var viewPager2: ViewPager2 | ||
private lateinit var binding: ActivityWelcomeBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_welcome) | ||
binding = ActivityWelcomeBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
viewPager2 = binding.welcomeViewpager | ||
viewPager2.apply { | ||
adapter = WelcomePageAdapter(this@WelcomeActivity) | ||
isUserInputEnabled = false | ||
setPageTransformer { page, position -> | ||
page.apply { | ||
val pageWidth = width | ||
//Thank you, fragula dev! | ||
when { | ||
position > 0 && position < 1 -> { | ||
alpha = 1f | ||
translationX = 0f | ||
} | ||
position > -1 && position <= 0 -> { | ||
alpha = 1.0f - abs(position * 0.7f) | ||
translationX = -pageWidth * position / 1.3F | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onBackPressed() { | ||
if (!navHost.popBackStack()) | ||
finish() | ||
if (viewPager2.currentItem == 0) { | ||
super.onBackPressed() | ||
} else { | ||
navigateTo(viewPager2.currentItem - 1) | ||
} | ||
} | ||
|
||
fun navigateTo(position: Int) { | ||
viewPager2.currentPosition = position | ||
} | ||
|
||
//Shit way to implement animation duration, but at least it works | ||
private var ViewPager2.currentPosition: Int | ||
get() = currentItem | ||
set(value) { | ||
val pixelsToDrag: Int = width * (value - currentItem) | ||
val animator = ValueAnimator.ofInt(0, pixelsToDrag) | ||
var previousValue = 0 | ||
animator.apply { | ||
addUpdateListener { valueAnimator -> | ||
val currentValue = valueAnimator.animatedValue as Int | ||
val currentPxToDrag = (currentValue - previousValue).toFloat() | ||
fakeDragBy(-currentPxToDrag) | ||
previousValue = currentValue | ||
} | ||
addListener(object : Animator.AnimatorListener { | ||
override fun onAnimationStart(animation: Animator?) { beginFakeDrag() } | ||
override fun onAnimationEnd(animation: Animator?) { endFakeDrag() } | ||
override fun onAnimationCancel(animation: Animator?) {} | ||
override fun onAnimationRepeat(animation: Animator?) {} | ||
}) | ||
interpolator = AccelerateDecelerateInterpolator() | ||
duration = 500 | ||
start() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package com.vanced.manager.ui.compose | ||
|
Oops, something went wrong.