Skip to content

Commit

Permalink
Suggest to open theme config with ColorBlendr
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Dec 12, 2024
1 parent 5775746 commit 604e416
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 37 deletions.
18 changes: 18 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:priority="999">
<action android:name="android.intent.action.VIEW" />

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

<data android:host="*" />
<data android:mimeType="*/*" />
<data android:scheme="content" />
<data android:pathPattern=".*\\.colorblendr" />
<data android:pathPattern=".*\\..*\\.colorblendr" />
<data android:pathPattern=".*\\..*\\..*\\.colorblendr" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.colorblendr" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.colorblendr" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.colorblendr" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.colorblendr" />
</intent-filter>
</activity>
<activity
android:name=".ui.activities.MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.drdisagree.colorblendr.databinding.ActivityMainBinding
import com.drdisagree.colorblendr.service.RestartBroadcastReceiver.Companion.scheduleJob
import com.drdisagree.colorblendr.ui.fragments.HomeFragment
import com.drdisagree.colorblendr.ui.fragments.onboarding.OnboardingFragment
import com.drdisagree.colorblendr.utils.parcelable
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.shape.MaterialShapeDrawable

Expand All @@ -49,10 +50,14 @@ class MainActivity : AppCompatActivity() {
HomeFragment().apply {
arguments = Bundle().apply {
putBoolean("success", true)
if (intent?.hasExtra("data") == true) {
putParcelable("data", intent.parcelable("data"))
}
}
},
false
)
intent?.removeExtra("data")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class SplashActivity : AppCompatActivity() {
MainActivity::class.java
).apply {
putExtra("success", success.get())
intent.data?.let { uri ->
putExtra("data", uri)
intent.removeExtra("data")
}
}
)
finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.drdisagree.colorblendr.ui.fragments

import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand All @@ -26,6 +27,7 @@ import com.drdisagree.colorblendr.utils.AppUtil.requestStoragePermission
import com.drdisagree.colorblendr.utils.FragmentUtil.TabSelection
import com.drdisagree.colorblendr.utils.FragmentUtil.getSlidingDirection
import com.drdisagree.colorblendr.utils.FragmentUtil.setCustomAnimations
import com.drdisagree.colorblendr.utils.parcelable
import com.google.android.material.snackbar.Snackbar

class HomeFragment : Fragment() {
Expand Down Expand Up @@ -67,6 +69,19 @@ class HomeFragment : Fragment() {
}
}, 2000)

arguments?.let { bundle ->
bundle.parcelable<Uri>("data")?.let { uri ->
replaceFragment(
SettingsFragment().apply {
arguments = Bundle().apply {
putParcelable("data", uri)
}
}
)
bundle.remove("data")
}
}

registerOnBackPressedCallback()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
Expand Down Expand Up @@ -54,6 +55,7 @@ import com.drdisagree.colorblendr.utils.MiscUtil.setToolbarTitle
import com.drdisagree.colorblendr.utils.OverlayManager.applyFabricatedColors
import com.drdisagree.colorblendr.utils.OverlayManager.isOverlayEnabled
import com.drdisagree.colorblendr.utils.OverlayManager.removeFabricatedColors
import com.drdisagree.colorblendr.utils.parcelable
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.gson.reflect.TypeToken
Expand Down Expand Up @@ -271,6 +273,13 @@ class SettingsFragment : Fragment() {
}
}
}, viewLifecycleOwner, Lifecycle.State.RESUMED)

arguments?.let { bundle ->
bundle.parcelable<Uri>("data")?.let { data ->
showRestoreDialog(data)
bundle.remove("data")
}
}
}

private fun crossfade(view: View) {
Expand Down Expand Up @@ -359,50 +368,61 @@ class SettingsFragment : Fragment() {
val data: Intent? = result.data
if (data?.data == null) return@registerForActivityResult

MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.confirmation_title))
.setMessage(getString(R.string.confirmation_desc))
.setPositiveButton(getString(android.R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
showRestoreDialog(data.data)
}
}

private fun showRestoreDialog(uri: Uri?) {
if (uri == null) return

MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.confirmation_title))
.setMessage(getString(R.string.confirmation_desc))
.setPositiveButton(getString(android.R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()

CoroutineScope(Dispatchers.IO).launch {
try {
restorePrefs(
appContext
.contentResolver
.openInputStream(uri)!!
)

CoroutineScope(Dispatchers.IO).launch {
withContext(Dispatchers.Main) {
try {
restorePrefs(
appContext
.contentResolver
.openInputStream(data.data!!)!!
applyFabricatedColors(requireContext())
} catch (ignored: Exception) {
}
}
} catch (exception: Exception) {
withContext(Dispatchers.Main) {
Snackbar
.make(
binding.getRoot(),
getString(R.string.restore_fail),
Snackbar.LENGTH_INDEFINITE
)

withContext(Dispatchers.Main) {
try {
applyFabricatedColors(requireContext())
} catch (ignored: Exception) {
}
}
} catch (exception: Exception) {
withContext(Dispatchers.Main) {
Snackbar
.make(
binding.getRoot(),
getString(R.string.restore_fail),
Snackbar.LENGTH_INDEFINITE
)
.setAction(getString(R.string.retry)) {
backupRestoreSettings(
false
)
}
.show()

Log.e(TAG, "startBackupActivityIntent: ", exception)
.setAction(getString(R.string.retry)) {
backupRestoreSettings(
false
)
}
}
.show()

Log.e(TAG, "startBackupActivityIntent: ", exception)
}
} finally {
arguments?.remove("data")
}
.setNegativeButton(getString(android.R.string.cancel)) { dialog: DialogInterface, _: Int -> dialog.dismiss() }
.show()
}
}
}
.setNegativeButton(getString(android.R.string.cancel)) { dialog: DialogInterface, _: Int ->
dialog.dismiss();
arguments?.remove("data")
}
.show()
}

@Suppress("DEPRECATION")
@Deprecated("Deprecated in Java")
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/drdisagree/colorblendr/utils/MiscUtil.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.drdisagree.colorblendr.utils

import android.content.Context
import android.content.Intent
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.os.Parcelable
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.appbar.MaterialToolbar
Expand Down Expand Up @@ -57,3 +61,13 @@ object MiscUtil {
return target
}
}

inline fun <reified T : Parcelable> Intent.parcelable(key: String): T? = when {
SDK_INT >= 33 -> getParcelableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T
}

inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? = when {
SDK_INT >= 33 -> getParcelable(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
}

0 comments on commit 604e416

Please sign in to comment.