Skip to content

Commit

Permalink
Merge pull request #3992 from kiwix/Fixes#3988
Browse files Browse the repository at this point in the history
Fixed: Opening new tab from app's shortcut in custom apps showing application is not installed.
  • Loading branch information
kelson42 authored Sep 11, 2024
2 parents c723537 + 8ce956c commit e3844e5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 46 deletions.
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
android:launchMode="singleTop"
android:theme="@style/KiwixTheme.Launcher"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package org.kiwix.kiwixmobile.main

import android.content.Intent
import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.content.res.Configuration
import android.graphics.drawable.Icon
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand All @@ -36,11 +39,13 @@ import com.google.android.material.navigation.NavigationView
import eu.mhutti1.utils.storage.StorageDeviceUtils
import org.kiwix.kiwixmobile.BuildConfig
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.drawable
import org.kiwix.kiwixmobile.core.R.mipmap
import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
import org.kiwix.kiwixmobile.core.dao.NewBookDao
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DOWNLOAD_NOTIFICATION_TITLE
import org.kiwix.kiwixmobile.core.main.ACTION_NEW_TAB
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.databinding.ActivityKiwixMainBinding
Expand All @@ -49,6 +54,7 @@ import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragmentDirection
import javax.inject.Inject

const val NAVIGATE_TO_ZIM_HOST_FRAGMENT = "navigate_to_zim_host_fragment"
const val ACTION_GET_CONTENT = "GET_CONTENT"

class KiwixMainActivity : CoreMainActivity() {
private var actionMode: ActionMode? = null
Expand Down Expand Up @@ -230,4 +236,35 @@ class KiwixMainActivity : CoreMainActivity() {
}

override fun getIconResId() = mipmap.ic_launcher

override fun createApplicationShortcuts() {
val shortcutManager = getSystemService(ShortcutManager::class.java)

// Create a shortcut for opening the "New tab"
val newTabShortcut = ShortcutInfo.Builder(this, "new_tab")
.setShortLabel(getString(string.new_tab_shortcut_label))
.setLongLabel(getString(string.new_tab_shortcut_label))
.setIcon(Icon.createWithResource(this, drawable.ic_shortcut_new_tab))
.setDisabledMessage(getString(string.shortcut_disabled_message))
.setIntent(
Intent(this, KiwixMainActivity::class.java).apply {
action = ACTION_NEW_TAB
}
)
.build()

// create a shortCut for opening the online fragment.
val getContentShortcut = ShortcutInfo.Builder(this, "get_content")
.setShortLabel(getString(string.get_content_shortcut_label))
.setLongLabel(getString(string.get_content_shortcut_label))
.setIcon(Icon.createWithResource(this, drawable.ic_shortcut_get_content))
.setDisabledMessage(getString(string.shortcut_disabled_message))
.setIntent(
Intent(this, KiwixMainActivity::class.java).apply {
action = ACTION_GET_CONTENT
}
)
.build()
shortcutManager.dynamicShortcuts = listOf(newTabShortcut, getContentShortcut)
}
}
27 changes: 0 additions & 27 deletions app/src/main/res/xml-v25/shortcuts.xml

This file was deleted.

1 change: 1 addition & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
tools:targetApi="s" />
<uses-permission
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const val SHOULD_OPEN_IN_NEW_TAB = "shouldOpenInNewTab"
const val FIND_IN_PAGE_SEARCH_STRING = "findInPageSearchString"
const val ZIM_FILE_URI_KEY = "zimFileUri"
const val KIWIX_INTERNAL_ERROR = 10
const val ACTION_NEW_TAB = "NEW_TAB"

abstract class CoreMainActivity : BaseActivity(), WebViewProvider {

Expand Down Expand Up @@ -139,6 +140,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
}
downloadManagerBroadcastReceiver.let(::registerReceiver)
downloadNotificationActionsReceiver.let(::registerReceiver)
createApplicationShortcuts()
}

@Suppress("DEPRECATION")
Expand Down Expand Up @@ -421,4 +423,5 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {

protected abstract fun getIconResId(): Int
abstract val readerFragmentResId: Int
abstract fun createApplicationShortcuts()
}
3 changes: 0 additions & 3 deletions custom/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

package org.kiwix.kiwixmobile.custom.main

import android.content.Intent
import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -28,9 +32,12 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.google.android.material.navigation.NavigationView
import org.kiwix.kiwixmobile.core.extensions.browserIntent
import org.kiwix.kiwixmobile.core.main.ACTION_NEW_TAB
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.custom.BuildConfig
import org.kiwix.kiwixmobile.custom.R
import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.core.R.drawable
import org.kiwix.kiwixmobile.custom.customActivityComponent
import org.kiwix.kiwixmobile.custom.databinding.ActivityCustomMainBinding

Expand Down Expand Up @@ -185,4 +192,21 @@ class CustomMainActivity : CoreMainActivity() {
}

override fun getIconResId() = R.mipmap.ic_launcher

override fun createApplicationShortcuts() {
val shortcutManager = getSystemService(ShortcutManager::class.java)
// Create a shortcut for opening the "New tab"
val newTabShortcut = ShortcutInfo.Builder(this, "new_tab")
.setShortLabel(getString(string.new_tab_shortcut_label))
.setLongLabel(getString(string.new_tab_shortcut_label))
.setIcon(Icon.createWithResource(this, drawable.ic_shortcut_new_tab))
.setDisabledMessage(getString(string.shortcut_disabled_message))
.setIntent(
Intent(this, CustomMainActivity::class.java).apply {
action = ACTION_NEW_TAB
}
)
.build()
shortcutManager.dynamicShortcuts = listOf(newTabShortcut)
}
}
13 changes: 0 additions & 13 deletions custom/src/main/res/xml-v25/shortcuts.xml

This file was deleted.

0 comments on commit e3844e5

Please sign in to comment.