Code Monkey home page Code Monkey logo

tinydb--android-shared-preferences-turbo's People

Contributors

adrianchifor avatar chanonly123 avatar kcochibili avatar lmagoncalo avatar prayashm avatar valentinbreiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinydb--android-shared-preferences-turbo's Issues

putImage and getImage don't seem to work

i used the putImage to save and image into TinyDB with the parameters but getting the image does not seem to work or am i doing something wrong
saving the image
private void saveImage() { tinyDB.putImage("Splanner/profile","profilepic.png", photo); }
getting the image
Bitmap getImage = tinyDB.getImage("Splanner/profile"); userDp.setImageBitmap(getImage);

Dependecies

Hello, what do I add to dependencies to use this library?

Adding getObject that retrives data using Gson's TypeToken

Hello,

I really loved your library, it helped me testing some features in my prototype.

But, using maps in Kotlin, I had some difficulties trying to get the map automatically filled. After some time trying to make things work, I remembered that Gson has a TypeToken interface that solved cases like that.

Originally I did this as an issue on mukeshsolanki/easypreferences#4, but I thought it would be correct to share this change with your project too as it served as a basis for him, so I will make a PR for it.

How to search for a specific string?

I store the following object in TinyDB:

import java.io.Serializable;


public class Image implements Serializable{
    private String name;
    private String small, medium, large;
    private String timestamp;

    public Image() {
    }

    public Image(String name, String small, String medium, String large, String timestamp) {
        this.name = name;
        this.small = small;
        this.medium = medium;
        this.large = large;
        this.timestamp = timestamp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSmall() {
        return small;
    }

    public void setSmall(String small) {
        this.small = small;
    }

    public String getMedium() {
        return medium;
    }

    public void setMedium(String medium) {
        this.medium = medium;
    }

    public String getLarge() {
        return large;
    }

    public void setLarge(String large) {
        this.large = large;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }
}

I can retrieve the object like this:
ArrayList<Object> img_aux = tinydb.getListObject("Favorites", Image.class);

Could I look for a SPECIFIC STRING within the Favorites key?

Delete object

How to delete the object class values.
I use this in putobject.
fun putObject(key: String, value: Any, context: Context) {
TinyDB(context).putObject(key, value)
}

but I need to delete also the object.

Wrong 2nd argument type

Hello,

i have a problem that i could not resolve.
i have my custom class "Article" and want to put an Article ArrayList.

public class Article extends Object 

This problem explains all... :x

ArrayList<Article> list = new ArrayList<Article>();
list.add(new Article(1,"ok", "ok", "ok"));
list.add(new Article(1,"ok", "ok", "ok"));
list.add(new Article(1,"ok", "ok", "ok"));
list.add(new Article(1,"ok", "ok", "ok"));
a.putObject("je", list.get(1)); // It works well
a.putListObject("tu", list); // It doesn't fuck*** work. Why ? :x

Your methods

public void putObject(String key, Object obj) // Object 
public void putListObject(String key, ArrayList<Object> objArray) // and Object... 
// Why it doesn't like Arraylist ? 

Thank you for your time.

Make lastImagePath static

I think that lastImagePath should be static.
Since it is the last, it doesn't matter which instance of the TinyDB it is.
Also, it is not really used so you can delete it...

java.lang.NullPointerException: listFood.get(0) must not be null

fun insertFood(item: FoodDomain){

    listFood = tinyDB.getListObject("CartList")
    listFood.add(item)
    tinyDB.putListObject("CartList",listFood)
    var fod : FoodDomain = listFood.get(0)
    }

The error is: when i get the list, it have size, 1 or 2 or 3 , is normal; but if i want get one object of the list, it say "must not be null"

like IS A LIST WITH SIZE BUT ALL OBJECT ARE NULL OR NOT EXIST ? please help :c i have this problem 2 months

using getObject() method

how to use ..

public Object getObject(String key, Class<?> classOfT){

    String json = getString(key);
    Object value = new Gson().fromJson(json, classOfT);
    if (value == null)
        throw new NullPointerException();
    return value;
}

this method.

Is this multi-process safe?

Older APIs was using the broken MULTI_PROCESS_MODE. Then people noticed it was unsafe.

Is this simplification reliable for multiple processes/services?

How does this compare in performance to tray and DPreference, for example?

Split Gson into plugable component

I see there is some hack to plug/unplug the Gson: Uncomment the save objects methods in your copy of TinyDB.java, starting at: Line31, Line317, Line332, Line462, Line468

I may offer a solution where you can plug-in external components in a more elegant way.

The idea is to wrap external component into interfaces and the TinyDB.class may call it's methods. On application start you can deploy the optional component if necessary.

Here is an example of how it can be done: https://github.com/Scarabei/Scarabei/blob/master/scarabei-api/src/com/jfixby/scarabei/api/desktop/DesktopSetup.java

Would you be interested?

Why not to make it as a singleton ?

Hi there!
Why note making this class as a singleton or making it an option. I use it on my production app but I have modified it to be as a Singelton, so those who use shared preferences across their app, only initialize it once (when they use the TinyDB class for the first time). I can help to contribute to making these changes if the maintainer would approve.

List all keys

I am using the phenomenal class! I can add, remove everything right!
But I need to list all the "Key" I used in tinydb.putListObject ("KEY", img);

Is it possible to do that?

getting: Forgot to register a type adapter?

Here is the error:

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: com.ilepez.weatherapp.data.model.CityArrayList. Forgot to register a type adapter? at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:76) at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:69) at com.google.gson.Gson.toJson(Gson.java:669) at com.google.gson.Gson.toJson(Gson.java:648) at com.google.gson.Gson.toJson(Gson.java:603) at com.google.gson.Gson.toJson(Gson.java:583) at com.ilepez.weatherapp.utils.TinyDB.putObject(TinyDB.java:462) at com.ilepez.weatherapp.activity.SearchActivity.onItemClick(SearchActivity.java:67) at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:928) at android.widget.AutoCompleteTextView.access$500(AutoCompleteTextView.java:93) at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1230) at android.widget.AdapterView.performItemClick(AdapterView.java:345) at android.widget.AbsListView.performItemClick(AbsListView.java:1547) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3821) at android.widget.AbsListView$3.run(AbsListView.java:5841) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 07-17 10:55:26.283 15392-15392/com.ilepez.weatherapp E/libEGL: call to OpenGL ES API with no current context (logged once per thread)

