Add nearby custom card view class

This commit is contained in:
neslihanturan 2018-09-12 15:40:55 +03:00
parent 5f91d7de0c
commit 730dabd61c
6 changed files with 154 additions and 1 deletions

View file

@ -42,6 +42,7 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.media.MediaDetailPagerFragment; import fr.free.nrw.commons.media.MediaDetailPagerFragment;
import fr.free.nrw.commons.mwapi.MediaWikiApi; import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.nearby.NearbyNoificationCardView;
import fr.free.nrw.commons.nearby.NearbyPlaces; import fr.free.nrw.commons.nearby.NearbyPlaces;
import fr.free.nrw.commons.notification.Notification; import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationController; import fr.free.nrw.commons.notification.NotificationController;
@ -88,6 +89,9 @@ public class ContributionsFragment
public static final String CONTRIBUTION_LIST_FRAGMENT_TAG = "ContributionListFragmentTag"; public static final String CONTRIBUTION_LIST_FRAGMENT_TAG = "ContributionListFragmentTag";
public static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag"; public static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag";
public NearbyNoificationCardView nearbyNoificationCardView;
/** /**
* Since we will need to use parent activity on onAuthCookieAcquired, we have to wait * Since we will need to use parent activity on onAuthCookieAcquired, we have to wait
* fragment to be attached. Latch will be responsible for this sync. * fragment to be attached. Latch will be responsible for this sync.

View file

@ -0,0 +1,54 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextSwitcher;
import java.util.ArrayList;
import java.util.List;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.notification.Notification;
/**
* Custom card view for nearby notification card view on main screen, above contributions list
*/
public class NearbyNoificationCardView extends CardView{
private Context context;
private TextSwitcher notificationTextSwitcher;
private TextSwitcher notificationTimeSwitcher;
private ImageView notificationIcon;
public NearbyNoificationCardView(@NonNull Context context) {
super(context);
this.context = context;
init();
}
public NearbyNoificationCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
init();
}
public NearbyNoificationCardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
init();
}
private void init() {
View rootView = inflate(context, R.layout.nearby_card_view, this);
notificationTextSwitcher = rootView.findViewById(R.id.nearby_title);
notificationTimeSwitcher = rootView.findViewById(R.id.nearby_distance);
notificationIcon = rootView.findViewById(R.id.nearby_icon);
}
}

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector>

View file

@ -0,0 +1,86 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/mainCardBackround"
android:layout_centerVertical="true"
android:minHeight="72dp">
<ImageView
android:id="@+id/nearby_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:contentDescription="@string/no_image_found"
android:visibility="gone"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_location_white_24dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal"
android:layout_toRightOf="@id/nearby_icon"
android:weightSum="4"
>
<TextSwitcher
android:id="@+id/nearby_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_toRightOf="@id/nearby_icon"
android:layout_centerInParent="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
tools:text="test distance">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:singleLine="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:singleLine="true"
/>
</TextSwitcher>
<TextSwitcher
android:id="@+id/nearby_distance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:minWidth="48dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
tools:text="test distance">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:singleLine="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:singleLine="true"
/>
</TextSwitcher>
</LinearLayout>
</RelativeLayout>

View file

@ -18,6 +18,8 @@
<attr name="contributionsListBackground" format="reference"/> <attr name="contributionsListBackground" format="reference"/>
<attr name="mainTabBackground" format="reference"/> <attr name="mainTabBackground" format="reference"/>
<attr name="mainCardBackground" format="reference"/>
<declare-styleable name="CompatTextView"> <declare-styleable name="CompatTextView">
<attr name="drawablePadding" format="dimension"/> <attr name="drawablePadding" format="dimension"/>

View file

@ -21,6 +21,7 @@
<item name="buttonBackgroundPressed">@color/pressed_button_dark</item> <item name="buttonBackgroundPressed">@color/pressed_button_dark</item>
<item name="textDisabled">@color/disabled_button_text_color_dark</item> <item name="textDisabled">@color/disabled_button_text_color_dark</item>
<item name="textEnabled">@color/enabled_button_text_color_dark</item> <item name="textEnabled">@color/enabled_button_text_color_dark</item>
<item name="mainCardBackround">@color/main_background_dark</item>
</style> </style>
<style name="LightAppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="LightAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
@ -43,6 +44,7 @@
<item name="buttonBackgroundPressed">@color/pressed_button_light</item> <item name="buttonBackgroundPressed">@color/pressed_button_light</item>
<item name="textDisabled">@color/disabled_button_text_color_light</item> <item name="textDisabled">@color/disabled_button_text_color_light</item>
<item name="textEnabled">@color/enabled_button_text_color_light</item> <item name="textEnabled">@color/enabled_button_text_color_light</item>
<item name="mainCardBackround">@color/primaryDarkColor</item>
</style> </style>
<style name="DarkSpinnerTheme" parent="DarkAppTheme"> <style name="DarkSpinnerTheme" parent="DarkAppTheme">