Ammar Githam
4 years ago
3 changed files with 62 additions and 81 deletions
-
129app/src/main/java/awais/instagrabber/InstaGrabberApplication.kt
-
2app/src/main/java/awais/instagrabber/utils/TextUtils.kt
-
2app/src/main/java/awais/instagrabber/utils/Utils.java
@ -1,89 +1,72 @@ |
|||
package awais.instagrabber; |
|||
|
|||
import android.app.Application; |
|||
import android.content.ClipboardManager; |
|||
import android.content.Context; |
|||
import android.os.Handler; |
|||
import android.util.Log; |
|||
|
|||
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); |
|||
package awais.instagrabber |
|||
|
|||
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.* |
|||
|
|||
|
|||
@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()); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue