Fixes jump listview when new content is available.

This commit is contained in:
tom79 2017-09-14 18:45:20 +02:00
parent 491d3f4285
commit 67285b0876
5 changed files with 15 additions and 19 deletions

View File

@ -154,13 +154,13 @@ public class MainActivity extends AppCompatActivity
if(notificationsFragment != null){
Notification notification = b.getParcelable("data");
notificationsFragment.refresh(notification);
countNewStatus++;
countNewNotifications++;
}
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
Status status = b.getParcelable("data");
if( homeFragment != null){
homeFragment.refresh(status);
countNewNotifications++;
countNewStatus++;
}
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
String id = b.getString("id");

View File

@ -15,12 +15,10 @@ 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;
@ -33,11 +31,8 @@ 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.drawers.NotificationsListAdapter;
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;
@ -231,12 +226,12 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if( context == null)
return;
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);
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);
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
lv_notifications.setAdapter(notificationsListAdapter);
notificationsListAdapter.notifyDataSetChanged();
lv_notifications.setSelectionFromTop(index, top);
if( textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
}

View File

@ -305,12 +305,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if (context == null)
return;
if (status != null) {
int index = lv_status.getFirstVisiblePosition() + 1;
View v = lv_status.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
statuses.add(0,status);
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);
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
lv_status.setAdapter(statusListAdapter);
statusListAdapter.notifyDataSetChanged();
lv_status.setSelectionFromTop(index, top);
if (textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
}

View File

@ -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"

View File

@ -157,13 +157,13 @@ public class MainActivity extends AppCompatActivity
if(notificationsFragment != null){
Notification notification = b.getParcelable("data");
notificationsFragment.refresh(notification);
countNewStatus++;
countNewNotifications++;
}
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
Status status = b.getParcelable("data");
if( homeFragment != null){
homeFragment.refresh(status);
countNewNotifications++;
countNewStatus++;
}
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
String id = b.getString("id");