Skip to content

Commit

Permalink
Merge pull request #245 from faisalcodes/master
Browse files Browse the repository at this point in the history
Added support for other apps to launch QuranApp via intent.
  • Loading branch information
faisalcodes authored Apr 21, 2023
2 parents 2294802 + 63e318e commit ddd821d
Show file tree
Hide file tree
Showing 22 changed files with 369 additions and 192 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
targetSdkVersion 33
// I don't know why I've used such a weird versioning scheme in the beginning,
// but I can't change it now as the app is already in the Play Store
versionCode 23_04_02_001
versionName "2023.04.02.1"
versionCode 23_04_21_001
versionName "2023.04.21.1"

resValue "string", "app_name", "QuranApp"

Expand Down
43 changes: 35 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,41 @@
<activity android:name=".activities.ActivityBookmark" />
<activity android:name=".activities.ActivityReadHistory" />
<activity android:name=".activities.ActivityDownloads" />
<activity android:name=".activities.ActivityReference" />
<activity android:name=".activities.ActivityReference"
android:exported="true">
<intent-filter>
<action android:name="com.quranapp.android.action.OPEN_REFERENCE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".activities.ActivityTopics" />
<activity android:name=".activities.ActivityProphets" />
<activity
android:name=".activities.ActivityTafsir"
android:launchMode="singleTask" />
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="com.quranapp.android.action.OPEN_TAFSIR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.ActivityChapInfo"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="com.quranapp.android.action.OPEN_CHAPTER_INFO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter android:label="About Surah (QuranApp)">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data
android:host="quran.com"
android:pathPattern="/chapter_info/.*" />
<!-- note that the leading "/" is required for pathPrefix -->
<data android:host="quran.com"/>
<data android:pathPattern="/chapter_info/.*"/>
</intent-filter>
</activity>
<activity
Expand All @@ -80,11 +94,24 @@
android:name=".activities.ActivityReader"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="com.quranapp.android.action.OPEN_READER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https"/>
<data android:host="quran.com"/>
<data android:pathPattern="/juz/.*"/>
<data android:pathPattern="/\\d+"/>
<data android:pathPattern="/\\d+/\\d+"/>
<data android:pathPattern="/\\d+/\\d+-\\d+"/>
<data android:pathPattern="/\\d+:\\d+"/>
<data android:pathPattern="/\\d+:\\d+-\\d+"/>
</intent-filter>
</activity>
<activity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.quranapp.android.activities;

import static com.quranapp.android.utils.IntentUtils.INTENT_ACTION_OPEN_CHAPTER_INFO;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -93,20 +95,18 @@ protected void onNewIntent(Intent intent) {

private void initContent(Intent intent) {
int DEFAULT_CHAPTER_INFO = -1;
int chapterNo = -1;
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
final int chapterNo;
String action = intent.getAction();
if (
Intent.ACTION_VIEW.equals(action)
|| INTENT_ACTION_OPEN_CHAPTER_INFO.equalsIgnoreCase(action)
) {
try {
Uri data = intent.getData();
List<String> pathSegments = data.getPathSegments();
chapterNo = Integer.parseInt(pathSegments.get(1));

String lang = data.getQueryParameter("language");
if (lang == null) {
lang = data.getQueryParameter("lang");
}
mLanguage = lang;
} catch (Exception ignored) {
chapterNo = validateIntent(intent);
} catch (Exception e) {
e.printStackTrace();
invalidParams();
return;
}
} else {
chapterNo = intent.getIntExtra(Keys.READER_KEY_CHAPTER_NO, DEFAULT_CHAPTER_INFO);
Expand All @@ -128,6 +128,27 @@ private void initContent(Intent intent) {
loadContent();
}

private int validateIntent(Intent intent) {
Uri url = intent.getData();
if (INTENT_ACTION_OPEN_CHAPTER_INFO.equalsIgnoreCase(intent.getAction())) {
mLanguage = intent.getStringExtra("language");
return intent.getIntExtra("chapterNo", -1);
} else if (url.getHost().equalsIgnoreCase("quran.com")) {
List<String> pathSegments = url.getPathSegments();
String lang = url.getQueryParameter("language");

if (lang == null) {
lang = url.getQueryParameter("lang");
}

mLanguage = lang;

return Integer.parseInt(pathSegments.get(1));
} else {
throw new IllegalArgumentException("Invalid params");
}
}

private void initThis() {
mBinding.title.setText(R.string.strTitleAboutSurah);
mBinding.back.setOnClickListener(v -> finish());
Expand Down
Loading

0 comments on commit ddd821d

Please sign in to comment.