Refactoring
This commit is contained in:
parent
58c4e56b44
commit
34e4ff33ae
5 changed files with 19 additions and 51 deletions
|
@ -12,7 +12,6 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.OsmandApplication;
|
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
@ -24,9 +23,6 @@ import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.dialogs.ProgressDialogPoiUploader;
|
import net.osmand.plus.osmedit.dialogs.ProgressDialogPoiUploader;
|
||||||
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
|
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
|
||||||
import net.osmand.util.Algorithms;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -78,7 +74,6 @@ public class DashOsmEditsFragment extends DashBaseFragment
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpenDash() {
|
public void onOpenDash() {
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
|
@ -121,13 +116,7 @@ public class DashOsmEditsFragment extends DashBaseFragment
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (point.getGroup() == OsmPoint.Group.POI) {
|
if (point.getGroup() == OsmPoint.Group.POI) {
|
||||||
selectedPoint = point;
|
selectedPoint = point;
|
||||||
OsmandApplication app = getMyApplication();
|
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
|
||||||
OsmandSettings settings = app.getSettings();
|
|
||||||
OsmOAuthAuthorizationAdapter authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
|
||||||
boolean isLogged = authorizationAdapter.isValidToken()
|
|
||||||
|| !Algorithms.isEmpty(settings.USER_NAME.get())
|
|
||||||
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|
|
||||||
if (isLogged) {
|
|
||||||
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{point});
|
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{point});
|
||||||
} else {
|
} else {
|
||||||
LoginBottomSheetFragment.showInstance(getActivity().getSupportFragmentManager(),
|
LoginBottomSheetFragment.showInstance(getActivity().getSupportFragmentManager(),
|
||||||
|
|
|
@ -35,11 +35,11 @@ public class HandleOsmNoteAsyncTask extends AsyncTask<Void, Void, OsmBugResult>
|
||||||
@Override
|
@Override
|
||||||
protected OsmBugResult doInBackground(Void... params) {
|
protected OsmBugResult doInBackground(Void... params) {
|
||||||
if (bug != null) {
|
if (bug != null) {
|
||||||
OsmNotesPoint pnt = new OsmNotesPoint();
|
OsmNotesPoint point = new OsmNotesPoint();
|
||||||
pnt.setId(bug.getId());
|
point.setId(bug.getId());
|
||||||
pnt.setLatitude(bug.getLatitude());
|
point.setLatitude(bug.getLatitude());
|
||||||
pnt.setLongitude(bug.getLongitude());
|
point.setLongitude(bug.getLongitude());
|
||||||
return osmbugsUtil.commit(pnt, text, action);
|
return osmbugsUtil.commit(point, text, action);
|
||||||
} else if (point != null) {
|
} else if (point != null) {
|
||||||
osmbugsUtil = local;
|
osmbugsUtil = local;
|
||||||
return osmbugsUtil.modify(point, text);
|
return osmbugsUtil.modify(point, text);
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package net.osmand.plus.osmedit;
|
package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -359,20 +357,18 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createBugDialog(final boolean offline, String text, int titleTextId, int posButtonTextId,
|
private void createBugDialog(final boolean offline, String text, int titleTextId, int posButtonTextId,
|
||||||
final Action action, final OpenStreetNote bug, final OsmNotesPoint point) {
|
final Action action, final OpenStreetNote bug, OsmNotesPoint point) {
|
||||||
@SuppressLint("InflateParams") final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null);
|
|
||||||
if (offline) {
|
if (offline) {
|
||||||
activity.getContextMenu().close();
|
activity.getContextMenu().close();
|
||||||
BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), getOsmbugsUtil(bug), local, text,
|
BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), getOsmbugsUtil(bug), local, text,
|
||||||
titleTextId, posButtonTextId, action, bug, point, getHandleBugListener());
|
titleTextId, posButtonTextId, action, bug, point, getHandleBugListener());
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
OsmNotesPoint pnt = new OsmNotesPoint();
|
OsmNotesPoint notesPoint = new OsmNotesPoint();
|
||||||
pnt.setAction(action);
|
notesPoint.setAction(action);
|
||||||
pnt.setId(bug.getId());
|
notesPoint.setId(bug.getId());
|
||||||
pnt.setLatitude(bug.getLatitude());
|
notesPoint.setLatitude(bug.getLatitude());
|
||||||
pnt.setLongitude(bug.getLongitude());
|
notesPoint.setLongitude(bug.getLongitude());
|
||||||
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), new OsmPoint[]{pnt});
|
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), new OsmPoint[]{notesPoint});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,19 +423,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUserName() {
|
|
||||||
return ((OsmandApplication) activity.getApplication()).getSettings().USER_NAME.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTextAndUpdateUserPwd(final View view) {
|
|
||||||
String text = getMessageText(view);
|
|
||||||
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) {
|
private String getMessageText(final View view) {
|
||||||
return ((EditText) view.findViewById(R.id.message_field)).getText().toString();
|
return ((EditText) view.findViewById(R.id.message_field)).getText().toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ import net.osmand.plus.osmedit.OsmPoint.Group;
|
||||||
import net.osmand.plus.osmedit.dialogs.ProgressDialogPoiUploader;
|
import net.osmand.plus.osmedit.dialogs.ProgressDialogPoiUploader;
|
||||||
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
|
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -634,13 +633,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements ProgressDial
|
||||||
FragmentActivity activity = getActivity();
|
FragmentActivity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
if (hasPoiGroup(points)) {
|
if (hasPoiGroup(points)) {
|
||||||
OsmandApplication app = getMyApplication();
|
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
|
||||||
OsmandSettings settings = app.getSettings();
|
|
||||||
OsmOAuthAuthorizationAdapter authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
|
||||||
boolean isLogged = authorizationAdapter.isValidToken()
|
|
||||||
|| !Algorithms.isEmpty(settings.USER_NAME.get())
|
|
||||||
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
|
|
||||||
if (isLogged) {
|
|
||||||
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), points);
|
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), points);
|
||||||
} else {
|
} else {
|
||||||
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
|
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
|
||||||
|
|
|
@ -28,9 +28,8 @@ public class OsmOAuthHelper {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmOAuthAuthorizationAdapter updateAdapter(){
|
public void updateAdapter() {
|
||||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||||
return authorizationAdapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeListener(OsmAuthorizationListener listener) {
|
public void removeListener(OsmAuthorizationListener listener) {
|
||||||
|
@ -76,6 +75,10 @@ public class OsmOAuthHelper {
|
||||||
return authorizationAdapter.isValidToken();
|
return authorizationAdapter.isValidToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLogged() {
|
||||||
|
return isValidToken() || isLoginExists();
|
||||||
|
}
|
||||||
|
|
||||||
public interface OsmAuthorizationListener {
|
public interface OsmAuthorizationListener {
|
||||||
void authorizationCompleted();
|
void authorizationCompleted();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue