forked from organicmaps/organicmaps
[android] Clear edits and logout.
This commit is contained in:
parent
d0c5b36c11
commit
192ccec1e4
6 changed files with 94 additions and 23 deletions
|
@ -23,7 +23,7 @@
|
|||
android:layout_gravity="end|center_vertical"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_download_map"
|
||||
android:src="@drawable/ic_logout"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
|
|
@ -32,8 +32,9 @@
|
|||
|
||||
<com.mapswithme.maps.widget.CustomTextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/base_block_size"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base"
|
||||
android:minHeight="@dimen/base_block_size">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/osm_username"
|
||||
|
@ -45,9 +46,9 @@
|
|||
|
||||
<com.mapswithme.maps.widget.CustomTextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/base_block_size"
|
||||
android:layout_marginBottom="@dimen/margin_base"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base"
|
||||
android:minHeight="@dimen/base_block_size">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/osm_password"
|
||||
|
@ -58,15 +59,29 @@
|
|||
|
||||
</com.mapswithme.maps.widget.CustomTextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/editor_auth_btn_height"
|
||||
android:layout_marginBottom="@dimen/margin_base"
|
||||
android:background="?buttonAccent"
|
||||
android:text="Log in"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_base">
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/editor_auth_btn_height"
|
||||
android:background="?buttonAccent"
|
||||
android:text="Log in"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/osm_login_progress"
|
||||
android:layout_width="@dimen/editor_auth_btn_height"
|
||||
android:layout_height="@dimen/editor_auth_btn_height"
|
||||
android:layout_gravity="center"
|
||||
android:elevation="@dimen/fab_elevation"
|
||||
tools:targetApi="lollipop"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lost_password"
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
android:id="@+id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/margin_half"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/abc_ic_menu_moreoverflow_mtrl_alpha"
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps.editor;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.LightingColorFilter;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -10,16 +11,24 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.widget.ToolbarController;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickListener
|
||||
{
|
||||
private ProgressBar mProgress;
|
||||
private TextView mTvLogin;
|
||||
private View mTvLostPassword;
|
||||
|
||||
private static class AuthToolbarController extends ToolbarController
|
||||
{
|
||||
AuthToolbarController(View root, Activity activity)
|
||||
|
@ -27,6 +36,7 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
super(root, activity);
|
||||
mToolbar.setNavigationIcon(Graphics.tint(activity,
|
||||
activity.getResources().getDrawable(R.drawable.ic_cancel)));
|
||||
mToolbar.setTitleTextColor(MwmApplication.get().getResources().getColor(R.color.text_dark));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,8 +63,13 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
mToolbarController.setTitle("Log In");
|
||||
mEtLogin = (EditText) view.findViewById(R.id.osm_username);
|
||||
mEtPassword = (EditText) view.findViewById(R.id.osm_password);
|
||||
view.findViewById(R.id.login).setOnClickListener(this);
|
||||
view.findViewById(R.id.lost_password).setOnClickListener(this);
|
||||
mTvLogin = (TextView) view.findViewById(R.id.login);
|
||||
mTvLogin.setOnClickListener(this);
|
||||
mTvLostPassword = view.findViewById(R.id.lost_password);
|
||||
mTvLostPassword.setOnClickListener(this);
|
||||
mProgress = (ProgressBar) view.findViewById(R.id.osm_login_progress);
|
||||
mProgress.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000, 0xFFFFFF));
|
||||
UiUtils.hide(mProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +81,6 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// TODO show/hide spinners
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.login:
|
||||
|
@ -82,14 +96,16 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
{
|
||||
final String username = mEtLogin.getText().toString();
|
||||
final String password = mEtPassword.getText().toString();
|
||||
enableInput(false);
|
||||
UiUtils.show(mProgress);
|
||||
mTvLogin.setText("");
|
||||
|
||||
ThreadPool.getWorker().execute(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final String[] auth;
|
||||
auth = OsmOAuth.nativeAuthWithPassword(username, password);
|
||||
final String[] auth = OsmOAuth.nativeAuthWithPassword(username, password);
|
||||
|
||||
UiThread.run(new Runnable()
|
||||
{
|
||||
|
@ -99,6 +115,9 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
if (!isAdded())
|
||||
return;
|
||||
|
||||
enableInput(true);
|
||||
UiUtils.hide(mProgress);
|
||||
mTvLogin.setText("Login");
|
||||
processAuth(auth);
|
||||
}
|
||||
});
|
||||
|
@ -106,6 +125,14 @@ public class OsmAuthFragment extends BaseAuthFragment implements View.OnClickLis
|
|||
});
|
||||
}
|
||||
|
||||
private void enableInput(boolean enable)
|
||||
{
|
||||
mEtPassword.setEnabled(enable);
|
||||
mEtLogin.setEnabled(enable);
|
||||
mTvLogin.setEnabled(enable);
|
||||
mTvLostPassword.setEnabled(enable);
|
||||
}
|
||||
|
||||
private void recoverPassword()
|
||||
{
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.Url.OSM_RECOVER_PASSWORD)));
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
|
||||
|
@ -32,7 +33,8 @@ public final class OsmOAuth
|
|||
|
||||
public static boolean isAuthorized()
|
||||
{
|
||||
return MwmApplication.prefs().contains(PREF_OSM_TOKEN) && MwmApplication.prefs().contains(PREF_OSM_SECRET);
|
||||
return MwmApplication.prefs().contains(PREF_OSM_TOKEN) &&
|
||||
MwmApplication.prefs().contains(PREF_OSM_SECRET);
|
||||
}
|
||||
|
||||
public static String getAuthToken()
|
||||
|
@ -50,7 +52,15 @@ public final class OsmOAuth
|
|||
MwmApplication.prefs().edit()
|
||||
.putString(PREF_OSM_TOKEN, token)
|
||||
.putString(PREF_OSM_SECRET, secret)
|
||||
.commit();
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static void clearAuthorization()
|
||||
{
|
||||
MwmApplication.prefs().edit()
|
||||
.remove(PREF_OSM_TOKEN)
|
||||
.remove(PREF_OSM_SECRET)
|
||||
.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,11 +3,14 @@ package com.mapswithme.maps.editor;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class ProfileFragment extends AuthFragment implements View.OnClickListener
|
||||
|
@ -39,6 +42,7 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
((ImageView) localEdits.findViewById(R.id.image)).setImageResource(R.drawable.ic_device);
|
||||
mEditsLocal = (TextView) localEdits.findViewById(R.id.title);
|
||||
mEditsMore = localEdits.findViewById(R.id.more);
|
||||
mEditsMore.setOnClickListener(this);
|
||||
UiUtils.hide(localEdits.findViewById(R.id.subtitle), localEdits.findViewById(R.id.more));
|
||||
final View sentEdits = mEditsBlock.findViewById(R.id.sent_edits);
|
||||
((ImageView) sentEdits.findViewById(R.id.image)).setImageResource(R.drawable.ic_upload);
|
||||
|
@ -68,18 +72,32 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
else
|
||||
// FIXME fix stats[2] element - now it wrongly contains seconds instead of millis
|
||||
UiUtils.setTextAndShow(mEditsSentDate, "Upload date : " + DateUtils.formatDateTime(getActivity(), stats[2] * 1000, 0));
|
||||
|
||||
UiUtils.showIf(stats[1] != stats[0], mEditsMore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// TODO show/hide spinners
|
||||
// TODO process clicks
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.logout:
|
||||
OsmOAuth.clearAuthorization();
|
||||
refreshViews();
|
||||
break;
|
||||
case R.id.more:
|
||||
BottomSheetHelper.create(getActivity())
|
||||
.sheet(Menu.NONE, R.drawable.ic_delete, R.string.delete)
|
||||
.listener(new MenuItem.OnMenuItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem)
|
||||
{
|
||||
Editor.nativeClearLocalEdits();
|
||||
refreshViews();
|
||||
return false;
|
||||
}
|
||||
}).tint().show();
|
||||
break;
|
||||
default:
|
||||
super.onClick(v);
|
||||
|
|
Loading…
Add table
Reference in a new issue