Merged in develop (pull request #35)

This commit is contained in:
tom79 2017-07-30 13:20:05 +00:00
commit e3b7b7067c
26 changed files with 372 additions and 70 deletions

View File

@ -5,10 +5,10 @@ android {
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 25
versionCode 37
versionName "1.3.8.1"
versionCode 38
versionName "1.3.9"
}
buildTypes {
release {

Binary file not shown.

View File

@ -21,6 +21,7 @@ import android.graphics.Paint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -103,7 +104,12 @@ public class LoginActivity extends AppCompatActivity {
connectionButton.setEnabled(false);
login_two_step.setVisibility(View.INVISIBLE);
if (!hasFocus) {
retrievesClientId();
if( Patterns.WEB_URL.matcher(login_instance.getText().toString().trim()).matches() ){
retrievesClientId();
}else {
Toast.makeText(getApplicationContext(), R.string.toast_error_instance, Toast.LENGTH_LONG).show();
}
}
}
});

View File

@ -46,8 +46,10 @@ import com.github.chrisbanes.photoview.OnMatrixChangedListener;
import com.github.chrisbanes.photoview.PhotoView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.FileAsyncHttpResponseHandler;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
@ -62,6 +64,7 @@ import java.util.ArrayList;
import cz.msebera.android.httpclient.Header;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.MastalabSSLSocketFactory;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -163,6 +166,15 @@ public class MediaActivity extends AppCompatActivity {
isHiding = false;
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
.imageDownloader(new PatchBaseImageDownloader(getApplicationContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
setTitle("");

View File

@ -42,11 +42,14 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -59,6 +62,7 @@ import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
@ -131,6 +135,15 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show();
}
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
.imageDownloader(new PatchBaseImageDownloader(getApplicationContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
statuses = new ArrayList<>();
boolean isOnWifi = Helper.isOnWIFI(getApplicationContext());
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);

View File

@ -62,12 +62,15 @@ import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
@ -91,6 +94,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter;
import fr.gouv.etalab.mastodon.drawers.DraftsListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -182,6 +186,15 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
//By default the toot is not restored so the id -1 is defined
currentToId = -1;
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
.imageDownloader(new PatchBaseImageDownloader(getApplicationContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();

View File

@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
@ -30,6 +31,7 @@ import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
@ -54,9 +56,9 @@ public class WebviewConnectActivity extends AppCompatActivity {
private AlertDialog alert;
private String clientId, clientSecret;
private String instance;
private int retry;
public void onCreate(Bundle savedInstanceState)
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
@ -71,7 +73,7 @@ public class WebviewConnectActivity extends AppCompatActivity {
instance = b.getString("instance");
if( instance == null)
finish();
retry = 0;
clientId = sharedpreferences.getString(Helper.CLIENT_ID, null);
clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, null);
@ -99,6 +101,13 @@ public class WebviewConnectActivity extends AppCompatActivity {
super.shouldOverrideUrlLoading(view,url);
if( url.contains(Helper.REDIRECT_CONTENT_WEB)){
String val[] = url.split("code=");
if (val.length< 2){
Toast.makeText(getApplicationContext(), R.string.toast_code_error, Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(WebviewConnectActivity.this, LoginActivity.class);
startActivity(myIntent);
finish();
return false;
}
String code = val[1];
String action = "/oauth/token";

View File

@ -0,0 +1,58 @@
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastalab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.interfaces.OnPostNotificationsActionInterface;
/**
* Created by Thomas on 29/07/2017.
* Posts to delete one or all notifications
*/
public class PostNotificationsAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
private OnPostNotificationsActionInterface listener;
private APIResponse apiResponse;
private Notification notification;
public PostNotificationsAsyncTask(Context context, Notification notification, OnPostNotificationsActionInterface onPostNotificationsActionInterface){
this.context = context;
this.listener = onPostNotificationsActionInterface;
this.notification = notification;
}
@Override
protected Void doInBackground(Void... params) {
if( notification != null)
apiResponse = new API(context).postNoticationAction(notification.getId());
else //Delete all notifications
apiResponse = new API(context).postNoticationAction(null);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onPostNotificationsAction(apiResponse, notification);
}
}

View File

@ -950,6 +950,40 @@ public class API {
}
/**
* Posts a status
* @param notificationId String, the current notification id, if null all notifications are deleted
* @return APIResponse
*/
public APIResponse postNoticationAction(String notificationId){
String action;
RequestParams requestParams = new RequestParams();
if( notificationId == null)
action = "/notifications/clear";
else {
requestParams.add("id",notificationId);
action = "/notifications/dismiss";
}
post(action, 30000, requestParams, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response) {
setError(statusCode, error);
error.printStackTrace();
}
});
return apiResponse;
}
/**
* Retrieves notifications for the authenticated account since an id*synchronously*
* @param since_id String since max

View File

@ -35,10 +35,13 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -46,6 +49,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -61,8 +65,6 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
private List<Account> accounts;
private LayoutInflater layoutInflater;
private ImageLoader imageLoader;
private DisplayImageOptions options;
private RetrieveAccountsAsyncTask.Type action;
private Context context;
private AccountsListAdapter accountsListAdapter;
@ -72,9 +74,6 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
this.context = context;
this.accounts = accounts;
layoutInflater = LayoutInflater.from(context);
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
this.action = action;
this.accountsListAdapter = this;
this.targetedId = targetedId;
@ -101,6 +100,18 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ImageLoader imageLoader = ImageLoader.getInstance();
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
.imageDownloader(new PatchBaseImageDownloader(context))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
final Account account = accounts.get(position);
final ViewHolder holder;
if (convertView == null) {

View File

@ -25,7 +25,6 @@ import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -46,9 +45,12 @@ import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.PostNotificationsAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnPostNotificationsActionInterface;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.client.Entities.Status;
@ -61,7 +63,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
* Created by Thomas on 24/04/2017.
* Adapter for Status
*/
public class NotificationsListAdapter extends BaseAdapter implements OnPostActionInterface {
public class NotificationsListAdapter extends BaseAdapter implements OnPostActionInterface, OnPostNotificationsActionInterface {
private Context context;
private List<Notification> notifications;
@ -120,6 +122,7 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
holder.status_date = (TextView) convertView.findViewById(R.id.status_date);
holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply);
holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy);
holder.notification_delete = (ImageView) convertView.findViewById(R.id.notification_delete);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
@ -145,6 +148,36 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
//Manages theme for icon colors
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK){
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_retweet,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_delete,R.color.dark_text);
}else {
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_retweet,R.color.black);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_photo,R.color.black);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.black);
changeDrawableColor(context, R.drawable.ic_delete,R.color.black);
}
final Status status = notification.getStatus();
if( status != null ){
if( status.getMedia_attachments() == null || status.getMedia_attachments().size() < 1)
@ -162,45 +195,13 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
}else{
holder.notification_account_displayname.setCompoundDrawables( null, null, null, null);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
holder.notification_status_content.setText(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT));
else
//noinspection deprecation
holder.notification_status_content.setText(Html.fromHtml(status.getContent()));
holder.notification_status_content.setAutoLinkMask(Linkify.WEB_URLS);
holder.notification_status_content = Helper.clickableElements(context, holder.notification_status_content,status.getContent(),
status.getReblog() != null?status.getReblog().getMentions():status.getMentions());
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count()));
holder.status_date.setText(Helper.dateDiff(context, status.getCreated_at()));
//Manages theme for icon colors
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK){
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_retweet,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text);
}else {
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_retweet,R.color.black);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_photo,R.color.black);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.black);
}
//Adds attachment -> disabled, to enable them uncomment the line below
//loadAttachments(status, holder);
holder.notification_status_container.setVisibility(View.VISIBLE);
@ -305,7 +306,12 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
}
});
holder.notification_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
displayConfirmationNotificationDialog(notification);
}
});
holder.notification_account_displayname.setText(Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true));
holder.notification_account_username.setText( String.format("@%s",notification.getAccount().getUsername()));
//Profile picture
@ -361,6 +367,44 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
.show();
}
/**
* Display a validation message for notification deletion
* @param notification Notification
*/
private void displayConfirmationNotificationDialog(final Notification notification){
final ArrayList seletedItems = new ArrayList();
AlertDialog dialog = new AlertDialog.Builder(context)
.setTitle(R.string.delete_notification_ask)
.setMultiChoiceItems(new String[]{context.getString(R.string.delete_notification_ask_all)}, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
if (isChecked) {
//noinspection unchecked
seletedItems.add(indexSelected);
} else {
if (seletedItems.contains(indexSelected))
seletedItems.remove(Integer.valueOf(indexSelected));
}
}
}).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (seletedItems.size() > 0)
new PostNotificationsAsyncTask(context, null, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
new PostNotificationsAsyncTask(context, notification, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
}).create();
dialog.show();
}
/**
* Favourites/Unfavourites a status
* @param status Status
@ -401,6 +445,25 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
}
}
@Override
public void onPostNotificationsAction(APIResponse apiResponse, Notification notification) {
if(apiResponse.getError() != null){
Toast.makeText(context, R.string.toast_error,Toast.LENGTH_LONG).show();
return;
}
if( notification != null){
notifications.remove(notification);
notificationsListAdapter.notifyDataSetChanged();
Toast.makeText(context,R.string.delete_notification,Toast.LENGTH_LONG).show();
}else{
notifications.clear();
notifications = new ArrayList<>();
notificationsListAdapter.notifyDataSetChanged();
Toast.makeText(context,R.string.delete_notification_all,Toast.LENGTH_LONG).show();
}
}
private class ViewHolder {
TextView notification_status_content;
@ -408,6 +471,7 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
TextView notification_account_username;
TextView notification_account_displayname;
ImageView notification_account_profile;
ImageView notification_delete;
TextView status_favorite_count;
TextView status_reblog_count;
TextView status_date;

View File

@ -31,10 +31,13 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -43,6 +46,7 @@ import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -63,9 +67,6 @@ public class SearchListAdapter extends BaseAdapter {
private static final int ACCOUNT_TYPE = 1;
private static final int TAG_TYPE = 2;
private LayoutInflater layoutInflater;
private ImageLoader imageLoader;
private DisplayImageOptions options;
public SearchListAdapter(Context context, List<Status> statuses, List<Account> accounts, List<String> tags){
this.context = context;
@ -73,9 +74,6 @@ public class SearchListAdapter extends BaseAdapter {
this.accounts = ( accounts != null)?accounts:new ArrayList<Account>();
this.tags = ( tags != null)?tags:new ArrayList<String>();
layoutInflater = LayoutInflater.from(context);
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
}
@Override
@ -116,6 +114,18 @@ public class SearchListAdapter extends BaseAdapter {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ImageLoader imageLoader = ImageLoader.getInstance();
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
.imageDownloader(new PatchBaseImageDownloader(context))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
int type = getItemViewType(position);
if( type == STATUS_TYPE){
View v = convertView;

View File

@ -42,14 +42,17 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
@ -59,6 +62,7 @@ import fr.gouv.etalab.mastodon.activities.MediaActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
import fr.gouv.etalab.mastodon.translation.YandexQuery;
@ -70,7 +74,6 @@ import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
@ -101,9 +104,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
this.isOnWifi = isOnWifi;
this.behaviorWithAttachments = behaviorWithAttachments;
layoutInflater = LayoutInflater.from(this.context);
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
statusListAdapter = this;
this.type = type;
this.targetedId = targetedId;
@ -130,6 +130,20 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
.imageDownloader(new PatchBaseImageDownloader(context))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
final Status status = statuses.get(position);
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.drawer_status, parent, false);

View File

@ -19,7 +19,7 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;

View File

@ -160,7 +160,7 @@ public class Helper {
public static final String SCOPE = "scope";
public static final String SCOPES = "scopes";
public static final String WEBSITE = "website";
public static final String WEBSITE_VALUE = "https://play.google.com/store/apps/details?id=fr.gouv.etalab.mastodon";
public static final String WEBSITE_VALUE = "https://tom79.bitbucket.io/";
public static final String SHOW_BATTERY_SAVER_MESSAGE = "show_battery_saver_message";
public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id";
public static final String LAST_HOMETIMELINE_MAX_ID = "last_hometimeline_max_id";

View File

@ -0,0 +1,27 @@
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastalab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
/**
* Created by Thomas on 29/07/2017.
* Interface when deleting a notification
*/
public interface OnPostNotificationsActionInterface {
void onPostNotificationsAction(APIResponse apiResponse, Notification notification);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

View File

@ -45,7 +45,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textWebEmailAddress"
android:hint="@string/instance"
android:hint="@string/instance_example"
/>
<EditText
android:id="@+id/login_uid"

View File

@ -30,13 +30,29 @@
android:layout_height="wrap_content"
android:id="@+id/main_container"
android:orientation="horizontal">
<ImageView
android:id="@+id/notification_account_profile"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_gravity="center_horizontal|top"
android:gravity="center_horizontal|top"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/notification_account_profile"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_gravity="center_horizontal|top"
android:gravity="center_horizontal|top"
tools:ignore="ContentDescription" />
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:id="@+id/notification_delete"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_delete"
android:layout_width="25dp"
android:layout_height="25dp"
tools:ignore="ContentDescription" />
</LinearLayout>
<LinearLayout
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
@ -83,6 +99,7 @@
<TextView
android:id="@+id/notification_status_content"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
android:autoLink="web"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@ -33,6 +33,7 @@
<string name="other_instance">Autre instance que mastodon.etalab.gouv.fr ?</string>
<string name="no_result">Aucun résultat !</string>
<string name="instance">Instance</string>
<string name="instance_example">Instance : mastodon.social</string>
<string name="toast_account_changed">Utilisation du compte %1$s</string>
<string name="add_account">Ajouter un compte</string>
<string name="clipboard">Le contenu du pouet a été copié dans le presse-papier</string>
@ -208,6 +209,10 @@
<item quantity="one">et %d autre pouet à découvrir</item>
<item quantity="other">et %d autres pouets à découvrir</item>
</plurals>
<string name="delete_notification_ask">Supprimer une notification ?</string>
<string name="delete_notification_ask_all">Supprimer toutes les notifications ?</string>
<string name="delete_notification">La notification a été supprimée!</string>
<string name="delete_notification_all">Toutes les notifications ont été supprimées !</string>
<!-- HEADER -->
<string name="following">Abonnements</string>
<string name="followers">Abonnés</string>
@ -227,6 +232,8 @@
<string name="toast_report">Le pouet a été signalé !</string>
<string name="toast_unstatus">Le pouet a été supprimé !</string>
<string name="toast_error">Oups ! Une erreur s\'est produite !</string>
<string name="toast_code_error">Une erreur s\'est produite ! L\'instance n\'a retourné aucun code d\authorisation !</string>
<string name="toast_error_instance">Le nom de l\'instance ne semble pas être valide !</string>
<string name="toast_error_loading_account">Une erreur s\'est produite en chargeant le compte !</string>
<string name="toast_error_search">Une erreur s\'est produite lors de la recherche !</string>
<string name="toast_error_login">Impossible de vous connecter !</string>

View File

@ -34,6 +34,7 @@
<string name="other_instance">Other instance than mastodon.etalab.gouv.fr?</string>
<string name="no_result">No results!</string>
<string name="instance">Instance</string>
<string name="instance_example">Instance: mastodon.social</string>
<string name="toast_account_changed">Now works with the account %1$s</string>
<string name="add_account">Add an account</string>
<string name="clipboard">The content of the toot has been copied to the clipboard</string>
@ -213,6 +214,10 @@
<item quantity="one">and another toot to discover</item>
<item quantity="other">and %d other toots to discover</item>
</plurals>
<string name="delete_notification_ask">Delete a notification?</string>
<string name="delete_notification_ask_all">Delete all notifications?</string>
<string name="delete_notification">The notification has been deleted!</string>
<string name="delete_notification_all">All notifications have been deleted!</string>
<!-- HEADER -->
<string name="following">Following</string>
<string name="followers">Followers</string>
@ -232,6 +237,8 @@
<string name="toast_report">The toot was reported!</string>
<string name="toast_unstatus">The toot was deleted!</string>
<string name="toast_error">Oops ! An error occurred!</string>
<string name="toast_code_error">An error occurred! The instance did not return an authorisation code!</string>
<string name="toast_error_instance">The instance domain does not seem to be valide!</string>
<string name="toast_error_loading_account">An error occurred while switching between accounts!</string>
<string name="toast_error_search">An error occurred while searching!</string>
<string name="toast_error_login">Can not log in!</string>