From 917282303dac3c67de31f7a4f1bbc0a24f9a094e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 6 Jun 2019 10:28:11 +0200 Subject: [PATCH] Import test Activities from Riot --- vector/src/debug/AndroidManifest.xml | 8 ++ .../features/debug/DebugMenuActivity.kt | 126 +++++++++++++++++ .../features/debug/TestLinkifyActivity.kt | 133 ++++++++++++++++++ .../debug/res/layout/activity_debug_menu.xml | 39 +++++ .../res/layout/activity_test_linkify.xml | 31 ++++ .../debug/res/layout/demo_store_listing.xml | 31 ++++ .../debug/res/layout/demo_theme_sample.xml | 28 ++++ vector/src/debug/res/layout/demo_themes.xml | 54 +++++++ .../debug/res/layout/item_test_linkify.xml | 43 ++++++ vector/src/debug/res/values/styles.xml | 8 ++ vector/src/main/AndroidManifest.xml | 1 + .../features/home/HomeDrawerFragment.kt | 5 + .../features/navigation/DefaultNavigator.kt | 5 + .../features/navigation/Navigator.kt | 2 + .../main/res/layout/fragment_home_drawer.xml | 11 ++ .../features/debug/DebugMenuActivity.kt | 22 +++ vector/src/release/res/values/styles.xml | 8 ++ 17 files changed, 555 insertions(+) create mode 100644 vector/src/debug/AndroidManifest.xml create mode 100644 vector/src/debug/java/im/vector/riotredesign/features/debug/DebugMenuActivity.kt create mode 100644 vector/src/debug/java/im/vector/riotredesign/features/debug/TestLinkifyActivity.kt create mode 100644 vector/src/debug/res/layout/activity_debug_menu.xml create mode 100644 vector/src/debug/res/layout/activity_test_linkify.xml create mode 100644 vector/src/debug/res/layout/demo_store_listing.xml create mode 100644 vector/src/debug/res/layout/demo_theme_sample.xml create mode 100644 vector/src/debug/res/layout/demo_themes.xml create mode 100644 vector/src/debug/res/layout/item_test_linkify.xml create mode 100644 vector/src/debug/res/values/styles.xml create mode 100644 vector/src/release/java/im/vector/riotredesign/features/debug/DebugMenuActivity.kt create mode 100644 vector/src/release/res/values/styles.xml diff --git a/vector/src/debug/AndroidManifest.xml b/vector/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..e8c44a87 --- /dev/null +++ b/vector/src/debug/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/vector/src/debug/java/im/vector/riotredesign/features/debug/DebugMenuActivity.kt b/vector/src/debug/java/im/vector/riotredesign/features/debug/DebugMenuActivity.kt new file mode 100644 index 00000000..71185006 --- /dev/null +++ b/vector/src/debug/java/im/vector/riotredesign/features/debug/DebugMenuActivity.kt @@ -0,0 +1,126 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotredesign.features.debug + +import android.app.NotificationChannel +import android.app.NotificationManager +import android.content.Context +import android.content.Intent +import android.os.Build +import androidx.core.app.NotificationCompat +import androidx.core.app.Person +import butterknife.OnClick +import im.vector.riotredesign.R +import im.vector.riotredesign.core.platform.VectorBaseActivity + + +class DebugMenuActivity : VectorBaseActivity() { + + override fun getLayoutRes() = R.layout.activity_debug_menu + + @OnClick(R.id.debug_test_text_view_link) + fun testTextViewLink() { + startActivity(Intent(this, TestLinkifyActivity::class.java)) + } + + @OnClick(R.id.debug_test_notification) + fun testNotification() { + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + // Create channel first + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val channel = + NotificationChannel( + "CHAN", + "Channel name", + NotificationManager.IMPORTANCE_DEFAULT + ) + + channel.description = "Channel description" + (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(channel) + + val channel2 = + NotificationChannel( + "CHAN2", + "Channel name 2", + NotificationManager.IMPORTANCE_DEFAULT + ) + + channel2.description = "Channel description 2" + (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(channel2) + } + + + val builder = NotificationCompat.Builder(this, "CHAN") + .setWhen(System.currentTimeMillis()) + .setContentTitle("Title") + .setContentText("Content") + // No effect because it's a group summary notif + .setNumber(33) + .setSmallIcon(R.drawable.logo_transparent) + // This provocate the badge issue: no badge for group notification + .setGroup("GroupKey") + .setGroupSummary(true) + + val messagingStyle1 = NotificationCompat.MessagingStyle( + Person.Builder() + .setName("User name") + .build() + ) + .addMessage("Message 1 - 1", System.currentTimeMillis(), Person.Builder().setName("user 1-1").build()) + .addMessage("Message 1 - 2", System.currentTimeMillis(), Person.Builder().setName("user 1-2").build()) + + val messagingStyle2 = NotificationCompat.MessagingStyle( + Person.Builder() + .setName("User name 2") + .build() + ) + .addMessage("Message 2 - 1", System.currentTimeMillis(), Person.Builder().setName("user 1-1").build()) + .addMessage("Message 2 - 2", System.currentTimeMillis(), Person.Builder().setName("user 1-2").build()) + + + notificationManager.notify(10, builder.build()) + + notificationManager.notify( + 11, + NotificationCompat.Builder(this, "CHAN") + .setChannelId("CHAN") + .setWhen(System.currentTimeMillis()) + .setContentTitle("Title 1") + .setContentText("Content 1") + // For shortcut on long press on launcher icon + .setBadgeIconType(NotificationCompat.BADGE_ICON_NONE) + .setStyle(messagingStyle1) + .setSmallIcon(R.drawable.logo_transparent) + .setGroup("GroupKey") + .build() + ) + + notificationManager.notify( + 12, + NotificationCompat.Builder(this, "CHAN2") + .setWhen(System.currentTimeMillis()) + .setContentTitle("Title 2") + .setContentText("Content 2") + .setStyle(messagingStyle2) + .setSmallIcon(R.drawable.logo_transparent) + .setGroup("GroupKey") + .build() + ) + } +} + diff --git a/vector/src/debug/java/im/vector/riotredesign/features/debug/TestLinkifyActivity.kt b/vector/src/debug/java/im/vector/riotredesign/features/debug/TestLinkifyActivity.kt new file mode 100644 index 00000000..7e37c319 --- /dev/null +++ b/vector/src/debug/java/im/vector/riotredesign/features/debug/TestLinkifyActivity.kt @@ -0,0 +1,133 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotredesign.features.debug + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.coordinatorlayout.widget.CoordinatorLayout +import butterknife.BindView +import butterknife.ButterKnife +import im.vector.riotredesign.R + + +class TestLinkifyActivity : AppCompatActivity() { + + @BindView(R.id.test_linkify_content_view) + lateinit var scrollContent: LinearLayout + + @BindView(R.id.test_linkify_coordinator) + lateinit var coordinatorLayout: CoordinatorLayout + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_test_linkify) + ButterKnife.bind(this) + + scrollContent.removeAllViews() + + listOf( + "https://www.html5rocks.com/en/tutorials/webrtc/basics/ |", + "https://www.html5rocks.com/en/tutorials/webrtc/basics/", + "mailto mailto:test@toto.com test@toto.com", + "Here is the link.www.test.com/foo/?23=35 you got it?", + "www.lemonde.fr", + " /www.lemonde.fr", + "://www.lemonde.fr", + "file:///dev/null ", + " ansible/xoxys.matrix#2c0b65eb", + "foo.ansible/xoxys.matrix#2c0b65eb", + "foo.ansible.fpo/xoxys.matrix#2c0b65eb", + "https://foo.ansible.fpo/xoxys.matrix#2c0b65eb", + "@vf:matrix.org", + "+44 207 123 1234", + "+33141437940", + "1234", + "3456.34,089", + "ksks9808", + "For example: geo:48.85828,2.29449?z=16 should be clickable", + "geo:37.786971,-122.399677;u=35", + "37.786971,-122.399677;u=35", + "48.107864,-1.712153", + "synchrone peut tenir la route la", + "that.is.some.sexy.link", + "test overlap 48.107864,0673728392 geo + pn?", + "test overlap 0673728392,48.107864 geo + pn?", + "If I add a link in brackets like (help for Riot: https://about.riot.im/help), the link is usable on Riot for Desktop", + "(help for Riot: https://about.riot.im/help)", + "http://example.com/test(1).html", + "http://example.com/test(1)", + "https://about.riot.im/help)", + "(http://example.com/test(1))", + "http://example.com/test1)", + "http://example.com/test1/, et ca", + "www.example.com/, et ca", + "foo.ansible.toplevel/xoxys.matrix#2c0b65eb", + "foo.ansible.ninja/xoxys.matrix#2c0b65eb", + "in brackets like (help for Riot: https://www.exemple/com/find(1)) , the link is usable ", + """ + In brackets like (help for Riot: https://about.riot.im/help) , the link is usable, + But you can call +44 207 123 1234 and come to 37.786971,-122.399677;u=35 then + see if this mail jhon@riot.im is active but this should not 12345 + """.trimIndent() + ) + .forEach { textContent -> + val item = LayoutInflater.from(this) + .inflate(R.layout.item_test_linkify, scrollContent, false) + + item.findViewById(R.id.test_linkify_auto_text) + ?.apply { + text = textContent + /* TODO Use BetterLinkMovementMethod when the other PR is merged + movementMethod = MatrixLinkMovementMethod(object : MockMessageAdapterActionListener() { + override fun onURLClick(uri: Uri?) { + Snackbar.make(coordinatorLayout, "URI Clicked: $uri", Snackbar.LENGTH_LONG) + .setAction("open") { + openUrlInExternalBrowser(this@TestLinkifyActivity, uri) + } + .show() + } + }) + */ + } + + item.findViewById(R.id.test_linkify_custom_text) + ?.apply { + text = textContent + /* TODO Use BetterLinkMovementMethod when the other PR is merged + movementMethod = MatrixLinkMovementMethod(object : MockMessageAdapterActionListener() { + override fun onURLClick(uri: Uri?) { + Snackbar.make(coordinatorLayout, "URI Clicked: $uri", Snackbar.LENGTH_LONG) + .setAction("open") { + openUrlInExternalBrowser(this@TestLinkifyActivity, uri) + } + .show() + } + }) + */ + + // TODO Call VectorLinkify.addLinks(text) + } + + scrollContent.addView(item, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) + } + } +} diff --git a/vector/src/debug/res/layout/activity_debug_menu.xml b/vector/src/debug/res/layout/activity_debug_menu.xml new file mode 100644 index 00000000..a6f95ab1 --- /dev/null +++ b/vector/src/debug/res/layout/activity_debug_menu.xml @@ -0,0 +1,39 @@ + + + + + + + +