Improve: Better Share menu

This commit is contained in:
LooKeR 2021-12-24 12:36:41 +05:30
parent 2899217422
commit dbd43b1a2b

View File

@ -37,10 +37,11 @@ import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.util.*
import kotlin.collections.ArrayList
class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks { class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
companion object { companion object {
@ -456,15 +457,7 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
} else Unit } else Unit
} }
AppDetailAdapter.Action.SHARE -> { AppDetailAdapter.Action.SHARE -> {
val sendIntent: Intent = Intent().apply { shareIntent(packageName, products[0].first.name)
this.action = Intent.ACTION_SEND
putExtra(
Intent.EXTRA_TEXT,
"https://www.f-droid.org/packages/${products[0].first.packageName}/"
)
type = "text/plain"
}
startActivity(Intent.createChooser(sendIntent, null))
} }
}::class }::class
} }
@ -482,6 +475,21 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
} }
} }
private fun shareIntent(packageName: String, appName: String) {
val shareIntent = Intent(Intent.ACTION_SEND)
val extraText = if (Android.sdk(24)) {
"https://www.f-droid.org/${resources.configuration.locales[0].language}/packages/${packageName}/"
} else "https://www.f-droid.org/${resources.configuration.locale.language}/packages/${packageName}/"
shareIntent.type = "text/plain"
shareIntent.putExtra(Intent.EXTRA_TITLE, appName)
shareIntent.putExtra(Intent.EXTRA_SUBJECT, appName)
shareIntent.putExtra(Intent.EXTRA_TEXT, extraText)
startActivity(Intent.createChooser(shareIntent, "Where to Send?"))
}
override fun onPreferenceChanged(preference: ProductPreference) { override fun onPreferenceChanged(preference: ProductPreference) {
lifecycleScope.launch { updateButtons(preference) } lifecycleScope.launch { updateButtons(preference) }
} }