mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
convert Utils to kotlin
This commit is contained in:
parent
28da88d5b3
commit
8849f56c10
@ -1,34 +0,0 @@
|
|||||||
package com.simplemobiletools.filemanager;
|
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
public static String getFilename(final String path) {
|
|
||||||
return path.substring(path.lastIndexOf("/") + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getFileExtension(String fileName) {
|
|
||||||
return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showToast(Context context, int resId) {
|
|
||||||
Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasStoragePermission(Context cxt) {
|
|
||||||
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNameValid(String name) {
|
|
||||||
final Pattern pattern = Pattern.compile("^[-_.A-Za-z0-9 ]+$");
|
|
||||||
final Matcher matcher = pattern.matcher(name);
|
|
||||||
return matcher.matches();
|
|
||||||
}
|
|
||||||
}
|
|
32
app/src/main/java/com/simplemobiletools/filemanager/Utils.kt
Normal file
32
app/src/main/java/com/simplemobiletools/filemanager/Utils.kt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.simplemobiletools.filemanager
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.support.v4.content.ContextCompat
|
||||||
|
import android.widget.Toast
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
|
object Utils {
|
||||||
|
fun getFilename(path: String): String {
|
||||||
|
return path.substring(path.lastIndexOf("/") + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFileExtension(fileName: String): String {
|
||||||
|
return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showToast(context: Context, resId: Int) {
|
||||||
|
Toast.makeText(context, context.resources.getString(resId), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasStoragePermission(cxt: Context): Boolean {
|
||||||
|
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isNameValid(name: String): Boolean {
|
||||||
|
val pattern = Pattern.compile("^[-_.A-Za-z0-9 ]+$")
|
||||||
|
val matcher = pattern.matcher(name)
|
||||||
|
return matcher.matches()
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user