Skip to content

Instantly share code, notes, and snippets.

View manijshrestha's full-sized avatar

Manij Shrestha manijshrestha

View GitHub Profile
@Override
public void onBackPressed() {
stopLockTask();
}
package com.manijshrestha.todolist.ui
import com.manijshrestha.todolist.data.Task
import com.manijshrestha.todolist.data.TaskDao
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class ToDoPresenter @Inject constructor(val taskDao: TaskDao) {
var tasks = ArrayList<Task>()
var presentation: ToDoPresentation? = null
fun onCreate(toDoPresentation: ToDoPresentation) {
presentation = toDoPresentation
loadTasks()
}
@Module class AppModule(private val context: Context) {
@Provides fun providesAppContext() = context
@Provides fun providesAppDatabase(context: Context): AppDatabase =
Room.databaseBuilder(context, AppDatabase::class.java, "my-todo-db").allowMainThreadQueries().build()
@Provides fun providesToDoDao(database: AppDatabase) = database.taskDao()
}
@Database(entities = arrayOf(Task::class), version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
abstract fun taskDao(): TaskDao
}
@Dao interface TaskDao {
@Query("select * from task")
fun getAllTasks(): List<Task>
@Query("select * from task where id = :p0")
fun findTaskById(id: Long): Task
@Insert(onConflict = REPLACE)
fun insertTask(task: Task)
import android.arch.persistence.room.ColumnInfo
import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey
@Entity(tableName = "task")
data class Task(@ColumnInfo(name = "completed_flag") var completed: Boolean = false,
@ColumnInfo(name = "task_desciption") var description: String) {
@ColumnInfo(name = "id")
@PrimaryKey(autoGenerate = true) var id: Long = 0
}
@manijshrestha
manijshrestha / build.gradle
Last active June 3, 2017 04:16
Include Room
dependencies {
....
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha1"
...
}
@manijshrestha
manijshrestha / gist:6565314
Created September 14, 2013 20:20
Chromecast Sender
<html data-cast-api-enabled="true">
<head>
<title>Chromecast Sender</title>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
//Jquery Init
$(function(){
$("#receivers").html('Initializing...');
$("#playBtn").bind("click", doPlay);
@manijshrestha
manijshrestha / index.htlm
Created October 19, 2012 20:15
Building app with responsive design using jQuery mobile and CSS3 (Media Query)
<!DOCTYPE html>
<html>
<head>
<title>Cool App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>