More work on #40

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-01-25 09:23:11 +01:00
parent b4fa5014bd
commit e461a0c28a
10 changed files with 297 additions and 49 deletions

View File

@ -44,7 +44,6 @@ import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import retrofit2.http.Url;
@ -95,9 +94,10 @@ public interface NcApi {
Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
*/
@FormUrlEncoded
@PUT
Observable<Void> renameRoom(@Header("Authorization") String authorization, @Url String url,
@QueryMap Map<String, String> options);
Observable<GenericOverall> renameRoom(@Header("Authorization") String authorization, @Url String url,
@Field("roomName") String roomName);
/*
@ -242,8 +242,9 @@ public interface NcApi {
@Url String url,
@QueryMap Map<String, String> fields);
@FormUrlEncoded
@PUT
Observable<GenericOverall> setPassword(@Header("Authorization") String authorization, @Url String url,
@Query("password") String password);
@Field("password") String password);
}

View File

@ -82,19 +82,6 @@ public class ApiHelper {
return retrofitBucket;
}
public static RetrofitBucket getRetrofitBucketForRenameRoom(String baseUrl, String token, String newRoomName) {
RetrofitBucket retrofitBucket = new RetrofitBucket();
retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token);
Map<String, String> queryMap = new HashMap<>();
queryMap.put("roomName", newRoomName);
retrofitBucket.setQueryMap(queryMap);
return retrofitBucket;
}
public static RetrofitBucket getRetrofitBucketForAddParticipant(String baseUrl, String token, String user) {
RetrofitBucket retrofitBucket = new RetrofitBucket();
retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/participants");

View File

@ -297,12 +297,16 @@ public class CallsListController extends BaseController implements SearchView.On
}
if (fromBottomSheet) {
bottomSheet.setCancelable(true);
if (bottomSheet.isShowing()) {
bottomSheet.cancel();
}
new Handler().postDelayed(() -> {
bottomSheet.setCancelable(true);
if (bottomSheet.isShowing()) {
bottomSheet.cancel();
}
}, 2500);
}
});
}
private void prepareViews() {

View File

@ -117,21 +117,22 @@ public class CallMenuController extends BaseController implements FlexibleAdapte
} else {
if (room.isHasPassword()) {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_change_password), 4));
menuItems.add(new MenuItem(getResources().getString(R.string.nc_clear_password), 5));
} else {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_set_password), 5));
menuItems.add(new MenuItem(getResources().getString(R.string.nc_set_password), 6));
}
}
}
if (room.isPublic()) {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_share_link), 6));
menuItems.add(new MenuItem(getResources().getString(R.string.nc_share_link), 7));
if (room.canModerate()) {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_make_call_private), 7));
menuItems.add(new MenuItem(getResources().getString(R.string.nc_make_call_private), 8));
}
}
if (room.isDeletable()) {
menuItems.add(new MenuItem(getResources().getString(R.string.nc_delete_call), 8));
menuItems.add(new MenuItem(getResources().getString(R.string.nc_delete_call), 9));
}
}
@ -139,14 +140,23 @@ public class CallMenuController extends BaseController implements FlexibleAdapte
public boolean onItemClick(int position) {
MenuItem menuItem = (MenuItem) adapter.getItem(position);
Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
if (menuItem != null) {
int tag = menuItem.getTag();
if (tag > 0 && tag < 9) {
eventBus.post(new BottomSheetLockEvent(false, 0, false));
if (tag == 5) {
room.setPassword("");
}
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
if (tag > 0 && tag < 10) {
bundle.putInt(BundleKeys.KEY_OPERATION_CODE, tag);
if (tag != 6 && tag != 2) {
if (tag != 2 && tag != 4 && tag != 6 && tag != 7) {
eventBus.post(new BottomSheetLockEvent(false, 0, false));
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)));
} else if (tag != 7) {
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)));
} else {
// do nothing for now, this is share
}
}
}

View File

@ -0,0 +1,164 @@
/*
* 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/>.
*/
package com.nextcloud.talk.controllers.bottomsheet;
import android.os.Bundle;
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;
import android.widget.Button;
import com.bluelinelabs.conductor.RouterTransaction;
import com.nextcloud.talk.R;
import com.nextcloud.talk.api.models.json.rooms.Room;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.BottomSheetLockEvent;
import com.nextcloud.talk.utils.bundle.BundleKeys;
import org.greenrobot.eventbus.EventBus;
import org.parceler.Parcels;
import javax.inject.Inject;
import autodagger.AutoInjector;
import butterknife.BindView;
import butterknife.OnClick;
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
import studio.carbonylgroup.textfieldboxes.TextFieldBoxes;
@AutoInjector(NextcloudTalkApplication.class)
public class EntryMenuController extends BaseController {
private static final String TAG = "EntryMenuController";
@BindView(R.id.ok_button)
Button proceedButton;
@BindView(R.id.extended_edit_text)
ExtendedEditText editText;
@BindView(R.id.text_field_boxes)
TextFieldBoxes textFieldBoxes;
@Inject
EventBus eventBus;
private int operationCode;
private Room room;
public EntryMenuController(Bundle args) {
super(args);
this.operationCode = args.getInt(BundleKeys.KEY_OPERATION_CODE);
this.room = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_ROOM));
}
@Override
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
return inflater.inflate(R.layout.controller_entry_menu, container, false);
}
@OnClick(R.id.ok_button)
public void onProceedButtonClick() {
eventBus.post(new BottomSheetLockEvent(false, 0, false));
Bundle bundle = new Bundle();
if (operationCode == 4 || operationCode == 6) {
room.setPassword(editText.getText().toString());
} else {
room.setName(editText.getText().toString());
}
bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
bundle.putInt(BundleKeys.KEY_OPERATION_CODE, operationCode);
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)));
}
@Override
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(s)) {
if (operationCode == 2) {
if (room.getName() == null || !room.getName().equals(s.toString())) {
if (proceedButton.isEnabled()) {
proceedButton.setEnabled(true);
proceedButton.setAlpha(1.0f);
}
} else {
if (!proceedButton.isEnabled()) {
proceedButton.setEnabled(false);
proceedButton.setAlpha(0.7f);
}
textFieldBoxes.setError(getResources().getString(R.string.nc_call_name_is_same),
true);
}
} else {
if (!proceedButton.isEnabled()) {
proceedButton.setEnabled(true);
proceedButton.setAlpha(1.0f);
}
}
} else {
if (proceedButton.isEnabled()) {
proceedButton.setEnabled(false);
proceedButton.setAlpha(0.7f);
}
}
}
});
String helperText = "";
switch (operationCode) {
case 2:
helperText = getResources().getString(R.string.nc_call_name);
break;
case 4:
helperText = getResources().getString(R.string.nc_new_password);
break;
case 6:
helperText = getResources().getString(R.string.nc_password);
break;
default:
break;
}
textFieldBoxes.setHelperText(helperText);
editText.requestFocus();
}
}

View File

@ -37,7 +37,6 @@ import com.nextcloud.talk.api.models.json.rooms.Room;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.BottomSheetLockEvent;
import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.persistence.entities.UserEntity;
import com.nextcloud.talk.utils.ColorUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys;
@ -57,6 +56,8 @@ import io.reactivex.schedulers.Schedulers;
@AutoInjector(NextcloudTalkApplication.class)
public class OperationsMenuController extends BaseController {
private static final String TAG = "OperationsMenuController";
@BindView(R.id.progress_bar)
ProgressBar progressBar;
@ -119,9 +120,8 @@ public class OperationsMenuController extends BaseController {
.subscribe(operationsObserver);
break;
case 2:
RetrofitBucket retrofitBucket = ApiHelper.getRetrofitBucketForRenameRoom(userEntity.getBaseUrl(),
room.getToken(), room.getName());
ncApi.renameRoom(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap())
ncApi.renameRoom(credentials, ApiHelper.getRoom(userEntity.getBaseUrl(), room.getToken()),
room.getName())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.retry(1)
@ -137,6 +137,7 @@ public class OperationsMenuController extends BaseController {
break;
case 4:
case 5:
case 6:
String pass = "";
if (room.getPassword() != null) {
pass = room.getPassword();
@ -148,10 +149,10 @@ public class OperationsMenuController extends BaseController {
.retry(1)
.subscribe(operationsObserver);
break;
case 6:
case 7:
// Operation 6 is sharing, so we handle this differently
break;
case 7:
case 8:
ncApi.makeRoomPrivate(credentials, ApiHelper.getUrlForRoomVisibility(userEntity.getBaseUrl(), room
.getToken()))
.subscribeOn(Schedulers.newThread())
@ -159,7 +160,7 @@ public class OperationsMenuController extends BaseController {
.retry(1)
.subscribe(operationsObserver);
break;
case 8:
case 9:
ncApi.deleteRoom(credentials, ApiHelper.getUrlForRoomParticipants(userEntity.getBaseUrl(), room.getToken()))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
@ -174,20 +175,31 @@ public class OperationsMenuController extends BaseController {
private void showResultImage(boolean everythingOK) {
progressBar.setVisibility(View.GONE);
if (everythingOK) {
resultImageView.setImageDrawable(ColorUtils.getTintedDrawable(getResources(), R.drawable
.ic_check_circle_black_24dp, R.color.nc_darkGreen));
} else {
resultImageView.setImageDrawable(ColorUtils.getTintedDrawable(getResources(), R.drawable
.ic_cancel_black_24dp, R.color.nc_darkRed));
}
resultImageView.setVisibility(View.VISIBLE);
if (everythingOK) {
resultsTextView.setText(R.string.nc_all_ok_operation);
} else {
resultsTextView.setTextColor(getResources().getColor(R.color.nc_darkRed));
resultsTextView.setText(R.string.nc_failed_to_perform_operation);
}
boolean shouldRefreshData = operationCode != 4 && operationCode != 5;
resultsTextView.setVisibility(View.VISIBLE);
if (everythingOK) {
eventBus.post(new BottomSheetLockEvent(true, 2500, shouldRefreshData));
eventBus.post(new BottomSheetLockEvent(true, 2500, true));
} else {
okButton.setOnClickListener(v -> eventBus.post(new BottomSheetLockEvent(true, 0, shouldRefreshData)));
resultImageView.setImageDrawable(ColorUtils.getTintedDrawable(getResources(), R.drawable
.ic_cancel_black_24dp, R.color.nc_darkRed));
okButton.setOnClickListener(v -> eventBus.post(new BottomSheetLockEvent(true, 0, true)));
okButton.setVisibility(View.VISIBLE);
}
}
@ -210,16 +222,12 @@ public class OperationsMenuController extends BaseController {
@Override
public void onNext(Object o) {
resultImageView.setImageDrawable(ColorUtils.getTintedDrawable(getResources(), R.drawable
.ic_check_circle_black_24dp, R.color.nc_darkGreen));
showResultImage(true);
}
@Override
public void onError(Throwable e) {
if (retryCount == 1) {
resultImageView.setImageDrawable(ColorUtils.getTintedDrawable(getResources(), R.drawable
.ic_cancel_black_24dp, R.color.nc_darkRed));
showResultImage(false);
}
dispose();
@ -231,5 +239,9 @@ public class OperationsMenuController extends BaseController {
}
}
@Override
public void onDestroy() {
super.onDestroy();
dispose();
}
}

View File

@ -21,7 +21,6 @@
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;
@ -30,7 +29,7 @@ public class ColorUtils {
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);
drawable.setTint(color);
return drawable;
}
}

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/nc_white_color">
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:id="@+id/text_field_boxes"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
app:errorColor="@color/nc_darkRed"
app:helperText=" "
app:panelBackgroundColor="@color/nc_white_color"
app:primaryColor="@color/colorPrimary">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/extended_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="textUri"
android:minWidth="5dp"
android:singleLine="true"
android:textColor="@color/colorPrimary"/>
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
<Button
android:id="@+id/ok_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@id/text_field_boxes"
android:layout_marginBottom="12dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:background="#0000"
android:enabled="false"
android:alpha="0.7"
android:text="@string/nc_proceed"
android:textColor="@color/colorPrimary"/>
</RelativeLayout>

View File

@ -29,8 +29,8 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerInParent="true"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
android:indeterminate="true"
android:indeterminateTint="@color/colorPrimary"
android:indeterminateTintMode="src_in"
@ -40,7 +40,7 @@
android:id="@+id/result_image_view"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
@ -54,9 +54,9 @@
android:layout_height="wrap_content"
android:layout_below="@id/result_image_view"
android:layout_centerHorizontal="true"
android:layout_marginBottom="12dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginBottom="12dp"
android:maxLines="2"
android:textAlignment="center"
android:textColor="@color/colorPrimary"

View File

@ -60,6 +60,7 @@
<string name="nc_no_proxy">No proxy</string>
<string name="nc_username">Username</string>
<string name="nc_password">Password</string>
<string name="nc_new_password">New password</string>
<string name="nc_about">About</string>
<string name="nc_privacy">Privacy</string>
<string name="nc_get_source_code">Get source code</string>
@ -74,6 +75,7 @@
<string name="nc_rename">Rename call</string>
<string name="nc_set_password">Set a password</string>
<string name="nc_change_password">Change a password</string>
<string name="nc_clear_password">Clear password</string>
<string name="nc_share_link">Share link</string>
<string name="nc_make_call_public">Make call public</string>
<string name="nc_make_call_private">Make call private</string>
@ -105,5 +107,8 @@
<string name="nc_failed_to_perform_operation">Sorry, something went wrong!</string>
<string name="nc_all_ok_operation">OK, all done!</string>
<string name="nc_ok">OK</string>
<string name="nc_call_name">Call name</string>
<string name="nc_proceed">Proceed</string>
<string name="nc_call_name_is_same">The name you entered is the same as the existing one</string>
</resources>