Hiding user password for anonymous usage. And showing login dialog after login failure.

This commit is contained in:
GaidamakUA 2016-02-24 17:53:22 +02:00
parent a5127ef7fb
commit cf1af7b409
6 changed files with 128 additions and 84 deletions

View file

@ -11,7 +11,7 @@
android:text="@string/osb_comment_dialog_message" />
<EditText
android:id="@+id/messageEditText"
android:id="@+id/message_field"
android:minLines="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
@ -29,7 +29,7 @@
android:text="@string/osb_comment_dialog_author" />
<EditText
android:id="@+id/userNameEditText"
android:id="@+id/user_name_field"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
@ -45,7 +45,7 @@
android:text="@string/osb_author_dialog_password" />
<EditText
android:id="@+id/passwordEditText"
android:id="@+id/password_field"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"

View file

@ -36,7 +36,7 @@
android:background="@color/divider_color"/>
<TextView
android:id="@+id/messageEditTextLabel"
android:id="@+id/message_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -45,7 +45,7 @@
android:text="@string/osb_comment_dialog_message"/>
<EditText
android:id="@+id/messageEditText"
android:id="@+id/message_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -54,7 +54,7 @@
android:minLines="1"/>
<CheckBox
android:id="@+id/closeChangeSetCheckBox"
android:id="@+id/close_change_set_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -62,6 +62,7 @@
android:text="@string/close_changeset"/>
<TextView
android:id="@+id/osm_user_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -69,7 +70,7 @@
android:text="@string/user_name"/>
<EditText
android:id="@+id/userNameEditText"
android:id="@+id/user_name_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -77,6 +78,7 @@
<TextView
android:id="@+id/osm_user_password_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
@ -84,7 +86,7 @@
android:text="@string/user_password"/>
<EditText
android:id="@+id/passwordEditText"
android:id="@+id/password_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"

View file

@ -1,8 +1,8 @@
package net.osmand.plus.osmedit;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.data.PointDescription;
@ -10,15 +10,12 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
import net.osmand.util.Algorithms;
import java.util.Map;
public class EditPOIMenuController extends MenuController {
private OsmPoint osmPoint;
@ -31,30 +28,11 @@ public class EditPOIMenuController extends MenuController {
this.osmPoint = osmPoint;
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
poiUploader = new ProgressDialogPoiUploader() {
poiUploader = new SendPoiDialogFragment.SimpleProgressDialogPoiUploader() {
@NonNull
@Override
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading,
R.string.local_openstreetmap_uploading,
ProgressDialog.STYLE_HORIZONTAL);
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getMapActivity(),
getMapActivity().getString(R.string.local_openstreetmap_were_uploaded)) {
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
super.uploadEnded(loadErrorsMap);
getMapActivity().getContextMenu().close();
OsmBugsLayer l = getMapActivity().getMapView().getLayerByClass(OsmBugsLayer.class);
if(l != null) {
l.clearCache();
getMapActivity().refreshMap();
}
}
};
dialog.show(mapActivity.getSupportFragmentManager(), ProgressDialogFragment.TAG);
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, points.length, closeChangeSet, anonymously);
uploadTask.execute(points);
protected MapActivity getMapActivity() {
return mapActivity;
}
};

View file

