mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Fixed: Opening new tab from app's shortcut in custom apps showing application is not installed.
* Since we are now creating dynamic shortcuts for the application, the static shortcut is no longer required, so we have removed the static shortcut code from our implementation.
This commit is contained in:
parent
c723537470
commit
8ce956cae3
@ -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" />
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<shortcut
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_new_tab"
|
||||
android:shortcutDisabledMessage="@string/shortcut_disabled_message"
|
||||
android:shortcutId="new_tab"
|
||||
android:shortcutLongLabel="@string/new_tab_shortcut_label"
|
||||
android:shortcutShortLabel="@string/new_tab_shortcut_label">
|
||||
<intent
|
||||
android:action="NEW_TAB"
|
||||
android:targetClass="org.kiwix.kiwixmobile.main.KiwixMainActivity"
|
||||
android:targetPackage="org.kiwix.kiwixmobile" />
|
||||
</shortcut>
|
||||
|
||||
<shortcut
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_get_content"
|
||||
android:shortcutDisabledMessage="@string/shortcut_disabled_message"
|
||||
android:shortcutId="get_content"
|
||||
android:shortcutLongLabel="@string/get_content_shortcut_label"
|
||||
android:shortcutShortLabel="@string/get_content_shortcut_label">
|
||||
<intent
|
||||
android:action="GET_CONTENT"
|
||||
android:targetClass="org.kiwix.kiwixmobile.main.KiwixMainActivity"
|
||||
android:targetPackage="org.kiwix.kiwixmobile" />
|
||||
</shortcut>
|
||||
</shortcuts>
|
@ -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" />
|
||||
|
@ -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 {
|
||||
|
||||
@ -139,6 +140,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
||||
}
|
||||
downloadManagerBroadcastReceiver.let(::registerReceiver)
|
||||
downloadNotificationActionsReceiver.let(::registerReceiver)
|
||||
createApplicationShortcuts()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@ -421,4 +423,5 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
|
||||
|
||||
protected abstract fun getIconResId(): Int
|
||||
abstract val readerFragmentResId: Int
|
||||
abstract fun createApplicationShortcuts()
|
||||
}
|
||||
|
@ -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" />
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<shortcut
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_new_tab"
|
||||
android:shortcutDisabledMessage="@string/shortcut_disabled_message"
|
||||
android:shortcutId="new_tab"
|
||||
android:shortcutLongLabel="@string/new_tab_shortcut_label"
|
||||
android:shortcutShortLabel="@string/new_tab_shortcut_label">
|
||||
<intent
|
||||
android:action="NEW_TAB"
|
||||
android:targetClass="org.kiwix.kiwixmobile.custom.main.CustomMainActivity" />
|
||||
</shortcut>
|
||||
</shortcuts>
|
Loading…
x
Reference in New Issue
Block a user