mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-22 21:16:57 +00:00
Delete prev stackstrace files on version update
This commit is contained in:
parent
05fd58405c
commit
dc6f60e70d
@ -14,6 +14,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import awais.instagrabber.BuildConfig;
|
||||
import awais.instagrabber.R;
|
||||
import awaisomereport.CrashReporterHelper;
|
||||
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
|
||||
@ -70,23 +71,23 @@ public final class FlavorTown {
|
||||
}
|
||||
|
||||
public static void changelogCheck(@NonNull final Context context) {
|
||||
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < BuildConfig.VERSION_CODE) {
|
||||
int appUaCode = settingsHelper.getInteger(Constants.APP_UA_CODE);
|
||||
int browserUaCode = settingsHelper.getInteger(Constants.BROWSER_UA_CODE);
|
||||
if (browserUaCode == -1 || browserUaCode >= UserAgentUtils.browsers.length) {
|
||||
browserUaCode = ThreadLocalRandom.current().nextInt(0, UserAgentUtils.browsers.length);
|
||||
settingsHelper.putInteger(Constants.BROWSER_UA_CODE, browserUaCode);
|
||||
}
|
||||
if (appUaCode == -1 || appUaCode >= UserAgentUtils.devices.length) {
|
||||
appUaCode = ThreadLocalRandom.current().nextInt(0, UserAgentUtils.devices.length);
|
||||
settingsHelper.putInteger(Constants.APP_UA_CODE, appUaCode);
|
||||
}
|
||||
final String appUa = UserAgentUtils.generateAppUA(appUaCode, LocaleUtils.getCurrentLocale().getLanguage());
|
||||
settingsHelper.putString(Constants.APP_UA, appUa);
|
||||
final String browserUa = UserAgentUtils.generateBrowserUA(browserUaCode);
|
||||
settingsHelper.putString(Constants.BROWSER_UA, browserUa);
|
||||
Toast.makeText(context, R.string.updated, Toast.LENGTH_SHORT).show();
|
||||
settingsHelper.putInteger(Constants.PREV_INSTALL_VERSION, BuildConfig.VERSION_CODE);
|
||||
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) >= BuildConfig.VERSION_CODE) return;
|
||||
int appUaCode = settingsHelper.getInteger(Constants.APP_UA_CODE);
|
||||
int browserUaCode = settingsHelper.getInteger(Constants.BROWSER_UA_CODE);
|
||||
if (browserUaCode == -1 || browserUaCode >= UserAgentUtils.browsers.length) {
|
||||
browserUaCode = ThreadLocalRandom.current().nextInt(0, UserAgentUtils.browsers.length);
|
||||
settingsHelper.putInteger(Constants.BROWSER_UA_CODE, browserUaCode);
|
||||
}
|
||||
if (appUaCode == -1 || appUaCode >= UserAgentUtils.devices.length) {
|
||||
appUaCode = ThreadLocalRandom.current().nextInt(0, UserAgentUtils.devices.length);
|
||||
settingsHelper.putInteger(Constants.APP_UA_CODE, appUaCode);
|
||||
}
|
||||
final String appUa = UserAgentUtils.generateAppUA(appUaCode, LocaleUtils.getCurrentLocale().getLanguage());
|
||||
settingsHelper.putString(Constants.APP_UA, appUa);
|
||||
final String browserUa = UserAgentUtils.generateBrowserUA(browserUaCode);
|
||||
settingsHelper.putString(Constants.BROWSER_UA, browserUa);
|
||||
CrashReporterHelper.deleteAllStacktraceFiles(context);
|
||||
Toast.makeText(context, R.string.updated, Toast.LENGTH_SHORT).show();
|
||||
settingsHelper.putInteger(Constants.PREV_INSTALL_VERSION, BuildConfig.VERSION_CODE);
|
||||
}
|
||||
}
|
@ -8,16 +8,16 @@ import java.util.*
|
||||
|
||||
// taken from my app TESV Console Codes
|
||||
object LocaleUtils {
|
||||
private var defaultLocale: Locale? = null
|
||||
private lateinit var defaultLocale: Locale
|
||||
|
||||
@JvmStatic
|
||||
var currentLocale: Locale? = null
|
||||
lateinit var currentLocale: Locale
|
||||
private set
|
||||
|
||||
@JvmStatic
|
||||
fun setLocale(baseContext: Context) {
|
||||
var baseContext1 = baseContext
|
||||
if (defaultLocale == null) defaultLocale = Locale.getDefault()
|
||||
defaultLocale = Locale.getDefault()
|
||||
if (baseContext1 is ContextThemeWrapper) baseContext1 = baseContext1.baseContext
|
||||
if (Utils.settingsHelper == null) Utils.settingsHelper = SettingsHelper(baseContext1)
|
||||
val appLanguageSettings = Utils.settingsHelper.getString(PreferenceKeys.APP_LANGUAGE)
|
||||
@ -30,7 +30,7 @@ object LocaleUtils {
|
||||
}
|
||||
else -> Locale(lang)
|
||||
}
|
||||
currentLocale?.let {
|
||||
currentLocale.let {
|
||||
Locale.setDefault(it)
|
||||
val res = baseContext1.resources
|
||||
val config = res.configuration
|
||||
@ -43,7 +43,7 @@ object LocaleUtils {
|
||||
|
||||
@JvmStatic
|
||||
fun updateConfig(wrapper: ContextThemeWrapper) {
|
||||
if (currentLocale == null) return
|
||||
if (!this::currentLocale.isInitialized) return
|
||||
val configuration = Configuration()
|
||||
// configuration.locale = currentLocale
|
||||
configuration.setLocale(currentLocale)
|
||||
|
@ -126,4 +126,20 @@ object CrashReporterHelper {
|
||||
Log.e(TAG, "", e)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deleteAllStacktraceFiles(context: Context) {
|
||||
val filePath = context.filesDir.absolutePath
|
||||
val errorFileList: Array<File>? = try {
|
||||
val dir = File(filePath)
|
||||
if (dir.exists() && !dir.isDirectory) {
|
||||
dir.delete()
|
||||
}
|
||||
dir.mkdirs()
|
||||
dir.listFiles { _: File?, name: String -> name.endsWith(".stacktrace") }
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
errorFileList?.forEach { it.delete() }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user