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 net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
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.SendOsmNoteBottomSheetFragment;
|
||||
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.List;
|
||||
|
@ -78,7 +74,6 @@ public class DashOsmEditsFragment extends DashBaseFragment
|
|||
return view;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onOpenDash() {
|
||||
if (plugin == null) {
|
||||
|
@ -121,13 +116,7 @@ public class DashOsmEditsFragment extends DashBaseFragment
|
|||
public void onClick(View v) {
|
||||
if (point.getGroup() == OsmPoint.Group.POI) {
|
||||
selectedPoint = point;
|
||||
OsmandApplication app = getMyApplication();
|
||||
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) {
|
||||
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
|
||||
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[]{point});
|
||||
} else {
|
||||
LoginBottomSheetFragment.showInstance(getActivity().getSupportFragmentManager(),
|
||||
|
|
|
@ -35,11 +35,11 @@ public class HandleOsmNoteAsyncTask extends AsyncTask<Void, Void, OsmBugResult>
|
|||
@Override
|
||||
protected OsmBugResult doInBackground(Void... params) {
|
||||
if (bug != null) {
|
||||
OsmNotesPoint pnt = new OsmNotesPoint();
|
||||
pnt.setId(bug.getId());
|
||||
pnt.setLatitude(bug.getLatitude());
|
||||
pnt.setLongitude(bug.getLongitude());
|
||||
return osmbugsUtil.commit(pnt, text, action);
|
||||
OsmNotesPoint point = new OsmNotesPoint();
|
||||
point.setId(bug.getId());
|
||||
point.setLatitude(bug.getLatitude());
|
||||
point.setLongitude(bug.getLongitude());
|
||||
return osmbugsUtil.commit(point, text, action);
|
||||
} else if (point != null) {
|
||||
osmbugsUtil = local;
|
||||
return osmbugsUtil.modify(point, text);
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.util.Xml;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
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,
|
||||
final Action action, final OpenStreetNote bug, final OsmNotesPoint point) {
|
||||
@SuppressLint("InflateParams") final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null);
|
||||
final Action action, final OpenStreetNote bug, OsmNotesPoint point) {
|
||||
if (offline) {
|
||||
activity.getContextMenu().close();
|
||||
BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), getOsmbugsUtil(bug), local, text,
|
||||
titleTextId, posButtonTextId, action, bug, point, getHandleBugListener());
|
||||
return;
|
||||
} else {
|
||||
OsmNotesPoint pnt = new OsmNotesPoint();
|
||||
pnt.setAction(action);
|
||||
pnt.setId(bug.getId());
|
||||
pnt.setLatitude(bug.getLatitude());
|
||||
pnt.setLongitude(bug.getLongitude());
|
||||
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), new OsmPoint[]{pnt});
|
||||
OsmNotesPoint notesPoint = new OsmNotesPoint();
|
||||
notesPoint.setAction(action);
|
||||
notesPoint.setId(bug.getId());
|
||||
notesPoint.setLatitude(bug.getLatitude());
|
||||
notesPoint.setLongitude(bug.getLongitude());
|
||||
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) {
|
||||
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.SendOsmNoteBottomSheetFragment;
|
||||
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.settings.backend.OsmandSettings;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -634,13 +633,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements ProgressDial
|
|||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
if (hasPoiGroup(points)) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
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) {
|
||||
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
|
||||
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), points);
|
||||
} else {
|
||||
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
|
||||
|
|
|
@ -28,9 +28,8 @@ public class OsmOAuthHelper {
|
|||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public OsmOAuthAuthorizationAdapter updateAdapter(){
|
||||
public void updateAdapter() {
|
||||
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
return authorizationAdapter;
|
||||
}
|
||||
|
||||
public void removeListener(OsmAuthorizationListener listener) {
|
||||
|
@ -76,6 +75,10 @@ public class OsmOAuthHelper {
|
|||
return authorizationAdapter.isValidToken();
|
||||
}
|
||||
|
||||
public boolean isLogged() {
|
||||
return isValidToken() || isLoginExists();
|
||||
}
|
||||
|
||||
public interface OsmAuthorizationListener {
|
||||
void authorizationCompleted();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue