Removes some useless methods

This commit is contained in:
tom79 2017-09-04 19:01:41 +02:00
parent c8a4b2c3ae
commit 7ef423abd8
5 changed files with 31 additions and 112 deletions

View File

@ -279,7 +279,7 @@ public class MainActivity extends AppCompatActivity
if (homeFragment != null && Helper.getUnreadToots(getApplicationContext(), null) > 0) {
homeFragment.refresh();
}
Helper.clearUnreadToots(getApplicationContext(), null);
Helper.cacheStatusClear(getApplicationContext(), null);
updateHomeCounter();
}else if( tab.getPosition() == 1) {
fragmentTag = "NOTIFICATIONS";
@ -287,7 +287,7 @@ public class MainActivity extends AppCompatActivity
if (notificationsFragment != null && Helper.getUnreadNotifications(getApplicationContext(), null) > 0) {
notificationsFragment.refresh();
}
Helper.clearUnreadNotifications(getApplicationContext(), null);
Helper.cacheNotificationsClear(getApplicationContext(), null);
updateNotifCounter();
}else if( tab.getPosition() == 2 && display_local) {
@ -338,7 +338,7 @@ public class MainActivity extends AppCompatActivity
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
if( displayStatusFragment != null )
displayStatusFragment.scrollToTop();
Helper.clearUnreadToots(getApplicationContext(), null);
Helper.cacheStatusClear(getApplicationContext(), null);
updateHomeCounter();
break;
case 2:
@ -351,7 +351,7 @@ public class MainActivity extends AppCompatActivity
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
if( displayNotificationsFragment != null )
displayNotificationsFragment.scrollToTop();
Helper.clearUnreadNotifications(getApplicationContext(), null);
Helper.cacheNotificationsClear(getApplicationContext(), null);
updateNotifCounter();
break;
}

View File

@ -153,7 +153,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
}
new_data.setVisibility(View.GONE);
notificationsTmp = new ArrayList<>();
Helper.clearUnreadNotifications(context, null);
Helper.cacheNotificationsClear(context, null);
((MainActivity) context).updateNotifCounter();
}
});
@ -209,7 +209,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
else
textviewNoAction.setVisibility(View.GONE);
if( swiped ){
Helper.clearUnreadNotifications(context,null);
Helper.cacheNotificationsClear(context,null);
((MainActivity) context).updateNotifCounter();
boolean isOnWifi = Helper.isOnWIFI(context);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
@ -253,7 +253,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
notificationsTmp = Helper.getTempNotification(context, null);
if( notificationsTmp.size() > 0){
for(int i = notificationsTmp.size() -1 ; i >= 0 ; i--){
this.notifications.add(0,notificationsTmp.get(i));
if( !this.notifications.contains(notificationsTmp.get(i)))
this.notifications.add(0,notificationsTmp.get(i));
}
boolean isOnWifi = Helper.isOnWIFI(context);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);

View File

@ -237,7 +237,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
new_data.setVisibility(View.GONE);
statusesTmp = new ArrayList<>();
Helper.clearUnreadToots(context, null);
Helper.cacheStatusClear(context, null);
((MainActivity) context).updateHomeCounter();
}
@ -315,7 +315,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
textviewNoAction.setVisibility(View.GONE);
if( swiped ){
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
Helper.clearUnreadToots(context,null);
Helper.cacheStatusClear(context,null);
((MainActivity) context).updateHomeCounter();
}
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
@ -362,7 +362,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
statusesTmp = Helper.getTempStatus(context, null);
if( statusesTmp.size() > 0){
for(int i = statusesTmp.size() -1 ; i >= 0 ; i--){
this.statuses.add(0,statusesTmp.get(i));
if( !this.statuses.contains(statusesTmp.get(i)))
this.statuses.add(0,statusesTmp.get(i));
}
boolean isOnWifi = Helper.isOnWIFI(context);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);

View File

@ -208,8 +208,6 @@ public class Helper {
public static final String SET_PREVIEW_REPLIES_PP = "set_preview_replies_pp";
public static final String SET_TRANSLATOR = "set_translator";
public static final String SET_LED_COLOUR = "set_led_colour";
private static final String SET_UNREAD_NOTIFICATIONS = "set_unread_notifications";
private static final String SET_UNREAD_TOOTS = "set_unread_toots";
private static final String SET_TEMP_STATUS = "set_temp_status";
private static final String SET_TEMP_NOTIFICATIONS = "set_temp_notifications";
@ -253,7 +251,6 @@ public class Helper {
//Refresh job
public static final int MINUTES_BETWEEN_NOTIFICATIONS_REFRESH = 15;
public static final int MINUTES_BETWEEN_HOME_TIMELINE = 30;
public static final int MINUTES_BETWEEN_STREAMING_CHECK_ALIVE = 15;
//Intent
public static final String INTENT_ACTION = "intent_action";
@ -1592,100 +1589,29 @@ public class Helper {
public static int getUnreadNotifications(Context context, String userId){
if( userId == null){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( userId == null)
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
return sharedpreferences.getInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
}else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
return sharedpreferences.getInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
}
}
public static void increaseUnreadNotifications(Context context, String userId){
if( userId == null){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
int unreadNotifications = sharedpreferences.getInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
SharedPreferences.Editor editor = sharedpreferences.edit();
unreadNotifications = unreadNotifications + 1;
editor.putInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, unreadNotifications);
editor.apply();
}else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int unreadNotifications = sharedpreferences.getInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
SharedPreferences.Editor editor = sharedpreferences.edit();
unreadNotifications = unreadNotifications + 1;
editor.putInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, unreadNotifications);
editor.apply();
}
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 void clearUnreadNotifications(Context context, String userId){
if( userId == null){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
editor.apply();
}else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
editor.apply();
}
}
public static int getUnreadToots(Context context, String userId){
if( userId == null){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( userId == null)
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
return sharedpreferences.getInt(Helper.SET_UNREAD_TOOTS + userId, 0);
}else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
return sharedpreferences.getInt(Helper.SET_UNREAD_TOOTS + userId, 0);
}
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 increaseUnreadToots(Context context, String userId){
if( userId == null){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
int unreadNotifications = sharedpreferences.getInt(Helper.SET_UNREAD_TOOTS + userId, 0);
SharedPreferences.Editor editor = sharedpreferences.edit();
unreadNotifications = unreadNotifications + 1;
editor.putInt(Helper.SET_UNREAD_TOOTS + userId, unreadNotifications);
editor.apply();
}else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int unreadNotifications = sharedpreferences.getInt(Helper.SET_UNREAD_TOOTS + userId, 0);
SharedPreferences.Editor editor = sharedpreferences.edit();
unreadNotifications = unreadNotifications + 1;
editor.putInt(Helper.SET_UNREAD_TOOTS + userId, unreadNotifications);
editor.apply();
}
}
public static void clearUnreadToots(Context context, String userId){
if( userId == null){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_UNREAD_TOOTS + userId, 0);
editor.apply();
}else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_UNREAD_TOOTS + userId, 0);
editor.apply();
}
}
public static String[] developers = {
"https://mastodon.etalab.gouv.fr/@tschneider",
"https://mastodon.xyz/@PhotonQyv",
"https://social.tchncs.de/@angrytux"
};
public static void cacheStatus(Context context, Status status, String userId){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -1725,6 +1651,7 @@ public class Helper {
return gson.fromJson(json, type);
}
public static void cacheNotifications(Context context, Notification notification, String userId){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( userId == null)
@ -1742,6 +1669,7 @@ public class Helper {
}
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);

View File

@ -23,7 +23,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;
@ -195,6 +194,7 @@ public class StreamingService extends Service {
@SuppressWarnings("ConstantConditions")
private String readStream(InputStream inputStream, HttpsURLConnection urlConnection, final Account account) {
BufferedReader reader = null;
try{
@ -370,7 +370,6 @@ public class StreamingService extends Service {
default:
break;
}
Helper.increaseUnreadNotifications(getApplicationContext(), userId);
Helper.cacheNotifications(getApplicationContext(), notification, userId);
if( notification.getStatus().getContent()!= null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@ -386,9 +385,7 @@ public class StreamingService extends Service {
}else if ( event == EventStreaming.UPDATE){
status = API.parseStatuses(getApplicationContext(), response);
status.setReplies(new ArrayList<Status>()); //Force to don't display replies.
Helper.increaseUnreadToots(getApplicationContext(), userId);
status.setReplies(new ArrayList<Status>()); //Force to don't display replies
Helper.cacheStatus(getApplicationContext(), status, userId);
if( status.getContent() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@ -424,14 +421,6 @@ public class StreamingService extends Service {
notify = false;
Intent intentBC = new Intent(Helper.RECEIVE_DATA);
intentBC.putExtra("eventStreaming", event);
Bundle b = new Bundle();
if( event == EventStreaming.UPDATE)
b.putParcelable("data", status);
else if(event == EventStreaming.NOTIFICATION)
b.putParcelable("data", notification);
else if(event == EventStreaming.DELETE)
b.putString("id", dataId);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentBC);
}
//User receiving the notification is connected and application is to front, notification won't be pushed