The full explanation can be found here: http://stackoverflow.com/questions/38419555/tinydb-sharedpreferences-getting-forgot-to-register-a-type-adapter

putObject method doesnt recognize Custom Object

Using this method to save an object of a class wrapping a HashMap object is resulting in a LinkTreeMap Class casting error.
Eg Class:

public class Categories {
    private String categoryName;
    private ActivityMasterModel amm;

    @SerializedName("activities")
    @Expose
    private ArrayList<ActivityMasterModel> allActivities;

    private HashMap<String, ArrayList<ActivityMasterModel>> allActivitiesByCategory;

    public ArrayList<ActivityMasterModel> getAllActivities() {
        return allActivities;
    }

    public void setAllActivities(ArrayList<ActivityMasterModel> allActivities) {
        this.allActivities = allActivities;
    }

I couldnt save allActivitiesByCategory object into shared preferences using putObject method. Hence I created the above class to be used with putObject method. However, the object allActivitiesByCategory is saved using the below modified method.

public void putHashMapObject(String key, Object obj) {
       checkForNullKey(key);
       Type type = new TypeToken<Map<String, ArrayList<ActivityMasterModel>>>() {}.getType();
       Gson gson = new Gson();
       putString(key, gson.toJson(obj, type));
   }

I was following the below link and it helped a lot.
https://stackoverflow.com/questions/32444863/google-gson-linkedtreemap-class-cast-to-myclass

However, the same solution didnt work for SparseArray instead of HashMap. I couldnt solve the issue yet. I am not a Java guy, I should say a beginner, and trying to get my head around it.

Using Joda DateTime in my custom object

Is there any way to modify the tinyDB class to be able to save a custom object with a DateTime field? I tried adding the following:
`
private class DateTimeSerializer implements JsonSerializer {
public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.toString());
}
}

private class DateTimeDeserializer implements JsonDeserializer<DateTime> {
    public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
            throws JsonParseException {
        return new DateTime(json.getAsJsonPrimitive().getAsString());
    }
}

public void retrieveGlobalDataFromStorage(Context context) {

// ...

    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(DateTime.class, new DateTimeSerializer());
    builder.registerTypeAdapter(DateTime.class, new DateTimeDeserializer());

    final Gson gson = builder.create();

// ...
}` but I am still getting a fatal exception
Caused by: java.lang.RuntimeException: Failed to invoke public org.joda.time.Chronology() with no args
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:111)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.google.gson.Gson.fromJson(Gson.java:773)
at dtcj.badgerme.TinyDB.getListObject(TinyDB.java:358)

