Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ dependencies {
//exoplayer
implementation 'com.google.android.exoplayer:exoplayer:r1.5.7'

implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleVersion"

//utils
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0@aar'
implementation "com.jakewharton:butterknife:$rootProject.butterknifeVersion"
Expand Down
308 changes: 55 additions & 253 deletions app/src/main/java/org/fossasia/phimpme/accounts/AccountActivity.java

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.fossasia.phimpme.accounts;

import io.realm.Realm;
import io.realm.RealmQuery;
import org.fossasia.phimpme.data.local.AccountDatabase;
import org.fossasia.phimpme.data.local.DatabaseHelper;

/** Created by @codedsun on 09/Oct/2019 */
class AccountRepository {

private Realm realm = Realm.getDefaultInstance();
private DatabaseHelper databaseHelper = new DatabaseHelper(realm);

// Fetches the details of all accounts
RealmQuery<AccountDatabase> fetchAllAccounts() {
return databaseHelper.fetchAccountDetails();
}

// saves username, password and serverUrl for an account in database
void saveUsernamePasswordServerUrlForAccount(
AccountDatabase.AccountName accountName, String serverUrl, String username, String password) {
realm.beginTransaction();
AccountDatabase account = realm.createObject(AccountDatabase.class, accountName.toString());
account.setServerUrl(serverUrl);
account.setUsername(username);
account.setPassword(password);
realm.commitTransaction();
}

// saves username and token for an account in database
void saveUsernameAndToken(
AccountDatabase.AccountName accountName, String username, String token) {
realm.beginTransaction();
AccountDatabase account = realm.createObject(AccountDatabase.class, accountName.toString());
account.setUsername(username);
account.setToken(token);
realm.commitTransaction();
}

// deletes an account from database
void deleteAccount(String accountName) {
databaseHelper.deleteSignedOutAccount(accountName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.fossasia.phimpme.accounts;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import io.realm.RealmQuery;
import org.fossasia.phimpme.data.local.AccountDatabase;

/** Created by @codedsun on 09/Oct/2019 */
public class AccountViewModel extends ViewModel {

final int NEXTCLOUD_REQUEST_CODE = 3;
final int OWNCLOUD_REQUEST_CODE = 9;
final int RESULT_OK = 1;

private AccountRepository accountRepository = new AccountRepository();
MutableLiveData<Boolean> error = new MutableLiveData<>();
MutableLiveData<RealmQuery<AccountDatabase>> accountDetails = new MutableLiveData<>();

public AccountViewModel() {}

// Used to fetch all the current logged in accounts
void fetchAccountDetails() {
RealmQuery<AccountDatabase> accountDetails = accountRepository.fetchAllAccounts();
if (accountDetails.findAll().size() > 0) {
this.accountDetails.postValue(accountDetails);
} else {
error.postValue(true);
}
}

// used to save nextcloud or owncloud details
void saveOwnCloudOrNextCloudToken(
int requestCode, String serverUrl, String userName, String password) {
switch (requestCode) {
case NEXTCLOUD_REQUEST_CODE:
accountRepository.saveUsernamePasswordServerUrlForAccount(
AccountDatabase.AccountName.NEXTCLOUD, serverUrl, userName, password);
break;

case OWNCLOUD_REQUEST_CODE:
accountRepository.saveUsernamePasswordServerUrlForAccount(
AccountDatabase.AccountName.OWNCLOUD, serverUrl, userName, password);
break;
}
}

// to save dropbox details
void saveDropboxToken(String token) {
accountRepository.saveUsernameAndToken(
AccountDatabase.AccountName.DROPBOX, AccountDatabase.AccountName.DROPBOX.toString(), token);
}

// to save box details
void saveBoxToken(String username, String token) {
accountRepository.saveUsernameAndToken(AccountDatabase.AccountName.BOX, username, token);
}

// to save pintrest details
void savePinterestToken(String username) {
accountRepository.saveUsernameAndToken(AccountDatabase.AccountName.PINTEREST, username, "");
}

// to delete a specific account from database
void deleteAccountFromDatabase(String accountName) {
accountRepository.deleteAccount(accountName);
}

// to save imgur account details
void saveImgurAccount(String username, String token) {
accountRepository.saveUsernameAndToken(AccountDatabase.AccountName.IMGUR, username, token);
}
}
35 changes: 0 additions & 35 deletions app/src/main/java/org/fossasia/phimpme/base/BasePresenter.java

This file was deleted.

26 changes: 0 additions & 26 deletions app/src/main/java/org/fossasia/phimpme/base/MvpView.java

This file was deleted.

25 changes: 0 additions & 25 deletions app/src/main/java/org/fossasia/phimpme/base/Presenter.java

This file was deleted.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ext {
stethoVersion = "1.5.0"
showcaseVersion = "5.4.3"
nextCloudVersion = "1.5.0"
lifecycleVersion = "2.1.0"
glideVersion = "4.10.0"
}