Newer
Older
NemophilaClient / app / src / main / java / com / example / nemophila / Nemophila.java
package com.example.nemophila;

import android.app.Application;
import android.content.SharedPreferences;

import com.example.nemophila.entities.Shop;
import com.google.type.LatLng;

public class Nemophila extends Application {
    //アカウントのデータ
    private String name;
    private String uid;
    private String token;

    //ショップのデータ
    private Shop currentShop;
    private double currentLongitude;
    private double currentLatitude;
    private Shop dummyShop;

    //カメラのデータ
    private Float cameraLatitude;
    private Float cameraLongitude;
    private float zoom;

    //Getter

    public String getName() {
        if(name == null){
            SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
            name = preferences.getString("name", null);
        }
        return name;
    }
    public String getUid() {
        if(uid == null){
            SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
            uid = preferences.getString("uid", null);
        }
        return uid;
    }
    public String getToken() {
        if(token == null){
            SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
            token = preferences.getString("token", null);
        }
        return token;
    }
    public Shop getCurrentShop() {
        return currentShop;
    }
    public double getCurrentLongitude() {
        return currentLongitude;
    }
    public double getCurrentLatitude() {
        return currentLatitude;
    }
    public Shop getDummyShop() {
        return dummyShop;
    }
    public Float getCameraLatitude() {
        if(cameraLatitude == 0){
            SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
            cameraLatitude = preferences.getFloat("cameraLatitude", 0);
        }
        return cameraLatitude;
    }
    public Float getCameraLongitude() {
        if(cameraLongitude == 0){
            SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
            cameraLongitude = preferences.getFloat("cameraLongitude", 0);
        }
        return cameraLongitude;
    }
    public float getZoom() {
        if(zoom == 0.0){
            SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
            zoom = preferences.getFloat("zoom", 0);
        }
        return zoom;
    }

    //Setter
    public void setName(String name) {
        SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("name", name);
        this.name = name;
        editor.commit();
    }
    public void setUid(String uid) {
        SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("uid", uid);
        this.uid = uid;
        editor.commit();
    }
    public void setToken(String token) {
        SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("token", token);
        this.token = token;
        editor.commit();
    }
    public void setCurrentShop(Shop currentShop) {
        this.currentShop = currentShop;
    }
    public void setCurrentLongitude(double currentLongitude) {
        this.currentLongitude = currentLongitude;
    }
    public void setCurrentLatitude(double currentLatitude) {
        this.currentLatitude = currentLatitude;
    }
    public void setDummyShop(Shop dummyShop) {
        this.dummyShop = dummyShop;
    }
    public void setCameraLatitude(Float cameraLatitude) {
        SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putFloat("cameraLatitude", cameraLatitude);
        this.cameraLatitude = cameraLatitude;
    }
    public void setCameraLongitude(Float cameraLongitude) {
        SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putFloat("cameraLongitude", cameraLongitude);
        this.cameraLongitude = cameraLongitude;
    }
    public void setZoom(float zoom) {
        SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putFloat("zoom", zoom);
        this.zoom = zoom;
    }
}