diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index f1cd7a7415..a643436a44 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -18,17 +18,22 @@ jobs: with: java-version: 1.8 + - name: Write firebase config to file + run: echo $FIREBASE_CONFIG > app/google-services.json + env: + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + - name: Grant rights run: chmod +x ./gradlew - name: Build project with Gradle run: ./gradlew build - - name: Build Release APK with Gradle + - name: Build Debug APK with Gradle run: ./gradlew assembleDebug - - name: Upload to GitHub + - name: Upload Debug uses: actions/upload-artifact@v2 with: - name: 'Vanced-Manager' + name: 'Manager' path: app/build/outputs/apk/debug/app-debug.apk \ No newline at end of file diff --git a/.gitignore b/.gitignore index cb4b2b4d94..ec679baaec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ out/ app/src/main/java/com/vanced/manager/core/base/DummyJava.java +app/google-services.json local.properties /.github/ *.iml diff --git a/README.md b/README.md index 31780008ae..3cc0a26428 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,5 @@ After 3 months of development, we are finally ready to introduce Vanced Manager - topjohnwu for his wonderful [LibSU](https://github.com/topjohnwu/libsu) - Mindorks for their amazing [PRDownloader](https://github.com/MindorksOpenSource/PRDownloader) - aefyr for [SAI](https://github.com/aefyr/SAI), which was an inspiration for our Manager -- 100rabhkr for their [GetJson](https://github.com/100rabhkr/getjson) library +- kittinunf for the [Fuel](https://github.com/kittinunf/Fuel) library +- cbeust for the [klaxon](https://github.com/cbeust/klaxon) library diff --git a/app/build.gradle b/app/build.gradle index 0e520aa457..5ad0872499 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,17 +2,20 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' +apply plugin: 'com.google.gms.google-services' +apply plugin: 'com.google.firebase.firebase-perf' +apply plugin: 'com.google.firebase.crashlytics' android { - compileSdkVersion 29 - buildToolsVersion "29.0.3" + compileSdkVersion 30 + buildToolsVersion "30.0.1" defaultConfig { applicationId "com.vanced.manager" minSdkVersion 21 - targetSdkVersion 29 - versionCode 11 - versionName "1.1.0 (Big Sur)" + targetSdkVersion 30 + versionCode 12 + versionName "1.2.0 (Niko)" vectorDrawables.useSupportLibrary = true } @@ -54,25 +57,38 @@ android { } dependencies { + // Kotlin implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" // AndroidX - implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.activity:activity:1.1.0' + implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.browser:browser:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'androidx.core:core-ktx:1.3.0' + implementation 'androidx.core:core-ktx:1.3.1' implementation 'androidx.fragment:fragment-ktx:1.2.5' implementation 'androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2' - implementation 'androidx.navigation:navigation-ui-ktx:2.2.2' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' implementation 'androidx.preference:preference-ktx:1.1.1' - implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' + implementation 'com.google.android.material:material:1.3.0-alpha02' // Other - implementation 'com.github.100rabhkr:GetJSON:1.0' - implementation 'com.github.topjohnwu.libsu:core:2.5.1' + implementation 'com.beust:klaxon:5.3' + implementation 'com.crowdin.platform:mobile-sdk:1.1.6' + implementation 'com.github.kittinunf.fuel:fuel:2.2.3' + implementation 'com.github.kittinunf.fuel:fuel-coroutines:2.2.3' + implementation 'com.github.kittinunf.fuel:fuel-json:2.2.3' + implementation 'com.github.topjohnwu.libsu:core:3.0.1' + implementation 'com.google.firebase:firebase-messaging:20.2.4' + implementation 'com.google.firebase:firebase-perf:19.0.8' implementation 'com.mindorks.android:prdownloader:0.6.0' + implementation 'com.google.firebase:firebase-analytics-ktx:17.4.4' + implementation 'com.google.firebase:firebase-crashlytics:17.1.1' + } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 55350fe611..52f5c22bbe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,8 +7,7 @@ - - + + tools:ignore="UnusedAttribute"> + android:label="@string/app_name" + android:theme="@style/DarkTheme.Blue"/> + + + + + + + + + + diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png deleted file mode 100644 index c78215cd29..0000000000 Binary files a/app/src/main/ic_launcher-playstore.png and /dev/null differ diff --git a/app/src/main/java/com/vanced/manager/adapter/SectionPageAdapter.kt b/app/src/main/java/com/vanced/manager/adapter/SectionPageAdapter.kt index 134c86cb42..3d8d47246b 100644 --- a/app/src/main/java/com/vanced/manager/adapter/SectionPageAdapter.kt +++ b/app/src/main/java/com/vanced/manager/adapter/SectionPageAdapter.kt @@ -8,19 +8,15 @@ import com.vanced.manager.ui.fragments.VancedChangelogFragment class SectionPageAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { - private val fragmentItems = 3 - override fun getItemCount(): Int { - return fragmentItems - } + override fun getItemCount(): Int = 3 override fun createFragment(position: Int): Fragment { - var fragment: Fragment? = null - when (position) { - 0 -> fragment = VancedChangelogFragment() - 1 -> fragment = MicrogChangelogFragment() - 2 -> fragment = ManagerChangelogFragment() + return when (position) { + 0 -> VancedChangelogFragment() + 1 -> MicrogChangelogFragment() + 2 -> ManagerChangelogFragment() + else -> throw NotImplementedError() } - return fragment!! } } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/adapter/SectionPageRootAdapter.kt b/app/src/main/java/com/vanced/manager/adapter/SectionPageRootAdapter.kt index ec7b1e4e49..d3fd89df21 100644 --- a/app/src/main/java/com/vanced/manager/adapter/SectionPageRootAdapter.kt +++ b/app/src/main/java/com/vanced/manager/adapter/SectionPageRootAdapter.kt @@ -7,18 +7,14 @@ import com.vanced.manager.ui.fragments.VancedChangelogFragment class SectionPageRootAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { - private val fragmentItems = 2 - override fun getItemCount(): Int { - return fragmentItems - } + override fun getItemCount(): Int = 2 override fun createFragment(position: Int): Fragment { - var fragment: Fragment? = null - when (position) { - 0 -> fragment = VancedChangelogFragment() - 1 -> fragment = ManagerChangelogFragment() + return when (position) { + 0 -> VancedChangelogFragment() + 1 -> ManagerChangelogFragment() + else -> throw NotImplementedError() } - return fragment!! } } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/core/App.kt b/app/src/main/java/com/vanced/manager/core/App.kt index 11a5a88a51..d69f5c1448 100644 --- a/app/src/main/java/com/vanced/manager/core/App.kt +++ b/app/src/main/java/com/vanced/manager/core/App.kt @@ -1,15 +1,29 @@ package com.vanced.manager.core import android.app.Application +import com.crowdin.platform.Crowdin +import com.crowdin.platform.CrowdinConfig +import com.crowdin.platform.data.remote.NetworkType import com.downloader.PRDownloader -import com.vanced.manager.utils.NotificationHelper.createNotifChannel class App: Application() { override fun onCreate() { super.onCreate() PRDownloader.initialize(this) - createNotifChannel(this) + + Crowdin.init(this, + CrowdinConfig.Builder() + .withDistributionHash("36c51aed3180a4f43073d28j4s6") + .withNetworkType(NetworkType.WIFI) + .build()) + } + + /* + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + Crowdin.onConfigurationChanged() } + */ } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/core/Main.kt b/app/src/main/java/com/vanced/manager/core/Main.kt deleted file mode 100644 index ebb7a73116..0000000000 --- a/app/src/main/java/com/vanced/manager/core/Main.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.vanced.manager.core - -import android.annotation.SuppressLint -import android.content.Context -import android.os.Bundle -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import androidx.preference.PreferenceManager -import com.dezlum.codelabs.getjson.GetJson -import com.vanced.manager.R -import com.vanced.manager.ui.dialogs.DialogContainer.basicDialog -import com.vanced.manager.ui.dialogs.DialogContainer.showRootDialog -import com.vanced.manager.ui.dialogs.DialogContainer.showSecurityDialog -import com.vanced.manager.ui.dialogs.DialogContainer.statementFalse -import com.vanced.manager.ui.fragments.UpdateCheckFragment -import com.vanced.manager.utils.InternetTools.isUpdateAvailable -import com.vanced.manager.utils.PackageHelper.getPackageVersionName - -// This activity will NOT be used in manifest -// since MainActivity will extend it -@SuppressLint("Registered") -open class Main: AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - val prefs = PreferenceManager.getDefaultSharedPreferences(this) - val variant = prefs.getString("vanced_variant", "nonroot") - val showRootDialog = prefs.getBoolean("show_root_dialog", true) - - when { - prefs.getBoolean("firstStart", true) -> showSecurityDialog(this) - !prefs.getBoolean("statement", true) -> statementFalse(this) - variant == "root" -> { - if (showRootDialog) - showRootDialog(this) - - if (getPackageVersionName("com.google.android.youtube", packageManager) == "14.21.54") - basicDialog(getString(R.string.hold_on), getString(R.string.magisk_vanced), this) - } - } - - checkUpdates() - - } - - override fun onPause() { - getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply() - getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isVancedDownloading", false).apply() - getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isMicrogDownloading", false).apply() - super.onPause() - } - - private fun checkUpdates() { - if (GetJson().isConnected(this) && isUpdateAvailable()) { - val fm = supportFragmentManager - UpdateCheckFragment().show(fm, "UpdateCheck") - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt index a315e9bdac..a2e29a9e0e 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt @@ -1,72 +1,87 @@ package com.vanced.manager.core.downloader import android.app.Service -import android.content.Context import android.content.Intent import android.os.IBinder +import android.widget.Toast import androidx.localbroadcastmanager.content.LocalBroadcastManager +import androidx.preference.PreferenceManager import com.downloader.Error import com.downloader.OnDownloadListener -import com.downloader.OnStartOrResumeListener import com.downloader.PRDownloader import com.vanced.manager.R import com.vanced.manager.core.installer.AppInstaller import com.vanced.manager.ui.fragments.HomeFragment +import com.vanced.manager.utils.AppUtils.installing +import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl import com.vanced.manager.utils.InternetTools.getObjectFromJson -import com.vanced.manager.utils.NotificationHelper -import com.vanced.manager.utils.NotificationHelper.cancelNotif -import com.vanced.manager.utils.NotificationHelper.createBasicNotif +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch class MicrogDownloadService: Service() { + //private var downloadId: Long = 0 + private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) } + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + //registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) downloadMicrog() stopSelf() return START_NOT_STICKY } private fun downloadMicrog() { - val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) + CoroutineScope(Dispatchers.IO).launch { + val url = getObjectFromJson( + "${PreferenceManager.getDefaultSharedPreferences(this@MicrogDownloadService) + .getString("install_url", baseUrl)}/microg.json", "url" + ) - val apkUrl = getObjectFromJson("https://vanced.app/api/v1/microg.json", "url", this) + //downloadId = download(url, "apk", "microg.apk", this@MicrogDownloadService) - val channel = 420 - PRDownloader.download(apkUrl, filesDir.path, "microg.apk") - .build() - .setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } } - .setOnProgressListener { progress -> - val mProgress = progress.currentBytes * 100 / progress.totalBytes - NotificationHelper.displayDownloadNotif( - channel, - mProgress.toInt(), - getFileNameFromUrl(apkUrl), - this - ) - } - .start(object : OnDownloadListener { - override fun onDownloadComplete() { - prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply() - cancelNotif(channel, this@MicrogDownloadService) - val intent = Intent(this@MicrogDownloadService, AppInstaller::class.java) - intent.putExtra("path", "${filesDir.path}/microg.apk") - intent.putExtra("pkg", "com.mgoogle.android.gms") - val mIntent = Intent(HomeFragment.MICROG_DOWNLOADED) - mIntent.action = HomeFragment.MICROG_DOWNLOADED - LocalBroadcastManager.getInstance(this@MicrogDownloadService).sendBroadcast(mIntent) - startService(intent) + PRDownloader.download(url, getExternalFilesDir("apk")?.path, "microg.apk") + .build() + .setOnStartOrResumeListener { installing = true } + .setOnProgressListener { progress -> + val mProgress = progress.currentBytes * 100 / progress.totalBytes + localBroadcastManager.sendBroadcast(Intent(HomeFragment.MICROG_DOWNLOADING).putExtra("progress", mProgress.toInt()).putExtra("file", getFileNameFromUrl(url))) } - override fun onError(error: Error) { - prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply() - createBasicNotif(getString(R.string.error_downloading, "Microg"), channel, this@MicrogDownloadService) - } - }) + .start(object : OnDownloadListener { + override fun onDownloadComplete() { + val intent = Intent(this@MicrogDownloadService, AppInstaller::class.java) + intent.putExtra("path", "${getExternalFilesDir("apk")}/microg.apk") + intent.putExtra("pkg", "com.mgoogle.android.gms") + localBroadcastManager.sendBroadcast(Intent(HomeFragment.MICROG_INSTALLING)) + startService(intent) + } + + override fun onError(error: Error?) { + installing = false + Toast.makeText(this@MicrogDownloadService, getString(R.string.error_downloading, "microG"), Toast.LENGTH_SHORT).show() + } + }) + + } + } - override fun onDestroy() { - super.onDestroy() - cancelNotif(420, this) + /* + private val receiver = object : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) { + //prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply() + //cancelNotif(channel, this@MicrogDownloadService) + val bIntent = Intent(this@MicrogDownloadService, AppInstaller::class.java) + bIntent.putExtra("path", "${getExternalFilesDir("apk")}/microg.apk") + bIntent.putExtra("pkg", "com.mgoogle.android.gms") + startService(bIntent) + } + } } + */ + override fun onBind(intent: Intent?): IBinder? { return null diff --git a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt index 34f6ae8769..537e29da71 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt @@ -5,27 +5,34 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.IBinder +import android.widget.Toast import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.preference.PreferenceManager import com.downloader.Error import com.downloader.OnDownloadListener -import com.downloader.OnStartOrResumeListener import com.downloader.PRDownloader import com.vanced.manager.R import com.vanced.manager.core.installer.RootSplitInstallerService import com.vanced.manager.core.installer.SplitInstaller import com.vanced.manager.ui.fragments.HomeFragment +import com.vanced.manager.utils.AppUtils.installing import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl import com.vanced.manager.utils.InternetTools.getObjectFromJson -import com.vanced.manager.utils.NotificationHelper.cancelNotif -import com.vanced.manager.utils.NotificationHelper.createBasicNotif -import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import java.io.File class VancedDownloadService: Service() { - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + //private var downloadId: Long = 0 + //private var apkType: String = "arch" + private var count: Int = 0 + private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) } + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + //registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) downloadSplits() stopSelf() return START_NOT_STICKY @@ -34,36 +41,40 @@ class VancedDownloadService: Service() { private fun downloadSplits( type: String = "arch" ) { - val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl) - val vancedVer = getObjectFromJson("https://vanced.app/api/v1/vanced.json", "version", this) + CoroutineScope(Dispatchers.IO).launch { + File(getExternalFilesDir("apk")?.path as String).deleteRecursively() + val defPrefs = PreferenceManager.getDefaultSharedPreferences(this@VancedDownloadService) + val installUrl = defPrefs.getString("install_url", baseUrl) + val vancedVer = getObjectFromJson("$installUrl/vanced.json", "version") - val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) - val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot") - val lang = prefs?.getString("lang", "en") - val theme = prefs?.getString("theme", "dark") - val arch = - when { - Build.SUPPORTED_ABIS.contains("x86") -> "x86" - Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a" - else -> "armeabi_v7a" - } - val url = - when (type) { - "arch" -> "$baseUrl/apks/v$vancedVer/$variant/Arch/split_config.$arch.apk" - "theme" -> "$baseUrl/apks/v$vancedVer/$variant/Theme/$theme.apk" - "lang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.$lang.apk" - "enlang" -> "$baseUrl/apks/v$vancedVer/$variant/Language/split_config.en.apk" - else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?") - } + val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) + val variant = defPrefs.getString("vanced_variant", "nonroot") + val lang = prefs?.getString("lang", "en")?.split(", ")?.toTypedArray() + val theme = prefs?.getString("theme", "dark") + val arch = + when { + Build.SUPPORTED_ABIS.contains("x86") -> "x86" + Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a" + else -> "armeabi_v7a" + } + val url = + when (type) { + "arch" -> "$installUrl/apks/v$vancedVer/$variant/Arch/split_config.$arch.apk" + "theme" -> "$installUrl/apks/v$vancedVer/$variant/Theme/$theme.apk" + "lang" -> "$installUrl/apks/v$vancedVer/$variant/Language/split_config.${lang?.get(count)}.apk" + else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?") + } + + //apkType = type + //downloadId = download(url, "apks", getFileNameFromUrl(url), this@VancedDownloadService) - val channel = 69 PRDownloader - .download(url, cacheDir.path, getFileNameFromUrl(url)) + .download(url, getExternalFilesDir("apks")?.path, getFileNameFromUrl(url)) .build() - .setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } } + .setOnStartOrResumeListener{ installing = true } .setOnProgressListener { progress -> val mProgress = progress.currentBytes * 100 / progress.totalBytes - displayDownloadNotif(channel, mProgress.toInt(), getFileNameFromUrl(url), this) + localBroadcastManager.sendBroadcast(Intent(HomeFragment.VANCED_DOWNLOADING).putExtra("progress", mProgress.toInt()).putExtra("file", getFileNameFromUrl(url))) } .start(object : OnDownloadListener { override fun onDownloadComplete() { @@ -71,41 +82,59 @@ class VancedDownloadService: Service() { "arch" -> downloadSplits("theme") "theme" -> downloadSplits("lang") "lang" -> { - if (lang == "en") { + count++ + if (count < lang?.count()!!) + downloadSplits("lang") + else prepareInstall(variant!!) - cancelNotif(channel, this@VancedDownloadService) - } else { - downloadSplits("enlang") - } - } - "enlang" -> { - prepareInstall(variant!!) - cancelNotif(channel, this@VancedDownloadService) } } } - override fun onError(error: Error) { - createBasicNotif(getString(R.string.error_downloading, "Vanced"), channel, this@VancedDownloadService) + override fun onError(error: Error?) { + installing = false + Toast.makeText(this@VancedDownloadService, getString(R.string.error_downloading, "Vanced"), Toast.LENGTH_SHORT).show() } }) + } } + /* + private val receiver = object : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + val prefs = context?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE) + val variant = PreferenceManager.getDefaultSharedPreferences(this@VancedDownloadService).getString("vanced_variant", "nonroot") + val lang = prefs?.getString("lang", "en") + if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) { + when (apkType) { + "arch" -> downloadSplits("theme") + "theme" -> downloadSplits("lang") + "lang" -> { + if (lang == "en") { + prepareInstall(variant!!) + //cancelNotif(channel, this@VancedDownloadService) + } else { + downloadSplits("enlang") + } + } + "enlang" -> { + prepareInstall(variant!!) + //cancelNotif(channel, this@VancedDownloadService) + } + } + } + } + } + */ + private fun prepareInstall(variant: String) { - val intent = Intent(HomeFragment.VANCED_DOWNLOADED) - intent.action = HomeFragment.VANCED_DOWNLOADED - LocalBroadcastManager.getInstance(this).sendBroadcast(intent) + localBroadcastManager.sendBroadcast(Intent(HomeFragment.VANCED_INSTALLING)) if (variant == "root") startService(Intent(this, RootSplitInstallerService::class.java)) else startService(Intent(this, SplitInstaller::class.java)) } - override fun onDestroy() { - super.onDestroy() - cancelNotif(69, this) - } - override fun onBind(intent: Intent?): IBinder? { return null } diff --git a/app/src/main/java/com/vanced/manager/core/firebase/CloudMessaging.kt b/app/src/main/java/com/vanced/manager/core/firebase/CloudMessaging.kt new file mode 100644 index 0000000000..9b52333d71 --- /dev/null +++ b/app/src/main/java/com/vanced/manager/core/firebase/CloudMessaging.kt @@ -0,0 +1,13 @@ +package com.vanced.manager.core.firebase + +import android.util.Log +import com.google.firebase.messaging.FirebaseMessagingService + +class CloudMessaging: FirebaseMessagingService() { + + override fun onNewToken(p0: String) { + super.onNewToken(p0) + Log.d("VMC", "Generated new token: $p0") + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/core/fragments/About.kt b/app/src/main/java/com/vanced/manager/core/fragments/About.kt deleted file mode 100644 index 9d470173dd..0000000000 --- a/app/src/main/java/com/vanced/manager/core/fragments/About.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.vanced.manager.core.fragments - -import android.annotation.SuppressLint -import android.os.Bundle -import android.view.MotionEvent -import android.view.View -import android.widget.Toast -import androidx.preference.PreferenceManager -import com.vanced.manager.core.base.BaseFragment - -open class About : BaseFragment() { - - private var count = 0 - private var startMillSec: Long = 0 - - @SuppressLint("ClickableViewAccessibility") - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - view.setOnTouchListener { _, event: MotionEvent -> - - val eventAction = event.action - if (eventAction == MotionEvent.ACTION_UP) { - val time = System.currentTimeMillis() - if (startMillSec == 0L || time - startMillSec > 3000) { - startMillSec = time - count = 1 - } else { - count++ - } - - if (count == 5) { - val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()) - val devSettings = prefs.getBoolean("devSettings", false) - if (!devSettings) { - Toast.makeText(requireContext(), "Dev options unlocked!", Toast.LENGTH_SHORT).show() - prefs.edit().putBoolean("devSettings", true).apply() - } else - Toast.makeText(requireContext(), "Dev options already unlocked", Toast.LENGTH_SHORT).show() - - } - return@setOnTouchListener true - } - false - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/core/fragments/Home.kt b/app/src/main/java/com/vanced/manager/core/fragments/Home.kt deleted file mode 100644 index 5bbe2abfb4..0000000000 --- a/app/src/main/java/com/vanced/manager/core/fragments/Home.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.vanced.manager.core.fragments - -import android.content.Context -import android.content.Intent -import android.os.Bundle -import android.util.Log -import android.view.View -import android.widget.ImageView -import android.widget.Toast -import androidx.navigation.findNavController -import androidx.preference.PreferenceManager.getDefaultSharedPreferences -import com.google.android.material.button.MaterialButton -import com.topjohnwu.superuser.Shell -import com.vanced.manager.R -import com.vanced.manager.core.base.BaseFragment -import com.vanced.manager.core.downloader.MicrogDownloadService -import com.vanced.manager.core.downloader.VancedDownloadService -import com.vanced.manager.ui.MainActivity -import com.vanced.manager.utils.PackageHelper.uninstallApk - -open class Home : BaseFragment(), View.OnClickListener { - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val microginstallbtn = view.findViewById(R.id.microg_installbtn) - val vancedinstallbtn = view.findViewById(R.id.vanced_installbtn) - val microguninstallbtn = view.findViewById(R.id.microg_uninstallbtn) - val vanceduninstallbtn = view.findViewById(R.id.vanced_uninstallbtn) - val rootswitch = view.findViewById(R.id.root_switch) - val nonrootswitch = view.findViewById(R.id.nonroot_switch) - - vancedinstallbtn.setOnClickListener(this) - microginstallbtn.setOnClickListener(this) - microguninstallbtn.setOnClickListener(this) - vanceduninstallbtn.setOnClickListener(this) - rootswitch.setOnClickListener(this) - nonrootswitch.setOnClickListener(this) - - } - - override fun onResume() { - super.onResume() - val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE) - val isInstalling = prefs?.getBoolean("isInstalling", false) - if (isInstalling!!) { - activity?.startService(Intent(activity, VancedDownloadService::class.java)) - prefs.edit().putBoolean("isInstalling", false).apply() - } - } - - override fun onClick(v: View?) { - val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE) - val isVancedDownloading: Boolean? = prefs?.getBoolean("isVancedDownloading", false) - val isMicrogDownloading: Boolean? = prefs?.getBoolean("isMicrogDownloading", false) - val variant = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot") - val vancedPkgName = - if (variant == "root") { - "com.google.android.youtube" - } else { - "com.vanced.android.youtube" - } - - when (v?.id) { - R.id.vanced_installbtn -> { - if (!isVancedDownloading!!) { - try { - activity?.cacheDir?.deleteRecursively() - } catch (e: Exception) { - Log.d("VMCache", "Unable to delete cacheDir") - } - if (prefs.getBoolean("valuesModified", false)) { - activity?.startService( - Intent( - activity, - VancedDownloadService::class.java - ) - ) - } else { - view?.findNavController()?.navigate(R.id.toInstallThemeFragment) - } - } else { - Toast.makeText(activity, activity?.getString(R.string.installation_wait), Toast.LENGTH_SHORT).show() - } - } - R.id.microg_installbtn -> { - if (!isMicrogDownloading!!) { - activity?.startService(Intent(activity, MicrogDownloadService::class.java)) - } else { - Toast.makeText(activity, activity?.getString(R.string.installation_wait), Toast.LENGTH_SHORT).show() - } - } - R.id.microg_uninstallbtn -> activity?.let { uninstallApk("com.mgoogle.android.gms", it) } - R.id.vanced_uninstallbtn -> activity?.let { uninstallApk(vancedPkgName, it) } - R.id.nonroot_switch -> writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right) - R.id.root_switch -> - if (Shell.rootAccess()) { - writeToVariantPref("root", R.anim.slide_in_right, R.anim.slide_out_left) - } else { - writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right) - Toast.makeText(activity, activity?.getString(R.string.root_not_granted), Toast.LENGTH_SHORT).show() - } - } - } - - private fun writeToVariantPref(variant: String, animIn: Int, animOut: Int) { - val prefs = getDefaultSharedPreferences(activity) - if (prefs.getString("vanced_variant", "nonroot") != variant) { - prefs.edit().putString("vanced_variant", variant).apply() - startActivity(Intent(activity, MainActivity::class.java)) - activity?.overridePendingTransition(animIn, animOut) - activity?.finish() - } else - Log.d("VMVariant", "$variant is already selected") - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/core/fragments/LanguageInstall.kt b/app/src/main/java/com/vanced/manager/core/fragments/LanguageInstall.kt deleted file mode 100644 index db7616b64f..0000000000 --- a/app/src/main/java/com/vanced/manager/core/fragments/LanguageInstall.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.vanced.manager.core.fragments - -import android.content.Context -import android.os.Bundle -import android.view.View -import android.widget.Button -import android.widget.RadioButton -import android.widget.RadioGroup -import androidx.navigation.findNavController -import com.vanced.manager.R -import com.vanced.manager.core.base.BaseFragment - -open class LanguageInstall : BaseFragment() { - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val finishButton = view.findViewById