Search in sources :

Example 1 with XmlStorage

use of io.divide.shared.file.XmlStorage in project divide by HiddenStage.

the class BackendModule method configure.

@Override
protected final void configure() {
    logConfiguration();
    if (config == null)
        throw new IllegalStateException("Config can not be null");
    // ORDER MATTER
    bind(type).toInstance(config);
    bind(Config.class).toInstance(config);
    bind(Backend.class).in(Singleton.class);
    bind(Storage.class).toInstance(new XmlStorage(new File(config.fileSavePath + "storage.xml"), Storage.MODE_WORLD_WRITEABLE));
    bind(AccountStorage.class).toInstance(new XmlAccoutStorage(new File(config.fileSavePath + "accounts.xml")));
    bind(new TypeLiteral<DAO<BackendObject, BackendObject>>() {
    }).to(new TypeLiteral<LocalStorageIBoxDb<BackendObject, BackendObject>>() {
    }).in(Singleton.class);
    // ugly but required, doesnt allow binding to itself
    if (AuthManager.class.equals(getAuthManagerClass())) {
        bind(AuthManager.class).in(Singleton.class);
    } else {
        bind(AuthManager.class).to(getAuthManagerClass()).in(Singleton.class);
    }
    if (DataManager.class.equals(getDataManagerClass())) {
        bind(DataManager.class).in(Singleton.class);
    } else {
        bind(DataManager.class).to(getDataManagerClass()).in(Singleton.class);
    }
    if (ObjectManager.class.equals(getObjectManagerClass())) {
        bind(ObjectManager.class).in(Singleton.class);
    } else {
        bind(ObjectManager.class).to(getObjectManagerClass()).in(Singleton.class);
    }
    requestStaticInjection(Backend.class);
    requestStaticInjection(BackendUser.class);
    requestStaticInjection(BackendServices.class);
    additionalConfig(config);
}
Also used : AuthManager(io.divide.client.auth.AuthManager) DataManager(io.divide.client.data.DataManager) XmlStorage(io.divide.shared.file.XmlStorage) XmlAccoutStorage(io.divide.client.auth.credentials.XmlAccoutStorage) AccountStorage(io.divide.client.auth.AccountStorage) ObjectManager(io.divide.client.data.ObjectManager) XmlAccoutStorage(io.divide.client.auth.credentials.XmlAccoutStorage) Storage(io.divide.shared.file.Storage) AccountStorage(io.divide.client.auth.AccountStorage) XmlStorage(io.divide.shared.file.XmlStorage) DAO(io.divide.shared.server.DAO) TypeLiteral(com.google.inject.TypeLiteral) File(java.io.File)

Example 2 with XmlStorage

use of io.divide.shared.file.XmlStorage in project divide by HiddenStage.

the class MyActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DivideDrawer.attach(this, R.layout.main);
    //        setContentView(R.layout.main);
    ButterKnife.inject(this);
    getActionBar().setHomeButtonEnabled(true);
    //        au = AuthUtils.get(this, AuthManager.ACCOUNT_TYPE); TODO replace this
    app = (MyApplication) this.getApplication();
    BackendServices.addLoginListener(new LoginListener() {

        @Override
        public void onNext(BackendUser user) {
            System.out.println("loginListener: setUser: " + user);
            if (user != null) {
                setUser(user);
            }
        }
    });
    adapter = new BackendObjectAdaper(this, objectList);
    usersLV.setAdapter(adapter);
    usersLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            BackendObject o = adapter.getItem(position);
            Query q = new QueryBuilder().delete().from(BackendObject.class).where(TransientObject.OBJECT_KEY, OPERAND.EQ, o.getObjectKey()).build();
            BackendServices.remote().query(BackendObject.class, q).subscribe(new Action1<Collection<BackendObject>>() {

                @Override
                public void call(Collection<BackendObject> backendObjects) {
                    getObjects();
                }
            });
            BackendServices.local().delete(o);
        }
    });
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (BackendUser.isLoggedIn())
                getObjects();
            else
                logger.debug("Not signed in, not querying data.");
        }
    }, 1000);
    Storage s = new XmlStorage(new File(this.getFilesDir() + File.separator + "something.xml"), Storage.MODE_WORLD_WRITEABLE);
    String id = "something";
    System.out.println("Stored: " + s.getString(id, ""));
    System.out.println("Stored: " + s.contains(id));
    s.edit().putString(id, "something2").commit();
    s.edit().putInt("int", 55).commit();
}
Also used : BackendObject(io.divide.client.BackendObject) Action1(rx.functions.Action1) Query(io.divide.shared.transitory.query.Query) Handler(android.os.Handler) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) BackendUser(io.divide.client.BackendUser) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) XmlStorage(io.divide.shared.file.XmlStorage) LoginListener(io.divide.client.auth.LoginListener) Storage(io.divide.shared.file.Storage) XmlStorage(io.divide.shared.file.XmlStorage) Collection(java.util.Collection) AdapterView(android.widget.AdapterView) File(java.io.File)

Aggregations

Storage (io.divide.shared.file.Storage)2 XmlStorage (io.divide.shared.file.XmlStorage)2 File (java.io.File)2 Handler (android.os.Handler)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 TypeLiteral (com.google.inject.TypeLiteral)1 BackendObject (io.divide.client.BackendObject)1 BackendUser (io.divide.client.BackendUser)1 AccountStorage (io.divide.client.auth.AccountStorage)1 AuthManager (io.divide.client.auth.AuthManager)1 LoginListener (io.divide.client.auth.LoginListener)1 XmlAccoutStorage (io.divide.client.auth.credentials.XmlAccoutStorage)1 DataManager (io.divide.client.data.DataManager)1 ObjectManager (io.divide.client.data.ObjectManager)1 DAO (io.divide.shared.server.DAO)1 Query (io.divide.shared.transitory.query.Query)1