Only connected account receives live events
This commit is contained in:
parent
0fc3214390
commit
9b8c6635e7
|
@ -16,10 +16,12 @@ package fr.gouv.etalab.mastodon.activities;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
|
@ -27,6 +29,7 @@ import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
|
@ -38,7 +41,6 @@ import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -146,20 +148,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
||||||
if(notificationsFragment != null){
|
if(notificationsFragment != null){
|
||||||
if(notificationsFragment.getUserVisibleHint() && isActivityVisible()){
|
|
||||||
notificationsFragment.showNewContent();
|
|
||||||
}else{
|
|
||||||
notificationsFragment.refresh();
|
notificationsFragment.refresh();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
||||||
if( homeFragment != null){
|
if( homeFragment != null){
|
||||||
if(homeFragment.getUserVisibleHint() && isActivityVisible()){
|
|
||||||
homeFragment.showNewContent();
|
|
||||||
}else{
|
|
||||||
homeFragment.refresh();
|
homeFragment.refresh();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
||||||
String id = b.getString("id");
|
String id = b.getString("id");
|
||||||
if(notificationsFragment != null) {
|
if(notificationsFragment != null) {
|
||||||
|
@ -174,6 +168,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
updateHomeCounter();
|
updateHomeCounter();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Intent intentService = new Intent(this, StreamingService.class);
|
||||||
|
bindService(intentService, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
||||||
|
|
||||||
|
|
||||||
|
@ -900,6 +896,37 @@ public class MainActivity extends AppCompatActivity
|
||||||
new UpdateAccountInfoByIDAsyncTask(getApplicationContext(), MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new UpdateAccountInfoByIDAsyncTask(getApplicationContext(), MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StreamingService streamingService = null;
|
||||||
|
boolean mBound = false;
|
||||||
|
private ServiceConnection serviceConnection = new ServiceConnection() {
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
|
StreamingService.StreamingServiceBinder binder = (StreamingService.StreamingServiceBinder) service;
|
||||||
|
streamingService = binder.getService();
|
||||||
|
mBound = true;
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(MainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||||
|
streamingService.connect(account);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName arg0) {
|
||||||
|
mBound = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@ -909,6 +936,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(){
|
public void onDestroy(){
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
if( streamingService != null)
|
||||||
|
streamingService.disconnect();
|
||||||
|
if (mBound) {
|
||||||
|
unbindService(serviceConnection);
|
||||||
|
mBound = false;
|
||||||
|
}
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="fr.gouv.etalab.mastodon.activities.MainApplication"
|
android:name="fr.gouv.etalab.mastodon.activities.MainApplication"
|
||||||
|
@ -38,11 +37,7 @@
|
||||||
<service
|
<service
|
||||||
android:name="fr.gouv.etalab.mastodon.services.StreamingService"
|
android:name="fr.gouv.etalab.mastodon.services.StreamingService"
|
||||||
android:exported="false"/>
|
android:exported="false"/>
|
||||||
<receiver android:name="fr.gouv.etalab.mastodon.services.BootService" >
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="fr.gouv.etalab.mastodon.activities.MainActivity"
|
android:name="fr.gouv.etalab.mastodon.activities.MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
|
|
@ -67,7 +67,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
private boolean swiped;
|
private boolean swiped;
|
||||||
private ListView lv_notifications;
|
private ListView lv_notifications;
|
||||||
private TextView new_data;
|
|
||||||
|
|
||||||
public DisplayNotificationsFragment(){
|
public DisplayNotificationsFragment(){
|
||||||
}
|
}
|
||||||
|
@ -86,7 +85,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
|
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
lv_notifications = (ListView) rootView.findViewById(R.id.lv_notifications);
|
lv_notifications = (ListView) rootView.findViewById(R.id.lv_notifications);
|
||||||
new_data = (TextView) rootView.findViewById(R.id.new_data);
|
|
||||||
mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
|
mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
|
||||||
nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_notifications);
|
nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_notifications);
|
||||||
textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
|
textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
|
||||||
|
@ -123,7 +121,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
new_data.setVisibility(View.GONE);
|
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -133,33 +130,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
|
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
new_data.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
notificationsTmp = Helper.getTempNotification(context, null);
|
|
||||||
if( notificationsTmp != null){
|
|
||||||
for(int i = notificationsTmp.size() -1 ; i >= 0 ; i--){
|
|
||||||
notifications.add(0,notificationsTmp.get(i));
|
|
||||||
}
|
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
|
||||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
|
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
|
||||||
if( notificationsTmp.size() > 0){
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationsTmp.get(0).getId());
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
if( notificationsTmp.size() > 0 && textviewNoAction.getVisibility() == View.VISIBLE)
|
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
new_data.setVisibility(View.GONE);
|
|
||||||
notificationsTmp = new ArrayList<>();
|
|
||||||
Helper.cacheNotificationsClear(context, null);
|
|
||||||
((MainActivity) context).updateNotifCounter();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
@ -190,27 +160,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
//New data are available
|
refresh();
|
||||||
notificationsTmp = Helper.getTempNotification(context, null);
|
|
||||||
if (getUserVisibleHint() && notificationsTmp != null && notificationsTmp.size() > 0 && notifications.size() > 0) {
|
|
||||||
ArrayList<String> added = new ArrayList<>();
|
|
||||||
for(Notification notification : notifications){
|
|
||||||
added.add(notification.getId());
|
|
||||||
}
|
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
|
||||||
for(int i = notificationsTmp.size() -1 ; i >= 0 ; i--){
|
|
||||||
if( !added.contains(notificationsTmp.get(i).getId())) {
|
|
||||||
this.notifications.add(0, notificationsTmp.get(i));
|
|
||||||
added.add(notificationsTmp.get(i).getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( this.notifications.size() > 0 )
|
|
||||||
max_id = this.notifications.get(this.notifications.size()-1).getId();
|
|
||||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
|
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -288,10 +238,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void showNewContent(){
|
|
||||||
new_data.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
if( context == null)
|
if( context == null)
|
||||||
return;
|
return;
|
||||||
|
@ -321,6 +267,5 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
textviewNoAction.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
new_data.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import android.view.ViewGroup;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -76,7 +75,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
private boolean isOnWifi;
|
private boolean isOnWifi;
|
||||||
private int behaviorWithAttachments;
|
private int behaviorWithAttachments;
|
||||||
private boolean showMediaOnly;
|
private boolean showMediaOnly;
|
||||||
private TextView new_data;
|
|
||||||
private int positionSpinnerTrans;
|
private int positionSpinnerTrans;
|
||||||
private boolean hideHeader;
|
private boolean hideHeader;
|
||||||
private String instanceValue;
|
private String instanceValue;
|
||||||
|
@ -128,7 +126,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
|
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
|
||||||
lv_status.setAdapter(statusListAdapter);
|
lv_status.setAdapter(statusListAdapter);
|
||||||
new_data = (TextView) rootView.findViewById(R.id.new_data);
|
|
||||||
if( !comesFromSearch){
|
if( !comesFromSearch){
|
||||||
|
|
||||||
//Hide account header when scrolling for ShowAccountActivity
|
//Hide account header when scrolling for ShowAccountActivity
|
||||||
|
@ -188,7 +185,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
new_data.setVisibility(View.GONE);
|
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||||
|
@ -215,35 +211,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_data.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
statusesTmp = Helper.getTempStatus(context, null);
|
|
||||||
if( statusesTmp != null){
|
|
||||||
for(int i = statusesTmp.size() -1 ; i >= 0 ; i--){
|
|
||||||
statuses.add(0,statusesTmp.get(i));
|
|
||||||
}
|
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
|
||||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
|
||||||
lv_status.setAdapter(statusListAdapter);
|
|
||||||
if( statusesTmp.size() > 0){
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statusesTmp.get(0).getId());
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
if( statusesTmp.size() > 0 && textviewNoAction.getVisibility() == View.VISIBLE)
|
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
new_data.setVisibility(View.GONE);
|
|
||||||
statusesTmp = new ArrayList<>();
|
|
||||||
Helper.cacheStatusClear(context, null);
|
|
||||||
((MainActivity) context).updateHomeCounter();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,30 +226,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
refresh();
|
||||||
//New data are available
|
|
||||||
statusesTmp = Helper.getTempStatus(context, null);
|
|
||||||
if (getUserVisibleHint() && statusesTmp != null && statusesTmp.size() > 0 && statuses.size() > 0) {
|
|
||||||
ArrayList<String> added = new ArrayList<>();
|
|
||||||
for (Status status : statuses) {
|
|
||||||
added.add(status.getId());
|
|
||||||
}
|
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
|
||||||
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
|
||||||
for (int i = statusesTmp.size() - 1; i >= 0; i--) {
|
|
||||||
if (!added.contains(statusesTmp.get(i).getId())) {
|
|
||||||
this.statuses.add(0, statusesTmp.get(i));
|
|
||||||
added.add(statusesTmp.get(i).getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.statuses.size() > 0)
|
|
||||||
max_id = this.statuses.get(this.statuses.size() - 1).getId();
|
|
||||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
|
||||||
lv_status.setAdapter(statusListAdapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -372,10 +316,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showNewContent(){
|
|
||||||
new_data.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||||
super.setUserVisibleHint(isVisibleToUser);
|
super.setUserVisibleHint(isVisibleToUser);
|
||||||
|
@ -414,7 +354,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
textviewNoAction.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
new_data.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package fr.gouv.etalab.mastodon.services;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
|
||||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Thomas on 29/08/2017.
|
|
||||||
* BroadcastReceiver to start service when device boot
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class BootService extends BroadcastReceiver {
|
|
||||||
|
|
||||||
public BootService() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
||||||
List<Account> accounts = new AccountDAO(context, db).getAllAccount();
|
|
||||||
if( accounts != null){
|
|
||||||
for (Account account: accounts) {
|
|
||||||
Intent intentService = new Intent(context, StreamingService.class);
|
|
||||||
intentService.putExtra("acccountId", account.getId());
|
|
||||||
intentService.putExtra("accountAcct", account.getAcct());
|
|
||||||
context.startService(intentService);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -24,6 +24,8 @@ import android.os.IBinder;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
@ -78,9 +80,15 @@ public class StreamingService extends Service {
|
||||||
|
|
||||||
|
|
||||||
public void disconnect(){
|
public void disconnect(){
|
||||||
if( httpsURLConnection != null)
|
Thread readThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if( httpsURLConnection != null){
|
||||||
httpsURLConnection.disconnect();
|
httpsURLConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
}});
|
||||||
|
readThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,6 +173,7 @@ public class StreamingService extends Service {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (event !=null){
|
if (event !=null){
|
||||||
|
|
||||||
if( (lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
if( (lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
||||||
switch (event.trim()) {
|
switch (event.trim()) {
|
||||||
case "event: update":
|
case "event: update":
|
||||||
|
|
|
@ -80,18 +80,5 @@
|
||||||
android:indeterminate="true" />
|
android:indeterminate="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:visibility="gone"
|
|
||||||
android:background="@color/mastodonC3"
|
|
||||||
android:textColor="@color/mastodonC1"
|
|
||||||
android:clickable="true"
|
|
||||||
android:padding="10dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/new_data"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:id="@+id/new_data"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
|
@ -78,19 +78,5 @@
|
||||||
android:indeterminate="true" />
|
android:indeterminate="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:visibility="gone"
|
|
||||||
android:padding="10dp"
|
|
||||||
android:background="@color/mastodonC3"
|
|
||||||
android:textColor="@color/mastodonC1"
|
|
||||||
android:clickable="true"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/new_data"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:id="@+id/new_data"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
|
@ -79,19 +79,5 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:indeterminate="true" />
|
android:indeterminate="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:background="@color/mastodonC3"
|
|
||||||
android:textColor="@color/mastodonC1"
|
|
||||||
android:clickable="true"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:padding="10dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/new_data"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:id="@+id/new_data"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
|
@ -77,20 +77,5 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:indeterminate="true" />
|
android:indeterminate="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:visibility="gone"
|
|
||||||
android:background="@color/mastodonC3"
|
|
||||||
android:textColor="@color/mastodonC1"
|
|
||||||
android:clickable="true"
|
|
||||||
android:padding="10dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/new_data"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:id="@+id/new_data"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Messenger;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
|
@ -152,20 +151,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
||||||
if(notificationsFragment != null){
|
if(notificationsFragment != null){
|
||||||
if(notificationsFragment.getUserVisibleHint() && isActivityVisible()){
|
|
||||||
notificationsFragment.showNewContent();
|
|
||||||
}else{
|
|
||||||
notificationsFragment.refresh();
|
notificationsFragment.refresh();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
||||||
if( homeFragment != null){
|
if( homeFragment != null){
|
||||||
if(homeFragment.getUserVisibleHint() && isActivityVisible()){
|
|
||||||
homeFragment.showNewContent();
|
|
||||||
}else{
|
|
||||||
homeFragment.refresh();
|
homeFragment.refresh();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
||||||
String id = b.getString("id");
|
String id = b.getString("id");
|
||||||
if(notificationsFragment != null) {
|
if(notificationsFragment != null) {
|
||||||
|
@ -180,6 +171,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
updateHomeCounter();
|
updateHomeCounter();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Intent intentService = new Intent(this, StreamingService.class);
|
||||||
|
bindService(intentService, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
||||||
|
|
||||||
|
|
||||||
|
@ -931,29 +924,28 @@ public class MainActivity extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Intent intent = new Intent(this, StreamingService.class);
|
|
||||||
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
if (mBound) {
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
mBound = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
MainActivity.activityPaused();
|
MainActivity.activityPaused();
|
||||||
if( streamingService != null)
|
|
||||||
streamingService.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy(){
|
public void onDestroy(){
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
if( streamingService != null)
|
||||||
|
streamingService.disconnect();
|
||||||
|
if (mBound) {
|
||||||
|
unbindService(serviceConnection);
|
||||||
|
mBound = false;
|
||||||
|
}
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue