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 all 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 @@ -24,7 +24,7 @@
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin"
android:layout_marginTop="@dimen/margin_standard"
android:text="@string/discard_changes"
app:icon="@drawable/ic_delete"
app:iconGravity="textStart"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/server_auth_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginTop="@dimen/margin"
android:layout_marginTop="@dimen/margin_standard"
android:layout_marginRight="20dip"
android:gravity="fill_horizontal"
android:hint="@string/password"
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.

Loading