Android Open Source - WearPomodoro Persistent Storage






From Project

Back to project page WearPomodoro.

License

The source code is released under:

GNU General Public License

If you think the Android project WearPomodoro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Alex Korovyansky./*  w  w w.  ja v  a  2  s. c  o  m*/
 */
package com.alexkorovyansky.wearpomodoro.helpers;

import android.content.Context;
import android.content.SharedPreferences;

import com.alexkorovyansky.wearpomodoro.model.ActivityType;

public class PersistentStorage {

    private final SharedPreferences sharedPreferences;

    public PersistentStorage(Context context) {
        this.sharedPreferences = context.getSharedPreferences("persistent", Context.MODE_PRIVATE);
    }

    public void writeActivityType(ActivityType activityType) {
        sharedPreferences.edit().putInt("activity_type", activityType.value()).apply();;
    }

    public ActivityType readActivityType() {
        return ActivityType.fromValue(sharedPreferences.getInt("activity_type", -1));
    }

    public void writeWhenMs(long whenMs) {
        sharedPreferences.edit().putLong("when", whenMs).apply();;
    }

    public long readWhenMs() {
        return sharedPreferences.getLong("when", -1);
    }

    public void writeLastEatenPomodoroTimestampMs(long timestampMs) {
        sharedPreferences.edit().putLong("last_eaten_pomodoro_timestamp", timestampMs).apply();
    }

    public long readLastEatenPomodoroTimestampMs() {
        return sharedPreferences.getLong("last_eaten_pomodoro_timestamp", 0);
    }

    public void writeEatenPomodoros(int number) {
        sharedPreferences.edit().putInt("eaten_pomodoros", number).apply();;
    }

    public int readEatenPomodoros() {
        return sharedPreferences.getInt("eaten_pomodoros", 0);
    }
}




Java Source Code List

com.alexkorovyansky.wearpomodoro.app.MainActivity.java
com.alexkorovyansky.wearpomodoro.app.PomodoroConstants.java
com.alexkorovyansky.wearpomodoro.app.base.BasePomodoroActivity.java
com.alexkorovyansky.wearpomodoro.app.receivers.PomodoroAlarmReceiver.java
com.alexkorovyansky.wearpomodoro.app.receivers.PomodoroAlarmTickReceiver.java
com.alexkorovyansky.wearpomodoro.app.receivers.PomodoroControlReceiver.java
com.alexkorovyansky.wearpomodoro.app.services.PomodoroNotificationService.java
com.alexkorovyansky.wearpomodoro.app.ui.PomodoroEntryActivity.java
com.alexkorovyansky.wearpomodoro.app.ui.PomodoroTransitionActivity.java
com.alexkorovyansky.wearpomodoro.helpers.PersistentStorage.java
com.alexkorovyansky.wearpomodoro.helpers.PomodoroMaster.java
com.alexkorovyansky.wearpomodoro.helpers.PomodoroUtils.java
com.alexkorovyansky.wearpomodoro.helpers.ServiceProvider.java
com.alexkorovyansky.wearpomodoro.helpers.UITimer.java
com.alexkorovyansky.wearpomodoro.helpers.WakefulBroadcastReceiver.java
com.alexkorovyansky.wearpomodoro.model.ActivityType.java