forked from GitHub-Mirror/riotX-android
Show disclaimer at first launch (Fixes #215)
This commit is contained in:
parent
f98f0e1a87
commit
f9c8e4f85a
@ -16,8 +16,15 @@
|
|||||||
|
|
||||||
package im.vector.riotredesign.core.extensions
|
package im.vector.riotredesign.core.extensions
|
||||||
|
|
||||||
|
import android.text.Spannable
|
||||||
|
import android.text.SpannableString
|
||||||
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import im.vector.riotredesign.features.themes.ThemeUtils
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a text in the TextView, or set visibility to GONE if the text is null
|
* Set a text in the TextView, or set visibility to GONE if the text is null
|
||||||
@ -31,3 +38,27 @@ fun TextView.setTextOrHide(newText: String?, hideWhenBlank: Boolean = true) {
|
|||||||
isVisible = true
|
isVisible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set text with a colored part
|
||||||
|
* @param fullTextRes the resource id of the full text. Value MUST contains a parameter for string, which will be replaced by the colored part
|
||||||
|
* @param coloredTextRes the resource id of the colored part of the text
|
||||||
|
* @param colorAttribute attribute of the color
|
||||||
|
*/
|
||||||
|
fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int,
|
||||||
|
@StringRes coloredTextRes: Int,
|
||||||
|
@AttrRes colorAttribute: Int) {
|
||||||
|
val coloredPart = resources.getString(coloredTextRes)
|
||||||
|
// Insert colored part into the full text
|
||||||
|
val fullText = resources.getString(fullTextRes, coloredPart)
|
||||||
|
val color = ThemeUtils.getColor(context, colorAttribute)
|
||||||
|
|
||||||
|
val foregroundSpan = ForegroundColorSpan(color)
|
||||||
|
|
||||||
|
val index = fullText.indexOf(coloredPart)
|
||||||
|
|
||||||
|
text = SpannableString(fullText)
|
||||||
|
.apply {
|
||||||
|
setSpan(foregroundSpan, index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -258,6 +258,20 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) {
|
|||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, mediaUri)
|
sendIntent.putExtra(Intent.EXTRA_STREAM, mediaUri)
|
||||||
|
|
||||||
context.startActivity(sendIntent)
|
context.startActivity(sendIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the play store to the provided application Id, default to this app
|
||||||
|
*/
|
||||||
|
fun openPlayStore(activity: Activity, appId: String = BuildConfig.APPLICATION_ID) {
|
||||||
|
try {
|
||||||
|
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
|
||||||
|
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||||
|
try {
|
||||||
|
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appId")))
|
||||||
|
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||||
|
activity.toast(R.string.error_no_external_application_found)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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.disclaimer
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.preference.PreferenceManager
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import im.vector.riotredesign.BuildConfig
|
||||||
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.core.extensions.setTextWithColoredPart
|
||||||
|
import im.vector.riotredesign.core.utils.openPlayStore
|
||||||
|
|
||||||
|
// Increase this value to show again the disclaimer dialog after an upgrade of the application
|
||||||
|
private const val CURRENT_DISCLAIMER_VALUE = 1
|
||||||
|
|
||||||
|
private const val SHARED_PREF_KEY = "LAST_DISCLAIMER_VERSION_VALUE"
|
||||||
|
|
||||||
|
fun showDisclaimerDialog(activity: Activity) {
|
||||||
|
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
|
|
||||||
|
if (sharedPrefs.getInt(SHARED_PREF_KEY, 0) < CURRENT_DISCLAIMER_VALUE) {
|
||||||
|
sharedPrefs.edit {
|
||||||
|
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
|
||||||
|
}
|
||||||
|
|
||||||
|
val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_disclaimer_content, null)
|
||||||
|
|
||||||
|
val textView = (dialogLayout as ViewGroup).findViewById<TextView>(R.id.dialogDisclaimerContentLine2)
|
||||||
|
@Suppress("ConstantConditionIf")
|
||||||
|
if (BuildConfig.FLAVOR == "gplay") {
|
||||||
|
|
||||||
|
textView.setTextWithColoredPart(
|
||||||
|
R.string.alpha_disclaimer_content_line_2_gplay,
|
||||||
|
R.string.alpha_disclaimer_content_line_2_gplay_colored_part,
|
||||||
|
R.attr.colorAccent
|
||||||
|
)
|
||||||
|
|
||||||
|
textView.setOnClickListener {
|
||||||
|
openPlayStore(activity)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
textView.setText(R.string.alpha_disclaimer_content_line_2_fdroid)
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setView(dialogLayout)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(R.string._continue, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
@ -40,6 +40,7 @@ import im.vector.riotredesign.core.platform.VectorBaseActivity
|
|||||||
import im.vector.riotredesign.core.pushers.PushersManager
|
import im.vector.riotredesign.core.pushers.PushersManager
|
||||||
import im.vector.riotredesign.features.crypto.keysrequest.KeyRequestHandler
|
import im.vector.riotredesign.features.crypto.keysrequest.KeyRequestHandler
|
||||||
import im.vector.riotredesign.features.crypto.verification.IncomingVerificationRequestHandler
|
import im.vector.riotredesign.features.crypto.verification.IncomingVerificationRequestHandler
|
||||||
|
import im.vector.riotredesign.features.disclaimer.showDisclaimerDialog
|
||||||
import im.vector.riotredesign.features.notifications.NotificationDrawerManager
|
import im.vector.riotredesign.features.notifications.NotificationDrawerManager
|
||||||
import im.vector.riotredesign.features.rageshake.BugReporter
|
import im.vector.riotredesign.features.rageshake.BugReporter
|
||||||
import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler
|
import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler
|
||||||
@ -151,6 +152,8 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||||||
.setPositiveButton(R.string.yes) { _, _ -> BugReporter.openBugReportScreen(this) }
|
.setPositiveButton(R.string.yes) { _, _ -> BugReporter.openBugReportScreen(this) }
|
||||||
.setNegativeButton(R.string.no) { _, _ -> BugReporter.deleteCrashFile(this) }
|
.setNegativeButton(R.string.no) { _, _ -> BugReporter.deleteCrashFile(this) }
|
||||||
.show()
|
.show()
|
||||||
|
} else {
|
||||||
|
showDisclaimerDialog(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Force remote backup state update to update the banner if needed
|
//Force remote backup state update to update the banner if needed
|
||||||
|
@ -31,6 +31,7 @@ import im.vector.matrix.android.api.session.sync.FilterService
|
|||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.extensions.showPassword
|
import im.vector.riotredesign.core.extensions.showPassword
|
||||||
import im.vector.riotredesign.core.platform.VectorBaseActivity
|
import im.vector.riotredesign.core.platform.VectorBaseActivity
|
||||||
|
import im.vector.riotredesign.features.disclaimer.showDisclaimerDialog
|
||||||
import im.vector.riotredesign.features.home.HomeActivity
|
import im.vector.riotredesign.features.home.HomeActivity
|
||||||
import im.vector.riotredesign.features.notifications.PushRuleTriggerListener
|
import im.vector.riotredesign.features.notifications.PushRuleTriggerListener
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
@ -57,6 +58,12 @@ class LoginActivity : VectorBaseActivity() {
|
|||||||
homeServerField.setText(DEFAULT_HOME_SERVER_URI)
|
homeServerField.setText(DEFAULT_HOME_SERVER_URI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
showDisclaimerDialog(this)
|
||||||
|
}
|
||||||
|
|
||||||
private fun authenticate() {
|
private fun authenticate() {
|
||||||
passwordShown = false
|
passwordShown = false
|
||||||
renderPasswordField()
|
renderPasswordField()
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="163dp"
|
||||||
|
android:height="127dp"
|
||||||
|
android:viewportWidth="163"
|
||||||
|
android:viewportHeight="127">
|
||||||
|
<path
|
||||||
|
android:pathData="M113.569,169.348C129.753,185.532 153.161,188.363 165.853,175.671C178.545,162.979 175.715,139.57 159.531,123.386C143.347,107.203 44.653,8.372 44.653,8.372L35.819,18.975C35.819,18.975 39.221,27.764 37.204,30.186C35.186,32.608 24.684,32.34 24.684,32.34L6.34,54.358C6.34,54.358 4.89,60.67 6.106,61.885C41.927,97.706 77.748,133.527 113.569,169.348Z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:fillAlpha="0.147508741"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:strokeColor="#00000000"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M19.447,19.068L19.447,27.722L28.202,27.713C28.313,27.713 28.415,27.71 28.515,27.703C30.818,27.551 32.617,25.656 32.617,23.391C32.617,21.007 30.641,19.068 28.211,19.068L19.447,19.068ZM10.788,61.81C6.006,61.81 2.129,58.007 2.129,53.316L2.129,37.127C2.097,36.833 2.08,36.535 2.08,36.232C2.08,35.925 2.096,35.621 2.129,35.322L2.129,10.574C2.129,5.882 6.006,2.079 10.788,2.079L28.211,2.079C40.19,2.079 49.935,11.639 49.935,23.391C49.935,34.563 41.04,43.902 29.684,44.652C29.201,44.685 28.704,44.702 28.211,44.702L19.447,44.71L19.447,53.316C19.447,58.007 15.57,61.81 10.788,61.81L10.788,61.81Z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:fillColor="#A2DDEF"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:strokeColor="#00000000"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M19.447,19.068L19.447,27.722L28.202,27.713C28.313,27.713 28.415,27.71 28.515,27.703C30.818,27.551 32.617,25.656 32.617,23.391C32.617,21.007 30.641,19.068 28.211,19.068L19.447,19.068ZM10.788,61.81C6.006,61.81 2.129,58.007 2.129,53.316L2.129,10.574C2.129,5.882 6.006,2.079 10.788,2.079L28.211,2.079C40.19,2.079 49.935,11.639 49.935,23.391C49.935,34.563 41.04,43.902 29.684,44.652C29.201,44.685 28.704,44.702 28.211,44.702L19.447,44.71L19.447,53.316C19.447,58.007 15.57,61.81 10.788,61.81Z"
|
||||||
|
android:strokeWidth="1.52445396"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#368BD6"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M10.788,53.315L10.788,10.574L28.211,10.574C35.426,10.574 41.276,16.312 41.276,23.39C41.276,30.175 35.902,35.729 29.102,36.178C28.807,36.197 28.51,36.207 28.211,36.207L10.788,36.207"
|
||||||
|
android:strokeWidth="1.52445396"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#368BD6"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:strokeLineCap="round"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M17.923,5.702C19.25,7.56 19.76,9.815 19.358,12.048C18.956,14.283 17.691,16.229 15.795,17.531C11.881,20.217 6.467,19.282 3.726,15.445C2.399,13.587 1.889,11.333 2.291,9.099C2.693,6.864 3.958,4.917 5.854,3.617C9.768,0.93 15.182,1.865 17.923,5.702ZM41.347,61.805C38.618,61.805 35.934,60.543 34.248,58.185L22.011,41.052C19.266,37.21 20.217,31.913 24.133,29.222C28.049,26.528 33.449,27.461 36.193,31.303L48.431,48.435C51.175,52.277 50.225,57.574 46.309,60.266C44.797,61.306 43.063,61.805 41.347,61.805Z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:fillColor="#368BD6"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:strokeColor="#00000000"/>
|
||||||
|
</vector>
|
58
vector/src/main/res/layout/dialog_disclaimer_content.xml
Normal file
58
vector/src/main/res/layout/dialog_disclaimer_content.xml
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<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">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="140dp"
|
||||||
|
android:background="#27303A">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="23dp"
|
||||||
|
android:layout_marginLeft="23dp"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:src="@drawable/disclaimer_top_banner_foreground" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginLeft="24dp"
|
||||||
|
android:layout_marginTop="92dp"
|
||||||
|
android:fontFamily="sans-serif"
|
||||||
|
android:lineSpacingExtra="8sp"
|
||||||
|
android:text="@string/alpha_disclaimer_title"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="normal" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="21dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:text="@string/alpha_disclaimer_content_line_1"
|
||||||
|
android:textColor="?riotx_text_primary"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dialogDisclaimerContentLine2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="21dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:layout_marginBottom="21dp"
|
||||||
|
android:textColor="?riotx_text_primary"
|
||||||
|
android:textSize="16sp"
|
||||||
|
tools:text="@string/alpha_disclaimer_content_line_2_gplay" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -3,6 +3,12 @@
|
|||||||
|
|
||||||
<!-- Strings not defined in Riot -->
|
<!-- Strings not defined in Riot -->
|
||||||
|
|
||||||
|
<string name="alpha_disclaimer_title">Welcome to the beta!</string>
|
||||||
|
<string name="alpha_disclaimer_content_line_1">"While Riot X is in early development, some features may be missing and you may experience bugs."</string>
|
||||||
|
<string name="alpha_disclaimer_content_line_2_gplay">"The latest feature list is always in the %1$s, and if you find bugs please submit a report in the top left menu of Home, and we’ll fix them as quickly as we can."</string>
|
||||||
|
<!-- Must be a substring of value of alpha_disclaimer_content_line_2_gplay -->
|
||||||
|
<string name="alpha_disclaimer_content_line_2_gplay_colored_part">"Play Store description"</string>
|
||||||
|
<string name="alpha_disclaimer_content_line_2_fdroid">"If you find bugs please submit a report in the top left menu of Home, and we’ll fix them as quickly as we can."</string>
|
||||||
|
|
||||||
<string name="import_e2e_keys_from_file">"Import e2e keys from file \"%1$s\"."</string>
|
<string name="import_e2e_keys_from_file">"Import e2e keys from file \"%1$s\"."</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user