mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Migrated util module files from java to kotlin (#5935)
* Rename .java to .kt * Migrated the following files in util module to Kotlin - AbstractTextWatcher - ActivityUtils - CommonsDateUtil - DateUtil * Rename .java to .kt * Migrated the following files in util module to Kotlin - DeviceInfoUtil - ExecutorUtils - FragmentUtils
This commit is contained in:
parent
248c7b0ceb
commit
5c8c4032e9
22 changed files with 288 additions and 290 deletions
|
|
@ -12,15 +12,15 @@ import androidx.annotation.Nullable;
|
|||
import fr.free.nrw.commons.campaigns.models.Campaign;
|
||||
import fr.free.nrw.commons.databinding.LayoutCampaginBinding;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.utils.DateUtil;
|
||||
import fr.free.nrw.commons.utils.CommonsDateUtil;
|
||||
|
||||
import fr.free.nrw.commons.utils.DateUtil;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.utils.CommonsDateUtil;
|
||||
import fr.free.nrw.commons.utils.SwipableCardView;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons.campaigns;
|
|||
import android.annotation.SuppressLint;
|
||||
|
||||
import fr.free.nrw.commons.campaigns.models.Campaign;
|
||||
import fr.free.nrw.commons.utils.CommonsDateUtil;
|
||||
import java.text.ParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
|
@ -14,7 +15,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import fr.free.nrw.commons.BasePresenter;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
import fr.free.nrw.commons.utils.CommonsDateUtil;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleObserver;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package fr.free.nrw.commons.delete;
|
|||
import android.content.Context;
|
||||
|
||||
import fr.free.nrw.commons.utils.DateUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.ViewPagerAdapter;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ import fr.free.nrw.commons.Utils;
|
|||
import fr.free.nrw.commons.actions.ThanksClient;
|
||||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient;
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException;
|
||||
import fr.free.nrw.commons.category.CategoryClient;
|
||||
import fr.free.nrw.commons.category.CategoryDetailsActivity;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package fr.free.nrw.commons.upload.mediaDetails;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static fr.free.nrw.commons.utils.ActivityUtils.startActivityWithFlags;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
|
|
@ -45,6 +44,7 @@ import fr.free.nrw.commons.upload.UploadBaseFragment;
|
|||
import fr.free.nrw.commons.upload.UploadItem;
|
||||
import fr.free.nrw.commons.upload.UploadMediaDetail;
|
||||
import fr.free.nrw.commons.upload.UploadMediaDetailAdapter;
|
||||
import fr.free.nrw.commons.utils.ActivityUtils;
|
||||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import fr.free.nrw.commons.utils.ImageUtils;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
|
|
@ -208,7 +208,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
|
||||
try {
|
||||
if(!presenter.getImageQuality(indexOfFragment, inAppPictureLocation, getActivity())) {
|
||||
startActivityWithFlags(
|
||||
ActivityUtils.startActivityWithFlags(
|
||||
getActivity(), MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class AbstractTextWatcher implements TextWatcher {
|
||||
private final TextChange textChange;
|
||||
|
||||
public AbstractTextWatcher(@NonNull TextChange textChange) {
|
||||
this.textChange = textChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
textChange.onTextChanged(s.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
public interface TextChange {
|
||||
void onTextChanged(String value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
|
||||
class AbstractTextWatcher(
|
||||
private val textChange: TextChange
|
||||
) : TextWatcher {
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
textChange.onTextChanged(s.toString())
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
interface TextChange {
|
||||
fun onTextChanged(value: String)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
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) {
|
||||
intent.addFlags(flag);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
16
app/src/main/java/fr/free/nrw/commons/utils/ActivityUtils.kt
Normal file
16
app/src/main/java/fr/free/nrw/commons/utils/ActivityUtils.kt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
object ActivityUtils {
|
||||
|
||||
@JvmStatic
|
||||
fun <T> startActivityWithFlags(context: Context, cls: Class<T>, vararg flags: Int) {
|
||||
val intent = Intent(context, cls)
|
||||
for (flag in flags) {
|
||||
intent.addFlags(flag)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Provides util functions for formatting date time
|
||||
* Most of our formatting needs are addressed by the data library's DateUtil class
|
||||
* Methods should be added here only if DateUtil class doesn't provide for it already
|
||||
*/
|
||||
public class CommonsDateUtil {
|
||||
|
||||
/**
|
||||
* Gets SimpleDateFormat for short date pattern
|
||||
* @return simpledateformat
|
||||
*/
|
||||
public static SimpleDateFormat getIso8601DateFormatShort() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
|
||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return simpleDateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets SimpleDateFormat for date pattern returned by Media object
|
||||
* @return simpledateformat
|
||||
*/
|
||||
public static SimpleDateFormat getMediaSimpleDateFormat() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
|
||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return simpleDateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the timestamp pattern for a date
|
||||
* @return timestamp
|
||||
*/
|
||||
public static SimpleDateFormat getIso8601DateFormatTimestamp() {
|
||||
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",
|
||||
Locale.ROOT);
|
||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return simpleDateFormat;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
/**
|
||||
* Provides util functions for formatting date time.
|
||||
* Most of our formatting needs are addressed by the data library's DateUtil class.
|
||||
* Methods should be added here only if DateUtil class doesn't provide for it already.
|
||||
*/
|
||||
object CommonsDateUtil {
|
||||
|
||||
/**
|
||||
* Gets SimpleDateFormat for short date pattern.
|
||||
* @return simpleDateFormat
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getIso8601DateFormatShort(): SimpleDateFormat {
|
||||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT)
|
||||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return simpleDateFormat
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets SimpleDateFormat for date pattern returned by Media object.
|
||||
* @return simpleDateFormat
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMediaSimpleDateFormat(): SimpleDateFormat {
|
||||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT)
|
||||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return simpleDateFormat
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the timestamp pattern for a date.
|
||||
* @return timestamp
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getIso8601DateFormatTimestamp(): SimpleDateFormat {
|
||||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT)
|
||||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return simpleDateFormat
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import static android.text.format.DateFormat.getBestDateTimePattern;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public final class DateUtil {
|
||||
private static Map<String, SimpleDateFormat> DATE_FORMATS = new HashMap<>();
|
||||
|
||||
// TODO: Switch to DateTimeFormatter when minSdk = 26.
|
||||
|
||||
public static synchronized String iso8601DateFormat(Date date) {
|
||||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).format(date);
|
||||
}
|
||||
|
||||
public static synchronized Date iso8601DateParse(String date) throws ParseException {
|
||||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).parse(date);
|
||||
}
|
||||
|
||||
public static String getMonthOnlyDateString(@NonNull Date date) {
|
||||
return getDateStringWithSkeletonPattern(date, "MMMM d");
|
||||
}
|
||||
|
||||
public static String getExtraShortDateString(@NonNull Date date) {
|
||||
return getDateStringWithSkeletonPattern(date, "MMM d");
|
||||
}
|
||||
|
||||
public static synchronized String getDateStringWithSkeletonPattern(@NonNull Date date, @NonNull String pattern) {
|
||||
return getCachedDateFormat(getBestDateTimePattern(Locale.getDefault(), pattern), Locale.getDefault(), false).format(date);
|
||||
}
|
||||
|
||||
private static SimpleDateFormat getCachedDateFormat(String pattern, Locale locale, boolean utc) {
|
||||
if (!DATE_FORMATS.containsKey(pattern)) {
|
||||
SimpleDateFormat df = new SimpleDateFormat(pattern, locale);
|
||||
if (utc) {
|
||||
df.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
DATE_FORMATS.put(pattern, df);
|
||||
}
|
||||
return DATE_FORMATS.get(pattern);
|
||||
}
|
||||
|
||||
private DateUtil() {
|
||||
}
|
||||
}
|
||||
62
app/src/main/java/fr/free/nrw/commons/utils/DateUtil.kt
Normal file
62
app/src/main/java/fr/free/nrw/commons/utils/DateUtil.kt
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.text.format.DateFormat.getBestDateTimePattern
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.HashMap
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
/**
|
||||
* Utility class for date formatting and parsing.
|
||||
* TODO: Switch to DateTimeFormatter when minSdk = 26.
|
||||
*/
|
||||
object DateUtil {
|
||||
|
||||
private val DATE_FORMATS: MutableMap<String, SimpleDateFormat> = HashMap()
|
||||
|
||||
@JvmStatic
|
||||
@Synchronized
|
||||
fun iso8601DateFormat(date: Date): String {
|
||||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).format(date)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Synchronized
|
||||
@Throws(ParseException::class)
|
||||
fun iso8601DateParse(date: String): Date {
|
||||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).parse(date)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMonthOnlyDateString(date: Date): String {
|
||||
return getDateStringWithSkeletonPattern(date, "MMMM d")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getExtraShortDateString(date: Date): String {
|
||||
return getDateStringWithSkeletonPattern(date, "MMM d")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Synchronized
|
||||
fun getDateStringWithSkeletonPattern(date: Date, pattern: String): String {
|
||||
return getCachedDateFormat(
|
||||
getBestDateTimePattern(Locale.getDefault(), pattern),
|
||||
Locale.getDefault(), false
|
||||
).format(date)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
private fun getCachedDateFormat(pattern: String, locale: Locale, utc: Boolean): SimpleDateFormat {
|
||||
if (!DATE_FORMATS.containsKey(pattern)) {
|
||||
val df = SimpleDateFormat(pattern, locale)
|
||||
if (utc) {
|
||||
df.timeZone = TimeZone.getTimeZone("UTC")
|
||||
}
|
||||
DATE_FORMATS[pattern] = df
|
||||
}
|
||||
return DATE_FORMATS[pattern]!!
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import fr.free.nrw.commons.utils.model.ConnectionType;
|
||||
import fr.free.nrw.commons.utils.model.NetworkConnectionType;
|
||||
|
||||
import static fr.free.nrw.commons.utils.model.ConnectionType.CELLULAR;
|
||||
import static fr.free.nrw.commons.utils.model.ConnectionType.CELLULAR_3G;
|
||||
import static fr.free.nrw.commons.utils.model.ConnectionType.CELLULAR_4G;
|
||||
import static fr.free.nrw.commons.utils.model.ConnectionType.NO_INTERNET;
|
||||
import static fr.free.nrw.commons.utils.model.ConnectionType.WIFI_NETWORK;
|
||||
import static fr.free.nrw.commons.utils.model.NetworkConnectionType.FOUR_G;
|
||||
import static fr.free.nrw.commons.utils.model.NetworkConnectionType.THREE_G;
|
||||
import static fr.free.nrw.commons.utils.model.NetworkConnectionType.TWO_G;
|
||||
import static fr.free.nrw.commons.utils.model.NetworkConnectionType.UNKNOWN;
|
||||
import static fr.free.nrw.commons.utils.model.NetworkConnectionType.WIFI;
|
||||
|
||||
/**
|
||||
* Util class to get any information about the user's device
|
||||
* Ensure that any sensitive information like IMEI is not fetched/shared without user's consent
|
||||
*/
|
||||
public class DeviceInfoUtil {
|
||||
private static final Map<NetworkConnectionType, ConnectionType> TYPE_MAPPING = new HashMap<>();
|
||||
|
||||
static {
|
||||
TYPE_MAPPING.put(TWO_G, CELLULAR);
|
||||
TYPE_MAPPING.put(THREE_G, CELLULAR_3G);
|
||||
TYPE_MAPPING.put(FOUR_G, CELLULAR_4G);
|
||||
TYPE_MAPPING.put(WIFI, WIFI_NETWORK);
|
||||
TYPE_MAPPING.put(UNKNOWN, CELLULAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network connection type
|
||||
* @param context
|
||||
* @return wifi/cellular-4g/cellular-3g/cellular-2g/no-internet
|
||||
*/
|
||||
public static ConnectionType getConnectionType(Context context) {
|
||||
if (!NetworkUtils.isInternetConnectionEstablished(context)) {
|
||||
return NO_INTERNET;
|
||||
}
|
||||
NetworkConnectionType networkType = NetworkUtils.getNetworkType(context);
|
||||
ConnectionType deviceNetworkType = TYPE_MAPPING.get(networkType);
|
||||
return deviceNetworkType == null ? CELLULAR : deviceNetworkType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Device manufacturer
|
||||
* @return
|
||||
*/
|
||||
public static String getDeviceManufacturer() {
|
||||
return Build.MANUFACTURER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Device model name
|
||||
* @return
|
||||
*/
|
||||
public static String getDeviceModel() {
|
||||
return Build.MODEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Android version. Eg. 4.4.2
|
||||
* @return
|
||||
*/
|
||||
public static String getAndroidVersion() {
|
||||
return Build.VERSION.RELEASE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API Level. Eg. 26
|
||||
* @return
|
||||
*/
|
||||
public static String getAPILevel() {
|
||||
return Build.VERSION.SDK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Device.
|
||||
* @return
|
||||
*/
|
||||
public static String getDevice() {
|
||||
return Build.DEVICE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import fr.free.nrw.commons.utils.model.ConnectionType
|
||||
import fr.free.nrw.commons.utils.model.NetworkConnectionType
|
||||
|
||||
/**
|
||||
* Util class to get any information about the user's device
|
||||
* Ensure that any sensitive information like IMEI is not fetched/shared without user's consent
|
||||
*/
|
||||
object DeviceInfoUtil {
|
||||
private val TYPE_MAPPING = mapOf(
|
||||
NetworkConnectionType.TWO_G to ConnectionType.CELLULAR,
|
||||
NetworkConnectionType.THREE_G to ConnectionType.CELLULAR_3G,
|
||||
NetworkConnectionType.FOUR_G to ConnectionType.CELLULAR_4G,
|
||||
NetworkConnectionType.WIFI to ConnectionType.WIFI_NETWORK,
|
||||
NetworkConnectionType.UNKNOWN to ConnectionType.CELLULAR
|
||||
)
|
||||
|
||||
/**
|
||||
* Get network connection type
|
||||
* @param context
|
||||
* @return wifi/cellular-4g/cellular-3g/cellular-2g/no-internet
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getConnectionType(context: Context): ConnectionType {
|
||||
return if (!NetworkUtils.isInternetConnectionEstablished(context)) {
|
||||
ConnectionType.NO_INTERNET
|
||||
} else {
|
||||
val networkType = NetworkUtils.getNetworkType(context)
|
||||
TYPE_MAPPING[networkType] ?: ConnectionType.CELLULAR
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Device manufacturer
|
||||
* @return
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getDeviceManufacturer(): String {
|
||||
return Build.MANUFACTURER
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Device model name
|
||||
* @return
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getDeviceModel(): String {
|
||||
return Build.MODEL
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Android version. Eg. 4.4.2
|
||||
* @return
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getAndroidVersion(): String {
|
||||
return Build.VERSION.RELEASE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API Level. Eg. 26
|
||||
* @return
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getAPILevel(): String {
|
||||
return Build.VERSION.SDK
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Device.
|
||||
* @return
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getDevice(): String {
|
||||
return Build.DEVICE
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class ExecutorUtils {
|
||||
|
||||
private static final Executor uiExecutor = command -> {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
command.run();
|
||||
} else {
|
||||
new Handler(Looper.getMainLooper()).post(command);
|
||||
}
|
||||
};
|
||||
|
||||
public static Executor uiExecutor() {
|
||||
return uiExecutor;
|
||||
}
|
||||
|
||||
|
||||
private static final ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
|
||||
public static ExecutorService get() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
}
|
||||
33
app/src/main/java/fr/free/nrw/commons/utils/ExecutorUtils.kt
Normal file
33
app/src/main/java/fr/free/nrw/commons/utils/ExecutorUtils.kt
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
object ExecutorUtils {
|
||||
|
||||
@JvmStatic
|
||||
private val uiExecutor: Executor = Executor { command ->
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
command.run()
|
||||
} else {
|
||||
Handler(Looper.getMainLooper()).post(command)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun uiExecutor(): Executor {
|
||||
return uiExecutor
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
private val executor: ExecutorService = Executors.newFixedThreadPool(3)
|
||||
|
||||
@JvmStatic
|
||||
fun get(): ExecutorService {
|
||||
return executor
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class FragmentUtils {
|
||||
|
||||
/**
|
||||
* Utility function to check whether the fragment UI is still active or not
|
||||
* @param fragment
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFragmentUIActive(Fragment fragment) {
|
||||
return fragment!=null && fragment.getActivity() != null && fragment.isAdded() && !fragment.isDetached() && !fragment.isRemoving();
|
||||
}
|
||||
}
|
||||
20
app/src/main/java/fr/free/nrw/commons/utils/FragmentUtils.kt
Normal file
20
app/src/main/java/fr/free/nrw/commons/utils/FragmentUtils.kt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
object FragmentUtils {
|
||||
|
||||
/**
|
||||
* Utility function to check whether the fragment UI is still active or not
|
||||
* @param fragment
|
||||
* @return Boolean
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isFragmentUIActive(fragment: Fragment?): Boolean {
|
||||
return fragment != null &&
|
||||
fragment.activity != null &&
|
||||
fragment.isAdded &&
|
||||
!fragment.isDetached &&
|
||||
!fragment.isRemoving
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,8 @@ import com.google.gson.JsonElement;
|
|||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import fr.free.nrw.commons.utils.DateUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import fr.free.nrw.commons.wikidata.GsonUtil;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue