Updated downloading modules

This commit is contained in:
Viktor De Pasquale 2019-07-10 19:36:01 +02:00 committed by John Wu
parent 224fff89e3
commit 0dcd3ece9d

View File

@ -1,19 +1,19 @@
package com.topjohnwu.magisk.ui.module package com.topjohnwu.magisk.ui.module
import android.annotation.SuppressLint
import android.app.AlertDialog import android.app.AlertDialog
import android.content.Intent
import android.os.Build
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.widget.SearchView import android.widget.SearchView
import com.skoumal.teanity.viewevents.ViewEvent import com.skoumal.teanity.viewevents.ViewEvent
import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.FragmentReposBinding import com.topjohnwu.magisk.databinding.FragmentReposBinding
import com.topjohnwu.magisk.model.download.DownloadModuleService import com.topjohnwu.magisk.model.download.CompoundDownloadService
import com.topjohnwu.magisk.model.entity.Repo import com.topjohnwu.magisk.model.entity.Repo
import com.topjohnwu.magisk.model.entity.internal.Configuration
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import com.topjohnwu.magisk.model.events.InstallModuleEvent import com.topjohnwu.magisk.model.events.InstallModuleEvent
import com.topjohnwu.magisk.model.events.OpenChangelogEvent import com.topjohnwu.magisk.model.events.OpenChangelogEvent
import com.topjohnwu.magisk.ui.base.MagiskFragment import com.topjohnwu.magisk.ui.base.MagiskFragment
@ -92,19 +92,16 @@ class ReposFragment : MagiskFragment<ModuleViewModel, FragmentReposBinding>(),
MarkDownWindow.show(requireActivity(), null, item.detailUrl) MarkDownWindow.show(requireActivity(), null, item.detailUrl)
} }
@SuppressLint("MissingPermission")
private fun installModule(item: Repo) { private fun installModule(item: Repo) {
val context = magiskActivity val context = magiskActivity
fun download(install: Boolean) { fun download(install: Boolean) {
context.withExternalRW { context.withExternalRW {
onSuccess { onSuccess {
val intent = Intent(activity, ClassMap[DownloadModuleService::class.java]) val config = if (install) Configuration.Flash() else Configuration.Download
.putExtra("repo", item).putExtra("install", install) val subject = DownloadSubject.Module(item, config)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CompoundDownloadService.download(context, subject)
context.startForegroundService(intent)
} else {
context.startService(intent)
}
} }
} }
} }