Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Import feature #62

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.c3r5b8.telegram_monet">

<queries>
<intent>
<action android:name="org.telegram.messenger.IMPORT_THEME"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent>
</queries>

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
44 changes: 43 additions & 1 deletion app/src/main/java/com/c3r5b8/telegram_monet/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package com.c3r5b8.telegram_monet

import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.content.pm.PackageManager.ResolveInfoFlags
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.FileProvider
import com.c3r5b8.telegram_monet.BuildConfig.APPLICATION_ID
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File

class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -168,7 +173,44 @@ class MainActivity : AppCompatActivity() {
"$APPLICATION_ID.provider",
file
)
val intent = Intent(Intent.ACTION_SEND)
val intent = Intent("org.telegram.messenger.IMPORT_THEME")
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.type = "*/*"

val flags = PackageManager.MATCH_DEFAULT_ONLY
val resolveInfos : List<ResolveInfo>
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
resolveInfos = packageManager.queryIntentActivities(intent, ResolveInfoFlags.of(flags.toLong()))
} else {
resolveInfos = packageManager.queryIntentActivities(intent, flags)
}
if (!resolveInfos.isEmpty()) {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.fast_import_choose_method)
.setMessage(R.string.fast_import_description)
.setPositiveButton(R.string.fast_import_method_fast_import) { dialog, which ->
resolveInfos.forEach {
grantUriPermission(it.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

val runIntent = Intent("org.telegram.messenger.IMPORT_THEME")
runIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
runIntent.type = "*/*"
runIntent.putExtra(Intent.EXTRA_STREAM, uri)
runIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(Intent.createChooser(runIntent, theme))
}
.setNegativeButton(R.string.fast_import_method_regular) { dialog, which -> shareThemeRegular(theme, uri) }
.show()

return
}

shareThemeRegular(theme, uri)
}

private fun shareThemeRegular(theme: String, uri: Uri) {
intent = Intent(Intent.ACTION_SEND)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.type = "*/*"
intent.putExtra(Intent.EXTRA_STREAM, uri)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
<string name="settings_card_title">Settings</string>
<string name="settings_card_use_gradient">Enable gradient (Telegram)</string>
<string name="settings_card_use_gradient_avatars">Enable gradient for avatars</string>
<!--Fast import-->
<string name="fast_import_choose_method">What to use?</string>
<string name="fast_import_description">The app has detected Telegram apps that supports fast theme importing.</string>
<string name="fast_import_method_fast_import">Fast import</string>
<string name="fast_import_method_regular">Regular (Sharing)</string>
</resources>