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
*/
@ -302,7 +309,7 @@ public class CommonsApplication extends MultiDexApplication {
}
sessionManager.logout()
.andThen(Completable.fromAction(() ->{
.andThen(Completable.fromAction(() -> {
Timber.d("All accounts have been removed");
clearImageCache();
//TODO: fix preference manager
@ -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,9 +160,10 @@ public class LocationPickerActivity extends AppCompatActivity implements OnMapRe
/**
* Enables location components
*
* @param loadedMapStyle Style
*/
@SuppressWarnings( {"MissingPermission"})
@SuppressWarnings({"MissingPermission"})
private void enableLocationComponent(@NonNull final Style loadedMapStyle) {
final UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setAttributionEnabled(false);
@ -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,13 +32,14 @@ public class LocationPickerViewModel extends AndroidViewModel implements Callbac
/**
* Responses on camera position changing
*
* @param call Call<CameraPosition>
* @param response Response<CameraPosition>
*/
@Override
public void onResponse(final @NotNull Call<CameraPosition> call,
final Response<CameraPosition> response) {
if(response.body()==null){
if (response.body() == null) {
result.setValue(null);
return;
}
@ -51,6 +53,7 @@ public class LocationPickerViewModel extends AndroidViewModel implements Callbac
/**
* Gets live CameraPosition
*
* @return MutableLiveData<CameraPosition>
*/
public MutableLiveData<CameraPosition> getResult() {

View file

@ -53,7 +53,7 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
return fragment;
}
public void setScroll(boolean canScroll){
public void setScroll(boolean canScroll) {
viewPager.setCanScroll(canScroll);
}
@ -80,7 +80,7 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
((MainActivity)getActivity()).showTabs();
((MainActivity) getActivity()).showTabs();
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
setupTabLayout();
@ -88,10 +88,10 @@ 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(){
public void setupTabLayout() {
tabLayout.setVisibility(View.VISIBLE);
if (adapter.getCount() == 1) {
tabLayout.setVisibility(View.GONE);
@ -100,11 +100,12 @@ 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;
}
// Event is not handled by the adapter ( performed back action ) change action bar.
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
}

View file

@ -30,7 +30,7 @@ import java.util.Iterator;
public class BookmarkListRootFragment extends CommonsDaggerSupportFragment implements
FragmentManager.OnBackStackChangedListener,
MediaDetailPagerFragment.MediaDetailProvider,
AdapterView.OnItemClickListener, CategoryImagesCallback{
AdapterView.OnItemClickListener, CategoryImagesCallback {
private MediaDetailPagerFragment mediaDetails;
//private BookmarkPicturesFragment bookmarkPicturesFragment;
@ -41,7 +41,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@BindView(R.id.explore_container)
FrameLayout container;
public BookmarkListRootFragment(){
public BookmarkListRootFragment() {
//empty constructor necessary otherwise crashes on recreate
}
@ -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);
@ -72,7 +73,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if(savedInstanceState==null) {
if (savedInstanceState == null) {
setFragment(listFragment, mediaDetails);
}
}
@ -82,18 +83,18 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
getChildFragmentManager()
.beginTransaction()
.hide(otherFragment)
.show( fragment)
.show(fragment)
.addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
.commit();
getChildFragmentManager().executePendingTransactions();
} else if (fragment.isAdded() && otherFragment == null) {
getChildFragmentManager()
.beginTransaction()
.show( fragment)
.show(fragment)
.addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
.commit();
getChildFragmentManager().executePendingTransactions();
}else if (!fragment.isAdded() && otherFragment != null ) {
} else if (!fragment.isAdded() && otherFragment != null) {
getChildFragmentManager()
.beginTransaction()
.hide(otherFragment)
@ -126,7 +127,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@Override
public void onMediaClicked(int position) {
Log.d("deneme8","on media clicked");
Log.d("deneme8", "on media clicked");
/*container.setVisibility(View.VISIBLE);
((BookmarkFragment)getParentFragment()).tabLayout.setVisibility(View.GONE);
mediaDetails = new MediaDetailPagerFragment(false, true, position);
@ -176,7 +177,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
*/
@Override
public void refreshNominatedMedia(int index) {
if(mediaDetails != null && !listFragment.isVisible()) {
if (mediaDetails != null && !listFragment.isVisible()) {
removeFragment(mediaDetails);
mediaDetails = new MediaDetailPagerFragment(false, true);
((BookmarkFragment) getParentFragment()).setScroll(false);
@ -198,24 +199,25 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
public boolean backPressed() {
//check mediaDetailPage fragment is not null then we check mediaDetail.is Visible or not to avoid NullPointerException
if(mediaDetails!=null) {
if (mediaDetails != null) {
if (mediaDetails.isVisible()) {
if(mediaDetails.backButtonClicked()) {
if (mediaDetails.backButtonClicked()) {
// mediaDetails handled the back clicked , no further action required.
return true;
}
// todo add get list fragment
((BookmarkFragment) getParentFragment()).setupTabLayout();
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
ArrayList<Integer> removed = mediaDetails.getRemovedItems();
removeFragment(mediaDetails);
((BookmarkFragment) getParentFragment()).setScroll(true);
setFragment(listFragment, mediaDetails);
((MainActivity) getActivity()).showTabs();
if(listFragment instanceof BookmarkPicturesFragment){
GridViewAdapter adapter=((GridViewAdapter)((BookmarkPicturesFragment)listFragment).getAdapter());
if (listFragment instanceof BookmarkPicturesFragment) {
GridViewAdapter adapter = ((GridViewAdapter) ((BookmarkPicturesFragment) listFragment)
.getAdapter());
Iterator i = removed.iterator();
while (i.hasNext()) {
adapter.remove(adapter.getItem((int)i.next()));
adapter.remove(adapter.getItem((int) i.next()));
}
mediaDetails.clearRemoved();
@ -230,15 +232,16 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
return false;
}
void moveToContributionsFragment(){
void moveToContributionsFragment() {
((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");
Log.d("deneme8", "on media clicked");
container.setVisibility(View.VISIBLE);
((BookmarkFragment)getParentFragment()).tabLayout.setVisibility(View.GONE);
((BookmarkFragment) getParentFragment()).tabLayout.setVisibility(View.GONE);
mediaDetails = new MediaDetailPagerFragment(false, true);
((BookmarkFragment) getParentFragment()).setScroll(false);
setFragment(mediaDetails, listFragment);

View file

@ -66,7 +66,7 @@ public class ContributionViewHolder extends RecyclerView.ViewHolder {
public void init(final int position, final Contribution contribution) {
//handling crashes when the contribution is null.
if( null == contribution) {
if (null == contribution) {
return;
}
@ -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

@ -158,8 +158,9 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
public void onItemRangeInserted(int positionStart, int itemCount) {
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
if (adapter.getContributionForPosition(positionStart) != null) {
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
@ -386,7 +390,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
public Media getMediaAtPosition(final int i) {
if(adapter.getContributionForPosition(i) != null) {
if (adapter.getContributionForPosition(i) != null) {
return adapter.getContributionForPosition(i).getMedia();
}
return null;

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

@ -12,9 +12,9 @@ import fr.free.nrw.commons.upload.depicts.DepictsDao
* The database for accessing the respective DAOs
*
*/
@Database(entities = [Contribution::class,Depicts::class], version = 8, exportSchema = false)
@Database(entities = [Contribution::class, Depicts::class], version = 8, exportSchema = false)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun contributionDao(): ContributionDao
abstract fun DepictsDao (): DepictsDao;
abstract fun DepictsDao(): DepictsDao;
}

View file

@ -29,7 +29,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@BindView(R.id.explore_container)
FrameLayout container;
public ExploreListRootFragment(){
public ExploreListRootFragment() {
//empty constructor necessary otherwise crashes on recreate
}
@ -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);
@ -54,7 +55,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if(savedInstanceState == null) {
if (savedInstanceState == null) {
setFragment(listFragment, mediaDetails);
}
}
@ -64,18 +65,18 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
getChildFragmentManager()
.beginTransaction()
.hide(otherFragment)
.show( fragment)
.show(fragment)
.addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
.commit();
getChildFragmentManager().executePendingTransactions();
} else if (fragment.isAdded() && otherFragment == null) {
getChildFragmentManager()
.beginTransaction()
.show( fragment)
.show(fragment)
.addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
.commit();
getChildFragmentManager().executePendingTransactions();
} else if (!fragment.isAdded() && otherFragment != null ) {
} else if (!fragment.isAdded() && otherFragment != null) {
getChildFragmentManager()
.beginTransaction()
.hide(otherFragment)
@ -109,7 +110,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@Override
public void onMediaClicked(int position) {
container.setVisibility(View.VISIBLE);
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.GONE);
((ExploreFragment) getParentFragment()).tabLayout.setVisibility(View.GONE);
mediaDetails = new MediaDetailPagerFragment(false, true);
setFragment(mediaDetails, listFragment);
mediaDetails.showImage(position);
@ -139,7 +140,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
*/
@Override
public int getTotalMediaCount() {
if (listFragment!=null) {
if (listFragment != null) {
return listFragment.getTotalMediaCount();
} else {
return 0;
@ -158,7 +159,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
*/
@Override
public void refreshNominatedMedia(int index) {
if(mediaDetails != null && !listFragment.isVisible()) {
if (mediaDetails != null && !listFragment.isVisible()) {
removeFragment(mediaDetails);
onMediaClicked(index);
}
@ -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)
@ -43,7 +46,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
ButterKnife.bind(this, rootView);
recentSearches = recentSearchesDao.recentSearches(10);
if(recentSearches.isEmpty()) {
if (recentSearches.isEmpty()) {
recent_searches_delete_button.setVisibility(View.GONE);
recent_searches_text_view.setText(R.string.no_recent_searches);
}
@ -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,22 +72,24 @@ 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)));
(SearchActivity) getContext()).updateText(recentSearches.get(position)));
recentSearchesList.setOnItemLongClickListener((parent, view, position, id) -> {
new AlertDialog.Builder(getContext())
.setMessage(R.string.delete_search_dialog)
.setPositiveButton(getString(R.string.delete).toUpperCase(),((dialog, which) -> {
.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();
}))
.setNegativeButton(android.R.string.cancel,null)
.setNegativeButton(android.R.string.cancel, null)
.create()
.show();
return true;
@ -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() {
@ -108,7 +115,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
recentSearches = recentSearchesDao.recentSearches(10);
adapter.notifyDataSetChanged();
if(!recentSearches.isEmpty()) {
if (!recentSearches.isEmpty()) {
recent_searches_delete_button.setVisibility(View.VISIBLE);
recent_searches_text_view.setText(R.string.search_recent_header);
}

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,12 +331,13 @@ 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() + "\"")
.replace("${LIMIT}",""+ limit)
.replace("${OFFSET}",""+ startPosition);
.replace("${LIMIT}", "" + limit)
.replace("${OFFSET}", "" + startPosition);
HttpUrl.Builder urlBuilder = HttpUrl
.parse(sparqlQueryUrl)
.newBuilder()

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
@ -25,7 +24,7 @@ public enum NavTab implements EnumCode {
return ContributionsFragment.newInstance();
}
},
NEARBY(R.string.nearby_fragment, R.drawable.ic_location_on_black_24dp){
NEARBY(R.string.nearby_fragment, R.drawable.ic_location_on_black_24dp) {
@NonNull
@Override
public Fragment newInstance() {

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

@ -26,7 +26,7 @@ public class NavTabLayout extends BottomNavigationView {
}
private void setTabViews() {
if (((MainActivity)getContext()).applicationKvStore.getBoolean("login_skipped") == true) {
if (((MainActivity) getContext()).applicationKvStore.getBoolean("login_skipped") == true) {
for (int i = 0; i < NavTabLoggedOut.size(); i++) {
NavTabLoggedOut navTab = NavTabLoggedOut.of(i);
getMenu().add(Menu.NONE, i, i, navTab.text()).setIcon(navTab.icon());

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) {
@ -114,7 +115,7 @@ public class UploadItem {
}
public void setHasInvalidLocation(boolean hasInvalidLocation) {
this.hasInvalidLocation=hasInvalidLocation;
this.hasInvalidLocation = hasInvalidLocation;
}
public boolean hasInvalidLocation() {

View file

@ -4,9 +4,10 @@ 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) {
for (int flag : flags) {
intent.addFlags(flag);
}
context.startActivity(intent);

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 -> {