[android] refactor profile and add changes loading indicator

Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
Arnaud Vergnet 2022-07-03 17:18:52 +02:00 committed by Roman Tsisyk
parent df48ab7b73
commit b56f07c245
9 changed files with 72 additions and 55 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 B

View file

@ -0,0 +1,10 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z" />
</vector>

View file

@ -15,13 +15,14 @@
android:theme="@style/MwmWidget.ToolbarTheme"
tools:ignore="UnusedAttribute">
<ImageView
android:id="@+id/more"
android:id="@+id/logout"
android:layout_width="?actionBarSize"
android:layout_height="?actionBarSize"
android:layout_gravity="end|center_vertical"
android:background="?selectableItemBackgroundBorderless"
android:scaleType="center"
android:src="@drawable/ic_more" />
android:src="@drawable/ic_logout"
android:contentDescription="@string/logout" />
</androidx.appcompat.widget.Toolbar>
<ScrollView
@ -42,23 +43,35 @@
android:animateLayoutChanges="true"
android:background="?colorPrimary"
android:orientation="vertical"
android:padding="@dimen/margin_base"
android:visibility="visible">
android:padding="@dimen/margin_base">
<LinearLayout
android:id="@+id/sent_edits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/margin_base"
android:orientation="vertical">
<TextView
android:id="@+id/edits_count"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="112dp"
android:gravity="center"
android:textColor="@color/text_light"
android:textSize="96sp"
android:textStyle="bold"
tools:text="244"/>
android:layout_height="112dp">
<TextView
android:id="@+id/edits_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/text_light"
android:textSize="96sp"
android:textStyle="bold"
tools:text="244"/>
<ProgressBar
android:id="@+id/edits_count_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="@dimen/margin_base"
android:indeterminateTint="@color/text_light"
android:visibility="gone"
tools:visibility="visible"/>
</FrameLayout>
<TextView
android:layout_width="match_parent"

View file

@ -45,7 +45,7 @@
tools:text="42000000" />
</LinearLayout>
<ImageView
android:id="@id/more"
android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"

View file

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -15,30 +16,13 @@ import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
import com.mapswithme.util.Constants;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.bottomsheet.MenuBottomSheetFragment;
import com.mapswithme.util.bottomsheet.MenuBottomSheetItem;
import com.mapswithme.util.concurrency.ThreadPool;
import com.mapswithme.util.concurrency.UiThread;
import java.util.ArrayList;
public class ProfileFragment extends BaseMwmToolbarFragment implements View.OnClickListener
public class ProfileFragment extends BaseMwmToolbarFragment
{
private TextView mEditsSent;
private void onLogoutActionSelected(final ProfileFragment fragment)
{
new AlertDialog.Builder(fragment.requireContext())
.setMessage(R.string.are_you_sure)
.setPositiveButton(android.R.string.ok, (dialog, which) ->
{
OsmOAuth.clearAuthorization(fragment.requireContext());
fragment.refreshViews();
})
.setNegativeButton(android.R.string.no, null)
.create()
.show();
}
private ProgressBar mEditsSentProgress;
@Nullable
@Override
@ -58,14 +42,15 @@ public class ProfileFragment extends BaseMwmToolbarFragment implements View.OnCl
private void initViews(View view)
{
View more = getToolbarController().getToolbar().findViewById(R.id.more);
more.setOnClickListener(this);
View logoutButton = getToolbarController().getToolbar().findViewById(R.id.logout);
logoutButton.setOnClickListener((v) -> logout());
View editsBlock = view.findViewById(R.id.block_edits);
UiUtils.show(editsBlock);
View sentBlock = editsBlock.findViewById(R.id.sent_edits);
mEditsSent = sentBlock.findViewById(R.id.edits_count);
view.findViewById(R.id.about_osm).setOnClickListener(this);
view.findViewById(R.id.osm_history).setOnClickListener(this);
mEditsSentProgress = sentBlock.findViewById(R.id.edits_count_progress);
view.findViewById(R.id.about_osm).setOnClickListener((v) -> openOsmAboutUrl());
view.findViewById(R.id.osm_history).setOnClickListener((v) -> openOsmHistoryUrl());
}
private void refreshViews()
@ -74,8 +59,17 @@ public class ProfileFragment extends BaseMwmToolbarFragment implements View.OnCl
{
// Update the number of uploaded changesets from OSM.
ThreadPool.getWorker().execute(() -> {
if (mEditsSent.getText().equals(""))
{
UiUtils.hide(mEditsSent);
UiUtils.show(mEditsSentProgress);
}
final int count = OsmOAuth.getOsmChangesetsCount(requireContext(), getParentFragmentManager());
UiThread.run(() -> mEditsSent.setText(String.valueOf(count)));
UiThread.run(() -> {
mEditsSent.setText(String.valueOf(count));
UiUtils.show(mEditsSent);
UiUtils.hide(mEditsSentProgress);
});
});
}
else
@ -87,27 +81,27 @@ public class ProfileFragment extends BaseMwmToolbarFragment implements View.OnCl
}
}
@Override
public void onClick(View v)
private void logout()
{
switch (v.getId())
{
case R.id.more:
showBottomSheet();
break;
case R.id.about_osm:
startActivity(new Intent((Intent.ACTION_VIEW), Uri.parse(Constants.Url.OSM_ABOUT)));
break;
case R.id.osm_history:
startActivity(new Intent((Intent.ACTION_VIEW), Uri.parse(OsmOAuth.getHistoryUrl(requireContext()))));
break;
}
new AlertDialog.Builder(requireContext())
.setMessage(R.string.are_you_sure)
.setPositiveButton(android.R.string.ok, (dialog, which) ->
{
OsmOAuth.clearAuthorization(requireContext());
refreshViews();
})
.setNegativeButton(android.R.string.no, null)
.create()
.show();
}
private void showBottomSheet()
private void openOsmAboutUrl()
{
ArrayList<MenuBottomSheetItem> items = new ArrayList<>();
items.add(new MenuBottomSheetItem(R.string.logout, R.drawable.ic_logout, () -> onLogoutActionSelected(ProfileFragment.this)));
new MenuBottomSheetFragment(items).show(getParentFragmentManager(), "profileBottomSheet");
startActivity(new Intent((Intent.ACTION_VIEW), Uri.parse(Constants.Url.OSM_ABOUT)));
}
private void openOsmHistoryUrl()
{
startActivity(new Intent((Intent.ACTION_VIEW), Uri.parse(OsmOAuth.getHistoryUrl(requireContext()))));
}
}