2022-05-29 16:31:04 +05:30
|
|
|
package com.github.libretube
|
|
|
|
|
|
|
|
import android.content.Intent
|
2022-05-29 18:52:35 +05:30
|
|
|
import android.content.pm.PackageManager
|
|
|
|
import android.net.Uri
|
2022-05-29 16:31:04 +05:30
|
|
|
import android.os.Bundle
|
|
|
|
import android.util.Log
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2022-06-07 13:05:49 +05:30
|
|
|
import com.github.libretube.util.ThemeHelper
|
2022-05-29 16:31:04 +05:30
|
|
|
|
|
|
|
class RouterActivity : AppCompatActivity() {
|
2022-05-29 18:52:35 +05:30
|
|
|
val TAG = "RouterActivity"
|
2022-05-29 16:31:04 +05:30
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2022-06-09 12:58:41 +05:30
|
|
|
if (intent.getStringExtra(Intent.EXTRA_TEXT) != null && checkHost(intent)) {
|
2022-06-01 11:15:02 +05:30
|
|
|
// start the main activity using the given URI as data if the host is known
|
2022-06-09 12:58:41 +05:30
|
|
|
val uri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!)
|
|
|
|
handleSendText(uri)
|
|
|
|
} else if (intent.data != null) {
|
|
|
|
val uri = intent.data
|
|
|
|
handleSendText(uri!!)
|
2022-06-01 11:15:02 +05:30
|
|
|
} else {
|
|
|
|
// start app as normal if URI not in host list
|
2022-06-07 13:05:49 +05:30
|
|
|
ThemeHelper().restartMainActivity(this)
|
2022-05-29 16:31:04 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 17:54:50 +05:30
|
|
|
private fun checkHost(intent: Intent): Boolean {
|
2022-05-30 18:54:44 +05:30
|
|
|
// check whether the host is known, current solution to replace the broken intent filter
|
2022-05-30 17:54:50 +05:30
|
|
|
val hostsList = resources.getStringArray(R.array.shareHostsList)
|
|
|
|
val intentDataUri: Uri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT))
|
|
|
|
val intentDataHost = intentDataUri.host
|
|
|
|
Log.d(TAG, "$intentDataHost")
|
|
|
|
return hostsList.contains(intentDataHost)
|
|
|
|
}
|
|
|
|
|
2022-06-09 12:58:41 +05:30
|
|
|
private fun handleSendText(uri: Uri) {
|
|
|
|
Log.i(TAG, uri.toString())
|
|
|
|
val pm: PackageManager = this.packageManager
|
|
|
|
val intent = pm.getLaunchIntentForPackage(this.packageName)
|
|
|
|
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
|
|
intent?.data = uri
|
|
|
|
this.startActivity(intent)
|
|
|
|
this.finishAndRemoveTask()
|
2022-05-29 16:31:04 +05:30
|
|
|
}
|
2022-05-29 18:52:35 +05:30
|
|
|
}
|