Fix refresh token + improve search layout
This commit is contained in:
parent
76e10fccf8
commit
0b58fba5dc
|
@ -1128,7 +1128,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
//It's not a peertube search
|
||||
if(displayPeertube == null){
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
|
||||
if( (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
|
||||
&& !query.contains("http://") && !query.contains("https://")){
|
||||
Intent intent = new Intent(BaseMainActivity.this, SearchResultTabActivity.class);
|
||||
intent.putExtra("search", query);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -374,46 +374,41 @@ public class API {
|
|||
isPleromaAdmin(account.getAcct());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
if( e.getStatusCode() == 401 || e.getStatusCode() == 403){
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
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).updateAccount(targetedAccount);
|
||||
String response;
|
||||
try {
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/accounts/verify_credentials"), 60, null, targetedAccount.getToken());
|
||||
account = parseAccountResponse(context, new JSONObject(response));
|
||||
if( account.getSocial().equals("PLEROMA")){
|
||||
isPleromaAdmin(account.getAcct());
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (KeyManagementException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
e1.printStackTrace();
|
||||
setError(e.getStatusCode(), e);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
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();
|
||||
}
|
||||
}else{
|
||||
}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).get(getAbsoluteUrl("/accounts/verify_credentials"), 60, null, targetedAccount.getToken());
|
||||
account = parseAccountResponse(context, new JSONObject(response));
|
||||
if( account.getSocial().equals("PLEROMA")){
|
||||
isPleromaAdmin(account.getAcct());
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (KeyManagementException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
e1.printStackTrace();
|
||||
setError(e.getStatusCode(), e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -380,41 +380,37 @@ public class PeertubeAPI {
|
|||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}catch (HttpsConnection.HttpsConnectionException e) {
|
||||
if( e.getStatusCode() == 401 || e.getStatusCode() == 403){
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
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).updateAccount(targetedAccount);
|
||||
String response;
|
||||
try {
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
|
||||
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
||||
account = parseAccountResponsePeertube(context, accountObject);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (KeyManagementException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
e1.printStackTrace();
|
||||
setError(e.getStatusCode(), e);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
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();
|
||||
}
|
||||
}else{
|
||||
}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).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
|
||||
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
||||
account = parseAccountResponsePeertube(context, accountObject);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (KeyManagementException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||
e1.printStackTrace();
|
||||
setError(e.getStatusCode(), e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -43,7 +43,7 @@ public class SearchTagsAdapter extends RecyclerView.Adapter {
|
|||
|
||||
public SearchTagsAdapter(Context context, List<String> tags){
|
||||
this.context = context;
|
||||
this.tags = ( tags != null)?tags:new ArrayList<String>();
|
||||
this.tags = ( tags != null)?tags:new ArrayList<>();
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class SearchTagsAdapter extends RecyclerView.Adapter {
|
|||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_tag_search, parent, false));
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_tag_search_tab, parent, false));
|
||||
}
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder{
|
||||
|
@ -69,10 +69,9 @@ public class SearchTagsAdapter extends RecyclerView.Adapter {
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
final ViewHolder holder = (ViewHolder) viewHolder;
|
||||
final String tag = (String) getItem(i);
|
||||
final String tag = getItem(i);
|
||||
|
||||
holder.tag_name.setText(String.format("#%s",tag));
|
||||
holder.tag_name.setPaintFlags(holder.tag_name.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
holder.tag_name.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2017 Thomas Schneider
|
||||
|
||||
This file is a part of Mastalab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/tag_name"
|
||||
android:layout_margin="5dp"
|
||||
android:textSize="18sp"
|
||||
android:padding="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue