Improvements with Friendica and GNU

This commit is contained in:
stom79 2019-02-08 19:13:40 +01:00
parent 70010afa92
commit 3c9c0a2057
6 changed files with 179 additions and 127 deletions

View File

@ -258,7 +258,6 @@ public abstract class BaseMainActivity extends BaseActivity
social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
else if( account.getSocial().equals("FRIENDICA"))
social = UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA;
Log.v(Helper.TAG, account.getSocial());
countNewStatus = 0;
countNewNotifications = 0;
@ -469,6 +468,8 @@ public abstract class BaseMainActivity extends BaseActivity
typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_LOCAL);
i++;
}
if( social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
display_global = false;
if( display_global) {
tabLayout.addTab(tabPublic);
tabPosition.put("global", i);
@ -590,7 +591,7 @@ public abstract class BaseMainActivity extends BaseActivity
countPage++;
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
countPage++;
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true) && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA )
countPage++;
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true)&& social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
countPage++;
@ -1124,7 +1125,7 @@ public abstract class BaseMainActivity extends BaseActivity
query= query.replaceAll("^#+", "");
//It's not a peertube search
if(displayPeertube == null){
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
intent.putExtra("search", query);
startActivity(intent);

View File

@ -616,77 +616,78 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
}
});
toot_content.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if( toot_content.getSelectionStart() != 0)
currentCursorPosition = toot_content.getSelectionStart();
if( s.toString().length() == 0 )
currentCursorPosition = 0;
//Only check last 15 characters before cursor position to avoid lags
if( currentCursorPosition < 15 ){ //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}else {
searchLength = 15;
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
toot_content.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
int totalChar = toot_cw_content.length() + toot_content.length();
toot_space_left.setText(String.valueOf(totalChar));
if( currentCursorPosition- (searchLength-1) < 0 || currentCursorPosition == 0 || currentCursorPosition > s.toString().length())
return;
Matcher m, mt;
if( s.toString().charAt(0) == '@')
m = sPattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
else
m = sPattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
if(m.matches()) {
String search = m.group(3);
if (pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.GONE);
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if( toot_content.getSelectionStart() != 0)
currentCursorPosition = toot_content.getSelectionStart();
if( s.toString().length() == 0 )
currentCursorPosition = 0;
//Only check last 15 characters before cursor position to avoid lags
if( currentCursorPosition < 15 ){ //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}else {
searchLength = 15;
}
new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
if( s.toString().charAt(0) == '#')
mt = tPattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
int totalChar = toot_cw_content.length() + toot_content.length();
toot_space_left.setText(String.valueOf(totalChar));
if( currentCursorPosition- (searchLength-1) < 0 || currentCursorPosition == 0 || currentCursorPosition > s.toString().length())
return;
Matcher m, mt;
if( s.toString().charAt(0) == '@')
m = sPattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
else
mt = tPattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
if(mt.matches()) {
String search = mt.group(3);
m = sPattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
if(m.matches()) {
String search = m.group(3);
if (pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.GONE);
}
new RetrieveSearchAsyncTask(getApplicationContext(),search,true, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
if( s.toString().charAt(0) == ':')
mt = ePattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
if( s.toString().charAt(0) == '#')
mt = tPattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
else
mt = ePattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
mt = tPattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
if(mt.matches()) {
String shortcode = mt.group(3);
String search = mt.group(3);
if (pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.GONE);
}
new RetrieveEmojiAsyncTask(getApplicationContext(),shortcode,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
toot_content.dismissDropDown();
new RetrieveSearchAsyncTask(getApplicationContext(),search,true, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
if( s.toString().charAt(0) == ':')
mt = ePattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
else
mt = ePattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
if(mt.matches()) {
String shortcode = mt.group(3);
if (pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.GONE);
}
new RetrieveEmojiAsyncTask(getApplicationContext(),shortcode,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else {
toot_content.dismissDropDown();
}
}
}
totalChar = toot_cw_content.length() + toot_content.length();
toot_space_left.setText(String.valueOf(totalChar));
}
totalChar = toot_cw_content.length() + toot_content.length();
toot_space_left.setText(String.valueOf(totalChar));
}
});
});
if( scheduledstatus != null)
restoreServerSchedule(scheduledstatus.getStatus());

View File

