Add BottomSheet with refresh and logout.
BIN
android/res/drawable-hdpi/ic_leaderboard.png
Normal file
After Width: | Height: | Size: 283 B |
BIN
android/res/drawable-hdpi/ic_more.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
android/res/drawable-ldpi/ic_leadreboard.png
Normal file
After Width: | Height: | Size: 185 B |
BIN
android/res/drawable-ldpi/ic_more.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
android/res/drawable-mdpi/ic_leaderboard.png
Normal file
After Width: | Height: | Size: 215 B |
BIN
android/res/drawable-mdpi/ic_more.png
Normal file
After Width: | Height: | Size: 88 B |
BIN
android/res/drawable-xhdpi/ic_leaderboard.png
Normal file
After Width: | Height: | Size: 341 B |
BIN
android/res/drawable-xhdpi/ic_more.png
Normal file
After Width: | Height: | Size: 115 B |
BIN
android/res/drawable-xxhdpi/ic_leaderboard.png
Normal file
After Width: | Height: | Size: 496 B |
BIN
android/res/drawable-xxhdpi/ic_more.png
Normal file
After Width: | Height: | Size: 150 B |
|
@ -15,13 +15,13 @@
|
|||
android:theme="@style/MwmWidget.ToolbarTheme"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<ImageView
|
||||
android:id="@+id/logout"
|
||||
android:id="@+id/more"
|
||||
android:layout_width="?actionBarSize"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_logout"
|
||||
android:src="@drawable/ic_more"
|
||||
android:visibility="gone"/>
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
|
@ -225,7 +225,7 @@
|
|||
android:layout_marginLeft="@dimen/margin_half"
|
||||
android:layout_marginStart="@dimen/margin_half"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_device"
|
||||
android:src="@drawable/ic_leaderboard"
|
||||
android:tint="?iconTint"/>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -3,16 +3,21 @@ package com.mapswithme.maps.editor;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.editor.data.UserStats;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
|
@ -23,12 +28,45 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
private View mSentBlock;
|
||||
private TextView mEditsSent;
|
||||
private TextView mEditsSentDate;
|
||||
private View mLogout;
|
||||
private View mMore;
|
||||
private View mAuthBlock;
|
||||
private View mRatingBlock;
|
||||
private TextView mEditorRank;
|
||||
private TextView mEditorLevelUp;
|
||||
|
||||
private enum MenuItem
|
||||
{
|
||||
LOGOUT(R.drawable.ic_logout, R.string.logout)
|
||||
{
|
||||
@Override
|
||||
void invoke(ProfileFragment fragment)
|
||||
{
|
||||
OsmOAuth.clearAuthorization();
|
||||
fragment.refreshViews();
|
||||
}
|
||||
},
|
||||
|
||||
REFRESH(R.drawable.ic_update, R.string.refresh)
|
||||
{
|
||||
@Override
|
||||
void invoke(ProfileFragment fragment)
|
||||
{
|
||||
OsmOAuth.nativeUpdateOsmUserStats(OsmOAuth.getUsername(), true /* forceUpdate */);
|
||||
}
|
||||
};
|
||||
|
||||
final @DrawableRes int icon;
|
||||
final @StringRes int title;
|
||||
|
||||
MenuItem(@DrawableRes int icon, @StringRes int title)
|
||||
{
|
||||
this.icon = icon;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
abstract void invoke(ProfileFragment fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
|
@ -37,13 +75,13 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
initViews(view);
|
||||
refreshViews();
|
||||
OsmOAuth.setUserStatsListener(this);
|
||||
OsmOAuth.nativeUpdateOsmUserStats(OsmOAuth.getUsername(), false /*forceUpdate*/);
|
||||
OsmOAuth.nativeUpdateOsmUserStats(OsmOAuth.getUsername(), false /* forceUpdate */);
|
||||
}
|
||||
|
||||
private void initViews(View view)
|
||||
{
|
||||
mLogout = mToolbarController.findViewById(R.id.logout);
|
||||
mLogout.setOnClickListener(this);
|
||||
mMore = mToolbarController.findViewById(R.id.more);
|
||||
mMore.setOnClickListener(this);
|
||||
View editsBlock = view.findViewById(R.id.block_edits);
|
||||
UiUtils.show(editsBlock);
|
||||
mLocalBlock = editsBlock.findViewById(R.id.local_edits);
|
||||
|
@ -64,13 +102,13 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
{
|
||||
if (OsmOAuth.isAuthorized())
|
||||
{
|
||||
UiUtils.show(mLogout, mRatingBlock, mSentBlock);
|
||||
UiUtils.show(mMore, mRatingBlock, mSentBlock);
|
||||
UiUtils.hide(mAuthBlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
UiUtils.show(mAuthBlock);
|
||||
UiUtils.hide(mLogout, mRatingBlock, mSentBlock);
|
||||
UiUtils.hide(mMore, mRatingBlock, mSentBlock);
|
||||
}
|
||||
|
||||
final long[] stats = Editor.nativeGetStats();
|
||||
|
@ -102,7 +140,7 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
editsDate = DateUtils.formatDateTime(getActivity(), uploadSeconds * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
|
||||
}
|
||||
mEditsSent.setText(edits);
|
||||
mEditsSentDate.setText(String.format(Locale.US, getString(R.string.last_update), editsDate));
|
||||
mEditsSentDate.setText(getString(R.string.last_update, editsDate));
|
||||
mEditorRank.setText(String.valueOf(rank));
|
||||
// FIXME show when it will be implemented on server
|
||||
// mEditorLevelUp.setText(levelFeat);
|
||||
|
@ -113,9 +151,8 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
{
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.logout:
|
||||
OsmOAuth.clearAuthorization();
|
||||
refreshViews();
|
||||
case R.id.more:
|
||||
showBottomSheet();
|
||||
break;
|
||||
case R.id.about_osm:
|
||||
startActivity(new Intent((Intent.ACTION_VIEW), Uri.parse(Constants.Url.OSM_ABOUT)));
|
||||
|
@ -134,4 +171,25 @@ public class ProfileFragment extends AuthFragment implements View.OnClickListene
|
|||
else
|
||||
refreshRatings(stats.editsCount, stats.uploadTimestampSeconds, stats.editorRank, stats.levelUp);
|
||||
}
|
||||
|
||||
private void showBottomSheet()
|
||||
{
|
||||
List<MenuItem> items = new ArrayList<>();
|
||||
items.add(MenuItem.REFRESH);
|
||||
items.add(MenuItem.LOGOUT);
|
||||
|
||||
BottomSheetHelper.Builder bs = BottomSheetHelper.create(getActivity());
|
||||
for (MenuItem item: items)
|
||||
bs.sheet(item.ordinal(), item.icon, item.title);
|
||||
|
||||
bs.listener(new android.view.MenuItem.OnMenuItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onMenuItemClick(android.view.MenuItem item)
|
||||
{
|
||||
MenuItem.values()[item.getItemId()].invoke(ProfileFragment.this);
|
||||
return false;
|
||||
}
|
||||
}).tint().show();
|
||||
}
|
||||
}
|
||||
|
|