mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge pull request #16 from brion/delete-failed
Retry and delete buttons for failed items
This commit is contained in:
commit
7e113eb16d
7 changed files with 95 additions and 10 deletions
|
|
@ -11,5 +11,19 @@
|
|||
android:icon="@android:drawable/ic_menu_view"
|
||||
android:title="@string/menu_open_in_browser"
|
||||
/>
|
||||
<item android:id="@+id/menu_retry_current_image"
|
||||
android:showAsAction="always|withText"
|
||||
android:icon="@android:drawable/ic_menu_revert"
|
||||
android:title="@string/menu_retry"
|
||||
android:visible="false"
|
||||
android:enabled="false"
|
||||
/>
|
||||
<item android:id="@+id/menu_abort_current_image"
|
||||
android:showAsAction="always|withText"
|
||||
android:icon="@android:drawable/ic_menu_delete"
|
||||
android:title="@string/menu_abort"
|
||||
android:visible="false"
|
||||
android:enabled="false"
|
||||
/>
|
||||
|
||||
</menu>
|
||||
|
|
@ -71,4 +71,6 @@
|
|||
<string name="menu_feedback">Menu item text that prompts user to send feedback to WMF via email</string>
|
||||
<string name="waiting_first_sync">Message shown on contributions list during first sync.</string>
|
||||
<string name="no_uploads_yet">Message shown on contribution list during non-first sync if no uploads present.</string>
|
||||
<string name="menu_retry">Menu item text prompting user to retry a failed upload.</string>
|
||||
<string name="menu_abort">Menu item text prompting user to abort and delete a failed upload.</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -84,4 +84,7 @@
|
|||
|
||||
<string name="waiting_first_sync">Waiting for first sync...</string>
|
||||
<string name="no_uploads_yet">You have not yet uploaded any photos.</string>
|
||||
|
||||
<string name="menu_retry">Retry</string>
|
||||
<string name="menu_abort">Abort</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -155,6 +155,19 @@ public class Contribution extends Media {
|
|||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
try {
|
||||
if(contentUri == null) {
|
||||
// noooo
|
||||
throw new RuntimeException("tried to delete item with no content URI");
|
||||
} else {
|
||||
client.delete(contentUri, null, null);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ContentValues toContentValues() {
|
||||
ContentValues cv = new ContentValues();
|
||||
|
|
|
|||
|
|
@ -120,6 +120,29 @@ public class ContributionsActivity
|
|||
mediaDetails.showImage(i);
|
||||
}
|
||||
|
||||
public void retryUpload(int i) {
|
||||
allContributions.moveToPosition(i);
|
||||
Contribution c = Contribution.fromCursor(allContributions);
|
||||
if(c.getState() == Contribution.STATE_FAILED) {
|
||||
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
|
||||
Log.d("Commons", "Restarting for" + c.toContentValues().toString());
|
||||
} else {
|
||||
Log.d("Commons", "Skipping re-upload for non-failed " + c.toContentValues().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteUpload(int i) {
|
||||
allContributions.moveToPosition(i);
|
||||
Contribution c = Contribution.fromCursor(allContributions);
|
||||
if(c.getState() == Contribution.STATE_FAILED) {
|
||||
Log.d("Commons", "Deleting failed contrib " + c.toContentValues().toString());
|
||||
c.setContentProviderClient(getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY));
|
||||
c.delete();
|
||||
} else {
|
||||
Log.d("Commons", "Skipping deletion for non-failed contrib " + c.toContentValues().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
|
|
@ -143,13 +166,10 @@ public class ContributionsActivity
|
|||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long item) {
|
||||
Cursor cursor = (Cursor)adapterView.getItemAtPosition(position);
|
||||
Contribution c = Contribution.fromCursor(cursor);
|
||||
if(c.getState() == Contribution.STATE_FAILED) {
|
||||
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
|
||||
Log.d("Commons", "Restarting for" + c.toContentValues().toString());
|
||||
} else {
|
||||
Log.d("Commons", "CLicking for " + c.toContentValues());
|
||||
showDetail(position);
|
||||
}
|
||||
|
||||
Log.d("Commons", "Clicking for " + c.toContentValues());
|
||||
showDetail(position);
|
||||
|
||||
Log.d("Commons", "You clicked on:" + c.toContentValues().toString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,24 @@ public class ContributionsContentProvider extends ContentProvider{
|
|||
|
||||
@Override
|
||||
public int delete(Uri uri, String s, String[] strings) {
|
||||
return 0;
|
||||
int rows = 0;
|
||||
int uriType = uriMatcher.match(uri);
|
||||
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
|
||||
switch(uriType) {
|
||||
case CONTRIBUTIONS_ID:
|
||||
Log.d("Commons", "Deleting contribution id " + uri.getLastPathSegment());
|
||||
rows = db.delete(Contribution.Table.TABLE_NAME,
|
||||
"_id = ?",
|
||||
new String[] { uri.getLastPathSegment() }
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown URI" + uri);
|
||||
}
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
|
|
@ -15,6 +16,8 @@ import com.actionbarsherlock.view.MenuItem;
|
|||
import com.actionbarsherlock.widget.ShareActionProvider;
|
||||
|
||||
import org.wikimedia.commons.*;
|
||||
import org.wikimedia.commons.contributions.Contribution;
|
||||
import org.wikimedia.commons.contributions.ContributionsActivity;
|
||||
|
||||
public class MediaDetailPagerFragment extends SherlockFragment implements ViewPager.OnPageChangeListener {
|
||||
private ViewPager pager;
|
||||
|
|
@ -83,6 +86,7 @@ public class MediaDetailPagerFragment extends SherlockFragment implements ViewPa
|
|||
view.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
pager.setCurrentItem(pageNumber, false);
|
||||
getSherlockActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
|
@ -128,6 +132,16 @@ public class MediaDetailPagerFragment extends SherlockFragment implements ViewPa
|
|||
viewIntent.setData(Uri.parse(m.getDescriptionUrl()));
|
||||
startActivity(viewIntent);
|
||||
return true;
|
||||
case R.id.menu_retry_current_image:
|
||||
// Is this... sane? :)
|
||||
((ContributionsActivity)getSherlockActivity()).retryUpload(pager.getCurrentItem());
|
||||
getSherlockActivity().getSupportFragmentManager().popBackStack();
|
||||
return true;
|
||||
case R.id.menu_abort_current_image:
|
||||
// todo: delete image
|
||||
((ContributionsActivity)getSherlockActivity()).deleteUpload(pager.getCurrentItem());
|
||||
getSherlockActivity().getSupportFragmentManager().popBackStack();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
@ -143,8 +157,10 @@ public class MediaDetailPagerFragment extends SherlockFragment implements ViewPa
|
|||
Media m = provider.getMediaAtPosition(pager.getCurrentItem());
|
||||
if(m != null && !m.getFilename().startsWith("File:")) {
|
||||
// Crude way of checking if the file has been successfully saved!
|
||||
menu.findItem(R.id.menu_browser_current_image).setEnabled(false);
|
||||
menu.findItem(R.id.menu_share_current_image).setEnabled(false);
|
||||
menu.findItem(R.id.menu_browser_current_image).setEnabled(false).setVisible(false);
|
||||
menu.findItem(R.id.menu_share_current_image).setEnabled(false).setVisible(false);
|
||||
menu.findItem(R.id.menu_retry_current_image).setEnabled(true).setVisible(true);
|
||||
menu.findItem(R.id.menu_abort_current_image).setEnabled(true).setVisible(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue