Merge remote-tracking branch 'remotes/tom-repo/develop' into PinningToots
This commit is contained in:
commit
9c77466915
|
@ -16,10 +16,12 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.PorterDuff;
|
||||
|
@ -27,6 +29,7 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
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.widget.SearchView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -75,6 +77,8 @@ import java.util.regex.Matcher;
|
|||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMetaDataAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
|
||||
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.fragments.DisplayAccountsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
||||
|
@ -129,6 +133,8 @@ public class MainActivity extends AppCompatActivity
|
|||
private DisplayNotificationsFragment notificationsFragment;
|
||||
private BroadcastReceiver receive_data;
|
||||
private boolean display_local, display_global;
|
||||
public static int countNewStatus = 0;
|
||||
public static int countNewNotifications = 0;
|
||||
|
||||
public MainActivity() {
|
||||
}
|
||||
|
@ -146,19 +152,15 @@ public class MainActivity extends AppCompatActivity
|
|||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
||||
if(notificationsFragment != null){
|
||||
if(notificationsFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
notificationsFragment.showNewContent();
|
||||
}else{
|
||||
notificationsFragment.refresh();
|
||||
}
|
||||
Notification notification = b.getParcelable("data");
|
||||
notificationsFragment.refresh(notification);
|
||||
countNewNotifications++;
|
||||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
||||
Status status = b.getParcelable("data");
|
||||
if( homeFragment != null){
|
||||
if(homeFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
homeFragment.showNewContent();
|
||||
}else{
|
||||
homeFragment.refresh();
|
||||
}
|
||||
homeFragment.refresh(status);
|
||||
countNewStatus++;
|
||||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
||||
String id = b.getString("id");
|
||||
|
@ -174,6 +176,8 @@ public class MainActivity extends AppCompatActivity
|
|||
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));
|
||||
|
||||
|
||||
|
@ -261,6 +265,12 @@ public class MainActivity extends AppCompatActivity
|
|||
tabLayout.addTab(tabPublic);
|
||||
|
||||
viewPager = (ViewPager) findViewById(R.id.viewpager);
|
||||
int countPage = 2;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
|
||||
countPage++;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
|
||||
countPage++;
|
||||
viewPager.setOffscreenPageLimit(countPage);
|
||||
main_app_container = (RelativeLayout) findViewById(R.id.main_app_container);
|
||||
PagerAdapter adapter = new PagerAdapter
|
||||
(getSupportFragmentManager(), tabLayout.getTabCount());
|
||||
|
@ -287,21 +297,10 @@ public class MainActivity extends AppCompatActivity
|
|||
if( tab.getPosition() == 0) {
|
||||
item = navigationView.getMenu().findItem(R.id.nav_home);
|
||||
fragmentTag = "HOME_TIMELINE";
|
||||
if (homeFragment != null && Helper.getUnreadToots(getApplicationContext(), null) > 0) {
|
||||
homeFragment.refresh();
|
||||
}
|
||||
Helper.cacheStatusClear(getApplicationContext(), null);
|
||||
updateHomeCounter();
|
||||
}else if( tab.getPosition() == 1) {
|
||||
fragmentTag = "NOTIFICATIONS";
|
||||
item = navigationView.getMenu().findItem(R.id.nav_notification);
|
||||
if (notificationsFragment != null && Helper.getUnreadNotifications(getApplicationContext(), null) > 0) {
|
||||
notificationsFragment.refresh();
|
||||
}
|
||||
Helper.cacheNotificationsClear(getApplicationContext(), null);
|
||||
updateNotifCounter();
|
||||
}else if( tab.getPosition() == 2 && display_local) {
|
||||
|
||||
fragmentTag = "LOCAL_TIMELINE";
|
||||
item = navigationView.getMenu().findItem(R.id.nav_local);
|
||||
}else if( tab.getPosition() == 2 && !display_local) {
|
||||
|
@ -347,10 +346,10 @@ public class MainActivity extends AppCompatActivity
|
|||
switch (tab.getPosition()){
|
||||
case 0:
|
||||
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||
countNewStatus = 0;
|
||||
updateHomeCounter();
|
||||
if( displayStatusFragment != null )
|
||||
displayStatusFragment.scrollToTop();
|
||||
Helper.cacheStatusClear(getApplicationContext(), null);
|
||||
updateHomeCounter();
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
|
@ -360,10 +359,10 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
case 1:
|
||||
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
||||
countNewNotifications = 0;
|
||||
updateNotifCounter();
|
||||
if( displayNotificationsFragment != null )
|
||||
displayNotificationsFragment.scrollToTop();
|
||||
Helper.cacheNotificationsClear(getApplicationContext(), null);
|
||||
updateNotifCounter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -900,6 +899,37 @@ public class MainActivity extends AppCompatActivity
|
|||
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
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
@ -909,6 +939,12 @@ public class MainActivity extends AppCompatActivity
|
|||
@Override
|
||||
public void onDestroy(){
|
||||
super.onDestroy();
|
||||
if( streamingService != null)
|
||||
streamingService.disconnect();
|
||||
if (mBound) {
|
||||
unbindService(serviceConnection);
|
||||
mBound = false;
|
||||
}
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
||||
}
|
||||
|
||||
|
@ -1124,8 +1160,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if( tabHome == null)
|
||||
return;
|
||||
TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter);
|
||||
tabCounterHome.setText(String.valueOf(Helper.getUnreadToots(getApplicationContext(), null)));
|
||||
if( Helper.getUnreadToots(getApplicationContext(), null) > 0){
|
||||
tabCounterHome.setText(String.valueOf(countNewStatus));
|
||||
if( countNewStatus> 0){
|
||||
//New data are available
|
||||
//The fragment is not displayed, so the counter is displayed
|
||||
tabCounterHome.setVisibility(View.VISIBLE);
|
||||
|
@ -1142,8 +1178,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if( tabNotif == null)
|
||||
return;
|
||||
TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter);
|
||||
tabCounterNotif.setText(String.valueOf(Helper.getUnreadNotifications(getApplicationContext(), null)));
|
||||
if( Helper.getUnreadNotifications(getApplicationContext(), null) > 0){
|
||||
tabCounterNotif.setText(String.valueOf(countNewNotifications));
|
||||
if( countNewNotifications > 0){
|
||||
tabCounterNotif.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
tabCounterNotif.setVisibility(View.GONE);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:name="fr.gouv.etalab.mastodon.activities.MainApplication"
|
||||
|
@ -38,11 +37,7 @@
|
|||
<service
|
||||
android:name="fr.gouv.etalab.mastodon.services.StreamingService"
|
||||
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
|
||||
android:name="fr.gouv.etalab.mastodon.activities.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
|
|
|
@ -15,6 +15,7 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
|
@ -216,7 +217,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
holder.status_prev4_container = (RelativeLayout) convertView.findViewById(R.id.status_prev4_container);
|
||||
holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply);
|
||||
holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy);
|
||||
holder.status_translate = (TextView) convertView.findViewById(R.id.status_translate);
|
||||
holder.status_translate = (FloatingActionButton) convertView.findViewById(R.id.status_translate);
|
||||
holder.status_content_translated_container = (LinearLayout) convertView.findViewById(R.id.status_content_translated_container);
|
||||
holder.main_container = (LinearLayout) convertView.findViewById(R.id.main_container);
|
||||
holder.status_spoiler_container = (LinearLayout) convertView.findViewById(R.id.status_spoiler_container);
|
||||
|
@ -290,7 +291,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
if( status.isNew())
|
||||
holder.new_element.setVisibility(View.VISIBLE);
|
||||
else
|
||||
holder.new_element.setVisibility(View.GONE);
|
||||
holder.new_element.setVisibility(View.INVISIBLE);
|
||||
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
|
||||
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
|
||||
|
||||
|
@ -333,7 +334,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
statusListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
holder.status_translate.setPaintFlags(holder.status_translate.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
if( currentLocale != null && status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale) && !status.getLanguage().trim().equals("null")){
|
||||
if (translator != Helper.TRANS_NONE)
|
||||
holder.status_translate.setVisibility(View.VISIBLE);
|
||||
|
@ -1241,7 +1241,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
ImageView status_reply;
|
||||
ImageView status_pin;
|
||||
ImageView status_privacy;
|
||||
TextView status_translate;
|
||||
FloatingActionButton status_translate;
|
||||
LinearLayout status_container2;
|
||||
LinearLayout status_container3;
|
||||
LinearLayout main_container;
|
||||
|
|
|
@ -15,33 +15,24 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter;
|
||||
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
||||
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.asynctasks.RetrieveNotificationsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
|
@ -61,13 +52,14 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private NotificationsListAdapter notificationsListAdapter;
|
||||
private String max_id;
|
||||
private List<Notification> notifications, notificationsTmp;
|
||||
private List<Notification> notifications;
|
||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
private boolean swiped;
|
||||
private ListView lv_notifications;
|
||||
private TextView new_data;
|
||||
private String lastReadNotifications;
|
||||
private String userId;
|
||||
|
||||
public DisplayNotificationsFragment(){
|
||||
}
|
||||
|
@ -86,7 +78,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
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);
|
||||
nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_notifications);
|
||||
textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
|
||||
|
@ -94,6 +85,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
nextElementLoader.setVisibility(View.GONE);
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
lastReadNotifications = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
lv_notifications.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
|
@ -123,7 +116,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
new_data.setVisibility(View.GONE);
|
||||
MainActivity.countNewNotifications = 0;
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
|
@ -133,33 +126,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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -190,34 +156,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
//New data are available
|
||||
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
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if( isVisibleToUser )
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -234,10 +172,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
swiped = false;
|
||||
return;
|
||||
}
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
List<Notification> notifications = apiResponse.getNotifications();
|
||||
String since_id = apiResponse.getSince_id();
|
||||
max_id = apiResponse.getMax_id();
|
||||
List<Notification> notifications = apiResponse.getNotifications();
|
||||
//The initial call comes from a classic tab refresh
|
||||
flag_loading = (max_id == null );
|
||||
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
||||
|
@ -245,42 +181,40 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if( swiped ){
|
||||
Helper.cacheNotificationsClear(context,null);
|
||||
((MainActivity) context).updateNotifCounter();
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, this.notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
swiped = false;
|
||||
}
|
||||
ArrayList<String> added = new ArrayList<>();
|
||||
for(Notification notification : this.notifications){
|
||||
added.add(notification.getId());
|
||||
}
|
||||
if( notifications != null && notifications.size() > 0) {
|
||||
for(Notification tmpNotification: notifications){
|
||||
if( !added.contains(tmpNotification.getId())) {
|
||||
this.notifications.add(tmpNotification);
|
||||
added.add(tmpNotification.getId());
|
||||
}
|
||||
if( Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications))
|
||||
MainActivity.countNewNotifications++;
|
||||
this.notifications.add(tmpNotification);
|
||||
}
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
if( firstLoad )
|
||||
((MainActivity)context).updateNotifCounter();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
//Store last notification id to avoid to notify for those that have been already seen
|
||||
if( notifications != null && notifications.size() > 0) {
|
||||
//acct is null as userId when used in Fragment, data need to be retrieved via shared preferences and db
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( currentAccount != null && firstLoad && since_id != null){
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
firstLoad = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMenuVisibility(final boolean visible) {
|
||||
super.setMenuVisibility(visible);
|
||||
if( context == null)
|
||||
return;
|
||||
//Store last notification id to avoid to notify for those that have been already seen
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
if (visible && notifications != null && notifications.size() > 0) {
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId());
|
||||
editor.apply();
|
||||
lastReadNotifications = notifications.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToTop(){
|
||||
if( lv_notifications != null)
|
||||
|
@ -288,39 +222,18 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
}
|
||||
|
||||
|
||||
public void showNewContent(){
|
||||
new_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void refresh(){
|
||||
public void refresh(Notification notification){
|
||||
if( context == null)
|
||||
return;
|
||||
notificationsTmp = Helper.getTempNotification(context, null);
|
||||
if( notificationsTmp.size() > 0){
|
||||
ArrayList<String> added = new ArrayList<>();
|
||||
for(Notification notification : notifications){
|
||||
added.add(notification.getId());
|
||||
}
|
||||
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();
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
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();
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
if( notification != null){
|
||||
int index = lv_notifications.getFirstVisiblePosition() + 1;
|
||||
View v = lv_notifications.getChildAt(0);
|
||||
int top = (v == null) ? 0 : v.getTop();
|
||||
notifications.add(0, notification);
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
lv_notifications.setSelectionFromTop(index, top);
|
||||
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
}
|
||||
new_data.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import android.view.ViewGroup;
|
|||
import android.widget.AbsListView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -40,12 +39,9 @@ import java.util.List;
|
|||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRepliesAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
|
||||
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.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
|
@ -64,7 +60,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private StatusListAdapter statusListAdapter;
|
||||
private String max_id;
|
||||
private List<Status> statuses, statusesTmp;
|
||||
private List<Status> statuses;
|
||||
private RetrieveFeedsAsyncTask.Type type;
|
||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
|
@ -76,10 +72,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private boolean isOnWifi;
|
||||
private int behaviorWithAttachments;
|
||||
private boolean showMediaOnly;
|
||||
private TextView new_data;
|
||||
private int positionSpinnerTrans;
|
||||
private boolean hideHeader;
|
||||
private String instanceValue;
|
||||
private String lastReadStatus;
|
||||
private String userId;
|
||||
|
||||
public DisplayStatusFragment(){
|
||||
}
|
||||
|
@ -119,7 +116,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
||||
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
|
||||
behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
lastReadStatus = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
lv_status = (ListView) rootView.findViewById(R.id.lv_status);
|
||||
mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
|
||||
nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_status);
|
||||
|
@ -128,7 +126,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
nextElementLoader.setVisibility(View.GONE);
|
||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
|
||||
lv_status.setAdapter(statusListAdapter);
|
||||
new_data = (TextView) rootView.findViewById(R.id.new_data);
|
||||
if( !comesFromSearch){
|
||||
|
||||
//Hide account header when scrolling for ShowAccountActivity
|
||||
|
@ -188,7 +185,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
new_data.setVisibility(View.GONE);
|
||||
MainActivity.countNewStatus = 0;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
|
@ -215,35 +212,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -259,30 +227,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||
//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
|
||||
|
@ -316,7 +260,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
return;
|
||||
}
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
String since_id = apiResponse.getSince_id();
|
||||
max_id = apiResponse.getMax_id();
|
||||
|
||||
flag_loading = (max_id == null );
|
||||
|
@ -325,41 +268,25 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if( swiped ){
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||
Helper.cacheStatusClear(context,null);
|
||||
((MainActivity) context).updateHomeCounter();
|
||||
}
|
||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
|
||||
lv_status.setAdapter(statusListAdapter);
|
||||
swiped = false;
|
||||
}
|
||||
ArrayList<String> added = new ArrayList<>();
|
||||
for(Status status : this.statuses){
|
||||
added.add(status.getId());
|
||||
}
|
||||
if( statuses != null && statuses.size() > 0) {
|
||||
for(Status tmpStatus: statuses){
|
||||
if( !added.contains(tmpStatus.getId())) {
|
||||
this.statuses.add(tmpStatus);
|
||||
added.add(tmpStatus.getId());
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)){
|
||||
tmpStatus.setNew(true);
|
||||
MainActivity.countNewStatus++;
|
||||
}else {
|
||||
tmpStatus.setNew(false);
|
||||
}
|
||||
this.statuses.add(tmpStatus);
|
||||
}
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
if( firstLoad && getActivity() != null && getActivity().getClass().isInstance(MainActivity.class))
|
||||
((MainActivity)context).updateHomeCounter();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
||||
if(statuses != null && statuses.size() > 0 && type == RetrieveFeedsAsyncTask.Type.HOME ){
|
||||
//acct is null when used in Fragment, data need to be retrieved via shared preferences and db
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( currentAccount != null && firstLoad && since_id != null){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + currentAccount.getId(), statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
firstLoad = false;
|
||||
|
||||
//Retrieves replies
|
||||
|
@ -372,49 +299,39 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
}
|
||||
}
|
||||
|
||||
public void showNewContent(){
|
||||
new_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if( isVisibleToUser )
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh(){
|
||||
public void refresh(Status status){
|
||||
//New data are available
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||
if (context == null)
|
||||
return;
|
||||
statusesTmp = Helper.getTempStatus(context, null);
|
||||
if (statusesTmp.size() > 0) {
|
||||
ArrayList<String> added = new ArrayList<>();
|
||||
for (Status status : statuses) {
|
||||
added.add(status.getId());
|
||||
}
|
||||
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();
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
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();
|
||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
||||
lv_status.setAdapter(statusListAdapter);
|
||||
if (status != null) {
|
||||
int index = lv_status.getFirstVisiblePosition() + 1;
|
||||
View v = lv_status.getChildAt(0);
|
||||
int top = (v == null) ? 0 : v.getTop();
|
||||
status.setReplies(new ArrayList<Status>());
|
||||
statuses.add(0,status);
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
lv_status.setSelectionFromTop(index, top);
|
||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
}
|
||||
new_data.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMenuVisibility(final boolean visible) {
|
||||
super.setMenuVisibility(visible);
|
||||
if( context == null)
|
||||
return;
|
||||
|
||||
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
||||
if (type == RetrieveFeedsAsyncTask.Type.HOME && visible && statuses != null && statuses.size() > 0) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||
lastReadStatus = statuses.get(0).getId();
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,7 +349,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
for(Status stmp: modifiedStatus){
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(stmp.getId()))
|
||||
status.setReplies(stmp.getReplies());
|
||||
if( stmp.getReplies() != null )
|
||||
status.setReplies(stmp.getReplies());
|
||||
else
|
||||
status.setReplies(new ArrayList<Status>());
|
||||
}
|
||||
}
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
|
|
|
@ -1601,125 +1601,4 @@ public class Helper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static int getUnreadNotifications(Context context, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Gson gson = new Gson();
|
||||
String json = sharedpreferences.getString(Helper.SET_TEMP_NOTIFICATIONS + userId, null);
|
||||
Type type = new TypeToken<ArrayList<Notification>>() {}.getType();
|
||||
ArrayList<Notification> notifications = gson.fromJson(json, type);
|
||||
return (notifications == null)?0:notifications.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int getUnreadToots(Context context, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Gson gson = new Gson();
|
||||
String json = sharedpreferences.getString(Helper.SET_TEMP_STATUS + userId, null);
|
||||
Type type = new TypeToken<ArrayList<Status>>() {}.getType();
|
||||
ArrayList<Status> statuses = gson.fromJson(json, type);
|
||||
return (statuses == null)?0:statuses.size();
|
||||
}
|
||||
|
||||
|
||||
public static void cacheStatus(Context context, Status status, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
ArrayList<Status> statuses = getTempStatus(context, userId);
|
||||
if( statuses == null)
|
||||
statuses = new ArrayList<>();
|
||||
if( status != null)
|
||||
statuses.add(0,status);
|
||||
Gson gson = new Gson();
|
||||
String serializedAccounts = gson.toJson(statuses);
|
||||
editor.putString(Helper.SET_TEMP_STATUS + userId, serializedAccounts);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void cacheStatusClear(Context context, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
ArrayList<Status> statuses = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
String serializedAccounts = gson.toJson(statuses);
|
||||
editor.putString(Helper.SET_TEMP_STATUS + userId, serializedAccounts);
|
||||
editor.apply();
|
||||
//noinspection EmptyTryBlock
|
||||
try {
|
||||
NotificationManager notificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
long notif_id = Long.parseLong(userId);
|
||||
int notificationId = ((notif_id + 2) > 2147483647) ? (int) (2147483647 - notif_id - 2) : (int) (notif_id + 2);
|
||||
notificationManager.cancel(notificationId);
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
|
||||
public static ArrayList<Status> getTempStatus(Context context, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Gson gson = new Gson();
|
||||
String json = sharedpreferences.getString(Helper.SET_TEMP_STATUS + userId, null);
|
||||
Type type = new TypeToken<ArrayList<Status>>() {}.getType();
|
||||
ArrayList<Status> statuses = gson.fromJson(json, type);
|
||||
return (statuses != null)?statuses:new ArrayList<Status>();
|
||||
}
|
||||
|
||||
|
||||
public static void cacheNotifications(Context context, Notification notification, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
ArrayList<Notification> notifications = getTempNotification(context, userId);
|
||||
if( notifications == null)
|
||||
notifications = new ArrayList<>();
|
||||
if( notification != null)
|
||||
notifications.add(0,notification);
|
||||
Gson gson = new Gson();
|
||||
String serializedAccounts = gson.toJson(notifications);
|
||||
editor.putString(Helper.SET_TEMP_NOTIFICATIONS + userId, serializedAccounts);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void cacheNotificationsClear(Context context, String userId){
|
||||
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
ArrayList<Notification> notifications = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
String serializedAccounts = gson.toJson(notifications);
|
||||
editor.putString(Helper.SET_TEMP_NOTIFICATIONS + userId, serializedAccounts);
|
||||
editor.apply();
|
||||
//noinspection EmptyTryBlock
|
||||
try {
|
||||
NotificationManager notificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
long notif_id = Long.parseLong(userId);
|
||||
int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1);
|
||||
notificationManager.cancel(notificationId);
|
||||
}catch (Exception ignored){}
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<Notification> getTempNotification(Context context, String userId){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( userId == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Gson gson = new Gson();
|
||||
String json = sharedpreferences.getString(Helper.SET_TEMP_NOTIFICATIONS + userId, null);
|
||||
Type type = new TypeToken<ArrayList<Notification>>() {}.getType();
|
||||
ArrayList<Notification> notifications = gson.fromJson(json, type);
|
||||
return (notifications != null)?notifications:new ArrayList<Notification>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,33 +19,18 @@ 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.Build;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.StrictMode;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
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;
|
||||
|
@ -53,29 +38,14 @@ import java.net.URL;
|
|||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
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.HOME_TIMELINE_INTENT;
|
||||
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.canNotify;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.notify_user;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 28/08/2017.
|
||||
|
@ -84,12 +54,10 @@ import static fr.gouv.etalab.mastodon.helper.Helper.notify_user;
|
|||
|
||||
public class StreamingService extends Service {
|
||||
|
||||
private String message;
|
||||
private int notificationId;
|
||||
private Intent intent;
|
||||
private String lastPreviousContent;
|
||||
private static HashMap<String, HttpsURLConnection> connectionHashMap = new HashMap<>();
|
||||
private static HashMap<String, Boolean> isConnectingHashMap = new HashMap<>();
|
||||
|
||||
private boolean isConnectingHashMap = false;
|
||||
private HttpsURLConnection httpsURLConnection;
|
||||
|
||||
private EventStreaming lastEvent;
|
||||
public enum EventStreaming{
|
||||
UPDATE,
|
||||
|
@ -97,45 +65,42 @@ public class StreamingService extends Service {
|
|||
DELETE,
|
||||
NONE
|
||||
}
|
||||
|
||||
private final IBinder iBinder = new StreamingServiceBinder();
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if( intent != null){
|
||||
String accountId = intent.getStringExtra("accountId");
|
||||
String accountAcct = intent.getStringExtra("accountAcct");
|
||||
if( accountId != null && accountAcct != null){
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByIDAcct(accountId, accountAcct);
|
||||
if( account != null)
|
||||
callAsynchronousTask(account);
|
||||
}else {
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accounts = new AccountDAO(getApplicationContext(), db).getAllAccount();
|
||||
if( accounts != null){
|
||||
for (Account account: accounts) {
|
||||
intent = new Intent(getApplicationContext(), StreamingService.class);
|
||||
intent.putExtra("accountId", account.getId());
|
||||
intent.putExtra("accountAcct", account.getAcct());
|
||||
startService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
public class StreamingServiceBinder extends Binder {
|
||||
public StreamingService getService() {
|
||||
return StreamingService.this;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
return iBinder;
|
||||
}
|
||||
|
||||
|
||||
public void disconnect(){
|
||||
Thread readThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if( httpsURLConnection != null){
|
||||
httpsURLConnection.disconnect();
|
||||
}
|
||||
}});
|
||||
readThread.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Task in background starts here.
|
||||
*/
|
||||
private void callAsynchronousTask(final Account account) {
|
||||
public void connect(final Account account) {
|
||||
//If an Internet connection and user agrees with notification refresh
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Check which notifications the user wants to see
|
||||
|
@ -151,7 +116,7 @@ public class StreamingService extends Service {
|
|||
if(!Helper.isLoggedIn(getApplicationContext()))
|
||||
return;
|
||||
//If WIFI only and on WIFI OR user defined any connections to use the service.
|
||||
if( isConnectingHashMap.get(account.getAcct()+account.getId()) != null && isConnectingHashMap.get(account.getAcct()+account.getId()))
|
||||
if( isConnectingHashMap)
|
||||
return;
|
||||
if(!sharedpreferences.getBoolean(Helper.SET_WIFI_ONLY, false) || Helper.isOnWIFI(getApplicationContext())) {
|
||||
Thread readThread = new Thread(new Runnable() {
|
||||
|
@ -159,30 +124,28 @@ public class StreamingService extends Service {
|
|||
public void run() {
|
||||
try {
|
||||
boolean connectionAlive = false;
|
||||
isConnectingHashMap.put(account.getAcct()+account.getId(), true);
|
||||
if( connectionHashMap.get(account.getAcct()+account.getId()) != null) {
|
||||
isConnectingHashMap = true;
|
||||
if( httpsURLConnection != null) {
|
||||
try {
|
||||
connectionAlive = (connectionHashMap.get(account.getAcct()+account.getId()).getResponseCode() == 200);
|
||||
connectionAlive = (httpsURLConnection.getResponseCode() == 200);
|
||||
} catch (Exception e) {
|
||||
connectionAlive = false;
|
||||
}
|
||||
}
|
||||
if( connectionAlive) {
|
||||
HttpsURLConnection httpsURLConnection = connectionHashMap.get(account.getAcct() + account.getId());
|
||||
if( httpsURLConnection != null)
|
||||
httpsURLConnection.disconnect();
|
||||
}
|
||||
try {
|
||||
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
||||
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
|
||||
urlConnection.setRequestProperty("Content-Type", "application/json");
|
||||
urlConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
||||
urlConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
urlConnection.setRequestProperty("Keep-Alive", "header");
|
||||
urlConnection.setRequestProperty("Connection", "close");
|
||||
urlConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
connectionHashMap.put(account.getAcct()+account.getId(), urlConnection);
|
||||
InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
||||
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||
httpsURLConnection.setRequestProperty("Keep-Alive", "header");
|
||||
httpsURLConnection.setRequestProperty("Connection", "close");
|
||||
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
||||
InputStream inputStream = new BufferedInputStream(httpsURLConnection.getInputStream());
|
||||
readStream(inputStream, account);
|
||||
} catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -199,16 +162,13 @@ public class StreamingService extends Service {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private String readStream(InputStream inputStream, final Account account) {
|
||||
BufferedReader reader = null;
|
||||
try{
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String event;
|
||||
EventStreaming eventStreaming = null;
|
||||
EventStreaming eventStreaming;
|
||||
//noinspection InfiniteLoopStatement
|
||||
while(true){
|
||||
try {
|
||||
|
@ -219,6 +179,7 @@ public class StreamingService extends Service {
|
|||
break;
|
||||
}
|
||||
if (event !=null){
|
||||
|
||||
if( (lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
||||
switch (event.trim()) {
|
||||
case "event: update":
|
||||
|
@ -252,7 +213,7 @@ public class StreamingService extends Service {
|
|||
lastEvent = EventStreaming.NONE;
|
||||
try {
|
||||
JSONObject eventJson = new JSONObject(event);
|
||||
onRetrieveStreaming(eventStreaming, eventJson, account.getAcct(), account.getId());
|
||||
onRetrieveStreaming(eventStreaming, eventJson, account.getId());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -275,7 +236,7 @@ public class StreamingService extends Service {
|
|||
}
|
||||
|
||||
private void forceRestart(Account account){
|
||||
isConnectingHashMap.put(account.getAcct()+account.getId(), false);
|
||||
isConnectingHashMap = false;
|
||||
SystemClock.sleep(1000);
|
||||
Intent intent = new Intent(getApplicationContext(), StreamingService.class);
|
||||
intent.putExtra("accountId", account.getId());
|
||||
|
@ -293,100 +254,23 @@ public class StreamingService extends Service {
|
|||
}
|
||||
|
||||
|
||||
public void onRetrieveStreaming(EventStreaming event, JSONObject response, String acct, String userId) {
|
||||
public void onRetrieveStreaming(EventStreaming event, JSONObject response, String userId) {
|
||||
if( response == null )
|
||||
return;
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
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);
|
||||
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
boolean notify = false;
|
||||
String notificationUrl = null;
|
||||
String title = null;
|
||||
Status status = null;
|
||||
Notification notification = null;
|
||||
Status status ;
|
||||
Notification notification;
|
||||
String dataId = null;
|
||||
|
||||
Bundle b = new Bundle();
|
||||
if( event == EventStreaming.NOTIFICATION){
|
||||
notification = API.parseNotificationResponse(getApplicationContext(), response);
|
||||
switch (notification.getType()){
|
||||
case "mention":
|
||||
if(notif_mention){
|
||||
lastPreviousContent = notification.getStatus().getContent();
|
||||
notify = true;
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
||||
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_mention));
|
||||
else
|
||||
title = String.format("%s %s", notification.getAccount().getUsername(),getString(R.string.notif_mention));
|
||||
}
|
||||
break;
|
||||
case "reblog":
|
||||
if(notif_share){
|
||||
notify = true;
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
||||
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_reblog));
|
||||
else
|
||||
title = String.format("%s %s", notification.getAccount().getUsername(),getString(R.string.notif_reblog));
|
||||
}
|
||||
break;
|
||||
case "favourite":
|
||||
if(notif_add){
|
||||
notify = true;
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
||||
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_favourite));
|
||||
else
|
||||
title = String.format("%s %s", notification.getAccount().getUsername(),getString(R.string.notif_favourite));
|
||||
}
|
||||
break;
|
||||
case "follow":
|
||||
if(notif_follow){
|
||||
notify = true;
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
||||
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_follow));
|
||||
else
|
||||
title = String.format("%s %s", notification.getAccount().getUsername(),getString(R.string.notif_follow));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Helper.cacheNotifications(getApplicationContext(), notification, userId);
|
||||
if( notification.getStatus().getContent()!= null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
message = Html.fromHtml(notification.getStatus().getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
//noinspection deprecation
|
||||
message = Html.fromHtml(notification.getStatus().getContent()).toString();
|
||||
message = message.substring(0, message.length()>49?49:message.length());
|
||||
message = message + "…";
|
||||
}else{
|
||||
message = "";
|
||||
}
|
||||
|
||||
b.putParcelable("data", notification);
|
||||
}else if ( event == EventStreaming.UPDATE){
|
||||
status = API.parseStatuses(getApplicationContext(), response);
|
||||
status.setReplies(new ArrayList<Status>()); //Force to don't display replies
|
||||
status.setReplies(new ArrayList<Status>());
|
||||
status.setNew(true);
|
||||
Helper.cacheStatus(getApplicationContext(), status, userId);
|
||||
if( status.getContent() != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
message = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
//noinspection deprecation
|
||||
message = Html.fromHtml(status.getContent()).toString();
|
||||
message = message.substring(0, message.length()>49?49:message.length());
|
||||
message = message + "…";
|
||||
}else{
|
||||
message = "";
|
||||
}
|
||||
title = getString(R.string.notif_pouet, status.getAccount().getUsername());
|
||||
notificationUrl = status.getAccount().getAvatar();
|
||||
b.putParcelable("data", status);
|
||||
}else if( event == EventStreaming.DELETE){
|
||||
try {
|
||||
dataId = response.getString("id");
|
||||
|
@ -394,110 +278,9 @@ public class StreamingService extends Service {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//Check which user is connected and if activity is to front
|
||||
boolean activityVisible = false;
|
||||
try{
|
||||
activityVisible = MainActivity.isActivityVisible();
|
||||
}catch (Exception ignored){}
|
||||
String connectedUser = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(connectedUser);
|
||||
//User receiving the notification is connected
|
||||
if( isCurrentAccountLoggedIn(acct, userId)){
|
||||
notify = false;
|
||||
Intent intentBC = new Intent(Helper.RECEIVE_DATA);
|
||||
intentBC.putExtra("eventStreaming", event);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentBC);
|
||||
}
|
||||
//User receiving the notification is connected and application is to front, notification won't be pushed
|
||||
//Instead, the interaction is done in the activity
|
||||
if( activityVisible && isCurrentAccountLoggedIn(acct, userId)){
|
||||
notify = false;
|
||||
}else if(event == EventStreaming.NOTIFICATION ){
|
||||
notify = true;
|
||||
}else if(event == EventStreaming.UPDATE ){
|
||||
//lastPreviousContent contains the content of the last notification, if it was a mention it will avoid to push two notifications
|
||||
if( account == null || (lastPreviousContent != null && lastPreviousContent.equals(status.getContent()))) {
|
||||
notify = false;
|
||||
}else {
|
||||
notify = true;
|
||||
//Retrieve users in db that owner has, and if the toot matches one of them we don't notify
|
||||
List<Account> accounts = new AccountDAO(getApplicationContext(),db).getAllAccount();
|
||||
for(Account act_tmp: accounts) {
|
||||
if(notify && act_tmp.getAcct().trim().equals(status.getAccount().getAcct()) && act_tmp.getId().trim().equals(status.getAccount().getId().trim())){
|
||||
notify = false;
|
||||
}
|
||||
}
|
||||
//Here we check if the user wants home timeline notifications
|
||||
if( notify )
|
||||
notify = sharedpreferences.getBoolean(Helper.SET_NOTIF_HOMETIMELINE, true);
|
||||
}
|
||||
lastPreviousContent = status.getContent();
|
||||
}
|
||||
//All is good here for a notification, we will know check if it can be done depending of the hour
|
||||
if( notify)
|
||||
notify = canNotify(getApplicationContext());
|
||||
if( notify && event == EventStreaming.NOTIFICATION){
|
||||
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, userId);
|
||||
long notif_id = Long.parseLong(userId);
|
||||
notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notification.getId());
|
||||
editor.apply();
|
||||
}
|
||||
if( notify && event == EventStreaming.UPDATE) {
|
||||
intent = new Intent(getApplicationContext(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(INTENT_ACTION, HOME_TIMELINE_INTENT);
|
||||
intent.putExtra(PREF_KEY_ID, userId);
|
||||
long notif_id = Long.parseLong(userId);
|
||||
notificationId = ((notif_id + 2) > 2147483647) ? (int) (2147483647 - notif_id - 2) : (int) (notif_id + 2);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, status.getId());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
if( notify){
|
||||
if( notificationUrl != null){
|
||||
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
|
||||
File cacheDir = new File(getApplicationContext().getCacheDir(), 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;
|
||||
imageLoaderNoty.loadImage(notificationUrl, 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, message);
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason){
|
||||
notify_user(getApplicationContext(), intent, notificationId, BitmapFactory.decodeResource(getApplicationContext().getResources(),
|
||||
R.drawable.mastodonlogo), finalTitle, message);
|
||||
}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCurrentAccountLoggedIn(String acct, String userId){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userconnected = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userconnected);
|
||||
return acct.trim().equals(account.getAcct().trim()) && userId.trim().equals(account.getId().trim());
|
||||
Intent intentBC = new Intent(Helper.RECEIVE_DATA);
|
||||
intentBC.putExtra("eventStreaming", event);
|
||||
intentBC.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentBC);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,18 +80,5 @@
|
|||
android:indeterminate="true" />
|
||||
</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>
|
||||
|
||||
|
|
|
@ -78,19 +78,5 @@
|
|||
android:indeterminate="true" />
|
||||
</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>
|
||||
|
||||
|
|
|
@ -71,16 +71,25 @@
|
|||
style="?attr/shapeBorder"
|
||||
android:visibility="gone"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<ImageView
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="70dp"
|
||||
android:id="@+id/new_element"
|
||||
android:visibility="gone"
|
||||
android:visibility="invisible"
|
||||
android:src="@drawable/ic_fiber_new"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="ContentDescription" />
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_below="@+id/new_element"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/status_translate"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
app:fabSize="mini"
|
||||
android:layout_marginTop="10dp"
|
||||
app:srcCompat="@drawable/ic_translate" />
|
||||
</RelativeLayout>
|
||||
<LinearLayout
|
||||
android:layout_marginStart="5dp"
|
||||
|
@ -332,17 +341,6 @@
|
|||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:visibility="gone"
|
||||
android:text="@string/translate_toot"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical|end"
|
||||
android:id="@+id/status_translate"
|
||||
android:textColor="@color/mastodonC4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:id="@+id/status_action_container"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -79,19 +79,5 @@
|
|||
android:layout_height="match_parent"
|
||||
android:indeterminate="true" />
|
||||
</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>
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
android:layout_height="match_parent">
|
||||
<ListView
|
||||
android:id="@+id/lv_status"
|
||||
android:transcriptMode="normal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
|
@ -77,20 +78,5 @@
|
|||
android:layout_height="match_parent"
|
||||
android:indeterminate="true" />
|
||||
</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>
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<resources>
|
||||
|
||||
<string name="navigation_drawer_open">Öffne Menü</string>
|
||||
<string name="navigation_drawer_close">Menü schließen</string>
|
||||
|
||||
|
@ -44,9 +43,8 @@
|
|||
<string name="speech_prompt">Bitte sag etwas</string>
|
||||
<string name="speech_not_supported">Sorry! Dein Gerät unterstützt keine Spracheingabe!</string>
|
||||
<string name="delete_all">Alles löschen</string>
|
||||
<string name="translate_toot">Übersetzen toot.</string>
|
||||
<string name="translate_toot">Toot übersetzen</string>
|
||||
<string name="schedule">Planen</string>
|
||||
|
||||
<string name="text_size">Text- und Symbolgröße</string>
|
||||
<string name="text_size_change">Ändere Textgröße:</string>
|
||||
<string name="icon_size_change">Ändere Symbolgröße:</string>
|
||||
|
@ -59,6 +57,8 @@
|
|||
<string name="shared_via">Geteilt von Mastalab</string>
|
||||
<string name="replies">Antworten</string>
|
||||
<string name="username">Benutzername</string>
|
||||
|
||||
<string name="new_data">Neue Beiträge sind verfügbar! Anzeigen?</string>
|
||||
<!--- Menu -->
|
||||
<string name="home_menu">Home</string>
|
||||
<string name="local_menu">Lokale Zeitleiste</string>
|
||||
|
@ -91,6 +91,7 @@
|
|||
<string name="reblog_removed">Toot wird nicht länger geteilt!</string>
|
||||
<string name="reblog_by">Geteilt von %1$s</string>
|
||||
|
||||
|
||||
<string name="favourite_add">Diesen toot deinen Favoriten hinzufügen?</string>
|
||||
<string name="favourite_remove">Diesen toot aus deinen Favoriten entfernen?</string>
|
||||
<string name="reblog_add">Teile diesen toot?</string>
|
||||
|
@ -127,6 +128,11 @@
|
|||
<item>null</item> <!-- Ugly hack to fix confirm box-->
|
||||
<item>null</item>
|
||||
</string-array>
|
||||
|
||||
<plurals name="preview_replies">
|
||||
<item quantity="one">%d Antwort</item>
|
||||
<item quantity="other">%d Antworten</item>
|
||||
</plurals>
|
||||
<!-- Date -->
|
||||
<plurals name="date_seconds">
|
||||
<item quantity="one">Vor %d Sekunden</item>
|
||||
|
@ -165,7 +171,7 @@
|
|||
<string name="toot_delete_media">Lösche diese Datei?</string>
|
||||
<string name="toot_error_no_content">Dein toot ist leer!</string>
|
||||
<string name="toot_visibility_tilte">Sichtbarkeit des toots:</string>
|
||||
<string name="toots_visibility_tilte">Standard Sichtbarkeit der toots: </string>
|
||||
<string name="toots_visibility_tilte">Standard Sichtbarkeit der toots:</string>
|
||||
<string name="toot_sent">Der toot wurde gesendet!</string>
|
||||
<string name="toot_reply_content_title">Du antwortest auf diesen toot:</string>
|
||||
<string name="toot_sensitive">Sensibler Inhalt?</string>
|
||||
|
@ -186,13 +192,12 @@
|
|||
<!-- About -->
|
||||
<string name="about_vesrion">Version %1$s</string>
|
||||
<string name="about_developer">Entwickler:</string>
|
||||
<string name="about_developer_action">\@tschneider</string>
|
||||
<string name="about_license">Lizenz: </string>
|
||||
<string name="about_developer_action">\\@tschneider</string>
|
||||
<string name="about_license">Lizenz:</string>
|
||||
<string name="about_license_action">GNU GPL V3</string>
|
||||
<string name="about_code">Quellcode: </string>
|
||||
<string name="about_code">Quellcode:</string>
|
||||
<string name="about_code_action">Bitbucket</string>
|
||||
<string name="about_yandex">Übersetzen von toots:</string>
|
||||
|
||||
<string name="about_thekinrar">Instanzensuche:</string>
|
||||
<string name="about_thekinrar_action">instances.social</string>
|
||||
|
||||
|
@ -202,16 +207,19 @@
|
|||
<!-- Accounts -->
|
||||
<string name="no_accounts">Keinen Nutzer gefunden</string>
|
||||
<string name="no_follow_request">Keine Folgen-Anfrage</string>
|
||||
<string name="status_cnt">Toots \n %d</string>
|
||||
<string name="following_cnt">Following \n %d</string>
|
||||
<string name="followers_cnt">Followers \n %d</string>
|
||||
<string name="status_cnt">Toots \n
|
||||
%d</string>
|
||||
<string name="following_cnt">Following \n
|
||||
%d</string>
|
||||
<string name="followers_cnt">Followers \n
|
||||
%d</string>
|
||||
<string name="authorize">Authorisieren</string>
|
||||
<string name="reject">Ablehnen</string>
|
||||
|
||||
|
||||
<!-- Scheduled toots -->
|
||||
<string name="no_scheduled_toots">Keine geplanten toots vorhanden!</string>
|
||||
<string name="no_scheduled_toots_indications">Schreibe einen toot und wähle <b>Planen</b> im Topmenü.</string>
|
||||
<string name="no_scheduled_toots_indications">Schreibe einen toot und wähle <b >Planen</b> im Topmenü.</string>
|
||||
<string name="remove_scheduled">Geplanten toot löschen?</string>
|
||||
<string name="media_count">Dateien: %d</string>
|
||||
<string name="toot_scheduled">Der toot wurde geplant!</string>
|
||||
|
@ -265,16 +273,16 @@
|
|||
<string name="toast_saved">Datei wurde gespeichert!</string>
|
||||
<string name="toast_error_translate">Während der Übersetzung ist ein Fehler aufgetreten!</string>
|
||||
<string name="toast_toot_saved">Entwurf gespeichert!</string>
|
||||
<string name="toast_error_char_limit">Bist du sicher das diese Instanz die Anzahl an Zeichen unterstützt? Gewöhnlich liegt der Wert bei 500.</string>
|
||||
<string name="toast_visibility_changed">Sichtbarkeit der toots für Nutzer %1$s wurde geändert</string>
|
||||
<string name="toast_empty_search">Instanzname und Benutzername dürfen nicht leer sein!</string>
|
||||
<!-- Settings -->
|
||||
<string name="settings_title_optimisation">Optimierter Ladevorgang</string>
|
||||
<string name="set_toots_page">Anzahl der toots beim Laden</string>
|
||||
<string name="set_accounts_page">Anzahl der Konten beim Laden</string>
|
||||
<string name="set_notifications_page">Anzahl der Benachrichtigungen beim Laden</string>
|
||||
<string name="toast_error_char_limit">Bist du sicher das diese Instanz die Anzahl an Zeichen unterstützt? Gewöhnlich liegt der Wert bei 500.</string>
|
||||
<string name="set_attachment_always">Immer</string>
|
||||
<string name="set_attachment_wifi">WLAN</string>
|
||||
<string name="toast_empty_search">Instanzname und Benutzername dürfen nicht leer sein!</string>
|
||||
<string name="set_attachment_ask">Fragen</string>
|
||||
<string name="set_attachment_action">Lade Anhang</string>
|
||||
<string name="load_attachment">Lade Bilder</string>
|
||||
|
@ -282,18 +290,19 @@
|
|||
<string name="load_sensitive_attachment">Sensibler Inhalt</string>
|
||||
<string name="set_display_reply">Zeige vorherige Nachricht beim Antworten</string>
|
||||
<string name="set_display_local">Lokale Zeitleiste anzeigen</string>
|
||||
<string name="set_display_global">Öffentliche Zeitlinie anzeigen</string>
|
||||
<string name="set_folder_title">Pfad: </string>
|
||||
<string name="set_display_global">Öffentliche Zeitleiste anzeigen</string>
|
||||
<string name="set_folder_title">Pfad:</string>
|
||||
<string name="set_auto_store_toot">Speichere Entwürfe automatisch</string>
|
||||
<string name="set_bubble_counter">Anzahl neuer Beiträge anzeigen</string>
|
||||
<string name="set_auto_add_media_url">Füge die URL bei Anhängen in toots hinzu</string>
|
||||
<string name="settings_title_notifications">Benachrichtigen wenn …</string>
|
||||
<string name="set_notif_follow">mir jemand folgt</string>
|
||||
<string name="set_notif_follow_ask">ich eine Folgen Anfrage erhalte</string>
|
||||
<string name="set_notif_follow_share">jemand meinen Status teilt</string>
|
||||
<string name="set_notif_follow_add">jemand meinen Status favorisiert</string>
|
||||
<string name="set_notif_follow_mention">ich erwähnt werde</string>
|
||||
<string name="set_auto_add_media_url">Füge die URL bei Anhängen in toots hinzu</string>
|
||||
<string name="set_share_validation">Zeige Bestätigungsdialog vor dem Teilen</string>
|
||||
<string name="set_share_validation_fav">Zeige Bestätigungsdialog vor dem zu favoriten hinzufügen</string>
|
||||
<string name="set_share_validation">Bestätigungsdialog vor dem Teilen</string>
|
||||
<string name="set_share_validation_fav">Bestätigungsdialog vor dem favorisieren</string>
|
||||
<string name="settings_title_more_options">Erweiterte Einstellungen</string>
|
||||
<string name="set_wifi_only">Nur bei WLAN benachrichtigen</string>
|
||||
<string name="set_notif_silent">Leise Benachrichtigungen</string>
|
||||
|
@ -303,27 +312,21 @@
|
|||
<string name="set_profile_description">Über mich…</string>
|
||||
<string name="set_save_changes">Änderungen speichern</string>
|
||||
<string name="set_header_picture_overlay">Wähle ein Profilbild</string>
|
||||
<string name="set_preview_reply">Zeige die Anzahl der Antworten in der home Zeitlinie an</string>
|
||||
<string name="set_preview_reply_pp">Profilbilder anzeigen?</string>
|
||||
<string name="note_no_space">Du hast die Grenze von 160 Zeichen erreicht!</string>
|
||||
<string name="username_no_space">Du hast die Grenze von 30 Zeichen erreicht!</string>
|
||||
|
||||
<string name="settings_title_hour">Zeitfenster für Benachrichtigungen:</string>
|
||||
<string name="settings_time_from">Zwischen</string>
|
||||
<string name="settings_time_to">und</string>
|
||||
<string name="set_preview_reply">Zeige die Anzahl der Antworten in der home Zeitlinie an</string>
|
||||
<string name="settings_time_greater">Uhrzeit muss größer sein als %1$s</string>
|
||||
<string name="set_preview_reply_pp">Profilbilder anzeigen?</string>
|
||||
<string name="settings_time_lower">Uhrzeit muss kleiner sein als %1$s</string>
|
||||
<string name="settings_hour_init">Anfangszeit</string>
|
||||
<string name="settings_hour_end">Ende</string>
|
||||
<string name="embedded_browser">Benutze internen browser</string>
|
||||
<string name="use_javascript">Javascript aktivieren</string>
|
||||
<string name="use_cookies">Erlaube cookies von Drittanbietern</string>
|
||||
|
||||
<string name="set_title_news">Neuigkeiten</string>
|
||||
<string name="set_notification_news">Benachrichtigung für neue toots auf der Startleiste</string>
|
||||
<string name="set_show_error_messages">Zeige Fehlermeldungen</string>
|
||||
<string name="action_follow">Folge</string>
|
||||
<string name="action_unfollow">Entfolge</string>
|
||||
<string name="settings_ui_layout">Zeitlininen wie anzeigen:</string>
|
||||
<string-array name="settings_menu_tabs">
|
||||
<item>Nur als Reiter</item>
|
||||
|
@ -331,25 +334,29 @@
|
|||
<item>Reiter und Menü</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
<string-array name="settings_translation">
|
||||
<item>Yandex</item>
|
||||
<item>Google</item>
|
||||
<item>Nein</item>
|
||||
</string-array>
|
||||
|
||||
<string name="set_led_colour">LED Farbe auswählen:</string>
|
||||
<string name="set_led_colour">LED Farbe auswählen</string>
|
||||
|
||||
<string-array name="led_colours">
|
||||
<item>Blue</item>
|
||||
<item>Blau</item>
|
||||
<item>Cyan</item>
|
||||
<item>Magenta</item>
|
||||
<item>Green</item>
|
||||
<item>Red</item>
|
||||
<item>Yellow</item>
|
||||
<item>White</item>
|
||||
<item>Grün</item>
|
||||
<item>Rot</item>
|
||||
<item>Gelb</item>
|
||||
<item>Weiß</item>
|
||||
</string-array>
|
||||
|
||||
<string name="set_title_news">Neuigkeiten</string>
|
||||
<string name="set_notification_news">Benachrichtigung für neue toots auf der Startleiste</string>
|
||||
<string name="set_show_error_messages">Zeige Fehlermeldungen</string>
|
||||
<string name="action_follow">Folge</string>
|
||||
<string name="action_unfollow">Entfolge</string>s
|
||||
<string name="action_block">Blockiere</string>
|
||||
<string name="action_unblock">Nicht mehr blockieren</string>
|
||||
<string name="action_mute">Stummschalten</string>
|
||||
|
@ -362,69 +369,53 @@
|
|||
|
||||
<!-- Quick settings for notifications -->
|
||||
<string name="settings_popup_title">Push Benachrichtigungen</string>
|
||||
<string name="settings_popup_message">
|
||||
Bitte bestätige welche Push Benachrichtigungen du erhalten möchtest.
|
||||
Diese können später im Benachrichtungsreiter aktiviert oder deaktiviert werden.
|
||||
</string>
|
||||
<string name="settings_popup_message">Bitte bestätige welche Push Benachrichtigungen du erhalten möchtest. Diese können später im Benachrichtungsreiter aktiviert oder deaktiviert werden.</string>
|
||||
<string name="settings_popup_timeline">Für ungelesene toots auf der Startleiste?</string>
|
||||
<string name="settings_popup_notification">Für ungelesene Benachrichtigungen?</string>
|
||||
<!-- CACHE -->
|
||||
<string name="cache_title">Speicher leeren</string>
|
||||
<string name="cache_message">Es sind %1$s Daten im Speicher.\n\nMöchtest du diese löschen?</string>
|
||||
<string name="cache_message">Es sind %1$s Daten im Speicher.\n
|
||||
\n
|
||||
Möchtest du diese löschen?</string>
|
||||
<string name="cache_units">Mb</string>
|
||||
<string name="toast_cache_clear">Speicher wurde geleert! %1$s wurden freigeben</string>
|
||||
|
||||
<!-- PRIVACY -->
|
||||
<string name="privacy_data_title">Aufgezeichnete Daten</string>
|
||||
<string name="privacy_data">
|
||||
Nur Grundinformationen der Konten werden auf dem Gerät gespeichert.
|
||||
Die Daten sind streng vertraulich und können nur von der Anwendung genutzt werden.
|
||||
Beim Löschen der Anwendung werden diese umgehend entfernt.\n
|
||||
⚠ Logindaten und Passwörter werden nie gespeichert. Sie werden nur während einer sicheren (SSL) Authentifizierung mit einer Instanz verwendet.
|
||||
</string>
|
||||
<string name="privacy_data">Nur Grundinformationen der Konten werden auf dem Gerät gespeichert. Die Daten sind streng vertraulich und können nur von der Anwendung genutzt werden. Beim Löschen der Anwendung werden diese umgehend entfernt.\n
|
||||
⚠ Logindaten und Passwörter werden nie gespeichert. Sie werden nur während einer sicheren (SSL) Authentifizierung mit einer Instanz verwendet.</string>
|
||||
|
||||
<string name="privacy_authorizations_title">Berechtigungen:</string>
|
||||
<string name="privacy_authorizations">
|
||||
- <b>ACCESS_NETWORK_STATE</b>: Erkennen von bestehenden Verbindungen zu WIFI Netzwerken.\n
|
||||
- <b>INTERNET</b>: Genutzt für Anfragen an eine Instanz.\n
|
||||
- <b>WRITE_EXTERNAL_STORAGE</b>: Dateien speichern oder App auf SD Karte verschieben.\n
|
||||
- <b>READ_EXTERNAL_STORAGE</b>: Dateianhänge für toots.\n
|
||||
- <b>BOOT_COMPLETED</b>: Benachrichtigungsdienst starten.\n
|
||||
- <b>WAKE_LOCK</b>: Benachrichtigungsdienst.
|
||||
</string>
|
||||
<string name="privacy_authorizations">- <b >ACCESS_NETWORK_STATE</b>: Erkennen von bestehenden Verbindungen zu WIFI Netzwerken.\n
|
||||
- <b >INTERNET</b>: Genutzt für Anfragen an eine Instanz.\n
|
||||
- <b >WRITE_EXTERNAL_STORAGE</b>: Dateien speichern oder App auf SD Karte verschieben.\n
|
||||
- <b >READ_EXTERNAL_STORAGE</b>: Dateianhänge für toots.\n
|
||||
- <b >BOOT_COMPLETED</b>: Benachrichtigungsdienst starten.\n
|
||||
- <b >WAKE_LOCK</b>: Benachrichtigungsdienst.</string>
|
||||
|
||||
<string name="privacy_API_authorizations_title">API Berechtigungen:</string>
|
||||
<string name="privacy_API_authorizations">
|
||||
- <b>Read</b>: Daten lesen.\n
|
||||
- <b>Write</b>: Status veröffentlichen und Dateien hochladen.\n
|
||||
- <b>Follow</b>: Folgen, nicht mehr folgen, blockieren, nicht mehr blockieren.\n\n
|
||||
<b>⚠ Diese Aktionen werden nur auf Verlangen des Benutzers durchgeführt.</b>
|
||||
</string>
|
||||
<string name="privacy_API_authorizations">- <b >Read</b>: Daten lesen.\n
|
||||
- <b >Write</b>: Status veröffentlichen und Dateien hochladen.\n
|
||||
- <b >Follow</b>: Folgen, nicht mehr folgen, blockieren, nicht mehr blockieren.\n
|
||||
\n
|
||||
<b >⚠ Diese Aktionen werden nur auf Verlangen des Benutzers durchgeführt.</b></string>
|
||||
<string name="privacy_API_title">Tracking und Bibliotheken</string>
|
||||
<string name="privacy_API">
|
||||
Die Anwendung <b>benutzt keine Trackingwerkzeuge</b> (Nutzerbewertung, Fehlerberichte, etc.) und enthält keinerlei Werbung.\n\n
|
||||
Die Nutzung von Bibliotheken ist minimiert: \n
|
||||
- <b>Android Asynchronous Http Client</b>: Anfragen verwalten\n
|
||||
- <b>Universal Image Loader</b>: Dateien verwalten\n
|
||||
- <b>Android-Job</b>: Dienste verwalten\n
|
||||
- <b>PhotoView</b>: Bilder verwalten\n
|
||||
- <b>Gson</b> : Entwürfe speichern
|
||||
</string>
|
||||
|
||||
<string name="privacy_API">Die Anwendung <b >benutzt keine Trackingwerkzeuge</b> (Nutzerbewertung, Fehlerberichte, etc.) und enthält keinerlei Werbung.\n
|
||||
\n
|
||||
Die Nutzung von Bibliotheken ist minimiert: \n
|
||||
- <b >Android Asynchronous Http Client</b>: Anfragen verwalten\n
|
||||
- <b >Universal Image Loader</b>: Dateien verwalten\n
|
||||
- <b >Android-Job</b>: Dienste verwalten\n
|
||||
- <b >PhotoView</b>: Bilder verwalten\n
|
||||
- <b >Gson</b> : Entwürfe speichern</string>
|
||||
|
||||
|
||||
<string name="privacy_API_yandex_title">Übersetzung von toots</string>
|
||||
<string name="privacy_API_yandex_authorizations">
|
||||
Die Anwendung bietet die Möglichkeit, toots mithilfe der lokalen sowie Yandex API zu übersetzen.\n
|
||||
Yandex hat seine eigene Datenschutzerklärung. Diese kann hier eingehesen werden: https://yandex.ru/legal/confidential/?lang=en
|
||||
</string>
|
||||
<string name="privacy_API_yandex_authorizations">Die Anwendung bietet die Möglichkeit, toots mithilfe der lokalen sowie Yandex API zu übersetzen.\n
|
||||
Yandex hat seine eigene Datenschutzerklärung. Diese kann hier eingehesen werden: https://yandex.ru/legal/confidential/?lang=en</string>
|
||||
|
||||
|
||||
<string name="thanks_text">Danke an Stéphane für das Logo.</string>
|
||||
|
||||
<string name="thanks_text_dev">
|
||||
Danke an:
|
||||
</string>
|
||||
<string name="new_data">Neue Daten verfügbar sind! Wollen Sie Sie anzeigen?</string>
|
||||
<string name="set_bubble_counter">Display-Zähler</string>
|
||||
<string name="thanks_text_dev">Danke an @PhotonQyv für seine Beiträge.</string>
|
||||
</resources>
|
|
@ -16,10 +16,12 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.PorterDuff;
|
||||
|
@ -27,6 +29,7 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.TabLayout;
|
||||
|
@ -76,6 +79,8 @@ import java.util.regex.Matcher;
|
|||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMetaDataAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
|
||||
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.fragments.DisplayAccountsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
||||
|
@ -131,6 +136,8 @@ public class MainActivity extends AppCompatActivity
|
|||
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
|
||||
private BroadcastReceiver receive_data;
|
||||
private boolean display_local, display_global;
|
||||
public static int countNewStatus = 0;
|
||||
public static int countNewNotifications = 0;
|
||||
|
||||
public MainActivity() {
|
||||
}
|
||||
|
@ -148,19 +155,15 @@ public class MainActivity extends AppCompatActivity
|
|||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
||||
if(notificationsFragment != null){
|
||||
if(notificationsFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
notificationsFragment.showNewContent();
|
||||
}else{
|
||||
notificationsFragment.refresh();
|
||||
}
|
||||
Notification notification = b.getParcelable("data");
|
||||
notificationsFragment.refresh(notification);
|
||||
countNewNotifications++;
|
||||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
||||
Status status = b.getParcelable("data");
|
||||
if( homeFragment != null){
|
||||
if(homeFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
homeFragment.showNewContent();
|
||||
}else{
|
||||
homeFragment.refresh();
|
||||
}
|
||||
homeFragment.refresh(status);
|
||||
countNewStatus++;
|
||||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
||||
String id = b.getString("id");
|
||||
|
@ -176,6 +179,8 @@ public class MainActivity extends AppCompatActivity
|
|||
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));
|
||||
|
||||
|
||||
|
@ -264,6 +269,12 @@ public class MainActivity extends AppCompatActivity
|
|||
tabLayout.addTab(tabPublic);
|
||||
|
||||
viewPager = (ViewPager) findViewById(R.id.viewpager);
|
||||
int countPage = 2;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
|
||||
countPage++;
|
||||
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
|
||||
countPage++;
|
||||
viewPager.setOffscreenPageLimit(countPage);
|
||||
main_app_container = (RelativeLayout) findViewById(R.id.main_app_container);
|
||||
PagerAdapter adapter = new PagerAdapter
|
||||
(getSupportFragmentManager(), tabLayout.getTabCount());
|
||||
|
@ -290,21 +301,10 @@ public class MainActivity extends AppCompatActivity
|
|||
if( tab.getPosition() == 0) {
|
||||
item = navigationView.getMenu().findItem(R.id.nav_home);
|
||||
fragmentTag = "HOME_TIMELINE";
|
||||
if (homeFragment != null && Helper.getUnreadToots(getApplicationContext(), null) > 0) {
|
||||
homeFragment.refresh();
|
||||
}
|
||||
Helper.cacheStatusClear(getApplicationContext(), null);
|
||||
updateHomeCounter();
|
||||
}else if( tab.getPosition() == 1) {
|
||||
fragmentTag = "NOTIFICATIONS";
|
||||
item = navigationView.getMenu().findItem(R.id.nav_notification);
|
||||
if (notificationsFragment != null && Helper.getUnreadNotifications(getApplicationContext(), null) > 0) {
|
||||
notificationsFragment.refresh();
|
||||
}
|
||||
Helper.cacheNotificationsClear(getApplicationContext(), null);
|
||||
updateNotifCounter();
|
||||
}else if( tab.getPosition() == 2 && display_local) {
|
||||
|
||||
fragmentTag = "LOCAL_TIMELINE";
|
||||
item = navigationView.getMenu().findItem(R.id.nav_local);
|
||||
}else if( tab.getPosition() == 2 && !display_local) {
|
||||
|
@ -350,10 +350,10 @@ public class MainActivity extends AppCompatActivity
|
|||
switch (tab.getPosition()){
|
||||
case 0:
|
||||
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||
countNewStatus = 0;
|
||||
updateHomeCounter();
|
||||
if( displayStatusFragment != null )
|
||||
displayStatusFragment.scrollToTop();
|
||||
Helper.cacheStatusClear(getApplicationContext(), null);
|
||||
updateHomeCounter();
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
|
@ -363,10 +363,10 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
case 1:
|
||||
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
||||
countNewNotifications = 0;
|
||||
updateNotifCounter();
|
||||
if( displayNotificationsFragment != null )
|
||||
displayNotificationsFragment.scrollToTop();
|
||||
Helper.cacheNotificationsClear(getApplicationContext(), null);
|
||||
updateNotifCounter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -903,6 +903,37 @@ public class MainActivity extends AppCompatActivity
|
|||
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
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
@ -912,6 +943,12 @@ public class MainActivity extends AppCompatActivity
|
|||
@Override
|
||||
public void onDestroy(){
|
||||
super.onDestroy();
|
||||
if( streamingService != null)
|
||||
streamingService.disconnect();
|
||||
if (mBound) {
|
||||
unbindService(serviceConnection);
|
||||
mBound = false;
|
||||
}
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
||||
}
|
||||
|
||||
|
@ -1174,8 +1211,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if( tabHome == null)
|
||||
return;
|
||||
TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter);
|
||||
tabCounterHome.setText(String.valueOf(Helper.getUnreadToots(getApplicationContext(), null)));
|
||||
if( Helper.getUnreadToots(getApplicationContext(), null) > 0){
|
||||
tabCounterHome.setText(String.valueOf(countNewStatus));
|
||||
if( countNewStatus> 0){
|
||||
//New data are available
|
||||
//The fragment is not displayed, so the counter is displayed
|
||||
tabCounterHome.setVisibility(View.VISIBLE);
|
||||
|
@ -1192,8 +1229,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if( tabNotif == null)
|
||||
return;
|
||||
TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter);
|
||||
tabCounterNotif.setText(String.valueOf(Helper.getUnreadNotifications(getApplicationContext(), null)));
|
||||
if( Helper.getUnreadNotifications(getApplicationContext(), null) > 0){
|
||||
tabCounterNotif.setText(String.valueOf(countNewNotifications));
|
||||
if( countNewNotifications > 0){
|
||||
tabCounterNotif.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
tabCounterNotif.setVisibility(View.GONE);
|
||||
|
|
Loading…
Reference in New Issue