From 81df8937f808e30b2d9e92f73d691f531272647b Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 6 Apr 2022 15:20:08 +0530 Subject: [PATCH 01/14] App lounge: (issue_4945) Define PWAPlayerStatusReceiver.kt and register in manifest --- app/src/main/AndroidManifest.xml | 13 +++++++++++++ .../e/apps/receiver/PWAPlayerStatusReceiver.kt | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b93355744..6ddaa42b6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -68,6 +68,19 @@ + + + + + + + + + + + + Date: Wed, 6 Apr 2022 20:13:23 +0530 Subject: [PATCH 02/14] App lounge: (issue_4945) Make broadcast receiver exported --- app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ddaa42b6..5fef1623c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -69,7 +69,7 @@ + android:exported="true"> -- GitLab From eb1c26f9501b821ea0a7b1c42e9e0bfd321377a6 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 7 Apr 2022 21:02:54 +0530 Subject: [PATCH 03/14] App lounge: (issue_4945) Receive Pwa shortcut id and update the status --- .../apps/receiver/PWAPlayerStatusReceiver.kt | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt index d35ddb124..c11b7ebf7 100644 --- a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt @@ -3,9 +3,43 @@ package foundation.e.apps.receiver import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import dagger.hilt.android.AndroidEntryPoint +import foundation.e.apps.manager.database.DatabaseRepository +import foundation.e.apps.utils.enums.Status +import kotlinx.coroutines.* +import javax.inject.Inject +@AndroidEntryPoint +@DelicateCoroutinesApi class PWAPlayerStatusReceiver: BroadcastReceiver() { + + companion object { + const val ACTION_PWA_ADDED = "foundation.e.pwaplayer.PWA_ADDED" + const val ACTION_PWA_REMOVED = "foundation.e.pwaplayer.PWA_REMOVED" + } + + @Inject + lateinit var databaseRepository: DatabaseRepository + override fun onReceive(context: Context?, intent: Intent?) { - System.out.println("Testingggg: received in app lounge: $intent"); + GlobalScope.launch { + try { + intent?.getStringExtra("SHORTCUT_ID")?.let { shortcutId -> + databaseRepository.getDownloadById(shortcutId)?.let { fusedDownload -> + when (intent.action) { + ACTION_PWA_ADDED -> { + fusedDownload.status = Status.INSTALLED + databaseRepository.updateDownload(fusedDownload) + } + ACTION_PWA_REMOVED -> { + databaseRepository.deleteDownload(fusedDownload) + } + } + } + } + } catch (e: Exception) { + e.printStackTrace() + } + } } } \ No newline at end of file -- GitLab From fcfe98daf32857e51621ea5e27b74dc956376d42 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 17:03:35 +0530 Subject: [PATCH 04/14] App lounge: (issue_4945) Define getPwaStatus() (similar to PkgManagerModule.getPackageStatus()) to get PWA installed status from PWA Player --- .../e/apps/utils/modules/PWAManagerModule.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt index 0618a08b2..f26629cdb 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt @@ -37,6 +37,40 @@ class PWAManagerModule @Inject constructor( private const val VIEW_PWA = "foundation.e.blisslauncher.VIEW_PWA" } + /** + * Fetch info from PWA Player to check if a PWA is installed. + * The column names returned from PWA helper are: [_id, shortcutId, url, title, icon] + * The last column ("icon") is a blob. + * Note that there is no pwa version. Also there is no "package_name". + * + * In this method, we get all the available PWAs from PWA Player and compare each of their url + * to the method argument [pwaUrl]. If an item (from the cursor) has url equal to [pwaUrl], + * we return [Status.INSTALLED]. + * + * As there is no concept of version, we cannot send [Status.UPDATABLE]. + */ + fun getPwaStatus(pwaUrl: String): Status { + context.contentResolver.query(Uri.parse(PWA_PLAYER), + null, null, null, null)?.let { cursor -> + if (cursor.count > 0) { + if (cursor.moveToFirst()) { + do { + try { + val pwaItemUrl = cursor.getString(cursor.columnNames.indexOf("url")) + if (pwaUrl == pwaItemUrl) return Status.INSTALLED + } + catch (e: Exception) { + e.printStackTrace() + } + } while (cursor.moveToNext()) + } + } + cursor.close() + } + + return Status.UNAVAILABLE + } + suspend fun installPWAApp(fusedDownload: FusedDownload) { // Update status fusedDownload.status = Status.DOWNLOADING -- GitLab From 7d60827f07319671ac9da9c13461452a038471dd Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 17:05:05 +0530 Subject: [PATCH 05/14] App lounge: (issue_4945) call PWAManagerModule.getPwaStatus() in FusedApp.updateStatus() --- .../main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 1a6cc16cc..c8e8e5008 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -44,6 +44,7 @@ import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type +import foundation.e.apps.utils.modules.PWAManagerModule import foundation.e.apps.utils.modules.PreferenceManagerModule import javax.inject.Inject import javax.inject.Singleton @@ -53,6 +54,7 @@ class FusedAPIImpl @Inject constructor( private val cleanAPKRepository: CleanAPKRepository, private val gPlayAPIRepository: GPlayAPIRepository, private val pkgManagerModule: PkgManagerModule, + private val pwaManagerModule: PWAManagerModule, private val preferenceManagerModule: PreferenceManagerModule, @ApplicationContext private val context: Context ) { @@ -643,8 +645,12 @@ class FusedAPIImpl @Inject constructor( private fun FusedApp.updateStatus() { if (this.status != Status.INSTALLATION_ISSUE) { - this.status = + this.status = if (this.is_pwa) { + pwaManagerModule.getPwaStatus(this.url) + } + else { pkgManagerModule.getPackageStatus(this.package_name, this.latest_version_code) + } } } -- GitLab From dabc68a0774899f154ecd55f259239904671612e Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 18:55:56 +0530 Subject: [PATCH 06/14] App lounge: (issue_4945) some documentation update --- .../e/apps/receiver/PWAPlayerStatusReceiver.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt index c11b7ebf7..98b8ece12 100644 --- a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt @@ -9,6 +9,15 @@ import foundation.e.apps.utils.enums.Status import kotlinx.coroutines.* import javax.inject.Inject +/** + * Illustration of how to get PWA installation status from broadcast from PWA player. + * This class is not of much use here as after a PWA is installed, the FusedDownload instance + * is deleted from the database. + * + * The sent intent contains following extras: + * 1. SHORTCUT_ID - string shortcut id. + * 2. URL - string url of the pwa. + */ @AndroidEntryPoint @DelicateCoroutinesApi class PWAPlayerStatusReceiver: BroadcastReceiver() { -- GitLab From de6efe09c5676c6c268396994bf63fb09efbb524 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 21:10:11 +0530 Subject: [PATCH 07/14] App lounge: (issue_4945) define FusedApp variable pwaPlayerDbId --- app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt b/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt index b654cb645..cf8204f90 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt @@ -48,6 +48,7 @@ data class FusedApp( val price: String = String(), val isFree: Boolean = true, val is_pwa: Boolean = false, + var pwaPlayerDbId: Long = -1, val url: String = String(), var type: Type = Type.NATIVE, var privacyScore: Int = -1 -- GitLab From 92118eef6d5cf3bab0f6aed5ed36ea2a2247a081 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 21:13:24 +0530 Subject: [PATCH 08/14] App lounge: (issue_4945) change method signature PWAManagerModule.getPwaStatus, accepts FusedApp and sets pwaPlayerDbId if PWA is installed --- .../e/apps/api/fused/FusedAPIImpl.kt | 2 +- .../e/apps/utils/modules/PWAManagerModule.kt | 253 +++++++++--------- 2 files changed, 130 insertions(+), 125 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index c8e8e5008..f2570cbcf 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -646,7 +646,7 @@ class FusedAPIImpl @Inject constructor( private fun FusedApp.updateStatus() { if (this.status != Status.INSTALLATION_ISSUE) { this.status = if (this.is_pwa) { - pwaManagerModule.getPwaStatus(this.url) + pwaManagerModule.getPwaStatus(this) } else { pkgManagerModule.getPackageStatus(this.package_name, this.latest_version_code) diff --git a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt index f26629cdb..d6ba5687d 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt @@ -1,124 +1,129 @@ -package foundation.e.apps.utils.modules - -import android.content.ContentUris -import android.content.ContentValues -import android.content.Context -import android.content.Intent -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.net.Uri -import android.util.Base64 -import androidx.core.content.pm.ShortcutInfoCompat -import androidx.core.content.pm.ShortcutManagerCompat -import androidx.core.graphics.drawable.IconCompat -import dagger.hilt.android.qualifiers.ApplicationContext -import foundation.e.apps.manager.database.DatabaseRepository -import foundation.e.apps.manager.database.fusedDownload.FusedDownload -import foundation.e.apps.utils.enums.Status -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class PWAManagerModule @Inject constructor( - @ApplicationContext private val context: Context, - private val databaseRepository: DatabaseRepository -) { - - companion object { - private const val URL = "URL" - private const val SHORTCUT_ID = "SHORTCUT_ID" - private const val TITLE = "TITLE" - private const val ICON = "ICON" - - private const val PWA_NAME = "PWA_NAME" - private const val PWA_ID = "PWA_ID" - - private const val PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa" - private const val VIEW_PWA = "foundation.e.blisslauncher.VIEW_PWA" - } - - /** - * Fetch info from PWA Player to check if a PWA is installed. - * The column names returned from PWA helper are: [_id, shortcutId, url, title, icon] - * The last column ("icon") is a blob. - * Note that there is no pwa version. Also there is no "package_name". - * - * In this method, we get all the available PWAs from PWA Player and compare each of their url - * to the method argument [pwaUrl]. If an item (from the cursor) has url equal to [pwaUrl], - * we return [Status.INSTALLED]. - * - * As there is no concept of version, we cannot send [Status.UPDATABLE]. - */ - fun getPwaStatus(pwaUrl: String): Status { - context.contentResolver.query(Uri.parse(PWA_PLAYER), - null, null, null, null)?.let { cursor -> - if (cursor.count > 0) { - if (cursor.moveToFirst()) { - do { - try { - val pwaItemUrl = cursor.getString(cursor.columnNames.indexOf("url")) - if (pwaUrl == pwaItemUrl) return Status.INSTALLED - } - catch (e: Exception) { - e.printStackTrace() - } - } while (cursor.moveToNext()) - } - } - cursor.close() - } - - return Status.UNAVAILABLE - } - - suspend fun installPWAApp(fusedDownload: FusedDownload) { - // Update status - fusedDownload.status = Status.DOWNLOADING - databaseRepository.updateDownload(fusedDownload) - - // Get bitmap and byteArray for icon - val iconByteArray = Base64.decode(fusedDownload.iconByteArray, Base64.DEFAULT) - val iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.size) - - val values = ContentValues() - values.apply { - put(URL, fusedDownload.downloadURLList[0]) - put(SHORTCUT_ID, fusedDownload.id) - put(TITLE, fusedDownload.name) - put(ICON, iconByteArray) - } - - context.contentResolver.insert(Uri.parse(PWA_PLAYER), values)?.let { - val databaseID = ContentUris.parseId(it) - publishShortcut(fusedDownload, iconBitmap, databaseID) - } - } - - private suspend fun publishShortcut(fusedDownload: FusedDownload, bitmap: Bitmap, databaseID: Long) { - // Update status - fusedDownload.status = Status.INSTALLING - databaseRepository.updateDownload(fusedDownload) - - val intent = Intent().apply { - action = VIEW_PWA - data = Uri.parse(fusedDownload.downloadURLList[0]) - putExtra(PWA_NAME, fusedDownload.name) - putExtra(PWA_ID, databaseID) - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) - } - - val shortcutInfo = ShortcutInfoCompat.Builder(context, fusedDownload.id) - .setShortLabel(fusedDownload.name) - .setIcon(IconCompat.createWithBitmap(bitmap)) - .setIntent(intent) - .build() - ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null) - - // Update status - fusedDownload.status = Status.INSTALLED - databaseRepository.updateDownload(fusedDownload) - - databaseRepository.deleteDownload(fusedDownload) - } -} +package foundation.e.apps.utils.modules + +import android.content.ContentUris +import android.content.ContentValues +import android.content.Context +import android.content.Intent +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.net.Uri +import android.util.Base64 +import androidx.core.content.pm.ShortcutInfoCompat +import androidx.core.content.pm.ShortcutManagerCompat +import androidx.core.graphics.drawable.IconCompat +import dagger.hilt.android.qualifiers.ApplicationContext +import foundation.e.apps.api.fused.data.FusedApp +import foundation.e.apps.manager.database.DatabaseRepository +import foundation.e.apps.manager.database.fusedDownload.FusedDownload +import foundation.e.apps.utils.enums.Status +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class PWAManagerModule @Inject constructor( + @ApplicationContext private val context: Context, + private val databaseRepository: DatabaseRepository +) { + + companion object { + private const val URL = "URL" + private const val SHORTCUT_ID = "SHORTCUT_ID" + private const val TITLE = "TITLE" + private const val ICON = "ICON" + + private const val PWA_NAME = "PWA_NAME" + private const val PWA_ID = "PWA_ID" + + private const val PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa" + private const val VIEW_PWA = "foundation.e.blisslauncher.VIEW_PWA" + } + + /** + * Fetch info from PWA Player to check if a PWA is installed. + * The column names returned from PWA helper are: [_id, shortcutId, url, title, icon] + * The last column ("icon") is a blob. + * Note that there is no pwa version. Also there is no "package_name". + * + * In this method, we get all the available PWAs from PWA Player and compare each of their url + * to the method argument [pwaUrl]. If an item (from the cursor) has url equal to [pwaUrl], + * we return [Status.INSTALLED]. + * + * As there is no concept of version, we cannot send [Status.UPDATABLE]. + */ + fun getPwaStatus(fusedApp: FusedApp): Status { + context.contentResolver.query(Uri.parse(PWA_PLAYER), + null, null, null, null)?.let { cursor -> + if (cursor.count > 0) { + if (cursor.moveToFirst()) { + do { + try { + val pwaItemUrl = cursor.getString(cursor.columnNames.indexOf("url")) + val pwaItemDbId = cursor.getLong(cursor.columnNames.indexOf("_id")) + if (fusedApp.url == pwaItemUrl) { + fusedApp.pwaPlayerDbId = pwaItemDbId + return Status.INSTALLED + } + } + catch (e: Exception) { + e.printStackTrace() + } + } while (cursor.moveToNext()) + } + } + cursor.close() + } + + return Status.UNAVAILABLE + } + + suspend fun installPWAApp(fusedDownload: FusedDownload) { + // Update status + fusedDownload.status = Status.DOWNLOADING + databaseRepository.updateDownload(fusedDownload) + + // Get bitmap and byteArray for icon + val iconByteArray = Base64.decode(fusedDownload.iconByteArray, Base64.DEFAULT) + val iconBitmap = BitmapFactory.decodeByteArray(iconByteArray, 0, iconByteArray.size) + + val values = ContentValues() + values.apply { + put(URL, fusedDownload.downloadURLList[0]) + put(SHORTCUT_ID, fusedDownload.id) + put(TITLE, fusedDownload.name) + put(ICON, iconByteArray) + } + + context.contentResolver.insert(Uri.parse(PWA_PLAYER), values)?.let { + val databaseID = ContentUris.parseId(it) + publishShortcut(fusedDownload, iconBitmap, databaseID) + } + } + + private suspend fun publishShortcut(fusedDownload: FusedDownload, bitmap: Bitmap, databaseID: Long) { + // Update status + fusedDownload.status = Status.INSTALLING + databaseRepository.updateDownload(fusedDownload) + + val intent = Intent().apply { + action = VIEW_PWA + data = Uri.parse(fusedDownload.downloadURLList[0]) + putExtra(PWA_NAME, fusedDownload.name) + putExtra(PWA_ID, databaseID) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) + } + + val shortcutInfo = ShortcutInfoCompat.Builder(context, fusedDownload.id) + .setShortLabel(fusedDownload.name) + .setIcon(IconCompat.createWithBitmap(bitmap)) + .setIntent(intent) + .build() + ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null) + + // Update status + fusedDownload.status = Status.INSTALLED + databaseRepository.updateDownload(fusedDownload) + + databaseRepository.deleteDownload(fusedDownload) + } +} -- GitLab From dd79d590db3a0e360df799195c40c1058c2a96ca Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 21:18:07 +0530 Subject: [PATCH 09/14] App lounge: (issue_4945) update documentation --- .../java/foundation/e/apps/utils/modules/PWAManagerModule.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt index d6ba5687d..24ec9d6cd 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt @@ -45,8 +45,9 @@ class PWAManagerModule @Inject constructor( * Note that there is no pwa version. Also there is no "package_name". * * In this method, we get all the available PWAs from PWA Player and compare each of their url - * to the method argument [pwaUrl]. If an item (from the cursor) has url equal to [pwaUrl], - * we return [Status.INSTALLED]. + * to the method argument [fusedApp]'s url. If an item (from the cursor) has url equal to + * that of pwa app, we return [Status.INSTALLED]. + * We also set [FusedApp.pwaPlayerDbId] for the [fusedApp]. * * As there is no concept of version, we cannot send [Status.UPDATABLE]. */ -- GitLab From 2cda7a372a2a649eeea28bd4984a032783aabd09 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 21:18:45 +0530 Subject: [PATCH 10/14] App lounge: (issue_4945) create method PWAManagerModule.launchPwa() --- .../e/apps/utils/modules/PWAManagerModule.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt index 24ec9d6cd..3a5eadd9b 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt @@ -77,6 +77,19 @@ class PWAManagerModule @Inject constructor( return Status.UNAVAILABLE } + /** + * Launch PWA using PWA Player. + */ + fun launchPwa(fusedApp: FusedApp) { + val launchIntent = Intent(VIEW_PWA).apply { + data = Uri.parse(fusedApp.url) + putExtra(PWA_ID, fusedApp.pwaPlayerDbId) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) + } + context.startActivity(launchIntent) + } + suspend fun installPWAApp(fusedDownload: FusedDownload) { // Update status fusedDownload.status = Status.DOWNLOADING -- GitLab From 12e7b415d13260b3b494937de10f93b70bb5ec29 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 22:39:54 +0530 Subject: [PATCH 11/14] App lounge: (issue_4945) implement calling PWAManagerModule.launchPwa() from various places in the code. --- .../e/apps/application/ApplicationFragment.kt | 10 +++++++++- .../e/apps/applicationlist/ApplicationListFragment.kt | 5 +++++ .../applicationlist/model/ApplicationListRVAdapter.kt | 8 +++++++- .../main/java/foundation/e/apps/home/HomeFragment.kt | 5 +++++ .../foundation/e/apps/home/model/HomeChildRVAdapter.kt | 8 +++++++- .../e/apps/home/model/HomeParentRVAdapter.kt | 4 +++- .../java/foundation/e/apps/search/SearchFragment.kt | 5 +++++ .../java/foundation/e/apps/updates/UpdatesFragment.kt | 5 +++++ 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index 881879940..e11168236 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -58,6 +58,7 @@ import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import javax.inject.Inject @@ -74,6 +75,9 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { @Inject lateinit var pkgManagerModule: PkgManagerModule + @Inject + lateinit var pwaManagerModule: PWAManagerModule + private val applicationViewModel: ApplicationViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() @@ -462,7 +466,11 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { backgroundTintList = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { - startActivity(pkgManagerModule.getLaunchIntent(fusedApp.package_name)) + if (fusedApp.is_pwa) { + pwaManagerModule.launchPwa(fusedApp) + } else { + startActivity(pkgManagerModule.getLaunchIntent(fusedApp.package_name)) + } } } } diff --git a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt index 28937de9f..72ad6ab31 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -45,6 +45,7 @@ import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.launch import javax.inject.Inject @@ -56,6 +57,9 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu @Inject lateinit var pkgManagerModule: PkgManagerModule + @Inject + lateinit var pwaManagerModule: PWAManagerModule + private val viewModel: ApplicationListViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() @@ -115,6 +119,7 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu fdroidFetchViewModel, it, pkgManagerModule, + pwaManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner ) { fusedApp -> diff --git a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt b/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt index b7cdbfe51..c70c36d4a 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt @@ -48,6 +48,7 @@ import foundation.e.apps.updates.UpdatesFragmentDirections import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule import javax.inject.Singleton @Singleton @@ -57,6 +58,7 @@ class ApplicationListRVAdapter( private val fdroidFetchViewModel: FdroidFetchViewModel, private val currentDestinationId: Int, private val pkgManagerModule: PkgManagerModule, + private val pwaManagerModule: PWAManagerModule, private val user: User, private val lifecycleOwner: LifecycleOwner, private val paidAppHandler: ((FusedApp) -> Unit)? = null @@ -341,7 +343,11 @@ class ApplicationListRVAdapter( backgroundTintList = ContextCompat.getColorStateList(view.context, R.color.colorAccent) strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { - context.startActivity(pkgManagerModule.getLaunchIntent(searchApp.package_name)) + if (searchApp.is_pwa) { + pwaManagerModule.launchPwa(searchApp) + } else { + context.startActivity(pkgManagerModule.getLaunchIntent(searchApp.package_name)) + } } } } diff --git a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt index f54faf6d0..af754a46e 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -42,6 +42,7 @@ import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.launch import javax.inject.Inject @@ -58,6 +59,9 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { @Inject lateinit var pkgManagerModule: PkgManagerModule + @Inject + lateinit var pwaManagerModule: PWAManagerModule + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) _binding = FragmentHomeBinding.bind(view) @@ -83,6 +87,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { val homeParentRVAdapter = HomeParentRVAdapter( this, pkgManagerModule, + pwaManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), mainActivityViewModel, viewLifecycleOwner ) { fusedApp -> diff --git a/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt b/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt index 0d4b74f32..42997ea63 100644 --- a/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/home/model/HomeChildRVAdapter.kt @@ -40,10 +40,12 @@ import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule class HomeChildRVAdapter( private val fusedAPIInterface: FusedAPIInterface, private val pkgManagerModule: PkgManagerModule, + private val pwaManagerModule: PWAManagerModule, private val user: User, private val paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(HomeChildFusedAppDiffUtil()) { @@ -106,7 +108,11 @@ class HomeChildRVAdapter( strokeColor = ContextCompat.getColorStateList(view.context, R.color.colorAccent) setOnClickListener { - context.startActivity(pkgManagerModule.getLaunchIntent(homeApp.package_name)) + if (homeApp.is_pwa) { + pwaManagerModule.launchPwa(homeApp) + } else { + context.startActivity(pkgManagerModule.getLaunchIntent(homeApp.package_name)) + } } } } diff --git a/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt b/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt index 5d3266834..2883c6510 100644 --- a/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt @@ -32,10 +32,12 @@ import foundation.e.apps.databinding.HomeParentListItemBinding import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule class HomeParentRVAdapter( private val fusedAPIInterface: FusedAPIInterface, private val pkgManagerModule: PkgManagerModule, + private val pwaManagerModule: PWAManagerModule, private val user: User, private val mainActivityViewModel: MainActivityViewModel, private val lifecycleOwner: LifecycleOwner, @@ -56,7 +58,7 @@ class HomeParentRVAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { val fusedHome = getItem(position) val homeChildRVAdapter = - HomeChildRVAdapter(fusedAPIInterface, pkgManagerModule, user, paidAppHandler) + HomeChildRVAdapter(fusedAPIInterface, pkgManagerModule, pwaManagerModule, user, paidAppHandler) homeChildRVAdapter.setData(fusedHome.list) holder.binding.titleTV.text = fusedHome.title diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 77d8e0471..fad5b2548 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -52,6 +52,7 @@ import foundation.e.apps.databinding.FragmentSearchBinding import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.launch import javax.inject.Inject @@ -65,6 +66,9 @@ class SearchFragment : @Inject lateinit var pkgManagerModule: PkgManagerModule + @Inject + lateinit var pwaManagerModule: PWAManagerModule + private var _binding: FragmentSearchBinding? = null private val binding get() = _binding!! @@ -119,6 +123,7 @@ class SearchFragment : fdroidFetchViewModel, it, pkgManagerModule, + pwaManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner ) { fusedApp -> diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt index 973dfd2e6..5685a9e44 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -43,6 +43,7 @@ import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User +import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.launch import javax.inject.Inject @@ -55,6 +56,9 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { @Inject lateinit var pkgManagerModule: PkgManagerModule + @Inject + lateinit var pwaManagerModule: PWAManagerModule + private val updatesViewModel: UpdatesViewModel by viewModels() private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels() private val fdroidFetchViewModel: FdroidFetchViewModel by viewModels() @@ -88,6 +92,7 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { fdroidFetchViewModel, it, pkgManagerModule, + pwaManagerModule, User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner, ) { fusedApp -> -- GitLab From f549e68c8975b07baeaa629d3b77a2c48b3aeca2 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 11 Apr 2022 23:47:13 +0530 Subject: [PATCH 12/14] App lounge: (issue_4945) add a small delay between PWA shortcut on home screen and setting pwa as installed. --- .../java/foundation/e/apps/utils/modules/PWAManagerModule.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt index 3a5eadd9b..643298bf8 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt @@ -16,6 +16,7 @@ import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.manager.database.DatabaseRepository import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.utils.enums.Status +import kotlinx.coroutines.delay import javax.inject.Inject import javax.inject.Singleton @@ -134,6 +135,9 @@ class PWAManagerModule @Inject constructor( .build() ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null) + // Add a small delay to avoid conflict of button states. + delay(100) + // Update status fusedDownload.status = Status.INSTALLED databaseRepository.updateDownload(fusedDownload) -- GitLab From 6894a71287a1b087fb39df0ab232bf62fea3cbc0 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 12 Apr 2022 12:33:33 +0530 Subject: [PATCH 13/14] App lounge: (issue_4945) add license --- .../e/apps/receiver/PWAPlayerStatusReceiver.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt index 98b8ece12..aedebc8d6 100644 --- a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt @@ -1,3 +1,21 @@ +/* + * Apps Quickly and easily install Android apps onto your device! + * Copyright (C) 2021 E FOUNDATION + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + package foundation.e.apps.receiver import android.content.BroadcastReceiver -- GitLab From 59d712b93a8dc0000ece6cca642316a10f1acaf5 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 12 Apr 2022 16:58:58 +0530 Subject: [PATCH 14/14] App lounge: (issue_4945) update license --- .../java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt index aedebc8d6..264213926 100644 --- a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt @@ -1,6 +1,5 @@ /* - * Apps Quickly and easily install Android apps onto your device! - * Copyright (C) 2021 E FOUNDATION + * Copyright (C) 2022 ECORP * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- GitLab