Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update markup and signature exit model with new styling #6300

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class FormMapViewModel(
.getBoolean(ProtectedProjectKeys.KEY_EDIT_SAVED)

return IconifiedText(
if (canEditSaved) R.drawable.ic_edit else R.drawable.ic_visibility,
if (canEditSaved) org.odk.collect.icons.R.drawable.ic_edit else R.drawable.ic_visibility,
resources.getString(if (canEditSaved) org.odk.collect.strings.R.string.edit_data else org.odk.collect.strings.R.string.view_data)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class FormMapViewModelTest {
smallIcon = R.drawable.ic_room_form_state_incomplete_24dp,
largeIcon = R.drawable.ic_room_form_state_incomplete_48dp,
action = IconifiedText(
R.drawable.ic_edit,
org.odk.collect.icons.R.drawable.ic_edit,
application.getString(org.odk.collect.strings.R.string.edit_data)
),
info = formatDate(
Expand Down Expand Up @@ -152,7 +152,7 @@ class FormMapViewModelTest {
smallIcon = R.drawable.ic_room_form_state_incomplete_24dp,
largeIcon = R.drawable.ic_room_form_state_incomplete_48dp,
action = IconifiedText(
R.drawable.ic_edit,
org.odk.collect.icons.R.drawable.ic_edit,
application.getString(org.odk.collect.strings.R.string.edit_data)
),
info = formatDate(
Expand Down Expand Up @@ -191,7 +191,7 @@ class FormMapViewModelTest {
smallIcon = R.drawable.ic_room_form_state_incomplete_24dp,
largeIcon = R.drawable.ic_room_form_state_incomplete_48dp,
action = IconifiedText(
R.drawable.ic_edit,
org.odk.collect.icons.R.drawable.ic_edit,
application.getString(org.odk.collect.strings.R.string.edit_data)
),
info = formatDate(
Expand Down
4 changes: 4 additions & 0 deletions draw/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ android {
isIncludeAndroidResources = true
}
}

buildFeatures {
viewBinding = true
}
}

dependencies {
Expand Down
54 changes: 5 additions & 49 deletions draw/src/main/java/org/odk/collect/draw/DrawActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
Expand All @@ -29,18 +28,14 @@
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.viewmodel.CreationExtras;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import org.odk.collect.androidshared.bitmap.ImageFileUtils;
Expand All @@ -52,8 +47,6 @@
import org.odk.collect.strings.localization.LocalizedActivity;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

Expand Down Expand Up @@ -82,8 +75,6 @@ public class DrawActivity extends LocalizedActivity {
private File savepointImage;

private DrawView drawView;
private String alertTitleString;
private AlertDialog alertDialog;

private DrawViewModel drawViewModel;

Expand Down Expand Up @@ -210,17 +201,6 @@ public void onClick(View view) {
// original)
// output -- where the output should be written

if (OPTION_SIGNATURE.equals(loadOption)) {
alertTitleString = getString(org.odk.collect.strings.R.string.quit_application,
getString(org.odk.collect.strings.R.string.sign_button));
} else if (OPTION_ANNOTATE.equals(loadOption)) {
alertTitleString = getString(org.odk.collect.strings.R.string.quit_application,
getString(org.odk.collect.strings.R.string.markup_image));
} else {
alertTitleString = getString(org.odk.collect.strings.R.string.quit_application,
getString(org.odk.collect.strings.R.string.draw_image));
}

drawView.setupView(OPTION_SIGNATURE.equals(loadOption));

viewModel.getPenColor().observe(this, penColor -> {
Expand Down Expand Up @@ -286,35 +266,11 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
* saving
*/
private void createQuitDrawDialog() {
int dividerHeight = getResources().getDimensionPixelSize(org.odk.collect.androidshared.R.dimen.margin_extra_small);
ListView actionListView = new ListView(this);
actionListView.setPadding(0, dividerHeight, 0, 0);
actionListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
actionListView.setDividerHeight(dividerHeight);

List<IconMenuListAdapter.IconMenuItem> items;
items = Arrays.asList(new IconMenuListAdapter.IconMenuItem(org.odk.collect.icons.R.drawable.ic_save, org.odk.collect.strings.R.string.keep_changes),
new IconMenuListAdapter.IconMenuItem(org.odk.collect.icons.R.drawable.ic_delete, org.odk.collect.strings.R.string.discard_changes));

final IconMenuListAdapter adapter = new IconMenuListAdapter(this, items);
actionListView.setAdapter(adapter);
actionListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
IconMenuListAdapter.IconMenuItem item = (IconMenuListAdapter.IconMenuItem) adapter.getItem(position);
if (item.getTextResId() == org.odk.collect.strings.R.string.keep_changes) {
drawViewModel.save(drawView);
} else {
cancelAndClose();
}
alertDialog.dismiss();
}
});
alertDialog = new MaterialAlertDialogBuilder(this)
.setTitle(alertTitleString)
.setPositiveButton(getString(org.odk.collect.strings.R.string.do_not_exit), null)
.setView(actionListView).create();
alertDialog.show();
QuitDrawingDialog.show(
this,
this::cancelAndClose,
() -> drawViewModel.save(drawView)
);
}

private void clear(View view) {
Expand Down
98 changes: 0 additions & 98 deletions draw/src/main/java/org/odk/collect/draw/IconMenuListAdapter.java

This file was deleted.

50 changes: 50 additions & 0 deletions draw/src/main/java/org/odk/collect/draw/QuitDrawingDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.odk.collect.draw

import android.app.Activity
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.odk.collect.draw.databinding.QuitDrawingDialogLayoutBinding

object QuitDrawingDialog {
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved

@JvmStatic
fun show(
activity: Activity,
onDiscardChanges: Runnable?,
onSaveChanges: Runnable?
): AlertDialog {
return create(
activity,
onDiscardChanges,
onSaveChanges
).also {
it.show()
}
}

private fun create(
activity: Activity,
onDiscardChanges: Runnable?,
onSaveChanges: Runnable?
): AlertDialog {
val binding = QuitDrawingDialogLayoutBinding.inflate(activity.layoutInflater)
val dialog = MaterialAlertDialogBuilder(activity)
.setTitle(org.odk.collect.strings.R.string.save_drawing_title)
.setView(binding.root)
.create()

binding.discardChanges.setOnClickListener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see any test coverage for these 3 buttons - I'm guessing that's an existing problem though. This is probably a good opportunity to add it (maybe as part of a DrawActivityTest).

onDiscardChanges?.run()
}

binding.keepEditing.setOnClickListener {
dialog.dismiss()
}

binding.saveChanges.setOnClickListener {
onSaveChanges?.run()
}

return dialog
}
}
16 changes: 0 additions & 16 deletions draw/src/main/res/layout/item_view_option.xml

This file was deleted.

64 changes: 64 additions & 0 deletions draw/src/main/res/layout/quit_drawing_dialog_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/margin_large">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/save_drawing_explanation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/save_drawing_explanation"
android:textAppearance="?textAppearanceBodyMedium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/discard_changes"
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin"
grzesiek2010 marked this conversation as resolved.
Show resolved Hide resolved
android:text="@string/discard_changes"
app:icon="@drawable/ic_delete"
app:iconGravity="textStart"
app:iconSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/save_drawing_explanation" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/keep_editing"
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin_extra_small"
android:text="@string/keep_editing"
app:icon="@drawable/ic_edit"
app:iconGravity="textStart"
app:iconSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/discard_changes" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeMaterialButton
android:id="@+id/saveChanges"
style="?materialButtonIconStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin_extra_small"
android:text="@string/keep_changes"
app:icon="@drawable/ic_save"
app:iconGravity="textStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/discard_changes"
app:layout_constraintStart_toStartOf="@id/discard_changes"
app:layout_constraintTop_toBottomOf="@id/keep_editing" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
3 changes: 0 additions & 3 deletions strings/src/main/res/values-af/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
<string name="data_saved_error">Jammer, stoor van vorm het misluk!</string>
<string name="data_saved_ok">Vorm suksesvol gestoor!</string>
<string name="save_point_error">Fout tydens stoor van herstel-punt: %s</string>
<!--Dialog title when exiting a drawing view. The name of the kind of drawing will be included-->
<string name="quit_application">Verlaat %s</string>
<!--Used when exiting a form filling session in which a form was not properly loaded. &lt; and &gt; surrounds the text so it will appear as <no form loaded>-->
<string name="keep_changes">Stoor Veranderinge</string>
<string name="saving_form">Besig om vorm te stoor</string>
Expand Down Expand Up @@ -361,7 +359,6 @@
<string name="cancel_loading_form">Kanselleer</string>
<string name="cancel_location">Kanselleer</string>
<string name="do_not_change">Kanselleer</string>
<string name="do_not_exit">Kanselleer</string>
<string name="success">Sukses</string>
<string name="error_occured">Daar was \'n fout</string>
<string name="please_wait">Wag asseblief \'n paar sekondes.</string>
Expand Down
Loading