Add back manual downloader from v3
This commit is contained in:
@@ -40,6 +40,11 @@ sealed class BusEvent {
|
||||
var email: String = String(),
|
||||
var aasToken: String = String()
|
||||
) : BusEvent()
|
||||
|
||||
data class ManualDownload(
|
||||
var packageName: String,
|
||||
var versionCode: Int
|
||||
) : BusEvent()
|
||||
}
|
||||
|
||||
sealed class InstallerEvent {
|
||||
|
||||
@@ -67,7 +67,7 @@ object PackageUtil {
|
||||
return try {
|
||||
val packageInfo = getPackageInfo(context, packageName)
|
||||
if (packageInfo != null) {
|
||||
"${packageInfo.versionName}.${packageInfo.versionCode}"
|
||||
"${packageInfo.versionName} (${packageInfo.versionCode})"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.aurora.store.databinding.ActivityDetailsBinding
|
||||
import com.aurora.store.util.*
|
||||
import com.aurora.store.view.ui.downloads.DownloadActivity
|
||||
import com.aurora.store.view.ui.sheets.InstallErrorDialogSheet
|
||||
import com.aurora.store.view.ui.sheets.ManualDownloadSheet
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
|
||||
@@ -116,6 +117,12 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
attachActions()
|
||||
}
|
||||
}
|
||||
is BusEvent.ManualDownload -> {
|
||||
if (app.packageName == event.packageName) {
|
||||
app.versionCode = event.versionCode
|
||||
purchase()
|
||||
}
|
||||
}
|
||||
is InstallerEvent.Failed -> {
|
||||
if (app.packageName == event.packageName) {
|
||||
InstallErrorDialogSheet.newInstance(
|
||||
@@ -206,6 +213,12 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
uninstallApp()
|
||||
return true
|
||||
}
|
||||
R.id.menu_download_manual -> {
|
||||
val sheet = ManualDownloadSheet.newInstance(app)
|
||||
sheet.isCancelable = false
|
||||
sheet.show(supportFragmentManager, ManualDownloadSheet.TAG)
|
||||
return true
|
||||
}
|
||||
R.id.menu_download_manager -> {
|
||||
open(DownloadActivity::class.java)
|
||||
return true
|
||||
@@ -327,7 +340,7 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
app
|
||||
)
|
||||
}
|
||||
txtLine3.text = ("v${app.versionName}.${app.versionCode}")
|
||||
txtLine3.text = ("${app.versionName} (${app.versionCode})")
|
||||
|
||||
val tags = mutableListOf<String>()
|
||||
if (app.isFree)
|
||||
@@ -546,7 +559,7 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
|
||||
if (isUpdatable) {
|
||||
B.layoutDetailsApp.txtLine3.text =
|
||||
("$installedVersion > ${app.versionName}.${app.versionCode}")
|
||||
("$installedVersion > ${app.versionName} (${app.versionCode})")
|
||||
btn.setText(R.string.action_update)
|
||||
btn.addOnClickListener { startDownload() }
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package com.aurora.store.view.ui.sheets
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.load
|
||||
import com.aurora.extensions.toast
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.PurchaseHelper
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.BusEvent
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.databinding.SheetManualDownloadBinding
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class ManualDownloadSheet : BaseBottomSheet() {
|
||||
|
||||
private lateinit var B: SheetManualDownloadBinding
|
||||
private lateinit var app: App
|
||||
private lateinit var authData: AuthData
|
||||
private lateinit var purchaseHelper: PurchaseHelper
|
||||
|
||||
companion object {
|
||||
|
||||
const val TAG = "ManualDownloadSheet"
|
||||
|
||||
@JvmStatic
|
||||
fun newInstance(
|
||||
app: App
|
||||
): ManualDownloadSheet {
|
||||
return ManualDownloadSheet().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(Constants.STRING_APP, gson.toJson(app))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateContentView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
B = SheetManualDownloadBinding.inflate(inflater)
|
||||
authData = AuthProvider.with(requireContext()).getAuthData()
|
||||
purchaseHelper = PurchaseHelper(authData)
|
||||
return B.root
|
||||
}
|
||||
|
||||
override fun onContentViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val bundle = arguments
|
||||
bundle?.let {
|
||||
val rawApp = bundle.getString(Constants.STRING_APP, "{}")
|
||||
app = gson.fromJson(rawApp, App::class.java)
|
||||
if (app.packageName.isNotEmpty()) {
|
||||
inflateData()
|
||||
attachActions()
|
||||
} else {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun inflateData() {
|
||||
B.imgIcon.load(app.iconArtwork.url) {
|
||||
placeholder(R.drawable.bg_placeholder)
|
||||
transform(RoundedCorners(32))
|
||||
}
|
||||
|
||||
B.txtLine1.text = app.displayName
|
||||
B.txtLine2.text = app.packageName
|
||||
B.txtLine3.text = ("${app.versionName} (${app.versionCode})")
|
||||
|
||||
B.versionCodeLayout.hint = "${app.versionCode}"
|
||||
}
|
||||
|
||||
private fun attachActions() {
|
||||
B.btnPrimary.setOnClickListener {
|
||||
val customVersionString = (B.versionCodeInp.text).toString()
|
||||
if (customVersionString.isEmpty())
|
||||
B.versionCodeInp.error = "Enter version code"
|
||||
else {
|
||||
val customVersion = customVersionString.toInt()
|
||||
|
||||
task {
|
||||
purchaseHelper.purchase(app.packageName, customVersion, app.offerType)
|
||||
} successUi {
|
||||
if (it.isNotEmpty()) {
|
||||
toast(R.string.toast_manual_available)
|
||||
EventBus.getDefault().post(BusEvent.ManualDownload(app.packageName, customVersion))
|
||||
dismissAllowingStateLoss()
|
||||
} else {
|
||||
toast(R.string.toast_manual_unavailable)
|
||||
}
|
||||
} failUi {
|
||||
toast(R.string.toast_manual_unavailable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
B.btnSecondary.setOnClickListener {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user