@ -251,9 +251,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
SITE_API = "http://api.openstreetmap.org/";
}
List<OpenStreetNote> bugs = new ArrayList<OpenStreetNote>();
List<OpenStreetNote> bugs = new ArrayList<>();
StringBuilder b = new StringBuilder();
b.append(SITE_API + "api/0.6/notes?bbox="); //$NON-NLS-1$
b.append(SITE_API).append("api/0.6/notes?bbox="); //$NON-NLS-1$
b.append(leftLongitude); //$NON-NLS-1$
b.append(",").append(bottomLatitude); //$NON-NLS-1$
b.append(",").append(rightLongitude); //$NON-NLS-1$
@ -301,15 +301,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
for (OpenStreetNote note : bugs) {
note.acquireDescriptionAndType();
}
} catch (IOException e) {
} catch (IOException | RuntimeException | XmlPullParserException e) {
log.warn("Error loading bugs", e); //$NON-NLS-1$
} catch (NumberFormatException e) {
log.warn("Error loading bugs", e); //$NON-NLS-1$
} catch (RuntimeException e) {
log.warn("Error loading bugs", e); //$NON-NLS-1$
} catch (XmlPullParserException e) {
log.warn("Error loading bugs", e); //$NON-NLS-1$
}
}
return bugs;
}
@ -429,18 +423,18 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
OsmBugsUtil util = getOsmbugsUtil(bug);
final boolean offline = util instanceof OsmBugsLocalUtil;
if(offline) {
view.findViewById(R.id.userNameEditText).setVisibility(View.GONE);
view.findViewById(R.id.user_name_field).setVisibility(View.GONE);
view.findViewById(R.id.userNameEditTextLabel).setVisibility(View.GONE);
view.findViewById(R.id.passwordEditText).setVisibility(View.GONE);
view.findViewById(R.id.password_field).setVisibility(View.GONE);
view.findViewById(R.id.passwordEditTextLabel).setVisibility(View.GONE);
} else {
((EditText)view.findViewById(R.id.userNameEditText)).setText(getUserName());
((EditText)view.findViewById(R.id.passwordEditText)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
((EditText)view.findViewById(R.id.user_name_field)).setText(getUserName());
((EditText)view.findViewById(R.id.password_field)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
}
if(!Algorithms.isEmpty(text)) {
((EditText)view.findViewById(R.id.messageEditText)).setText(text);
((EditText)view.findViewById(R.id.message_field)).setText(text);
}
AndroidUtils.softKeyboardDelayed(view.findViewById(R.id.messageEditText));
AndroidUtils.softKeyboardDelayed(view.findViewById(R.id.message_field));
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View dialog) {
@ -476,15 +470,15 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private String getTextAndUpdateUserPwd(final View view) {
String text = getMessageText(view);
String author = ((EditText)view.findViewById(R.id.userNameEditText)).getText().toString();
String pwd = ((EditText)view.findViewById(R.id.passwordEditText)).getText().toString();
String author = ((EditText)view.findViewById(R.id.user_name_field)).getText().toString();
String pwd = ((EditText)view.findViewById(R.id.password_field)).getText().toString();
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_NAME.set(author);
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_PASSWORD.set(pwd);
return text;
}
private String getMessageText(final View view) {
return ((EditText)view.findViewById(R.id.messageEditText)).getText().toString();
return ((EditText)view.findViewById(R.id.message_field)).getText().toString();
}
public void refreshMap(){
@ -553,7 +547,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
switch (id) {
case DIALOG_BUG:
prepareBugDialog(dialogBundle, dialog);
((EditText)dialog.findViewById(R.id.messageEditText)).setText("");
((EditText)dialog.findViewById(R.id.message_field)).setText("");
break;
}
}
@ -567,9 +561,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private double longitude;
private String description;
private String typeName;
private List<String> dates = new ArrayList<String>();
private List<String> comments = new ArrayList<String>();
private List<String> users = new ArrayList<String>();
private List<String> dates = new ArrayList<>();
private List<String> comments = new ArrayList<>();
private List<String> users = new ArrayList<>();
private long id;
private boolean opened;

View file

@ -4,7 +4,6 @@ import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
@ -28,7 +27,9 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -67,9 +68,24 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
Log.v(TAG, "in if1");
OsmPoint point = loadErrorsMap.keySet().iterator().next();
String message = loadErrorsMap.get(point);
DialogFragment dialogFragment =
UploadingErrorDialogFragment.getInstance(message, point);
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
if (message.equals(activity.getString(R.string.auth_failed))) {
SendPoiDialogFragment dialogFragment =
SendPoiDialogFragment.createInstance(new OsmPoint[]{point});
if (activity instanceof MapActivity) {
dialogFragment.setPoiUploader(new SendPoiDialogFragment.SimpleProgressDialogPoiUploader() {
@NonNull
@Override
protected MapActivity getMapActivity() {
return (MapActivity) activity;
}
});
}
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
} else {
DialogFragment dialogFragment =
UploadingErrorDialogFragment.getInstance(message, point);
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
}
} else {
UploadingMultipleErrorDialogFragment dialogFragment =
UploadingMultipleErrorDialogFragment.createInstance(loadErrorsMap);
@ -79,12 +95,11 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
}
private static void showUploadItemsProgressDialog(Fragment fragment, OsmPoint[] toUpload) {
FragmentActivity activity = fragment.getActivity();
MapActivity activity = (MapActivity) fragment.getActivity();
OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
OsmEditsUploadListenerHelper helper = new OsmEditsUploadListenerHelper(activity,
activity.getResources().getString(R.string.local_openstreetmap_were_uploaded));
Resources resources = activity.getResources();
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading,
R.string.local_openstreetmap_uploading,
@ -111,20 +126,20 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
getResources().getString(R.string.error_message_pattern), errorMessage))
.setPositiveButton(R.string.shared_string_ok, null);
builder.setNeutralButton(getResources().getString(R.string.delete_change),
new DialogInterface.OnClickListener() {
public void onClick(@Nullable DialogInterface dialog, int id) {
OsmEditingPlugin plugin =
OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
assert point != null;
assert plugin != null;
if (point.getGroup() == OsmPoint.Group.BUG) {
plugin.getDBBug().deleteAllBugModifications(
(OsmNotesPoint) point);
} else if (point.getGroup() == OsmPoint.Group.POI) {
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) point);
}
}
});
new DialogInterface.OnClickListener() {
public void onClick(@Nullable DialogInterface dialog, int id) {
OsmEditingPlugin plugin =
OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
assert point != null;
assert plugin != null;
if (point.getGroup() == OsmPoint.Group.BUG) {
plugin.getDBBug().deleteAllBugModifications(
(OsmNotesPoint) point);
} else if (point.getGroup() == OsmPoint.Group.POI) {
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) point);
}
}
});
return builder.create();
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -9,13 +10,24 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmBugsLayer;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmEditsUploadListener;
import net.osmand.plus.osmedit.OsmEditsUploadListenerHelper;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.UploadOpenstreetmapPointAsyncTask;
import java.util.Map;
public class SendPoiDialogFragment extends DialogFragment {
public static final String TAG = "SendPoiDialogFragment";
@ -33,13 +45,15 @@ public class SendPoiDialogFragment extends DialogFragment {
final OsmPoint[] poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
final View messageEditTextLabel = view.findViewById(R.id.messageEditTextLabel);
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
final EditText messageEditText = (EditText) view.findViewById(R.id.messageEditText);
final EditText userNameEditText = (EditText) view.findViewById(R.id.userNameEditText);
final EditText passwordEditText = (EditText) view.findViewById(R.id.passwordEditText);
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
final EditText userNameEditText = (EditText) view.findViewById(R.id.user_name_field);
final EditText passwordEditText = (EditText) view.findViewById(R.id.password_field);
final View messageLabel = view.findViewById(R.id.message_label);
final View userNameLabel = view.findViewById(R.id.osm_user_name_label);
final View passwordLabel = view.findViewById(R.id.osm_user_password_label);
final CheckBox closeChangeSetCheckBox =
(CheckBox) view.findViewById(R.id.closeChangeSetCheckBox);
(CheckBox) view.findViewById(R.id.close_change_set_checkbox);
messageEditText.setText(comment);
final OsmandSettings settings = ((OsmandApplication) getActivity().getApplication())
.getSettings();
@ -53,9 +67,18 @@ public class SendPoiDialogFragment extends DialogFragment {
break;
}
}
messageEditTextLabel.setVisibility(hasOsmPOI ? View.VISIBLE : View.GONE);
messageLabel.setVisibility(hasOsmPOI ? View.VISIBLE : View.GONE);
messageEditText.setVisibility(hasOsmPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setVisibility(hasOsmPOI ? View.VISIBLE : View.GONE);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
userNameLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
userNameEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
}
});
final ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploader != null) {
@ -100,4 +123,36 @@ public class SendPoiDialogFragment extends DialogFragment {
public interface ProgressDialogPoiUploader {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously);
}
public static abstract class SimpleProgressDialogPoiUploader implements ProgressDialogPoiUploader {
@Override
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading,
R.string.local_openstreetmap_uploading,
ProgressDialog.STYLE_HORIZONTAL);
final MapActivity mapActivity = getMapActivity();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(mapActivity,
mapActivity.getString(R.string.local_openstreetmap_were_uploaded)) {
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
super.uploadEnded(loadErrorsMap);
mapActivity.getContextMenu().close();
OsmBugsLayer l = mapActivity.getMapView().getLayerByClass(OsmBugsLayer.class);
if(l != null) {
l.clearCache();
mapActivity.refreshMap();
}
}
};
dialog.show(mapActivity.getSupportFragmentManager(), ProgressDialogFragment.TAG);
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, points.length, closeChangeSet, anonymously);
uploadTask.execute(points);
}
@NonNull
abstract protected MapActivity getMapActivity();
}
}