mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Convert InstaGrabberApplication to kotlin
This commit is contained in:
parent
e0a13f7fb7
commit
631d55af85
@ -1,89 +1,72 @@
|
||||
package awais.instagrabber;
|
||||
package awais.instagrabber
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.app.Application
|
||||
import android.content.ClipboardManager
|
||||
import android.util.Log
|
||||
import awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT
|
||||
import awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED
|
||||
import awais.instagrabber.fragments.settings.PreferenceKeys.DATE_TIME_FORMAT
|
||||
import awais.instagrabber.utils.*
|
||||
import awais.instagrabber.utils.LocaleUtils.currentLocale
|
||||
import awais.instagrabber.utils.Utils.settingsHelper
|
||||
import awais.instagrabber.utils.extensions.TAG
|
||||
import awaisomereport.CrashReporter
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.imagepipeline.core.ImagePipelineConfig
|
||||
import java.net.CookieHandler
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.imagepipeline.core.ImagePipelineConfig;
|
||||
|
||||
import java.net.CookieHandler;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
import awais.instagrabber.fragments.settings.PreferenceKeys;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.LocaleUtils;
|
||||
import awais.instagrabber.utils.SettingsHelper;
|
||||
import awais.instagrabber.utils.TextUtils;
|
||||
import awaisomereport.CrashReporter;
|
||||
|
||||
import static awais.instagrabber.utils.CookieUtils.NET_COOKIE_MANAGER;
|
||||
import static awais.instagrabber.utils.Utils.applicationHandler;
|
||||
import static awais.instagrabber.utils.Utils.cacheDir;
|
||||
import static awais.instagrabber.utils.Utils.clipboardManager;
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
|
||||
public final class InstaGrabberApplication extends Application {
|
||||
private static final String TAG = "InstaGrabberApplication";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
CookieHandler.setDefault(NET_COOKIE_MANAGER);
|
||||
|
||||
if (settingsHelper == null) {
|
||||
settingsHelper = new SettingsHelper(this);
|
||||
@Suppress("unused")
|
||||
class InstaGrabberApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
CookieHandler.setDefault(NET_COOKIE_MANAGER)
|
||||
setupCrashReporter()
|
||||
setupCloseGuard()
|
||||
setupFresco()
|
||||
Utils.cacheDir = cacheDir.absolutePath
|
||||
settingsHelper = SettingsHelper(this)
|
||||
Utils.clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||
LocaleUtils.setLocale(baseContext)
|
||||
val pattern = if (settingsHelper.getBoolean(CUSTOM_DATE_TIME_FORMAT_ENABLED)) {
|
||||
settingsHelper.getString(CUSTOM_DATE_TIME_FORMAT)
|
||||
} else {
|
||||
settingsHelper.getString(DATE_TIME_FORMAT)
|
||||
}
|
||||
TextUtils.setFormatter(DateTimeFormatter.ofPattern(pattern, currentLocale))
|
||||
if (TextUtils.isEmpty(settingsHelper.getString(Constants.DEVICE_UUID))) {
|
||||
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString())
|
||||
}
|
||||
}
|
||||
|
||||
if (!BuildConfig.DEBUG) {
|
||||
CrashReporter.get(this).start();
|
||||
}
|
||||
private fun setupCrashReporter() {
|
||||
if (BuildConfig.DEBUG) return
|
||||
CrashReporter.get(this).start()
|
||||
// logCollector = new LogCollector(this);
|
||||
}
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
private fun setupCloseGuard() {
|
||||
if (!BuildConfig.DEBUG) return
|
||||
try {
|
||||
Class.forName("dalvik.system.CloseGuard")
|
||||
.getMethod("setEnabled", boolean.class)
|
||||
.invoke(null, true);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error", e);
|
||||
.getMethod("setEnabled", Boolean::class.javaPrimitiveType)
|
||||
.invoke(null, true)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupFresco() {
|
||||
// final Set<RequestListener> requestListeners = new HashSet<>();
|
||||
// requestListeners.add(new RequestLoggingListener());
|
||||
final ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig
|
||||
.newBuilder(this)
|
||||
// .setMainDiskCacheConfig(diskCacheConfig)
|
||||
val imagePipelineConfig = ImagePipelineConfig
|
||||
.newBuilder(this) // .setMainDiskCacheConfig(diskCacheConfig)
|
||||
// .setRequestListeners(requestListeners)
|
||||
.setDownsampleEnabled(true)
|
||||
.build();
|
||||
Fresco.initialize(this, imagePipelineConfig);
|
||||
.build()
|
||||
Fresco.initialize(this, imagePipelineConfig)
|
||||
// FLog.setMinimumLoggingLevel(FLog.VERBOSE);
|
||||
|
||||
if (applicationHandler == null) {
|
||||
applicationHandler = new Handler(getApplicationContext().getMainLooper());
|
||||
}
|
||||
|
||||
if (cacheDir == null) {
|
||||
cacheDir = getCacheDir().getAbsolutePath();
|
||||
}
|
||||
|
||||
LocaleUtils.setLocale(getBaseContext());
|
||||
|
||||
if (clipboardManager == null)
|
||||
clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
TextUtils.setFormatter(DateTimeFormatter.ofPattern(
|
||||
settingsHelper.getBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED) ?
|
||||
settingsHelper.getString(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT) :
|
||||
settingsHelper.getString(PreferenceKeys.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()));
|
||||
|
||||
if (TextUtils.isEmpty(settingsHelper.getString(Constants.DEVICE_UUID))) {
|
||||
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString());
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import java.util.*
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
object TextUtils {
|
||||
var datetimeParser: DateTimeFormatter = DateTimeFormatter.ofPattern("")
|
||||
lateinit var datetimeParser: DateTimeFormatter
|
||||
|
||||
@JvmStatic
|
||||
fun isEmpty(charSequence: CharSequence?): Boolean {
|
||||
|
@ -17,7 +17,6 @@ import android.media.MediaScannerConnection;
|
||||
import android.media.MediaScannerConnection.OnScanCompletedListener;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.provider.Browser;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
@ -80,7 +79,6 @@ public final class Utils {
|
||||
public static SimpleCache simpleCache;
|
||||
private static int statusBarHeight;
|
||||
private static int actionBarHeight;
|
||||
public static Handler applicationHandler;
|
||||
public static String cacheDir;
|
||||
public static String tabOrderString;
|
||||
private static int defaultStatusBarColor;
|
||||
|
Loading…
Reference in New Issue
Block a user