Avoid issue with Tokens
This commit is contained in:
parent
a205d072ca
commit
9b7b499997
|
@ -233,11 +233,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
boolean displayFollowInstance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(token);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
if( account == null){
|
||||
Helper.logout(getApplicationContext());
|
||||
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
|
||||
|
@ -257,6 +256,9 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
|
||||
else if( account.getSocial().equals("GNU"))
|
||||
social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
||||
else if( account.getSocial().equals("FRIENDICA"))
|
||||
social = UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA;
|
||||
Log.v(Helper.TAG, account.getSocial());
|
||||
countNewStatus = 0;
|
||||
countNewNotifications = 0;
|
||||
|
||||
|
@ -345,7 +347,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
delete_all = findViewById(R.id.delete_all);
|
||||
add_new = findViewById(R.id.add_new);
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
TabLayout.Tab tabHome = tabLayout.newTab();
|
||||
TabLayout.Tab tabNotif = tabLayout.newTab();
|
||||
TabLayout.Tab tabDirect = tabLayout.newTab();
|
||||
|
@ -421,23 +423,23 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
tabLayout.addTab(tabHome);
|
||||
tabLayout.addTab(tabNotif);
|
||||
tabPosition.put("home",0);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.HOME);
|
||||
else
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.GNU_HOME);
|
||||
tabPosition.put("notifications",1);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
typePosition.put(1, RetrieveFeedsAsyncTask.Type.NOTIFICATION);
|
||||
else
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.GNU_NOTIFICATION);
|
||||
int i = 2;
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
display_direct = false;
|
||||
if( display_direct) {
|
||||
tabLayout.addTab(tabDirect);
|
||||
tabPosition.put("direct",i);
|
||||
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU ) {
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
|
||||
|
@ -461,7 +463,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
if( display_local) {
|
||||
tabLayout.addTab(tabLocal);
|
||||
tabPosition.put("local", i);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.LOCAL);
|
||||
else
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_LOCAL);
|
||||
|
@ -470,13 +472,13 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
if( display_global) {
|
||||
tabLayout.addTab(tabPublic);
|
||||
tabPosition.put("global", i);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA )
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||
else
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_WHOLE);
|
||||
i++;
|
||||
}
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
display_art = false;
|
||||
if( display_art ) {
|
||||
tabLayout.addTab(tabArt);
|
||||
|
@ -584,13 +586,13 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
});
|
||||
|
||||
countPage = 2;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true) && social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true) && social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
countPage++;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
|
||||
countPage++;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
|
||||
countPage++;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true)&& social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true)&& social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
countPage++;
|
||||
|
||||
if( tabPosition.containsKey("global"))
|
||||
|
@ -1101,10 +1103,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
startSreaming();
|
||||
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
Helper.refreshSearchTag(BaseMainActivity.this, tabLayout, adapter);
|
||||
int tabCount = tabLayout.getTabCount();
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
for( int j = countPage ; j < tabCount ; j++){
|
||||
attacheDelete(j);
|
||||
}
|
||||
|
@ -1122,7 +1124,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
query= query.replaceAll("^#+", "");
|
||||
//It's not a peertube search
|
||||
if(displayPeertube == null){
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
|
||||
intent.putExtra("search", query);
|
||||
startActivity(intent);
|
||||
|
@ -1232,7 +1234,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
|
||||
tabLayout.getTabAt(0).select();
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
toot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -1516,7 +1518,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
// Asked once for notification opt-in
|
||||
boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false);
|
||||
if(!popupShown && (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)){
|
||||
if(!popupShown && (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)){
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.popup_quick_settings, null);
|
||||
|
@ -1560,7 +1562,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
mamageNewIntent(getIntent());
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
|
||||
// Retrieves instance
|
||||
new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
@ -1844,10 +1846,11 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
DisplayStatusFragment fragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.MYVIDEOS);
|
||||
bundle.putString("instanceType","PEERTUBE");
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(token);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
bundle.putString("targetedid",account.getUsername());
|
||||
bundle.putBoolean("ownvideos", true);
|
||||
fragment.setArguments(bundle);
|
||||
|
@ -2181,9 +2184,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.MYVIDEOS);
|
||||
bundle.putString("instanceType","PEERTUBE");
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(token);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
bundle.putString("targetedid",account.getUsername());
|
||||
bundle.putBoolean("ownvideos", true);
|
||||
fragment.setArguments(bundle);
|
||||
|
@ -2463,14 +2467,14 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
|
||||
public void removeTabPage() {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
this.mNumOfTabs--;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void addTabPage(String title) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
TabLayout.Tab tab = tabLayout.newTab();
|
||||
tab.setText(title);
|
||||
this.mNumOfTabs++;
|
||||
|
@ -2480,7 +2484,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
//Remove the search bar
|
||||
if (!toolbar_search.isIconified()) {
|
||||
toolbarTitle.setVisibility(View.VISIBLE);
|
||||
|
@ -2492,7 +2496,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
Bundle bundle = new Bundle();
|
||||
if (position == 0) {
|
||||
homeFragment = new DisplayStatusFragment();
|
||||
if(social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if(social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME);
|
||||
else
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.GNU_HOME);
|
||||
|
@ -2595,7 +2599,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
||||
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
|
||||
registeredFragments.put(position, createdFragment);
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
|
||||
// save the appropriate reference depending on position
|
||||
if (position == 0) {
|
||||
|
@ -3078,7 +3082,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
public void manageFloatingButton(boolean display){
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean displayFollowInstance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU|| social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
if (display) {
|
||||
tootShow();
|
||||
if (!displayFollowInstance)
|
||||
|
@ -3095,7 +3099,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
}
|
||||
public void tootShow(){
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU|| social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
toot.show();
|
||||
}else{
|
||||
toot.hide();
|
||||
|
|
|
@ -208,9 +208,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
|||
}
|
||||
}
|
||||
});
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), my_pp);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null) {
|
||||
|
|
|
@ -288,7 +288,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
Button toot_cw = findViewById(R.id.toot_cw);
|
||||
toot_space_left = findViewById(R.id.toot_space_left);
|
||||
toot_visibility = findViewById(R.id.toot_visibility);
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
toot_visibility.setVisibility(View.GONE);
|
||||
toot_picture = findViewById(R.id.toot_picture);
|
||||
toot_picture_container = findViewById(R.id.toot_picture_container);
|
||||
|
|
|
@ -198,7 +198,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
statusCode = peertubeAPI.deleteVideo(targetedId);
|
||||
}
|
||||
error = peertubeAPI.getError();
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
GNUAPI gnuapi;
|
||||
if (account != null)
|
||||
gnuapi = new GNUAPI(contextReference.get(), account.getInstance(), account.getToken());
|
||||
|
|
|
@ -59,7 +59,7 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()));
|
||||
if( isconnected) {
|
||||
if (account == null) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RetrieveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
account = peertubeAPI.getAccount(targetedId);
|
||||
error = peertubeAPI.getError();
|
||||
}else if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
}else if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU|| MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
||||
account = gnuapi.getAccount(targetedId);
|
||||
error = gnuapi.getError();
|
||||
|
|
|
@ -78,13 +78,13 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
protected Void doInBackground(Void... params) {
|
||||
API api = null;
|
||||
GNUAPI gnuapi = null;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
api = new API(this.contextReference.get());
|
||||
else
|
||||
gnuapi = new GNUAPI(this.contextReference.get());
|
||||
switch (action){
|
||||
case REBLOGGED:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
assert api != null;
|
||||
apiResponse = api.getRebloggedBy(targetedId, max_id);
|
||||
}else {
|
||||
|
@ -93,7 +93,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
break;
|
||||
case FAVOURITED:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
assert api != null;
|
||||
apiResponse = api.getFavouritedBy(targetedId, max_id);
|
||||
}else {
|
||||
|
@ -102,7 +102,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
break;
|
||||
case BLOCKED:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
assert api != null;
|
||||
apiResponse = api.getBlocks(max_id);
|
||||
}else {
|
||||
|
@ -111,7 +111,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
break;
|
||||
case MUTED:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
assert api != null;
|
||||
apiResponse = api.getMuted(max_id);
|
||||
}else {
|
||||
|
@ -120,7 +120,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
break;
|
||||
case FOLLOWING:
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
assert api != null;
|
||||
apiResponse = api.getFollowing(targetedId, max_id);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
break;
|
||||
case FOLLOWERS:
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
assert api != null;
|
||||
apiResponse = api.getFollowers(targetedId, max_id);
|
||||
}else {
|
||||
|
|
|
@ -221,7 +221,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
break;
|
||||
case FAVOURITES:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
apiResponse = api.getFavourites(max_id);
|
||||
}else{
|
||||
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
||||
|
@ -236,7 +236,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
apiResponse = api.getPinnedStatuses(targetedID, max_id);
|
||||
else
|
||||
apiResponse = api.getAccountTLStatuses(targetedID, max_id, !showReply);
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
||||
if (showMediaOnly)
|
||||
apiResponse = gnuapi.getStatusWithMedia(targetedID, max_id);
|
||||
|
@ -261,7 +261,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
apiResponse = api.getStatusbyId(targetedID);
|
||||
break;
|
||||
case TAG:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(tag);
|
||||
if (tagTimelines != null && tagTimelines.size() > 0) {
|
||||
TagTimeline tagTimeline = tagTimelines.get(0);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RetrieveManyRelationshipsAsyncTask extends AsyncTask<Void, Void, Vo
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
apiResponse = new API(this.contextReference.get()).getRelationship(accounts);
|
||||
else
|
||||
apiResponse = new GNUAPI(this.contextReference.get()).getRelationship(accounts);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
API api;
|
||||
if (account == null) {
|
||||
api = new API(this.contextReference.get());
|
||||
|
|
|
@ -56,8 +56,9 @@ public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Voi
|
|||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
Account account = new AccountDAO(contextReference.get(), db).getAccountByToken(token);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(contextReference.get()));
|
||||
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername());
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
API api = new API(this.contextReference.get());
|
||||
relationship = api.getRelationship(accountId);
|
||||
error = api.getError();
|
||||
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
||||
relationship = gnuapi.getRelationship(accountId);
|
||||
error = gnuapi.getError();
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.HashMap;
|
|||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.GNUAPI;
|
||||
import fr.gouv.etalab.mastodon.client.HttpsConnection;
|
||||
import fr.gouv.etalab.mastodon.client.PeertubeAPI;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
@ -52,7 +53,8 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
PEERTUBE,
|
||||
PIXELFED,
|
||||
PLEROMA,
|
||||
GNU
|
||||
GNU,
|
||||
FRIENDICA
|
||||
}
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token, String client_id, String client_secret, String refresh_token, String instance, SOCIAL social){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
|
@ -69,7 +71,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
Account account = null;
|
||||
if( social == SOCIAL.MASTODON) {
|
||||
account = new API(this.contextReference.get(), instance, null).verifyCredentials();
|
||||
account.setSocial("MASTODON");
|
||||
account.setSocial(account.getSocial());
|
||||
}else if( social == SOCIAL.PEERTUBE) {
|
||||
try {
|
||||
account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials();
|
||||
|
@ -83,6 +85,9 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.refresh_token = values.get("refresh_token");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
account = new GNUAPI(this.contextReference.get(), instance, null).verifyCredentials();
|
||||
account.setSocial(account.getSocial());
|
||||
}
|
||||
|
||||
if( account == null)
|
||||
|
|
|
@ -26,6 +26,7 @@ import fr.gouv.etalab.mastodon.client.API;
|
|||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.GNUAPI;
|
||||
import fr.gouv.etalab.mastodon.client.HttpsConnection;
|
||||
import fr.gouv.etalab.mastodon.client.PeertubeAPI;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
@ -68,8 +69,8 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
}catch (HttpsConnection.HttpsConnectionException exception){
|
||||
if(exception.getStatusCode() == 401){
|
||||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
account = new AccountDAO(this.contextReference.get(), db).getAccountByToken(token);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(contextReference.get()));
|
||||
account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
HashMap<String, String> values = new PeertubeAPI(this.contextReference.get()).refreshToken(account.getClient_id(), account.getClient_secret(), account.getRefresh_token());
|
||||
if( values != null) {
|
||||
String newtoken = values.get("access_token");
|
||||
|
@ -83,6 +84,8 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
}
|
||||
}
|
||||
|
||||
}else if ( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
account = new GNUAPI(this.contextReference.get()).verifyCredentials();
|
||||
}
|
||||
if( account == null)
|
||||
return null;
|
||||
|
@ -91,6 +94,7 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account);
|
||||
if( userExists) {
|
||||
Account accountDb = new AccountDAO(this.contextReference.get(), db).getAccountByID(userId);
|
||||
|
||||
if( accountDb != null){
|
||||
account.setInstance(accountDb.getInstance());
|
||||
account.setToken(accountDb.getToken());
|
||||
|
|
|
@ -148,7 +148,9 @@ public class API {
|
|||
this.instance = Helper.getLiveInstance(context);
|
||||
else {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(this.prefKeyOauthTokenT);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
if( account == null) {
|
||||
APIError = new Error();
|
||||
APIError.setError(context.getString(R.string.toast_error));
|
||||
|
|
|
@ -96,7 +96,9 @@ public class GNUAPI {
|
|||
this.instance = Helper.getLiveInstance(context);
|
||||
else {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(this.prefKeyOauthTokenT);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
if( account == null) {
|
||||
APIError = new Error();
|
||||
APIError.setError(context.getString(R.string.toast_error));
|
||||
|
@ -182,7 +184,7 @@ public class GNUAPI {
|
|||
public Account verifyCredentials() {
|
||||
account = new Account();
|
||||
try {
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/accounts/verify_credentials"), 60, null, prefKeyOauthTokenT);
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/account/verify_credentials.json"), 60, null, prefKeyOauthTokenT);
|
||||
account = parseAccountResponse(context, new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -238,10 +240,42 @@ public class GNUAPI {
|
|||
|
||||
Relationship relationship = null;
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("target_id",accountId);
|
||||
|
||||
try {
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/friendships/show.json"), 60, params, prefKeyOauthTokenT);
|
||||
relationship = parseRelationshipResponse(new JSONObject(response));
|
||||
String response;
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
params.put("target_id",accountId);
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/friendships/show.json"), 60, params, prefKeyOauthTokenT);
|
||||
relationship = parseRelationshipResponse(new JSONObject(response));
|
||||
}else if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
params.put("target_id",accountId);
|
||||
response = new HttpsConnection(context).get(getAbsoluteUrl("/users/show.json"), 60, params, prefKeyOauthTokenT);
|
||||
JSONObject resobj = new JSONObject(response);
|
||||
try {
|
||||
relationship = new Relationship();
|
||||
relationship.setId(resobj.get("id").toString());
|
||||
relationship.setFollowing(Boolean.valueOf(resobj.get("following").toString()));
|
||||
relationship.setFollowed_by(Boolean.valueOf(resobj.get("follow_request_sent").toString()));
|
||||
relationship.setBlocking(Boolean.valueOf(resobj.get("statusnet_blocking").toString()));
|
||||
try {
|
||||
relationship.setMuting(Boolean.valueOf(resobj.get("muting").toString()));
|
||||
}catch (Exception ignored){
|
||||
relationship.setMuting(false);
|
||||
}
|
||||
try {
|
||||
relationship.setMuting_notifications(!Boolean.valueOf(resobj.get("notifications_enabled").toString()));
|
||||
}catch (Exception ignored){
|
||||
relationship.setMuting_notifications(false);
|
||||
}
|
||||
relationship.setEndorsed(false);
|
||||
relationship.setShowing_reblogs(true);
|
||||
relationship.setRequested(false);
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
return relationship;
|
||||
}
|
||||
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -1435,9 +1469,10 @@ public class GNUAPI {
|
|||
String url = null;
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Current user
|
||||
String currentToken = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(currentToken);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
if(type == DisplayNotificationsFragment.Type.MENTION){
|
||||
params.put("name",account.getAcct());
|
||||
url = getAbsoluteUrl("/statuses/mentions_timeline.json");
|
||||
|
@ -1710,7 +1745,11 @@ public class GNUAPI {
|
|||
Status status = new Status();
|
||||
try {
|
||||
status.setId(resobj.get("id").toString());
|
||||
status.setUri(resobj.get("uri").toString());
|
||||
try {
|
||||
status.setUri(resobj.get("uri").toString());
|
||||
}catch (Exception ignored){
|
||||
status.setUri(resobj.get("id").toString());
|
||||
}
|
||||
status.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString()));
|
||||
status.setIn_reply_to_id(resobj.get("in_reply_to_status_id").toString());
|
||||
status.setIn_reply_to_account_id(resobj.get("in_reply_to_user_id").toString());
|
||||
|
@ -1881,8 +1920,11 @@ public class GNUAPI {
|
|||
account.setHeader("null");
|
||||
account.setHeader_static("null");
|
||||
}
|
||||
account.setSocial("GNU");
|
||||
|
||||
if( resobj.has("cid"))
|
||||
account.setSocial("FRIENDICA");
|
||||
else
|
||||
account.setSocial("GNU");
|
||||
account.setEmojis(new ArrayList<>());
|
||||
} catch (JSONException ignored) {} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1124,9 +1124,11 @@ public class HttpsConnection {
|
|||
else
|
||||
token = tokenUsed;
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(token);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
URL url;
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
url = new URL("https://" + account.getInstance() + "/api/v1/media");
|
||||
else
|
||||
url = new URL("https://" + account.getInstance() + "/api/media/upload.json");
|
||||
|
@ -1152,7 +1154,7 @@ public class HttpsConnection {
|
|||
int lengthSent = pixels.length;
|
||||
lengthSent += (twoHyphens + boundary + lineEnd).getBytes().length;
|
||||
lengthSent += (twoHyphens + boundary + twoHyphens +lineEnd).getBytes().length;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
lengthSent += ("Content-Disposition: form-data; name=\"file\"; filename=\""+fileName+"\"" + lineEnd).getBytes().length;
|
||||
else
|
||||
lengthSent += ("Content-Disposition: form-data; name=\"media\"; filename=\""+fileName+"\"" + lineEnd).getBytes().length;
|
||||
|
@ -1183,7 +1185,7 @@ public class HttpsConnection {
|
|||
DataOutputStream request = new DataOutputStream(httpsURLConnection.getOutputStream());
|
||||
|
||||
request.writeBytes(twoHyphens + boundary + lineEnd);
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\""+fileName+"\"" + lineEnd);
|
||||
else
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"media\"; filename=\""+fileName+"\"" + lineEnd);
|
||||
|
@ -1246,7 +1248,7 @@ public class HttpsConnection {
|
|||
});
|
||||
|
||||
Attachment attachment;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
attachment = API.parseAttachmentResponse(new JSONObject(response));
|
||||
else
|
||||
attachment = GNUAPI.parseUploadedAttachmentResponse(new JSONObject(response));
|
||||
|
@ -1296,7 +1298,9 @@ public class HttpsConnection {
|
|||
else
|
||||
token = tokenUsed;
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(token);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
final URL url = new URL("http://" + account.getInstance() + "/api/v1/media");
|
||||
ByteArrayOutputStream ous = null;
|
||||
try {
|
||||
|
@ -1406,7 +1410,7 @@ public class HttpsConnection {
|
|||
|
||||
|
||||
Attachment attachment;
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
attachment = API.parseAttachmentResponse(new JSONObject(response));
|
||||
else
|
||||
attachment = GNUAPI.parseUploadedAttachmentResponse(new JSONObject(response));
|
||||
|
|
|
@ -97,8 +97,9 @@ public class PeertubeAPI {
|
|||
this.instance = Helper.getLiveInstance(context);
|
||||
else {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(token);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
if( account == null) {
|
||||
apiResponse = new APIResponse();
|
||||
APIError = new Error();
|
||||
|
@ -534,8 +535,9 @@ public class PeertubeAPI {
|
|||
if( e.getStatusCode() == 401){ //Avoid the issue with the refresh token
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
account = new AccountDAO(context, db).getAccountByToken(token);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
HashMap<String, String> values = new PeertubeAPI(context).refreshToken(account.getClient_id(), account.getClient_secret(), account.getRefresh_token());
|
||||
if( values != null) {
|
||||
String newtoken = values.get("access_token");
|
||||
|
|
|
@ -1753,7 +1753,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
|
||||
}
|
||||
}
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
popup.getMenu().findItem(R.id.action_info).setVisible(false);
|
||||
popup.getMenu().findItem(R.id.action_report).setVisible(false);
|
||||
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
|
||||
|
|
|
@ -235,7 +235,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
|
||||
|
||||
//Manage broadcast receiver for Mastodon timelines
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
if( receive_action != null)
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
|
||||
receive_action = new BroadcastReceiver() {
|
||||
|
|
|
@ -784,9 +784,10 @@ public class SettingsFragment extends Fragment {
|
|||
|
||||
|
||||
LinearLayout toot_visibility_container = rootView.findViewById(R.id.toot_visibility_container);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
final Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
final Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
final ImageView set_toot_visibility = rootView.findViewById(R.id.set_toot_visibility);
|
||||
if( theme == Helper.THEME_DARK){
|
||||
changeDrawableColor(context, set_toot_visibility, R.color.dark_text);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
|
||||
TabLayout tabLayout = inflatedView.findViewById(R.id.tabLayout);
|
||||
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.all)));
|
||||
|
||||
TabLayout.Tab tabMention = tabLayout.newTab();
|
||||
|
@ -68,9 +68,10 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
TabLayout.Tab tabFollow = tabLayout.newTab();
|
||||
|
||||
tabMention.setCustomView(R.layout.tab_badge);
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
tabFav.setCustomView(R.layout.tab_badge);
|
||||
tabBoost.setCustomView(R.layout.tab_badge);
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
tabBoost.setCustomView(R.layout.tab_badge);
|
||||
tabFollow.setCustomView(R.layout.tab_badge);
|
||||
|
||||
|
||||
|
@ -90,10 +91,11 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
iconFav.setImageResource(R.drawable.ic_star_notif_tab);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
||||
ImageView iconBoost = tabBoost.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconBoost.setImageResource(R.drawable.ic_repeat_notif_tab);
|
||||
|
||||
ImageView iconBoost =null;
|
||||
if( tabBoost.getCustomView() != null) {
|
||||
iconBoost = tabBoost.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconBoost.setImageResource(R.drawable.ic_repeat_notif_tab);
|
||||
}
|
||||
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
||||
ImageView iconFollow = tabFollow.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconFollow.setImageResource(R.drawable.ic_follow_notif_tab);
|
||||
|
@ -103,7 +105,8 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
tabLayout.addTab(tabMention);
|
||||
if( tabFav.getCustomView() != null)
|
||||
tabLayout.addTab(tabFav);
|
||||
tabLayout.addTab(tabBoost);
|
||||
if( tabBoost.getCustomView() != null)
|
||||
tabLayout.addTab(tabBoost);
|
||||
tabLayout.addTab(tabFollow);
|
||||
|
||||
if (theme == THEME_BLACK)
|
||||
|
@ -115,13 +118,15 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
if( iconFav != null)
|
||||
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
if( iconBoost != null)
|
||||
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
iconFollow.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
if( iconFav != null)
|
||||
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
if( iconBoost != null)
|
||||
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
iconFollow.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
|
@ -174,16 +179,18 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
String tag = "";
|
||||
switch (position) {
|
||||
case 0:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU ) {
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
type = DisplayNotificationsFragment.Type.ALL;
|
||||
}else
|
||||
type = DisplayNotificationsFragment.Type.MENTION;
|
||||
break;
|
||||
case 1:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
type = DisplayNotificationsFragment.Type.MENTION;
|
||||
else
|
||||
else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
type = DisplayNotificationsFragment.Type.BOOST;
|
||||
else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
type = DisplayNotificationsFragment.Type.FOLLOW;
|
||||
break;
|
||||
case 2:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TabLayoutTootsFragment extends Fragment {
|
|||
TabLayout tabLayout = inflatedView.findViewById(R.id.tabLayout);
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.replies)));
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.media)));
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.pinned_toots)));
|
||||
}
|
||||
|
|
|
@ -550,9 +550,11 @@ public class Helper {
|
|||
public static void logoutCurrentUser(Activity activity) {
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Current user
|
||||
String currentToken = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(activity, db).getAccountByToken(currentToken);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(activity));
|
||||
Account account = new AccountDAO(activity, db).getUniqAccount(userId, instance);
|
||||
account.setToken("null");
|
||||
new AccountDAO(activity, db).updateAccount(account);
|
||||
Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
|
||||
|
@ -1370,7 +1372,7 @@ public class Helper {
|
|||
MenuItem itemPCom = menu.findItem(R.id.nav_peertube_comm);
|
||||
if( itemPCom != null)
|
||||
itemPCom.setVisible(false);
|
||||
}else if( BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
|
||||
MenuItem itemCom = menu.findItem(R.id.nav_peertube_comm);
|
||||
if( itemCom != null)
|
||||
itemCom.setVisible(false);
|
||||
|
@ -1378,7 +1380,7 @@ public class Helper {
|
|||
if( itemPFCom != null)
|
||||
itemPFCom.setVisible(false);
|
||||
|
||||
if( BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
if( BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
MenuItem nav_list = menu.findItem(R.id.nav_list);
|
||||
if( nav_list != null)
|
||||
nav_list.setVisible(false);
|
||||
|
@ -2875,7 +2877,7 @@ public class Helper {
|
|||
} catch (Exception ignored) {
|
||||
}
|
||||
return;
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||
try {
|
||||
Glide.with(imageView.getContext())
|
||||
.load(R.drawable.gnu_default_avatar)
|
||||
|
|
|
@ -249,6 +249,21 @@ public class AccountDAO {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an Account by token
|
||||
* @param userId String
|
||||
* @param instance String
|
||||
* @return Account
|
||||
*/
|
||||
public Account getUniqAccount(String userId, String instance){
|
||||
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_USER_ID + " = \"" + userId + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\"", null, null, null, null, "1");
|
||||
return cursorToUser(c);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the current user is already stored in data base
|
||||
|
|
Loading…
Reference in New Issue