Revert "Ask save changes answer"

This reverts commit 49e50c7d33.
pull/172/head
M66B 5 years ago
parent f9af0b1c1a
commit 5ccfc8a36d

@ -25,10 +25,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -36,7 +34,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -57,16 +54,15 @@ public class FragmentAnswer extends FragmentBase {
private CheckBox cbHide; private CheckBox cbHide;
private EditTextCompose etText; private EditTextCompose etText;
private BottomNavigationView style_bar; private BottomNavigationView style_bar;
private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpReady; private Group grpReady;
private long id = -1; private long id = -1;
private long copy = -1; private long copy = -1;
private boolean dirty = false;
private static final int REQUEST_LINK = 1; private static final int REQUEST_LINK = 1;
private final static int REQUEST_SAVE = 2; private final static int REQUEST_DELETE = 2;
private final static int REQUEST_DELETE = 3;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -96,6 +92,7 @@ public class FragmentAnswer extends FragmentBase {
etText = view.findViewById(R.id.etText); etText = view.findViewById(R.id.etText);
style_bar = view.findViewById(R.id.style_bar); style_bar = view.findViewById(R.id.style_bar);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady); grpReady = view.findViewById(R.id.grpReady);
@ -114,25 +111,19 @@ public class FragmentAnswer extends FragmentBase {
} }
}); });
addKeyPressedListener(new ActivityBase.IKeyPressedListener() { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onKeyPressed(int keyCode) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
return false; switch (menuItem.getItemId()) {
} case R.id.action_delete:
onActionDelete();
@Override return true;
public boolean onBackPressed() { case R.id.action_save:
if (dirty) { onActionSave();
Bundle aargs = new Bundle(); return true;
aargs.putString("question", getString(R.string.title_ask_save)); default:
return false;
FragmentDialogAsk fragment = new FragmentDialogAsk(); }
fragment.setArguments(aargs);
fragment.setTargetFragment(FragmentAnswer.this, REQUEST_SAVE);
fragment.show(getParentFragmentManager(), "account:save");
return true;
} else
return false;
} }
}); });
@ -164,35 +155,7 @@ public class FragmentAnswer extends FragmentBase {
cbFavorite.setChecked(answer == null ? false : answer.favorite); cbFavorite.setChecked(answer == null ? false : answer.favorite);
cbHide.setChecked(answer == null ? false : answer.hide); cbHide.setChecked(answer == null ? false : answer.hide);
etText.setText(answer == null ? null : HtmlHelper.fromHtml(answer.text)); etText.setText(answer == null ? null : HtmlHelper.fromHtml(answer.text));
bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE);
TextWatcher watcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
dirty = true;
}
@Override
public void afterTextChanged(Editable s) {
// Do nothing
}
};
CompoundButton.OnCheckedChangeListener checker = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
dirty = true;
}
};
etName.addTextChangedListener(watcher);
cbFavorite.setOnCheckedChangeListener(checker);
cbHide.setOnCheckedChangeListener(checker);
etText.addTextChangedListener(watcher);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
@ -207,25 +170,16 @@ public class FragmentAnswer extends FragmentBase {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_operations, menu); inflater.inflate(R.menu.menu_answer, menu);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
} }
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_delete).setVisible(id > 0);
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_help: case R.id.menu_help:
onMenuHelp(); onMenuHelp();
return true; return true;
case R.id.menu_delete:
onMenuDelete();
return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -235,7 +189,7 @@ public class FragmentAnswer extends FragmentBase {
new FragmentInfo().show(getParentFragmentManager(), "answer:info"); new FragmentInfo().show(getParentFragmentManager(), "answer:info");
} }
private void onMenuDelete() { private void onActionDelete() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_delete_answer)); args.putString("question", getString(R.string.title_ask_delete_answer));
@ -245,38 +199,7 @@ public class FragmentAnswer extends FragmentBase {
fragment.show(getParentFragmentManager(), "answer:delete"); fragment.show(getParentFragmentManager(), "answer:delete");
} }
@Override private void onActionSave() {
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case REQUEST_LINK:
if (resultCode == RESULT_OK && data != null)
onLinkSelected(data.getBundleExtra("args"));
break;
case REQUEST_SAVE:
if (resultCode == RESULT_OK)
onSave();
else
finish();
break;
case REQUEST_DELETE:
if (resultCode == RESULT_OK)
onDelete();
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
StyleHelper.apply(R.id.menu_link, etText, link);
}
private void onSave() {
etText.clearComposingText(); etText.clearComposingText();
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -343,6 +266,31 @@ public class FragmentAnswer extends FragmentBase {
}.execute(this, args, "answer:save"); }.execute(this, args, "answer:save");
} }
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case REQUEST_LINK:
if (resultCode == RESULT_OK && data != null)
onLinkSelected(data.getBundleExtra("args"));
break;
case REQUEST_DELETE:
if (resultCode == RESULT_OK)
onDelete();
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
StyleHelper.apply(R.id.menu_link, etText, link);
}
private void onDelete() { private void onDelete() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);

@ -1,101 +1,119 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent" android:layout_height="match_parent"
tools:context="eu.faircode.email.ActivityView"> tools:context="eu.faircode.email.ActivityView">
<EditText <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/etName" android:layout_width="match_parent"
android:layout_width="0dp" android:layout_height="match_parent"
android:layout_height="wrap_content" app:layout_behavior="eu.faircode.email.BehaviorBottomPadding">
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:hint="@string/title_answer_name"
android:imeOptions="actionNext"
android:inputType="textCapSentences|textAutoCorrect"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox <EditText
android:id="@+id/cbFavorite" android:id="@+id/etName"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:text="@string/title_answer_favorite" android:layout_marginEnd="6dp"
app:layout_constraintStart_toStartOf="parent" android:hint="@string/title_answer_name"
app:layout_constraintTop_toBottomOf="@+id/etName" /> android:imeOptions="actionNext"
android:inputType="textCapSentences|textAutoCorrect"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox <CheckBox
android:id="@+id/cbHide" android:id="@+id/cbFavorite"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:text="@string/title_answer_hide" android:text="@string/title_answer_favorite"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbFavorite" /> app:layout_constraintTop_toBottomOf="@+id/etName" />
<View <CheckBox
android:id="@+id/vSeparator" android:id="@+id/cbHide"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="1dp" android:layout_height="wrap_content"
android:layout_marginTop="6dp" android:layout_marginStart="6dp"
android:background="?attr/colorSeparator" android:layout_marginTop="6dp"
app:layout_constraintEnd_toEndOf="parent" android:text="@string/title_answer_hide"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbHide" /> app:layout_constraintTop_toBottomOf="@+id/cbFavorite" />
<eu.faircode.email.EditTextCompose <View
android:id="@+id/etText" android:id="@+id/vSeparator"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="1dp"
android:layout_margin="6dp" android:layout_marginTop="6dp"
android:background="@null" android:background="?attr/colorSeparator"
android:fontFamily="monospace" app:layout_constraintEnd_toEndOf="parent"
android:gravity="top" app:layout_constraintStart_toStartOf="parent"
android:hint="@string/title_answer_text" app:layout_constraintTop_toBottomOf="@+id/cbHide" />
android:imeOptions="actionDone"
android:inputType="textCapSentences|textMultiLine|textAutoCorrect"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toTopOf="@+id/style_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparator" />
<com.google.android.material.bottomnavigation.BottomNavigationView <eu.faircode.email.EditTextCompose
android:id="@+id/style_bar" android:id="@+id/etText"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="36dp" android:layout_height="0dp"
android:background="?attr/colorActionBackground" android:layout_margin="6dp"
app:itemIconTint="@color/action_foreground" android:background="@null"
app:itemTextColor="@color/action_foreground" android:fontFamily="monospace"
app:labelVisibilityMode="unlabeled" android:gravity="top"
app:layout_constraintBottom_toBottomOf="parent" android:hint="@string/title_answer_text"
app:layout_constraintEnd_toEndOf="parent" android:imeOptions="actionDone"
app:layout_constraintStart_toStartOf="parent" android:inputType="textCapSentences|textMultiLine|textAutoCorrect"
app:layout_constraintTop_toBottomOf="@id/etText" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:menu="@menu/action_answer_style" /> app:layout_constraintBottom_toTopOf="@+id/style_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparator" />
<eu.faircode.email.ContentLoadingProgressBar <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/pbWait" android:id="@+id/style_bar"
style="@style/Base.Widget.AppCompat.ProgressBar" android:layout_width="0dp"
android:layout_width="wrap_content" android:layout_height="36dp"
android:layout_height="wrap_content" android:background="?attr/colorActionBackground"
android:indeterminate="true" app:itemIconTint="@color/action_foreground"
app:layout_constraintBottom_toBottomOf="parent" app:itemTextColor="@color/action_foreground"
app:layout_constraintEnd_toEndOf="parent" app:labelVisibilityMode="unlabeled"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/action_answer_style" />
<androidx.constraintlayout.widget.Group <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/grpReady" android:id="@+id/bottom_navigation"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="wrap_content"
app:constraint_referenced_ids="etName,cbFavorite,cbHide,vSeparator,etText" /> android:background="?attr/colorPrimary"
</androidx.constraintlayout.widget.ConstraintLayout> app:itemIconTint="@color/action_foreground"
app:itemTextColor="@color/action_foreground"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/action_answer" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="etName,vSeparator,etText,bottom_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_delete"
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_delete" />
<item
android:id="@+id/action_save"
android:icon="@drawable/baseline_save_alt_24"
android:title="@string/title_save" />
</menu>

@ -6,9 +6,4 @@
android:icon="@drawable/baseline_help_24" android:icon="@drawable/baseline_help_24"
android:title="" android:title=""
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/menu_delete"
android:title="@string/title_delete"
app:showAsAction="never" />
</menu> </menu>

Loading…
Cancel
Save