Move assets

This commit is contained in:
Thomas 2020-07-24 19:52:36 +02:00
parent 361857aff4
commit 82e4e40af5
22 changed files with 77 additions and 166 deletions

View File

@ -106,6 +106,7 @@ import app.fedilab.android.asynctasks.RetrieveStoriesAsyncTask;
import app.fedilab.android.asynctasks.SyncTimelinesAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoByIDAsyncTask;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Announcement;
@ -316,6 +317,11 @@ public abstract class BaseMainActivity extends BaseActivity
} catch (Exception ignored) {
}
}
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
new Thread(() -> {
new API(BaseMainActivity.this).refreshToken(account);
}).start();
}
//Here, the user is authenticated
appBar = findViewById(R.id.appBar);
Toolbar toolbar = findViewById(R.id.toolbar);

View File

@ -1062,14 +1062,14 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
JSONObject response = null;
JSONObject response;
pixelfed_story.setEnabled(true);
try {
response = new JSONObject(serverResponse.getBodyAsString());
addNewMedia(response, uploadInfo.getSuccessfullyUploadedFiles());
} catch (JSONException e) {
e.printStackTrace();
}
addNewMedia(response, uploadInfo.getSuccessfullyUploadedFiles());
}
@Override

View File

@ -292,15 +292,16 @@ public abstract class BaseTootActivity extends BaseActivity implements UploadSta
@Override
public void onReceive(Context context, Intent intent) {
JSONObject response = null;
JSONObject response;
ArrayList<String> successfullyUploadedFiles;
try {
response = new JSONObject(Objects.requireNonNull(intent.getStringExtra("response")));
successfullyUploadedFiles = intent.getStringArrayListExtra("uploadInfo");
addNewMedia(response, successfullyUploadedFiles);
} catch (JSONException e) {
e.printStackTrace();
}
successfullyUploadedFiles = intent.getStringArrayListExtra("uploadInfo");
addNewMedia(response, successfullyUploadedFiles);
}
};

View File

@ -589,13 +589,14 @@ public class LoginActivity extends BaseActivity {
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU && socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
try {
resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
String token = resobj.getString("access_token");
String refresh_token = null;
if (resobj.has("refresh_token"))
refresh_token = resobj.getString("refresh_token");
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.apply();
//Update the account with the token;
if (instance != null) {
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, instance, socialNetwork).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

View File

@ -344,7 +344,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
statuses = new ArrayList<>();
statuses.clear();
for (Status status : apiResponse.getContext().getAncestors()) {
if (detailsStatus.equals(status)) {
if (detailsStatus != null && detailsStatus.equals(status)) {
break;
}
i++;

View File

@ -82,7 +82,6 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
instance = URLDecoder.decode(instance, "utf-8");
} catch (UnsupportedEncodingException ignored) {
}
SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
account.setToken(token);
account.setClient_id(client_id);

View File

@ -2531,74 +2531,55 @@ public class API {
}
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
if (e.getStatusCode() == 401 || e.getStatusCode() == 403) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
if (targetedAccount == null)
return null;
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
if (values.containsKey("access_token") && values.get("access_token") != null) {
targetedAccount.setToken(values.get("access_token"));
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
//This account is currently logged in, the token is updated
if (prefKeyOauthTokenT.equals(token)) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, targetedAccount.getToken());
editor.apply();
}
}
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
targetedAccount.setRefresh_token(values.get("refresh_token"));
new AccountDAO(context, db).updateAccountCredential(targetedAccount);
String response;
try {
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, targetedAccount.getToken());
account = parseAccountResponse(new JSONObject(response));
if (social != null) {
account.setSocial(social.toUpperCase());
}
if (account.getSocial().equals("PLEROMA")) {
isPleromaAdmin(account.getAcct());
}
} catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e1) {
e1.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e1) {
e1.printStackTrace();
setError(e.getStatusCode(), e);
}
}
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
return account;
}
/***
* Verifiy credential of the authenticated user *synchronously*
* @return Account
*/
private HashMap<String, String> refreshToken(String client_id, String client_secret, String refresh_token) {
account = new Account();
public void refreshToken(Account account) {
HashMap<String, String> params = new HashMap<>();
HashMap<String, String> newValues = new HashMap<>();
params.put("grant_type", "refresh_token");
params.put("client_id", client_id);
params.put("client_secret", client_secret);
params.put("refresh_token", refresh_token);
params.put("client_id", account.getClient_id());
params.put("client_secret", account.getClient_secret());
params.put("refresh_token", account.getRefresh_token());
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
try {
String response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/oauth/token"), 10, params, null);
String response;
if (account.getSocial().compareTo("PEERTUBE") == 0) {
response = new HttpsConnection(context, instance).post(getAbsoluteUrl("/users/token"), 60, params, account.getToken());
} else {
response = new HttpsConnection(context, instance).post("https://" + instance + "/oauth/token", 60, params, account.getToken());
}
JSONObject resobj = new JSONObject(response);
String token = resobj.getString("access_token");
if (resobj.has("refresh_token"))
refresh_token = resobj.getString("refresh_token");
newValues.put("access_token", token);
newValues.put("refresh_token", refresh_token);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) {
String newToken = resobj.getString("access_token");
String newRefreshToken = resobj.getString("refresh_token");
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, newToken);
editor.apply();
if (account.getSocial().compareTo("PEERTUBE") == 0) {
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, newToken);
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
account = parseAccountResponsePeertube(instance, accountObject);
} else {
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, newToken);
account = parseAccountResponse(new JSONObject(response));
}
account.setRefresh_token(newRefreshToken);
account.setToken(newToken);
new AccountDAO(context, db).updateAccount(account);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}
return newValues;
}
public APIResponse createAccount(AccountCreation accountCreation) {

View File

@ -664,45 +664,8 @@ public class PeertubeAPI {
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
if (e.getStatusCode() == 401 || e.getStatusCode() == 403) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
if (targetedAccount != null) {
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
if (values.containsKey("access_token") && values.get("access_token") != null) {
targetedAccount.setToken(values.get("access_token"));
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
//This account is currently logged in, the token is updated
if (prefKeyOauthTokenT != null && prefKeyOauthTokenT.equals(token)) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, targetedAccount.getToken());
editor.apply();
}
}
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
targetedAccount.setRefresh_token(values.get("refresh_token"));
new AccountDAO(context, db).updateAccount(targetedAccount);
String response;
try {
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
account = parseAccountResponsePeertube(accountObject);
if (social != null) {
account.setSocial(social.toUpperCase());
}
} catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e1) {
e1.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e1) {
e1.printStackTrace();
setError(e.getStatusCode(), e);
}
} else {
setError(e.getStatusCode(), e);
}
e.printStackTrace();
}
setError(e.getStatusCode(), e);
e.printStackTrace();
}
return account;
}
@ -745,31 +708,6 @@ public class PeertubeAPI {
return apiResponse;
}
/***
* Verifiy credential of the authenticated user *synchronously*
* @return Account
*/
private HashMap<String, String> refreshToken(String client_id, String client_secret, String refresh_token) {
account = new Account();
HashMap<String, String> params = new HashMap<>();
HashMap<String, String> newValues = new HashMap<>();
params.put("grant_type", "refresh_token");
params.put("client_id", client_id);
params.put("client_secret", client_secret);
params.put("refresh_token", refresh_token);
try {
String response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/users/token"), 60, params, null);
JSONObject resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
if (resobj.has("refresh_token"))
refresh_token = resobj.get("refresh_token").toString();
newValues.put("access_token", token);
newValues.put("refresh_token", refresh_token);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
}
return newValues;
}
/**
* Returns an account
@ -1059,29 +997,6 @@ public class PeertubeAPI {
try {
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
} catch (HttpsConnection.HttpsConnectionException e) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
if (targetedAccount != null && (e.getStatusCode() == 401 || e.getStatusCode() == 403)) {
HashMap<String, String> values = refreshToken(targetedAccount.getClient_id(), targetedAccount.getClient_secret(), targetedAccount.getRefresh_token());
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if (values.containsKey("access_token") && values.get("access_token") != null) {
targetedAccount.setToken(values.get("access_token"));
//This account is currently logged in, the token is updated
SharedPreferences.Editor editor = sharedpreferences.edit();
prefKeyOauthTokenT = targetedAccount.getToken();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, targetedAccount.getToken());
editor.apply();
}
if (values.containsKey("refresh_token") && values.get("refresh_token") != null)
targetedAccount.setRefresh_token(values.get("refresh_token"));
new AccountDAO(context, db).updateAccount(targetedAccount);
try {
return getTL("/users/me/subscriptions/videos", "-publishedAt", null, max_id, null, null);
} catch (HttpsConnection.HttpsConnectionException e1) {
setError(e.getStatusCode(), e);
return apiResponse;
}
}
setError(e.getStatusCode(), e);
return apiResponse;
}

View File

@ -91,7 +91,8 @@ public class CustomEmojiAdapter extends BaseAdapter {
if (imageView != null && emoji.getDrawable() != null) {
try {
imageView.setImageDrawable(emoji.getDrawable());
}catch (Exception ignored){}
} catch (Exception ignored) {
}
}
}

View File

@ -74,9 +74,11 @@ public class AccountDAO {
values.put(Sqlite.COL_INSTANCE, account.getInstance());
values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis()));
values.put(Sqlite.COL_SOCIAL, account.getSocial());
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
if (account.getClient_id() != null && account.getClient_secret() != null) {
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
}
if (account.getRefresh_token() != null) {
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
}
if (account.getToken() != null)
@ -122,9 +124,11 @@ public class AccountDAO {
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis()));
values.put(Sqlite.COL_SOCIAL, account.getSocial());
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
if (account.getClient_id() != null && account.getClient_secret() != null) {
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
}
if (account.getRefresh_token() != null) {
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
}
if (account.getToken() != null)
@ -164,9 +168,11 @@ public class AccountDAO {
if (account.getSocial() != null) {
values.put(Sqlite.COL_SOCIAL, account.getSocial());
}
if (account.getClient_id() != null && account.getClient_secret() != null && account.getRefresh_token() != null) {
if (account.getClient_id() != null && account.getClient_secret() != null) {
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
}
if (account.getRefresh_token() != null) {
values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token());
}
if (account.getToken() != null)

View File

@ -344,7 +344,7 @@
android:id="@+id/comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:minLines="3"
app:layout_constraintTop_toBottomOf="@id/comment_label" />

View File

@ -54,10 +54,11 @@
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="@string/title_hint_custom_sharing"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:lines="2"
android:maxLines="2"
android:minLines="1" />
android:minLines="1"
android:inputType="textWebEditText" />
<!-- Description -->

View File

@ -133,7 +133,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
<EditText
@ -141,7 +141,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>

View File

@ -41,7 +41,7 @@
android:id="@+id/add_phrase"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text"
android:singleLine="true" />

View File

@ -935,7 +935,7 @@
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>

View File

@ -875,7 +875,7 @@
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>

View File

@ -779,7 +779,7 @@
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>

View File

@ -791,7 +791,7 @@
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>

View File

@ -420,7 +420,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_custom_sharing_url"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="textUri" />
<!-- ADD TAGS -->

View File

@ -569,7 +569,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/your_api_key"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>

View File

@ -85,7 +85,7 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:hint="@string/set_invidious_host"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="textWebEditText" />
<LinearLayout

View File

@ -20,7 +20,7 @@
android:id="@+id/fake_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:importantForAutofill="noExcludeDescendants"
android:inputType="text" />
</LinearLayout>