Fixes last bug with broadcastreceiver

This commit is contained in:
tom79 2017-09-24 19:27:04 +02:00
parent 47a41a47d9
commit e73006fa49
5 changed files with 31 additions and 11 deletions

View File

@ -139,6 +139,7 @@ public class MainActivity extends AppCompatActivity
public static int countNewNotifications = 0;
private String userIdService;
private Intent streamingIntent;
public static boolean broadCastRegistred = false;
public MainActivity() {
}
@ -188,7 +189,11 @@ public class MainActivity extends AppCompatActivity
};
streamingIntent = new Intent(this, StreamingService.class);
startService(streamingIntent);
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
if( !broadCastRegistred) {
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
broadCastRegistred = true;
}
@ -906,6 +911,7 @@ public class MainActivity extends AppCompatActivity
if( streamingIntent != null)
stopService(streamingIntent);
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
broadCastRegistred = false;
}
@SuppressWarnings("StatementWithEmptyBody")

View File

@ -302,15 +302,22 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
lv_status.setAdapter(statusListAdapter);
swiped = false;
}
if( statuses != null && statuses.size() > 0) {
ArrayList<String> knownId = new ArrayList<>();
for(Status st: this.statuses){
knownId.add(st.getId());
}
for(Status tmpStatus: statuses){
if( type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && lastReadStatus != null && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)){
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
}else {
tmpStatus.setNew(false);
if( !knownId.contains(tmpStatus.getId())) {
if( type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && lastReadStatus != null && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)){
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
}else {
tmpStatus.setNew(false);
}
this.statuses.add(tmpStatus);
}
this.statuses.add(tmpStatus);
}
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME) {
@ -351,7 +358,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
int top = (v == null) ? 0 : v.getTop();
status.setReplies(new ArrayList<Status>());
statuses.add(0,status);
MainActivity.countNewStatus++;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
if( !status.getAccount().getId().equals(userId))
MainActivity.countNewStatus++;
statusListAdapter.notifyDataSetChanged();
lv_status.setSelectionFromTop(index, top);
if (textviewNoAction.getVisibility() == View.VISIBLE)

View File

@ -1594,7 +1594,7 @@ public class Helper {
paint.setStrokeWidth(12);
paint.setTextSize(30);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
canvas.drawText("Via #Mastalab", view.getWidth()-230, view.getHeight() - 35, paint);
canvas.drawText("Via #Mastalab", view.getWidth()-230, view.getHeight() - 5, paint);
if( new_element != null)
new_element.setVisibility(new_element_v);

View File

@ -22,7 +22,6 @@ import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import org.json.JSONException;

View File

@ -142,6 +142,7 @@ public class MainActivity extends AppCompatActivity
public static int countNewNotifications = 0;
private String userIdService;
private Intent streamingIntent;
public static boolean broadCastRegistred = false;
public MainActivity() {
}
@ -191,8 +192,11 @@ public class MainActivity extends AppCompatActivity
};
streamingIntent = new Intent(this, StreamingService.class);
startService(streamingIntent);
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
if( !broadCastRegistred) {
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
broadCastRegistred = true;
}
ProviderInstaller.installIfNeededAsync(this, this);
@ -910,6 +914,7 @@ public class MainActivity extends AppCompatActivity
if( streamingIntent != null)
stopService(streamingIntent);
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
broadCastRegistred = false;
}
@SuppressWarnings("StatementWithEmptyBody")