Skip to content

Commit

Permalink
Migrated all remaining files in util module
Browse files Browse the repository at this point in the history
  • Loading branch information
Saifuddin53 committed Nov 18, 2024
1 parent a42067e commit d543625
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 566 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void initiateCameraPick(Activity activity,
},
R.string.storage_permission_title,
R.string.write_storage_permission_rationale,
PermissionUtils.PERMISSIONS_STORAGE);
PermissionUtils.getPERMISSIONS_STORAGE());
}

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ public void initiateCustomGalleryPickWithPermission(final Activity activity, Act
() -> FilePicker.openCustomSelector(activity, resultLauncher, 0),
R.string.storage_permission_title,
R.string.write_storage_permission_rationale,
PermissionUtils.PERMISSIONS_STORAGE);
PermissionUtils.getPERMISSIONS_STORAGE());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package fr.free.nrw.commons.contributions;

import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -16,10 +13,8 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;
import androidx.work.ExistingWorkPolicy;
import fr.free.nrw.commons.databinding.MainBinding;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.WelcomeActivity;
import fr.free.nrw.commons.auth.SessionManager;
Expand All @@ -41,7 +36,6 @@
import fr.free.nrw.commons.quiz.QuizChecker;
import fr.free.nrw.commons.settings.SettingsFragment;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.upload.UploadActivity;
import fr.free.nrw.commons.upload.UploadProgressActivity;
import fr.free.nrw.commons.upload.worker.WorkRequestHelper;
import fr.free.nrw.commons.utils.PermissionUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
import static fr.free.nrw.commons.utils.MapUtils.ZOOM_LEVEL;

import android.Manifest;
import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
Expand All @@ -21,22 +19,17 @@
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import fr.free.nrw.commons.BaseMarker;
import fr.free.nrw.commons.MapController;
Expand All @@ -48,7 +41,6 @@
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.explore.ExploreMapRootFragment;
import fr.free.nrw.commons.explore.paging.LiveDataConverter;
import fr.free.nrw.commons.filepicker.Constants;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationPermissionsHelper;
Expand All @@ -60,7 +52,6 @@
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.MapUtils;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.PermissionUtils;
import fr.free.nrw.commons.utils.SystemThemeUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void run() {
}

