Search in sources :

Example 1 with AuthTable

use of org.storymaker.app.model.AuthTable in project storymaker by StoryMaker.

the class AccountsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getIntent().getBooleanExtra("isDialog", false)) {
        setTheme(android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);
    }
    setContentView(R.layout.activity_accounts);
    boolean isUserLoggedIntoSM = false;
    Auth storymakerAuth = (new AuthTable()).getAuthDefault(getApplicationContext(), Auth.SITE_STORYMAKER);
    if (storymakerAuth != null) {
        // FIXME we should check a little more carefully if the auth credentials are valid
        isUserLoggedIntoSM = true;
    }
    Bundle bundle = null;
    Intent intent = getIntent();
    bundle = new Bundle();
    bundle.putBoolean("isDialog", intent.getBooleanExtra("isDialog", false));
    bundle.putBoolean("inSelectionMode", intent.getBooleanExtra("inSelectionMode", false));
    bundle.putBoolean("isUserLoggedIntoSM", isUserLoggedIntoSM);
    addChooseAccountFragment(bundle);
}
Also used : Bundle(android.os.Bundle) Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable) Intent(android.content.Intent)

Example 2 with AuthTable

use of org.storymaker.app.model.AuthTable in project storymaker by StoryMaker.

the class AccountsActivity method addChooseAccountFragment.

public void addChooseAccountFragment(Bundle bundle) {
    FragmentManager fragManager = getSupportFragmentManager();
    FragmentTransaction fragTrans = fragManager.beginTransaction();
    List<Account> accounts = new ArrayList<>();
    final AuthTable authTable = new AuthTable();
    String[] siteAvailableNames = Account.CONTROLLER_SITE_NAMES;
    String[] siteAvailableKeys = Account.CONTROLLER_SITE_KEYS;
    Auth auth;
    for (int i = 0; i < siteAvailableKeys.length; i++) {
        auth = authTable.getAuthDefault(this, siteAvailableKeys[i]);
        if (auth == null) {
            accounts.add(new Account(-1, siteAvailableNames[i], siteAvailableKeys[i], "", "", null, false, false));
        } else {
            accounts.add(auth.convertToAccountObject());
        }
    }
    caFragment = new ChooseAccountFragment();
    caFragment.setArguments(bundle);
    caFragment.setLoginIntent(new Intent(this, ConnectAccountActivity.class));
    // FIXME we should probably make Account object parcelable and pass this through the bundle
    caFragment.setAccountsList(accounts);
    caFragment.setOnEventListener(new SiteController.OnEventListener() {

        @Override
        public void onSuccess(Account account) {
            Auth auth = authTable.getAuthDefault(getApplicationContext(), account.getSite());
            //if auth doesn't exist in db
            if (auth == null) {
                auth = new Auth(getApplicationContext(), -1, account.getName(), account.getSite(), null, null, null, null, null);
                auth.insert();
            }
            //set id of account based on returned id of auth insert
            account.setId(auth.getId());
            auth.setCredentials(account.getCredentials());
            auth.setData(account.getData());
            auth.setUserName(account.getUserName());
            auth.setExpires(null);
            authTable.updateLastLogin(getApplicationContext(), account.getSite(), auth.getUserName());
            auth.update();
        }

        @Override
        public void onFailure(Account account, String failureMessage) {
            Auth auth = authTable.getAuthDefault(getApplicationContext(), account.getSite());
            if (auth != null) {
                //TODO set variables here
                auth.setCredentials(account.getCredentials());
                auth.setUserName(account.getName());
                auth.setData(account.getData());
                // FIXME this is a hack to get isValid to fail, probably should be a setFailed() in auth that marks that we are busted
                auth.setExpires(new Date());
                auth.update();
            }
        }

        @Override
        public void onRemove(Account account) {
            authTable.delete(getApplicationContext(), account.getId());
        }
    });
    fragTrans.add(R.id.fragmentLayout, caFragment);
    fragTrans.commit();
}
Also used : Account(io.scal.secureshare.model.Account) ChooseAccountFragment(io.scal.secureshare.lib.ChooseAccountFragment) AuthTable(org.storymaker.app.model.AuthTable) ArrayList(java.util.ArrayList) Intent(android.content.Intent) SiteController(io.scal.secureshare.controller.SiteController) Date(java.util.Date) FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Auth(org.storymaker.app.model.Auth)

Example 3 with AuthTable

use of org.storymaker.app.model.AuthTable in project storymaker by StoryMaker.

