0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

lint: DeckPickerFloatingActionMenu

(cherry picked from commit 2ca4938b4f)
This commit is contained in:
David Allison 2021-06-02 23:09:54 +01:00 committed by Mike Hardy
parent c8d19d621f
commit 631c50888b
No known key found for this signature in database
GPG Key ID: 2FB9315A0E38FF42

View File

@ -1,40 +1,34 @@
/****************************************************************************************
* Copyright (c) 2021 Akshay Jadhav <jadhavakshay0701@gmail.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/>. *
****************************************************************************************/
/*
* Copyright (c) 2021 Akshay Jadhav <jadhavakshay0701@gmail.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.ichi2.anki;
import android.animation.Animator;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.ichi2.anki.dialogs.CreateDeckDialog;
import com.ichi2.libanki.Decks;
import com.ichi2.ui.FixedEditText;
import timber.log.Timber;
public class DeckPickerFloatingActionMenu {
private final FloatingActionButton mAddDeckButton;
private final FloatingActionButton mAddNoteButton;
private final FloatingActionButton mAddSharedButton;
private final FloatingActionButton mFabMain;
private final LinearLayout mAddSharedLayout;
private final LinearLayout mAddDeckLayout;
@ -43,17 +37,17 @@ public class DeckPickerFloatingActionMenu {
private boolean mIsFABOpen = false;
private final DeckPicker mDeckPicker;
private LinearLayout mLinearLayout;
private final LinearLayout mLinearLayout;
public DeckPickerFloatingActionMenu(View view, DeckPicker deckPicker) {
this.mDeckPicker = deckPicker;
mDeckPicker = deckPicker;
mAddNoteLayout = (LinearLayout)view.findViewById(R.id.add_note_layout);
mAddSharedLayout = (LinearLayout)view.findViewById(R.id.add_shared_layout);
mAddDeckLayout = (LinearLayout)view.findViewById(R.id.add_deck_layout);
mFabMain = (FloatingActionButton)view.findViewById(R.id.fab_main);
mAddNoteButton = (FloatingActionButton)view.findViewById(R.id.add_note_action);
mAddSharedButton = (FloatingActionButton)view.findViewById(R.id.add_shared_action);
mAddDeckButton = (FloatingActionButton)view.findViewById(R.id.add_deck_action);
FloatingActionButton addNoteButton = (FloatingActionButton) view.findViewById(R.id.add_note_action);
FloatingActionButton addSharedButton = (FloatingActionButton) view.findViewById(R.id.add_shared_action);
FloatingActionButton addDeckButton = (FloatingActionButton) view.findViewById(R.id.add_deck_action);
mFabBGLayout = view.findViewById(R.id.fabBGLayout);
mLinearLayout = view.findViewById(R.id.deckpicker_view);
@ -61,35 +55,25 @@ public class DeckPickerFloatingActionMenu {
TextView addSharedLabel = view.findViewById(R.id.add_shared_label);
TextView addDeckLabel = view.findViewById(R.id.add_deck_label);
mFabMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!mIsFABOpen) {
showFloatingActionMenu();
} else {
closeFloatingActionMenu();
}
}
});
mFabBGLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mFabMain.setOnClickListener(v -> {
if (!mIsFABOpen) {
showFloatingActionMenu();
} else {
closeFloatingActionMenu();
}
});
mFabBGLayout.setOnClickListener(v -> closeFloatingActionMenu());
View.OnClickListener addDeckListener = addDeckButtonView -> {
if (mIsFABOpen) {
closeFloatingActionMenu();
CreateDeckDialog createDeckDialog = new CreateDeckDialog(mDeckPicker, R.string.new_deck, CreateDeckDialog.DeckDialogType.DECK, null);
createDeckDialog.setOnNewDeckCreated((i) -> {
deckPicker.updateDeckList();
});
createDeckDialog.setOnNewDeckCreated((i) -> deckPicker.updateDeckList());
createDeckDialog.showDialog();
}
};
mAddDeckButton.setOnClickListener(addDeckListener);
addDeckButton.setOnClickListener(addDeckListener);
addDeckLabel.setOnClickListener(addDeckListener);
View.OnClickListener addSharedListener = addSharedButtonView -> {
@ -97,7 +81,7 @@ public class DeckPickerFloatingActionMenu {
closeFloatingActionMenu();
deckPicker.addSharedDeck();
};
mAddSharedButton.setOnClickListener(addSharedListener);
addSharedButton.setOnClickListener(addSharedListener);
addSharedLabel.setOnClickListener(addSharedListener);
View.OnClickListener addNoteListener = addNoteButtonView -> {
@ -105,13 +89,13 @@ public class DeckPickerFloatingActionMenu {
closeFloatingActionMenu();
deckPicker.addNote();
};
mAddNoteButton.setOnClickListener(addNoteListener);
addNoteButton.setOnClickListener(addNoteListener);
addNoteLabel.setOnClickListener(addNoteListener);
}
private boolean animationDisabled() {
private boolean animationEnabled() {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(mDeckPicker);
return preferences.getBoolean("safeDisplay", false);
return !preferences.getBoolean("safeDisplay", false);
}
@ -128,7 +112,7 @@ public class DeckPickerFloatingActionMenu {
private void showFloatingActionMenu() {
mLinearLayout.setAlpha(0.5f);
mIsFABOpen = true;
if (!animationDisabled()) {
if (animationEnabled()) {
// Show with animation
mAddNoteLayout.setVisibility(View.VISIBLE);
mAddSharedLayout.setVisibility(View.VISIBLE);
@ -154,7 +138,7 @@ public class DeckPickerFloatingActionMenu {
mLinearLayout.setAlpha(1f);
mIsFABOpen = false;
mFabBGLayout.setVisibility(View.GONE);
if (!animationDisabled()) {
if (animationEnabled()) {
// Close with animation
mFabMain.animate().rotation(0);
mAddNoteLayout.animate().translationY(200f).setDuration(30);