mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Add refresh button only for Campaigns
Temp. hack to let people see new images when they come through Change-Id: I986bc274ccebd53fef75dbaeffcdff891a4f77bf
This commit is contained in:
parent
ad0e299f33
commit
da8db5a2ca
6 changed files with 45 additions and 6 deletions
|
|
@ -26,5 +26,9 @@
|
|||
android:showAsAction="never"
|
||||
android:icon="@android:drawable/ic_menu_send"
|
||||
/>
|
||||
<item android:id="@+id/menu_refresh"
|
||||
android:title="@string/menu_refresh"
|
||||
android:showAsAction="never"
|
||||
/>
|
||||
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
<string name="app_name">The name of the application.
|
||||
{{Identical|Wikimedia Commons}}</string>
|
||||
<string name="app_name_beta">Name of the beta version of the application</string>
|
||||
<string name="menu_refresh">Label for menu item that refreshes current list of images.</string>
|
||||
<string name="menu_settings">Label for menu item to show settings.
|
||||
{{Identical|Settings}}</string>
|
||||
<string name="username">{{Identical|Username}}</string>
|
||||
|
|
|
|||
|
|
@ -141,4 +141,5 @@
|
|||
<string name="detail_description_empty">No description</string>
|
||||
<string name="detail_license_empty">Unknown license</string>
|
||||
<string name="provider_campaigns">Campaigns</string>
|
||||
<string name="menu_refresh">Refresh</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ public class ContributionsActivity
|
|||
AdapterView.OnItemClickListener,
|
||||
MediaDetailPagerFragment.MediaDetailProvider,
|
||||
ContributionsListFragment.CurrentCampaignProvider,
|
||||
FragmentManager.OnBackStackChangedListener {
|
||||
FragmentManager.OnBackStackChangedListener,
|
||||
ContributionsListFragment.SourceRefresher {
|
||||
|
||||
|
||||
private Cursor allContributions;
|
||||
|
|
@ -219,7 +220,11 @@ public class ContributionsActivity
|
|||
|
||||
getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.contributions_subtitle, cursor.getCount(), cursor.getCount()));
|
||||
} else {
|
||||
contributionsList.setAdapter(new MediaListAdapter(this, (ArrayList<Media>) result));
|
||||
if(contributionsList.getAdapter() == null) {
|
||||
contributionsList.setAdapter(new MediaListAdapter(this, (ArrayList<Media>) result));
|
||||
} else {
|
||||
((MediaListAdapter)contributionsList.getAdapter()).updateMediaList((ArrayList<Media>) result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,8 +232,7 @@ public class ContributionsActivity
|
|||
if(campaign == null) {
|
||||
((CursorAdapter) contributionsList.getAdapter()).swapCursor(null);
|
||||
} else {
|
||||
//((MediaListAdapter) contributionsList.getAdapter()).
|
||||
// DO SOMETHING!
|
||||
contributionsList.setAdapter(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -262,4 +266,8 @@ public class ContributionsActivity
|
|||
public Campaign getCurrentCampaign() {
|
||||
return campaign;
|
||||
}
|
||||
|
||||
public void refreshSource() {
|
||||
getSupportLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
Campaign getCurrentCampaign();
|
||||
}
|
||||
|
||||
public interface SourceRefresher {
|
||||
void refreshSource();
|
||||
}
|
||||
|
||||
private GridView contributionsList;
|
||||
private TextView waitingMessage;
|
||||
private TextView emptyMessage;
|
||||
|
|
@ -87,7 +91,9 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, CommonsApplication.APPLICATION_VERSION));
|
||||
startActivity(feedbackIntent);
|
||||
return true;
|
||||
|
||||
case R.id.menu_refresh:
|
||||
((SourceRefresher)getActivity()).refreshSource();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
@ -102,6 +108,9 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
if (!app.deviceHasCamera()) {
|
||||
menu.findItem(R.id.menu_from_camera).setEnabled(false);
|
||||
}
|
||||
if(campaign == null) {
|
||||
menu.findItem(R.id.menu_refresh).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -119,7 +128,8 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
controller = new ContributionController(this, ((CurrentCampaignProvider)getActivity()).getCurrentCampaign());
|
||||
campaign = ((CurrentCampaignProvider)getActivity()).getCurrentCampaign();
|
||||
controller = new ContributionController(this, campaign);
|
||||
controller.loadState(savedInstanceState);
|
||||
|
||||
contributionsList = (GridView)getView().findViewById(R.id.contributionsList);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,21 @@ public class MediaListAdapter extends BaseAdapter {
|
|||
this.activity = activity;
|
||||
}
|
||||
|
||||
public void updateMediaList(ArrayList<Media> newMediaList) {
|
||||
// FIXME: Hack for now, replace with something more efficient later on
|
||||
for(Media newMedia: newMediaList) {
|
||||
boolean isDuplicate = false;
|
||||
for(Media oldMedia: mediaList ) {
|
||||
if(newMedia.getFilename().equals(oldMedia.getFilename())) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!isDuplicate) {
|
||||
mediaList.add(0, newMedia);
|
||||
}
|
||||
}
|
||||
}
|
||||
public int getCount() {
|
||||
return mediaList.size();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue