Merge branch 'develop' into custom_search
This commit is contained in:
commit
6c48fd6c3a
|
@ -6,4 +6,3 @@
|
|||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
/crowdin.properties
|
||||
|
|
|
@ -7,8 +7,8 @@ android {
|
|||
applicationId "fr.gouv.etalab.mastodon"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 27
|
||||
versionCode 77
|
||||
versionName "1.6.1"
|
||||
versionCode 78
|
||||
versionName "1.6.2-beta-1"
|
||||
}
|
||||
flavorDimensions "default"
|
||||
buildTypes {
|
||||
|
|
|
@ -1088,7 +1088,10 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.0");
|
||||
MenuItem itemEmoji = menu.findItem(R.id.action_emoji);
|
||||
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
final List<Emojis> emojis = new CustomEmojiDAO(getApplicationContext(), db).getAllEmojis();
|
||||
//Displays button only if custom emojis
|
||||
if (emojis != null && emojis.size() > 0 && (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion))) {
|
||||
itemEmoji.setVisible(true);
|
||||
}else{
|
||||
itemEmoji.setVisible(false);
|
||||
|
|
|
@ -20,13 +20,17 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
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.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.CustomEmojiDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
|
||||
|
@ -68,6 +72,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
if( account.getUsername() != null && account.getCreated_at() != null)
|
||||
new AccountDAO(this.contextReference.get(), db).insertAccount(account);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,13 @@ import android.os.AsyncTask;
|
|||
import java.lang.ref.WeakReference;
|
||||
|
||||
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.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.CustomEmojiDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
/**
|
||||
|
@ -60,6 +63,15 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
new AccountDAO(this.contextReference.get(), db).updateAccount(account);
|
||||
}
|
||||
}
|
||||
try {
|
||||
APIResponse response = new API(contextReference.get()).getCustomEmoji();
|
||||
if( response != null && response.getEmojis() != null && response.getEmojis().size() > 0){
|
||||
new CustomEmojiDAO(contextReference.get(), db).removeAll();
|
||||
for(Emojis emojis: response.getEmojis()){
|
||||
new CustomEmojiDAO(contextReference.get(), db).insertEmoji(emojis);
|
||||
}
|
||||
}
|
||||
}catch (Exception ignored){}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1133,6 +1133,31 @@ public class API {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves Accounts when searching (ie: via @...) *synchronously*
|
||||
*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getCustomEmoji() {
|
||||
List<Emojis> emojis = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection();
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/custom_emojis"), 60, null, prefKeyOauthTokenT);
|
||||
emojis = parseEmojis(new JSONArray(response));
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setEmojis(emojis);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique account
|
||||
* @param resobj JSONObject
|
||||
|
@ -1266,10 +1291,7 @@ public class API {
|
|||
if( arrayTag != null){
|
||||
for(int j = 0 ; j < emojisTag.length() ; j++){
|
||||
JSONObject emojisObj = emojisTag.getJSONObject(j);
|
||||
Emojis emojis = new Emojis();
|
||||
emojis.setShortcode(emojisObj.get("shortcode").toString());
|
||||
emojis.setStatic_url(emojisObj.get("static_url").toString());
|
||||
emojis.setUrl(emojisObj.get("url").toString());
|
||||
Emojis emojis = parseEmojis(emojisObj);
|
||||
emojiList.add(emojis);
|
||||
}
|
||||
}
|
||||
|
@ -1327,6 +1349,47 @@ public class API {
|
|||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse emojis
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Emojis> of emojis
|
||||
*/
|
||||
private List<Emojis> parseEmojis(JSONArray jsonArray){
|
||||
List<Emojis> emojis = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Emojis emojis1 = parseEmojis(resobj);
|
||||
emojis.add(emojis1);
|
||||
i++;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return emojis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response for emoji
|
||||
* @param resobj JSONObject
|
||||
* @return Emojis
|
||||
*/
|
||||
private static Emojis parseEmojis(JSONObject resobj){
|
||||
Emojis emojis = new Emojis();
|
||||
try {
|
||||
emojis.setShortcode(resobj.get("shortcode").toString());
|
||||
emojis.setStatic_url(resobj.get("static_url").toString());
|
||||
emojis.setUrl(resobj.get("url").toString());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return emojis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique account
|
||||
* @param resobj JSONObject
|
||||
|
|
|
@ -30,6 +30,7 @@ public class APIResponse {
|
|||
private List<Context> contexts = null;
|
||||
private List<Notification> notifications = null;
|
||||
private List<Relationship> relationships = null;
|
||||
private List<Emojis> emojis = null;
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Error error = null;
|
||||
private String since_id, max_id;
|
||||
private Instance instance;
|
||||
|
@ -105,4 +106,12 @@ public class APIResponse {
|
|||
public void setRelationships(List<Relationship> relationships) {
|
||||
this.relationships = relationships;
|
||||
}
|
||||
|
||||
public List<Emojis> getEmojis() {
|
||||
return emojis;
|
||||
}
|
||||
|
||||
public void setEmojis(List<Emojis> emojis) {
|
||||
this.emojis = emojis;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,7 +291,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
|
||||
|
||||
if( filter != null && filter.length() > 0){
|
||||
Pattern filterPattern = Pattern.compile("(" + filter + ")");
|
||||
Pattern filterPattern = Pattern.compile("(" + filter + ")", Pattern.CASE_INSENSITIVE);
|
||||
String content;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
|
|
|
@ -139,7 +139,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Status;
|
|||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.CustomEmojiDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
import static android.content.Context.DOWNLOAD_SERVICE;
|
||||
|
@ -1236,15 +1235,6 @@ public class Helper {
|
|||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
for (final Emojis emoji : emojis) {
|
||||
boolean sameInstance;
|
||||
if( instance != null) {
|
||||
if (status.getReblog() == null)
|
||||
sameInstance = status.getUri().contains(instance);
|
||||
else
|
||||
sameInstance = status.getReblog().getUri().contains(instance);
|
||||
if (sameInstance)
|
||||
storeEmoji(context, db, emoji);
|
||||
}
|
||||
NonViewAware imageAware = new NonViewAware(new ImageSize(50, 50), ViewScaleType.CROP);
|
||||
imageLoader.displayImage(emoji.getUrl(), imageAware, options, new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
|
@ -1334,21 +1324,6 @@ public class Helper {
|
|||
return spannableString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage custom emoji to store or update them
|
||||
* @param context Context
|
||||
* @param db SQLiteDatabase
|
||||
* @param emojis Emojis
|
||||
*/
|
||||
private static void storeEmoji(Context context, SQLiteDatabase db, Emojis emojis){
|
||||
try{
|
||||
Emojis emoji_ = new CustomEmojiDAO(context, db).getEmoji(emojis.getShortcode());
|
||||
if( emoji_ == null)
|
||||
new CustomEmojiDAO(context, db).insertEmoji(emojis);
|
||||
else
|
||||
new CustomEmojiDAO(context, db).updateEmoji(emojis);
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the account bio contents urls & tags and fills the content with ClickableSpan
|
||||
|
|
|
@ -92,6 +92,14 @@ public class CustomEmojiDAO {
|
|||
return db.delete(Sqlite.TABLE_CUSTOM_EMOJI, Sqlite.COL_SHORTCODE + " = \"" + emoji.getShortcode() + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance+ "\"", null);
|
||||
}
|
||||
|
||||
/***
|
||||
* Remove emoji by id
|
||||
*/
|
||||
public void removeAll(){
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
db.delete(Sqlite.TABLE_CUSTOM_EMOJI, Sqlite.COL_INSTANCE + " = \"" + instance + "\"", null);
|
||||
}
|
||||
|
||||
//------- GETTERS -------
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue