99import android .view .ViewGroup ;
1010
1111import fr .free .nrw .commons .R ;
12+ import fr .free .nrw .commons .upload .UploadService ;
13+ import timber .log .Timber ;
14+
15+ import static fr .free .nrw .commons .contributions .Contribution .STATE_FAILED ;
1216
1317class ContributionsListAdapter extends CursorAdapter {
1418
1519 private final ContributionDao contributionDao ;
20+ private Cursor allContributions ;
21+ private UploadService uploadService ;
1622
1723 public ContributionsListAdapter (Context context , Cursor c , int flags , ContributionDao contributionDao ) {
1824 super (context , c , flags );
1925 this .contributionDao = contributionDao ;
2026 }
2127
28+ public void setUploadService (Cursor allContributions , UploadService uploadService ) {
29+ this .allContributions = allContributions ;
30+ this .uploadService = uploadService ;
31+ }
32+
2233 @ Override
2334 public View newView (Context context , Cursor cursor , ViewGroup viewGroup ) {
2435 View parent = LayoutInflater .from (context )
@@ -37,20 +48,8 @@ public void bindView(View view, Context context, Cursor cursor) {
3748
3849 views .seqNumView .setText (String .valueOf (cursor .getPosition () + 1 ));
3950 views .seqNumView .setVisibility (View .VISIBLE );
51+ views .position = cursor .getPosition ();
4052
41- views .retryButton .setOnClickListener (new View .OnClickListener () {
42- @ Override
43- public void onClick (View view ) {
44- Log .d ("deneme" ,"Retry button is clicked" );
45- }
46- });
47-
48- views .cancelButton .setOnClickListener (new View .OnClickListener () {
49- @ Override
50- public void onClick (View view ) {
51- Log .d ("deneme" ,"Cancel button is clicked" );
52- }
53- });
5453
5554 switch (contribution .getState ()) {
5655 case Contribution .STATE_COMPLETED :
@@ -86,7 +85,45 @@ public void onClick(View view) {
8685 views .progressView .setVisibility (View .GONE );
8786 views .retryButton .setVisibility (View .VISIBLE );
8887 views .cancelButton .setVisibility (View .VISIBLE );
88+
89+ views .retryButton .setOnClickListener (new View .OnClickListener () {
90+ @ Override
91+ public void onClick (View view ) {
92+ Log .d ("deneme" ,"contex:" +context );
93+ Log .d ("deneme" ,"Retry button is clicked" );
94+ retryUpload (cursor );
95+ }
96+ });
97+
98+ views .cancelButton .setOnClickListener (new View .OnClickListener () {
99+ @ Override
100+ public void onClick (View view ) {
101+ Log .d ("deneme" ,"Cancel button is clicked" );
102+ }
103+ });
104+
105+
89106 break ;
90107 }
91108 }
109+
110+ /**
111+ * Retry upload when it is failed
112+ * @param cursor position of upload which will be retried
113+ */
114+ public void retryUpload (Cursor cursor ) {
115+ // TODO: first check for internet connection, if not display a message and do nothing.
116+ Log .d ("deneme" ,"Retrying i:" +cursor .getColumnName (1 ));
117+ Contribution c = contributionDao .fromCursor (cursor );
118+ if (c .getState () == STATE_FAILED ) {
119+ uploadService .queue (UploadService .ACTION_UPLOAD_FILE , c );
120+ Timber .d ("Restarting for %s" , c .toString ());
121+ Log .d ("deneme" ,"Restarting for %s" + c .getFilename ());
122+
123+ } else {
124+ Timber .d ("Skipping re-upload for non-failed %s" , c .toString ());
125+ Log .d ("deneme" ,"Skipping re-upload for non-failed %s" + c .getFilename ());
126+
127+ }
128+ }
92129}
0 commit comments