3
3
import android .content .Context ;
4
4
import android .net .Uri ;
5
5
import android .util .AttributeSet ;
6
+ import android .view .LayoutInflater ;
6
7
import android .view .View ;
7
- import android .widget .ImageView ;
8
- import android .widget .TextView ;
9
8
10
9
import androidx .annotation .NonNull ;
11
10
import androidx .annotation .Nullable ;
12
11
13
12
import fr .free .nrw .commons .campaigns .models .Campaign ;
13
+ import fr .free .nrw .commons .databinding .LayoutCampaginBinding ;
14
14
import fr .free .nrw .commons .theme .BaseActivity ;
15
15
import fr .free .nrw .commons .utils .DateUtil ;
16
16
17
17
import java .text .ParseException ;
18
18
import java .util .Date ;
19
19
20
- import butterknife .BindView ;
21
- import butterknife .ButterKnife ;
22
20
import fr .free .nrw .commons .R ;
23
21
import fr .free .nrw .commons .Utils ;
24
22
import fr .free .nrw .commons .contributions .MainActivity ;
31
29
*/
32
30
public class CampaignView extends SwipableCardView {
33
31
Campaign campaign ;
32
+ private LayoutCampaginBinding binding ;
34
33
private ViewHolder viewHolder ;
35
34
36
35
public static final String CAMPAIGNS_DEFAULT_PREFERENCE = "displayCampaignsCardView" ;
@@ -76,8 +75,8 @@ public void setCampaign(final Campaign campaign) {
76
75
}
77
76
78
77
private void init () {
79
- final View rootView = inflate (getContext (), R . layout . layout_campagin , this );
80
- viewHolder = new ViewHolder (rootView );
78
+ binding = LayoutCampaginBinding . inflate (LayoutInflater . from ( getContext ()), this , true );
79
+ viewHolder = new ViewHolder ();
81
80
setOnClickListener (view -> {
82
81
if (campaign != null ) {
83
82
if (campaign .isWLMCampaign ()) {
@@ -90,35 +89,24 @@ private void init() {
90
89
}
91
90
92
91
public class ViewHolder {
93
-
94
- @ BindView (R .id .iv_campaign )
95
- ImageView ivCampaign ;
96
- @ BindView (R .id .tv_title ) TextView tvTitle ;
97
- @ BindView (R .id .tv_description ) TextView tvDescription ;
98
- @ BindView (R .id .tv_dates ) TextView tvDates ;
99
-
100
- public ViewHolder (View itemView ) {
101
- ButterKnife .bind (this , itemView );
102
- }
103
-
104
92
public void init () {
105
93
if (campaign != null ) {
106
- ivCampaign .setImageDrawable (
94
+ binding . ivCampaign .setImageDrawable (
107
95
getResources ().getDrawable (R .drawable .ic_campaign ));
108
96
109
- tvTitle .setText (campaign .getTitle ());
110
- tvDescription .setText (campaign .getDescription ());
97
+ binding . tvTitle .setText (campaign .getTitle ());
98
+ binding . tvDescription .setText (campaign .getDescription ());
111
99
try {
112
100
if (campaign .isWLMCampaign ()) {
113
- tvDates .setText (
101
+ binding . tvDates .setText (
114
102
String .format ("%1s - %2s" , campaign .getStartDate (),
115
103
campaign .getEndDate ()));
116
104
} else {
117
105
final Date startDate = CommonsDateUtil .getIso8601DateFormatShort ()
118
106
.parse (campaign .getStartDate ());
119
107
final Date endDate = CommonsDateUtil .getIso8601DateFormatShort ()
120
108
.parse (campaign .getEndDate ());
121
- tvDates .setText (String .format ("%1s - %2s" , DateUtil .getExtraShortDateString (startDate ),
109
+ binding . tvDates .setText (String .format ("%1s - %2s" , DateUtil .getExtraShortDateString (startDate ),
122
110
DateUtil .getExtraShortDateString (endDate )));
123
111
}
124
112
} catch (final ParseException e ) {
0 commit comments