Fix unnecessary logout

This commit is contained in:
Dima-1 2020-11-20 13:36:44 +02:00
parent a026824e08
commit 72ac363d7d

View file

@ -15,7 +15,6 @@ import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import net.osmand.PlatformUtil;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
@ -31,16 +30,12 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB;
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener, public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener,
OsmAuthorizationListener { OsmAuthorizationListener {
private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class);
private static final String OSM_LOGOUT = "osm_logout"; private static final String OSM_LOGOUT = "osm_logout";
private static final String OPEN_OSM_EDITS = "open_osm_edits"; private static final String OPEN_OSM_EDITS = "open_osm_edits";
public static final String OSM_LOGIN_DATA = "osm_login_data"; public static final String OSM_LOGIN_DATA = "osm_login_data";
@ -213,16 +208,19 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
} }
private void osmLogout() { private void osmLogout() {
if (isValidToken()) { boolean validToken = isValidToken();
settings.USER_ACCESS_TOKEN.resetToDefault(); if (validToken || isLoginExists()) {
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault(); if (validToken) {
authorizationAdapter.resetToken(); settings.USER_ACCESS_TOKEN.resetToDefault();
} else { settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
settings.USER_NAME.resetToDefault(); authorizationAdapter.resetToken();
settings.USER_PASSWORD.resetToDefault(); } else {
settings.USER_NAME.resetToDefault();
settings.USER_PASSWORD.resetToDefault();
}
app.showShortToastMessage(R.string.osm_edit_logout_success);
updateAllSettings();
} }
app.showShortToastMessage(R.string.osm_edit_logout_success);
updateAllSettings();
} }
@Override @Override