Various fixes and changes

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-12-17 20:59:05 +01:00
parent a7233ebd7f
commit 32e6752486
9 changed files with 209 additions and 90 deletions

View File

@ -112,7 +112,7 @@ dependencies {
debugImplementation "javax.transaction:transaction-api:1.1-rev-1"
implementation 'com.github.HITGIF:TextFieldBoxes:1.3.4'
implementation 'com.github.HITGIF:TextFieldBoxes:1.3.7'
implementation 'eu.davidea:flexible-adapter:5.0.0-rc3'

View File

@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
tools:replace="label, icon, theme, name, allowBackup"
@ -45,7 +46,6 @@
android:configChanges="orientation|screenSize"
/>
<service
android:name=".services.firebase.MagicFirebaseMessagingService">
<intent-filter>

View File

@ -20,9 +20,13 @@
*/
package com.nextcloud.talk.application;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.support.v7.widget.AppCompatDrawableManager;
import android.util.Log;
import com.evernote.android.job.JobManager;
import com.evernote.android.job.JobRequest;
@ -39,6 +43,9 @@ import com.nextcloud.talk.utils.database.user.UserModule;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.GeneralSecurityException;
import javax.inject.Singleton;
@ -76,6 +83,32 @@ public class NextcloudTalkApplication extends MultiDexApplication {
}
//endregion
//region private methods
// Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected
private void useCompatVectorIfNeeded() {
int sdkInt = Build.VERSION.SDK_INT;
if (sdkInt == 21 || sdkInt == 22) {
try {
@SuppressLint("RestrictedApi") AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
Class<?> inflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$InflateDelegate");
Class<?> vdcInflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate");
Constructor<?> constructor = vdcInflateDelegateClass.getDeclaredConstructor();
constructor.setAccessible(true);
Object vdcInflateDelegate = constructor.newInstance();
Class<?> args[] = {String.class, inflateDelegateClass};
Method addDelegate = AppCompatDrawableManager.class.getDeclaredMethod("addDelegate", args);
addDelegate.setAccessible(true);
addDelegate.invoke(drawableManager, "vector", vdcInflateDelegate);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
InvocationTargetException | IllegalAccessException e) {
Log.d(TAG, "Failed to use reflection to enable proper vector scaling");
}
}
}
//endregion
//region Overridden methods
@Override
public void onCreate() {
@ -84,6 +117,8 @@ public class NextcloudTalkApplication extends MultiDexApplication {
FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(false);
sharedApplication = this;
useCompatVectorIfNeeded();
try {
buildComponent();

View File

@ -22,6 +22,9 @@ package com.nextcloud.talk.controllers;
import android.content.pm.ActivityInfo;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -84,17 +87,54 @@ public class ServerSelectionController extends BaseController {
getActionBar().hide();
}
textFieldBoxes.setLabelText(getResources().getString(R.string.nc_app_name) + " " + getResources().getString(R.string.nc_appended_server_url));
textFieldBoxes.setLabelText(getResources().getString(R.string.nc_server_url));
textFieldBoxes.getEndIconImageButton().setBackgroundDrawable(getResources().getDrawable(R.drawable
.ic_arrow_forward_white_24px));
textFieldBoxes.getEndIconImageButton().setAlpha(0.5f);
textFieldBoxes.getEndIconImageButton().setEnabled(false);
textFieldBoxes.getEndIconImageButton().setVisibility(View.VISIBLE);
textFieldBoxes.getEndIconImageButton().setOnClickListener(view1 -> checkServerAndProceed());
serverEntry.requestFocus();
serverEntry.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (!textFieldBoxes.isOnError() && !TextUtils.isEmpty(serverEntry.getText())) {
textFieldBoxes.getEndIconImageButton().setEnabled(true);
textFieldBoxes.getEndIconImageButton().setAlpha(1f);
} else {
textFieldBoxes.getEndIconImageButton().setEnabled(false);
textFieldBoxes.getEndIconImageButton().setAlpha(0.5f);
}
}
});
serverEntry.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
checkServerAndProceed();
}
return false;
});
}
private void checkServerAndProceed() {
dispose();
String url = serverEntry.getText().toString().trim();
if (url.startsWith("http://") || url.startsWith("https://")) {
serverEntry.setEnabled(false);
progressBar.setVisibility(View.VISIBLE);
@ -103,8 +143,15 @@ public class ServerSelectionController extends BaseController {
}
String queryUrl = url + ApiHelper.getUrlPostfixForStatus();
final String finalServerUrl = url;
if (url.startsWith("http://") || url.startsWith("https://")) {
checkServer(queryUrl, false);
} else {
checkServer("https://" + queryUrl, true);
}
}
private void checkServer(String queryUrl, boolean checkForcedHttps) {
statusQueryDisposable = ncApi.getServerStatus(queryUrl)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
@ -116,7 +163,8 @@ public class ServerSelectionController extends BaseController {
status.getVersion().startsWith("13.")) {
getRouter().pushController(RouterTransaction.with(
new WebViewLoginController(finalServerUrl, false))
new WebViewLoginController(queryUrl.replace("/status.php", ""),
false))
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} else if (!status.isInstalled()) {
@ -140,33 +188,27 @@ public class ServerSelectionController extends BaseController {
}
}, throwable -> {
if (checkForcedHttps && (throwable instanceof Exception)) {
checkServer(queryUrl.replace("https://", "http://"), false);
} else {
if (throwable.getLocalizedMessage() != null) {
textFieldBoxes.setError(throwable.getLocalizedMessage(), true);
} else if (throwable.getCause() instanceof CertificateException) {
textFieldBoxes.setError(getResources().getString(R.string.nc_certificate_error),
true);
}
if (serverEntry != null) {
serverEntry.setEnabled(true);
}
progressBar.setVisibility(View.GONE);
dispose();
}
}, () -> {
progressBar.setVisibility(View.GONE);
dispose();
});
} else {
textFieldBoxes.setError(getResources().getString(R.string.nc_server_url_prefix), true);
serverEntry.setEnabled(true);
return true;
}
}
return false;
});
}
@Override

View File

@ -245,7 +245,7 @@ public class WebViewLoginController extends BaseController {
// We use the URL user entered because one provided by the server is NOT reliable
ErrorMessageHolder.ErrorMessageType finalErrorMessageType = errorMessageType;
userQueryDisposable = userUtils.createOrUpdateUser(loginData.getUsername(), loginData.getToken(),
baseUrl, null, null, true).
loginData.getServerUrl(), null, null, true).
subscribe(userEntity -> {
cookieManager.getCookieStore().removeAll();
if (!isPasswordUpdate && finalErrorMessageType == null) {

View File

@ -20,6 +20,19 @@
package com.nextcloud.talk.utils;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
public class ColorUtils {
public static String colorSeed = "ballast butte permute doxy graham rummage grateful songbook pledge escapade";
public static Drawable getTintedDrawable(Resources res, @DrawableRes int drawableResId, @ColorRes int colorResId) {
Drawable drawable = res.getDrawable(drawableResId);
int color = res.getColor(colorResId);
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
return drawable;
}
}

View File

@ -0,0 +1,25 @@
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
</vector>

View File

@ -23,7 +23,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
android:background="@color/colorPrimary"
android:fitsSystemWindows="true">
<ImageView
android:layout_width="96dp"
@ -31,29 +32,31 @@
android:layout_above="@id/text_field_boxes"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp"
android:background="@drawable/ic_logo"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_logo"
/>
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:id="@+id/text_field_boxes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_centerInParent="true"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
app:errorColor="@color/nc_white_color_complete"
app:helperText=" "
app:primaryColor="@color/nc_white_color_complete"
>
app:panelBackgroundColor="@color/colorPrimary"
app:primaryColor="@color/nc_white_color_complete">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/extended_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="textUri"
android:textSize="12sp"
android:minWidth="5dp"
android:singleLine="true"
android:textColor="@color/nc_white_color_complete"/>
@ -65,14 +68,15 @@
android:layout_width="@dimen/small_item_height"
android:layout_height="@dimen/small_item_height"
android:layout_below="@id/text_field_boxes"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/padding_between_elements"
android:layout_marginTop="24dp"
android:indeterminate="true"
android:progressTint="@color/nc_white_color"
android:progressDrawable="@color/nc_white_color_complete"
android:progressTint="@color/nc_white_color_complete"
android:visibility="invisible"/>
</RelativeLayout>

View File

@ -5,7 +5,7 @@
<string name="nc_bottom_navigation_title_settings">Settings</string>
<!-- Server selection -->
<string name="nc_appended_server_url">server address</string>
<string name="nc_server_url">Server address</string>
<string name="nc_server_url_prefix">Please enter http:// or https:// before the hostname</string>
<string name="nc_server_not_installed">Please finish your %1$s installation</string>
<string name="nc_server_db_upgrade_needed">Please upgrade your %1$s database</string>