Changed statistics to badges

This commit is contained in:
yujing 2024-11-01 12:56:20 +11:00 committed by Yujing
parent 197855af0e
commit 776e099cde
5 changed files with 115 additions and 221 deletions

View file

@ -44,6 +44,7 @@ dependencies {
implementation 'com.github.pedrovgs:renderers:3.3.3'
implementation "org.maplibre.gl:android-sdk:$MAPLIBRE_VERSION"
implementation 'org.maplibre.gl:android-plugin-scalebar-v9:1.0.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'

View file

@ -2,12 +2,16 @@ package fr.free.nrw.commons.profile.achievements;
import android.accounts.Account;
import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.view.ContextThemeWrapper;
@ -28,6 +32,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
@ -92,10 +97,10 @@ public class AchievementsFragment extends CommonsDaggerSupportFragment {
binding.imagesUploadInfo.setOnClickListener(view -> showUploadInfo());
binding.imagesRevertedInfo.setOnClickListener(view -> showRevertedInfo());
binding.imagesUsedByWikiInfo.setOnClickListener(view -> showUsedByWikiInfo());
binding.imagesNearbyInfo.setOnClickListener(view -> showImagesViaNearbyInfo());
binding.imagesFeaturedInfo.setOnClickListener(view -> showFeaturedImagesInfo());
binding.thanksReceivedInfo.setOnClickListener(view -> showThanksReceivedInfo());
binding.qualityImagesInfo.setOnClickListener(view -> showQualityImagesInfo());
binding.wikidataEditsIcon.setOnClickListener(view -> showImagesViaNearbyInfo());
binding.qualityImageIcon.setOnClickListener(view -> showFeaturedImagesInfo());
binding.featuredImageIcon.setOnClickListener(view -> showThanksReceivedInfo());
binding.thanksImageIcon.setOnClickListener(view -> showThanksReceivedInfo());
// DisplayMetrics used to fetch the size of the screen
DisplayMetrics displayMetrics = new DisplayMetrics();
@ -132,11 +137,26 @@ public class AchievementsFragment extends CommonsDaggerSupportFragment {
binding.imageFeatured.setText("0");
binding.qualityImages.setText("0");
binding.achievementLevel.setText("0");
binding.thanksReceived.setText("0");
Map<ImageView,TextView> badgeMap = Map.of(
binding.wikidataEditsIcon,binding.wikidataEdits,
binding.featuredImageIcon,binding.imageFeatured,
binding.qualityImageIcon, binding.qualityImages,
binding.thanksImageIcon, binding.thanksReceived
);
badgeRender(badgeMap);
setMenuVisibility(true);
return rootView;
}
setWikidataEditCount();
setAchievements();
Map<ImageView,TextView> badgeMap = Map.of(
binding.wikidataEditsIcon,binding.wikidataEdits,
binding.featuredImageIcon,binding.imageFeatured,
binding.qualityImageIcon, binding.qualityImages,
binding.thanksImageIcon, binding.thanksReceived
);
badgeRender(badgeMap);
return rootView;
}
@ -479,4 +499,28 @@ public class AchievementsFragment extends CommonsDaggerSupportFragment {
}
return true;
}
/**
* list the badgeset and set the 0 one to gray
* @param badgeMap
*/
public void badgeRender(Map<ImageView, TextView> badgeMap){
for(Map.Entry<ImageView,TextView> badge:badgeMap.entrySet()){
TextView textView= badge.getValue();
ImageView imageView=badge.getKey();
if(textView.getText().equals("0")){
Grayfilter(imageView);
textView.setVisibility(View.GONE);
}
}
}
/**
* Set imageView element to Gray
* @param imageView
*/
public void Grayfilter(ImageView imageView){
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imageView.setColorFilter(filter);
}
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/divider_grey"/>
<corners android:radius="12dp"/>
</shape>

View file

@ -335,104 +335,53 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/statistics"
android:text="@string/badges"
style="?android:textAppearanceLarge"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginTop="@dimen/activity_margin_vertical"
android:textAllCaps="true"/>
<RelativeLayout
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginTop="@dimen/activity_margin_horizontal">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_badges"
app:flexWrap="wrap">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/images_nearby_info"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/wikidata_edits"
android:orientation="horizontal"
android:gravity="center_vertical">
android:padding="8dp"
>
<ImageView
android:id="@+id/wikidata_edits_icon"
android:layout_width="@dimen/overflow_icon_dimen"
android:layout_height="@dimen/overflow_icon_dimen"
android:layout_row="0"
android:layout_column="0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_custom_map_marker_dark" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/images_nearby_data"
style="?android:textAppearanceMedium"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/wikidata_edits_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/images_nearby_info_icon"
android:text="@string/statistics_wikidata_edits" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/wikidata_edits"
android:text="2"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_gravity="end|bottom"
android:background="@drawable/badge_number_background"
/>
<ImageView
android:layout_width="@dimen/medium_width"
android:layout_height="@dimen/medium_height"
android:id="@+id/images_nearby_info_icon"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_gravity="top"
app:layout_constraintLeft_toRightOf="@id/images_nearby_data"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/ic_info_outline_24dp"
app:tint="@color/primaryLightColor" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:textAppearanceMedium"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/half_standard_height"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_centerVertical="true"
tools:text="2"
android:id="@+id/wikidata_edits"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginTop="@dimen/activity_margin_horizontal">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/images_featured_info"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/image_featured"
android:orientation="horizontal"
android:gravity="center_vertical">
android:padding="8dp">
<ImageView
android:layout_width="@dimen/overflow_icon_dimen"
android:layout_height="@dimen/overflow_icon_dimen"
@ -441,71 +390,29 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/featured"
android:scaleType="centerCrop" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
style="?android:textAppearanceMedium"
android:id="@+id/images_featured_data"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/featured_image_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/images_featured_info_icon"
android:text="@string/statistics_featured" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image_featured"
android:text="2"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_gravity="end|bottom"
android:background="@drawable/badge_number_background"
/>
<ImageView
android:layout_width="@dimen/medium_width"
android:layout_height="@dimen/medium_height"
android:id="@+id/images_featured_info_icon"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/images_featured_data"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="top"
app:srcCompat="@drawable/ic_info_outline_24dp"
app:tint="@color/primaryLightColor" />
app:tint="@color/primaryLightColor" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:textAppearanceMedium"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_centerVertical="true"
tools:text="2"
android:id="@+id/image_featured"
android:layout_marginEnd="@dimen/half_standard_height"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginTop="@dimen/activity_margin_horizontal">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/quality_images_info"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/quality_images"
android:orientation="horizontal"
android:gravity="center_vertical">
android:padding="8dp">
<ImageView
android:layout_width="@dimen/overflow_icon_dimen"
android:layout_height="@dimen/overflow_icon_dimen"
@ -514,72 +421,29 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_quality_images_logo"
android:scaleType="centerInside" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
style="?android:textAppearanceMedium"
android:id="@+id/quality_images_data"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/quality_image_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/quality_images_info_icon"
android:text="@string/statistics_quality" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/quality_images"
android:text="2"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_gravity="end|bottom"
android:background="@drawable/badge_number_background"
/>
<ImageView
android:layout_width="@dimen/medium_width"
android:layout_height="@dimen/medium_height"
android:id="@+id/quality_images_info_icon"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/quality_images_data"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="top"
app:srcCompat="@drawable/ic_info_outline_24dp"
app:tint="@color/primaryLightColor" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:textAppearanceMedium"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_centerVertical="true"
tools:text="2"
android:text="0"
android:id="@+id/quality_images"
android:layout_marginEnd="@dimen/half_standard_height"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thanks_received_info"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/thanks_received"
android:orientation="horizontal"
android:gravity="center_vertical">
android:padding="8dp">
<ImageView
android:layout_width="@dimen/overflow_icon_dimen"
android:layout_height="@dimen/overflow_icon_dimen"
@ -590,49 +454,28 @@
android:scaleType="centerCrop" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
style="?android:textAppearanceMedium"
android:id="@+id/thanks_received_data"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_marginLeft="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
android:layout_marginRight="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/thanks_image_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/thanks_received_info_icon"
android:text="@string/statistics_thanks" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thanks_received"
android:text="2"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_gravity="end|bottom"
android:background="@drawable/badge_number_background"
/>
<ImageView
android:id="@+id/thanks_received_info_icon"
android:layout_width="@dimen/medium_width"
android:layout_height="@dimen/medium_height"
android:id="@+id/thanks_received_info_icon"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginEnd="@dimen/activity_margin_horizontal"
app:layout_constraintLeft_toRightOf="@id/thanks_received_data"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="top"
app:srcCompat="@drawable/ic_info_outline_24dp"
app:tint="@color/primaryLightColor" />
app:tint="@color/primaryLightColor"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:textAppearanceMedium"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/activity_margin_horizontal"
android:layout_marginStart="@dimen/activity_margin_horizontal"
android:layout_centerVertical="true"
tools:text="2"
android:id="@+id/thanks_received"
android:layout_marginEnd="@dimen/half_standard_height"
/>
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

View file

@ -370,7 +370,8 @@
<string name="delete">Delete</string>
<string name="Achievements">Achievements</string>
<string name="Profile">Profile</string>
<string name="statistics">Statistics</string>
<string name="statistics">Badges</string>
<string name="badges">Badges</string>
<string name="statistics_thanks">Thanks Received</string>
<string name="statistics_featured">Featured Images</string>
<string name="statistics_wikidata_edits">Images via \"Nearby Places\"</string>