diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1f747c7ed..d87ba5e4e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,15 +38,19 @@ + - - + + diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java index 792d2cce3..cb8824e0a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java @@ -32,6 +32,7 @@ import android.widget.Toast; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteAccountsAsyncTask; import fr.gouv.etalab.mastodon.client.Entities.Account; @@ -43,7 +44,6 @@ import fr.gouv.etalab.mastodon.helper.ExpandableHeightListView; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; -import mastodon.etalab.gouv.fr.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java index 40b341d77..352dc5ec4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java @@ -50,12 +50,13 @@ import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import cz.msebera.android.httpclient.Header; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask; import fr.gouv.etalab.mastodon.client.KinrarClient; import fr.gouv.etalab.mastodon.client.MastalabSSLSocketFactory; import fr.gouv.etalab.mastodon.client.OauthClient; import fr.gouv.etalab.mastodon.helper.Helper; -import mastodon.etalab.gouv.fr.mastodon.R; + import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index ff83a4f31..c6d1b1565 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -74,6 +74,7 @@ import java.util.Locale; import java.util.Stack; import java.util.regex.Matcher; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveMetaDataAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask; @@ -92,6 +93,7 @@ import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface; import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface; +import fr.gouv.etalab.mastodon.services.LiveNotificationService; import fr.gouv.etalab.mastodon.services.StreamingService; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; @@ -1057,22 +1059,22 @@ public abstract class BaseMainActivity extends AppCompatActivity @Override public void onReceive(Context context, Intent intent) { Bundle b = intent.getExtras(); - StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming"); + LiveNotificationService.EventStreaming eventStreaming = (LiveNotificationService.EventStreaming) intent.getSerializableExtra("eventStreaming"); assert b != null; userIdService = b.getString("userIdService", null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); if( userIdService != null && userIdService.equals(userId)) { - if (eventStreaming == StreamingService.EventStreaming.NOTIFICATION) { + if (eventStreaming == LiveNotificationService.EventStreaming.NOTIFICATION) { Notification notification = b.getParcelable("data"); if (notificationsFragment != null) { notificationsFragment.refresh(notification); } - } else if (eventStreaming == StreamingService.EventStreaming.UPDATE) { + } else if (eventStreaming == LiveNotificationService.EventStreaming.UPDATE) { Status status = b.getParcelable("data"); if (homeFragment != null) { homeFragment.refresh(status); } - } else if (eventStreaming == StreamingService.EventStreaming.DELETE) { + } else if (eventStreaming == LiveNotificationService.EventStreaming.DELETE) { //noinspection unused String id = b.getString("id"); if (notificationsFragment != null) { @@ -1460,9 +1462,17 @@ public abstract class BaseMainActivity extends AppCompatActivity return activityPaused; } + public void startSreaming(boolean restart){ - streamingIntent = new Intent(this, StreamingService.class); - streamingIntent.putExtra("restart",restart); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); + boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); + if( notify && liveNotifications) { + streamingIntent = new Intent(this, LiveNotificationService.class); + streamingIntent.putExtra("restart", restart); + }else { + streamingIntent = new Intent(this, StreamingService.class); + } startService(streamingIntent); } } \ No newline at end of file diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java index 8a4669424..3d6b267c9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java @@ -58,6 +58,8 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; + +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountInfoAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateCredentialAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; @@ -69,7 +71,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnUpdateCredentialInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; + diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java index ed7781e38..7d998539a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java @@ -33,13 +33,14 @@ import android.widget.Toast; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.drawers.StatusListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; -import mastodon.etalab.gouv.fr.mastodon.R; + /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceActivity.java index 42ebf1db2..e6956f594 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceActivity.java @@ -31,12 +31,13 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Instance; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface; -import mastodon.etalab.gouv.fr.mastodon.R; + import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java index b25b03d1c..ade8ff029 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java @@ -63,11 +63,12 @@ import java.security.UnrecoverableKeyException; import java.util.ArrayList; import cz.msebera.android.httpclient.Header; +import fr.gouv.etalab.mastodon.R; 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; + import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE; import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PrivacyActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PrivacyActivity.java index 831e16471..dddbc6e7d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PrivacyActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PrivacyActivity.java @@ -19,8 +19,10 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; + +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.helper.Helper; -import mastodon.etalab.gouv.fr.mastodon.R; + /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java index 9632576a5..66b79fba9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java @@ -63,6 +63,7 @@ import java.util.ArrayList; import java.util.List; import cz.msebera.android.httpclient.Header; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteAccountsAsyncTask; @@ -81,7 +82,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; + /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java index a897b8a4f..82a661e4d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java @@ -26,6 +26,7 @@ import android.widget.RelativeLayout; import android.widget.Toast; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Error; @@ -34,7 +35,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.drawers.SearchListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface; -import mastodon.etalab.gouv.fr.mastodon.R; + /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index 59f1bb568..6441f4dc8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -70,6 +70,7 @@ import java.util.ArrayList; import java.util.List; import de.hdodenhof.circleimageview.CircleImageView; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; @@ -90,7 +91,6 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface; -import mastodon.etalab.gouv.fr.mastodon.R; import fr.gouv.etalab.mastodon.client.Entities.Relationship; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index e381335c3..7066f31d2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -51,6 +51,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveContextAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; @@ -65,7 +66,6 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveContextInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 1ea9e28dd..b9150fed5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -143,7 +143,7 @@ import fr.gouv.etalab.mastodon.jobs.ScheduledTootsSyncJob; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java index a15fba197..4eedc7964 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java @@ -37,7 +37,7 @@ import android.widget.FrameLayout; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.webview.MastalabWebChromeClient; import fr.gouv.etalab.mastodon.webview.MastalabWebViewClient; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE; import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java index 18f115dab..56198d618 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java @@ -43,7 +43,7 @@ import cz.msebera.android.httpclient.Header; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask; import fr.gouv.etalab.mastodon.client.OauthClient; import fr.gouv.etalab.mastodon.helper.Helper; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** * Created by Thomas on 24/04/2017. diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index b9b1f76b5..1ff202adb 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -45,11 +45,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import cz.msebera.android.httpclient.Header; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.client.Entities.*; import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAttachmentInterface; -import mastodon.etalab.gouv.fr.mastodon.R; + import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountSearchDevAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountSearchDevAdapter.java index 8d57ff25d..8283c6c41 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountSearchDevAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountSearchDevAdapter.java @@ -23,7 +23,6 @@ import android.os.Build; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v4.content.ContextCompat; -import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -42,6 +41,7 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer; import java.io.File; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; import fr.gouv.etalab.mastodon.client.API; @@ -50,9 +50,7 @@ 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; -import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; /** @@ -111,11 +109,11 @@ public class AccountSearchDevAdapter extends BaseAdapter implements OnPostAction if (convertView == null) { convertView = layoutInflater.inflate(R.layout.drawer_account_search_dev, parent, false); holder = new ViewHolder(); - holder.account_pp = (ImageView) convertView.findViewById(R.id.account_pp); - holder.account_dn = (TextView) convertView.findViewById(R.id.account_dn); - holder.account_un = (TextView) convertView.findViewById(R.id.account_un); - holder.account_follow = (FloatingActionButton) convertView.findViewById(R.id.account_follow); - holder.acccount_container = (LinearLayout) convertView.findViewById(R.id.acccount_container); + holder.account_pp = convertView.findViewById(R.id.account_pp); + holder.account_dn = convertView.findViewById(R.id.account_dn); + holder.account_un = convertView.findViewById(R.id.account_un); + holder.account_follow = convertView.findViewById(R.id.account_follow); + holder.acccount_container = convertView.findViewById(R.id.acccount_container); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); @@ -124,6 +122,7 @@ public class AccountSearchDevAdapter extends BaseAdapter implements OnPostAction final float scale = context.getResources().getDisplayMetrics().density; if( account != null && account.isLocked()){ Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_lock_outline); + assert img != null; img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f)); holder.account_dn.setCompoundDrawables( null, null, img, null); }else{ @@ -132,13 +131,15 @@ public class AccountSearchDevAdapter extends BaseAdapter implements OnPostAction if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + assert account != null; holder.account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true)); holder.account_un.setText(String.format("@%s",account.getAcct())); }else { + assert account != null; holder.account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true)); holder.account_un.setText(String.format("@%s",account.getAcct())); } - changeDrawableColor(context, R.drawable.ic_lock_outline,R.color.mastodonC4); + Helper.changeDrawableColor(context, R.drawable.ic_lock_outline,R.color.mastodonC4); //Profile picture imageLoader.displayImage(account.getAvatar(), holder.account_pp, options); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsFollowRequestAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsFollowRequestAdapter.java index b4923afa6..5a281009e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsFollowRequestAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsFollowRequestAdapter.java @@ -45,7 +45,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java index cafb12e3d..c90207606 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java @@ -39,6 +39,8 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer; import java.io.File; import java.util.ArrayList; import java.util.List; + +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; @@ -46,7 +48,6 @@ 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; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsReplyAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsReplyAdapter.java index b1dcf27ec..947d767d9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsReplyAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsReplyAdapter.java @@ -30,9 +30,10 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer; import java.util.List; + +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.TootActivity; import fr.gouv.etalab.mastodon.client.Entities.Account; -import mastodon.etalab.gouv.fr.mastodon.R; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java index 9dabde5e0..87cba4582 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java @@ -35,12 +35,14 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer; import java.util.ArrayList; import java.util.List; + +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Mention; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; + /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/CustomEmojiAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/CustomEmojiAdapter.java index 80c501f0c..9bcf4be5e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/CustomEmojiAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/CustomEmojiAdapter.java @@ -38,7 +38,7 @@ import java.util.List; import fr.gouv.etalab.mastodon.client.Entities.Emojis; import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** * Created by Thomas on 03/11/2017. diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java index e2bfb5f42..02ccea719 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java @@ -38,7 +38,7 @@ import fr.gouv.etalab.mastodon.client.Entities.StoredStatus; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/EmojisSearchAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/EmojisSearchAdapter.java index 79d738b96..24be9505b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/EmojisSearchAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/EmojisSearchAdapter.java @@ -33,8 +33,9 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.client.Entities.Emojis; -import mastodon.etalab.gouv.fr.mastodon.R; + /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index a1c1b518b..1c3b44c86 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -57,6 +57,7 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.MediaActivity; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; import fr.gouv.etalab.mastodon.activities.ShowConversationActivity; @@ -73,7 +74,6 @@ import fr.gouv.etalab.mastodon.helper.CrossActions; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; import fr.gouv.etalab.mastodon.interfaces.OnPostNotificationsActionInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface; -import mastodon.etalab.gouv.fr.mastodon.R; import fr.gouv.etalab.mastodon.client.Entities.Notification; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.helper.Helper; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java index caeb334de..b6d0eed00 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ScheduledTootsListAdapter.java @@ -51,7 +51,7 @@ import fr.gouv.etalab.mastodon.jobs.ApplicationJob; import fr.gouv.etalab.mastodon.jobs.ScheduledTootsSyncJob; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java index 6ad22d594..06c495f03 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java @@ -48,7 +48,7 @@ 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; +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index a94fe79f6..560a7356f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -71,6 +71,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.MediaActivity; import fr.gouv.etalab.mastodon.activities.ShowAccountActivity; import fr.gouv.etalab.mastodon.activities.ShowConversationActivity; @@ -93,7 +94,6 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface; import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface; -import mastodon.etalab.gouv.fr.mastodon.R; import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsListAdapter.java index d587c2439..3990686c5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsListAdapter.java @@ -23,7 +23,7 @@ import android.widget.BaseAdapter; import android.widget.TextView; import java.util.List; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsSearchAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsSearchAdapter.java index bc7739110..4bc81fec9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsSearchAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/TagsSearchAdapter.java @@ -26,7 +26,8 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.List; -import mastodon.etalab.gouv.fr.mastodon.R; + +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java index 7a132a963..8ea0952e9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java @@ -40,7 +40,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Relationship; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveManyRelationshipsInterface; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; import fr.gouv.etalab.mastodon.drawers.AccountsListAdapter; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java index 25a05e050..3db43874d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java @@ -37,7 +37,7 @@ import fr.gouv.etalab.mastodon.drawers.DraftsListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java index 8471a40d8..34e31096d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFollowRequestSentFragment.java @@ -38,7 +38,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.drawers.AccountsFollowRequestAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java index 2f816aa92..83dec2708 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java @@ -33,13 +33,13 @@ import android.widget.Toast; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingNotificationsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingNotificationsInterface; -import mastodon.etalab.gouv.fr.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveNotificationsAsyncTask; import fr.gouv.etalab.mastodon.client.Entities.Notification; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayScheduledTootsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayScheduledTootsFragment.java index 560f7baaa..9a3911035 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayScheduledTootsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayScheduledTootsFragment.java @@ -42,7 +42,7 @@ import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveScheduledTootsInterface; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 7e18449e0..78c9ccc1b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -35,6 +35,7 @@ import android.widget.Toast; import java.util.ArrayList; import java.util.List; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; @@ -43,7 +44,6 @@ import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface; import fr.gouv.etalab.mastodon.services.StreamingFederatedTimelineService; import fr.gouv.etalab.mastodon.services.StreamingLocalTimelineService; -import mastodon.etalab.gouv.fr.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index cc6ef2685..33c571375 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -52,7 +52,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static android.app.Activity.RESULT_OK; import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java index 92415b8c3..7be076a75 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java @@ -16,10 +16,8 @@ package fr.gouv.etalab.mastodon.fragments; import android.app.TimePickerDialog; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; -import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; @@ -41,15 +39,8 @@ import android.widget.TimePicker; import android.widget.Toast; -import java.util.List; - -import fr.gouv.etalab.mastodon.activities.BaseMainActivity; -import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.helper.Helper; -import fr.gouv.etalab.mastodon.services.StreamingService; -import fr.gouv.etalab.mastodon.sqlite.AccountDAO; -import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.compareDate; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsOptimizationFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsOptimizationFragment.java index 74ce6cccb..957617b1f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsOptimizationFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsOptimizationFragment.java @@ -25,7 +25,7 @@ import android.widget.SeekBar; import android.widget.TextView; import fr.gouv.etalab.mastodon.helper.Helper; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java index 769f45ba0..cfc5bd7e2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java @@ -24,7 +24,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java index 5d2487571..04b5d2f62 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java @@ -41,7 +41,7 @@ import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** * Will handle cross actions between accounts boost/favourites/pin and replies diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index ffab82d35..7ca2cfe13 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -123,6 +123,7 @@ import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.HashTagActivity; import fr.gouv.etalab.mastodon.activities.LoginActivity; import fr.gouv.etalab.mastodon.activities.MainActivity; @@ -140,7 +141,6 @@ 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 mastodon.etalab.gouv.fr.mastodon.R; import static android.content.Context.DOWNLOAD_SERVICE; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/HomeTimelineSyncJob.java b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/HomeTimelineSyncJob.java index 5b3379404..916155fff 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/HomeTimelineSyncJob.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/HomeTimelineSyncJob.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.asynctasks.RetrieveHomeTimelineServiceAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; @@ -50,7 +51,7 @@ import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHomeTimelineServiceInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; + import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java index acc58cd8d..5ede03e6f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/jobs/NotificationsSyncJob.java @@ -44,7 +44,7 @@ import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader; import fr.gouv.etalab.mastodon.helper.Helper; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveNotificationsAsyncTask; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Notification; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java new file mode 100644 index 000000000..c7a6a364b --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java @@ -0,0 +1,369 @@ +package fr.gouv.etalab.mastodon.services; +/* 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 Mastalab; if not, + * see . */ +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.database.sqlite.SQLiteDatabase; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.os.IBinder; +import android.os.SystemClock; +import android.support.annotation.Nullable; +import android.support.v4.content.LocalBroadcastManager; +import android.view.View; + + +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 org.json.JSONException; +import org.json.JSONObject; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + + +import javax.net.ssl.HttpsURLConnection; + +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.activities.BaseMainActivity; +import fr.gouv.etalab.mastodon.activities.MainActivity; +import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Notification; +import fr.gouv.etalab.mastodon.client.Entities.Status; +import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader; +import fr.gouv.etalab.mastodon.client.TLSSocketFactory; +import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.sqlite.AccountDAO; +import fr.gouv.etalab.mastodon.sqlite.Sqlite; + +import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; +import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT; +import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID; +import static fr.gouv.etalab.mastodon.helper.Helper.notify_user; + + +/** + * Created by Thomas on 28/08/2017. + * Manage service for streaming api and new notifications + */ + +public class LiveNotificationService extends Service { + + + public enum EventStreaming{ + UPDATE, + NOTIFICATION, + DELETE, + NONE + } + protected Account account; + + private boolean restartCalled; + + public void onCreate() { + super.onCreate(); + restartCalled = false; + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); + boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); + if( liveNotifications && notify){ + SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + List accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccount(); + for(final Account accountStream: accountStreams){ + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + streamOnUser(accountStream); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + thread.start(); + } + } + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Bundle extras = intent.getExtras(); + if(extras != null) { + boolean restart = (boolean) extras.get("restart"); + if( restart) { + SystemClock.sleep(1000); + sendBroadcast(new Intent("RestartStreamingService")); + stopSelf(); + } + } + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + + private void streamOnUser(Account accountStream){ + InputStream inputStream = null; + HttpsURLConnection httpsURLConnection = null; + BufferedReader reader = null; + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + EventStreaming lastEvent = null; + if( accountStream != null){ + try { + URL url = new URL("https://" + accountStream.getInstance() + "/api/v1/streaming/user"); + httpsURLConnection = (HttpsURLConnection) url.openConnection(); + httpsURLConnection.setRequestProperty("Content-Type", "application/json"); + httpsURLConnection.setRequestProperty("Authorization", "Bearer " + accountStream.getToken()); + httpsURLConnection.setRequestProperty("Connection", "Keep-Alive"); + httpsURLConnection.setRequestProperty("Keep-Alive", "header"); + httpsURLConnection.setRequestProperty("Connection", "close"); + httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory()); + httpsURLConnection.setRequestMethod("GET"); + httpsURLConnection.setConnectTimeout(70000); + httpsURLConnection.setReadTimeout(70000); + inputStream = new BufferedInputStream(httpsURLConnection.getInputStream()); + reader = new BufferedReader(new InputStreamReader(inputStream)); + String event; + EventStreaming eventStreaming; + while((event = reader.readLine()) != null) { + if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING, true) ) { + stopSelf(); + return; + } + + if ((lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) { + switch (event.trim()) { + case "event: update": + lastEvent = EventStreaming.UPDATE; + break; + case "event: notification": + lastEvent = EventStreaming.NOTIFICATION; + break; + case "event: delete": + lastEvent = EventStreaming.DELETE; + break; + default: + lastEvent = EventStreaming.NONE; + } + } else { + if (!event.startsWith("data: ")) { + lastEvent = EventStreaming.NONE; + continue; + } + event = event.substring(6); + if (lastEvent == EventStreaming.UPDATE) { + eventStreaming = EventStreaming.UPDATE; + } else if (lastEvent == EventStreaming.NOTIFICATION) { + eventStreaming = EventStreaming.NOTIFICATION; + } else if (lastEvent == EventStreaming.DELETE) { + eventStreaming = EventStreaming.DELETE; + event = "{id:" + event + "}"; + } else { + eventStreaming = EventStreaming.UPDATE; + } + lastEvent = EventStreaming.NONE; + try { + JSONObject eventJson = new JSONObject(event); + onRetrieveStreaming(eventStreaming, accountStream, eventJson); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + }finally { + if(reader != null){ + try{ + reader.close(); + }catch (IOException ignored){} + } + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException ignored) {} + } + if( httpsURLConnection != null) + httpsURLConnection.disconnect(); + if( !restartCalled ) { + restartCalled = true; + SystemClock.sleep(1000); + sendBroadcast(new Intent("RestartStreamingService")); + stopSelf(); + } + } + } + } + + public void onRetrieveStreaming(EventStreaming event, final Account account, JSONObject response) { + if( response == null ) + return; + //No previous notifications in cache, so no notification will be sent + Status status ; + final Notification notification; + String dataId = null; + + Bundle b = new Bundle(); + if( event == EventStreaming.NOTIFICATION){ + notification = API.parseNotificationResponse(getApplicationContext(), response); + b.putParcelable("data", notification); + boolean activityPaused; + try { + activityPaused = BaseMainActivity.activityState(); + }catch (Exception e){ + activityPaused = true; + } + final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); + boolean canNotify = Helper.canNotify(getApplicationContext()); + boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + + if((userId == null || !userId.equals(account.getId()) || activityPaused) && liveNotifications && canNotify && notify) { + boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); + boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); + boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); + boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share); + String title = null; + if( somethingToPush && notification != null){ + switch (notification.getType()){ + case "mention": + if(notif_mention){ + if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) + title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_mention)); + else + title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_mention)); + } + break; + case "reblog": + if(notif_share){ + if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) + title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_reblog)); + else + title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_reblog)); + } + break; + case "favourite": + if(notif_add){ + if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) + title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_favourite)); + else + title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_favourite)); + } + break; + case "follow": + if(notif_follow){ + if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) + title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_follow)); + else + title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_follow)); + } + break; + default: + } + //Some others notification + final Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK ); + intent.putExtra(INTENT_ACTION, NOTIFICATION_INTENT); + intent.putExtra(PREF_KEY_ID, account.getId()); + long notif_id = Long.parseLong(account.getId()); + final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1); + if( notification.getAccount().getAvatar() != null ) { + ImageLoader imageLoaderNoty = ImageLoader.getInstance(); + File cacheDir = new File(getApplicationContext().getCacheDir(), getApplicationContext().getString(R.string.app_name)); + ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) + .imageDownloader(new PatchBaseImageDownloader(getApplicationContext())) + .threadPoolSize(5) + .threadPriority(Thread.MIN_PRIORITY + 3) + .denyCacheImageMultipleSizesInMemory() + .diskCache(new UnlimitedDiskCache(cacheDir)) + .build(); + imageLoaderNoty.init(config); + DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) + .cacheOnDisk(true).resetViewBeforeLoading(true).build(); + + final String finalTitle = title; + if( title != null) { + imageLoaderNoty.loadImage(notification.getAccount().getAvatar(), options, new SimpleImageLoadingListener() { + @Override + public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { + super.onLoadingComplete(imageUri, view, loadedImage); + notify_user(getApplicationContext(), intent, notificationId, loadedImage, finalTitle, "@"+account.getAcct()+"@"+account.getInstance()); + String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); + if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), notification.getId()); + editor.apply(); + } + } + + @Override + public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason) { + notify_user(getApplicationContext(), intent, notificationId, BitmapFactory.decodeResource(getApplicationContext().getResources(), + R.drawable.mastodonlogo), finalTitle, "@"+account.getAcct()+"@"+account.getInstance()); + String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); + if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), notification.getId()); + editor.apply(); + } + } + }); + } + } + } + } + }else if ( event == EventStreaming.UPDATE){ + status = API.parseStatuses(getApplicationContext(), response); + status.setReplies(new ArrayList()); + status.setNew(true); + b.putParcelable("data", status); + }else if( event == EventStreaming.DELETE){ + try { + dataId = response.getString("id"); + } catch (JSONException e) { + e.printStackTrace(); + } + } + if( account != null) + b.putString("userIdService",account.getId()); + Intent intentBC = new Intent(Helper.RECEIVE_DATA); + intentBC.putExtra("eventStreaming", event); + intentBC.putExtras(b); + LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentBC); + } + +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartLiveNotificationReceiver.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartLiveNotificationReceiver.java new file mode 100644 index 000000000..2c03fa8ff --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartLiveNotificationReceiver.java @@ -0,0 +1,43 @@ +package fr.gouv.etalab.mastodon.services; +/* 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 Mastalab; if not, + * see . */ +import android.annotation.SuppressLint; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; + +import fr.gouv.etalab.mastodon.helper.Helper; + +/** + * Created by Thomas on 22/09/2017. + * BroadcastReceiver for restarting the service + */ + +public class RestartLiveNotificationReceiver extends BroadcastReceiver { + + @SuppressLint("UnsafeProtectedBroadcastReceiver") + @Override + public void onReceive(Context context, Intent intent) { + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); + boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); + if( notify && liveNotifications) { + Intent streamingServiceIntent = new Intent(context.getApplicationContext(), LiveNotificationService.class); + context.startService(streamingServiceIntent); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartServiceReceiver.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartServiceReceiver.java index b826204f0..318e131b0 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartServiceReceiver.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/RestartServiceReceiver.java @@ -13,13 +13,9 @@ package fr.gouv.etalab.mastodon.services; * * You should have received a copy of the GNU General Public License along with Mastalab; if not, * see . */ -import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; - -import fr.gouv.etalab.mastodon.helper.Helper; /** * Created by Thomas on 22/09/2017. @@ -28,16 +24,10 @@ import fr.gouv.etalab.mastodon.helper.Helper; public class RestartServiceReceiver extends BroadcastReceiver { - @SuppressLint("UnsafeProtectedBroadcastReceiver") @Override public void onReceive(Context context, Intent intent) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); - boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); - if( notify && liveNotifications) { - Intent streamingServiceIntent = new Intent(context.getApplicationContext(), StreamingService.class); - context.startService(streamingServiceIntent); - } + Intent streamingServiceIntent = new Intent(context.getApplicationContext(), StreamingService.class); + context.startService(streamingServiceIntent); } } \ No newline at end of file diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingFederatedTimelineService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingFederatedTimelineService.java index bf259dfb3..210bc2807 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingFederatedTimelineService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingFederatedTimelineService.java @@ -40,7 +40,6 @@ import javax.net.ssl.HttpsURLConnection; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; -import fr.gouv.etalab.mastodon.client.Entities.Notification; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.client.TLSSocketFactory; import fr.gouv.etalab.mastodon.helper.Helper; @@ -61,9 +60,11 @@ public class StreamingFederatedTimelineService extends IntentService { * * @param name Used to name the worker thread, important only for debugging. */ + @SuppressWarnings("unused") public StreamingFederatedTimelineService(String name) { super(name); } + @SuppressWarnings("unused") public StreamingFederatedTimelineService() { super("StreamingFederatedTimelineService"); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingLocalTimelineService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingLocalTimelineService.java index 1fba974e0..e850661e5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingLocalTimelineService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingLocalTimelineService.java @@ -59,9 +59,11 @@ public class StreamingLocalTimelineService extends IntentService { * * @param name Used to name the worker thread, important only for debugging. */ + @SuppressWarnings("unused") public StreamingLocalTimelineService(String name) { super(name); } + @SuppressWarnings("unused") public StreamingLocalTimelineService() { super("StreamingLocalTimelineService"); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java index 1f465fa7f..0ba245706 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java @@ -13,61 +13,37 @@ package fr.gouv.etalab.mastodon.services; * * You should have received a copy of the GNU General Public License along with Mastalab; if not, * see . */ -import android.app.Service; +import android.app.IntentService; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.os.Bundle; -import android.os.IBinder; import android.os.SystemClock; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; -import android.view.View; -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 org.json.JSONException; import org.json.JSONObject; import java.io.BufferedInputStream; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; -import java.util.List; - import javax.net.ssl.HttpsURLConnection; -import fr.gouv.etalab.mastodon.activities.BaseMainActivity; -import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Notification; import fr.gouv.etalab.mastodon.client.Entities.Status; -import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader; import fr.gouv.etalab.mastodon.client.TLSSocketFactory; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import mastodon.etalab.gouv.fr.mastodon.R; - -import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; -import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT; -import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID; -import static fr.gouv.etalab.mastodon.helper.Helper.notify_user; /** @@ -75,9 +51,25 @@ import static fr.gouv.etalab.mastodon.helper.Helper.notify_user; * Manage service for streaming api and new notifications */ -public class StreamingService extends Service { +public class StreamingService extends IntentService { + private EventStreaming lastEvent; + /** + * Creates an IntentService. Invoked by your subclass's constructor. + * + * @param name Used to name the worker thread, important only for debugging. + */ + @SuppressWarnings("unused") + public StreamingService(String name) { + super(name); + } + @SuppressWarnings("unused") + public StreamingService() { + super("StreamingService"); + } + + private static HttpsURLConnection httpsURLConnection; public enum EventStreaming{ UPDATE, NOTIFICATION, @@ -86,62 +78,32 @@ public class StreamingService extends Service { } protected Account account; - private boolean restartCalled; - public void onCreate() { super.onCreate(); - restartCalled = false; SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); - boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); - if( liveNotifications && notify){ - SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - List accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccount(); - for(final Account accountStream: accountStreams){ - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - try { - streamOnUser(accountStream); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - thread.start(); - } - } + SharedPreferences.Editor editor = sharedpreferences.edit(); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING+userId, true); + editor.apply(); } + @Override - public int onStartCommand(Intent intent, int flags, int startId) { - Bundle extras = intent.getExtras(); - if(extras != null) { - boolean restart = (boolean) extras.get("restart"); - if( restart) { - SystemClock.sleep(1000); - sendBroadcast(new Intent("RestartStreamingService")); - stopSelf(); - } - } - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } - - - private void streamOnUser(Account accountStream){ - InputStream inputStream = null; - HttpsURLConnection httpsURLConnection = null; + protected void onHandleIntent(@Nullable Intent intent) { + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + InputStream inputStream; BufferedReader reader = null; - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - EventStreaming lastEvent = null; + Account accountStream = null; + if( httpsURLConnection != null) + httpsURLConnection.disconnect(); + if( userId != null) { + SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + accountStream = new AccountDAO(getApplicationContext(), db).getAccountByID(userId); + } if( accountStream != null){ try { + URL url = new URL("https://" + accountStream.getInstance() + "/api/v1/streaming/user"); httpsURLConnection = (HttpsURLConnection) url.openConnection(); httpsURLConnection.setRequestProperty("Content-Type", "application/json"); @@ -158,11 +120,8 @@ public class StreamingService extends Service { String event; EventStreaming eventStreaming; while((event = reader.readLine()) != null) { - if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING, true) ) { + if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId(), true) ) stopSelf(); - return; - } - if ((lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) { switch (event.trim()) { case "event: update": @@ -208,144 +167,29 @@ public class StreamingService extends Service { if(reader != null){ try{ reader.close(); - }catch (IOException ignored){} - } - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException ignored) {} - } - if( httpsURLConnection != null) - httpsURLConnection.disconnect(); - if( !restartCalled ) { - restartCalled = true; - SystemClock.sleep(1000); - sendBroadcast(new Intent("RestartStreamingService")); - stopSelf(); + }catch (IOException e){ + e.printStackTrace(); + } } + SystemClock.sleep(1000); + sendBroadcast(new Intent("RestartStreamingService")); } } } - public void onRetrieveStreaming(EventStreaming event, final Account account, JSONObject response) { + public void onRetrieveStreaming(EventStreaming event, Account account, JSONObject response) { if( response == null ) return; //No previous notifications in cache, so no notification will be sent Status status ; - final Notification notification; + Notification notification; + //noinspection unused String dataId = null; Bundle b = new Bundle(); if( event == EventStreaming.NOTIFICATION){ notification = API.parseNotificationResponse(getApplicationContext(), response); b.putParcelable("data", notification); - boolean activityPaused; - try { - activityPaused = BaseMainActivity.activityState(); - }catch (Exception e){ - activityPaused = true; - } - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); - boolean canNotify = Helper.canNotify(getApplicationContext()); - boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - - if((userId == null || !userId.equals(account.getId()) || activityPaused) && liveNotifications && canNotify && notify) { - boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); - boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); - boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); - boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); - boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share); - String title = null; - if( somethingToPush && notification != null){ - switch (notification.getType()){ - case "mention": - if(notif_mention){ - if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) - title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_mention)); - else - title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_mention)); - } - break; - case "reblog": - if(notif_share){ - if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) - title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_reblog)); - else - title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_reblog)); - } - break; - case "favourite": - if(notif_add){ - if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) - title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_favourite)); - else - title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_favourite)); - } - break; - case "follow": - if(notif_follow){ - if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 ) - title = String.format("@%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getApplicationContext().getString(R.string.notif_follow)); - else - title = String.format("@%s %s", notification.getAccount().getUsername(),getApplicationContext().getString(R.string.notif_follow)); - } - break; - default: - } - //Some others notification - final Intent intent = new Intent(getApplicationContext(), MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK ); - intent.putExtra(INTENT_ACTION, NOTIFICATION_INTENT); - intent.putExtra(PREF_KEY_ID, account.getId()); - long notif_id = Long.parseLong(account.getId()); - final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1); - if( notification.getAccount().getAvatar() != null ) { - ImageLoader imageLoaderNoty = ImageLoader.getInstance(); - File cacheDir = new File(getApplicationContext().getCacheDir(), getApplicationContext().getString(R.string.app_name)); - ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) - .imageDownloader(new PatchBaseImageDownloader(getApplicationContext())) - .threadPoolSize(5) - .threadPriority(Thread.MIN_PRIORITY + 3) - .denyCacheImageMultipleSizesInMemory() - .diskCache(new UnlimitedDiskCache(cacheDir)) - .build(); - imageLoaderNoty.init(config); - DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) - .cacheOnDisk(true).resetViewBeforeLoading(true).build(); - - final String finalTitle = title; - if( title != null) { - imageLoaderNoty.loadImage(notification.getAccount().getAvatar(), options, new SimpleImageLoadingListener() { - @Override - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - super.onLoadingComplete(imageUri, view, loadedImage); - notify_user(getApplicationContext(), intent, notificationId, loadedImage, finalTitle, "@"+account.getAcct()+"@"+account.getInstance()); - String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); - if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), notification.getId()); - editor.apply(); - } - } - - @Override - public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason) { - notify_user(getApplicationContext(), intent, notificationId, BitmapFactory.decodeResource(getApplicationContext().getResources(), - R.drawable.mastodonlogo), finalTitle, "@"+account.getAcct()+"@"+account.getInstance()); - String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); - if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), notification.getId()); - editor.apply(); - } - } - }); - } - } - } - } }else if ( event == EventStreaming.UPDATE){ status = API.parseStatuses(getApplicationContext(), response); status.setReplies(new ArrayList()); @@ -353,6 +197,7 @@ public class StreamingService extends Service { b.putParcelable("data", status); }else if( event == EventStreaming.DELETE){ try { + //noinspection UnusedAssignment dataId = response.getString("id"); } catch (JSONException e) { e.printStackTrace(); @@ -366,4 +211,4 @@ public class StreamingService extends Service { LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentBC); } -} +} \ No newline at end of file diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/translation/Translate.java b/app/src/main/java/fr/gouv/etalab/mastodon/translation/Translate.java index 9140e806b..4a5c24cca 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/translation/Translate.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/translation/Translate.java @@ -32,10 +32,10 @@ import java.util.Iterator; import java.util.Map; import java.util.regex.Matcher; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface; -import mastodon.etalab.gouv.fr.mastodon.R; import static fr.gouv.etalab.mastodon.activities.BaseMainActivity.currentLocale; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebChromeClient.java b/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebChromeClient.java index dabd78c3a..a7a00eeec 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebChromeClient.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebChromeClient.java @@ -30,7 +30,7 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** * Created by Thomas on 25/06/2017. diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebViewClient.java b/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebViewClient.java index dced8229c..5285336f0 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebViewClient.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebViewClient.java @@ -25,7 +25,7 @@ import android.webkit.WebViewClient; import android.widget.TextView; import fr.gouv.etalab.mastodon.activities.WebviewActivity; -import mastodon.etalab.gouv.fr.mastodon.R; +import fr.gouv.etalab.mastodon.R; /** * Created by Thomas on 25/06/2017.