Sync tabs after moving them.

This commit is contained in:
tom79 2019-04-23 18:42:15 +02:00
parent 6e91768343
commit 69762e650c
5 changed files with 13 additions and 15 deletions

View File

@ -1344,6 +1344,10 @@ public abstract class BaseMainActivity extends BaseActivity
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
DisplayReorderTabFragment displayReorderTabFragment = (DisplayReorderTabFragment)getSupportFragmentManager().findFragmentByTag("REORDER_TIMELINES");
if (displayReorderTabFragment != null && displayReorderTabFragment.isVisible() && DisplayReorderTabFragment.updated) {
new SyncTimelinesAsyncTask(BaseMainActivity.this, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
@ -1783,7 +1787,8 @@ public abstract class BaseMainActivity extends BaseActivity
@Override
public void syncedTimelines(List<ManageTimelines> manageTimelines, boolean updateOnly) {
public void syncedTimelines(List<ManageTimelines> manageTimelines) {
DisplayReorderTabFragment.updated = false;
new ManageTimelines().createTabs(BaseMainActivity.this, manageTimelines);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean optimize_loading = sharedpreferences.getBoolean(Helper.SET_OPTIMIZE_LOADING, false);

View File

@ -27,11 +27,9 @@ import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Instance;
import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnSyncTimelineInterface;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
@ -52,18 +50,11 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
private OnSyncTimelineInterface listener;
private WeakReference<Context> contextReference;
private List<ManageTimelines> manageTimelines;
private boolean updateOnly;
public SyncTimelinesAsyncTask(Context context, boolean updateOnly, OnSyncTimelineInterface onSyncTimelineInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onSyncTimelineInterface;
this.updateOnly = updateOnly;
}
public SyncTimelinesAsyncTask(Context context, OnSyncTimelineInterface onSyncTimelineInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onSyncTimelineInterface;
this.updateOnly = false;
}
@Override
@ -302,7 +293,7 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
listener.syncedTimelines(manageTimelines, updateOnly);
listener.syncedTimelines(manageTimelines);
}
}

View File

@ -37,6 +37,7 @@ import java.util.List;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
import fr.gouv.etalab.mastodon.fragments.DisplayReorderTabFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.ItemTouchHelperAdapter;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.ItemTouchHelperViewHolder;
@ -172,6 +173,7 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<ReorderTabAdapter.It
}else{
holder.hideView.setImageResource(R.drawable.ic_make_tab_unvisible);
}
DisplayReorderTabFragment.updated = true;
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new TimelinesDAO(context, db).update(tl);
}
@ -206,7 +208,7 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<ReorderTabAdapter.It
new TimelinesDAO(context, db).update(timelines);
i++;
}
DisplayReorderTabFragment.updated = true;
return true;
}

View File

@ -48,14 +48,14 @@ public class DisplayReorderTabFragment extends Fragment implements OnStartDragLi
private Context context;
public static boolean updated;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_reorder_tabs, container, false);
context = getContext();
updated = false;
RecyclerView lv_reorder_tabs = rootView.findViewById(R.id.lv_reorder_tabs);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();

View File

@ -24,5 +24,5 @@ import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
* Interface when timelines are retrieved
*/
public interface OnSyncTimelineInterface {
void syncedTimelines(List<ManageTimelines> manageTimelines, boolean updateOnly);
void syncedTimelines(List<ManageTimelines> manageTimelines);
}