public void launchZoomActivity(final View view) {
final boolean hasPermission = PermissionUtils.hasPermission(getActivity(), PermissionUtils.PERMISSIONS_STORAGE);
final boolean hasPermission = PermissionUtils.hasPermission(getActivity(), PermissionUtils.getPERMISSIONS_STORAGE());
if (hasPermission) {
launchZoomActivityAfterPermissionCheck(view);
} else {
Expand All @@ -328,7 +328,7 @@ public void launchZoomActivity(final View view) {
},
R.string.storage_permission_title,
R.string.read_storage_permission_rationale,
PermissionUtils.PERMISSIONS_STORAGE
PermissionUtils.getPERMISSIONS_STORAGE()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
Expand Down Expand Up @@ -543,7 +542,7 @@ private String getCurrentLanguageCode(final String preferenceKey) {
* First checks for external storage permissions and then sends logs via email
*/
private void checkPermissionsAndSendLogs() {
if (PermissionUtils.hasPermission(getActivity(), PermissionUtils.PERMISSIONS_STORAGE)) {
if (PermissionUtils.hasPermission(getActivity(), PermissionUtils.getPERMISSIONS_STORAGE())) {
commonsLogSender.send(getActivity(), null);
} else {
requestExternalStoragePermissions();
Expand All @@ -556,7 +555,7 @@ private void checkPermissionsAndSendLogs() {
*/
private void requestExternalStoragePermissions() {
Dexter.withActivity(getActivity())
.withPermissions(PermissionUtils.PERMISSIONS_STORAGE)
.withPermissions(PermissionUtils.getPERMISSIONS_STORAGE())
.withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.free.nrw.commons.upload;

import static fr.free.nrw.commons.contributions.ContributionController.ACTION_INTERNAL_UPLOADS;
import static fr.free.nrw.commons.utils.PermissionUtils.PERMISSIONS_STORAGE;
import static fr.free.nrw.commons.utils.PermissionUtils.checkPermissionsAndPerformAction;
import static fr.free.nrw.commons.utils.PermissionUtils.getPERMISSIONS_STORAGE;
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
import static fr.free.nrw.commons.wikidata.WikidataConstants.SELECTED_NEARBY_PLACE;
import static fr.free.nrw.commons.wikidata.WikidataConstants.SELECTED_NEARBY_PLACE_CATEGORY;
Expand Down Expand Up @@ -32,7 +32,6 @@
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.work.ExistingWorkPolicy;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.auth.SessionManager;
Expand Down Expand Up @@ -277,7 +276,7 @@ protected void checkBlockStatus() {

public void checkStoragePermissions() {
// Check if all required permissions are granted
final boolean hasAllPermissions = PermissionUtils.hasPermission(this, PERMISSIONS_STORAGE);
final boolean hasAllPermissions = PermissionUtils.hasPermission(this, getPERMISSIONS_STORAGE());
final boolean hasPartialAccess = PermissionUtils.hasPartialAccess(this);
if (hasAllPermissions || hasPartialAccess) {
// All required permissions are granted, so enable UI elements and perform actions
Expand All @@ -297,7 +296,7 @@ public void checkStoragePermissions() {
},
R.string.storage_permission_title,
R.string.write_storage_permission_rationale_for_image_share,
PERMISSIONS_STORAGE);
getPERMISSIONS_STORAGE());
}
}
/* If all permissions are not granted and a dialog is already showing on screen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package fr.free.nrw.commons.utils;
package fr.free.nrw.commons.utils

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils

import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList

object MediaDataExtractorUtil {

public class MediaDataExtractorUtil {
/**
* Extracts a list of categories from | separated category string
*
* @param source
* @return
*/
public static List<String> extractCategoriesFromList(String source) {
if (StringUtils.isBlank(source)) {
return new ArrayList<>();
@JvmStatic
fun extractCategoriesFromList(source: String): List<String> {
if (source.isBlank()) {
return emptyList()
}
String[] cats = source.split("\\|");
List<String> categories = new ArrayList<>();
for (String category : cats) {
if (!StringUtils.isBlank(category.trim())) {
categories.add(category);
val cats = source.split("|")
val categories = mutableListOf<String>()
for (category in cats) {
if (category.trim().isNotBlank()) {
categories.add(category)
}
}
return categories;
return categories
}

}
76 changes: 40 additions & 36 deletions app/src/main/java/fr/free/nrw/commons/utils/NearbyFABUtils.kt
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
package fr.free.nrw.commons.utils;
package fr.free.nrw.commons.utils

import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.floatingactionbutton.FloatingActionButton

import androidx.coordinatorlayout.widget.CoordinatorLayout;
object NearbyFABUtils {

import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class NearbyFABUtils {
/*
* Add anchors back before making them visible again.
* */
public static void addAnchorToBigFABs(FloatingActionButton floatingActionButton, int anchorID) {
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
params.setAnchorId(anchorID);
params.anchorGravity = Gravity.TOP|Gravity.RIGHT|Gravity.END;
floatingActionButton.setLayoutParams(params);
*/
@JvmStatic
fun addAnchorToBigFABs(floatingActionButton: FloatingActionButton, anchorID: Int) {
val params = CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
params.anchorId = anchorID
params.anchorGravity = Gravity.TOP or Gravity.RIGHT or Gravity.END
floatingActionButton.layoutParams = params
}

/*
* Add anchors back before making them visible again. Big and small fabs have different anchor
* gravities, therefore the are two methods.
* */
public static void addAnchorToSmallFABs(FloatingActionButton floatingActionButton, int anchorID) {
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
params.setAnchorId(anchorID);
params.anchorGravity = Gravity.CENTER_HORIZONTAL;
floatingActionButton.setLayoutParams(params);
* gravities, therefore there are two methods.
*/
@JvmStatic
fun addAnchorToSmallFABs(floatingActionButton: FloatingActionButton, anchorID: Int) {
val params = CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
params.anchorId = anchorID
params.anchorGravity = Gravity.CENTER_HORIZONTAL
floatingActionButton.layoutParams = params
}

/*
* We are not able to hide FABs without removing anchors, this method removes anchors
* */
public static void removeAnchorFromFAB(FloatingActionButton floatingActionButton) {
//get rid of anchors
//Somehow this was the only way https://stackoverflow.com/questions/32732932
// /floatingactionbutton-visible-for-sometime-even-if-visibility-is-set-to-gone
CoordinatorLayout.LayoutParams param = (CoordinatorLayout.LayoutParams) floatingActionButton
.getLayoutParams();
param.setAnchorId(View.NO_ID);
* We are not able to hide FABs without removing anchors, this method removes anchors.
*/
@JvmStatic
fun removeAnchorFromFAB(floatingActionButton: FloatingActionButton) {
// get rid of anchors
// Somehow this was the only way https://stackoverflow.com/questions/32732932
// floatingactionbutton-visible-for-sometime-even-if-visibility-is-set-to-gone
val params = floatingActionButton.layoutParams as CoordinatorLayout.LayoutParams
params.anchorId = View.NO_ID
// If we don't set them to zero, then they become visible for a moment on upper left side
param.width = 0;
param.height = 0;
floatingActionButton.setLayoutParams(param);
params.width = 0
params.height = 0
floatingActionButton.layoutParams = params
}

}
Loading

0 comments on commit d543625

Please sign in to comment.