1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

convert some utils to kotlin

This commit is contained in:
Austin Huang 2021-06-22 19:23:41 -04:00
parent 9b76051dd5
commit b1628492f5
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 54 additions and 48 deletions

View File

@ -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;
import java.util.Calendar;
import java.util.Locale;
object DateUtils {
val timezoneOffset: Int
get() {
val calendar = Calendar.getInstance(Locale.getDefault())
return -(calendar[Calendar.ZONE_OFFSET] + calendar[Calendar.DST_OFFSET]) / (60 * 1000)
}
public final class DateUtils {
public static int getTimezoneOffset() {
final Calendar calendar = Calendar.getInstance(Locale.getDefault());
return -(calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
@JvmStatic
fun isBeforeOrEqual(localDateTime: LocalDateTime, comparedTo: LocalDateTime): Boolean {
return localDateTime.isBefore(comparedTo) || localDateTime.isEqual(comparedTo)
}
public static boolean isBeforeOrEqual(@NonNull final LocalDateTime localDateTime, @NonNull final LocalDateTime comparedTo) {
return localDateTime.isBefore(comparedTo) || localDateTime.isEqual(comparedTo);
}
}
}

View File

@ -1,46 +1,53 @@
package awais.instagrabber.utils;
package awais.instagrabber.utils
import android.content.Context;
import android.content.pm.PackageManager;
import android.Manifest.permission
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;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.RECORD_AUDIO;
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;
object PermissionUtils {
val AUDIO_RECORD_PERMS = arrayOf(permission.RECORD_AUDIO)
val ATTACH_MEDIA_PERMS = arrayOf(permission.READ_EXTERNAL_STORAGE)
val CAMERA_PERMS = arrayOf(permission.CAMERA)
@JvmStatic
fun hasAudioRecordPerms(context: Context): Boolean {
return PermissionChecker.checkSelfPermission(
context,
permission.RECORD_AUDIO
) == PermissionChecker.PERMISSION_GRANTED
}
public static void requestAudioRecordPerms(final Fragment fragment, final int requestCode) {
fragment.requestPermissions(AUDIO_RECORD_PERMS, requestCode);
@JvmStatic
fun requestAudioRecordPerms(fragment: Fragment, requestCode: Int) {
fragment.requestPermissions(AUDIO_RECORD_PERMS, requestCode)
}
public static boolean hasAttachMediaPerms(@NonNull final Context context) {
return checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
@JvmStatic
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) {
fragment.requestPermissions(ATTACH_MEDIA_PERMS, requestCode);
@JvmStatic
fun requestAttachMediaPerms(fragment: Fragment, requestCode: Int) {
fragment.requestPermissions(ATTACH_MEDIA_PERMS, requestCode)
}
public static boolean hasCameraPerms(final Context context) {
return ContextCompat.checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
fun hasCameraPerms(context: Context?): Boolean {
return ContextCompat.checkSelfPermission(
context!!,
permission.CAMERA
) == PackageManager.PERMISSION_GRANTED
}
public static void requestCameraPerms(final AppCompatActivity activity, final int requestCode) {
ActivityCompat.requestPermissions(activity, CAMERA_PERMS, requestCode);
fun requestCameraPerms(activity: AppCompatActivity?, requestCode: Int) {
ActivityCompat.requestPermissions(activity!!, CAMERA_PERMS, requestCode)
}
}
}

View File

@ -132,7 +132,7 @@ class MediaRepository(private val service: MediaService) {
videoOptions.clips = listOf(Clip(videoOptions.length, options.sourceType))
}
}
val timezoneOffset = DateUtils.getTimezoneOffset().toString()
val timezoneOffset = DateUtils.timezoneOffset.toString()
val form = mutableMapOf<String, Any>(
"timezone_offset" to timezoneOffset,
"_csrftoken" to csrfToken,