Skip to content
Snippets Groups Projects
Commit fca619f7 authored by Amirhossein Naghshzan's avatar Amirhossein Naghshzan Committed by Andreas Traczyk
Browse files

accountSummary: add bottomSheet behavior to new device layout

Change-Id: I78ea4cb561c89bb5d59c0fe2a62c5f4753f0044b
parent d184a670
No related branches found
No related tags found
No related merge requests found
...@@ -57,6 +57,7 @@ import cx.ring.fragments.AdvancedAccountFragment; ...@@ -57,6 +57,7 @@ import cx.ring.fragments.AdvancedAccountFragment;
import cx.ring.fragments.GeneralAccountFragment; import cx.ring.fragments.GeneralAccountFragment;
import cx.ring.fragments.MediaPreferenceFragment; import cx.ring.fragments.MediaPreferenceFragment;
import cx.ring.fragments.SecurityAccountFragment; import cx.ring.fragments.SecurityAccountFragment;
import cx.ring.interfaces.BackHandlerInterface;
public class AccountEditionActivity extends AppCompatActivity implements AccountEditionView { public class AccountEditionActivity extends AppCompatActivity implements AccountEditionView {
...@@ -80,6 +81,8 @@ public class AccountEditionActivity extends AppCompatActivity implements Account ...@@ -80,6 +81,8 @@ public class AccountEditionActivity extends AppCompatActivity implements Account
private MenuItem mItemAdvanced; private MenuItem mItemAdvanced;
private MenuItem mItemBlacklist; private MenuItem mItemBlacklist;
private BackHandlerInterface mBackHandlerInterface;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -176,6 +179,9 @@ public class AccountEditionActivity extends AppCompatActivity implements Account ...@@ -176,6 +179,9 @@ public class AccountEditionActivity extends AppCompatActivity implements Account
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (mBackHandlerInterface.onBackPressed()) {
return;
}
if (frameLayout.getVisibility() == View.VISIBLE) { if (frameLayout.getVisibility() == View.VISIBLE) {
super.onBackPressed(); super.onBackPressed();
} else { } else {
...@@ -185,6 +191,12 @@ public class AccountEditionActivity extends AppCompatActivity implements Account ...@@ -185,6 +191,12 @@ public class AccountEditionActivity extends AppCompatActivity implements Account
} }
} }
@Override
protected void onDestroy() {
super.onDestroy();
mBackHandlerInterface = null;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
...@@ -339,4 +351,9 @@ public class AccountEditionActivity extends AppCompatActivity implements Account ...@@ -339,4 +351,9 @@ public class AccountEditionActivity extends AppCompatActivity implements Account
return result; return result;
} }
} }
public void setOnBackPressedListener(BackHandlerInterface backPressedListener) {
mBackHandlerInterface = backPressedListener;
}
} }
...@@ -28,6 +28,8 @@ import android.graphics.Typeface; ...@@ -28,6 +28,8 @@ import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.chip.Chip; import com.google.android.material.chip.Chip;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
...@@ -69,7 +71,6 @@ import cx.ring.mvp.BaseSupportFragment; ...@@ -69,7 +71,6 @@ import cx.ring.mvp.BaseSupportFragment;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.utils.AndroidFileUtils; import cx.ring.utils.AndroidFileUtils;
import cx.ring.utils.KeyboardVisibilityManager; import cx.ring.utils.KeyboardVisibilityManager;
import cx.ring.views.LinkNewDeviceLayout;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountSummaryPresenter> implements BackHandlerInterface, public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountSummaryPresenter> implements BackHandlerInterface,
...@@ -89,8 +90,6 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -89,8 +90,6 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
/* /*
UI Bindings UI Bindings
*/ */
@BindView(R.id.linkaccount_container)
LinkNewDeviceLayout mLinkAccountView;
@BindView(R.id.ring_password) @BindView(R.id.ring_password)
EditText mRingPassword; EditText mRingPassword;
...@@ -117,7 +116,7 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -117,7 +116,7 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
Button mChangePasswordBtn; Button mChangePasswordBtn;
@BindView(R.id.layout_add_device) @BindView(R.id.layout_add_device)
LinearLayout mAddAccountLayout; MaterialCardView mAddAccountLayout;
@BindView(R.id.export_account_btn) @BindView(R.id.export_account_btn)
Button mExportButton; Button mExportButton;
...@@ -159,6 +158,7 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -159,6 +158,7 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
private String mBestName = ""; private String mBestName = "";
private String mAccountId = ""; private String mAccountId = "";
private File mCacheArchive = null; private File mCacheArchive = null;
private BottomSheetBehavior mSheetBehavior;
@Inject @Inject
AccountService mAccountService; AccountService mAccountService;
...@@ -166,7 +166,8 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -166,7 +166,8 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
@Override @Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
mLinkAccountView.setContainer(this); mSheetBehavior = BottomSheetBehavior.from(mAddAccountLayout);
hidePopWizard(); hidePopWizard();
if (getArguments() != null) { if (getArguments() != null) {
String accountId = getArguments().getString(AccountEditionActivity.ACCOUNT_ID_KEY); String accountId = getArguments().getString(AccountEditionActivity.ACCOUNT_ID_KEY);
...@@ -174,6 +175,25 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -174,6 +175,25 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
presenter.setAccountId(accountId); presenter.setAccountId(accountId);
} }
} }
((AccountEditionActivity) getActivity()).setOnBackPressedListener(this);
mSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View view, int i) {
if (mSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED){
mPasswordLayout.setVisibility(mAccountHasPassword ? View.VISIBLE : View.GONE);
mEndBtn.setVisibility(View.GONE);
mStartBtn.setVisibility(View.VISIBLE);
mExportInfos.setText(R.string.account_link_export_info);
}
}
@Override
public void onSlide(@NonNull View view, float v) {
}
});
} }
public void onActivityResult(int requestCode, int resultCode, Intent resultData) { public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
...@@ -277,10 +297,13 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -277,10 +297,13 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
BackHandlerInterface BackHandlerInterface
*/ */
@Override @Override
public void onBackPressed() { public boolean onBackPressed() {
if (isDisplayingWizard()) { if (isDisplayingWizard()) {
hideWizard(); hideWizard();
return true;
} }
return false;
} }
/* /*
...@@ -297,22 +320,17 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -297,22 +320,17 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
} }
private void showWizard() { private void showWizard() {
mLinkAccountView.setVisibility(View.VISIBLE); mSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mPasswordLayout.setVisibility(mAccountHasPassword ? View.VISIBLE : View.GONE);
mEndBtn.setVisibility(View.GONE);
mStartBtn.setVisibility(View.VISIBLE);
mExportInfos.setText(R.string.account_link_export_info);
} }
@OnClick(R.id.btn_end_export) @OnClick(R.id.btn_end_export)
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void hidePopWizard() { public void hidePopWizard() {
mLinkAccountView.setVisibility(View.GONE); mSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} }
public void hideWizard() { public void hideWizard() {
mLinkAccountView.setVisibility(View.GONE); mSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mRingPassword.setText("");
KeyboardVisibilityManager.hideKeyboard(getActivity(), 0); KeyboardVisibilityManager.hideKeyboard(getActivity(), 0);
} }
...@@ -344,7 +362,7 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -344,7 +362,7 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
} }
public boolean isDisplayingWizard() { public boolean isDisplayingWizard() {
return mLinkAccountView.getVisibility() == View.VISIBLE; return mSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
} }
@OnEditorAction(R.id.ring_password) @OnEditorAction(R.id.ring_password)
...@@ -439,8 +457,8 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS ...@@ -439,8 +457,8 @@ public class RingAccountSummaryFragment extends BaseSupportFragment<RingAccountS
@Override @Override
public void showPIN(final String pin) { public void showPIN(final String pin) {
hideWizard(); mRingPassword.setText("");
mLinkAccountView.setVisibility(View.VISIBLE); mSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mPasswordLayout.setVisibility(View.GONE); mPasswordLayout.setVisibility(View.GONE);
mEndBtn.setVisibility(View.VISIBLE); mEndBtn.setVisibility(View.VISIBLE);
mStartBtn.setVisibility(View.GONE); mStartBtn.setVisibility(View.GONE);
......
...@@ -19,5 +19,5 @@ ...@@ -19,5 +19,5 @@
package cx.ring.interfaces; package cx.ring.interfaces;
public interface BackHandlerInterface { public interface BackHandlerInterface {
void onBackPressed(); boolean onBackPressed();
} }
/*
* Copyright (C) 2004-2019 Savoir-faire Linux Inc.
*
* Author: Loïc Siret <loic.siret@savoirfairelinux.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 cx.ring.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import cx.ring.account.RingAccountSummaryFragment;
public class LinkNewDeviceLayout extends LinearLayout {
private RingAccountSummaryFragment container = null;
public LinkNewDeviceLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LinkNewDeviceLayout(Context context) {
super(context);
}
/**
* Overrides the handling of the back key to move back to
* dismiss the view, instead of only dismissing the input method.
*/
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if (container != null &&
event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
KeyEvent.DispatcherState state = getKeyDispatcherState();
if (state != null) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getRepeatCount() == 0) {
state.startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP
&& !event.isCanceled() && state.isTracking(event)) {
container.onBackPressed();
return true;
}
}
}
return super.dispatchKeyEventPreIme(event);
}
public void setContainer(RingAccountSummaryFragment container) {
this.container = container;
}
}
...@@ -16,22 +16,32 @@ GNU General Public License for more details. ...@@ -16,22 +16,32 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingTop="20dp"
tools:showIn="@layout/frag_acc_summary"> tools:showIn="@layout/frag_acc_summary">
<LinearLayout <com.google.android.material.card.MaterialCardView
android:id="@+id/layout_add_device" android:id="@+id/layout_add_device"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorPrimary" app:cardCornerRadius="15dp"
android:layout_marginBottom="-15dp"
android:elevation="4dp" android:elevation="4dp"
app:behavior_hideable="false"
app:behavior_peekHeight="50dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:paddingBottom="15dp"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
...@@ -43,12 +53,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ...@@ -43,12 +53,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
android:text="@string/account_link_export_button" android:text="@string/account_link_export_button"
android:textColor="@color/colorOnPrimary" /> android:textColor="@color/colorOnPrimary" />
<cx.ring.views.LinkNewDeviceLayout
android:id="@+id/linkaccount_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
...@@ -80,6 +84,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ...@@ -80,6 +84,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
app:passwordToggleTint="@color/colorPrimary" app:passwordToggleTint="@color/colorPrimary"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp"
android:layout_marginBottom="8dp"
app:passwordToggleEnabled="true"> app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
...@@ -99,6 +104,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ...@@ -99,6 +104,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginBottom="8dp"
android:text="@string/account_start_export_button" android:text="@string/account_start_export_button"
app:backgroundTint="@color/colorSecondary" app:backgroundTint="@color/colorSecondary"
android:textColor="@color/colorOnSecondary"/> android:textColor="@color/colorOnSecondary"/>
...@@ -116,6 +122,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ...@@ -116,6 +122,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</cx.ring.views.LinkNewDeviceLayout>
</LinearLayout> </LinearLayout>
</FrameLayout>
\ No newline at end of file </com.google.android.material.card.MaterialCardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment