Import test Activities from Riot

This commit is contained in:
Benoit Marty 2019-06-06 10:28:11 +02:00
parent 8afe31192b
commit 917282303d
17 changed files with 555 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity android:name="im.vector.riotredesign.features.debug.TestLinkifyActivity" />
</application>

</manifest>

View File

@ -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()
)
}
}

View File

@ -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<TextView>(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<TextView>(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))
}
}
}

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="im.vector.riotredesign.features.debug.DebugMenuActivity"
tools:ignore="HardcodedText">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/layout_horizontal_margin">

<Button
android:id="@+id/debug_test_text_view_link"
style="@style/VectorButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test linkification" />

<Button
android:id="@+id/debug_test_notification"
style="@style/VectorButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_vertical_margin"
android:text="Test Notification" />

</LinearLayout>

</ScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/test_linkify_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/riot_secondary_text_color_status"
tools:context="im.vector.riotredesign.features.debug.TestLinkifyActivity">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/test_linkify_content_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<!-- Will be removed at runtime -->
<include layout="@layout/item_test_linkify" />

<include layout="@layout/item_test_linkify" />

<include layout="@layout/item_test_linkify" />

</LinearLayout>

</androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/store_title" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/store_whats_new" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/store_short_description" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/store_full_description" />

</LinearLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
The aim of this file is to test the different themes of Riot
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="HardcodedText">

<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="?colorPrimaryDark"
android:gravity="center_vertical"
android:text="Status Bar" />

<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="?colorPrimary"
android:gravity="center_vertical"
android:text="This is a simple text" />

</LinearLayout>

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
The aim of this file is to test the different themes of Riot
Unfortunately, this does not work in the preview.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:theme="@style/AppTheme.Light">

<include layout="@layout/demo_theme_sample" />

</FrameLayout>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:theme="@style/AppTheme.Dark">

<include layout="@layout/demo_theme_sample" />

</FrameLayout>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:theme="@style/AppTheme.Black">

<include layout="@layout/demo_theme_sample" />

</FrameLayout>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:theme="@style/AppTheme.Status">

<include layout="@layout/demo_theme_sample" />

</FrameLayout>

</LinearLayout>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
tools:ignore="HardcodedText">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
style="@style/ListHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AutoLink" />

<TextView
android:id="@+id/test_linkify_auto_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:autoLink="all"
tools:text="www.example.org" />

<TextView
style="@style/ListHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom Link" />

<TextView
android:id="@+id/test_linkify_custom_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
tools:text="www.example.org" />

</LinearLayout>

</androidx.cardview.widget.CardView>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="VectorDebug">
<item name="android:visibility">visible</item>
</style>

</resources>

View File

@ -46,6 +46,7 @@
<activity android:name=".features.roomdirectory.RoomDirectoryActivity" />
<activity android:name=".features.roomdirectory.roompreview.RoomPreviewActivity" />
<activity android:name=".features.home.room.detail.RoomDetailActivity" />
<activity android:name=".features.debug.DebugMenuActivity" />

<service
android:name=".core.services.CallService"

View File

@ -56,5 +56,10 @@ class HomeDrawerFragment : VectorBaseFragment() {
homeDrawerHeaderSettingsView.setOnClickListener {
navigator.openSettings()
}

// Debug menu
homeDrawerHeaderDebugView.setOnClickListener {
navigator.openDebug()
}
}
}

View File

@ -20,6 +20,7 @@ import android.app.Activity
import android.content.Intent
import androidx.fragment.app.Fragment
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
import im.vector.riotredesign.features.debug.DebugMenuActivity
import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity
@ -50,4 +51,8 @@ class DefaultNavigator(private val fraqment: Fragment) : Navigator {
val intent = VectorSettingsActivity.getIntent(activity, "TODO")
activity.startActivity(intent)
}

override fun openDebug() {
activity.startActivity(Intent(activity, DebugMenuActivity::class.java))
}
}

View File

@ -28,4 +28,6 @@ interface Navigator {

fun openSettings()

fun openDebug()

}

View File

@ -16,6 +16,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/homeDrawerHeaderDebugView"
style="@style/VectorDebug"
android:layout_width="@dimen/layout_touch_size"
android:layout_height="@dimen/layout_touch_size"
android:scaleType="center"
android:src="@drawable/ic_settings_x"
android:tint="@color/riotx_accent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/homeDrawerHeaderAvatarView"
android:layout_width="64dp"

View File

@ -0,0 +1,22 @@
/*
* 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 androidx.appcompat.app.AppCompatActivity

// This activity is not accessible
class DebugMenuActivity : AppCompatActivity()

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="VectorDebug">
<item name="android:visibility">gone</item>
</style>

</resources>