Home timeline + fixes
This commit is contained in:
parent
ee3a835660
commit
064a6545d1
|
@ -254,7 +254,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
social = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
|
||||
else if( account.getSocial().equals("PLEROMA"))
|
||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
|
||||
|
||||
else if( account.getSocial().equals("GNU"))
|
||||
social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
||||
countNewStatus = 0;
|
||||
countNewNotifications = 0;
|
||||
|
||||
|
@ -343,7 +344,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) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
TabLayout.Tab tabHome = tabLayout.newTab();
|
||||
TabLayout.Tab tabNotif = tabLayout.newTab();
|
||||
TabLayout.Tab tabDirect = tabLayout.newTab();
|
||||
|
@ -419,47 +420,66 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
tabLayout.addTab(tabHome);
|
||||
tabLayout.addTab(tabNotif);
|
||||
tabPosition.put("home",0);
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.HOME);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.HOME);
|
||||
else
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.GNU_HOME);
|
||||
tabPosition.put("notifications",1);
|
||||
typePosition.put(1, RetrieveFeedsAsyncTask.Type.NOTIFICATION);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
typePosition.put(1, RetrieveFeedsAsyncTask.Type.NOTIFICATION);
|
||||
else
|
||||
typePosition.put(0, RetrieveFeedsAsyncTask.Type.GNU_NOTIFICATION);
|
||||
int i = 2;
|
||||
if( display_direct) {
|
||||
tabLayout.addTab(tabDirect);
|
||||
tabPosition.put("direct",i);
|
||||
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU ) {
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.6");
|
||||
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.CONVERSATION);
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.6");
|
||||
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.CONVERSATION);
|
||||
} else {
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||
}
|
||||
} else {
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||
}
|
||||
}else{
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_DM);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if( display_local) {
|
||||
tabLayout.addTab(tabLocal);
|
||||
tabPosition.put("local", i);
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.LOCAL);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.LOCAL);
|
||||
else
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_LOCAL);
|
||||
i++;
|
||||
}
|
||||
if( display_global) {
|
||||
tabLayout.addTab(tabPublic);
|
||||
tabPosition.put("global", i);
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||
else
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_WHOLE);
|
||||
i++;
|
||||
}
|
||||
if( display_art) {
|
||||
tabLayout.addTab(tabArt);
|
||||
tabPosition.put("art", i);
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.ART);
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.ART);
|
||||
else
|
||||
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_ART);
|
||||
}
|
||||
|
||||
if( (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE)
|
||||
|
@ -1084,10 +1104,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
startSreaming();
|
||||
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
Helper.refreshSearchTag(BaseMainActivity.this, tabLayout, adapter);
|
||||
int tabCount = tabLayout.getTabCount();
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
for( int j = countPage ; j < tabCount ; j++){
|
||||
attacheDelete(j);
|
||||
}
|
||||
|
@ -1207,7 +1227,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
|
||||
tabLayout.getTabAt(0).select();
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
toot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -1491,7 +1511,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)){
|
||||
if(!popupShown && (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU)){
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.popup_quick_settings, null);
|
||||
|
@ -1531,7 +1551,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
mamageNewIntent(getIntent());
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
|
||||
// Retrieves instance
|
||||
new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
@ -2430,14 +2450,14 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
|
||||
public void removeTabPage() {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
this.mNumOfTabs--;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void addTabPage(String title) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
TabLayout.Tab tab = tabLayout.newTab();
|
||||
tab.setText(title);
|
||||
this.mNumOfTabs++;
|
||||
|
@ -2447,7 +2467,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
//Remove the search bar
|
||||
if (!toolbar_search.isIconified()) {
|
||||
toolbarTitle.setVisibility(View.VISIBLE);
|
||||
|
@ -2459,7 +2479,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
Bundle bundle = new Bundle();
|
||||
if (position == 0) {
|
||||
homeFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME);
|
||||
if(social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME);
|
||||
else
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.GNU_HOME);
|
||||
homeFragment.setArguments(bundle);
|
||||
return homeFragment;
|
||||
} else if (position == 1) {
|
||||
|
@ -2560,7 +2583,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) {
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
|
||||
// save the appropriate reference depending on position
|
||||
if (position == 0) {
|
||||
|
|
|
@ -238,7 +238,6 @@ public class LoginActivity extends BaseActivity {
|
|||
case R.id.set_gnu:
|
||||
login_uid.setHint(R.string.username);
|
||||
connectionButton.setEnabled(true);
|
||||
connectionButton.setClickable(true);
|
||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
||||
break;
|
||||
}
|
||||
|
@ -446,112 +445,111 @@ public class LoginActivity extends BaseActivity {
|
|||
super.onResume();
|
||||
|
||||
if (login_instance != null &&login_instance.getText() != null && login_instance.getText().toString().length() > 0 && client_id_for_webview) {
|
||||
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
connectionButton.setEnabled(false);
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
}
|
||||
connectionButton.setEnabled(false);
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
}
|
||||
}
|
||||
|
||||
private void retrievesClientId(){
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
return;
|
||||
String instanceFromField = login_instance.getText().toString().trim();
|
||||
final String[] host = new String[1];
|
||||
|
||||
|
||||
try {
|
||||
URL url = new URL(instanceFromField);
|
||||
host[0] = url.getHost();
|
||||
} catch (MalformedURLException e) {
|
||||
host[0] = instanceFromField;
|
||||
}
|
||||
try {
|
||||
instance = URLEncoder.encode(host[0], "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Toasty.error(LoginActivity.this,getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
|
||||
actionToken = "/api/v1/apps";
|
||||
else
|
||||
actionToken = "/api/v1/oauth-clients/local";
|
||||
final HashMap<String, String> parameters = new HashMap<>();
|
||||
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
|
||||
parameters.put(Helper.REDIRECT_URIS, client_id_for_webview?Helper.REDIRECT_CONTENT_WEB:Helper.REDIRECT_CONTENT);
|
||||
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
||||
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES);
|
||||
}else {
|
||||
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
|
||||
}
|
||||
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
String instanceFromField = login_instance.getText().toString().trim();
|
||||
String host = instanceFromField;
|
||||
|
||||
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
|
||||
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String response;
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
|
||||
response = new HttpsConnection(LoginActivity.this).post(Helper.instanceWithProtocol(instance) + actionToken, 30, parameters, null );
|
||||
else
|
||||
response = new HttpsConnection(LoginActivity.this).get(Helper.instanceWithProtocol(instance) + actionToken, 30, parameters, null );
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
client_id = resobj.get(Helper.CLIENT_ID).toString();
|
||||
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
||||
String id = null;
|
||||
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
|
||||
id = resobj.get(Helper.ID).toString();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.CLIENT_ID, client_id);
|
||||
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
||||
editor.putString(Helper.ID, id);
|
||||
editor.apply();
|
||||
connectionButton.setEnabled(true);
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
login_two_step.setVisibility(View.VISIBLE);
|
||||
info_2FA.setVisibility(View.VISIBLE);
|
||||
showCase2FA(true);
|
||||
}
|
||||
if( client_id_for_webview){
|
||||
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
|
||||
if( embedded_browser) {
|
||||
Intent i = new Intent(LoginActivity.this, WebviewConnectActivity.class);
|
||||
i.putExtra("social", socialNetwork);
|
||||
i.putExtra("instance", instance);
|
||||
startActivity(i);
|
||||
}else{
|
||||
String url = redirectUserToAuthorizeAndLogin(client_id, instance);
|
||||
Helper.openBrowser(LoginActivity.this, url);
|
||||
}
|
||||
}
|
||||
} catch (JSONException ignored) {ignored.printStackTrace();}
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
String message;
|
||||
if( e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
|
||||
message = e.getLocalizedMessage();
|
||||
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
|
||||
message = e.getMessage();
|
||||
else
|
||||
message = getString(R.string.client_error);
|
||||
Toasty.error(getApplicationContext(), message,Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
try {
|
||||
URL url = new URL(instanceFromField);
|
||||
host = url.getHost();
|
||||
} catch (MalformedURLException e) { }
|
||||
try {
|
||||
instance = URLEncoder.encode(host, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Toasty.error(LoginActivity.this,getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
|
||||
actionToken = "/api/v1/apps";
|
||||
else
|
||||
actionToken = "/api/v1/oauth-clients/local";
|
||||
final HashMap<String, String> parameters = new HashMap<>();
|
||||
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
|
||||
parameters.put(Helper.REDIRECT_URIS, client_id_for_webview?Helper.REDIRECT_CONTENT_WEB:Helper.REDIRECT_CONTENT);
|
||||
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
||||
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES);
|
||||
}else {
|
||||
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
|
||||
}
|
||||
}).start();
|
||||
|
||||
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
|
||||
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String response;
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
|
||||
response = new HttpsConnection(LoginActivity.this).post(Helper.instanceWithProtocol(instance) + actionToken, 30, parameters, null );
|
||||
else
|
||||
response = new HttpsConnection(LoginActivity.this).get(Helper.instanceWithProtocol(instance) + actionToken, 30, parameters, null );
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
client_id = resobj.get(Helper.CLIENT_ID).toString();
|
||||
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
||||
String id = null;
|
||||
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
|
||||
id = resobj.get(Helper.ID).toString();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.CLIENT_ID, client_id);
|
||||
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
||||
editor.putString(Helper.ID, id);
|
||||
editor.apply();
|
||||
connectionButton.setEnabled(true);
|
||||
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
login_two_step.setVisibility(View.VISIBLE);
|
||||
info_2FA.setVisibility(View.VISIBLE);
|
||||
showCase2FA(true);
|
||||
}
|
||||
if( client_id_for_webview){
|
||||
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
|
||||
if( embedded_browser) {
|
||||
Intent i = new Intent(LoginActivity.this, WebviewConnectActivity.class);
|
||||
i.putExtra("social", socialNetwork);
|
||||
i.putExtra("instance", instance);
|
||||
startActivity(i);
|
||||
}else{
|
||||
String url = redirectUserToAuthorizeAndLogin(client_id, instance);
|
||||
Helper.openBrowser(LoginActivity.this, url);
|
||||
}
|
||||
}
|
||||
} catch (JSONException ignored) {ignored.printStackTrace();}
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
String message;
|
||||
if( e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
|
||||
message = e.getLocalizedMessage();
|
||||
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
|
||||
message = e.getMessage();
|
||||
else
|
||||
message = getString(R.string.client_error);
|
||||
Toasty.error(getApplicationContext(), message,Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}else{
|
||||
connectionButton.setEnabled(true);
|
||||
}
|
||||
connectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -588,14 +586,15 @@ public class LoginActivity extends BaseActivity {
|
|||
oauthUrl = "/api/v1/users/token";
|
||||
}else if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
String instanceFromField = login_instance.getText().toString().trim();
|
||||
String host;
|
||||
try {
|
||||
URL url = new URL(instanceFromField);
|
||||
host[0] = url.getHost();
|
||||
host = url.getHost();
|
||||
} catch (MalformedURLException e) {
|
||||
host[0] = instanceFromField;
|
||||
host = instanceFromField;
|
||||
}
|
||||
try {
|
||||
instance = URLEncoder.encode(host[0], "utf-8");
|
||||
instance = URLEncoder.encode(host, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
String username = login_uid.getText().toString().trim().toLowerCase();
|
||||
|
|
|
@ -27,6 +27,7 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
|
||||
import fr.gouv.etalab.mastodon.client.GNUAPI;
|
||||
import fr.gouv.etalab.mastodon.client.PeertubeAPI;
|
||||
import fr.gouv.etalab.mastodon.helper.FilterToots;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||
|
@ -72,13 +73,10 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
ONESTATUS,
|
||||
CONTEXT,
|
||||
TAG,
|
||||
CACHE_BOOKMARKS,
|
||||
CACHE_BOOKMARKS_PEERTUBE,
|
||||
CACHE_STATUS,
|
||||
REMOTE_INSTANCE,
|
||||
ART,
|
||||
NOTIFICATION,
|
||||
PIXELFED,
|
||||
|
||||
PSUBSCRIPTIONS,
|
||||
POVERVIEW,
|
||||
PTRENDING,
|
||||
|
@ -87,11 +85,27 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
PLOCAL,
|
||||
CHANNEL,
|
||||
MYVIDEOS,
|
||||
|
||||
PIXELFED,
|
||||
PF_HOME,
|
||||
PF_LOCAL,
|
||||
PF_DISCOVER,
|
||||
PF_NOTIFICATION,
|
||||
SCHEDULED_TOOTS
|
||||
|
||||
|
||||
GNU_HOME,
|
||||
GNU_LOCAL,
|
||||
GNU_WHOLE,
|
||||
GNU_NOTIFICATION,
|
||||
GNU_DM,
|
||||
GNU_ART,
|
||||
GNU_TAG,
|
||||
|
||||
SCHEDULED_TOOTS,
|
||||
CACHE_BOOKMARKS,
|
||||
CACHE_BOOKMARKS_PEERTUBE,
|
||||
CACHE_STATUS,
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -314,6 +328,23 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
break;
|
||||
case HASHTAG:
|
||||
break;
|
||||
|
||||
case GNU_HOME:
|
||||
GNUAPI gnuAPI = new GNUAPI(this.contextReference.get());
|
||||
apiResponse = gnuAPI.getHomeTimeline(max_id);
|
||||
break;
|
||||
case GNU_LOCAL:
|
||||
gnuAPI = new GNUAPI(this.contextReference.get());
|
||||
break;
|
||||
case GNU_WHOLE:
|
||||
gnuAPI = new GNUAPI(this.contextReference.get());
|
||||
break;
|
||||
case GNU_NOTIFICATION:
|
||||
gnuAPI = new GNUAPI(this.contextReference.get());
|
||||
break;
|
||||
case GNU_DM:
|
||||
gnuAPI = new GNUAPI(this.contextReference.get());
|
||||
break;
|
||||
}
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
List<String> bookmarks = new StatusCacheDAO(contextReference.get(), db).getAllStatusId(StatusCacheDAO.BOOKMARK_CACHE);
|
||||
|
|
|
@ -53,6 +53,8 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_OAUTH_TOKEN;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 02/02/2019.
|
||||
|
@ -88,7 +90,7 @@ public class GNUAPI {
|
|||
tootPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40);
|
||||
accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40);
|
||||
notificationPerPage = sharedpreferences.getInt(Helper.SET_NOTIFICATIONS_PER_PAGE, 15);
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
if( Helper.getLiveInstance(context) != null)
|
||||
this.instance = Helper.getLiveInstance(context);
|
||||
else {
|
||||
|
@ -124,7 +126,7 @@ public class GNUAPI {
|
|||
if( token != null)
|
||||
this.prefKeyOauthTokenT = token;
|
||||
else
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
apiResponse = new APIResponse();
|
||||
APIError = null;
|
||||
}
|
||||
|
@ -689,16 +691,18 @@ public class GNUAPI {
|
|||
params.put("min_id", min_id);
|
||||
if (0 > limit || limit > 80)
|
||||
limit = 80;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Current user
|
||||
statuses = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/timelines/home"), 60, params, prefKeyOauthTokenT);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/statuses/home_timeline.json"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
|
@ -780,10 +784,7 @@ public class GNUAPI {
|
|||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String url;
|
||||
if( instanceName == null)
|
||||
url = getAbsoluteUrl("/timelines/public");
|
||||
else
|
||||
url = getAbsoluteUrlRemoteInstance(instanceName);
|
||||
url = getAbsoluteUrl("/timelines/public");
|
||||
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
|
@ -804,60 +805,6 @@ public class GNUAPI {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves discover timeline for the account *synchronously*
|
||||
* @param local boolean only local timeline
|
||||
* @param max_id String id max
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getDiscoverTimeline(boolean local, String max_id){
|
||||
return getDiscoverTimeline(local, max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves discover timeline for the account *synchronously*
|
||||
* @param local boolean only local timeline
|
||||
* @param max_id String id max
|
||||
* @param since_id String since the id
|
||||
* @param limit int limit - max value 40
|
||||
* @return APIResponse
|
||||
*/
|
||||
private APIResponse getDiscoverTimeline(boolean local, String max_id, String since_id, int limit){
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if( local)
|
||||
params.put("local", Boolean.toString(true));
|
||||
if( max_id != null )
|
||||
params.put("max_id", max_id);
|
||||
if( since_id != null )
|
||||
params.put("since_id", since_id);
|
||||
if( 0 > limit || limit > 40)
|
||||
limit = 40;
|
||||
params.put("limit",String.valueOf(limit));
|
||||
statuses = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String url;
|
||||
url = getAbsoluteUr2l("/discover/posts");
|
||||
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1815,15 +1762,18 @@ public class GNUAPI {
|
|||
status.setSensitive(false);
|
||||
status.setSpoiler_text(null);
|
||||
status.setVisibility("public");
|
||||
status.setLanguage(resobj.get("geo").toString());
|
||||
status.setLanguage(resobj.isNull("geo")?null:resobj.getString("geo"));
|
||||
status.setUrl(resobj.get("external_url").toString());
|
||||
//Retrieves attachments
|
||||
JSONArray arrayAttachement = resobj.getJSONArray("attachments");
|
||||
|
||||
ArrayList<Attachment> attachments = new ArrayList<>(parseAttachmentResponse(arrayAttachement));
|
||||
try {
|
||||
JSONArray arrayAttachement = resobj.getJSONArray("attachments");
|
||||
ArrayList<Attachment> attachments = new ArrayList<>(parseAttachmentResponse(arrayAttachement));
|
||||
status.setMedia_attachments(attachments);
|
||||
}catch (Exception ignored){ status.setMedia_attachments(new ArrayList<>());}
|
||||
|
||||
status.setCard(null);
|
||||
status.setMedia_attachments(attachments);
|
||||
|
||||
//Retrieves mentions
|
||||
List<Mention> mentions = new ArrayList<>();
|
||||
JSONArray arrayMention = resobj.getJSONArray("attentions");
|
||||
|
@ -1848,13 +1798,13 @@ public class GNUAPI {
|
|||
try {
|
||||
if(resobj.getJSONObject("source") != null){
|
||||
application.setName(resobj.getJSONObject("source").toString());
|
||||
application.setWebsite(null);
|
||||
application.setWebsite(resobj.getJSONObject("source_link").toString());
|
||||
}
|
||||
}catch (Exception e){
|
||||
application = new Application();
|
||||
}
|
||||
status.setApplication(application);
|
||||
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
|
||||
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("user")));
|
||||
status.setContent(resobj.get("statusnet_html").toString());
|
||||
status.setFavourites_count(Integer.valueOf(resobj.get("fave_num").toString()));
|
||||
status.setReblogs_count(Integer.valueOf(resobj.get("repeat_num").toString()));
|
||||
|
@ -1873,8 +1823,8 @@ public class GNUAPI {
|
|||
status.setPinned(false);
|
||||
try{
|
||||
status.setReblog(parseStatuses(context, resobj.getJSONObject("retweeted_status")));
|
||||
}catch (Exception ignored){}
|
||||
} catch (JSONException ignored) {} catch (ParseException e) {
|
||||
}catch (Exception ignored){ status.setReblog(null);}
|
||||
} catch (JSONException ignored) {ignored.printStackTrace();} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return status;
|
||||
|
@ -2176,17 +2126,7 @@ public class GNUAPI {
|
|||
|
||||
|
||||
private String getAbsoluteUrl(String action) {
|
||||
return Helper.instanceWithProtocol(this.instance) + "/api/v1" + action;
|
||||
}
|
||||
private String getAbsoluteUr2l(String action) {
|
||||
return Helper.instanceWithProtocol(this.instance) + "/api/v2" + action;
|
||||
}
|
||||
private String getAbsoluteUrlRemote(String remote, String action) {
|
||||
return "https://" + remote + "/api/v1" + action;
|
||||
}
|
||||
|
||||
private String getAbsoluteUrlRemoteInstance(String instanceName) {
|
||||
return "https://" + instanceName + "/api/v1/timelines/public?local=true";
|
||||
return Helper.instanceWithProtocol(this.instance) + "/api" + action;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if( receive_action != null)
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
|
||||
receive_action = new BroadcastReceiver() {
|
||||
|
|
|
@ -599,14 +599,18 @@ public class Helper {
|
|||
//noinspection deprecation
|
||||
userLocale = context.getResources().getConfiguration().locale;
|
||||
}
|
||||
final String STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||
String STRING_DATE_FORMAT;
|
||||
if( !date.contains("+"))
|
||||
STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||
else //GNU date format
|
||||
STRING_DATE_FORMAT = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, userLocale);
|
||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
|
||||
simpleDateFormat.setLenient(true);
|
||||
try {
|
||||
return simpleDateFormat.parse(date);
|
||||
}catch (Exception e){
|
||||
String newdate = date.split("\\+")[0];
|
||||
String newdate = date.split("\\+")[0].trim();
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", userLocale);
|
||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
|
||||
simpleDateFormat.setLenient(true);
|
||||
|
@ -2801,7 +2805,7 @@ public class Helper {
|
|||
if( url != null && url.startsWith("/")){
|
||||
url = Helper.getLiveInstanceWithProtocol(context) + url;
|
||||
}
|
||||
if( url == null || url.equals("null") || url.contains("missing.png") || url.contains(".svg")) {
|
||||
if( url == null || url.equals("null")|| url.equals("false") || url.contains("missing.png") || url.contains(".svg")) {
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
try {
|
||||
Glide.with(imageView.getContext())
|
||||
|
@ -2820,6 +2824,15 @@ public class Helper {
|
|||
} catch (Exception ignored) {
|
||||
}
|
||||
return;
|
||||
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU){
|
||||
try {
|
||||
Glide.with(imageView.getContext())
|
||||
.load(R.drawable.gnu_default_avatar)
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
.into(imageView);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( !disableGif)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
Loading…
Reference in New Issue