@ -21,9 +21,11 @@ import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import java.util.List;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.GNUAPI;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -59,32 +61,40 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
if (!tagsOnly)
results = api.search(query);
else {
//search tags only
results = api.search(query);
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query);
if (results != null && results.getHashtags() != null) {
//If cache contains matching tags
if (cachedTags != null) {
for (String apiTag : results.getHashtags()) {
//Cache doesn't contain the tags coming from the api (case insensitive)
if (!Helper.containsCaseInsensitive(apiTag, cachedTags)) {
cachedTags.add(apiTag); //It's added
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
API api = new API(this.contextReference.get());
if (!tagsOnly)
results = api.search(query);
else {
//search tags only
results = api.search(query);
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query);
if (results != null && results.getHashtags() != null) {
//If cache contains matching tags
if (cachedTags != null) {
for (String apiTag : results.getHashtags()) {
//Cache doesn't contain the tags coming from the api (case insensitive)
if (!Helper.containsCaseInsensitive(apiTag, cachedTags)) {
cachedTags.add(apiTag); //It's added
}
}
results.setHashtags(cachedTags);
}
} else if (cachedTags != null) {
if (results == null)
results = new Results();
results.setHashtags(cachedTags);
}
} else if (cachedTags != null) {
if (results == null)
results = new Results();
results.setHashtags(cachedTags);
}
error = api.getError();
}else {
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
results = gnuapi.search(query);
error = gnuapi.getError();
}
error = api.getError();
return null;
}

View File

@ -59,9 +59,11 @@ import java.util.regex.Pattern;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.PeertubeActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
@ -1087,11 +1089,13 @@ public class Status implements Parcelable{
spannableStringT.setSpan(new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
Intent intent = new Intent(context, HashTagActivity.class);
Bundle b = new Bundle();
b.putString("tag", tag.substring(1));
intent.putExtras(b);
context.startActivity(intent);
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
Intent intent = new Intent(context, HashTagActivity.class);
Bundle b = new Bundle();
b.putString("tag", tag.substring(1));
intent.putExtras(b);
context.startActivity(intent);
}
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {

View File

@ -68,18 +68,15 @@ public class GNUAPI {
private Account account;
private Context context;
private Results results;
private Attachment attachment;
private List<Account> accounts;
private List<Status> statuses;
private List<Conversation> conversations;
private int tootPerPage, accountPerPage, notificationPerPage;
private int actionCode;
private String instance;
private String prefKeyOauthTokenT;
private APIResponse apiResponse;
private Error APIError;
private List<String> domains;
public enum accountPrivacy {
PUBLIC,
@ -248,7 +245,7 @@ public class GNUAPI {
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);
params.put("user_id",accountId);
response = new HttpsConnection(context).get(getAbsoluteUrl("/users/show.json"), 60, params, prefKeyOauthTokenT);
JSONObject resobj = new JSONObject(response);
try {
@ -610,7 +607,7 @@ public class GNUAPI {
if (0 > limit || limit > 80)
limit = 80;
params.put("limit",String.valueOf(limit));
conversations = new ArrayList<>();
List<Conversation> conversations = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/conversations"), 60, params, prefKeyOauthTokenT);
@ -1572,6 +1569,44 @@ public class GNUAPI {
return attachment;
}
/**
* Retrieves Accounts and feeds when searching *synchronously*
*
* @param query String search
* @return Results
*/
public Results search(String query) {
Results results = new Results();
HashMap<String, String> params = new HashMap<>();
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
params.put("q", query);
else
try {
params.put("q", URLEncoder.encode(query, "UTF-8"));
} catch (UnsupportedEncodingException e) {
params.put("q", query);
}
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl("/users/search.json"), 60, params, prefKeyOauthTokenT);
List<Account> accounts = parseAccountResponse(new JSONArray(response));
results.setAccounts(accounts);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return results;
}
/**
* Retrieves Accounts and feeds when searching *synchronously*
*

View File

@ -831,48 +831,49 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
});
//Click on a conversation
if ((getItemViewType(viewHolder.getAdapterPosition()) == DISPLAYED_STATUS || getItemViewType(viewHolder.getAdapterPosition()) == COMPACT_STATUS)) {
holder.status_content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if (status.getReblog() == null)
b.putParcelable("status", status);
else
b.putParcelable("status", status.getReblog());
intent.putExtras(b);
if (type == RetrieveFeedsAsyncTask.Type.CONTEXT)
((Activity) context).finish();
context.startActivity(intent);
} else {
if( social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
CrossActions.doCrossConversation(context, status);
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
if ((getItemViewType(viewHolder.getAdapterPosition()) == DISPLAYED_STATUS || getItemViewType(viewHolder.getAdapterPosition()) == COMPACT_STATUS)) {
holder.status_content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if (status.getReblog() == null)
b.putParcelable("status", status);
else
b.putParcelable("status", status.getReblog());
intent.putExtras(b);
if (type == RetrieveFeedsAsyncTask.Type.CONTEXT)
((Activity) context).finish();
context.startActivity(intent);
} else {
if( social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
CrossActions.doCrossConversation(context, status);
}
}
}
});
holder.main_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if (status.getReblog() == null)
b.putParcelable("status", status);
else
b.putParcelable("status", status.getReblog());
intent.putExtras(b);
if (type == RetrieveFeedsAsyncTask.Type.CONTEXT)
((Activity) context).finish();
context.startActivity(intent);
} else {
if( social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
CrossActions.doCrossConversation(context, status);
});
holder.main_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if (status.getReblog() == null)
b.putParcelable("status", status);
else
b.putParcelable("status", status.getReblog());
intent.putExtras(b);
if (type == RetrieveFeedsAsyncTask.Type.CONTEXT)
((Activity) context).finish();
context.startActivity(intent);
} else {
if( social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
CrossActions.doCrossConversation(context, status);
}
}
}
});
}
});
}
holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE);
if (truncate_toots_size > 0) {
holder.status_content.setMaxLines(truncate_toots_size);