Enable drag / Move
This commit is contained in:
parent
94aba5f3a0
commit
291a500d1d
|
@ -133,6 +133,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment;
|
|||
import fr.gouv.etalab.mastodon.fragments.DisplayMutedInstanceFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayPeertubeNotificationsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayReorderTabFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.SettingsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.SettingsPeertubeFragment;
|
||||
|
@ -1638,6 +1639,12 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
fragmentTag = "WHO_TO_FOLLOW";
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, whoToFollowFragment, fragmentTag).commit();
|
||||
}else if(id == R.id.nav_drag_timelines){
|
||||
toot.hide();
|
||||
DisplayReorderTabFragment displayReorderTabFragment = new DisplayReorderTabFragment();
|
||||
fragmentTag = "REORDER_TIMELINES";
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, displayReorderTabFragment, fragmentTag).commit();
|
||||
}
|
||||
|
||||
populateTitleWithTag(fragmentTag, item.getTitle().toString(), item.getItemId());
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.SharedPreferences;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -32,19 +31,15 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.ItemTouchHelperAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.ItemTouchHelperViewHolder;
|
||||
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.OnStartDragListener;
|
||||
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO;
|
||||
|
||||
|
@ -159,14 +154,20 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<ReorderTabAdapter.It
|
|||
holder.hideView.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
if(tl.isDisplayed()){
|
||||
holder.hideView.setImageResource(R.drawable.ic_make_tab_visible);
|
||||
}else{
|
||||
holder.hideView.setImageResource(R.drawable.ic_make_tab_unvisible);
|
||||
}
|
||||
|
||||
holder.hideView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tl.setDisplayed(! tl.isDisplayed());
|
||||
if(tl.isDisplayed()){
|
||||
holder.handleView.setImageResource(R.drawable.ic_make_tab_unvisible);
|
||||
holder.hideView.setImageResource(R.drawable.ic_make_tab_visible);
|
||||
}else{
|
||||
holder.handleView.setImageResource(R.drawable.ic_make_tab_visible);
|
||||
holder.hideView.setImageResource(R.drawable.ic_make_tab_unvisible);
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelinesDAO(context, db).update(tl);
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -33,6 +34,7 @@ import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
|
|||
import fr.gouv.etalab.mastodon.drawers.ReorderTabAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.OnStartDragListener;
|
||||
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.SimpleItemTouchHelperCallback;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO;
|
||||
|
||||
|
@ -54,13 +56,19 @@ public class DisplayReorderTabFragment extends Fragment implements OnStartDragLi
|
|||
context = getContext();
|
||||
|
||||
RecyclerView lv_reorder_tabs = rootView.findViewById(R.id.lv_reorder_tabs);
|
||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_reorder_tabs.setLayoutManager(mLayoutManager);
|
||||
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<ManageTimelines> timelines = new TimelinesDAO(context, db).getAllTimelines();
|
||||
new ReorderTabAdapter(context, timelines, DisplayReorderTabFragment.this);
|
||||
ReorderTabAdapter adapter = new ReorderTabAdapter(context, timelines, DisplayReorderTabFragment.this);
|
||||
|
||||
ItemTouchHelper.Callback callback =
|
||||
new SimpleItemTouchHelperCallback(adapter);
|
||||
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
||||
touchHelper.attachToRecyclerView(lv_reorder_tabs);
|
||||
|
||||
lv_reorder_tabs.setAdapter(adapter);
|
||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_reorder_tabs.setLayoutManager(mLayoutManager);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,9H4v2h16V9zM4,15h16v-2H4v2z"/>
|
||||
</vector>
|
|
@ -17,44 +17,49 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?listPreferredItemHeight"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="?listPreferredItemHeight"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical|left"
|
||||
android:scaleType="center"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="center"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/hide"
|
||||
android:layout_width="?listPreferredItemHeight"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical|right"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_make_tab_unvisible"
|
||||
android:contentDescription="@string/hide_timeline"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
<ImageView
|
||||
android:id="@+id/hide"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_make_tab_unvisible"
|
||||
android:contentDescription="@string/hide_timeline"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/handle"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_drag_handle"
|
||||
android:contentDescription="@string/move_timeline"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/handle"
|
||||
android:layout_width="?listPreferredItemHeight"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical|right"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_drag_handle"
|
||||
android:contentDescription="@string/move_timeline"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
</FrameLayout>
|
|
@ -48,6 +48,10 @@
|
|||
android:id="@+id/nav_who_to_follow"
|
||||
android:icon="@drawable/ic_people"
|
||||
android:title="@string/how_to_follow" />
|
||||
<item
|
||||
android:id="@+id/nav_drag_timelines"
|
||||
android:icon="@drawable/ic_drag_handle_menu"
|
||||
android:title="@string/reorder_timelines" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
|
|
@ -923,6 +923,7 @@
|
|||
<string name="hide_tab">Hide the tab</string>
|
||||
<string name="move_timeline">Move timeline</string>
|
||||
<string name="hide_timeline">Hide timeline</string>
|
||||
<string name="reorder_timelines">Reorder timelines</string>
|
||||
|
||||
<plurals name="number_of_vote">
|
||||
<item quantity="one">%d vote</item>
|
||||
|
|
Loading…
Reference in New Issue