Home timeline + fixes

This commit is contained in:
stom79 2019-02-03 09:27:02 +01:00
parent ee3a835660
commit 064a6545d1
7 changed files with 222 additions and 216 deletions

View File

@ -254,7 +254,8 @@ public abstract class BaseMainActivity extends BaseActivity
social = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED; social = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
else if( account.getSocial().equals("PLEROMA")) else if( account.getSocial().equals("PLEROMA"))
social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA; social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
else if( account.getSocial().equals("GNU"))
social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
countNewStatus = 0; countNewStatus = 0;
countNewNotifications = 0; countNewNotifications = 0;
@ -343,7 +344,7 @@ public abstract class BaseMainActivity extends BaseActivity
delete_all = findViewById(R.id.delete_all); delete_all = findViewById(R.id.delete_all);
add_new = findViewById(R.id.add_new); 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 tabHome = tabLayout.newTab();
TabLayout.Tab tabNotif = tabLayout.newTab(); TabLayout.Tab tabNotif = tabLayout.newTab();
TabLayout.Tab tabDirect = tabLayout.newTab(); TabLayout.Tab tabDirect = tabLayout.newTab();
@ -419,47 +420,66 @@ public abstract class BaseMainActivity extends BaseActivity
tabLayout.addTab(tabHome); tabLayout.addTab(tabHome);
tabLayout.addTab(tabNotif); tabLayout.addTab(tabNotif);
tabPosition.put("home",0); 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); 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; int i = 2;
if( display_direct) { if( display_direct) {
tabLayout.addTab(tabDirect); tabLayout.addTab(tabDirect);
tabPosition.put("direct",i); tabPosition.put("direct",i);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU ) {
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext())); 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); String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
if (instanceVersion != null) { if (instanceVersion != null) {
Version currentVersion = new Version(instanceVersion); Version currentVersion = new Version(instanceVersion);
Version minVersion = new Version("2.6"); Version minVersion = new Version("2.6");
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) { if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
typePosition.put(i, RetrieveFeedsAsyncTask.Type.CONVERSATION); typePosition.put(i, RetrieveFeedsAsyncTask.Type.CONVERSATION);
} else {
typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT);
}
} else { } else {
typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT); typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT);
} }
}else{ }else{
typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT); typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_DM);
} }
i++; i++;
} }
if( display_local) { if( display_local) {
tabLayout.addTab(tabLocal); tabLayout.addTab(tabLocal);
tabPosition.put("local", i); 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++; i++;
} }
if( display_global) { if( display_global) {
tabLayout.addTab(tabPublic); tabLayout.addTab(tabPublic);
tabPosition.put("global", i); 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++; i++;
} }
if( display_art) { if( display_art) {
tabLayout.addTab(tabArt); tabLayout.addTab(tabArt);
tabPosition.put("art", i); 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) if( (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE)
@ -1084,10 +1104,10 @@ public abstract class BaseMainActivity extends BaseActivity
startSreaming(); 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); Helper.refreshSearchTag(BaseMainActivity.this, tabLayout, adapter);
int tabCount = tabLayout.getTabCount(); 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++){ for( int j = countPage ; j < tabCount ; j++){
attacheDelete(j); attacheDelete(j);
} }
@ -1207,7 +1227,7 @@ public abstract class BaseMainActivity extends BaseActivity
tabLayout.getTabAt(0).select(); 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() { toot.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -1491,7 +1511,7 @@ public abstract class BaseMainActivity extends BaseActivity
// Asked once for notification opt-in // Asked once for notification opt-in
boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false); 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); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style);
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.popup_quick_settings, null); @SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.popup_quick_settings, null);
@ -1531,7 +1551,7 @@ public abstract class BaseMainActivity extends BaseActivity
mamageNewIntent(getIntent()); 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 // Retrieves instance
new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -2430,14 +2450,14 @@ public abstract class BaseMainActivity extends BaseActivity
} }
public void removeTabPage() { 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--; this.mNumOfTabs--;
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }
public void addTabPage(String title) { 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(); TabLayout.Tab tab = tabLayout.newTab();
tab.setText(title); tab.setText(title);
this.mNumOfTabs++; this.mNumOfTabs++;
@ -2447,7 +2467,7 @@ public abstract class BaseMainActivity extends BaseActivity
@Override @Override
public Fragment getItem(int position) { 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 //Remove the search bar
if (!toolbar_search.isIconified()) { if (!toolbar_search.isIconified()) {
toolbarTitle.setVisibility(View.VISIBLE); toolbarTitle.setVisibility(View.VISIBLE);
@ -2459,7 +2479,10 @@ public abstract class BaseMainActivity extends BaseActivity
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (position == 0) { if (position == 0) {
homeFragment = new DisplayStatusFragment(); 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); homeFragment.setArguments(bundle);
return homeFragment; return homeFragment;
} else if (position == 1) { } else if (position == 1) {
@ -2560,7 +2583,7 @@ public abstract class BaseMainActivity extends BaseActivity
public Object instantiateItem(@NonNull ViewGroup container, int position) { public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position); Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
registeredFragments.put(position, createdFragment); 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 // save the appropriate reference depending on position
if (position == 0) { if (position == 0) {

View File

@ -238,7 +238,6 @@ public class LoginActivity extends BaseActivity {
case R.id.set_gnu: case R.id.set_gnu:
login_uid.setHint(R.string.username); login_uid.setHint(R.string.username);
connectionButton.setEnabled(true); connectionButton.setEnabled(true);
connectionButton.setClickable(true);
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU; socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
break; break;
} }
@ -446,112 +445,111 @@ public class LoginActivity extends BaseActivity {
super.onResume(); super.onResume();
if (login_instance != null &&login_instance.getText() != null && login_instance.getText().toString().length() > 0 && client_id_for_webview) { 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);
connectionButton.setEnabled(false); client_id_for_webview = false;
client_id_for_webview = false; retrievesClientId();
retrievesClientId();
}
} }
} }
private void retrievesClientId(){ private void retrievesClientId(){
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU)
return;
String instanceFromField = login_instance.getText().toString().trim();
final String[] host = new String[1];
try { if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU){
URL url = new URL(instanceFromField); String instanceFromField = login_instance.getText().toString().trim();
host[0] = url.getHost(); String host = instanceFromField;
} 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);
}
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
new Thread(new Runnable(){ try {
@Override URL url = new URL(instanceFromField);
public void run() { host = url.getHost();
try { } catch (MalformedURLException e) { }
String response; try {
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) instance = URLEncoder.encode(host, "utf-8");
response = new HttpsConnection(LoginActivity.this).post(Helper.instanceWithProtocol(instance) + actionToken, 30, parameters, null ); } catch (UnsupportedEncodingException e) {
else Toasty.error(LoginActivity.this,getString(R.string.client_error), Toast.LENGTH_LONG).show();
response = new HttpsConnection(LoginActivity.this).get(Helper.instanceWithProtocol(instance) + actionToken, 30, parameters, null ); }
if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
runOnUiThread(new Runnable() { actionToken = "/api/v1/apps";
public void run() { else
JSONObject resobj; actionToken = "/api/v1/oauth-clients/local";
try { final HashMap<String, String> parameters = new HashMap<>();
resobj = new JSONObject(response); parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
client_id = resobj.get(Helper.CLIENT_ID).toString(); parameters.put(Helper.REDIRECT_URIS, client_id_for_webview?Helper.REDIRECT_CONTENT_WEB:Helper.REDIRECT_CONTENT);
client_secret = resobj.get(Helper.CLIENT_SECRET).toString(); if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
String id = null; parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES);
if( socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) }else {
id = resobj.get(Helper.ID).toString(); parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
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();
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() { connectionButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -588,14 +586,15 @@ public class LoginActivity extends BaseActivity {
oauthUrl = "/api/v1/users/token"; oauthUrl = "/api/v1/users/token";
}else if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU) { }else if( socialNetwork == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
String instanceFromField = login_instance.getText().toString().trim(); String instanceFromField = login_instance.getText().toString().trim();
String host;
try { try {
URL url = new URL(instanceFromField); URL url = new URL(instanceFromField);
host[0] = url.getHost(); host = url.getHost();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
host[0] = instanceFromField; host = instanceFromField;
} }
try { try {
instance = URLEncoder.encode(host[0], "utf-8"); instance = URLEncoder.encode(host, "utf-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
} }
String username = login_uid.getText().toString().trim().toLowerCase(); String username = login_uid.getText().toString().trim().toLowerCase();

View File

@ -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.Peertube;
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance; import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline; 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.client.PeertubeAPI;
import fr.gouv.etalab.mastodon.helper.FilterToots; import fr.gouv.etalab.mastodon.helper.FilterToots;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
@ -72,13 +73,10 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
ONESTATUS, ONESTATUS,
CONTEXT, CONTEXT,
TAG, TAG,
CACHE_BOOKMARKS,
CACHE_BOOKMARKS_PEERTUBE,
CACHE_STATUS,
REMOTE_INSTANCE, REMOTE_INSTANCE,
ART, ART,
NOTIFICATION, NOTIFICATION,
PIXELFED,
PSUBSCRIPTIONS, PSUBSCRIPTIONS,
POVERVIEW, POVERVIEW,
PTRENDING, PTRENDING,
@ -87,11 +85,27 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
PLOCAL, PLOCAL,
CHANNEL, CHANNEL,
MYVIDEOS, MYVIDEOS,
PIXELFED,
PF_HOME, PF_HOME,
PF_LOCAL, PF_LOCAL,
PF_DISCOVER, PF_DISCOVER,
PF_NOTIFICATION, 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; break;
case HASHTAG: case HASHTAG:
break; 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) { if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
List<String> bookmarks = new StatusCacheDAO(contextReference.get(), db).getAllStatusId(StatusCacheDAO.BOOKMARK_CACHE); List<String> bookmarks = new StatusCacheDAO(contextReference.get(), db).getAllStatusId(StatusCacheDAO.BOOKMARK_CACHE);

View File

@ -53,6 +53,8 @@ import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite; 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. * Created by Thomas on 02/02/2019.
@ -88,7 +90,7 @@ public class GNUAPI {
tootPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40); tootPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40);
accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40); accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40);
notificationPerPage = sharedpreferences.getInt(Helper.SET_NOTIFICATIONS_PER_PAGE, 15); 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) if( Helper.getLiveInstance(context) != null)
this.instance = Helper.getLiveInstance(context); this.instance = Helper.getLiveInstance(context);
else { else {
@ -124,7 +126,7 @@ public class GNUAPI {
if( token != null) if( token != null)
this.prefKeyOauthTokenT = token; this.prefKeyOauthTokenT = token;
else else
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); this.prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
apiResponse = new APIResponse(); apiResponse = new APIResponse();
APIError = null; APIError = null;
} }
@ -689,16 +691,18 @@ public class GNUAPI {
params.put("min_id", min_id); params.put("min_id", min_id);
if (0 > limit || limit > 80) if (0 > limit || limit > 80)
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<>(); statuses = new ArrayList<>();
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context); 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.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id()); apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
@ -780,10 +784,7 @@ public class GNUAPI {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context); HttpsConnection httpsConnection = new HttpsConnection(context);
String url; String url;
if( instanceName == null) url = getAbsoluteUrl("/timelines/public");
url = getAbsoluteUrl("/timelines/public");
else
url = getAbsoluteUrlRemoteInstance(instanceName);
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT); String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_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.setSensitive(false);
status.setSpoiler_text(null); status.setSpoiler_text(null);
status.setVisibility("public"); 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()); status.setUrl(resobj.get("external_url").toString());
//Retrieves attachments //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.setCard(null);
status.setMedia_attachments(attachments);
//Retrieves mentions //Retrieves mentions
List<Mention> mentions = new ArrayList<>(); List<Mention> mentions = new ArrayList<>();
JSONArray arrayMention = resobj.getJSONArray("attentions"); JSONArray arrayMention = resobj.getJSONArray("attentions");
@ -1848,13 +1798,13 @@ public class GNUAPI {
try { try {
if(resobj.getJSONObject("source") != null){ if(resobj.getJSONObject("source") != null){
application.setName(resobj.getJSONObject("source").toString()); application.setName(resobj.getJSONObject("source").toString());
application.setWebsite(null); application.setWebsite(resobj.getJSONObject("source_link").toString());
} }
}catch (Exception e){ }catch (Exception e){
application = new Application(); application = new Application();
} }
status.setApplication(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.setContent(resobj.get("statusnet_html").toString());
status.setFavourites_count(Integer.valueOf(resobj.get("fave_num").toString())); status.setFavourites_count(Integer.valueOf(resobj.get("fave_num").toString()));
status.setReblogs_count(Integer.valueOf(resobj.get("repeat_num").toString())); status.setReblogs_count(Integer.valueOf(resobj.get("repeat_num").toString()));
@ -1873,8 +1823,8 @@ public class GNUAPI {
status.setPinned(false); status.setPinned(false);
try{ try{
status.setReblog(parseStatuses(context, resobj.getJSONObject("retweeted_status"))); status.setReblog(parseStatuses(context, resobj.getJSONObject("retweeted_status")));
}catch (Exception ignored){} }catch (Exception ignored){ status.setReblog(null);}
} catch (JSONException ignored) {} catch (ParseException e) { } catch (JSONException ignored) {ignored.printStackTrace();} catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
return status; return status;
@ -2176,17 +2126,7 @@ public class GNUAPI {
private String getAbsoluteUrl(String action) { private String getAbsoluteUrl(String action) {
return Helper.instanceWithProtocol(this.instance) + "/api/v1" + action; return Helper.instanceWithProtocol(this.instance) + "/api" + 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";
} }

View File

@ -235,7 +235,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//Manage broadcast receiver for Mastodon timelines //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) if( receive_action != null)
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action); LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
receive_action = new BroadcastReceiver() { receive_action = new BroadcastReceiver() {

View File

@ -599,14 +599,18 @@ public class Helper {
//noinspection deprecation //noinspection deprecation
userLocale = context.getResources().getConfiguration().locale; 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 simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, userLocale);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
simpleDateFormat.setLenient(true); simpleDateFormat.setLenient(true);
try { try {
return simpleDateFormat.parse(date); return simpleDateFormat.parse(date);
}catch (Exception e){ }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 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", userLocale);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
simpleDateFormat.setLenient(true); simpleDateFormat.setLenient(true);
@ -2801,7 +2805,7 @@ public class Helper {
if( url != null && url.startsWith("/")){ if( url != null && url.startsWith("/")){
url = Helper.getLiveInstanceWithProtocol(context) + url; 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) { if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
try { try {
Glide.with(imageView.getContext()) Glide.with(imageView.getContext())
@ -2820,6 +2824,15 @@ public class Helper {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
return; 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) if( !disableGif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB