Skip to content
Proyek

kcochibili/TinyDB--Android-Shared-Preferences-Turbo

Lihat di GitHub

Tentang

Kelas ini menyederhanakan pemanggilan SharedPreferences menjadi satu baris kode. Kelas ini juga dapat melakukan lebih banyak hal, seperti menyimpan daftar String, bilangan bulat, dan gambar. Semuanya dalam satu baris kode!

Desain dan media

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
-1
dalam 15 hari
-2
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

TinyDB -- Android-Shared-Preferences-Turbo

This class simplifies calls to SharedPreferences in a line of code. It can also do more like: saving a list of strings, integers and saving images. All in 1 line of code!

Example usage:

TinyDB tinydb = new TinyDB(context);

//Put data in database
tinydb.putInt("clickCount", 2);
tinydb.putFloat("xPoint", 3.6f);
tinydb.putLong("userCount", 39832L);

tinydb.putString("userName", "john");
tinydb.putBoolean("isUserMale", true); 

tinydb.putList("MyUsers", mUsersArray);
tinydb.putImagePNG("DropBox/WorkImages", "MeAtlunch.png", lunchBitmap);

//Get data from database
int dataint = tinyDB.getInt("clickCount");
String datastring = tinyDB.getString("userName");
//These plus the corresponding get methods are all included

This is just an example of how easy it is to use. There are many more useful methods included in the class. Enjoy :)

If you'd like to also save Objects, use the methods:

tinydb.putObject(key, object);
tinydb.putListObject(key, objectsArray);

Example of saving Objects:

Person person = new Person("john", 24);
tinydb.putObject("user1", person); //saves the object
tinydb.getObject("user1", Person.class); // retrieves the object from storage

ArrayList<Person> usersWhoWon = new ArrayList<Person>();
ArrayList<Object> winnersObjects = new ArrayList<Object>();

for(Person p : usersWhoWon){
    winnersObjects.add((Object)p); // casting to raw objects
}

tinydb.putListObject("allWinners", winnersObjects);

Kotlin usage sample:

// instantiate
var tinyDB : TinyDB = TinyDB(applicationContext)


// put / save
tinyDB.putString("nameKey", "John")

var winnerPerson : Person = Person()
tinyDB.putObject("winnerKey", winnerPerson);

// get
var personName : String  = tinyDB.getString("nameKey")
var winnerPerson : Person = tinyDB.getObject("winnerKey", Person::class.java)

Before you can use the save objects methods, you must first:

  1. Import Gson into your project Gradle:
dependencies {
  implementation 'com.google.code.gson:gson:2.8.8'
}
  1. Uncomment the save objects methods in your copy of TinyDB.java, starting at: Line31, Line330, Line345, Line486

Installation

Just add the TinyDB.java file as a Java Class into your project.

Learning app developement?

Check out my very easy videos on youtube

Lastly, there is TinyDB for IOS too 😊

Jelajahi proyek terkait

Memuat…