the class ProjectsProvider method update.

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    mCacheWordHandler.connectToService();
    setTimer(60000);
    SQLiteDatabase db = getDB();
    if (db != null) {
        int uriType = sURIMatcher.match(uri);
        switch(uriType) {
            case PROJECTS:
            case PROJECT_ID:
                return (new ProjectTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case SCENES:
            case SCENE_ID:
                return (new SceneTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case LESSONS:
            case LESSON_ID:
                return (new LessonTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case MEDIA:
            case MEDIA_ID:
                return (new MediaTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case AUTH:
            case AUTH_ID:
                return (new AuthTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case TAGS:
            case TAG_ID:
            case DISTINCT_TAGS:
            case DISTINCT_TAG_ID:
                return (new TagTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case JOBS:
            case JOB_ID:
                return (new JobTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case PUBLISH_JOBS:
            case PUBLISH_JOB_ID:
                return (new PublishJobTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            case AUDIO_CLIPS:
            case AUDIO_CLIP_ID:
                return (new AudioClipTable(db)).update(getContext(), uri, values, selection, selectionArgs);
            default:
                throw new IllegalArgumentException("Unknown URI");
        }
    }
    return 0;
}
Also used : SceneTable(org.storymaker.app.model.SceneTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) JobTable(org.storymaker.app.model.JobTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) MediaTable(org.storymaker.app.model.MediaTable) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) AudioClipTable(org.storymaker.app.model.AudioClipTable) AuthTable(org.storymaker.app.model.AuthTable) TagTable(org.storymaker.app.model.TagTable) ProjectTable(org.storymaker.app.model.ProjectTable) LessonTable(org.storymaker.app.model.LessonTable)

Example 4 with AuthTable

use of org.storymaker.app.model.AuthTable in project storymaker by StoryMaker.

the class ProjectsProvider method query.

@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    mCacheWordHandler.connectToService();
    setTimer(60000);
    SQLiteDatabase db = getDB();
    if (db != null) {
        int uriType = sURIMatcher.match(uri);
        switch(uriType) {
            case PROJECT_ID:
                return (new ProjectTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case PROJECTS:
                return (new ProjectTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case SCENE_ID:
                return (new SceneTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case SCENES:
                return (new SceneTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case LESSON_ID:
                return (new LessonTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case LESSONS:
                return (new LessonTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case MEDIA_ID:
                return (new MediaTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case MEDIA:
                return (new MediaTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case AUTH_ID:
                return (new AuthTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case AUTH:
                return (new AuthTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case TAG_ID:
                return (new TagTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case TAGS:
                return (new TagTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case DISTINCT_TAG_ID:
                return (new TagTable(db)).queryOneDistinct(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case DISTINCT_TAGS:
                return (new TagTable(db)).queryAllDistinct(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case JOB_ID:
                return (new JobTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case JOBS:
                return (new JobTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case PUBLISH_JOB_ID:
                return (new PublishJobTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case PUBLISH_JOBS:
                return (new PublishJobTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case AUDIO_CLIP_ID:
                return (new AudioClipTable(db)).queryOne(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            case AUDIO_CLIPS:
                return (new AudioClipTable(db)).queryAll(getContext(), uri, projection, selection, selectionArgs, sortOrder);
            default:
                throw new IllegalArgumentException("Unknown URI");
        }
    }
    return null;
}
Also used : SceneTable(org.storymaker.app.model.SceneTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) JobTable(org.storymaker.app.model.JobTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) MediaTable(org.storymaker.app.model.MediaTable) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) AudioClipTable(org.storymaker.app.model.AudioClipTable) AuthTable(org.storymaker.app.model.AuthTable) TagTable(org.storymaker.app.model.TagTable) ProjectTable(org.storymaker.app.model.ProjectTable) LessonTable(org.storymaker.app.model.LessonTable) Nullable(android.support.annotation.Nullable)

Example 5 with AuthTable

use of org.storymaker.app.model.AuthTable in project storymaker by StoryMaker.

the class ArchiveUploader method start.

// FIXME move the render file checks into base class
@Override
public void start() {
    final SiteController controller = SiteController.getSiteController(ArchiveSiteController.SITE_KEY, mContext, mHandler, "" + mJob.getId());
    final Project project = mJob.getProject();
    final PublishJob publishJob = mJob.getPublishJob();
    final String path = publishJob.getLastRenderFilePath();
    final Auth auth = (new AuthTable()).getAuthDefault(mContext, ArchiveSiteController.SITE_KEY);
    if (Utils.stringNotBlank(path) && (new File(path)).exists()) {
        jobProgress(mJob, 0, mContext.getString(R.string.uploading_to_internet_archive));
        HashMap<String, String> valueMap = publishJob.getMetadata();
        addValuesToHashmap(valueMap, project.getTitle(), project.getDescription(), path);
        // FIXME need to hookup Account to this
        controller.upload(auth.convertToAccountObject(), valueMap);
    } else {
        Timber.d("Can't upload to Internet Archive server, last rendered file doesn't exist.");
        // TODO get this error back to the activity for display 
        // FIXME move to strings.xml
        jobFailed(null, ERROR_NO_RENDER_FILE, "Can't upload to Internet Archive server, last rendered file doesn't exist.");
    }
}
Also used : Project(org.storymaker.app.model.Project) Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable) SiteController(io.scal.secureshare.controller.SiteController) ArchiveSiteController(io.scal.secureshare.controller.ArchiveSiteController) File(java.io.File) PublishJob(org.storymaker.app.model.PublishJob)

Aggregations

AuthTable (org.storymaker.app.model.AuthTable)18 Auth (org.storymaker.app.model.Auth)14 SiteController (io.scal.secureshare.controller.SiteController)6 Project (org.storymaker.app.model.Project)6 PublishJob (org.storymaker.app.model.PublishJob)6 Handler (android.os.Handler)4 File (java.io.File)4 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)4 AudioClipTable (org.storymaker.app.model.AudioClipTable)4 JobTable (org.storymaker.app.model.JobTable)4 LessonTable (org.storymaker.app.model.LessonTable)4 MediaTable (org.storymaker.app.model.MediaTable)4 ProjectTable (org.storymaker.app.model.ProjectTable)4 PublishJobTable (org.storymaker.app.model.PublishJobTable)4 SceneTable (org.storymaker.app.model.SceneTable)4 TagTable (org.storymaker.app.model.TagTable)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)2 Nullable (android.support.annotation.Nullable)2 Date (java.util.Date)2