mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Hook up link preview suggestion dialog
This commit is contained in:
parent
05ac781b55
commit
f1745448bb
@ -82,6 +82,7 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
|
|||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||||
import org.thoughtcrime.securesms.giph.ui.GiphyActivity
|
import org.thoughtcrime.securesms.giph.ui.GiphyActivity
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository
|
||||||
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel.LinkPreviewState
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel.LinkPreviewState
|
||||||
import org.thoughtcrime.securesms.loki.utilities.ActivityDispatcher
|
import org.thoughtcrime.securesms.loki.utilities.ActivityDispatcher
|
||||||
@ -98,6 +99,7 @@ import org.thoughtcrime.securesms.permissions.Permissions
|
|||||||
import org.thoughtcrime.securesms.util.DateUtils
|
import org.thoughtcrime.securesms.util.DateUtils
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil
|
import org.thoughtcrime.securesms.util.MediaUtil
|
||||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask
|
||||||
|
import org.w3c.dom.Text
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ExecutionException
|
import java.util.concurrent.ExecutionException
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
@ -402,8 +404,19 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun inputBarEditTextContentChanged(newContent: CharSequence) {
|
override fun inputBarEditTextContentChanged(newContent: CharSequence) {
|
||||||
|
if (TextSecurePreferences.isLinkPreviewsEnabled(this)) {
|
||||||
linkPreviewViewModel?.onTextChanged(this, inputBar.text, 0, 0)
|
linkPreviewViewModel?.onTextChanged(this, inputBar.text, 0, 0)
|
||||||
|
}
|
||||||
showOrHideMentionCandidatesIfNeeded(newContent)
|
showOrHideMentionCandidatesIfNeeded(newContent)
|
||||||
|
if (LinkPreviewUtil.findWhitelistedUrls(newContent.toString()).isNotEmpty()
|
||||||
|
&& !TextSecurePreferences.isLinkPreviewsEnabled(this) && !TextSecurePreferences.hasSeenLinkPreviewSuggestionDialog(this)) {
|
||||||
|
LinkPreviewDialog {
|
||||||
|
setUpLinkPreviewObserver()
|
||||||
|
linkPreviewViewModel?.onEnabled()
|
||||||
|
linkPreviewViewModel?.onTextChanged(this, inputBar.text, 0, 0)
|
||||||
|
}.show(supportFragmentManager, "Link Preview Dialog")
|
||||||
|
TextSecurePreferences.setHasSeenLinkPreviewSuggestionDialog(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showOrHideMentionCandidatesIfNeeded(text: CharSequence) {
|
private fun showOrHideMentionCandidatesIfNeeded(text: CharSequence) {
|
||||||
|
@ -4,11 +4,12 @@ import android.view.LayoutInflater
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import kotlinx.android.synthetic.main.dialog_link_preview.view.*
|
import kotlinx.android.synthetic.main.dialog_link_preview.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
||||||
|
|
||||||
/** Shown the first time the user inputs a URL that could generate a link preview, to
|
/** Shown the first time the user inputs a URL that could generate a link preview, to
|
||||||
* let them know that Session offers the ability to send and receive link previews. */
|
* let them know that Session offers the ability to send and receive link previews. */
|
||||||
class LinkPreviewDialog() : BaseDialog() {
|
class LinkPreviewDialog(private val onEnabled: () -> Unit) : BaseDialog() {
|
||||||
|
|
||||||
override fun setContentView(builder: AlertDialog.Builder) {
|
override fun setContentView(builder: AlertDialog.Builder) {
|
||||||
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_link_preview, null)
|
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_link_preview, null)
|
||||||
@ -18,6 +19,8 @@ class LinkPreviewDialog() : BaseDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun enable() {
|
private fun enable() {
|
||||||
// TODO: Implement
|
TextSecurePreferences.setLinkPreviewsEnabled(requireContext(), true)
|
||||||
|
dismiss()
|
||||||
|
onEnabled()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -103,7 +103,6 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||||||
TextSecurePreferences.setScreenLockTimeout(getContext(), 0);
|
TextSecurePreferences.setScreenLockTimeout(getContext(), 0);
|
||||||
} else {
|
} else {
|
||||||
long timeoutSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
|
long timeoutSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
|
||||||
// long timeoutSeconds = Math.max(TimeUnit.MILLISECONDS.toSeconds(duration), 60);
|
|
||||||
TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds);
|
TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +116,6 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||||||
private class ReadReceiptToggleListener implements Preference.OnPreferenceChangeListener {
|
private class ReadReceiptToggleListener implements Preference.OnPreferenceChangeListener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
boolean enabled = (boolean)newValue;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,21 +136,6 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||||||
private class LinkPreviewToggleListener implements Preference.OnPreferenceChangeListener {
|
private class LinkPreviewToggleListener implements Preference.OnPreferenceChangeListener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
boolean enabled = (boolean)newValue;
|
|
||||||
|
|
||||||
if (enabled) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
|
||||||
builder.setTitle("Enable Link Previews?");
|
|
||||||
builder.setMessage("You will not have full metadata protection when sending or receiving link previews.");
|
|
||||||
builder.setPositiveButton("OK", (dialog, which) -> dialog.dismiss());
|
|
||||||
builder.setNegativeButton("Cancel", (dialog, which) -> {
|
|
||||||
TextSecurePreferences.setLinkPreviewsEnabled(requireContext(), false);
|
|
||||||
((SwitchPreferenceCompat)AppProtectionPreferenceFragment.this.findPreference(TextSecurePreferences.LINK_PREVIEWS)).setChecked(false);
|
|
||||||
dialog.dismiss();
|
|
||||||
});
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -779,4 +779,12 @@ object TextSecurePreferences {
|
|||||||
fun setLastOpenDate(context: Context) {
|
fun setLastOpenDate(context: Context) {
|
||||||
setLongPreference(context, LAST_OPEN_DATE, System.currentTimeMillis())
|
setLongPreference(context, LAST_OPEN_DATE, System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasSeenLinkPreviewSuggestionDialog(context: Context): Boolean {
|
||||||
|
return getBooleanPreference(context, "has_seen_link_preview_suggestion_dialog", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setHasSeenLinkPreviewSuggestionDialog(context: Context) {
|
||||||
|
setBooleanPreference(context, "has_seen_link_preview_suggestion_dialog", true)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user