Thanks for any advice!
Taryn

How to use tinyDB in my apiInterface class ?

Hi , My api interface class like this

public interface ApiInterface {
    @FormUrlEncoded
    @Headers("wkey",***********TinyDB*********)
    @POST("srrvk")
    Call<JoinAllAllowedInnoResponse> GETJOINALLOWEDINNOLIST(@Field("a") Integer lastOrderId, @Field("b") Integer rowCount);

I saved a wkey parameter in tinyDB, My question is how can I use tinyDB in my apiInterface class ?

Persistence

Does this provide persistence to app closure and possible background kills? How does it perform in comparison to other storage methods? Perhaps you can say a few words in the README how to put this to use. We're looking for better and more efficient and simple methods for storing network/app information in our app, without SQLite overhead. Would this be suitable? Thanks.

context

Sorry, stupid question, fixed, please delete

Replacing the image stored

when i store an image and i want to replace it i do the same code for putting it in with the same path name so it replaces it but it gives me errors. (TinyDb.checkForNullValue). Please is there another way to do it. That is to replace the image that has been stored in that path with another image

Retrive ListObjects

I have been trying to retrieve ListObjects but all to no avail. The issue here is the mClass. How do I go about it? Thanks. Nice work anyways

If tinydb is null

hi thanks for your useful class .
how can i find out if tinydb with key a is null or not .
example : if (tinydb.getint("a") == null);

putListObject not working for custom object

I have a custom Object NotificationItem and an ArrayList of these objects. When I try to save the ArrayList using tinydb.putListObject I get this error:
Wrong 2nd argument type Found 'java.uti.ArrayList<dtcj.myapp.NotificationItem>', required 'java.util.ArrayList<java.lang.object>'
Can you please advise me how to correct this? Thanks, Taryn
Here is the relevant code
ArrayList<NotificationItem> notificationData = new ArrayList();`

NotificationItem medicineExample = new NotificationItem();

tinydb.putObject("medicineExample",medicineExample);

notificationData.add(medicineExample);

tinydb.putListObject("notificationData",notificationData);

Wrong 2nd argument type. Found: 'java.util.ArrayList<electronic.business.card.data.model.EcardSavedContactData>', required: 'java.util.ArrayList<java.lang.Object>'

For ,

ArrayList<Person> usersWhoWon = new ArrayList<Person>(); tinydb.putListObject("allWinners", usersWhoWon);

I got cannot resolve for tinydb.putListObject("allWinners", usersWhoWon); line usersWhoWon.
Error:
Wrong 2nd argument type. Found: 'java.util.ArrayList<electronic.business.card.data.model.EcardSavedContactData>', required: 'java.util.ArrayList<java.lang.Object>'

Implementing Singleton Pattern

Hi, i was thinking that why you haven't implemented singleton pattern for this utility class, so that we can load this class just one time in whole application.
is there any special reason?
(i know that built-in shared preferences object uses singleton pattern by default)

Value change listeners ?

First of all thanks for this class. But it would be great to have value change listeners. Is it discarded for the simplicity ?

Consistency

Why some function receive as parameter a default value, for example, getLong and getDouble , but other functions like getFloat and getInt does not? It wouldn't be easier if all function received a default parameter that is return in case of error?

API Compat

Issue with apply() when using GB(lvl 10), even when the doc states that this was added in API Level 9.
Used an old phone to test my app (min sdk 8) and it crashed, it was ok on phone(18) and Emulator(19).
Replacing with commit() solves the problem. Any true problem of apply() being replaced?

Need a Kotlin

Can you guys please provide this class in kotlin?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.