Should fix #27
This commit is contained in:
parent
9c9b45aeab
commit
246ec2c3ac
@ -22,7 +22,7 @@ import apps.amine.bou.readerforselfoss.api.mercury.MercuryApi
|
||||
import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent
|
||||
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
|
||||
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
|
||||
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
|
||||
|
||||
class ReaderActivity : DragDismissActivity() {
|
||||
@ -73,12 +73,7 @@ class ReaderActivity : DragDismissActivity() {
|
||||
.into(image)
|
||||
|
||||
shareBtn.setOnClickListener {
|
||||
val sendIntent = Intent()
|
||||
sendIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
sendIntent.action = Intent.ACTION_SEND
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, response.body()!!.url)
|
||||
sendIntent.type = "text/plain"
|
||||
startActivity(Intent.createChooser(sendIntent, getString(R.string.share)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
shareLink(response.body()!!.url, this@ReaderActivity)
|
||||
}
|
||||
|
||||
browserBtn.setOnClickListener {
|
||||
|
@ -2,10 +2,8 @@ package apps.amine.bou.readerforselfoss.adapters
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.support.constraint.ConstraintLayout
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory
|
||||
@ -39,7 +37,9 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
|
||||
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
|
||||
import apps.amine.bou.readerforselfoss.utils.openInBrowser
|
||||
import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
|
||||
class ItemCardAdapter(private val app: Activity,
|
||||
private val items: ArrayList<Item>,
|
||||
@ -221,21 +221,11 @@ class ItemCardAdapter(private val app: Activity,
|
||||
})
|
||||
|
||||
shareBtn.setOnClickListener {
|
||||
val i = items[adapterPosition]
|
||||
val sendIntent = Intent()
|
||||
sendIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
sendIntent.action = Intent.ACTION_SEND
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, i.getLinkDecoded())
|
||||
sendIntent.type = "text/plain"
|
||||
c.startActivity(Intent.createChooser(sendIntent, c.getString(R.string.share)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
shareLink(items[adapterPosition].getLinkDecoded(), c)
|
||||
}
|
||||
|
||||
browserBtn.setOnClickListener {
|
||||
val i = items[adapterPosition]
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent.data = Uri.parse(i.getLinkDecoded())
|
||||
c.startActivity(intent)
|
||||
openInBrowser(items[adapterPosition], c)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,9 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
|
||||
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
|
||||
import apps.amine.bou.readerforselfoss.utils.openInBrowser
|
||||
import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
|
||||
|
||||
class ItemListAdapter(private val app: Activity,
|
||||
@ -229,21 +230,12 @@ class ItemListAdapter(private val app: Activity,
|
||||
})
|
||||
|
||||
shareBtn.setOnClickListener {
|
||||
val i = items[adapterPosition]
|
||||
val sendIntent = Intent()
|
||||
sendIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
sendIntent.action = Intent.ACTION_SEND
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, i.getLinkDecoded())
|
||||
sendIntent.type = "text/plain"
|
||||
c.startActivity(Intent.createChooser(sendIntent, c.getString(R.string.share)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
shareLink(items[adapterPosition].getLinkDecoded(), c)
|
||||
}
|
||||
|
||||
browserBtn.setOnClickListener {
|
||||
val i = items[adapterPosition]
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent.data = Uri.parse(i.getLinkDecoded())
|
||||
c.startActivity(intent)
|
||||
openInBrowser(items[adapterPosition], c)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import okhttp3.HttpUrl
|
||||
|
||||
import apps.amine.bou.readerforselfoss.BuildConfig
|
||||
import apps.amine.bou.readerforselfoss.R
|
||||
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
|
||||
|
||||
fun checkAndDisplayStoreApk(context: Context) = {
|
||||
@ -102,4 +102,26 @@ fun longHash(string: String): Long {
|
||||
h = 31 * h + chars[i].toLong()
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
fun handleLinksWithoutHttp(itemUrl: String) =
|
||||
if (!itemUrl.startsWith("https://") && !itemUrl.startsWith("http://"))
|
||||
"http://" + itemUrl
|
||||
else
|
||||
itemUrl
|
||||
|
||||
fun shareLink(itemUrl: String, c: Context) {
|
||||
val sendIntent = Intent()
|
||||
sendIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
sendIntent.action = Intent.ACTION_SEND
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, handleLinksWithoutHttp(itemUrl))
|
||||
sendIntent.type = "text/plain"
|
||||
c.startActivity(Intent.createChooser(sendIntent, c.getString(R.string.share)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
}
|
||||
|
||||
fun openInBrowser(i: Item, c: Context) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent.data = Uri.parse(handleLinksWithoutHttp(i.getLinkDecoded()))
|
||||
c.startActivity(intent)
|
||||
}
|
Loading…
Reference in New Issue
Block a user