mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
convert some utils to kotlin
This commit is contained in:
parent
9b76051dd5
commit
b1628492f5
@ -1,18 +1,17 @@
|
|||||||
package awais.instagrabber.utils;
|
package awais.instagrabber.utils
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import java.time.LocalDateTime
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
object DateUtils {
|
||||||
import java.util.Calendar;
|
val timezoneOffset: Int
|
||||||
import java.util.Locale;
|
get() {
|
||||||
|
val calendar = Calendar.getInstance(Locale.getDefault())
|
||||||
|
return -(calendar[Calendar.ZONE_OFFSET] + calendar[Calendar.DST_OFFSET]) / (60 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
public final class DateUtils {
|
@JvmStatic
|
||||||
public static int getTimezoneOffset() {
|
fun isBeforeOrEqual(localDateTime: LocalDateTime, comparedTo: LocalDateTime): Boolean {
|
||||||
final Calendar calendar = Calendar.getInstance(Locale.getDefault());
|
return localDateTime.isBefore(comparedTo) || localDateTime.isEqual(comparedTo)
|
||||||
return -(calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static boolean isBeforeOrEqual(@NonNull final LocalDateTime localDateTime, @NonNull final LocalDateTime comparedTo) {
|
|
||||||
return localDateTime.isBefore(comparedTo) || localDateTime.isEqual(comparedTo);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +1,53 @@
|
|||||||
package awais.instagrabber.utils;
|
package awais.instagrabber.utils
|
||||||
|
|
||||||
import android.content.Context;
|
import android.Manifest.permission
|
||||||
import android.content.pm.PackageManager;
|
import android.content.Context
|
||||||
|
import androidx.core.content.PermissionChecker
|
||||||
|
import awais.instagrabber.utils.PermissionUtils
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
object PermissionUtils {
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
val AUDIO_RECORD_PERMS = arrayOf(permission.RECORD_AUDIO)
|
||||||
import androidx.core.app.ActivityCompat;
|
val ATTACH_MEDIA_PERMS = arrayOf(permission.READ_EXTERNAL_STORAGE)
|
||||||
import androidx.core.content.ContextCompat;
|
val CAMERA_PERMS = arrayOf(permission.CAMERA)
|
||||||
import androidx.core.content.PermissionChecker;
|
@JvmStatic
|
||||||
import androidx.fragment.app.Fragment;
|
fun hasAudioRecordPerms(context: Context): Boolean {
|
||||||
|
return PermissionChecker.checkSelfPermission(
|
||||||
import static android.Manifest.permission.CAMERA;
|
context,
|
||||||
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
permission.RECORD_AUDIO
|
||||||
import static android.Manifest.permission.RECORD_AUDIO;
|
) == PermissionChecker.PERMISSION_GRANTED
|
||||||
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
|
||||||
|
|
||||||
public class PermissionUtils {
|
|
||||||
public static final String[] AUDIO_RECORD_PERMS = new String[]{RECORD_AUDIO};
|
|
||||||
public static final String[] ATTACH_MEDIA_PERMS = new String[]{READ_EXTERNAL_STORAGE};
|
|
||||||
public static final String[] CAMERA_PERMS = new String[]{CAMERA};
|
|
||||||
|
|
||||||
public static boolean hasAudioRecordPerms(@NonNull final Context context) {
|
|
||||||
return checkSelfPermission(context, RECORD_AUDIO) == PermissionChecker.PERMISSION_GRANTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requestAudioRecordPerms(final Fragment fragment, final int requestCode) {
|
@JvmStatic
|
||||||
fragment.requestPermissions(AUDIO_RECORD_PERMS, requestCode);
|
fun requestAudioRecordPerms(fragment: Fragment, requestCode: Int) {
|
||||||
|
fragment.requestPermissions(AUDIO_RECORD_PERMS, requestCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasAttachMediaPerms(@NonNull final Context context) {
|
@JvmStatic
|
||||||
return checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
|
fun hasAttachMediaPerms(context: Context): Boolean {
|
||||||
|
return PermissionChecker.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
permission.READ_EXTERNAL_STORAGE
|
||||||
|
) == PermissionChecker.PERMISSION_GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requestAttachMediaPerms(final Fragment fragment, final int requestCode) {
|
@JvmStatic
|
||||||
fragment.requestPermissions(ATTACH_MEDIA_PERMS, requestCode);
|
fun requestAttachMediaPerms(fragment: Fragment, requestCode: Int) {
|
||||||
|
fragment.requestPermissions(ATTACH_MEDIA_PERMS, requestCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasCameraPerms(final Context context) {
|
fun hasCameraPerms(context: Context?): Boolean {
|
||||||
return ContextCompat.checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
|
return ContextCompat.checkSelfPermission(
|
||||||
|
context!!,
|
||||||
|
permission.CAMERA
|
||||||
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requestCameraPerms(final AppCompatActivity activity, final int requestCode) {
|
fun requestCameraPerms(activity: AppCompatActivity?, requestCode: Int) {
|
||||||
ActivityCompat.requestPermissions(activity, CAMERA_PERMS, requestCode);
|
ActivityCompat.requestPermissions(activity!!, CAMERA_PERMS, requestCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -132,7 +132,7 @@ class MediaRepository(private val service: MediaService) {
|
|||||||
videoOptions.clips = listOf(Clip(videoOptions.length, options.sourceType))
|
videoOptions.clips = listOf(Clip(videoOptions.length, options.sourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val timezoneOffset = DateUtils.getTimezoneOffset().toString()
|
val timezoneOffset = DateUtils.timezoneOffset.toString()
|
||||||
val form = mutableMapOf<String, Any>(
|
val form = mutableMapOf<String, Any>(
|
||||||
"timezone_offset" to timezoneOffset,
|
"timezone_offset" to timezoneOffset,
|
||||||
"_csrftoken" to csrfToken,
|
"_csrftoken" to csrfToken,
|
||||||
|
Loading…
Reference in New Issue
Block a user