This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| krefson["someKey"] = someData //put | |
| val data = krefson["someKey", defalutValue] //get with default value | |
| val anotherData: SomeData? = krefson["someOtherKey"] //get nullable | |
| if ("someKey" in krefson) //check if "someKey" is exist | |
| krefson.remove("someKey") //simply remove a key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline fun <reified T> Gson.fromJson(string: String?): T? { | |
| return fromJson(string, object : TypeToken<T>() {}.type) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open class Krefson(context: Context, val name: String, val gson: Gson = Gson()) { | |
| val sharedPreference: SharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE) | |
| inline operator fun <reified T> get(key: String): T? { | |
| return gson.fromJson(sharedPreference.getString(key, null)) | |
| } | |
| inline operator fun <reified T> get(key: String, defaultValue: T): T { | |
| return gson.fromJson(sharedPreference.getString(key, null)) ?: defaultValue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PersonAdapter extends RecyclerView.Adapter<PersonAdapter.PersonHolder> { | |
| private List<Person> list; | |
| public PersonAdapter(@NonNull List<Person> list) { | |
| this.list = list; | |
| } | |
| @Override | |
| public PersonHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Person { | |
| public String name; | |
| public int age; | |
| public Person(String name, int age) { | |
| this.name = name; | |
| this.age = age; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| RecyclerView recyclerView; | |
| List<Person> people; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| recyclerView = (RecyclerView) findViewById(R.id.recyclerView); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Person { | |
| public String name; | |
| public int age; | |
| public boolean isChecked; | |
| public Person(String name, int age) { | |
| this.name = name; | |
| this.age = age; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PersonAdapter extends RecyclerView.Adapter<PersonAdapter.PersonHolder> { | |
| private List<Person> list; | |
| public PersonAdapter(@NonNull List<Person> list) { | |
| this.list = list; | |
| } | |
| @Override | |
| public PersonHolder onCreateViewHolder(ViewGroup parent, int viewType) { |