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);
}
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();
}
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;
}
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;
}
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.");
}
}
Aggregations