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
package net.ahammad.roomsample; | |
import android.arch.persistence.db.SupportSQLiteDatabase; | |
import android.arch.persistence.room.Database; | |
import android.arch.persistence.room.Room; | |
import android.arch.persistence.room.RoomDatabase; | |
import android.arch.persistence.room.migration.Migration; | |
import android.content.Context; | |
import android.support.annotation.NonNull; | |
import android.util.Log; |
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
object AppPreferences { | |
private const val NAME = "SpinKotlin" | |
private const val MODE = Context.MODE_PRIVATE | |
private lateinit var preferences: SharedPreferences | |
// list of app specific preferences | |
private val IS_FIRST_RUN_PREF = Pair("is_first_run", false) | |
fun init(context: Context) { | |
preferences = context.getSharedPreferences(NAME, MODE) | |
} |
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
class SpInKotlinApp : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
AppPreferences.init(this) | |
} | |
} |
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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
if (!AppPreferences.firstRun) { | |
AppPreferences.firstRun = true | |
Log.d("SpinKotlin", "The value of our pref is: ${AppPreferences.firstRun}") | |
} |
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
@Entity(tableName = "DAY_LOOK") | |
data class DayLookEntity( | |
@PrimaryKey(autoGenerate = true) | |
@ColumnInfo(name = "_id") | |
var id: Long? = null, | |
@ColumnInfo(name = "DATE") | |
var date: String, |
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
@Database(entities = [DayLookEntity::class], version = 2) | |
abstract class ScreenCounterDb : RoomDatabase() { | |
private var dbClearFlag = false | |
abstract fun dayLookDao(): DayLookDbDao | |
companion object { | |
@Volatile |
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
/** | |
* Service which starts a receiver for catching SCREEN_ON, SCREEN_OFF, and USER_PRESENT events. | |
* | |
* @author Antonina | |
*/ | |
class LookCounterService : Service() { | |
private val SERVICE_ID = 1 | |
private lateinit var screenLookReceiver: ScreenLookReceiver |
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
@Dao | |
interface DayLookDbDao { | |
@Query("SELECT * FROM DAY_LOOK WHERE DATE = :dateToSearch LIMIT 1") | |
fun getDayLookByDate(dateToSearch: String?): Maybe<DayLookEntity> | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun insert(dayLook: DayLookEntity) | |
@Query("SELECT * FROM DAY_LOOK") |
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
interface CalendarContract { | |
interface Presenter : BaseMvpPresenter<CalendarContract.View> { | |
fun populateList(context: Context?, date: Calendar, screenLookCategory: ScreenLookCategory) | |
} | |
interface View : BaseView { | |
fun setViewTitle(titleMonth: Calendar) | |
fun setWeekLabels(weekLabels: List<String>) |
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
interface BaseView { | |
@LayoutRes | |
fun getContentResource(): Int | |
fun init(view: View, @Nullable state: Bundle?) | |
} |
OlderNewer