Browse Source

- made fragments work with inflated layouts to maintain w900 fragments layout

- simplified PagerAdapter
pull/526/head
Twig N 5 years ago
parent
commit
4aca5e6806
  1. 43
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java
  2. 61
      app/src/main/res/layout-w900dp/activity_rssfeeds.xml
  3. 35
      app/src/main/res/layout/activity_rssfeeds.xml

43
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -22,16 +22,17 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.view.PagerAdapter;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.SnackbarManager;
@ -57,7 +58,6 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.remoterss.RemoteRssFragment; import org.transdroid.core.gui.remoterss.RemoteRssFragment;
import org.transdroid.core.gui.remoterss.RemoteRssFragment_;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier;
@ -112,38 +112,45 @@ public class RssfeedsActivity extends AppCompatActivity {
protected ConnectivityHelper connectivityHelper; protected ConnectivityHelper connectivityHelper;
class PagerAdapter extends FragmentPagerAdapter { protected class LayoutPagerAdapter extends PagerAdapter {
boolean hasRemoteRss = false; boolean hasRemoteRss;
String serverName = ""; String serverName;
public PagerAdapter(FragmentManager fm, boolean hasRemoteRss, String name) { public LayoutPagerAdapter(boolean hasRemoteRss, String name) {
super(fm); super();
this.hasRemoteRss = hasRemoteRss; this.hasRemoteRss = hasRemoteRss;
this.serverName = (name.length() > 0 ? name : getString(R.string.navigation_rss_tabs_remote)); this.serverName = (name.length() > 0 ? name : getString(R.string.navigation_rss_tabs_remote));
} }
@NonNull
@Override @Override
public Fragment getItem(int position) { public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = null; int resId = 0;
if (position == RSS_FEEDS_LOCAL) { if (position == RSS_FEEDS_LOCAL) {
fragment = RssfeedsFragment_.builder().build(); resId = R.id.layout_rssfeeds_local;
} }
else if (position == RSS_FEEDS_REMOTE) { else if (position == RSS_FEEDS_REMOTE) {
fragment = RemoteRssFragment_.builder().build(); resId = R.id.layout_rss_feeds_remote;
} }
return fragment; return findViewById(resId);
} }
@Override @Override
public int getCount() { public int getCount() {
if (this.hasRemoteRss) { return (this.hasRemoteRss ? 2 : 1);
return 2; }
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return (view == o);
}
return 1; @Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
} }
@Nullable @Nullable
@ -178,7 +185,7 @@ public class RssfeedsActivity extends AppCompatActivity {
IDaemonAdapter currentConnection = this.getCurrentConnection(); IDaemonAdapter currentConnection = this.getCurrentConnection();
boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(currentConnection.getType()); boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(currentConnection.getType());
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), hasRemoteRss, currentConnection.getSettings().getName()); PagerAdapter pagerAdapter = new LayoutPagerAdapter(hasRemoteRss, currentConnection.getSettings().getName());
viewPager.setAdapter(pagerAdapter); viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(0); viewPager.setCurrentItem(0);

61
app/src/main/res/layout-w900dp/activity_rssfeeds.xml

@ -32,28 +32,53 @@
style="@style/DefaultToolbarShadow" style="@style/DefaultToolbarShadow"
android:layout_below="@id/rssfeeds_toolbar" /> android:layout_below="@id/rssfeeds_toolbar" />
<LinearLayout <android.support.v4.view.ViewPager
android:id="@+id/rssfeeds_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@id/rssfeeds_toolbar" android:layout_below="@+id/rssfeeds_toolbar">
android:baselineAligned="false"
android:orientation="horizontal"> <android.support.design.widget.TabLayout
android:id="@+id/rssfeeds_tabs"
<fragment android:layout_width="match_parent"
android:id="@+id/rssfeeds_fragment" android:layout_height="wrap_content" />
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
android:layout_width="0dip" <LinearLayout
android:id="@+id/layout_rssfeeds_local"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="2" android:baselineAligned="false"
tools:layout="@layout/fragment_rssfeeds" /> android:orientation="horizontal">
<fragment
android:id="@+id/rssfeeds_fragment"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@layout/fragment_rssfeeds" />
<fragment
android:id="@+id/rssitems_fragment"
class="org.transdroid.core.gui.rss.RssitemsFragment_"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="3"
tools:layout="@layout/fragment_rssitems" />
</LinearLayout>
<fragment <LinearLayout
android:id="@+id/rssitems_fragment" android:id="@+id/layout_rss_feeds_remote"
class="org.transdroid.core.gui.rss.RssitemsFragment_" android:layout_width="match_parent"
android:layout_width="0dip"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="3" android:baselineAligned="false"
tools:layout="@layout/fragment_rssitems" /> android:orientation="horizontal">
</LinearLayout> <fragment
android:id="@+id/remoterss_fragment"
class="org.transdroid.core.gui.remoterss.RemoteRssFragment_"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_torrents" />
</LinearLayout>
</android.support.v4.view.ViewPager>
</RelativeLayout> </RelativeLayout>

35
app/src/main/res/layout/activity_rssfeeds.xml

@ -44,13 +44,34 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<!-- <fragment--> <LinearLayout
<!-- android:id="@+id/rssfeeds_fragment"--> android:id="@+id/layout_rssfeeds_local"
<!-- class="org.transdroid.core.gui.rss.RssfeedsFragment_"--> android:layout_width="match_parent"
<!-- android:layout_width="match_parent"--> android:layout_height="match_parent"
<!-- android:layout_height="match_parent"--> android:baselineAligned="false"
<!-- android:layout_marginTop="-2dp"--> android:orientation="horizontal">
<!-- tools:layout="@layout/fragment_rssfeeds" />--> <fragment
android:id="@+id/rssfeeds_fragment"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@layout/fragment_rssfeeds" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_rss_feeds_remote"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<fragment
android:id="@+id/remoterss_fragment"
class="org.transdroid.core.gui.remoterss.RemoteRssFragment_"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_torrents" />
</LinearLayout>
</android.support.v4.view.ViewPager> </android.support.v4.view.ViewPager>

Loading…
Cancel
Save