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.app.Application
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager
|
||||||
import android.content.Context;
|
import android.util.Log
|
||||||
import android.os.Handler;
|
import awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT
|
||||||
import android.util.Log;
|
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;
|
@Suppress("unused")
|
||||||
import java.time.format.DateTimeFormatter;
|
class InstaGrabberApplication : Application() {
|
||||||
import java.util.UUID;
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
import awais.instagrabber.fragments.settings.PreferenceKeys;
|
CookieHandler.setDefault(NET_COOKIE_MANAGER)
|
||||||
import awais.instagrabber.utils.Constants;
|
setupCrashReporter()
|
||||||
import awais.instagrabber.utils.LocaleUtils;
|
setupCloseGuard()
|
||||||
import awais.instagrabber.utils.SettingsHelper;
|
setupFresco()
|
||||||
import awais.instagrabber.utils.TextUtils;
|
Utils.cacheDir = cacheDir.absolutePath
|
||||||
import awaisomereport.CrashReporter;
|
settingsHelper = SettingsHelper(this)
|
||||||
|
Utils.clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
import static awais.instagrabber.utils.CookieUtils.NET_COOKIE_MANAGER;
|
LocaleUtils.setLocale(baseContext)
|
||||||
import static awais.instagrabber.utils.Utils.applicationHandler;
|
val pattern = if (settingsHelper.getBoolean(CUSTOM_DATE_TIME_FORMAT_ENABLED)) {
|
||||||
import static awais.instagrabber.utils.Utils.cacheDir;
|
settingsHelper.getString(CUSTOM_DATE_TIME_FORMAT)
|
||||||
import static awais.instagrabber.utils.Utils.clipboardManager;
|
} else {
|
||||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
settingsHelper.getString(DATE_TIME_FORMAT)
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
TextUtils.setFormatter(DateTimeFormatter.ofPattern(pattern, currentLocale))
|
||||||
if (!BuildConfig.DEBUG) {
|
|
||||||
CrashReporter.get(this).start();
|
|
||||||
}
|
|
||||||
// logCollector = new LogCollector(this);
|
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
try {
|
|
||||||
Class.forName("dalvik.system.CloseGuard")
|
|
||||||
.getMethod("setEnabled", boolean.class)
|
|
||||||
.invoke(null, true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "Error", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// final Set<RequestListener> requestListeners = new HashSet<>();
|
|
||||||
// requestListeners.add(new RequestLoggingListener());
|
|
||||||
final ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig
|
|
||||||
.newBuilder(this)
|
|
||||||
// .setMainDiskCacheConfig(diskCacheConfig)
|
|
||||||
// .setRequestListeners(requestListeners)
|
|
||||||
.setDownsampleEnabled(true)
|
|
||||||
.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))) {
|
if (TextUtils.isEmpty(settingsHelper.getString(Constants.DEVICE_UUID))) {
|
||||||
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString());
|
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupCrashReporter() {
|
||||||
|
if (BuildConfig.DEBUG) return
|
||||||
|
CrashReporter.get(this).start()
|
||||||
|
// logCollector = new LogCollector(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupCloseGuard() {
|
||||||
|
if (!BuildConfig.DEBUG) return
|
||||||
|
try {
|
||||||
|
Class.forName("dalvik.system.CloseGuard")
|
||||||
|
.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());
|
||||||
|
val imagePipelineConfig = ImagePipelineConfig
|
||||||
|
.newBuilder(this) // .setMainDiskCacheConfig(diskCacheConfig)
|
||||||
|
// .setRequestListeners(requestListeners)
|
||||||
|
.setDownsampleEnabled(true)
|
||||||
|
.build()
|
||||||
|
Fresco.initialize(this, imagePipelineConfig)
|
||||||
|
// FLog.setMinimumLoggingLevel(FLog.VERBOSE);
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ import java.util.*
|
|||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
object TextUtils {
|
object TextUtils {
|
||||||
var datetimeParser: DateTimeFormatter = DateTimeFormatter.ofPattern("")
|
lateinit var datetimeParser: DateTimeFormatter
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun isEmpty(charSequence: CharSequence?): Boolean {
|
fun isEmpty(charSequence: CharSequence?): Boolean {
|
||||||
|
@ -17,7 +17,6 @@ import android.media.MediaScannerConnection;
|
|||||||
import android.media.MediaScannerConnection.OnScanCompletedListener;
|
import android.media.MediaScannerConnection.OnScanCompletedListener;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
|
||||||
import android.provider.Browser;
|
import android.provider.Browser;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -80,7 +79,6 @@ public final class Utils {
|
|||||||
public static SimpleCache simpleCache;
|
public static SimpleCache simpleCache;
|
||||||
private static int statusBarHeight;
|
private static int statusBarHeight;
|
||||||
private static int actionBarHeight;
|
private static int actionBarHeight;
|
||||||
public static Handler applicationHandler;
|
|
||||||
public static String cacheDir;
|
public static String cacheDir;
|
||||||
public static String tabOrderString;
|
public static String tabOrderString;
|
||||||
private static int defaultStatusBarColor;
|
private static int defaultStatusBarColor;
|
||||||
|
Loading…
Reference in New Issue
Block a user