Merge pull request #1215 from nextcloud/bugfix/noid/add-server-version-warning

Add a warning when the server version is (almost) EOL
This commit is contained in:
Andy Scherzinger 2021-05-05 16:05:35 +02:00 committed by GitHub
commit 067af733c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 136 additions and 4 deletions

View File

@ -270,6 +270,11 @@ public class ConversationsListController extends BaseController implements Searc
currentUser = userUtils.getCurrentUser(); currentUser = userUtils.getCurrentUser();
if (currentUser != null) { if (currentUser != null) {
if (currentUser.isServerEOL()) {
showServerEOLDialog();
return;
}
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()); credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
shouldUseLastMessageLayout = currentUser.hasSpreedFeatureCapability("last-room-activity"); shouldUseLastMessageLayout = currentUser.hasSpreedFeatureCapability("last-room-activity");
if (getActivity() != null && getActivity() instanceof MainActivity) { if (getActivity() != null && getActivity() instanceof MainActivity) {
@ -863,6 +868,50 @@ public class ConversationsListController extends BaseController implements Searc
} }
} }
private void showServerEOLDialog() {
new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL)
.setTopColorRes(R.color.nc_darkRed)
.setIcon(DisplayUtils.getTintedDrawable(context.getResources(),
R.drawable.ic_warning_white,
R.color.bg_default))
.setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed))
.setCancelable(false)
.setTitle(R.string.nc_settings_server_eol_title)
.setMessage(R.string.nc_settings_server_eol)
.setPositiveButton(R.string.nc_settings_remove_account, new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(currentUser.getId());
OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build();
WorkManager.getInstance().enqueue(accountRemovalWork);
if (otherUserExists && getView() != null) {
onViewBound(getView());
onAttach(getView());
} else if (!otherUserExists) {
getRouter().setRoot(RouterTransaction.with(
new ServerSelectionController())
.pushChangeHandler(new VerticalChangeHandler())
.popChangeHandler(new VerticalChangeHandler()));
}
}
})
.setNegativeButton(R.string.nc_cancel, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (userUtils.hasMultipleUsers()) {
getRouter().pushController(RouterTransaction.with(new SwitchAccountController()));
} else {
getActivity().finishAffinity();
getActivity().finish();
}
}
})
.setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler)
.show();
}
private void deleteConversation(Data data) { private void deleteConversation(Data data) {
OneTimeWorkRequest deleteConversationWorker = OneTimeWorkRequest deleteConversationWorker =
new OneTimeWorkRequest.Builder(DeleteConversationWorker.class).setInputData(data).build(); new OneTimeWorkRequest.Builder(DeleteConversationWorker.class).setInputData(data).build();

View File

@ -29,6 +29,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -45,6 +46,7 @@ import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.Checkable; import android.widget.Checkable;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
@ -56,6 +58,7 @@ import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler; import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.bluelinelabs.logansquare.LoganSquare; import com.bluelinelabs.logansquare.LoganSquare;
import com.facebook.drawee.view.SimpleDraweeView; import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import com.nextcloud.talk.BuildConfig; import com.nextcloud.talk.BuildConfig;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
@ -103,6 +106,7 @@ import javax.inject.Inject;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.emoji.widget.EmojiTextView; import androidx.emoji.widget.EmojiTextView;
import androidx.work.OneTimeWorkRequest; import androidx.work.OneTimeWorkRequest;
@ -144,6 +148,12 @@ public class SettingsController extends BaseController {
EmojiTextView displayNameTextView; EmojiTextView displayNameTextView;
@BindView(R.id.base_url_text) @BindView(R.id.base_url_text)
TextView baseUrlTextView; TextView baseUrlTextView;
@BindView(R.id.server_age_warning_text_card)
MaterialCardView serverAgeCardView;
@BindView(R.id.server_age_warning_text)
TextView serverAgeTextView;
@BindView(R.id.server_age_warning_icon)
ImageView serverAgeIcon;
@BindView(R.id.settings_call_sound) @BindView(R.id.settings_call_sound)
MaterialStandardPreference settingsCallSound; MaterialStandardPreference settingsCallSound;
@BindView(R.id.settings_message_sound) @BindView(R.id.settings_message_sound)
@ -551,6 +561,20 @@ public class SettingsController extends BaseController {
baseUrlTextView.setText(Uri.parse(currentUser.getBaseUrl()).getHost()); baseUrlTextView.setText(Uri.parse(currentUser.getBaseUrl()).getHost());
if (currentUser.isServerEOL()) {
serverAgeTextView.setTextColor(ContextCompat.getColor(context, R.color.nc_darkRed));
serverAgeTextView.setText(R.string.nc_settings_server_eol);
serverAgeIcon.setColorFilter(ContextCompat.getColor(context, R.color.nc_darkRed),
PorterDuff.Mode.SRC_IN);
} else if (currentUser.isServerAlmostEOL()) {
serverAgeTextView.setTextColor(ContextCompat.getColor(context, R.color.nc_darkYellow));
serverAgeTextView.setText(R.string.nc_settings_server_almost_eol);
serverAgeIcon.setColorFilter(ContextCompat.getColor(context, R.color.nc_darkYellow),
PorterDuff.Mode.SRC_IN);
} else {
serverAgeCardView.setVisibility(View.GONE);
}
reauthorizeButton.addPreferenceClickListener(view14 -> { reauthorizeButton.addPreferenceClickListener(view14 -> {
getRouter().pushController(RouterTransaction.with( getRouter().pushController(RouterTransaction.with(
new WebViewLoginController(currentUser.getBaseUrl(), true)) new WebViewLoginController(currentUser.getBaseUrl(), true))

View File

@ -92,6 +92,16 @@ public interface User extends Parcelable, Persistable, Serializable {
return false; return false;
} }
default boolean isServerEOL() {
// Capability is available since Talk 4 => Nextcloud 14 => Autmn 2018
return !hasSpreedFeatureCapability("no-ping");
}
default boolean isServerAlmostEOL() {
// Capability is available since Talk 8 => Nextcloud 18 => January 2020
return !hasSpreedFeatureCapability("chat-replies");
}
default boolean hasSpreedFeatureCapability(String capabilityName) { default boolean hasSpreedFeatureCapability(String capabilityName) {
if (getCapabilities() != null) { if (getCapabilities() != null) {
try { try {

View File

@ -48,6 +48,11 @@ public class UserUtils {
.limit(1).get().value() > 0); .limit(1).get().value() > 0);
} }
public boolean hasMultipleUsers() {
return (dataStore.count(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE))
.get().value() > 1);
}
public List getUsers() { public List getUsers() {
Result findUsersQueryResult = dataStore.select(User.class).where Result findUsersQueryResult = dataStore.select(User.class).where
(UserEntity.SCHEDULED_FOR_DELETION.notEqual(true)).get(); (UserEntity.SCHEDULED_FOR_DELETION.notEqual(true)).get();

View File

@ -22,6 +22,7 @@
<com.yarolegovich.mp.MaterialPreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <com.yarolegovich.mp.MaterialPreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:apc="http://schemas.android.com/apk/res-auto" xmlns:apc="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_screen" android:id="@+id/settings_screen"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -71,7 +72,46 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_margin="4dp" android:layout_margin="4dp"
android:textColor="@color/medium_emphasis_text" android:textColor="@color/medium_emphasis_text"
tools:text="jane@nextcloud.com" /> tools:text="nextcloud.com" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/server_age_warning_text_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/base_url_text"
android:layout_margin="@dimen/standard_margin"
app:cardCornerRadius="8dp"
app:cardElevation="2dp"
app:strokeWidth="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/standard_padding">
<ImageView
android:id="@+id/server_age_warning_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_warning_white"
android:layout_centerVertical="true"
app:tint="@color/nc_darkRed"
android:contentDescription="@string/nc_settings_warning" />
<TextView
android:id="@+id/server_age_warning_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/server_age_warning_icon"
android:paddingStart="@dimen/standard_padding"
android:paddingEnd="0dp"
android:layout_centerHorizontal="true"
android:textColor="@color/nc_darkRed"
tools:text="@string/nc_settings_server_almost_eol" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<com.facebook.drawee.view.SimpleDraweeView <com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/avatar_image" android:id="@+id/avatar_image"
@ -82,12 +122,11 @@
apc:roundAsCircle="true" apc:roundAsCircle="true"
tools:src="@tools:sample/avatars[0]" /> tools:src="@tools:sample/avatars[0]" />
<com.yarolegovich.mp.MaterialStandardPreference <com.yarolegovich.mp.MaterialStandardPreference
android:id="@+id/settings_switch" android:id="@+id/settings_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/base_url_text" android:layout_below="@id/server_age_warning_text_card"
android:tag="switchAccountButton" android:tag="switchAccountButton"
apc:mp_title="@string/nc_settings_switch_account" /> apc:mp_title="@string/nc_settings_switch_account" />

View File

@ -50,6 +50,7 @@
<color name="conversation_unread_bubble_text">#222222</color> <color name="conversation_unread_bubble_text">#222222</color>
<color name="nc_darkRed">#D32F2F</color> <color name="nc_darkRed">#D32F2F</color>
<color name="nc_darkYellow">#FF9800</color>
<color name="nc_darkGreen">#006400</color> <color name="nc_darkGreen">#006400</color>
<color name="controller_chat_separator">#E8E8E8</color> <color name="controller_chat_separator">#E8E8E8</color>
<color name="grey_600">#757575</color> <color name="grey_600">#757575</color>

View File

@ -85,6 +85,10 @@
<string name="nc_settings_remove_confirmation">Please confirm your intent to remove the current account.</string> <string name="nc_settings_remove_confirmation">Please confirm your intent to remove the current account.</string>
<string name="nc_settings_remove_account">Remove account</string> <string name="nc_settings_remove_account">Remove account</string>
<string name="nc_settings_add_account">Add a new account</string> <string name="nc_settings_add_account">Add a new account</string>
<string name="nc_settings_server_eol_title">Unsupported server</string>
<string name="nc_settings_server_eol">The server version is too old and not supported by this version of the Android app</string>
<string name="nc_settings_server_almost_eol">The server version is very old and will not be supported in the next release!</string>
<string name="nc_settings_warning">Warning</string>
<string name="nc_add">Add</string> <string name="nc_add">Add</string>
<string name="nc_settings_wrong_account">Only current account can be reauthorized</string> <string name="nc_settings_wrong_account">Only current account can be reauthorized</string>
<string name="nc_settings_no_talk_installed">Talk app is not installed on the server you tried to authenticate against</string> <string name="nc_settings_no_talk_installed">Talk app is not installed on the server you tried to authenticate against</string>

View File

@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 3 errors and 346 warnings</span> <span class="mdl-layout-title">Lint Report: 3 errors and 348 warnings</span>