How to add Date property to not be timestamp - android

So,
i'm using greendDao library and i want to store in SQL a date, but always is a timestamp date.
I do not want that!
Is possible to change that configuration?

Looking at the greedDao source i found that the date property is set by Integer type.
As a need a fast solution, i'll not add Date property, but string property and save the Date formated.
Maybe later i can fork greenDao and do the changes.

I did some adjustments to greendao. These include a method setDateFormat(String format). This method actually only applies for export to csv which is also among the adjustments I made. I will also include some lines to automatically truncate the date according to the format given.
I plan to make my changes available as plugins or extensions to greendao via contribution. Unfortunately I don't have time right now and so this project will have to wait.
Until then I suggest using date-properties and writing additional getters and setters in the KEEP-SECTION. This way you won't lose the possibility to sort this columns and you will probably be able to use the database in future (when there are possibilities to limit the value to date or time), since you don't have to change the column-type.
Using Strings is of course also a valid approach.

Related

Set localized defaults for remote config

I am implementing Remote Config in my app. The idea is to be able to A/B test some of the messages shown to the user.
I might want to run some of the experiments with the English messages only and I am trying to figure out what is the best (or most practical) way to do this.
One way would be having an xml file with default values for each language in the res/xml- directory. The main drawback I see is that this will be hard to maintain as every single value needs to be copied to all the xml files (some experiments might be language independent such as a layout color).
A second way would be setting language dependent values to an empty string and then implement some logic to look for the right string in R.strings if the value provided by remote config is empty. This seems like too much overhead for what I want to accomplish.
What is the recommended way to run experiments only for a certain language with A/B testing and Remote Config?
It is a default way in android to provide a localized string resources. Is hard to maintain but there are a service which can help you https://phraseapp.com/ . They have a lot of nice features, like manual translation, cross platform app and ide plugins which can replace/add/append/remove new strings to your xml localized files, also it works for ios.
You can keep string resources name in remote config and load it by some kid of reflection. Here is an nice answer How to get a resource id with a known resource name? . Here is an example for your case:
int resourceId = context.getResources().getIdentifier(nameFromRemoteConfig, "string", context.getPackageName())
Localization a very static logic, boring and expensive process in terms of time and maintaining. From my point of view better solution is to develop your own maximum abstract mechanism for localization and reuse it in all your projects. For example a backend service or library which will provide localized data by your own format, and a library for clients which will deserialize that data. As a result you will obtain production ready api for future projects.

Conditions in Firebase Remote Config Defaults

I'm trying to set up Firebase Remote Config. One of important parts in my project is correct localization. So I have conditions for different languages set up in console. But now I'd like to make defaults xml. Example on github is to simple. There are only few values without any conditions. Documentation does not describe this format at all. So I'm wondering if it is possible to specify all my localizations in defaults.xml and how do I do this.
The defaults file can't be used to specify conditions. It is just key/value pairs as shown. These values will be used before anything is actually fetched and cached from Firebase, for example, the first time your app is launched.
Just put localized xml with defaults in folder xml-fr for French or xml-ru for Russian (just xml for other localizations).

How should I store API URLs in Android, if they are dependent on locale?

Right now they are just stored on a class called Globals as static fields.
I'm not the one who made the app, but I am considering putting them in localized strings.xml files, such as <string name="API_URL">http://someurl</string>. Is this good or bad practice?
UPDATE:
I chose the answer that I feel answers the question most comprehensibly.
But after some re-thinking, I have chosen a different solution alltogether.
Given that URLs are actually based on the country which the app should be distributed for, it doesn't make sense to switch them based on locale, as the URLs should stay the same regardless of the language on the phone.
Instead, I have implemented Gradle Flavors, which create different APKs based on different settings and such. It allows you to create variations of the same app with the small changes that you need. :) So now I have the URLs in a flavor-specific file.
Thank you to everyone who took their time to comment and help me.
I agree with puneet, it's neither good nor bad. It depends on what you are doing with the API Urls.
Are you going to append them later with user input? If so I would suggest you keep them as global variables that way you can modify the API URL programatically as needed.
If the API Url are complete and will not need to be appended then putting them in the strings.xml would be fine. Just remember that you would still have to create a local String variable in the java to hold the text from the API_URL in the string.xml, which seems inefficient if what you're aiming for is to write less code.
Neither good nor bad.If your concern is the security then none of them provide the security as decompilation is possible.

Android Time Zone Issue

I am using TimeZone class to get the time zone in SHORT format like "PST", "EST" etc. using TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT, Locale.getDefault())
For some devices this piece of code is returning "PST" etc but some of the devices its returning "GMT+007" value. Anybody has an idea what can be the change I make to make it consistent to "PST" format.
The short name is a part of the time zone database. It seems that some devices are shipping time zone databases that doesn't include this information, or whose libraries ignore it.
To make this consistent I would include a mapping that maps from the long names to the short names. But then you would have to maintain that yourself, and you also need to get the long name (like "US/Hawaii") for each timezone, I don't know if that is possible for you, it depends on the use case.
Please also be aware that the short time zone names are ambiguous, there are many time zones called EST for example.

Is it possible to reset the last modified date of an Android file?

I'm writing a purge function for our software that removes all image files that haven't been used in over a month. To do this, I am checking two things:
the last-modified date of the file
a query on a database that shows recently viewed files.
The query is much slower than the file check. So I would ideally like to be able to reset the last modified date on any files that fail the first check, but pass the second, so that (for example) a list of venerable but often-used files aren't gradually increasing the processing load of the management system.
Is there a way to do this without recourse to something crude (and possibly even slower), like renaming each file to a temporary label, then itself?
As Nik said the setLastModified() method on the File class may not always work depending where you are in the Android file system. If on the SD Card then some devices will return false from that call and thus not change the date.
There are more details about it here:
http://code.google.com/p/android/issues/detail?id=1992
http://code.google.com/p/android/issues/detail?id=1699
Plus some other stackoverflow thread here:
file.lastModified() is never what was set with file.setLastModified()
setLastModified() is a standard method on any Java File object that you can use to update this value.
SDK Documentation.

Categories

Resources