Fixes #4437 - Changed indentation on files with 2 spaces to 4 spaces (#4462)

* Edited Project.xml to make indent size 4

* Changed files with 2 space indentation to use 4 space indentation

* Edited Project.xml to make indent size 4

* changed files with 2 space indent to 4 space indent

* fix :Back Pressed Event not work in Explore tab when user not login (#4404)

* fix :Back Pressed Event not work in Explore tab

* minor changes

* fix :Upload count or number of contribution does not get updated when media  is successful uploaded (#4399)

* * fix:Number of Contributions not updated
 * Add javadocs

* minor changes

* made minor changes

* String was nonsense and untranslatible, fixed (#4466)

* Ability to show captions and descriptions in all entered languages (#4355)

* implement Ability to show captions and descriptions in all entered languages
*Add Javadoc

* handle Back event of fragment(mediaDetailFragment)

* fix minor bugs

* add internationalization

* revert previous changes

* fix visibility bug

* resolve conflict

Co-authored-by: Prince kushwaha <65972015+Prince-kushwaha@users.noreply.github.com>
Co-authored-by: neslihanturan <tur.neslihan@gmail.com>
This commit is contained in:
Jamie Brown 2021-06-21 04:33:11 +01:00 committed by GitHub
parent b202f553f0
commit ca9f6f5e47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 3047 additions and 2988 deletions

View file

@ -111,7 +111,6 @@
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="2" />
</indentOptions>

View file

@ -66,7 +66,8 @@ import timber.log.Timber;
buildConfigClass = BuildConfig.class,
resReportSendSuccessToast = R.string.crash_dialog_ok_toast,
reportFormat = StringFormat.KEY_VALUE_LIST,
reportContent = {USER_COMMENT, APP_VERSION_CODE, APP_VERSION_NAME, ANDROID_VERSION, PHONE_MODEL, STACK_TRACE}
reportContent = {USER_COMMENT, APP_VERSION_CODE, APP_VERSION_NAME, ANDROID_VERSION, PHONE_MODEL,
STACK_TRACE}
)
@AcraMailSender(
@ -118,16 +119,19 @@ public class CommonsApplication extends MultiDexApplication {
private RefWatcher refWatcher;
private static CommonsApplication INSTANCE;
public static CommonsApplication getInstance() {
return INSTANCE;
}
private AppLanguageLookUpTable languageLookUpTable;
public AppLanguageLookUpTable getLanguageLookUpTable() {
return languageLookUpTable;
}
@Inject ContributionDao contributionDao;
@Inject
ContributionDao contributionDao;
/**
* In memory list of contributios whose uploads ahve been paused by the user
@ -154,7 +158,6 @@ public class CommonsApplication extends MultiDexApplication {
initTimber();
if (!defaultPrefs.getBoolean("has_user_manually_removed_location")) {
Set<String> defaultExifTagsSet = defaultPrefs.getStringSet(Prefs.MANAGED_EXIF_TAGS);
if (null == defaultExifTagsSet) {
@ -192,9 +195,7 @@ public class CommonsApplication extends MultiDexApplication {
}
/**
* Plants debug and file logging tree.
* Timber lets you plant your own logging trees.
*
* Plants debug and file logging tree. Timber lets you plant your own logging trees.
*/
private void initTimber() {
boolean isBeta = ConfigUtils.isBetaFlavour();
@ -247,22 +248,27 @@ public class CommonsApplication extends MultiDexApplication {
public static void createNotificationChannel(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = manager.getNotificationChannel(NOTIFICATION_CHANNEL_ID_ALL);
NotificationManager manager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = manager
.getNotificationChannel(NOTIFICATION_CHANNEL_ID_ALL);
if (channel == null) {
channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID_ALL,
context.getString(R.string.notifications_channel_name_all), NotificationManager.IMPORTANCE_DEFAULT);
context.getString(R.string.notifications_channel_name_all),
NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
}
}
public String getUserAgent() {
return "Commons/" + ConfigUtils.getVersionNameWithSha(this) + " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE;
return "Commons/" + ConfigUtils.getVersionNameWithSha(this)
+ " (https://mediawiki.org/wiki/Apps/Commons) Android/" + Build.VERSION.RELEASE;
}
/**
* Helps in setting up LeakCanary library
*
* @return instance of LeakCanary
*/
protected RefWatcher setupLeakCanary() {
@ -285,6 +291,7 @@ public class CommonsApplication extends MultiDexApplication {
/**
* clears data of current application
*
* @param context Application context
* @param logoutListener Implementation of interface LogoutListener
*/
@ -332,7 +339,8 @@ public class CommonsApplication extends MultiDexApplication {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
CategoryDao.Table.onDelete(db);
dbOpenHelper.deleteTable(db,CONTRIBUTIONS_TABLE);//Delete the contributions table in the existing db on older versions
dbOpenHelper.deleteTable(db,
CONTRIBUTIONS_TABLE);//Delete the contributions table in the existing db on older versions
try {
contributionDao.deleteAll();
@ -348,6 +356,7 @@ public class CommonsApplication extends MultiDexApplication {
* Interface used to get log-out events
*/
public interface LogoutListener {
void onLogoutComplete();
}
}

View file

@ -12,6 +12,7 @@ public final class LocationPicker {
/**
* Getting camera position from the intent using constants
*
* @param data intent
* @return CameraPosition
*/
@ -32,6 +33,7 @@ public final class LocationPicker {
/**
* Gets and puts location in intent
*
* @param position CameraPosition
* @return LocationPicker.IntentBuilder
*/
@ -43,6 +45,7 @@ public final class LocationPicker {
/**
* Gets and sets the activity
*
* @param activity Activity
* @return Intent
*/

View file

@ -75,7 +75,8 @@ public class LocationPickerActivity extends AppCompatActivity implements OnMapRe
setContentView(R.layout.activity_location_picker);
if (savedInstanceState == null) {
cameraPosition = getIntent().getParcelableExtra(LocationPickerConstants.MAP_CAMERA_POSITION);
cameraPosition = getIntent()
.getParcelableExtra(LocationPickerConstants.MAP_CAMERA_POSITION);
}
final LocationPickerViewModel viewModel = new ViewModelProvider(this)
@ -137,6 +138,7 @@ public class LocationPickerActivity extends AppCompatActivity implements OnMapRe
/**
* Takes action when map is ready to show
*
* @param mapboxMap map
*/
@Override
@ -158,6 +160,7 @@ public class LocationPickerActivity extends AppCompatActivity implements OnMapRe
/**
* Enables location components
*
* @param loadedMapStyle Style
*/
@SuppressWarnings({"MissingPermission"})
@ -189,6 +192,7 @@ public class LocationPickerActivity extends AppCompatActivity implements OnMapRe
/**
* Acts on camera moving
*
* @param reason int
*/
@Override
@ -212,6 +216,7 @@ public class LocationPickerActivity extends AppCompatActivity implements OnMapRe
/**
* Takes action on camera position
*
* @param position position of picker
*/
@Override

View file

@ -23,6 +23,7 @@ public class LocationPickerViewModel extends AndroidViewModel implements Callbac
/**
* Constructor for this class
*
* @param application Application
*/
public LocationPickerViewModel(@NonNull final Application application) {
@ -31,6 +32,7 @@ public class LocationPickerViewModel extends AndroidViewModel implements Callbac
/**
* Responses on camera position changing
*
* @param call Call<CameraPosition>
* @param response Response<CameraPosition>
*/
@ -51,6 +53,7 @@ public class LocationPickerViewModel extends AndroidViewModel implements Callbac
/**
* Gets live CameraPosition
*
* @return MutableLiveData<CameraPosition>
*/
public MutableLiveData<CameraPosition> getResult() {

View file

@ -88,8 +88,8 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
}
/**
* This method sets up the tab layout.
* If the adapter has only one element it sets the visibility of tabLayout to gone.
* This method sets up the tab layout. If the adapter has only one element it sets the
* visibility of tabLayout to gone.
*/
public void setupTabLayout() {
tabLayout.setVisibility(View.VISIBLE);
@ -100,7 +100,8 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
public void onBackPressed() {
if(((BookmarkListRootFragment)(adapter.getItem(tabLayout.getSelectedTabPosition()))).backPressed()) {
if (((BookmarkListRootFragment) (adapter.getItem(tabLayout.getSelectedTabPosition())))
.backPressed()) {
// The event is handled internally by the adapter , no further action required.
return;
}

View file

@ -61,7 +61,8 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container,
public View onCreateView(@NonNull final LayoutInflater inflater,
@Nullable final ViewGroup container,
@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_featured_root, container, false);
@ -212,7 +213,8 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
setFragment(listFragment, mediaDetails);
((MainActivity) getActivity()).showTabs();
if (listFragment instanceof BookmarkPicturesFragment) {
GridViewAdapter adapter=((GridViewAdapter)((BookmarkPicturesFragment)listFragment).getAdapter());
GridViewAdapter adapter = ((GridViewAdapter) ((BookmarkPicturesFragment) listFragment)
.getAdapter());
Iterator i = removed.iterator();
while (i.hasNext()) {
adapter.remove(adapter.getItem((int) i.next()));
@ -234,6 +236,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
((MainActivity) getActivity()).showTabs();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("deneme8", "on media clicked");

View file

@ -81,7 +81,6 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
imageView.getHierarchy().setPlaceholderImage(R.drawable.image_placeholder);
imageView.getHierarchy().setFailureImage(R.drawable.image_placeholder);
final String imageSource = chooseImageSource(contribution.getMedia().getThumbUrl(),
contribution.getLocalUri());
if (!TextUtils.isEmpty(imageSource)) {
@ -150,8 +149,8 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
}
/**
* Checks if a media exists on the corresponding Wikipedia article Currently the check is made for
* the device's current language Wikipedia
* Checks if a media exists on the corresponding Wikipedia article Currently the check is made
* for the device's current language Wikipedia
*
* @param contribution
*/
@ -170,9 +169,9 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
}
/**
* Handle action buttons visibility if the corresponding wikipedia page doesn't contain any media.
* This method needs to control the state of just the scenario where media does not exists as
* other scenarios are already handled in the init method.
* Handle action buttons visibility if the corresponding wikipedia page doesn't contain any
* media. This method needs to control the state of just the scenario where media does not
* exists as other scenarios are already handled in the init method.
*
* @param mediaExists
*/

View file

@ -159,7 +159,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
super.onItemRangeInserted(positionStart, itemCount);
if (itemCount > 0 && positionStart == 0) {
if (adapter.getContributionForPosition(positionStart) != null) {
rvContributionsList.scrollToPosition(0);//Newly upload items are always added to the top
rvContributionsList
.scrollToPosition(0);//Newly upload items are always added to the top
}
}
}
@ -232,7 +233,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
fab_layout.setOrientation(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ?
LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
rvContributionsList
.setLayoutManager(new GridLayoutManager(getContext(), getSpanCount(newConfig.orientation)));
.setLayoutManager(
new GridLayoutManager(getContext(), getSpanCount(newConfig.orientation)));
}
private void initializeAnimations() {
@ -353,6 +355,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
/**
* Pauses the current upload
*
* @param contribution
*/
@Override
@ -363,6 +366,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
/**
* Resumes the current upload
*
* @param contribution
*/
@Override

View file

@ -39,8 +39,8 @@ public class ContributionsListPresenter implements UserActionListener {
}
/**
* Setup the paged list. This method sets the configuration for paged list and ties it up with the
* live data object. This method can be tweaked to update the lazy loading behavior of the
* Setup the paged list. This method sets the configuration for paged list and ties it up with
* the live data object. This method can be tweaked to update the lazy loading behavior of the
* contributions list
*/
void setup() {
@ -48,7 +48,8 @@ public class ContributionsListPresenter implements UserActionListener {
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
contributionList = (new LivePagedListBuilder(repository.fetchContributions(), pagedListConfig)
contributionList = (new LivePagedListBuilder(repository.fetchContributions(),
pagedListConfig)
.setBoundaryCallback(contributionBoundaryCallback)).build();
}

View file

@ -43,7 +43,8 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container,
public View onCreateView(@NonNull final LayoutInflater inflater,
@Nullable final ViewGroup container,
@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_featured_root, container, false);
@ -176,8 +177,9 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
}
/**
* Performs back pressed action on the fragment.
* Return true if the event was handled by the mediaDetails otherwise returns false.
* Performs back pressed action on the fragment. Return true if the event was handled by the
* mediaDetails otherwise returns false.
*
* @return
*/
public boolean backPressed() {

View file

@ -6,8 +6,7 @@ import android.view.MotionEvent;
import androidx.viewpager.widget.ViewPager;
/**
* ParentViewPager
* A custom viewPager whose scrolling can be enabled and disabled.
* ParentViewPager A custom viewPager whose scrolling can be enabled and disabled.
*/
public class ParentViewPager extends ViewPager {
@ -55,8 +54,8 @@ public class ParentViewPager extends ViewPager {
/**
* A facilitator method that allows parent to intercept touch events before its children.
* thus making it possible to prevent swiping parent on child end.
* A facilitator method that allows parent to intercept touch events before its children. thus
* making it possible to prevent swiping parent on child end.
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
@ -64,6 +63,4 @@ public class ParentViewPager extends ViewPager {
}
}

View file

@ -27,8 +27,11 @@ import fr.free.nrw.commons.explore.SearchActivity;
* Displays the recent searches screen.
*/
public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
@Inject RecentSearchesDao recentSearchesDao;
@BindView(R.id.recent_searches_list) ListView recentSearchesList;
@Inject
RecentSearchesDao recentSearchesDao;
@BindView(R.id.recent_searches_list)
ListView recentSearchesList;
List<String> recentSearches;
ArrayAdapter adapter;
@BindView(R.id.recent_searches_delete_button)
@ -55,9 +58,11 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
recentSearchesDao.deleteAll();
recent_searches_delete_button.setVisibility(View.GONE);
recent_searches_text_view.setText(R.string.no_recent_searches);
Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), getString(R.string.search_history_deleted),
Toast.LENGTH_SHORT).show();
recentSearches = recentSearchesDao.recentSearches(10);
adapter = new ArrayAdapter<>(getContext(), R.layout.item_recent_searches, recentSearches);
adapter = new ArrayAdapter<>(getContext(), R.layout.item_recent_searches,
recentSearches);
recentSearchesList.setAdapter(adapter);
adapter.notifyDataSetChanged();
dialog.dismiss();
@ -67,7 +72,8 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
.show();
});
adapter = new ArrayAdapter<>(requireContext(), R.layout.item_recent_searches, recentSearches);
adapter = new ArrayAdapter<>(requireContext(), R.layout.item_recent_searches,
recentSearches);
recentSearchesList.setAdapter(adapter);
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
(SearchActivity) getContext()).updateText(recentSearches.get(position)));
@ -77,7 +83,8 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
.setPositiveButton(getString(R.string.delete).toUpperCase(), ((dialog, which) -> {
recentSearchesDao.delete(recentSearchesDao.find(recentSearches.get(position)));
recentSearches = recentSearchesDao.recentSearches(10);
adapter = new ArrayAdapter<>(getContext(), R.layout.item_recent_searches, recentSearches);
adapter = new ArrayAdapter<>(getContext(), R.layout.item_recent_searches,
recentSearches);
recentSearchesList.setAdapter(adapter);
adapter.notifyDataSetChanged();
dialog.dismiss();
@ -92,8 +99,8 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
}
/**
* This method is called on back press of activity
* so we are updating the list from database to refresh the recent searches list.
* This method is called on back press of activity so we are updating the list from database to
* refresh the recent searches list.
*/
@Override
public void onResume() {

View file

@ -126,8 +126,10 @@ public class CustomOkHttpNetworkFetcher
public Map<String, String> getExtraMap(OkHttpNetworkFetchState fetchState, int byteSize) {
Map<String, String> extraMap = new HashMap<>(4);
extraMap.put(QUEUE_TIME, Long.toString(fetchState.responseTime - fetchState.submitTime));
extraMap.put(FETCH_TIME, Long.toString(fetchState.fetchCompleteTime - fetchState.responseTime));
extraMap.put(TOTAL_TIME, Long.toString(fetchState.fetchCompleteTime - fetchState.submitTime));
extraMap
.put(FETCH_TIME, Long.toString(fetchState.fetchCompleteTime - fetchState.responseTime));
extraMap
.put(TOTAL_TIME, Long.toString(fetchState.fetchCompleteTime - fetchState.submitTime));
extraMap.put(IMAGE_SIZE, Integer.toString(byteSize));
return extraMap;
}
@ -167,7 +169,8 @@ public class CustomOkHttpNetworkFetcher
try {
if (!response.isSuccessful()) {
handleException(
call, new IOException("Unexpected HTTP code " + response), callback);
call, new IOException("Unexpected HTTP code " + response),
callback);
return;
}
@ -203,7 +206,8 @@ public class CustomOkHttpNetworkFetcher
/**
* Handles exceptions.
*
* <p>OkHttp notifies callers of cancellations via an IOException. If IOException is caught after
* <p>OkHttp notifies callers of cancellations via an IOException. If IOException is caught
* after
* request cancellation, then the exception is interpreted as successful cancellation and
* onCancellation is called. Otherwise onFailure is called.
*/

View file

@ -70,6 +70,7 @@ public class OkHttpJsonApiClient {
/**
* The method will gradually calls the leaderboard API and fetches the leaderboard
*
* @param userName username of leaderboard user
* @param duration duration for leaderboard
* @param category category for leaderboard
@ -78,7 +79,8 @@ public class OkHttpJsonApiClient {
* @return LeaderboardResponse object
*/
@NonNull
public Observable<LeaderboardResponse> getLeaderboard(String userName, String duration, String category, String limit, String offset) {
public Observable<LeaderboardResponse> getLeaderboard(String userName, String duration,
String category, String limit, String offset) {
final String fetchLeaderboardUrlTemplate = wikiMediaTestToolforgeUrl
+ LEADERBOARD_END_POINT;
String url = String.format(Locale.ENGLISH,
@ -118,6 +120,7 @@ public class OkHttpJsonApiClient {
/**
* This method will update the leaderboard user avatar
*
* @param username username to update
* @param avatar url of the new avatar
* @return UpdateAvatarResponse object
@ -222,8 +225,8 @@ public class OkHttpJsonApiClient {
}
/**
* This takes userName as input, which is then used to fetch the feedback/achievements statistics
* using OkHttp and JavaRx. This function return JSONObject
* This takes userName as input, which is then used to fetch the feedback/achievements
* statistics using OkHttp and JavaRx. This function return JSONObject
*
* @param userName MediaWiki user name
* @return
@ -261,7 +264,8 @@ public class OkHttpJsonApiClient {
});
}
public Observable<List<Place>> getNearbyPlaces(LatLng cur, String language, double radius) throws IOException {
public Observable<List<Place>> getNearbyPlaces(LatLng cur, String language, double radius)
throws IOException {
String wikidataQuery = FileUtils.readFromResource("/queries/nearby_query.rq");
String query = wikidataQuery
.replace("${RAD}", String.format(Locale.ROOT, "%.2f", radius))
@ -304,7 +308,8 @@ public class OkHttpJsonApiClient {
*/
public Single<List<DepictedItem>> getChildDepictions(String qid, int startPosition,
int limit) throws IOException {
return depictedItemsFrom(sparqlQuery(qid, startPosition, limit,"/queries/subclasses_query.rq"));
return depictedItemsFrom(
sparqlQuery(qid, startPosition, limit, "/queries/subclasses_query.rq"));
}
/**
@ -326,7 +331,8 @@ public class OkHttpJsonApiClient {
}
@NotNull
private Request sparqlQuery(String qid, int startPosition, int limit, String fileName) throws IOException {
private Request sparqlQuery(String qid, int startPosition, int limit, String fileName)
throws IOException {
String query = FileUtils.readFromResource(fileName)
.replace("${QID}", qid)
.replace("${LANG}", "\"" + Locale.getDefault().getLanguage() + "\"")

View file

@ -16,7 +16,6 @@ import org.wikipedia.model.EnumCodeMap;
import fr.free.nrw.commons.R;
public enum NavTab implements EnumCode {
CONTRIBUTIONS(R.string.contributions_fragment, R.drawable.ic_baseline_person_24) {
@NonNull

View file

@ -8,6 +8,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
public class NavTabFragmentPagerAdapter extends FragmentPagerAdapter {
private Fragment currentFragment;
public NavTabFragmentPagerAdapter(FragmentManager mgr) {
@ -19,11 +20,13 @@ public class NavTabFragmentPagerAdapter extends FragmentPagerAdapter {
return currentFragment;
}
@Override public Fragment getItem(int pos) {
@Override
public Fragment getItem(int pos) {
return NavTab.of(pos).newInstance();
}
@Override public int getCount() {
@Override
public int getCount() {
return NavTab.size();
}

View file

@ -35,7 +35,8 @@ public enum NavTabLoggedOut implements EnumCode {
}
};
private static final EnumCodeMap<NavTabLoggedOut> MAP = new EnumCodeMap<>(NavTabLoggedOut.class);
private static final EnumCodeMap<NavTabLoggedOut> MAP = new EnumCodeMap<>(
NavTabLoggedOut.class);
@StringRes
private final int text;

View file

@ -22,6 +22,7 @@ import timber.log.Timber;
*/
@Singleton
public class ImageProcessingService {
private final FileUtilsWrapper fileUtilsWrapper;
private final ImageUtilsWrapper imageUtilsWrapper;
private final ReadFBMD readFBMD;
@ -62,7 +63,8 @@ public class ImageProcessingService {
checkFBMD(filePath),
checkEXIF(filePath),
(duplicateImage, wrongGeoLocation, darkImage, itemTitle, fbmd, exif) -> {
Timber.d("duplicate: %d, geo: %d, dark: %d, title: %d" + "fbmd:" + fbmd + "exif:" + exif,
Timber.d("duplicate: %d, geo: %d, dark: %d, title: %d" + "fbmd:" + fbmd + "exif:"
+ exif,
duplicateImage, wrongGeoLocation, darkImage, itemTitle);
return duplicateImage | wrongGeoLocation | darkImage | itemTitle | fbmd | exif;
}
@ -79,10 +81,10 @@ public class ImageProcessingService {
}
/**
* We try to minimize uploads from the Commons app that might be copyright violations.
* If an image does not have any Exif metadata, then it was likely downloaded from the internet,
* and is probably not an original work by the user. We detect these kinds of images by looking
* for the presence of some basic Exif metadata.
* We try to minimize uploads from the Commons app that might be copyright violations. If an
* image does not have any Exif metadata, then it was likely downloaded from the internet, and
* is probably not an original work by the user. We detect these kinds of images by looking for
* the presence of some basic Exif metadata.
*/
private Single<Integer> checkEXIF(String filepath) {
return EXIFReader.processMetadata(filepath);
@ -90,9 +92,7 @@ public class ImageProcessingService {
/**
* Checks item caption
* - empty caption
* - existing caption
* Checks item caption - empty caption - existing caption
*
* @param uploadItem
* @return
@ -142,8 +142,8 @@ public class ImageProcessingService {
}
/**
* Checks for image geolocation
* returns IMAGE_OK if the place is null or if the file doesn't contain a geolocation
* Checks for image geolocation returns IMAGE_OK if the place is null or if the file doesn't
* contain a geolocation
*
* @param filePath file to be checked
* @return IMAGE_GEOLOCATION_DIFFERENT or IMAGE_OK
@ -159,7 +159,8 @@ public class ImageProcessingService {
if (StringUtils.isBlank(geoLocation)) {
return Single.just(ImageUtils.IMAGE_OK);
}
return imageUtilsWrapper.checkImageGeolocationIsDifferent(geoLocation, place.getLocation());
return imageUtilsWrapper
.checkImageGeolocationIsDifferent(geoLocation, place.getLocation());
})
.subscribeOn(Schedulers.io());
}

View file

@ -62,8 +62,9 @@ public class UploadClient {
}
/**
* Upload file to stash in chunks of specified size. Uploading files in chunks will make handling
* of large files easier. Also, it will be useful in supporting pause/resume of uploads
* Upload file to stash in chunks of specified size. Uploading files in chunks will make
* handling of large files easier. Also, it will be useful in supporting pause/resume of
* uploads
*/
public Observable<StashUploadResult> uploadFileToStash(
final Context context, final String filename, final Contribution contribution,
@ -102,7 +103,8 @@ public class UploadClient {
return;
}
if (chunkInfo.get() != null && index.get() < chunkInfo.get().getIndexOfNextChunkToUpload()) {
if (chunkInfo.get() != null && index.get() < chunkInfo.get()
.getIndexOfNextChunkToUpload()) {
index.incrementAndGet();
Timber.d("Chunk: Increment and return: %s", index.get());
return;
@ -155,6 +157,7 @@ public class UploadClient {
/**
* Stash is valid for 6 hours. This function checks the validity of stash
*
* @param contribution
* @return
*/
@ -217,9 +220,11 @@ public class UploadClient {
CommonsApplication.DEFAULT_EDIT_SUMMARY,
uniqueFileName,
fileKey).map(uploadResponse -> {
UploadResponse uploadResult = gson.fromJson(uploadResponse, UploadResponse.class);
UploadResponse uploadResult = gson
.fromJson(uploadResponse, UploadResponse.class);
if (uploadResult.getUpload() == null) {
final MwException exception = gson.fromJson(uploadResponse, MwException.class);
final MwException exception = gson
.fromJson(uploadResponse, MwException.class);
Timber.e(exception, "Error in uploading file from stash");
throw new RuntimeException(exception.getErrorCode());
}

View file

@ -72,6 +72,7 @@ public class UploadItem {
/**
* Sets the corresponding place to the uploadItem
*
* @param place geolocated Wikidata item
*/
public void setPlace(Place place) {

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
public class ActivityUtils {
public static <T> void startActivityWithFlags(Context context, Class<T> cls, int... flags) {
Intent intent = new Intent(context, cls);
for (int flag : flags) {

View file

@ -44,7 +44,8 @@ public class WikiBaseClient {
String languageCode, String captionValue) {
return csrfToken()
.switchMap(editToken -> wikiBaseInterface
.addLabelstoWikidata(PAGE_ID_PREFIX + fileEntityId, editToken, languageCode, captionValue));
.addLabelstoWikidata(PAGE_ID_PREFIX + fileEntityId, editToken, languageCode,
captionValue));
}

View file

@ -31,7 +31,8 @@ public class WikidataClient {
*/
Observable<Long> setClaim(Statement_partial claim, String tags) {
return getCsrfToken()
.flatMap(csrfToken -> wikidataInterface.postSetClaim(gson.toJson(claim), tags, csrfToken))
.flatMap(
csrfToken -> wikidataInterface.postSetClaim(gson.toJson(claim), tags, csrfToken))
.map(mwPostResponse -> mwPostResponse.getPageinfo().getLastrevid());
}

View file

@ -68,8 +68,8 @@ public class WikidataEditService {
}
/**
* Edits the wikibase entity by adding DEPICTS property. Adding DEPICTS property requires call to
* the wikibase API to set tag against the entity.
* Edits the wikibase entity by adding DEPICTS property. Adding DEPICTS property requires call
* to the wikibase API to set tag against the entity.
*/
@SuppressLint("CheckResult")
private Observable<Boolean> addDepictsProperty(final String fileEntityId,
@ -137,8 +137,8 @@ public class WikidataEditService {
}
}
public Long createClaim(@Nullable final WikidataPlace wikidataPlace, final String fileName, final
Map<String, String> captions) {
public Long createClaim(@Nullable final WikidataPlace wikidataPlace, final String fileName,
final Map<String, String> captions) {
if (!(directKvStore.getBoolean("Picture_Has_Correct_Location", true))) {
Timber
.d("Image location and nearby place location mismatched, so Wikidata item won't be edited");
@ -149,7 +149,8 @@ public class WikidataEditService {
public Long addImageAndMediaLegends(final WikidataItem wikidataItem, final String fileName,
final Map<String, String> captions) {
final Snak_partial p18 = new Snak_partial("value", WikidataProperties.IMAGE.getPropertyName(),
final Snak_partial p18 = new Snak_partial("value",
WikidataProperties.IMAGE.getPropertyName(),
new ValueString(fileName.replace("File:", "")));
final List<Snak_partial> snaks = new ArrayList<>();
@ -179,10 +180,12 @@ public class WikidataEditService {
}
}
public Observable addDepictionsAndCaptions(final UploadResult uploadResult, final Contribution contribution) {
public Observable addDepictionsAndCaptions(final UploadResult uploadResult,
final Contribution contribution) {
return wikiBaseClient.getFileEntityId(uploadResult)
.doOnError(throwable -> {
Timber.e(throwable, "Error occurred while getting EntityID to set DEPICTS property");
Timber
.e(throwable, "Error occurred while getting EntityID to set DEPICTS property");
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
})
.switchMap(fileEntityId -> {