Skip to content

Instantly share code, notes, and snippets.

View yashprakash13's full-sized avatar
📱
/* ... and everything in between ... */ :)

Yash Prakash yashprakash13

📱
/* ... and everything in between ... */ :)
View GitHub Profile
@yashprakash13
yashprakash13 / MainActivity.java
Last active February 5, 2019 13:49
SampleOperationsOnEasyRoom
MyRepository mRepository = new MyRepository(getApplicationContext);
String title = "First note title";
String desc = "First note desc";
mRepository.insert(title, desc);
String newTitle = "New Title";
Stirng descNew = "New Description";
Entity entity = new Entity();
entity.setTitle(newTitle);
entity.setContent(newTitle);
entity.setWroteAt(AppTools.getCurrentDateTime());
//Updating a row
mRepository.update(entity);
<item android:id="@+id/searchItems"
android:title="@string/search"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_baseline_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
@yashprakash13
yashprakash13 / Repository.kt
Last active August 15, 2019 09:11
ViewModel.kt
@WorkerThread
fun search(desc : String) : LiveData<List<DataClass>>{
return myDao.getSearchResults(desc)
}
@yashprakash13
yashprakash13 / MainActivity.kt
Last active August 15, 2019 09:42
onCreateMenu For Search
val search = menu.findItem(R.id.searchItems)
searchView = search.actionView as androidx.appcompat.widget.SearchView
searchView.isSubmitButtonEnabled = true
searchView.setOnQueryTextListener(object: androidx.appcompat.widget.
SearchView.OnQueryTextListener{
override fun onQueryTextSubmit(query: String?): Boolean {
if (query != null) {
getItemsFromDb(query)
}
return true
@yashprakash13
yashprakash13 / MainActivity.kt
Last active August 15, 2019 09:27
getItemsFromDb
private fun getItemsFromDb(searchText: String) {
var searchText = searchText
searchText = "%$searchText%"
myViewModel.searchForItems(desc = searchText).observe(this@MainActivity, Observer { list ->
list?.let {
Log.e("List = ", list.toString())
}
})
# Install R + RStudio on Ubuntu 16.04
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys E084DAB9
# Ubuntu 12.04: precise
# Ubuntu 14.04: trusty
# Ubuntu 16.04: xenial
# Basic format of next line deb https://<my.favorite.cran.mirror>/bin/linux/ubuntu <enter your ubuntu version>/
sudo add-apt-repository 'deb https://ftp.ussg.iu.edu/CRAN/bin/linux/ubuntu xenial/'
sudo apt-get update
@Entity(tableName = "word_table")
data class Word (
@PrimaryKey
@NonNull
var name: String,
var meaning: String? = null,
var audioPath: String? = null
)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertWord(word: Word)
@Query ("Select * from word_table")
fun getAllWordsPaged() : DataSource.Factory<Int, Word>
@Query("Delete from word_table where name like :name")
fun deleteWord(name: String)
@Query("Update word_table set name = :name, meaning = :meaning, audioPath = :audiopath where name like :originalName")