Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #429 from YTVanced/dev
Browse files Browse the repository at this point in the history
Vanced Manager v2.5.1
  • Loading branch information
KevinX8 authored Feb 24, 2021
2 parents dfdeb48 + 7c6e3e6 commit 6cb6745
Show file tree
Hide file tree
Showing 97 changed files with 696 additions and 685 deletions.
38 changes: 27 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ android {
applicationId = "com.vanced.manager"
minSdkVersion(21)
targetSdkVersion(30)
versionCode = 250
versionName = "2.5.0 (Weed)"
versionCode = 251
versionName = "2.5.1 (Weed)"

vectorDrawables.useSupportLibrary = true

buildConfigField("String[]", "MANAGER_LANGUAGES", "{" + getLanguages() + "}")
buildConfigField("String[]", "MANAGER_LANGUAGES", "{$languages}")
buildConfigField("Boolean", "ENABLE_CROWDIN_AUTH", "false")
buildConfigField("String", "CROWDIN_HASH", "\"${System.getenv("CROWDIN_HASH")}\"")
buildConfigField("String", "CROWDIN_CLIENT_ID", "\"${System.getenv("CROWDIN_CLIENT_ID")}\"")
Expand All @@ -45,6 +45,7 @@ android {

buildFeatures {
viewBinding = true
//compose = true
}

packagingOptions {
Expand All @@ -63,28 +64,31 @@ android {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
//useIR = true
}
}

}

fun getLanguages(): String {
val languages: String get() {
val langs = arrayListOf("en", "bn_BD", "bn_IN", "pa_IN", "pa_PK", "pt_BR", "pt_PT", "zh_CN", "zh_TW")
val exceptions = arrayOf("bn", "pa", "pt", "zh")

File("$projectDir/src/main/res").listFiles()?.forEach { dir ->
if (dir.name.startsWith("values-") && !dir.name.contains("v23")) {
val dirname = dir.name.substringAfter("-").substringBefore("-")
if (!exceptions.any { dirname == it }) {
langs.add(dirname)
}
File("$projectDir/src/main/res").listFiles()?.filter {
val name = it.name
name.startsWith("values-") && !name.contains("v23")
}?.forEach { dir ->
val dirname = dir.name.substringAfter("-").substringBefore("-")
if (!exceptions.contains(dirname)) {
langs.add(dirname)
}
}
return langs.joinToString(", ") { "\"$it\"" }
}

dependencies {

//val composeVersion = "1.0.0-alpha12"
implementation(project(":core-presentation"))
implementation(project(":core-ui"))

Expand All @@ -108,6 +112,17 @@ dependencies {
implementation("androidx.preference:preference-ktx:1.1.1")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")


// Compose
// implementation("androidx.compose.ui:ui:$composeVersion")
// implementation("androidx.compose.ui:ui-tooling:$composeVersion")
// implementation("androidx.compose.foundation:foundation:$composeVersion")
// implementation("androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha02")
// implementation("androidx.compose.material:material:$composeVersion")
// implementation("androidx.compose.material:material-icons-core:$composeVersion")
// implementation("androidx.compose.material:material-icons-extended:$composeVersion")
// implementation("androidx.compose.runtime:runtime-livedata:$composeVersion")

// Appearance
implementation("com.github.madrapps:pikolo:2.0.1")
implementation("com.google.android.material:material:1.3.0")
Expand All @@ -116,7 +131,7 @@ dependencies {
implementation("com.beust:klaxon:5.4")

// Crowdin
implementation("com.crowdin.platform:mobile-sdk:1.2.0")
implementation("com.github.crowdin.mobile-sdk-android:sdk:1.4.0")

// Tips
implementation("com.github.florent37:viewtooltip:1.2.2")
Expand All @@ -126,6 +141,7 @@ dependencies {
implementation("com.github.kittinunf.fuel:fuel-coroutines:2.2.3")
implementation("com.github.kittinunf.fuel:fuel-json:2.2.3")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
implementation("com.squareup.retrofit2:retrofit:2.9.0")

// Root permissions
implementation("com.github.topjohnwu.libsu:core:3.1.1")
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- is required for some Android 5.x devices -->
<uses-permission
Expand Down
30 changes: 14 additions & 16 deletions app/src/main/java/com/vanced/manager/adapter/AppListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LifecycleOwner
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import androidx.recyclerview.widget.RecyclerView
import com.github.florent37.viewtooltip.ViewTooltip
Expand All @@ -17,16 +16,15 @@ import com.vanced.manager.ui.viewmodels.HomeViewModel
import com.vanced.manager.utils.*

class AppListAdapter(
private val context: FragmentActivity,
private val activity: FragmentActivity,
private val viewModel: HomeViewModel,
private val lifecycleOwner: LifecycleOwner,
private val tooltip: ViewTooltip
private val tooltip: ViewTooltip?
) : RecyclerView.Adapter<AppListAdapter.ListViewHolder>() {

private val apps = mutableListOf<String>()
private val dataModels = mutableListOf<DataModel?>()
private val rootDataModels = mutableListOf<RootDataModel?>()
private val prefs = getDefaultSharedPreferences(context)
private val prefs = getDefaultSharedPreferences(activity)

private val isRoot = prefs.managerVariant == "root"

Expand All @@ -36,11 +34,11 @@ class AppListAdapter(
val dataModel = if (isRoot) rootDataModels[position] else dataModels[position]
with(binding) {
appName.text = dataModel?.appName
dataModel?.buttonTxt?.observe(lifecycleOwner) {
dataModel?.buttonTxt?.observe(activity) {
appInstallButton.text = it
}
appInstallButton.setOnClickListener {
if (vanced.value != null) {
if (dataModel?.versionName?.value != activity.getString(R.string.unavailable)) {
viewModel.openInstallDialog(it, apps[position])
} else {
return@setOnClickListener
Expand All @@ -52,35 +50,35 @@ class AppListAdapter(
appLaunch.setOnClickListener {
viewModel.launchApp(apps[position], isRoot)
}
dataModel?.isAppInstalled?.observe(lifecycleOwner) {
dataModel?.isAppInstalled?.observe(activity) {
appUninstall.isVisible = it
appLaunch.isVisible = it
}
dataModel?.versionName?.observe(lifecycleOwner) {
dataModel?.versionName?.observe(activity) {
appRemoteVersion.text = it
}
dataModel?.installedVersionName?.observe(lifecycleOwner) {
dataModel?.installedVersionName?.observe(activity) {
appInstalledVersion.text = it
}
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListViewHolder {
val view = ViewAppBinding.inflate(LayoutInflater.from(context), parent, false)
val view = ViewAppBinding.inflate(LayoutInflater.from(activity), parent, false)
return ListViewHolder(view)
}

override fun onBindViewHolder(holder: ListViewHolder, position: Int) {
holder.bind(position)
val dataModel = if (isRoot) rootDataModels[position] else dataModels[position]
holder.appCard.setOnClickListener {
tooltip.close()
tooltip?.close()
AppInfoDialog.newInstance(
appName = apps[position],
appIcon = dataModel?.appIcon,
changelog = dataModel?.changelog?.value
).show(context.supportFragmentManager, "info")
).show(activity.supportFragmentManager, "info")
}
}

Expand All @@ -94,7 +92,7 @@ class AppListAdapter(
} else {
dataModels.add(viewModel.vancedModel.value)
}
apps.add(context.getString(R.string.vanced))
apps.add(activity.getString(R.string.vanced))
}

if (prefs.enableMusic) {
Expand All @@ -103,12 +101,12 @@ class AppListAdapter(
} else {
dataModels.add(viewModel.musicModel.value)
}
apps.add(context.getString(R.string.music))
apps.add(activity.getString(R.string.music))
}

if (!isRoot) {
dataModels.add(viewModel.microgModel.value)
apps.add(context.getString(R.string.microg))
apps.add(activity.getString(R.string.microg))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import com.vanced.manager.model.SponsorModel
import com.vanced.manager.ui.viewmodels.HomeViewModel
import com.vanced.manager.utils.LIGHT
import com.vanced.manager.utils.currentTheme
import com.vanced.manager.utils.defPrefs
import com.vanced.manager.utils.managerTheme

class SponsorAdapter(
private val context: Context,
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/vanced/manager/adapter/WelcomePageAdapter.kt
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")
}
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/vanced/manager/model/DataModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class DataModel(
lifecycleOwner: LifecycleOwner,
val appPkg: String,
val appName: String,
val appIcon: Drawable?,
val appIcon: Drawable?
) {

private val versionCode = MutableLiveData<Int>()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/vanced/manager/model/LinkModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import android.graphics.drawable.Drawable

data class LinkModel(
val linkIcon: Drawable?,
val linkUrl: String,
val linkUrl: String
)
75 changes: 69 additions & 6 deletions app/src/main/java/com/vanced/manager/ui/WelcomeActivity.kt
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()
}
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/com/vanced/manager/ui/compose/Colors.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package com.vanced.manager.ui.compose

Loading

0 comments on commit 6cb6745

Please sign in to comment.